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" |
| 38 | #include "ColorLayer.h" |
| 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, |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 331 | const std::vector<renderengine::LayerSettings>&, ANativeWindowBuffer*, |
| 332 | const bool, base::unique_fd&&, 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, |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 380 | const std::vector<renderengine::LayerSettings>&, ANativeWindowBuffer*, |
| 381 | const bool, base::unique_fd&&, base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 382 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 383 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 384 | displaySettings.physicalDisplay); |
| 385 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 386 | displaySettings.clip); |
| 387 | EXPECT_EQ(ui::Dataspace::UNKNOWN, displaySettings.outputDataspace); |
| 388 | return NO_ERROR; |
| 389 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | template <typename Case> |
| 393 | static void setupRELayerCompositionCallExpectations(CompositionTest* test) { |
| 394 | Case::Layer::setupRECompositionCallExpectations(test); |
| 395 | } |
| 396 | |
| 397 | template <typename Case> |
| 398 | static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 399 | Case::Layer::setupREScreenshotCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 400 | } |
| 401 | }; |
| 402 | |
| 403 | struct DefaultDisplaySetupVariant : public BaseDisplayVariant<DefaultDisplaySetupVariant> {}; |
| 404 | |
| 405 | struct InsecureDisplaySetupVariant : public BaseDisplayVariant<InsecureDisplaySetupVariant> { |
| 406 | static constexpr bool IS_SECURE = false; |
| 407 | |
| 408 | template <typename Case> |
| 409 | static void setupRELayerCompositionCallExpectations(CompositionTest* test) { |
| 410 | Case::Layer::setupInsecureRECompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | template <typename Case> |
| 414 | static void setupRELayerScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 415 | Case::Layer::setupInsecureREScreenshotCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 416 | } |
| 417 | }; |
| 418 | |
| 419 | struct PoweredOffDisplaySetupVariant : public BaseDisplayVariant<PoweredOffDisplaySetupVariant> { |
| 420 | static constexpr int INIT_POWER_MODE = HWC_POWER_MODE_OFF; |
| 421 | |
| 422 | template <typename Case> |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 423 | static void setupPreconditionCallExpectations(CompositionTest*) {} |
| 424 | |
| 425 | template <typename Case> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 426 | static void setupCommonCompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 427 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
| 428 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 429 | // TODO: This seems like an unnecessary call if display is powered off. |
| 430 | EXPECT_CALL(*test->mComposer, |
| 431 | setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY)) |
| 432 | .Times(1); |
| 433 | |
| 434 | // TODO: This seems like an unnecessary call if display is powered off. |
| 435 | Case::CompositionType::setupHwcSetCallExpectations(test); |
| 436 | } |
| 437 | |
| 438 | static void setupHwcCompositionCallExpectations(CompositionTest*) {} |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 439 | static void setupHwcClientCompositionCallExpectations(CompositionTest*) {} |
| 440 | static void setupHwcForcedClientCompositionCallExpectations(CompositionTest*) {} |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 441 | |
| 442 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | 86fa3db | 2019-02-04 18:46:01 -0800 | [diff] [blame] | 443 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
| 444 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 445 | // TODO: This seems like an unnecessary call if display is powered off. |
| 446 | EXPECT_CALL(*test->mDisplaySurface, getClientTargetAcquireFence()) |
| 447 | .WillRepeatedly(ReturnRef(test->mClientTargetAcquireFence)); |
| 448 | } |
| 449 | |
| 450 | template <typename Case> |
| 451 | static void setupRELayerCompositionCallExpectations(CompositionTest*) {} |
| 452 | }; |
| 453 | |
| 454 | /* ------------------------------------------------------------------------ |
| 455 | * Variants for each layer configuration which can be tested |
| 456 | */ |
| 457 | |
| 458 | template <typename LayerProperties> |
| 459 | struct BaseLayerProperties { |
| 460 | static constexpr uint32_t WIDTH = 100; |
| 461 | static constexpr uint32_t HEIGHT = 100; |
| 462 | static constexpr PixelFormat FORMAT = PIXEL_FORMAT_RGBA_8888; |
| 463 | static constexpr uint64_t USAGE = |
| 464 | GraphicBuffer::USAGE_SW_READ_NEVER | GraphicBuffer::USAGE_SW_WRITE_NEVER; |
| 465 | static constexpr android_dataspace DATASPACE = HAL_DATASPACE_UNKNOWN; |
| 466 | static constexpr uint32_t SCALING_MODE = 0; |
| 467 | static constexpr uint32_t TRANSFORM = 0; |
| 468 | static constexpr uint32_t LAYER_FLAGS = 0; |
| 469 | static constexpr float COLOR[] = {1.f, 1.f, 1.f, 1.f}; |
| 470 | static constexpr IComposerClient::BlendMode BLENDMODE = |
| 471 | IComposerClient::BlendMode::PREMULTIPLIED; |
| 472 | |
| 473 | static void enqueueBuffer(CompositionTest*, sp<BufferQueueLayer> layer) { |
| 474 | auto producer = layer->getProducer(); |
| 475 | |
| 476 | IGraphicBufferProducer::QueueBufferOutput qbo; |
| 477 | status_t result = producer->connect(nullptr, NATIVE_WINDOW_API_EGL, false, &qbo); |
| 478 | if (result != NO_ERROR) { |
| 479 | ALOGE("Failed to connect() (%d)", result); |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | int slot; |
| 484 | sp<Fence> fence; |
| 485 | result = producer->dequeueBuffer(&slot, &fence, LayerProperties::WIDTH, |
| 486 | LayerProperties::HEIGHT, LayerProperties::FORMAT, |
| 487 | LayerProperties::USAGE, nullptr, nullptr); |
| 488 | if (result != IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) { |
| 489 | ALOGE("Failed to dequeueBuffer() (%d)", result); |
| 490 | return; |
| 491 | } |
| 492 | |
| 493 | sp<GraphicBuffer> buffer; |
| 494 | result = producer->requestBuffer(slot, &buffer); |
| 495 | if (result != NO_ERROR) { |
| 496 | ALOGE("Failed to requestBuffer() (%d)", result); |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | IGraphicBufferProducer::QueueBufferInput qbi(systemTime(), false /* isAutoTimestamp */, |
| 501 | LayerProperties::DATASPACE, |
| 502 | Rect(LayerProperties::WIDTH, |
| 503 | LayerProperties::HEIGHT), |
| 504 | LayerProperties::SCALING_MODE, |
| 505 | LayerProperties::TRANSFORM, Fence::NO_FENCE); |
| 506 | result = producer->queueBuffer(slot, qbi, &qbo); |
| 507 | if (result != NO_ERROR) { |
| 508 | ALOGE("Failed to queueBuffer (%d)", result); |
| 509 | return; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | static void setupLatchedBuffer(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 514 | // TODO: Eliminate the complexity of actually creating a buffer |
| 515 | EXPECT_CALL(*test->mRenderEngine, getMaxTextureSize()).WillOnce(Return(16384)); |
| 516 | EXPECT_CALL(*test->mRenderEngine, getMaxViewportDims()).WillOnce(Return(16384)); |
| 517 | status_t err = |
| 518 | layer->setDefaultBufferProperties(LayerProperties::WIDTH, LayerProperties::HEIGHT, |
| 519 | LayerProperties::FORMAT); |
| 520 | ASSERT_EQ(NO_ERROR, err); |
| 521 | Mock::VerifyAndClear(test->mRenderEngine); |
| 522 | |
| 523 | EXPECT_CALL(*test->mMessageQueue, invalidate()).Times(1); |
| 524 | enqueueBuffer(test, layer); |
| 525 | Mock::VerifyAndClear(test->mMessageQueue); |
| 526 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 527 | EXPECT_CALL(*test->mRenderEngine, useNativeFenceSync()).WillRepeatedly(Return(true)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 528 | bool ignoredRecomputeVisibleRegions; |
Dominik Laskowski | a8955dd | 2019-07-10 10:19:09 -0700 | [diff] [blame] | 529 | layer->latchBuffer(ignoredRecomputeVisibleRegions, 0, 0); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 530 | Mock::VerifyAndClear(test->mRenderEngine); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 534 | setupLatchedBuffer(test, layer); |
| 535 | } |
| 536 | |
| 537 | static void setupBufferLayerPostFrameCallExpectations(CompositionTest* test) { |
| 538 | // BufferLayer::onPostComposition(), when there is no present fence |
| 539 | EXPECT_CALL(*test->mComposer, getActiveConfig(HWC_DISPLAY, _)) |
| 540 | .WillOnce(DoAll(SetArgPointee<1>(DEFAULT_CONFIG_ID), Return(Error::NONE))); |
| 541 | } |
| 542 | |
| 543 | static void setupHwcSetGeometryCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 544 | if (!test->mDisplayOff) { |
| 545 | // TODO: Coverage of other values |
| 546 | EXPECT_CALL(*test->mComposer, |
| 547 | setLayerBlendMode(HWC_DISPLAY, HWC_LAYER, LayerProperties::BLENDMODE)) |
| 548 | .Times(1); |
| 549 | // TODO: Coverage of other values for origin |
| 550 | EXPECT_CALL(*test->mComposer, |
| 551 | setLayerDisplayFrame(HWC_DISPLAY, HWC_LAYER, |
| 552 | IComposerClient::Rect({0, 0, LayerProperties::WIDTH, |
| 553 | LayerProperties::HEIGHT}))) |
| 554 | .Times(1); |
| 555 | EXPECT_CALL(*test->mComposer, |
| 556 | setLayerPlaneAlpha(HWC_DISPLAY, HWC_LAYER, LayerProperties::COLOR[3])) |
| 557 | .Times(1); |
| 558 | // TODO: Coverage of other values |
| 559 | EXPECT_CALL(*test->mComposer, setLayerZOrder(HWC_DISPLAY, HWC_LAYER, 0u)).Times(1); |
| 560 | // TODO: Coverage of other values |
| 561 | 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] | 562 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 563 | // These expectations retire on saturation as the code path these |
| 564 | // expectations are for appears to make an extra call to them. |
| 565 | // TODO: Investigate this extra call |
| 566 | EXPECT_CALL(*test->mComposer, |
| 567 | setLayerTransform(HWC_DISPLAY, HWC_LAYER, DEFAULT_TRANSFORM)) |
| 568 | .Times(AtLeast(1)) |
| 569 | .RetiresOnSaturation(); |
| 570 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 574 | if (!test->mDisplayOff) { |
| 575 | EXPECT_CALL(*test->mComposer, |
| 576 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 577 | IComposerClient::FRect({0.f, 0.f, LayerProperties::WIDTH, |
| 578 | LayerProperties::HEIGHT}))) |
| 579 | .Times(1); |
| 580 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static void setupHwcSetSourceCropColorCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 584 | if (!test->mDisplayOff) { |
| 585 | EXPECT_CALL(*test->mComposer, |
| 586 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 587 | IComposerClient::FRect({0.f, 0.f, 0.f, 0.f}))) |
| 588 | .Times(1); |
| 589 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static void setupHwcSetPerFrameCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 593 | if (!test->mDisplayOff) { |
| 594 | EXPECT_CALL(*test->mComposer, |
| 595 | setLayerVisibleRegion(HWC_DISPLAY, HWC_LAYER, |
| 596 | std::vector<IComposerClient::Rect>( |
| 597 | {IComposerClient::Rect( |
| 598 | {0, 0, LayerProperties::WIDTH, |
| 599 | LayerProperties::HEIGHT})}))) |
| 600 | .Times(1); |
| 601 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void setupHwcSetPerFrameColorCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 605 | if (!test->mDisplayOff) { |
| 606 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)) |
| 607 | .Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 608 | |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 609 | // TODO: use COLOR |
| 610 | EXPECT_CALL(*test->mComposer, |
| 611 | setLayerColor(HWC_DISPLAY, HWC_LAYER, |
| 612 | IComposerClient::Color({0xff, 0xff, 0xff, 0xff}))) |
| 613 | .Times(1); |
| 614 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 618 | if (!test->mDisplayOff) { |
| 619 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)) |
| 620 | .Times(1); |
| 621 | EXPECT_CALL(*test->mComposer, setLayerBuffer(HWC_DISPLAY, HWC_LAYER, _, _, _)).Times(1); |
| 622 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 623 | |
| 624 | setupBufferLayerPostFrameCallExpectations(test); |
| 625 | } |
| 626 | |
| 627 | static void setupREBufferCompositionCommonCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 628 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 629 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
| 630 | const std::vector<renderengine::LayerSettings>& layerSettings, |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 631 | ANativeWindowBuffer*, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 632 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 633 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 634 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 635 | displaySettings.physicalDisplay); |
| 636 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 637 | displaySettings.clip); |
| 638 | // screen capture adds an additional color layer as an alpha |
| 639 | // prefill, so gtet the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 640 | if (layerSettings.empty()) { |
| 641 | ADD_FAILURE() << "layerSettings was not expected to be empty in " |
| 642 | "setupREBufferCompositionCommonCallExpectations " |
| 643 | "verification lambda"; |
| 644 | return NO_ERROR; |
| 645 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 646 | renderengine::LayerSettings layer = layerSettings.back(); |
| 647 | EXPECT_THAT(layer.source.buffer.buffer, Not(IsNull())); |
| 648 | EXPECT_THAT(layer.source.buffer.fence, Not(IsNull())); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 649 | EXPECT_EQ(DEFAULT_TEXTURE_ID, layer.source.buffer.textureName); |
| 650 | EXPECT_EQ(false, layer.source.buffer.isY410BT2020); |
| 651 | EXPECT_EQ(true, layer.source.buffer.usePremultipliedAlpha); |
| 652 | EXPECT_EQ(false, layer.source.buffer.isOpaque); |
| 653 | EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius); |
| 654 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace); |
| 655 | EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha); |
| 656 | return NO_ERROR; |
| 657 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static void setupREBufferCompositionCallExpectations(CompositionTest* test) { |
| 661 | LayerProperties::setupREBufferCompositionCommonCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) { |
| 665 | setupREBufferCompositionCallExpectations(test); |
| 666 | } |
| 667 | |
| 668 | static void setupREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 669 | LayerProperties::setupREBufferCompositionCommonCallExpectations(test); |
| 670 | } |
| 671 | |
| 672 | static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 673 | LayerProperties::setupREBufferCompositionCommonCallExpectations(test); |
| 674 | } |
| 675 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 676 | static void setupREColorCompositionCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 677 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 678 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
| 679 | const std::vector<renderengine::LayerSettings>& layerSettings, |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 680 | ANativeWindowBuffer*, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 681 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 682 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 683 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 684 | displaySettings.physicalDisplay); |
| 685 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 686 | displaySettings.clip); |
| 687 | // screen capture adds an additional color layer as an alpha |
| 688 | // prefill, so get the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 689 | if (layerSettings.empty()) { |
| 690 | ADD_FAILURE() |
| 691 | << "layerSettings was not expected to be empty in " |
| 692 | "setupREColorCompositionCallExpectations verification lambda"; |
| 693 | return NO_ERROR; |
| 694 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 695 | renderengine::LayerSettings layer = layerSettings.back(); |
| 696 | EXPECT_THAT(layer.source.buffer.buffer, IsNull()); |
| 697 | EXPECT_EQ(half3(LayerProperties::COLOR[0], LayerProperties::COLOR[1], |
| 698 | LayerProperties::COLOR[2]), |
| 699 | layer.source.solidColor); |
| 700 | EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius); |
| 701 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace); |
| 702 | EXPECT_EQ(LayerProperties::COLOR[3], layer.alpha); |
| 703 | return NO_ERROR; |
| 704 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | static void setupREColorScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 708 | setupREColorCompositionCallExpectations(test); |
| 709 | } |
| 710 | }; |
| 711 | |
| 712 | struct DefaultLayerProperties : public BaseLayerProperties<DefaultLayerProperties> {}; |
| 713 | |
| 714 | struct ColorLayerProperties : public BaseLayerProperties<ColorLayerProperties> {}; |
| 715 | |
| 716 | struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> { |
| 717 | using Base = BaseLayerProperties<SidebandLayerProperties>; |
| 718 | static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE; |
| 719 | |
| 720 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 721 | sp<NativeHandle> stream = |
| 722 | NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM), |
| 723 | false); |
| 724 | test->mFlinger.setLayerSidebandStream(layer, stream); |
| 725 | } |
| 726 | |
| 727 | static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) { |
| 728 | EXPECT_CALL(*test->mComposer, |
| 729 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 730 | IComposerClient::FRect({0.f, 0.f, -1.f, -1.f}))) |
| 731 | .Times(1); |
| 732 | } |
| 733 | |
| 734 | static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) { |
| 735 | EXPECT_CALL(*test->mComposer, |
| 736 | setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER, |
| 737 | reinterpret_cast<native_handle_t*>( |
| 738 | DEFAULT_SIDEBAND_STREAM))) |
| 739 | .WillOnce(Return(Error::NONE)); |
| 740 | |
| 741 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1); |
| 742 | } |
| 743 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 744 | static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {} |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 745 | }; |
| 746 | |
| 747 | struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> { |
| 748 | using Base = BaseLayerProperties<SecureLayerProperties>; |
| 749 | |
| 750 | static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure; |
| 751 | |
| 752 | static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 753 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 754 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
| 755 | const std::vector<renderengine::LayerSettings>& layerSettings, |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 756 | ANativeWindowBuffer*, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 757 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 758 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 759 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 760 | displaySettings.physicalDisplay); |
| 761 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 762 | displaySettings.clip); |
| 763 | // screen capture adds an additional color layer as an alpha |
| 764 | // prefill, so get the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 765 | if (layerSettings.empty()) { |
| 766 | ADD_FAILURE() << "layerSettings was not expected to be empty in " |
| 767 | "setupInsecureREBufferCompositionCommonCallExpectations " |
| 768 | "verification lambda"; |
| 769 | return NO_ERROR; |
| 770 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 771 | renderengine::LayerSettings layer = layerSettings.back(); |
| 772 | EXPECT_THAT(layer.source.buffer.buffer, IsNull()); |
| 773 | EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer.source.solidColor); |
| 774 | EXPECT_EQ(0.0, layer.geometry.roundedCornersRadius); |
| 775 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer.sourceDataspace); |
| 776 | EXPECT_EQ(1.0f, layer.alpha); |
| 777 | return NO_ERROR; |
| 778 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) { |
| 782 | setupInsecureREBufferCompositionCommonCallExpectations(test); |
| 783 | Base::setupBufferLayerPostFrameCallExpectations(test); |
| 784 | } |
| 785 | |
| 786 | static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 787 | setupInsecureREBufferCompositionCommonCallExpectations(test); |
| 788 | } |
| 789 | }; |
| 790 | |
| 791 | struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> { |
| 792 | using Base = BaseLayerProperties<CursorLayerProperties>; |
| 793 | |
| 794 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 795 | Base::setupLayerState(test, layer); |
| 796 | test->mFlinger.setLayerPotentialCursor(layer, true); |
| 797 | } |
| 798 | }; |
| 799 | |
| 800 | struct NoLayerVariant { |
| 801 | using FlingerLayerType = sp<BufferQueueLayer>; |
| 802 | |
| 803 | static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); } |
| 804 | static void injectLayer(CompositionTest*, FlingerLayerType) {} |
| 805 | static void cleanupInjectedLayers(CompositionTest*) {} |
| 806 | |
| 807 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 808 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 809 | }; |
| 810 | |
| 811 | template <typename LayerProperties> |
| 812 | struct BaseLayerVariant { |
| 813 | template <typename L, typename F> |
| 814 | static sp<L> createLayerWithFactory(CompositionTest* test, F factory) { |
| 815 | EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0); |
| 816 | |
| 817 | sp<L> layer = factory(); |
| 818 | |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 819 | // Layer should be registered with scheduler. |
| 820 | EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize()); |
| 821 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 822 | Mock::VerifyAndClear(test->mComposer); |
| 823 | Mock::VerifyAndClear(test->mRenderEngine); |
| 824 | Mock::VerifyAndClear(test->mMessageQueue); |
| 825 | |
| 826 | auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); |
| 827 | layerDrawingState.layerStack = DEFAULT_LAYER_STACK; |
| 828 | layerDrawingState.active.w = 100; |
| 829 | layerDrawingState.active.h = 100; |
| 830 | layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1], |
| 831 | LayerProperties::COLOR[2], LayerProperties::COLOR[3]); |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 832 | layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 833 | |
| 834 | return layer; |
| 835 | } |
| 836 | |
| 837 | static void injectLayer(CompositionTest* test, sp<Layer> layer) { |
| 838 | EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _)) |
| 839 | .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE))); |
| 840 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 841 | auto outputLayer = test->mDisplay->getCompositionDisplay() |
| 842 | ->injectOutputLayerForTest(layer->getCompositionLayer(), layer); |
| 843 | outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 844 | outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 845 | |
| 846 | Mock::VerifyAndClear(test->mComposer); |
| 847 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 848 | test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer); |
| 849 | } |
| 850 | |
| 851 | static void cleanupInjectedLayers(CompositionTest* test) { |
| 852 | EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER)) |
| 853 | .WillOnce(Return(Error::NONE)); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 854 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 855 | test->mDisplay->getCompositionDisplay()->clearOutputLayers(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 856 | test->mFlinger.mutableDrawingState().layersSortedByZ.clear(); |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 857 | |
| 858 | // Layer should be unregistered with scheduler. |
| 859 | test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE); |
| 860 | EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize()); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 861 | } |
| 862 | }; |
| 863 | |
| 864 | template <typename LayerProperties> |
| 865 | struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> { |
| 866 | using Base = BaseLayerVariant<LayerProperties>; |
| 867 | using FlingerLayerType = sp<ColorLayer>; |
| 868 | |
| 869 | static FlingerLayerType createLayer(CompositionTest* test) { |
| 870 | FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() { |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 871 | return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 872 | "test-layer", LayerProperties::WIDTH, |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 873 | LayerProperties::HEIGHT, |
Evan Rosky | a1f1e15 | 2019-01-24 16:17:46 -0800 | [diff] [blame] | 874 | LayerProperties::LAYER_FLAGS, LayerMetadata())); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 875 | }); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 876 | |
| 877 | auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); |
| 878 | layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 879 | return layer; |
| 880 | } |
| 881 | |
| 882 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 883 | LayerProperties::setupREColorCompositionCallExpectations(test); |
| 884 | } |
| 885 | |
| 886 | static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 887 | LayerProperties::setupREColorScreenshotCompositionCallExpectations(test); |
| 888 | } |
| 889 | |
| 890 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 891 | LayerProperties::setupHwcSetGeometryCallExpectations(test); |
| 892 | LayerProperties::setupHwcSetSourceCropColorCallExpectations(test); |
| 893 | } |
| 894 | |
| 895 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 896 | LayerProperties::setupHwcSetPerFrameCallExpectations(test); |
| 897 | LayerProperties::setupHwcSetPerFrameColorCallExpectations(test); |
| 898 | } |
| 899 | }; |
| 900 | |
| 901 | template <typename LayerProperties> |
| 902 | struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> { |
| 903 | using Base = BaseLayerVariant<LayerProperties>; |
| 904 | using FlingerLayerType = sp<BufferQueueLayer>; |
| 905 | |
| 906 | static FlingerLayerType createLayer(CompositionTest* test) { |
| 907 | test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID); |
| 908 | |
| 909 | FlingerLayerType layer = |
| 910 | Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 911 | sp<Client> client; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 912 | LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer", |
| 913 | LayerProperties::WIDTH, LayerProperties::HEIGHT, |
| 914 | LayerProperties::LAYER_FLAGS, LayerMetadata()); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 915 | args.textureName = test->mFlinger.mutableTexturePool().back(); |
| 916 | return new BufferQueueLayer(args); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 917 | }); |
| 918 | |
| 919 | LayerProperties::setupLayerState(test, layer); |
| 920 | |
| 921 | return layer; |
| 922 | } |
| 923 | |
| 924 | static void cleanupInjectedLayers(CompositionTest* test) { |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 925 | EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 926 | Base::cleanupInjectedLayers(test); |
| 927 | } |
| 928 | |
| 929 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 930 | LayerProperties::setupHwcSetGeometryCallExpectations(test); |
| 931 | LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test); |
| 932 | } |
| 933 | |
| 934 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 935 | LayerProperties::setupHwcSetPerFrameCallExpectations(test); |
| 936 | LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test); |
| 937 | } |
| 938 | |
| 939 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
| 940 | LayerProperties::setupREBufferCompositionCallExpectations(test); |
| 941 | } |
| 942 | |
| 943 | static void setupInsecureRECompositionCallExpectations(CompositionTest* test) { |
| 944 | LayerProperties::setupInsecureREBufferCompositionCallExpectations(test); |
| 945 | } |
| 946 | |
| 947 | static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 948 | LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test); |
| 949 | } |
| 950 | |
| 951 | static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 952 | LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test); |
| 953 | } |
| 954 | }; |
| 955 | |
| 956 | /* ------------------------------------------------------------------------ |
| 957 | * Variants to control how the composition type is changed |
| 958 | */ |
| 959 | |
| 960 | struct NoCompositionTypeVariant { |
| 961 | static void setupHwcSetCallExpectations(CompositionTest*) {} |
| 962 | |
| 963 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 964 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1); |
| 965 | } |
| 966 | }; |
| 967 | |
| 968 | template <IComposerClient::Composition CompositionType> |
| 969 | struct KeepCompositionTypeVariant { |
| 970 | static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType); |
| 971 | |
| 972 | static void setupHwcSetCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 973 | if (!test->mDisplayOff) { |
| 974 | EXPECT_CALL(*test->mComposer, |
| 975 | setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType)) |
| 976 | .Times(1); |
| 977 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 981 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1); |
| 982 | } |
| 983 | }; |
| 984 | |
| 985 | template <IComposerClient::Composition InitialCompositionType, |
| 986 | IComposerClient::Composition FinalCompositionType> |
| 987 | struct ChangeCompositionTypeVariant { |
| 988 | static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType); |
| 989 | |
| 990 | static void setupHwcSetCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 991 | if (!test->mDisplayOff) { |
| 992 | EXPECT_CALL(*test->mComposer, |
| 993 | setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType)) |
| 994 | .Times(1); |
| 995 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 999 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)) |
| 1000 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{ |
| 1001 | static_cast<Hwc2::Layer>(HWC_LAYER)}), |
| 1002 | SetArgPointee<2>(std::vector<IComposerClient::Composition>{ |
| 1003 | FinalCompositionType}), |
| 1004 | Return(Error::NONE))); |
| 1005 | } |
| 1006 | }; |
| 1007 | |
| 1008 | /* ------------------------------------------------------------------------ |
| 1009 | * Variants to select how the composition is expected to be handled |
| 1010 | */ |
| 1011 | |
| 1012 | struct CompositionResultBaseVariant { |
| 1013 | static void setupLayerState(CompositionTest*, sp<Layer>) {} |
| 1014 | |
| 1015 | template <typename Case> |
| 1016 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 1017 | Case::Layer::setupCallExpectationsForDirtyGeometry(test); |
| 1018 | } |
| 1019 | |
| 1020 | template <typename Case> |
| 1021 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 1022 | Case::Layer::setupCallExpectationsForDirtyFrame(test); |
| 1023 | } |
| 1024 | }; |
| 1025 | |
| 1026 | struct NoCompositionResultVariant : public CompositionResultBaseVariant { |
| 1027 | template <typename Case> |
| 1028 | static void setupCallExpectations(CompositionTest* test) { |
| 1029 | Case::Display::setupEmptyFrameCompositionCallExpectations(test); |
| 1030 | Case::Display::setupHwcCompositionCallExpectations(test); |
| 1031 | } |
| 1032 | }; |
| 1033 | |
| 1034 | struct HwcCompositionResultVariant : public CompositionResultBaseVariant { |
| 1035 | template <typename Case> |
| 1036 | static void setupCallExpectations(CompositionTest* test) { |
| 1037 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1038 | Case::Display::setupHwcCompositionCallExpectations(test); |
| 1039 | } |
| 1040 | }; |
| 1041 | |
| 1042 | struct RECompositionResultVariant : public CompositionResultBaseVariant { |
| 1043 | template <typename Case> |
| 1044 | static void setupCallExpectations(CompositionTest* test) { |
| 1045 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1046 | Case::Display::setupHwcClientCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1047 | Case::Display::setupRECompositionCallExpectations(test); |
| 1048 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1049 | } |
| 1050 | }; |
| 1051 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1052 | struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1053 | static void setupLayerState(CompositionTest* test, sp<Layer> layer) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1054 | const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay); |
| 1055 | LOG_FATAL_IF(!outputLayer); |
| 1056 | outputLayer->editState().forceClientComposition = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | template <typename Case> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1060 | static void setupCallExpectations(CompositionTest* test) { |
| 1061 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1062 | Case::Display::setupHwcForcedClientCompositionCallExpectations(test); |
| 1063 | Case::Display::setupRECompositionCallExpectations(test); |
| 1064 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1065 | } |
| 1066 | |
| 1067 | template <typename Case> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1068 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 1069 | |
| 1070 | template <typename Case> |
| 1071 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 1072 | }; |
| 1073 | |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 1074 | struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant { |
| 1075 | static void setupLayerState(CompositionTest* test, sp<Layer>) { |
| 1076 | test->mFlinger.mutableDebugDisableHWC() = true; |
| 1077 | } |
| 1078 | |
| 1079 | template <typename Case> |
| 1080 | static void setupCallExpectations(CompositionTest* test) { |
| 1081 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1082 | Case::Display::setupHwcForcedClientCompositionCallExpectations(test); |
| 1083 | Case::Display::setupRECompositionCallExpectations(test); |
| 1084 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1085 | } |
| 1086 | |
| 1087 | template <typename Case> |
| 1088 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 1089 | |
| 1090 | template <typename Case> |
| 1091 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 1092 | }; |
| 1093 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1094 | struct EmptyScreenshotResultVariant { |
| 1095 | static void setupLayerState(CompositionTest*, sp<Layer>) {} |
| 1096 | |
| 1097 | template <typename Case> |
| 1098 | static void setupCallExpectations(CompositionTest*) {} |
| 1099 | }; |
| 1100 | |
| 1101 | struct REScreenshotResultVariant : public EmptyScreenshotResultVariant { |
| 1102 | using Base = EmptyScreenshotResultVariant; |
| 1103 | |
| 1104 | template <typename Case> |
| 1105 | static void setupCallExpectations(CompositionTest* test) { |
| 1106 | Base::template setupCallExpectations<Case>(test); |
| 1107 | Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test); |
| 1108 | } |
| 1109 | }; |
| 1110 | |
| 1111 | /* ------------------------------------------------------------------------ |
| 1112 | * Composition test case, containing all the variants being tested |
| 1113 | */ |
| 1114 | |
| 1115 | template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase, |
| 1116 | typename CompositionResultCase> |
| 1117 | struct CompositionCase { |
| 1118 | using ThisCase = |
| 1119 | CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>; |
| 1120 | using Display = DisplayCase; |
| 1121 | using Layer = LayerCase; |
| 1122 | using CompositionType = CompositionTypeCase; |
| 1123 | using CompositionResult = CompositionResultCase; |
| 1124 | |
| 1125 | static void setupCommon(CompositionTest* test) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 1126 | Display::template setupPreconditionCallExpectations<ThisCase>(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1127 | Display::setupPreconditions(test); |
| 1128 | |
| 1129 | auto layer = Layer::createLayer(test); |
| 1130 | Layer::injectLayer(test, layer); |
| 1131 | CompositionResult::setupLayerState(test, layer); |
| 1132 | } |
| 1133 | |
| 1134 | static void setupForDirtyGeometry(CompositionTest* test) { |
| 1135 | setupCommon(test); |
| 1136 | |
| 1137 | Display::template setupCommonCompositionCallExpectations<ThisCase>(test); |
| 1138 | CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test); |
| 1139 | CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test); |
| 1140 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1141 | } |
| 1142 | |
| 1143 | static void setupForDirtyFrame(CompositionTest* test) { |
| 1144 | setupCommon(test); |
| 1145 | |
| 1146 | Display::template setupCommonCompositionCallExpectations<ThisCase>(test); |
| 1147 | CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test); |
| 1148 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1149 | } |
| 1150 | |
| 1151 | static void setupForScreenCapture(CompositionTest* test) { |
| 1152 | setupCommon(test); |
| 1153 | |
| 1154 | Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test); |
| 1155 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1156 | } |
| 1157 | |
| 1158 | static void cleanup(CompositionTest* test) { |
| 1159 | Layer::cleanupInjectedLayers(test); |
| 1160 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 1161 | for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) { |
| 1162 | static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get()) |
| 1163 | ->mutableLayers() |
| 1164 | .clear(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1165 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1166 | } |
| 1167 | }; |
| 1168 | |
| 1169 | /* ------------------------------------------------------------------------ |
| 1170 | * Composition cases to test |
| 1171 | */ |
| 1172 | |
| 1173 | TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) { |
| 1174 | displayRefreshCompositionDirtyGeometry< |
| 1175 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1176 | NoCompositionResultVariant>>(); |
| 1177 | } |
| 1178 | |
| 1179 | TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) { |
| 1180 | displayRefreshCompositionDirtyFrame< |
| 1181 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1182 | NoCompositionResultVariant>>(); |
| 1183 | } |
| 1184 | |
| 1185 | TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) { |
| 1186 | captureScreenComposition< |
| 1187 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1188 | EmptyScreenshotResultVariant>>(); |
| 1189 | } |
| 1190 | |
| 1191 | /* ------------------------------------------------------------------------ |
| 1192 | * Simple buffer layers |
| 1193 | */ |
| 1194 | |
| 1195 | TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) { |
| 1196 | displayRefreshCompositionDirtyGeometry< |
| 1197 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1198 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1199 | HwcCompositionResultVariant>>(); |
| 1200 | } |
| 1201 | |
| 1202 | TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) { |
| 1203 | displayRefreshCompositionDirtyFrame< |
| 1204 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1205 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1206 | HwcCompositionResultVariant>>(); |
| 1207 | } |
| 1208 | |
| 1209 | TEST_F(CompositionTest, REComposedNormalBufferLayer) { |
| 1210 | displayRefreshCompositionDirtyFrame< |
| 1211 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1212 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1213 | IComposerClient::Composition::CLIENT>, |
| 1214 | RECompositionResultVariant>>(); |
| 1215 | } |
| 1216 | |
| 1217 | TEST_F(CompositionTest, captureScreenNormalBufferLayer) { |
| 1218 | captureScreenComposition< |
| 1219 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1220 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1221 | } |
| 1222 | |
| 1223 | /* ------------------------------------------------------------------------ |
| 1224 | * Single-color layers |
| 1225 | */ |
| 1226 | |
| 1227 | TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) { |
| 1228 | displayRefreshCompositionDirtyGeometry< |
| 1229 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1230 | KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>, |
| 1231 | HwcCompositionResultVariant>>(); |
| 1232 | } |
| 1233 | |
| 1234 | TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) { |
| 1235 | displayRefreshCompositionDirtyFrame< |
| 1236 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1237 | KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>, |
| 1238 | HwcCompositionResultVariant>>(); |
| 1239 | } |
| 1240 | |
| 1241 | TEST_F(CompositionTest, REComposedColorLayer) { |
| 1242 | displayRefreshCompositionDirtyFrame< |
| 1243 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1244 | ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR, |
| 1245 | IComposerClient::Composition::CLIENT>, |
| 1246 | RECompositionResultVariant>>(); |
| 1247 | } |
| 1248 | |
| 1249 | TEST_F(CompositionTest, captureScreenColorLayer) { |
| 1250 | captureScreenComposition< |
| 1251 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1252 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1253 | } |
| 1254 | |
| 1255 | /* ------------------------------------------------------------------------ |
| 1256 | * Layers with sideband buffers |
| 1257 | */ |
| 1258 | |
| 1259 | TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) { |
| 1260 | displayRefreshCompositionDirtyGeometry< |
| 1261 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1262 | KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>, |
| 1263 | HwcCompositionResultVariant>>(); |
| 1264 | } |
| 1265 | |
| 1266 | TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) { |
| 1267 | displayRefreshCompositionDirtyFrame< |
| 1268 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1269 | KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>, |
| 1270 | HwcCompositionResultVariant>>(); |
| 1271 | } |
| 1272 | |
| 1273 | TEST_F(CompositionTest, REComposedSidebandBufferLayer) { |
| 1274 | displayRefreshCompositionDirtyFrame< |
| 1275 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1276 | ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND, |
| 1277 | IComposerClient::Composition::CLIENT>, |
| 1278 | RECompositionResultVariant>>(); |
| 1279 | } |
| 1280 | |
| 1281 | TEST_F(CompositionTest, captureScreenSidebandBufferLayer) { |
| 1282 | captureScreenComposition< |
| 1283 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1284 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1285 | } |
| 1286 | |
| 1287 | /* ------------------------------------------------------------------------ |
| 1288 | * Layers with ISurfaceComposerClient::eSecure, on a secure display |
| 1289 | */ |
| 1290 | |
| 1291 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) { |
| 1292 | displayRefreshCompositionDirtyGeometry< |
| 1293 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1294 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1295 | HwcCompositionResultVariant>>(); |
| 1296 | } |
| 1297 | |
| 1298 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) { |
| 1299 | displayRefreshCompositionDirtyFrame< |
| 1300 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1301 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1302 | HwcCompositionResultVariant>>(); |
| 1303 | } |
| 1304 | |
| 1305 | TEST_F(CompositionTest, REComposedSecureBufferLayer) { |
| 1306 | displayRefreshCompositionDirtyFrame< |
| 1307 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1308 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1309 | IComposerClient::Composition::CLIENT>, |
| 1310 | RECompositionResultVariant>>(); |
| 1311 | } |
| 1312 | |
| 1313 | TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) { |
| 1314 | captureScreenComposition< |
| 1315 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1316 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1317 | } |
| 1318 | |
| 1319 | /* ------------------------------------------------------------------------ |
| 1320 | * Layers with ISurfaceComposerClient::eSecure, on a non-secure display |
| 1321 | */ |
| 1322 | |
| 1323 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) { |
| 1324 | displayRefreshCompositionDirtyGeometry< |
| 1325 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1326 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1327 | ForcedClientCompositionResultVariant>>(); |
| 1328 | } |
| 1329 | |
| 1330 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) { |
| 1331 | displayRefreshCompositionDirtyFrame< |
| 1332 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1333 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1334 | ForcedClientCompositionResultVariant>>(); |
| 1335 | } |
| 1336 | |
| 1337 | TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) { |
| 1338 | captureScreenComposition< |
| 1339 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1340 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1341 | } |
| 1342 | |
| 1343 | /* ------------------------------------------------------------------------ |
| 1344 | * Cursor layers |
| 1345 | */ |
| 1346 | |
| 1347 | TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) { |
| 1348 | displayRefreshCompositionDirtyGeometry< |
| 1349 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1350 | KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>, |
| 1351 | HwcCompositionResultVariant>>(); |
| 1352 | } |
| 1353 | |
| 1354 | TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) { |
| 1355 | displayRefreshCompositionDirtyFrame< |
| 1356 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1357 | KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>, |
| 1358 | HwcCompositionResultVariant>>(); |
| 1359 | } |
| 1360 | |
| 1361 | TEST_F(CompositionTest, REComposedCursorLayer) { |
| 1362 | displayRefreshCompositionDirtyFrame< |
| 1363 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1364 | ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR, |
| 1365 | IComposerClient::Composition::CLIENT>, |
| 1366 | RECompositionResultVariant>>(); |
| 1367 | } |
| 1368 | |
| 1369 | TEST_F(CompositionTest, captureScreenCursorLayer) { |
| 1370 | captureScreenComposition< |
| 1371 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1372 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1373 | } |
| 1374 | |
| 1375 | /* ------------------------------------------------------------------------ |
| 1376 | * Simple buffer layer on a display which is powered off. |
| 1377 | */ |
| 1378 | |
| 1379 | TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1380 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1381 | displayRefreshCompositionDirtyGeometry<CompositionCase< |
| 1382 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1383 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1384 | HwcCompositionResultVariant>>(); |
| 1385 | } |
| 1386 | |
| 1387 | TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1388 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1389 | displayRefreshCompositionDirtyFrame<CompositionCase< |
| 1390 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1391 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1392 | HwcCompositionResultVariant>>(); |
| 1393 | } |
| 1394 | |
| 1395 | TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1396 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1397 | displayRefreshCompositionDirtyFrame<CompositionCase< |
| 1398 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1399 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1400 | IComposerClient::Composition::CLIENT>, |
| 1401 | RECompositionResultVariant>>(); |
| 1402 | } |
| 1403 | |
| 1404 | TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) { |
| 1405 | captureScreenComposition<CompositionCase< |
| 1406 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1407 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1408 | } |
| 1409 | |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 1410 | /* ------------------------------------------------------------------------ |
| 1411 | * Client composition forced through debug/developer settings |
| 1412 | */ |
| 1413 | |
| 1414 | TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) { |
| 1415 | displayRefreshCompositionDirtyGeometry< |
| 1416 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1417 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1418 | ForcedClientCompositionViaDebugOptionResultVariant>>(); |
| 1419 | } |
| 1420 | |
| 1421 | TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) { |
| 1422 | displayRefreshCompositionDirtyFrame< |
| 1423 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1424 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1425 | ForcedClientCompositionViaDebugOptionResultVariant>>(); |
| 1426 | } |
| 1427 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1428 | } // namespace |
| 1429 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1430 | |
| 1431 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1432 | #pragma clang diagnostic pop // ignored "-Wconversion" |