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