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