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