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