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