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