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