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