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