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