Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 21 | #undef LOG_TAG |
| 22 | #define LOG_TAG "CompositionTest" |
| 23 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 24 | #include <compositionengine/Display.h> |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 25 | #include <compositionengine/mock/DisplaySurface.h> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 26 | #include <gmock/gmock.h> |
| 27 | #include <gtest/gtest.h> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 28 | #include <gui/IProducerListener.h> |
Evan Rosky | a1f1e15 | 2019-01-24 16:17:46 -0800 | [diff] [blame] | 29 | #include <gui/LayerMetadata.h> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 30 | #include <log/log.h> |
Lloyd Pique | 3823e7b | 2018-10-18 16:58:10 -0700 | [diff] [blame] | 31 | #include <renderengine/mock/Framebuffer.h> |
| 32 | #include <renderengine/mock/Image.h> |
| 33 | #include <renderengine/mock/RenderEngine.h> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 34 | #include <system/window.h> |
| 35 | #include <utils/String8.h> |
| 36 | |
| 37 | #include "BufferQueueLayer.h" |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 38 | #include "DisplayRenderArea.h" |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 39 | #include "EffectLayer.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 40 | #include "Layer.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 41 | #include "TestableSurfaceFlinger.h" |
| 42 | #include "mock/DisplayHardware/MockComposer.h" |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 43 | #include "mock/DisplayHardware/MockPowerAdvisor.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 44 | #include "mock/MockDispSync.h" |
| 45 | #include "mock/MockEventControlThread.h" |
| 46 | #include "mock/MockEventThread.h" |
| 47 | #include "mock/MockMessageQueue.h" |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 48 | #include "mock/MockTimeStats.h" |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 49 | #include "mock/system/window/MockNativeWindow.h" |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 50 | |
| 51 | namespace android { |
| 52 | namespace { |
| 53 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 54 | namespace hal = android::hardware::graphics::composer::hal; |
| 55 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 56 | using hal::Error; |
| 57 | using hal::IComposer; |
| 58 | using hal::IComposerClient; |
| 59 | using hal::PowerMode; |
| 60 | using hal::Transform; |
| 61 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 62 | using testing::_; |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 63 | using testing::AtLeast; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 64 | using testing::Between; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 65 | using testing::ByMove; |
| 66 | using testing::DoAll; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 67 | using testing::Field; |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 68 | using testing::Invoke; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 69 | using testing::IsNull; |
| 70 | using testing::Mock; |
| 71 | using testing::NotNull; |
| 72 | using testing::Ref; |
| 73 | using testing::Return; |
| 74 | using testing::ReturnRef; |
| 75 | using testing::SetArgPointee; |
| 76 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 77 | using FakeHwcDisplayInjector = TestableSurfaceFlinger::FakeHwcDisplayInjector; |
| 78 | using FakeDisplayDeviceInjector = TestableSurfaceFlinger::FakeDisplayDeviceInjector; |
| 79 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 80 | constexpr hal::HWDisplayId HWC_DISPLAY = FakeHwcDisplayInjector::DEFAULT_HWC_DISPLAY_ID; |
| 81 | constexpr hal::HWLayerId HWC_LAYER = 5000; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 82 | constexpr Transform DEFAULT_TRANSFORM = static_cast<Transform>(0); |
| 83 | |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 84 | constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42}; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 85 | constexpr int DEFAULT_DISPLAY_WIDTH = 1920; |
| 86 | constexpr int DEFAULT_DISPLAY_HEIGHT = 1024; |
| 87 | |
| 88 | constexpr int DEFAULT_CONFIG_ID = 0; |
| 89 | constexpr int DEFAULT_TEXTURE_ID = 6000; |
| 90 | constexpr int DEFAULT_LAYER_STACK = 7000; |
| 91 | |
| 92 | constexpr int DEFAULT_DISPLAY_MAX_LUMINANCE = 500; |
| 93 | |
| 94 | constexpr int DEFAULT_SIDEBAND_STREAM = 51; |
| 95 | |
| 96 | class CompositionTest : public testing::Test { |
| 97 | public: |
| 98 | CompositionTest() { |
| 99 | const ::testing::TestInfo* const test_info = |
| 100 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 101 | ALOGD("**** Setting up for %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 102 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 103 | mFlinger.mutableEventQueue().reset(mMessageQueue); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 104 | setupScheduler(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 105 | |
Alec Mouri | f6fd29e | 2018-11-17 04:56:41 +0000 | [diff] [blame] | 106 | EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 107 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); |
| 108 | EXPECT_CALL(*mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 109 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0))); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 110 | |
| 111 | mFlinger.setupRenderEngine(std::unique_ptr<renderengine::RenderEngine>(mRenderEngine)); |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 112 | mFlinger.setupTimeStats(std::shared_ptr<TimeStats>(mTimeStats)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 113 | setupComposer(0); |
| 114 | } |
| 115 | |
| 116 | ~CompositionTest() { |
| 117 | const ::testing::TestInfo* const test_info = |
| 118 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 119 | ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name()); |
| 120 | } |
| 121 | |
| 122 | void setupComposer(int virtualDisplayCount) { |
| 123 | mComposer = new Hwc2::mock::Composer(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 124 | EXPECT_CALL(*mComposer, getMaxVirtualDisplayCount()).WillOnce(Return(virtualDisplayCount)); |
| 125 | mFlinger.setupComposer(std::unique_ptr<Hwc2::Composer>(mComposer)); |
| 126 | |
| 127 | Mock::VerifyAndClear(mComposer); |
| 128 | } |
| 129 | |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 130 | void setupScheduler() { |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 131 | auto eventThread = std::make_unique<mock::EventThread>(); |
| 132 | auto sfEventThread = std::make_unique<mock::EventThread>(); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 133 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 134 | EXPECT_CALL(*eventThread, registerDisplayEventConnection(_)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 135 | EXPECT_CALL(*eventThread, createEventConnection(_, _)) |
| 136 | .WillOnce(Return( |
| 137 | new EventThreadConnection(eventThread.get(), ResyncCallback(), |
| 138 | ISurfaceComposer::eConfigChangedSuppress))); |
| 139 | |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 140 | EXPECT_CALL(*sfEventThread, registerDisplayEventConnection(_)); |
Dominik Laskowski | 9804183 | 2019-08-01 18:35:59 -0700 | [diff] [blame] | 141 | EXPECT_CALL(*sfEventThread, createEventConnection(_, _)) |
| 142 | .WillOnce(Return( |
| 143 | new EventThreadConnection(sfEventThread.get(), ResyncCallback(), |
| 144 | ISurfaceComposer::eConfigChangedSuppress))); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 145 | |
| 146 | auto primaryDispSync = std::make_unique<mock::DispSync>(); |
| 147 | |
Ady Abraham | 0ed31c9 | 2020-04-16 11:48:45 -0700 | [diff] [blame] | 148 | EXPECT_CALL(*primaryDispSync, computeNextRefresh(0, _)).WillRepeatedly(Return(0)); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 149 | EXPECT_CALL(*primaryDispSync, getPeriod()) |
| 150 | .WillRepeatedly(Return(FakeHwcDisplayInjector::DEFAULT_REFRESH_RATE)); |
Ady Abraham | 0ed31c9 | 2020-04-16 11:48:45 -0700 | [diff] [blame] | 151 | EXPECT_CALL(*primaryDispSync, expectedPresentTime(_)).WillRepeatedly(Return(0)); |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 152 | |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 153 | constexpr bool kHasMultipleConfigs = true; |
Dominik Laskowski | 7c9dbf9 | 2019-08-01 17:57:31 -0700 | [diff] [blame] | 154 | mFlinger.setupScheduler(std::move(primaryDispSync), |
| 155 | std::make_unique<mock::EventControlThread>(), |
Dominik Laskowski | 983f2b5 | 2020-06-25 16:54:06 -0700 | [diff] [blame] | 156 | std::move(eventThread), std::move(sfEventThread), |
| 157 | kHasMultipleConfigs); |
| 158 | |
| 159 | // Layer history should be created if there are multiple configs. |
| 160 | ASSERT_TRUE(mFlinger.scheduler()->hasLayerHistory()); |
Ana Krulec | afb4584 | 2019-02-13 13:33:03 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 163 | void setupForceGeometryDirty() { |
| 164 | // TODO: This requires the visible region and other related |
| 165 | // state to be set, and is problematic for BufferLayers since they are |
| 166 | // not visible without a buffer (and setting up a buffer looks like a |
| 167 | // pain) |
| 168 | // mFlinger.mutableVisibleRegionsDirty() = true; |
| 169 | |
| 170 | mFlinger.mutableGeometryInvalid() = true; |
| 171 | } |
| 172 | |
| 173 | template <typename Case> |
| 174 | void displayRefreshCompositionDirtyGeometry(); |
| 175 | |
| 176 | template <typename Case> |
| 177 | void displayRefreshCompositionDirtyFrame(); |
| 178 | |
| 179 | template <typename Case> |
| 180 | void captureScreenComposition(); |
| 181 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 182 | std::unordered_set<hal::Capability> mDefaultCapabilities = {hal::Capability::SIDEBAND_STREAM}; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 183 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 184 | bool mDisplayOff = false; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 185 | TestableSurfaceFlinger mFlinger; |
| 186 | sp<DisplayDevice> mDisplay; |
| 187 | sp<DisplayDevice> mExternalDisplay; |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 188 | sp<compositionengine::mock::DisplaySurface> mDisplaySurface = |
| 189 | new compositionengine::mock::DisplaySurface(); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 190 | mock::NativeWindow* mNativeWindow = new mock::NativeWindow(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 191 | |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 192 | sp<GraphicBuffer> mBuffer = new GraphicBuffer(); |
| 193 | ANativeWindowBuffer* mNativeWindowBuffer = mBuffer->getNativeBuffer(); |
| 194 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 195 | Hwc2::mock::Composer* mComposer = nullptr; |
| 196 | renderengine::mock::RenderEngine* mRenderEngine = new renderengine::mock::RenderEngine(); |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 197 | mock::TimeStats* mTimeStats = new mock::TimeStats(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 198 | mock::MessageQueue* mMessageQueue = new mock::MessageQueue(); |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 199 | Hwc2::mock::PowerAdvisor mPowerAdvisor; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 200 | |
| 201 | sp<Fence> mClientTargetAcquireFence = Fence::NO_FENCE; |
| 202 | |
| 203 | sp<GraphicBuffer> mCaptureScreenBuffer; |
| 204 | }; |
| 205 | |
| 206 | template <typename LayerCase> |
| 207 | void CompositionTest::displayRefreshCompositionDirtyGeometry() { |
| 208 | setupForceGeometryDirty(); |
| 209 | LayerCase::setupForDirtyGeometry(this); |
| 210 | |
| 211 | // -------------------------------------------------------------------- |
| 212 | // Invocation |
| 213 | |
| 214 | mFlinger.onMessageReceived(MessageQueue::INVALIDATE); |
| 215 | mFlinger.onMessageReceived(MessageQueue::REFRESH); |
| 216 | |
| 217 | LayerCase::cleanup(this); |
| 218 | } |
| 219 | |
| 220 | template <typename LayerCase> |
| 221 | void CompositionTest::displayRefreshCompositionDirtyFrame() { |
| 222 | LayerCase::setupForDirtyFrame(this); |
| 223 | |
| 224 | // -------------------------------------------------------------------- |
| 225 | // Invocation |
| 226 | |
| 227 | mFlinger.onMessageReceived(MessageQueue::INVALIDATE); |
| 228 | mFlinger.onMessageReceived(MessageQueue::REFRESH); |
| 229 | |
| 230 | LayerCase::cleanup(this); |
| 231 | } |
| 232 | |
| 233 | template <typename LayerCase> |
| 234 | void CompositionTest::captureScreenComposition() { |
| 235 | LayerCase::setupForScreenCapture(this); |
| 236 | |
| 237 | const Rect sourceCrop(0, 0, DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 238 | constexpr bool useIdentityTransform = true; |
| 239 | constexpr bool forSystem = true; |
Lucas Dupin | 9d763b7 | 2020-04-20 18:42:31 -0700 | [diff] [blame] | 240 | constexpr bool regionSampling = false; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 241 | |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 242 | auto renderArea = DisplayRenderArea::create(mDisplay, sourceCrop, sourceCrop.getSize(), |
| 243 | ui::Dataspace::V0_SRGB, ui::Transform::ROT_0); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 244 | |
| 245 | auto traverseLayers = [this](const LayerVector::Visitor& visitor) { |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 246 | return mFlinger.traverseLayersInLayerStack(mDisplay->getLayerStack(), visitor); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | // TODO: Eliminate expensive/real allocation if possible. |
| 250 | const uint32_t usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN | |
| 251 | GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE; |
Marin Shalamanov | 1c43429 | 2020-06-12 01:47:29 +0200 | [diff] [blame] | 252 | mCaptureScreenBuffer = new GraphicBuffer(renderArea->getReqWidth(), renderArea->getReqHeight(), |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 253 | HAL_PIXEL_FORMAT_RGBA_8888, 1, usage, "screenshot"); |
| 254 | |
| 255 | int fd = -1; |
| 256 | status_t result = |
chaviw | 426b5c0 | 2020-07-27 11:20:15 -0700 | [diff] [blame^] | 257 | mFlinger.renderScreenImplLocked(*renderArea, traverseLayers, mCaptureScreenBuffer.get(), |
| 258 | useIdentityTransform, forSystem, &fd, regionSampling); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 259 | if (fd >= 0) { |
| 260 | close(fd); |
| 261 | } |
| 262 | |
| 263 | EXPECT_EQ(NO_ERROR, result); |
| 264 | |
| 265 | LayerCase::cleanup(this); |
| 266 | } |
| 267 | |
| 268 | /* ------------------------------------------------------------------------ |
| 269 | * Variants for each display configuration which can be tested |
| 270 | */ |
| 271 | |
| 272 | template <typename Derived> |
| 273 | struct BaseDisplayVariant { |
| 274 | static constexpr bool IS_SECURE = true; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 275 | static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::ON; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 276 | |
| 277 | static void setupPreconditions(CompositionTest* test) { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 278 | EXPECT_CALL(*test->mComposer, setPowerMode(HWC_DISPLAY, Derived::INIT_POWER_MODE)) |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 279 | .WillOnce(Return(Error::NONE)); |
Alec Mouri | ba013fa | 2018-10-16 12:43:11 -0700 | [diff] [blame] | 280 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 281 | FakeHwcDisplayInjector(DEFAULT_DISPLAY_ID, hal::DisplayType::PHYSICAL, true /* isPrimary */) |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 282 | .setCapabilities(&test->mDefaultCapabilities) |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 283 | .setPowerMode(Derived::INIT_POWER_MODE) |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 284 | .inject(&test->mFlinger, test->mComposer); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 285 | Mock::VerifyAndClear(test->mComposer); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 286 | |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 287 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_WIDTH, _)) |
| 288 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_WIDTH), Return(0))); |
| 289 | EXPECT_CALL(*test->mNativeWindow, query(NATIVE_WINDOW_HEIGHT, _)) |
| 290 | .WillRepeatedly(DoAll(SetArgPointee<1>(DEFAULT_DISPLAY_HEIGHT), Return(0))); |
| 291 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_BUFFERS_FORMAT)).Times(1); |
| 292 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_API_CONNECT)).Times(1); |
| 293 | EXPECT_CALL(*test->mNativeWindow, perform(NATIVE_WINDOW_SET_USAGE64)).Times(1); |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 294 | |
| 295 | const ::testing::TestInfo* const test_info = |
| 296 | ::testing::UnitTest::GetInstance()->current_test_info(); |
| 297 | |
| 298 | auto ceDisplayArgs = |
| 299 | compositionengine::DisplayCreationArgsBuilder() |
| 300 | .setPhysical({DEFAULT_DISPLAY_ID, DisplayConnectionType::Internal}) |
| 301 | .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT}) |
| 302 | .setIsSecure(Derived::IS_SECURE) |
| 303 | .setLayerStackId(DEFAULT_LAYER_STACK) |
| 304 | .setPowerAdvisor(&test->mPowerAdvisor) |
| 305 | .setName(std::string("Injected display for ") + |
| 306 | test_info->test_case_name() + "." + test_info->name()) |
| 307 | .build(); |
| 308 | |
| 309 | auto compositionDisplay = |
| 310 | compositionengine::impl::createDisplay(test->mFlinger.getCompositionEngine(), |
| 311 | ceDisplayArgs); |
| 312 | |
Marin Shalamanov | 700e639 | 2020-02-12 20:22:26 +0100 | [diff] [blame] | 313 | test->mDisplay = FakeDisplayDeviceInjector(test->mFlinger, compositionDisplay, |
| 314 | DisplayConnectionType::Internal, HWC_DISPLAY, |
| 315 | true /* isPrimary */) |
| 316 | .setDisplaySurface(test->mDisplaySurface) |
| 317 | .setNativeWindow(test->mNativeWindow) |
| 318 | .setSecure(Derived::IS_SECURE) |
| 319 | .setPowerMode(Derived::INIT_POWER_MODE) |
| 320 | .inject(); |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 321 | Mock::VerifyAndClear(test->mNativeWindow); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 322 | test->mDisplay->setLayerStack(DEFAULT_LAYER_STACK); |
| 323 | } |
| 324 | |
| 325 | template <typename Case> |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 326 | static void setupPreconditionCallExpectations(CompositionTest* test) { |
| 327 | EXPECT_CALL(*test->mComposer, getDisplayCapabilities(HWC_DISPLAY, _)) |
| 328 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::DisplayCapability>({})), |
| 329 | Return(Error::NONE))); |
| 330 | } |
| 331 | |
| 332 | template <typename Case> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 333 | static void setupCommonCompositionCallExpectations(CompositionTest* test) { |
| 334 | EXPECT_CALL(*test->mComposer, |
| 335 | setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY)) |
| 336 | .Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 337 | EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1); |
| 338 | EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1); |
| 339 | EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1); |
| 340 | EXPECT_CALL(*test->mComposer, getReleaseFences(HWC_DISPLAY, _, _)).Times(1); |
| 341 | |
| 342 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 343 | |
| 344 | EXPECT_CALL(*test->mDisplaySurface, onFrameCommitted()).Times(1); |
| 345 | EXPECT_CALL(*test->mDisplaySurface, advanceFrame()).Times(1); |
| 346 | |
| 347 | Case::CompositionType::setupHwcSetCallExpectations(test); |
| 348 | Case::CompositionType::setupHwcGetCallExpectations(test); |
| 349 | } |
| 350 | |
| 351 | template <typename Case> |
| 352 | static void setupCommonScreensCaptureCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 353 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 354 | .WillRepeatedly([](const renderengine::DisplaySettings& displaySettings, |
| 355 | const std::vector<const renderengine::LayerSettings*>&, |
| 356 | const sp<GraphicBuffer>&, const bool, base::unique_fd&&, |
| 357 | base::unique_fd*) -> status_t { |
| 358 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 359 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 360 | displaySettings.physicalDisplay); |
| 361 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 362 | displaySettings.clip); |
| 363 | return NO_ERROR; |
| 364 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | static void setupNonEmptyFrameCompositionCallExpectations(CompositionTest* test) { |
| 368 | EXPECT_CALL(*test->mDisplaySurface, beginFrame(true)).Times(1); |
| 369 | } |
| 370 | |
| 371 | static void setupEmptyFrameCompositionCallExpectations(CompositionTest* test) { |
| 372 | EXPECT_CALL(*test->mDisplaySurface, beginFrame(false)).Times(1); |
| 373 | } |
| 374 | |
| 375 | static void setupHwcCompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 376 | EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1); |
| 377 | |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 378 | EXPECT_CALL(*test->mDisplaySurface, |
| 379 | prepareFrame(compositionengine::DisplaySurface::COMPOSITION_HWC)) |
| 380 | .Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 383 | static void setupHwcClientCompositionCallExpectations(CompositionTest* test) { |
| 384 | EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1); |
| 385 | } |
| 386 | |
| 387 | static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) { |
| 388 | EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1); |
| 389 | } |
| 390 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 391 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | 542307f | 2018-10-19 13:24:08 -0700 | [diff] [blame] | 392 | EXPECT_CALL(*test->mDisplaySurface, |
Peiyong Lin | f3ffc4e | 2019-12-13 00:46:24 -0800 | [diff] [blame] | 393 | prepareFrame(compositionengine::DisplaySurface::COMPOSITION_GPU)) |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 394 | .Times(1); |
| 395 | EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence()) |
| 396 | .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence)); |
| 397 | |
Alec Mouri | 0a9c7b8 | 2018-11-16 13:05:25 -0800 | [diff] [blame] | 398 | EXPECT_CALL(*test->mNativeWindow, queueBuffer(_, _)).WillOnce(Return(0)); |
| 399 | EXPECT_CALL(*test->mNativeWindow, dequeueBuffer(_, _)) |
| 400 | .WillOnce(DoAll(SetArgPointee<0>(test->mNativeWindowBuffer), SetArgPointee<1>(-1), |
| 401 | Return(0))); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 402 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
Lloyd Pique | 9370a48 | 2019-10-03 17:58:30 -0700 | [diff] [blame] | 403 | .WillRepeatedly([](const renderengine::DisplaySettings& displaySettings, |
| 404 | const std::vector<const renderengine::LayerSettings*>&, |
| 405 | const sp<GraphicBuffer>&, const bool, base::unique_fd&&, |
| 406 | base::unique_fd*) -> status_t { |
| 407 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 408 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 409 | displaySettings.physicalDisplay); |
| 410 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 411 | displaySettings.clip); |
| 412 | EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace); |
| 413 | return NO_ERROR; |
| 414 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | template <typename Case> |
| 418 | static void setupRELayerCompositionCallExpectations(CompositionTest* test) { |
| 419 | Case::Layer::setupRECompositionCallExpectations(test); |
| 420 | } |
| 421 | |
| 422 | template <typename Case> |
| 423 | static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 424 | Case::Layer::setupREScreenshotCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 425 | } |
| 426 | }; |
| 427 | |
| 428 | struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {}; |
| 429 | |
| 430 | struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> { |
| 431 | static constexpr bool IS_SECURE = false; |
| 432 | |
| 433 | template <typename Case> |
| 434 | static void setupRELayerCompositionCallExpectations(CompositionTest* test) { |
| 435 | Case::Layer::setupInsecureRECompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | template <typename Case> |
| 439 | static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 440 | Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 441 | } |
| 442 | }; |
| 443 | |
| 444 | struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 445 | static constexpr hal::PowerMode INIT_POWER_MODE = hal::PowerMode::OFF; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 446 | |
| 447 | template <typename Case> |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 448 | static void setupPreconditionCallExpectations(CompositionTest*) {} |
| 449 | |
| 450 | template <typename Case> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 451 | static void setupCommonCompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 452 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
| 453 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 454 | // TODO: This seems like an unnecessary call if display is powered off. |
| 455 | EXPECT_CALL(*test->mComposer, |
| 456 | setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY)) |
| 457 | .Times(1); |
| 458 | |
| 459 | // TODO: This seems like an unnecessary call if display is powered off. |
| 460 | Case::CompositionType::setupHwcSetCallExpectations(test); |
| 461 | } |
| 462 | |
| 463 | static void setupHwcCompositionCallExpectations(CompositionTest*) {} |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 464 | static void setupHwcClientCompositionCallExpectations(CompositionTest*) {} |
| 465 | static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {} |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 466 | |
| 467 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 468 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
| 469 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 470 | // TODO: This seems like an unnecessary call if display is powered off. |
| 471 | EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence()) |
| 472 | .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence)); |
| 473 | } |
| 474 | |
| 475 | template <typename Case> |
| 476 | static void setupRELayerCompositionCallExpectations(CompositionTest*) {} |
| 477 | }; |
| 478 | |
| 479 | /* ------------------------------------------------------------------------ |
| 480 | * Variants for each layer configuration which can be tested |
| 481 | */ |
| 482 | |
| 483 | template <typename LayerProperties> |
| 484 | struct BaseLayerProperties { |
| 485 | static constexpr uint32_t WIDTH = 100; |
| 486 | static constexpr uint32_t HEIGHT = 100; |
| 487 | static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888; |
| 488 | static constexpr uint64_t USAGE = |
| 489 | GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER; |
| 490 | static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN; |
| 491 | static constexpr uint32_t SCALING_MODE = 0; |
| 492 | static constexpr uint32_t TRANSFORM = 0; |
| 493 | static constexpr uint32_t LAYER_FLAGS = 0; |
| 494 | static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f}; |
| 495 | static constexpr IComposerClient::BlendMode BLENDMODE = |
| 496 | IComposerClient::BlendMode::PREMULTIPLIED; |
| 497 | |
| 498 | static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) { |
| 499 | auto producer = layer->getProducer(); |
| 500 | |
| 501 | IGraphicBufferProducer::QueueBufferOutput qbo; |
| 502 | status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo); |
| 503 | if (result != NO_ERROR) { |
| 504 | ALOGE("Failed to connect() (%d)", result); |
| 505 | return; |
| 506 | } |
| 507 | |
| 508 | int slot; |
| 509 | sp<Fence> fence; |
| 510 | result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH, |
| 511 | LayerProperties::HEIGHT, LayerProperties::FORMAT, |
| 512 | LayerProperties::USAGE, nullptr, nullptr); |
| 513 | if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) { |
| 514 | ALOGE("Failed to dequeueBuffer() (%d)", result); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | sp<GraphicBuffer> buffer; |
| 519 | result = producer->requestBuffer(slot, &buffer); |
| 520 | if (result != NO_ERROR) { |
| 521 | ALOGE("Failed to requestBuffer() (%d)", result); |
| 522 | return; |
| 523 | } |
| 524 | |
| 525 | IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */, |
| 526 | LayerProperties::DATASPACE, |
| 527 | Rect(LayerProperties::WIDTH, |
| 528 | LayerProperties::HEIGHT), |
| 529 | LayerProperties::SCALING_MODE, |
| 530 | LayerProperties::TRANSFORM, Fence::NO_FENCE); |
| 531 | result = producer->queueBuffer(slot, qbi, &qbo); |
| 532 | if (result != NO_ERROR) { |
| 533 | ALOGE("Failed to queueBuffer (%d)", result); |
| 534 | return; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 539 | // TODO: Eliminate the complexity of actually creating a buffer |
| 540 | EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384)); |
| 541 | EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384)); |
| 542 | status_t err = |
| 543 | layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT, |
| 544 | LayerProperties::FORMAT); |
| 545 | ASSERT_EQ(NO_ERROR, err); |
| 546 | Mock::VerifyAndClear(test->mRenderEngine); |
| 547 | |
| 548 | EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1); |
| 549 | enqueueBuffer(test, layer); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 550 | Mock::VerifyAndClearExpectations(test->mMessageQueue); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 551 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 552 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 553 | bool ignoredRecomputeVisibleRegions; |
Dominik Laskowski | a8955dd | 2019-07-10 10:19:09 -0700 | [diff] [blame] | 554 | layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 555 | Mock::VerifyAndClear(test->mRenderEngine); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 559 | setupLatchedBuffer(test, layer); |
| 560 | } |
| 561 | |
| 562 | static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) { |
| 563 | // BufferLayer::onPostComposition(), when there is no present fence |
| 564 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _)) |
| 565 | .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE))); |
| 566 | } |
| 567 | |
| 568 | static void setupHwcSetGeometryCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 569 | if (!test->mDisplayOff) { |
| 570 | // TODO: Coverage of other values |
| 571 | EXPECT_CALL(*test->mComposer, |
| 572 | setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE)) |
| 573 | .Times(1); |
| 574 | // TODO: Coverage of other values for origin |
| 575 | EXPECT_CALL(*test->mComposer, |
| 576 | setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER, |
| 577 | IComposerClient::Rect({0, 0, LayerProperties::WIDTH, |
| 578 | LayerProperties::HEIGHT}))) |
| 579 | .Times(1); |
| 580 | EXPECT_CALL(*test->mComposer, |
| 581 | setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3])) |
| 582 | .Times(1); |
| 583 | // TODO: Coverage of other values |
| 584 | EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1); |
| 585 | // TODO: Coverage of other values |
| 586 | EXPECT_CALL(*test->mComposer, setLayerInfo(HWC_DISPLAY, HWC_LAYER, 0u, 0u)).Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 587 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 588 | // These expectations retire on saturation as the code path these |
| 589 | // expectations are for appears to make an extra call to them. |
| 590 | // TODO: Investigate this extra call |
| 591 | EXPECT_CALL(*test->mComposer, |
| 592 | setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM)) |
| 593 | .Times(AtLeast(1)) |
| 594 | .RetiresOnSaturation(); |
| 595 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 599 | if (!test->mDisplayOff) { |
| 600 | EXPECT_CALL(*test->mComposer, |
| 601 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 602 | IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH, |
| 603 | LayerProperties::HEIGHT}))) |
| 604 | .Times(1); |
| 605 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 609 | if (!test->mDisplayOff) { |
| 610 | EXPECT_CALL(*test->mComposer, |
| 611 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 612 | IComposerClient::FRect({0.f, 0.f, 0.f, 0.f}))) |
| 613 | .Times(1); |
| 614 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 618 | if (!test->mDisplayOff) { |
| 619 | EXPECT_CALL(*test->mComposer, |
| 620 | setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER, |
| 621 | std::vector<IComposerClient::Rect>( |
| 622 | {IComposerClient::Rect( |
| 623 | {0, 0, LayerProperties::WIDTH, |
| 624 | LayerProperties::HEIGHT})}))) |
| 625 | .Times(1); |
| 626 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 630 | if (!test->mDisplayOff) { |
| 631 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)) |
| 632 | .Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 633 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 634 | // TODO: use COLOR |
| 635 | EXPECT_CALL(*test->mComposer, |
| 636 | setLayerColor(HWC_DISPLAY, HWC_LAYER, |
| 637 | IComposerClient::Color({0xff, 0xff, 0xff, 0xff}))) |
| 638 | .Times(1); |
| 639 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 643 | if (!test->mDisplayOff) { |
| 644 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)) |
| 645 | .Times(1); |
| 646 | EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1); |
| 647 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 648 | |
| 649 | setupBufferLayerPostFrameCallExpectations(test); |
| 650 | } |
| 651 | |
| 652 | static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 653 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 654 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 655 | const std::vector<const renderengine::LayerSettings*>& layerSettings, |
Ana Krulec | fc874ae | 2020-02-22 15:39:32 -0800 | [diff] [blame] | 656 | const sp<GraphicBuffer>&, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 657 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 658 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 659 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 660 | displaySettings.physicalDisplay); |
| 661 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 662 | displaySettings.clip); |
| 663 | // screen capture adds an additional color layer as an alpha |
| 664 | // prefill, so gtet the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 665 | if (layerSettings.empty()) { |
| 666 | ADD_FAILURE() << "layerSettings was not expected to be empty in " |
| 667 | "setupREBufferCompositionCommonCallExpectations " |
| 668 | "verification lambda"; |
| 669 | return NO_ERROR; |
| 670 | } |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 671 | const renderengine::LayerSettings* layer = layerSettings.back(); |
| 672 | EXPECT_THAT(layer->source.buffer.buffer, Not(IsNull())); |
| 673 | EXPECT_THAT(layer->source.buffer.fence, Not(IsNull())); |
| 674 | EXPECT_EQ(DEFAULT_TEXTURE_ID, layer->source.buffer.textureName); |
| 675 | EXPECT_EQ(false, layer->source.buffer.isY410BT2020); |
| 676 | EXPECT_EQ(true, layer->source.buffer.usePremultipliedAlpha); |
| 677 | EXPECT_EQ(false, layer->source.buffer.isOpaque); |
| 678 | EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius); |
| 679 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace); |
| 680 | EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 681 | return NO_ERROR; |
| 682 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | static void setupREBufferCompositionCallExpectations(CompositionTest* test) { |
| 686 | LayerProperties::setupREBufferCompositionCommonCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) { |
| 690 | setupREBufferCompositionCallExpectations(test); |
| 691 | } |
| 692 | |
| 693 | static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 694 | LayerProperties::setupREBufferCompositionCommonCallExpectations(test); |
| 695 | } |
| 696 | |
| 697 | static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 698 | LayerProperties::setupREBufferCompositionCommonCallExpectations(test); |
| 699 | } |
| 700 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 701 | static void setupREColorCompositionCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 702 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 703 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 704 | const std::vector<const renderengine::LayerSettings*>& layerSettings, |
Ana Krulec | fc874ae | 2020-02-22 15:39:32 -0800 | [diff] [blame] | 705 | const sp<GraphicBuffer>&, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 706 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 707 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 708 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 709 | displaySettings.physicalDisplay); |
| 710 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 711 | displaySettings.clip); |
| 712 | // screen capture adds an additional color layer as an alpha |
| 713 | // prefill, so get the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 714 | if (layerSettings.empty()) { |
| 715 | ADD_FAILURE() |
| 716 | << "layerSettings was not expected to be empty in " |
| 717 | "setupREColorCompositionCallExpectations verification lambda"; |
| 718 | return NO_ERROR; |
| 719 | } |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 720 | const renderengine::LayerSettings* layer = layerSettings.back(); |
| 721 | EXPECT_THAT(layer->source.buffer.buffer, IsNull()); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 722 | EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1], |
| 723 | LayerProperties::COLOR[2]), |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 724 | layer->source.solidColor); |
| 725 | EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius); |
| 726 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace); |
| 727 | EXPECT_EQ(LayerProperties::COLOR[3], layer->alpha); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 728 | return NO_ERROR; |
| 729 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 733 | setupREColorCompositionCallExpectations(test); |
| 734 | } |
| 735 | }; |
| 736 | |
| 737 | struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {}; |
| 738 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 739 | struct EffectLayerProperties : public BaseLayerProperties<EffectLayerProperties> { |
Alec Mouri | da8a9d1 | 2020-01-30 20:00:31 -0800 | [diff] [blame] | 740 | static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE; |
| 741 | }; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 742 | |
| 743 | struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> { |
| 744 | using Base = BaseLayerProperties<SidebandLayerProperties>; |
| 745 | static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE; |
| 746 | |
| 747 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 748 | sp<NativeHandle> stream = |
| 749 | NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM), |
| 750 | false); |
| 751 | test->mFlinger.setLayerSidebandStream(layer, stream); |
| 752 | } |
| 753 | |
| 754 | static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) { |
| 755 | EXPECT_CALL(*test->mComposer, |
| 756 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 757 | IComposerClient::FRect({0.f, 0.f, -1.f, -1.f}))) |
| 758 | .Times(1); |
| 759 | } |
| 760 | |
| 761 | static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) { |
| 762 | EXPECT_CALL(*test->mComposer, |
| 763 | setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER, |
| 764 | reinterpret_cast<native_handle_t*>( |
| 765 | DEFAULT_SIDEBAND_STREAM))) |
| 766 | .WillOnce(Return(Error::NONE)); |
| 767 | |
| 768 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1); |
| 769 | } |
| 770 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 771 | static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {} |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 772 | }; |
| 773 | |
| 774 | struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> { |
| 775 | using Base = BaseLayerProperties<SecureLayerProperties>; |
| 776 | |
| 777 | static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure; |
| 778 | |
| 779 | static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 780 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 781 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 782 | const std::vector<const renderengine::LayerSettings*>& layerSettings, |
Ana Krulec | fc874ae | 2020-02-22 15:39:32 -0800 | [diff] [blame] | 783 | const sp<GraphicBuffer>&, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 784 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 785 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 786 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 787 | displaySettings.physicalDisplay); |
| 788 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 789 | displaySettings.clip); |
| 790 | // screen capture adds an additional color layer as an alpha |
| 791 | // prefill, so get the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 792 | if (layerSettings.empty()) { |
| 793 | ADD_FAILURE() << "layerSettings was not expected to be empty in " |
| 794 | "setupInsecureREBufferCompositionCommonCallExpectations " |
| 795 | "verification lambda"; |
| 796 | return NO_ERROR; |
| 797 | } |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 798 | const renderengine::LayerSettings* layer = layerSettings.back(); |
| 799 | EXPECT_THAT(layer->source.buffer.buffer, IsNull()); |
| 800 | EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor); |
| 801 | EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius); |
| 802 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace); |
| 803 | EXPECT_EQ(1.0f, layer->alpha); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 804 | return NO_ERROR; |
| 805 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) { |
| 809 | setupInsecureREBufferCompositionCommonCallExpectations(test); |
| 810 | Base::setupBufferLayerPostFrameCallExpectations(test); |
| 811 | } |
| 812 | |
| 813 | static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 814 | setupInsecureREBufferCompositionCommonCallExpectations(test); |
| 815 | } |
| 816 | }; |
| 817 | |
| 818 | struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> { |
| 819 | using Base = BaseLayerProperties<CursorLayerProperties>; |
| 820 | |
| 821 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 822 | Base::setupLayerState(test, layer); |
| 823 | test->mFlinger.setLayerPotentialCursor(layer, true); |
| 824 | } |
| 825 | }; |
| 826 | |
| 827 | struct NoLayerVariant { |
| 828 | using FlingerLayerType = sp<BufferQueueLayer>; |
| 829 | |
| 830 | static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); } |
| 831 | static void injectLayer(CompositionTest*, FlingerLayerType) {} |
| 832 | static void cleanupInjectedLayers(CompositionTest*) {} |
| 833 | |
| 834 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 835 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 836 | }; |
| 837 | |
| 838 | template <typename LayerProperties> |
| 839 | struct BaseLayerVariant { |
| 840 | template <typename L, typename F> |
| 841 | static sp<L> createLayerWithFactory(CompositionTest* test, F factory) { |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 842 | EXPECT_CALL(*test->mMessageQueue, postMessage(_)).Times(0); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 843 | |
| 844 | sp<L> layer = factory(); |
| 845 | |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 846 | // Layer should be registered with scheduler. |
| 847 | EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize()); |
| 848 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 849 | Mock::VerifyAndClear(test->mComposer); |
| 850 | Mock::VerifyAndClear(test->mRenderEngine); |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 851 | Mock::VerifyAndClearExpectations(test->mMessageQueue); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 852 | |
| 853 | auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); |
| 854 | layerDrawingState.layerStack = DEFAULT_LAYER_STACK; |
| 855 | layerDrawingState.active.w = 100; |
| 856 | layerDrawingState.active.h = 100; |
| 857 | layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1], |
| 858 | LayerProperties::COLOR[2], LayerProperties::COLOR[3]); |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 859 | layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 860 | |
| 861 | return layer; |
| 862 | } |
| 863 | |
| 864 | static void injectLayer(CompositionTest* test, sp<Layer> layer) { |
| 865 | EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _)) |
| 866 | .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE))); |
| 867 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 868 | auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest( |
| 869 | layer->getCompositionEngineLayerFE()); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 870 | outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 871 | outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 872 | |
| 873 | Mock::VerifyAndClear(test->mComposer); |
| 874 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 875 | test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer); |
| 876 | } |
| 877 | |
| 878 | static void cleanupInjectedLayers(CompositionTest* test) { |
| 879 | EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER)) |
| 880 | .WillOnce(Return(Error::NONE)); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 881 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 882 | test->mDisplay->getCompositionDisplay()->clearOutputLayers(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 883 | test->mFlinger.mutableDrawingState().layersSortedByZ.clear(); |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 884 | |
| 885 | // Layer should be unregistered with scheduler. |
| 886 | test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE); |
| 887 | EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize()); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 888 | } |
| 889 | }; |
| 890 | |
| 891 | template <typename LayerProperties> |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 892 | struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 893 | using Base = BaseLayerVariant<LayerProperties>; |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 894 | using FlingerLayerType = sp<EffectLayer>; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 895 | |
| 896 | static FlingerLayerType createLayer(CompositionTest* test) { |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 897 | FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() { |
| 898 | return new EffectLayer( |
| 899 | LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), "test-layer", |
| 900 | LayerProperties::WIDTH, LayerProperties::HEIGHT, |
| 901 | LayerProperties::LAYER_FLAGS, LayerMetadata())); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 902 | }); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 903 | |
| 904 | auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); |
| 905 | layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 906 | return layer; |
| 907 | } |
| 908 | |
| 909 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 910 | LayerProperties::setupREColorCompositionCallExpectations(test); |
| 911 | } |
| 912 | |
| 913 | static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 914 | LayerProperties::setupREColorScreenshotCompositionCallExpectations(test); |
| 915 | } |
| 916 | |
| 917 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 918 | LayerProperties::setupHwcSetGeometryCallExpectations(test); |
| 919 | LayerProperties::setupHwcSetSourceCropColorCallExpectations(test); |
| 920 | } |
| 921 | |
| 922 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 923 | LayerProperties::setupHwcSetPerFrameCallExpectations(test); |
| 924 | LayerProperties::setupHwcSetPerFrameColorCallExpectations(test); |
| 925 | } |
| 926 | }; |
| 927 | |
| 928 | template <typename LayerProperties> |
| 929 | struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> { |
| 930 | using Base = BaseLayerVariant<LayerProperties>; |
| 931 | using FlingerLayerType = sp<BufferQueueLayer>; |
| 932 | |
| 933 | static FlingerLayerType createLayer(CompositionTest* test) { |
| 934 | test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID); |
| 935 | |
| 936 | FlingerLayerType layer = |
| 937 | Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 938 | sp<Client> client; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 939 | LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer", |
| 940 | LayerProperties::WIDTH, LayerProperties::HEIGHT, |
| 941 | LayerProperties::LAYER_FLAGS, LayerMetadata()); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 942 | args.textureName = test->mFlinger.mutableTexturePool().back(); |
| 943 | return new BufferQueueLayer(args); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 944 | }); |
| 945 | |
| 946 | LayerProperties::setupLayerState(test, layer); |
| 947 | |
| 948 | return layer; |
| 949 | } |
| 950 | |
| 951 | static void cleanupInjectedLayers(CompositionTest* test) { |
Dominik Laskowski | dd4ef27 | 2020-04-23 14:02:12 -0700 | [diff] [blame] | 952 | EXPECT_CALL(*test->mMessageQueue, postMessage(_)).Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 953 | Base::cleanupInjectedLayers(test); |
| 954 | } |
| 955 | |
| 956 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 957 | LayerProperties::setupHwcSetGeometryCallExpectations(test); |
| 958 | LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test); |
| 959 | } |
| 960 | |
| 961 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 962 | LayerProperties::setupHwcSetPerFrameCallExpectations(test); |
| 963 | LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test); |
| 964 | } |
| 965 | |
| 966 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
| 967 | LayerProperties::setupREBufferCompositionCallExpectations(test); |
| 968 | } |
| 969 | |
| 970 | static void setupInsecureRECompositionCallExpectations(CompositionTest* test) { |
| 971 | LayerProperties::setupInsecureREBufferCompositionCallExpectations(test); |
| 972 | } |
| 973 | |
| 974 | static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 975 | LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test); |
| 976 | } |
| 977 | |
| 978 | static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 979 | LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test); |
| 980 | } |
| 981 | }; |
| 982 | |
| 983 | /* ------------------------------------------------------------------------ |
| 984 | * Variants to control how the composition type is changed |
| 985 | */ |
| 986 | |
| 987 | struct NoCompositionTypeVariant { |
| 988 | static void setupHwcSetCallExpectations(CompositionTest*) {} |
| 989 | |
| 990 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 991 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1); |
| 992 | } |
| 993 | }; |
| 994 | |
| 995 | template <IComposerClient::Composition CompositionType> |
| 996 | struct KeepCompositionTypeVariant { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 997 | static constexpr hal::Composition TYPE = CompositionType; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 998 | |
| 999 | static void setupHwcSetCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1000 | if (!test->mDisplayOff) { |
| 1001 | EXPECT_CALL(*test->mComposer, |
| 1002 | setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType)) |
| 1003 | .Times(1); |
| 1004 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 1008 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1); |
| 1009 | } |
| 1010 | }; |
| 1011 | |
| 1012 | template <IComposerClient::Composition InitialCompositionType, |
| 1013 | IComposerClient::Composition FinalCompositionType> |
| 1014 | struct ChangeCompositionTypeVariant { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 1015 | static constexpr hal::Composition TYPE = FinalCompositionType; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1016 | |
| 1017 | static void setupHwcSetCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1018 | if (!test->mDisplayOff) { |
| 1019 | EXPECT_CALL(*test->mComposer, |
| 1020 | setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType)) |
| 1021 | .Times(1); |
| 1022 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 1026 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)) |
| 1027 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{ |
| 1028 | static_cast<Hwc2::Layer>(HWC_LAYER)}), |
| 1029 | SetArgPointee<2>(std::vector<IComposerClient::Composition>{ |
| 1030 | FinalCompositionType}), |
| 1031 | Return(Error::NONE))); |
| 1032 | } |
| 1033 | }; |
| 1034 | |
| 1035 | /* ------------------------------------------------------------------------ |
| 1036 | * Variants to select how the composition is expected to be handled |
| 1037 | */ |
| 1038 | |
| 1039 | struct CompositionResultBaseVariant { |
| 1040 | static void setupLayerState(CompositionTest*, sp<Layer>) {} |
| 1041 | |
| 1042 | template <typename Case> |
| 1043 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 1044 | Case::Layer::setupCallExpectationsForDirtyGeometry(test); |
| 1045 | } |
| 1046 | |
| 1047 | template <typename Case> |
| 1048 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 1049 | Case::Layer::setupCallExpectationsForDirtyFrame(test); |
| 1050 | } |
| 1051 | }; |
| 1052 | |
| 1053 | struct NoCompositionResultVariant : public CompositionResultBaseVariant { |
| 1054 | template <typename Case> |
| 1055 | static void setupCallExpectations(CompositionTest* test) { |
| 1056 | Case::Display::setupEmptyFrameCompositionCallExpectations(test); |
| 1057 | Case::Display::setupHwcCompositionCallExpectations(test); |
| 1058 | } |
| 1059 | }; |
| 1060 | |
| 1061 | struct HwcCompositionResultVariant : public CompositionResultBaseVariant { |
| 1062 | template <typename Case> |
| 1063 | static void setupCallExpectations(CompositionTest* test) { |
| 1064 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1065 | Case::Display::setupHwcCompositionCallExpectations(test); |
| 1066 | } |
| 1067 | }; |
| 1068 | |
| 1069 | struct RECompositionResultVariant : public CompositionResultBaseVariant { |
| 1070 | template <typename Case> |
| 1071 | static void setupCallExpectations(CompositionTest* test) { |
| 1072 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1073 | Case::Display::setupHwcClientCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1074 | Case::Display::setupRECompositionCallExpectations(test); |
| 1075 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1076 | } |
| 1077 | }; |
| 1078 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1079 | struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1080 | static void setupLayerState(CompositionTest* test, sp<Layer> layer) { |
Dominik Laskowski | b7251f4 | 2020-04-20 17:42:59 -0700 | [diff] [blame] | 1081 | const auto outputLayer = |
| 1082 | TestableSurfaceFlinger::findOutputLayerForDisplay(layer, test->mDisplay); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1083 | LOG_FATAL_IF(!outputLayer); |
| 1084 | outputLayer->editState().forceClientComposition = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | template <typename Case> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1088 | static void setupCallExpectations(CompositionTest* test) { |
| 1089 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1090 | Case::Display::setupHwcForcedClientCompositionCallExpectations(test); |
| 1091 | Case::Display::setupRECompositionCallExpectations(test); |
| 1092 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1093 | } |
| 1094 | |
| 1095 | template <typename Case> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1096 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 1097 | |
| 1098 | template <typename Case> |
| 1099 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 1100 | }; |
| 1101 | |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 1102 | struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant { |
| 1103 | static void setupLayerState(CompositionTest* test, sp<Layer>) { |
| 1104 | test->mFlinger.mutableDebugDisableHWC() = true; |
| 1105 | } |
| 1106 | |
| 1107 | template <typename Case> |
| 1108 | static void setupCallExpectations(CompositionTest* test) { |
| 1109 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1110 | Case::Display::setupHwcForcedClientCompositionCallExpectations(test); |
| 1111 | Case::Display::setupRECompositionCallExpectations(test); |
| 1112 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1113 | } |
| 1114 | |
| 1115 | template <typename Case> |
| 1116 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 1117 | |
| 1118 | template <typename Case> |
| 1119 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 1120 | }; |
| 1121 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1122 | struct EmptyScreenshotResultVariant { |
| 1123 | static void setupLayerState(CompositionTest*, sp<Layer>) {} |
| 1124 | |
| 1125 | template <typename Case> |
| 1126 | static void setupCallExpectations(CompositionTest*) {} |
| 1127 | }; |
| 1128 | |
| 1129 | struct REScreenshotResultVariant : public EmptyScreenshotResultVariant { |
| 1130 | using Base = EmptyScreenshotResultVariant; |
| 1131 | |
| 1132 | template <typename Case> |
| 1133 | static void setupCallExpectations(CompositionTest* test) { |
| 1134 | Base::template setupCallExpectations<Case>(test); |
| 1135 | Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test); |
| 1136 | } |
| 1137 | }; |
| 1138 | |
| 1139 | /* ------------------------------------------------------------------------ |
| 1140 | * Composition test case, containing all the variants being tested |
| 1141 | */ |
| 1142 | |
| 1143 | template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase, |
| 1144 | typename CompositionResultCase> |
| 1145 | struct CompositionCase { |
| 1146 | using ThisCase = |
| 1147 | CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>; |
| 1148 | using Display = DisplayCase; |
| 1149 | using Layer = LayerCase; |
| 1150 | using CompositionType = CompositionTypeCase; |
| 1151 | using CompositionResult = CompositionResultCase; |
| 1152 | |
| 1153 | static void setupCommon(CompositionTest* test) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 1154 | Display::template setupPreconditionCallExpectations<ThisCase>(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1155 | Display::setupPreconditions(test); |
| 1156 | |
| 1157 | auto layer = Layer::createLayer(test); |
| 1158 | Layer::injectLayer(test, layer); |
| 1159 | CompositionResult::setupLayerState(test, layer); |
| 1160 | } |
| 1161 | |
| 1162 | static void setupForDirtyGeometry(CompositionTest* test) { |
| 1163 | setupCommon(test); |
| 1164 | |
| 1165 | Display::template setupCommonCompositionCallExpectations<ThisCase>(test); |
| 1166 | CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test); |
| 1167 | CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test); |
| 1168 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1169 | } |
| 1170 | |
| 1171 | static void setupForDirtyFrame(CompositionTest* test) { |
| 1172 | setupCommon(test); |
| 1173 | |
| 1174 | Display::template setupCommonCompositionCallExpectations<ThisCase>(test); |
| 1175 | CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test); |
| 1176 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1177 | } |
| 1178 | |
| 1179 | static void setupForScreenCapture(CompositionTest* test) { |
| 1180 | setupCommon(test); |
| 1181 | |
| 1182 | Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test); |
| 1183 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1184 | } |
| 1185 | |
| 1186 | static void cleanup(CompositionTest* test) { |
| 1187 | Layer::cleanupInjectedLayers(test); |
| 1188 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 1189 | for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) { |
| 1190 | static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get()) |
| 1191 | ->mutableLayers() |
| 1192 | .clear(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1193 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1194 | } |
| 1195 | }; |
| 1196 | |
| 1197 | /* ------------------------------------------------------------------------ |
| 1198 | * Composition cases to test |
| 1199 | */ |
| 1200 | |
| 1201 | TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) { |
| 1202 | displayRefreshCompositionDirtyGeometry< |
| 1203 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1204 | NoCompositionResultVariant>>(); |
| 1205 | } |
| 1206 | |
| 1207 | TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) { |
| 1208 | displayRefreshCompositionDirtyFrame< |
| 1209 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1210 | NoCompositionResultVariant>>(); |
| 1211 | } |
| 1212 | |
| 1213 | TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) { |
| 1214 | captureScreenComposition< |
| 1215 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1216 | EmptyScreenshotResultVariant>>(); |
| 1217 | } |
| 1218 | |
| 1219 | /* ------------------------------------------------------------------------ |
| 1220 | * Simple buffer layers |
| 1221 | */ |
| 1222 | |
| 1223 | TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) { |
| 1224 | displayRefreshCompositionDirtyGeometry< |
| 1225 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1226 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1227 | HwcCompositionResultVariant>>(); |
| 1228 | } |
| 1229 | |
| 1230 | TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) { |
| 1231 | displayRefreshCompositionDirtyFrame< |
| 1232 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1233 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1234 | HwcCompositionResultVariant>>(); |
| 1235 | } |
| 1236 | |
| 1237 | TEST_F(CompositionTest, REComposedNormalBufferLayer) { |
| 1238 | displayRefreshCompositionDirtyFrame< |
| 1239 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1240 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1241 | IComposerClient::Composition::CLIENT>, |
| 1242 | RECompositionResultVariant>>(); |
| 1243 | } |
| 1244 | |
| 1245 | TEST_F(CompositionTest, captureScreenNormalBufferLayer) { |
| 1246 | captureScreenComposition< |
| 1247 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1248 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1249 | } |
| 1250 | |
| 1251 | /* ------------------------------------------------------------------------ |
| 1252 | * Single-color layers |
| 1253 | */ |
| 1254 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1255 | TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyGeometry) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1256 | displayRefreshCompositionDirtyGeometry< |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1257 | CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>, |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1258 | KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>, |
| 1259 | HwcCompositionResultVariant>>(); |
| 1260 | } |
| 1261 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1262 | TEST_F(CompositionTest, HWCComposedEffectLayerWithDirtyFrame) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1263 | displayRefreshCompositionDirtyFrame< |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1264 | CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>, |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1265 | KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>, |
| 1266 | HwcCompositionResultVariant>>(); |
| 1267 | } |
| 1268 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1269 | TEST_F(CompositionTest, REComposedEffectLayer) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1270 | displayRefreshCompositionDirtyFrame< |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1271 | CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>, |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1272 | ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR, |
| 1273 | IComposerClient::Composition::CLIENT>, |
| 1274 | RECompositionResultVariant>>(); |
| 1275 | } |
| 1276 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1277 | TEST_F(CompositionTest, captureScreenEffectLayer) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1278 | captureScreenComposition< |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 1279 | CompositionCase<DefaultDisplaySetupVariant, EffectLayerVariant<EffectLayerProperties>, |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1280 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1281 | } |
| 1282 | |
| 1283 | /* ------------------------------------------------------------------------ |
| 1284 | * Layers with sideband buffers |
| 1285 | */ |
| 1286 | |
| 1287 | TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) { |
| 1288 | displayRefreshCompositionDirtyGeometry< |
| 1289 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1290 | KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>, |
| 1291 | HwcCompositionResultVariant>>(); |
| 1292 | } |
| 1293 | |
| 1294 | TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) { |
| 1295 | displayRefreshCompositionDirtyFrame< |
| 1296 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1297 | KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>, |
| 1298 | HwcCompositionResultVariant>>(); |
| 1299 | } |
| 1300 | |
| 1301 | TEST_F(CompositionTest, REComposedSidebandBufferLayer) { |
| 1302 | displayRefreshCompositionDirtyFrame< |
| 1303 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1304 | ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND, |
| 1305 | IComposerClient::Composition::CLIENT>, |
| 1306 | RECompositionResultVariant>>(); |
| 1307 | } |
| 1308 | |
| 1309 | TEST_F(CompositionTest, captureScreenSidebandBufferLayer) { |
| 1310 | captureScreenComposition< |
| 1311 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1312 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1313 | } |
| 1314 | |
| 1315 | /* ------------------------------------------------------------------------ |
| 1316 | * Layers with ISurfaceComposerClient::eSecure, on a secure display |
| 1317 | */ |
| 1318 | |
| 1319 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) { |
| 1320 | displayRefreshCompositionDirtyGeometry< |
| 1321 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1322 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1323 | HwcCompositionResultVariant>>(); |
| 1324 | } |
| 1325 | |
| 1326 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) { |
| 1327 | displayRefreshCompositionDirtyFrame< |
| 1328 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1329 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1330 | HwcCompositionResultVariant>>(); |
| 1331 | } |
| 1332 | |
| 1333 | TEST_F(CompositionTest, REComposedSecureBufferLayer) { |
| 1334 | displayRefreshCompositionDirtyFrame< |
| 1335 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1336 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1337 | IComposerClient::Composition::CLIENT>, |
| 1338 | RECompositionResultVariant>>(); |
| 1339 | } |
| 1340 | |
| 1341 | TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) { |
| 1342 | captureScreenComposition< |
| 1343 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1344 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1345 | } |
| 1346 | |
| 1347 | /* ------------------------------------------------------------------------ |
| 1348 | * Layers with ISurfaceComposerClient::eSecure, on a non-secure display |
| 1349 | */ |
| 1350 | |
| 1351 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) { |
| 1352 | displayRefreshCompositionDirtyGeometry< |
| 1353 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1354 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1355 | ForcedClientCompositionResultVariant>>(); |
| 1356 | } |
| 1357 | |
| 1358 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) { |
| 1359 | displayRefreshCompositionDirtyFrame< |
| 1360 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1361 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1362 | ForcedClientCompositionResultVariant>>(); |
| 1363 | } |
| 1364 | |
| 1365 | TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) { |
| 1366 | captureScreenComposition< |
| 1367 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1368 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1369 | } |
| 1370 | |
| 1371 | /* ------------------------------------------------------------------------ |
| 1372 | * Cursor layers |
| 1373 | */ |
| 1374 | |
| 1375 | TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) { |
| 1376 | displayRefreshCompositionDirtyGeometry< |
| 1377 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1378 | KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>, |
| 1379 | HwcCompositionResultVariant>>(); |
| 1380 | } |
| 1381 | |
| 1382 | TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) { |
| 1383 | displayRefreshCompositionDirtyFrame< |
| 1384 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1385 | KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>, |
| 1386 | HwcCompositionResultVariant>>(); |
| 1387 | } |
| 1388 | |
| 1389 | TEST_F(CompositionTest, REComposedCursorLayer) { |
| 1390 | displayRefreshCompositionDirtyFrame< |
| 1391 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1392 | ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR, |
| 1393 | IComposerClient::Composition::CLIENT>, |
| 1394 | RECompositionResultVariant>>(); |
| 1395 | } |
| 1396 | |
| 1397 | TEST_F(CompositionTest, captureScreenCursorLayer) { |
| 1398 | captureScreenComposition< |
| 1399 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1400 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1401 | } |
| 1402 | |
| 1403 | /* ------------------------------------------------------------------------ |
| 1404 | * Simple buffer layer on a display which is powered off. |
| 1405 | */ |
| 1406 | |
| 1407 | TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1408 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1409 | displayRefreshCompositionDirtyGeometry<CompositionCase< |
| 1410 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1411 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1412 | HwcCompositionResultVariant>>(); |
| 1413 | } |
| 1414 | |
| 1415 | TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1416 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1417 | displayRefreshCompositionDirtyFrame<CompositionCase< |
| 1418 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1419 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1420 | HwcCompositionResultVariant>>(); |
| 1421 | } |
| 1422 | |
| 1423 | TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1424 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1425 | displayRefreshCompositionDirtyFrame<CompositionCase< |
| 1426 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1427 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1428 | IComposerClient::Composition::CLIENT>, |
| 1429 | RECompositionResultVariant>>(); |
| 1430 | } |
| 1431 | |
| 1432 | TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) { |
| 1433 | captureScreenComposition<CompositionCase< |
| 1434 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1435 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1436 | } |
| 1437 | |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 1438 | /* ------------------------------------------------------------------------ |
| 1439 | * Client composition forced through debug/developer settings |
| 1440 | */ |
| 1441 | |
| 1442 | TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) { |
| 1443 | displayRefreshCompositionDirtyGeometry< |
| 1444 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1445 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1446 | ForcedClientCompositionViaDebugOptionResultVariant>>(); |
| 1447 | } |
| 1448 | |
| 1449 | TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) { |
| 1450 | displayRefreshCompositionDirtyFrame< |
| 1451 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1452 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1453 | ForcedClientCompositionViaDebugOptionResultVariant>>(); |
| 1454 | } |
| 1455 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1456 | } // namespace |
| 1457 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1458 | |
| 1459 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1460 | #pragma clang diagnostic pop // ignored "-Wconversion" |