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