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, |
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 | |
| 716 | struct ColorLayerProperties : public BaseLayerProperties<ColorLayerProperties> {}; |
| 717 | |
| 718 | struct SidebandLayerProperties : public BaseLayerProperties<SidebandLayerProperties> { |
| 719 | using Base = BaseLayerProperties<SidebandLayerProperties>; |
| 720 | static constexpr IComposerClient::BlendMode BLENDMODE = IComposerClient::BlendMode::NONE; |
| 721 | |
| 722 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 723 | sp<NativeHandle> stream = |
| 724 | NativeHandle::create(reinterpret_cast<native_handle_t*>(DEFAULT_SIDEBAND_STREAM), |
| 725 | false); |
| 726 | test->mFlinger.setLayerSidebandStream(layer, stream); |
| 727 | } |
| 728 | |
| 729 | static void setupHwcSetSourceCropBufferCallExpectations(CompositionTest* test) { |
| 730 | EXPECT_CALL(*test->mComposer, |
| 731 | setLayerSourceCrop(HWC_DISPLAY, HWC_LAYER, |
| 732 | IComposerClient::FRect({0.f, 0.f, -1.f, -1.f}))) |
| 733 | .Times(1); |
| 734 | } |
| 735 | |
| 736 | static void setupHwcSetPerFrameBufferCallExpectations(CompositionTest* test) { |
| 737 | EXPECT_CALL(*test->mComposer, |
| 738 | setLayerSidebandStream(HWC_DISPLAY, HWC_LAYER, |
| 739 | reinterpret_cast<native_handle_t*>( |
| 740 | DEFAULT_SIDEBAND_STREAM))) |
| 741 | .WillOnce(Return(Error::NONE)); |
| 742 | |
| 743 | EXPECT_CALL(*test->mComposer, setLayerSurfaceDamage(HWC_DISPLAY, HWC_LAYER, _)).Times(1); |
| 744 | } |
| 745 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 746 | static void setupREBufferCompositionCommonCallExpectations(CompositionTest* /*test*/) {} |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 747 | }; |
| 748 | |
| 749 | struct SecureLayerProperties : public BaseLayerProperties<SecureLayerProperties> { |
| 750 | using Base = BaseLayerProperties<SecureLayerProperties>; |
| 751 | |
| 752 | static constexpr uint32_t LAYER_FLAGS = ISurfaceComposerClient::eSecure; |
| 753 | |
| 754 | static void setupInsecureREBufferCompositionCommonCallExpectations(CompositionTest* test) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 755 | EXPECT_CALL(*test->mRenderEngine, drawLayers) |
| 756 | .WillOnce([](const renderengine::DisplaySettings& displaySettings, |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 757 | const std::vector<const renderengine::LayerSettings*>& layerSettings, |
Alec Mouri | fe0d72b | 2019-03-21 14:05:56 -0700 | [diff] [blame] | 758 | ANativeWindowBuffer*, const bool, base::unique_fd&&, |
Alec Mouri | 6338c9d | 2019-02-07 16:57:51 -0800 | [diff] [blame] | 759 | base::unique_fd*) -> status_t { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 760 | EXPECT_EQ(DEFAULT_DISPLAY_MAX_LUMINANCE, displaySettings.maxLuminance); |
| 761 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 762 | displaySettings.physicalDisplay); |
| 763 | EXPECT_EQ(Rect(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT), |
| 764 | displaySettings.clip); |
| 765 | // screen capture adds an additional color layer as an alpha |
| 766 | // prefill, so get the back layer. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 767 | if (layerSettings.empty()) { |
| 768 | ADD_FAILURE() << "layerSettings was not expected to be empty in " |
| 769 | "setupInsecureREBufferCompositionCommonCallExpectations " |
| 770 | "verification lambda"; |
| 771 | return NO_ERROR; |
| 772 | } |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 773 | const renderengine::LayerSettings* layer = layerSettings.back(); |
| 774 | EXPECT_THAT(layer->source.buffer.buffer, IsNull()); |
| 775 | EXPECT_EQ(half3(0.0f, 0.0f, 0.0f), layer->source.solidColor); |
| 776 | EXPECT_EQ(0.0, layer->geometry.roundedCornersRadius); |
| 777 | EXPECT_EQ(ui::Dataspace::UNKNOWN, layer->sourceDataspace); |
| 778 | EXPECT_EQ(1.0f, layer->alpha); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 779 | return NO_ERROR; |
| 780 | }); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | static void setupInsecureREBufferCompositionCallExpectations(CompositionTest* test) { |
| 784 | setupInsecureREBufferCompositionCommonCallExpectations(test); |
| 785 | Base::setupBufferLayerPostFrameCallExpectations(test); |
| 786 | } |
| 787 | |
| 788 | static void setupInsecureREBufferScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 789 | setupInsecureREBufferCompositionCommonCallExpectations(test); |
| 790 | } |
| 791 | }; |
| 792 | |
| 793 | struct CursorLayerProperties : public BaseLayerProperties<CursorLayerProperties> { |
| 794 | using Base = BaseLayerProperties<CursorLayerProperties>; |
| 795 | |
| 796 | static void setupLayerState(CompositionTest* test, sp<BufferQueueLayer> layer) { |
| 797 | Base::setupLayerState(test, layer); |
| 798 | test->mFlinger.setLayerPotentialCursor(layer, true); |
| 799 | } |
| 800 | }; |
| 801 | |
| 802 | struct NoLayerVariant { |
| 803 | using FlingerLayerType = sp<BufferQueueLayer>; |
| 804 | |
| 805 | static FlingerLayerType createLayer(CompositionTest*) { return FlingerLayerType(); } |
| 806 | static void injectLayer(CompositionTest*, FlingerLayerType) {} |
| 807 | static void cleanupInjectedLayers(CompositionTest*) {} |
| 808 | |
| 809 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 810 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 811 | }; |
| 812 | |
| 813 | template <typename LayerProperties> |
| 814 | struct BaseLayerVariant { |
| 815 | template <typename L, typename F> |
| 816 | static sp<L> createLayerWithFactory(CompositionTest* test, F factory) { |
| 817 | EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(0); |
| 818 | |
| 819 | sp<L> layer = factory(); |
| 820 | |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 821 | // Layer should be registered with scheduler. |
| 822 | EXPECT_EQ(1, test->mFlinger.scheduler()->layerHistorySize()); |
| 823 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 824 | Mock::VerifyAndClear(test->mComposer); |
| 825 | Mock::VerifyAndClear(test->mRenderEngine); |
| 826 | Mock::VerifyAndClear(test->mMessageQueue); |
| 827 | |
| 828 | auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); |
| 829 | layerDrawingState.layerStack = DEFAULT_LAYER_STACK; |
| 830 | layerDrawingState.active.w = 100; |
| 831 | layerDrawingState.active.h = 100; |
| 832 | layerDrawingState.color = half4(LayerProperties::COLOR[0], LayerProperties::COLOR[1], |
| 833 | LayerProperties::COLOR[2], LayerProperties::COLOR[3]); |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 834 | layer->computeBounds(FloatRect(0, 0, 100, 100), ui::Transform(), 0.f /* shadowRadius */); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 835 | |
| 836 | return layer; |
| 837 | } |
| 838 | |
| 839 | static void injectLayer(CompositionTest* test, sp<Layer> layer) { |
| 840 | EXPECT_CALL(*test->mComposer, createLayer(HWC_DISPLAY, _)) |
| 841 | .WillOnce(DoAll(SetArgPointee<1>(HWC_LAYER), Return(Error::NONE))); |
| 842 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame^] | 843 | auto outputLayer = test->mDisplay->getCompositionDisplay()->injectOutputLayerForTest( |
| 844 | layer->getCompositionEngineLayerFE()); |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 845 | outputLayer->editState().visibleRegion = Region(Rect(0, 0, 100, 100)); |
| 846 | outputLayer->editState().outputSpaceVisibleRegion = Region(Rect(0, 0, 100, 100)); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 847 | |
| 848 | Mock::VerifyAndClear(test->mComposer); |
| 849 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 850 | test->mFlinger.mutableDrawingState().layersSortedByZ.add(layer); |
| 851 | } |
| 852 | |
| 853 | static void cleanupInjectedLayers(CompositionTest* test) { |
| 854 | EXPECT_CALL(*test->mComposer, destroyLayer(HWC_DISPLAY, HWC_LAYER)) |
| 855 | .WillOnce(Return(Error::NONE)); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 856 | |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 857 | test->mDisplay->getCompositionDisplay()->clearOutputLayers(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 858 | test->mFlinger.mutableDrawingState().layersSortedByZ.clear(); |
Dominik Laskowski | 49cea51 | 2019-11-12 14:13:23 -0800 | [diff] [blame] | 859 | |
| 860 | // Layer should be unregistered with scheduler. |
| 861 | test->mFlinger.onMessageReceived(MessageQueue::INVALIDATE); |
| 862 | EXPECT_EQ(0, test->mFlinger.scheduler()->layerHistorySize()); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 863 | } |
| 864 | }; |
| 865 | |
| 866 | template <typename LayerProperties> |
| 867 | struct ColorLayerVariant : public BaseLayerVariant<LayerProperties> { |
| 868 | using Base = BaseLayerVariant<LayerProperties>; |
| 869 | using FlingerLayerType = sp<ColorLayer>; |
| 870 | |
| 871 | static FlingerLayerType createLayer(CompositionTest* test) { |
| 872 | FlingerLayerType layer = Base::template createLayerWithFactory<ColorLayer>(test, [test]() { |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 873 | return new ColorLayer(LayerCreationArgs(test->mFlinger.mFlinger.get(), sp<Client>(), |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 874 | "test-layer", LayerProperties::WIDTH, |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 875 | LayerProperties::HEIGHT, |
Evan Rosky | a1f1e15 | 2019-01-24 16:17:46 -0800 | [diff] [blame] | 876 | LayerProperties::LAYER_FLAGS, LayerMetadata())); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 877 | }); |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 878 | |
| 879 | auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); |
| 880 | layerDrawingState.crop_legacy = Rect(0, 0, LayerProperties::HEIGHT, LayerProperties::WIDTH); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 881 | return layer; |
| 882 | } |
| 883 | |
| 884 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 885 | LayerProperties::setupREColorCompositionCallExpectations(test); |
| 886 | } |
| 887 | |
| 888 | static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 889 | LayerProperties::setupREColorScreenshotCompositionCallExpectations(test); |
| 890 | } |
| 891 | |
| 892 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 893 | LayerProperties::setupHwcSetGeometryCallExpectations(test); |
| 894 | LayerProperties::setupHwcSetSourceCropColorCallExpectations(test); |
| 895 | } |
| 896 | |
| 897 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 898 | LayerProperties::setupHwcSetPerFrameCallExpectations(test); |
| 899 | LayerProperties::setupHwcSetPerFrameColorCallExpectations(test); |
| 900 | } |
| 901 | }; |
| 902 | |
| 903 | template <typename LayerProperties> |
| 904 | struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> { |
| 905 | using Base = BaseLayerVariant<LayerProperties>; |
| 906 | using FlingerLayerType = sp<BufferQueueLayer>; |
| 907 | |
| 908 | static FlingerLayerType createLayer(CompositionTest* test) { |
| 909 | test->mFlinger.mutableTexturePool().push_back(DEFAULT_TEXTURE_ID); |
| 910 | |
| 911 | FlingerLayerType layer = |
| 912 | Base::template createLayerWithFactory<BufferQueueLayer>(test, [test]() { |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 913 | sp<Client> client; |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 914 | LayerCreationArgs args(test->mFlinger.mFlinger.get(), client, "test-layer", |
| 915 | LayerProperties::WIDTH, LayerProperties::HEIGHT, |
| 916 | LayerProperties::LAYER_FLAGS, LayerMetadata()); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 917 | args.textureName = test->mFlinger.mutableTexturePool().back(); |
| 918 | return new BufferQueueLayer(args); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 919 | }); |
| 920 | |
| 921 | LayerProperties::setupLayerState(test, layer); |
| 922 | |
| 923 | return layer; |
| 924 | } |
| 925 | |
| 926 | static void cleanupInjectedLayers(CompositionTest* test) { |
Dan Stoza | 67765d8 | 2019-05-07 14:58:27 -0700 | [diff] [blame] | 927 | EXPECT_CALL(*test->mMessageQueue, postMessage(_, 0)).Times(1); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 928 | Base::cleanupInjectedLayers(test); |
| 929 | } |
| 930 | |
| 931 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 932 | LayerProperties::setupHwcSetGeometryCallExpectations(test); |
| 933 | LayerProperties::setupHwcSetSourceCropBufferCallExpectations(test); |
| 934 | } |
| 935 | |
| 936 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 937 | LayerProperties::setupHwcSetPerFrameCallExpectations(test); |
| 938 | LayerProperties::setupHwcSetPerFrameBufferCallExpectations(test); |
| 939 | } |
| 940 | |
| 941 | static void setupRECompositionCallExpectations(CompositionTest* test) { |
| 942 | LayerProperties::setupREBufferCompositionCallExpectations(test); |
| 943 | } |
| 944 | |
| 945 | static void setupInsecureRECompositionCallExpectations(CompositionTest* test) { |
| 946 | LayerProperties::setupInsecureREBufferCompositionCallExpectations(test); |
| 947 | } |
| 948 | |
| 949 | static void setupREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 950 | LayerProperties::setupREBufferScreenshotCompositionCallExpectations(test); |
| 951 | } |
| 952 | |
| 953 | static void setupInsecureREScreenshotCompositionCallExpectations(CompositionTest* test) { |
| 954 | LayerProperties::setupInsecureREBufferScreenshotCompositionCallExpectations(test); |
| 955 | } |
| 956 | }; |
| 957 | |
| 958 | /* ------------------------------------------------------------------------ |
| 959 | * Variants to control how the composition type is changed |
| 960 | */ |
| 961 | |
| 962 | struct NoCompositionTypeVariant { |
| 963 | static void setupHwcSetCallExpectations(CompositionTest*) {} |
| 964 | |
| 965 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 966 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1); |
| 967 | } |
| 968 | }; |
| 969 | |
| 970 | template <IComposerClient::Composition CompositionType> |
| 971 | struct KeepCompositionTypeVariant { |
| 972 | static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(CompositionType); |
| 973 | |
| 974 | static void setupHwcSetCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 975 | if (!test->mDisplayOff) { |
| 976 | EXPECT_CALL(*test->mComposer, |
| 977 | setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, CompositionType)) |
| 978 | .Times(1); |
| 979 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 983 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)).Times(1); |
| 984 | } |
| 985 | }; |
| 986 | |
| 987 | template <IComposerClient::Composition InitialCompositionType, |
| 988 | IComposerClient::Composition FinalCompositionType> |
| 989 | struct ChangeCompositionTypeVariant { |
| 990 | static constexpr HWC2::Composition TYPE = static_cast<HWC2::Composition>(FinalCompositionType); |
| 991 | |
| 992 | static void setupHwcSetCallExpectations(CompositionTest* test) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 993 | if (!test->mDisplayOff) { |
| 994 | EXPECT_CALL(*test->mComposer, |
| 995 | setLayerCompositionType(HWC_DISPLAY, HWC_LAYER, InitialCompositionType)) |
| 996 | .Times(1); |
| 997 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | static void setupHwcGetCallExpectations(CompositionTest* test) { |
| 1001 | EXPECT_CALL(*test->mComposer, getChangedCompositionTypes(HWC_DISPLAY, _, _)) |
| 1002 | .WillOnce(DoAll(SetArgPointee<1>(std::vector<Hwc2::Layer>{ |
| 1003 | static_cast<Hwc2::Layer>(HWC_LAYER)}), |
| 1004 | SetArgPointee<2>(std::vector<IComposerClient::Composition>{ |
| 1005 | FinalCompositionType}), |
| 1006 | Return(Error::NONE))); |
| 1007 | } |
| 1008 | }; |
| 1009 | |
| 1010 | /* ------------------------------------------------------------------------ |
| 1011 | * Variants to select how the composition is expected to be handled |
| 1012 | */ |
| 1013 | |
| 1014 | struct CompositionResultBaseVariant { |
| 1015 | static void setupLayerState(CompositionTest*, sp<Layer>) {} |
| 1016 | |
| 1017 | template <typename Case> |
| 1018 | static void setupCallExpectationsForDirtyGeometry(CompositionTest* test) { |
| 1019 | Case::Layer::setupCallExpectationsForDirtyGeometry(test); |
| 1020 | } |
| 1021 | |
| 1022 | template <typename Case> |
| 1023 | static void setupCallExpectationsForDirtyFrame(CompositionTest* test) { |
| 1024 | Case::Layer::setupCallExpectationsForDirtyFrame(test); |
| 1025 | } |
| 1026 | }; |
| 1027 | |
| 1028 | struct NoCompositionResultVariant : public CompositionResultBaseVariant { |
| 1029 | template <typename Case> |
| 1030 | static void setupCallExpectations(CompositionTest* test) { |
| 1031 | Case::Display::setupEmptyFrameCompositionCallExpectations(test); |
| 1032 | Case::Display::setupHwcCompositionCallExpectations(test); |
| 1033 | } |
| 1034 | }; |
| 1035 | |
| 1036 | struct HwcCompositionResultVariant : public CompositionResultBaseVariant { |
| 1037 | template <typename Case> |
| 1038 | static void setupCallExpectations(CompositionTest* test) { |
| 1039 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1040 | Case::Display::setupHwcCompositionCallExpectations(test); |
| 1041 | } |
| 1042 | }; |
| 1043 | |
| 1044 | struct RECompositionResultVariant : public CompositionResultBaseVariant { |
| 1045 | template <typename Case> |
| 1046 | static void setupCallExpectations(CompositionTest* test) { |
| 1047 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1048 | Case::Display::setupHwcClientCompositionCallExpectations(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1049 | Case::Display::setupRECompositionCallExpectations(test); |
| 1050 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1051 | } |
| 1052 | }; |
| 1053 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1054 | struct ForcedClientCompositionResultVariant : public CompositionResultBaseVariant { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 1055 | static void setupLayerState(CompositionTest* test, sp<Layer> layer) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 1056 | const auto outputLayer = layer->findOutputLayerForDisplay(test->mDisplay); |
| 1057 | LOG_FATAL_IF(!outputLayer); |
| 1058 | outputLayer->editState().forceClientComposition = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | template <typename Case> |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 1062 | static void setupCallExpectations(CompositionTest* test) { |
| 1063 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1064 | Case::Display::setupHwcForcedClientCompositionCallExpectations(test); |
| 1065 | Case::Display::setupRECompositionCallExpectations(test); |
| 1066 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1067 | } |
| 1068 | |
| 1069 | template <typename Case> |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1070 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 1071 | |
| 1072 | template <typename Case> |
| 1073 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 1074 | }; |
| 1075 | |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 1076 | struct ForcedClientCompositionViaDebugOptionResultVariant : public CompositionResultBaseVariant { |
| 1077 | static void setupLayerState(CompositionTest* test, sp<Layer>) { |
| 1078 | test->mFlinger.mutableDebugDisableHWC() = true; |
| 1079 | } |
| 1080 | |
| 1081 | template <typename Case> |
| 1082 | static void setupCallExpectations(CompositionTest* test) { |
| 1083 | Case::Display::setupNonEmptyFrameCompositionCallExpectations(test); |
| 1084 | Case::Display::setupHwcForcedClientCompositionCallExpectations(test); |
| 1085 | Case::Display::setupRECompositionCallExpectations(test); |
| 1086 | Case::Display::template setupRELayerCompositionCallExpectations<Case>(test); |
| 1087 | } |
| 1088 | |
| 1089 | template <typename Case> |
| 1090 | static void setupCallExpectationsForDirtyGeometry(CompositionTest*) {} |
| 1091 | |
| 1092 | template <typename Case> |
| 1093 | static void setupCallExpectationsForDirtyFrame(CompositionTest*) {} |
| 1094 | }; |
| 1095 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1096 | struct EmptyScreenshotResultVariant { |
| 1097 | static void setupLayerState(CompositionTest*, sp<Layer>) {} |
| 1098 | |
| 1099 | template <typename Case> |
| 1100 | static void setupCallExpectations(CompositionTest*) {} |
| 1101 | }; |
| 1102 | |
| 1103 | struct REScreenshotResultVariant : public EmptyScreenshotResultVariant { |
| 1104 | using Base = EmptyScreenshotResultVariant; |
| 1105 | |
| 1106 | template <typename Case> |
| 1107 | static void setupCallExpectations(CompositionTest* test) { |
| 1108 | Base::template setupCallExpectations<Case>(test); |
| 1109 | Case::Display::template setupRELayerScreenshotCompositionCallExpectations<Case>(test); |
| 1110 | } |
| 1111 | }; |
| 1112 | |
| 1113 | /* ------------------------------------------------------------------------ |
| 1114 | * Composition test case, containing all the variants being tested |
| 1115 | */ |
| 1116 | |
| 1117 | template <typename DisplayCase, typename LayerCase, typename CompositionTypeCase, |
| 1118 | typename CompositionResultCase> |
| 1119 | struct CompositionCase { |
| 1120 | using ThisCase = |
| 1121 | CompositionCase<DisplayCase, LayerCase, CompositionTypeCase, CompositionResultCase>; |
| 1122 | using Display = DisplayCase; |
| 1123 | using Layer = LayerCase; |
| 1124 | using CompositionType = CompositionTypeCase; |
| 1125 | using CompositionResult = CompositionResultCase; |
| 1126 | |
| 1127 | static void setupCommon(CompositionTest* test) { |
Peiyong Lin | 1336e6e | 2019-05-28 09:23:50 -0700 | [diff] [blame] | 1128 | Display::template setupPreconditionCallExpectations<ThisCase>(test); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1129 | Display::setupPreconditions(test); |
| 1130 | |
| 1131 | auto layer = Layer::createLayer(test); |
| 1132 | Layer::injectLayer(test, layer); |
| 1133 | CompositionResult::setupLayerState(test, layer); |
| 1134 | } |
| 1135 | |
| 1136 | static void setupForDirtyGeometry(CompositionTest* test) { |
| 1137 | setupCommon(test); |
| 1138 | |
| 1139 | Display::template setupCommonCompositionCallExpectations<ThisCase>(test); |
| 1140 | CompositionResult::template setupCallExpectationsForDirtyGeometry<ThisCase>(test); |
| 1141 | CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test); |
| 1142 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1143 | } |
| 1144 | |
| 1145 | static void setupForDirtyFrame(CompositionTest* test) { |
| 1146 | setupCommon(test); |
| 1147 | |
| 1148 | Display::template setupCommonCompositionCallExpectations<ThisCase>(test); |
| 1149 | CompositionResult::template setupCallExpectationsForDirtyFrame<ThisCase>(test); |
| 1150 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1151 | } |
| 1152 | |
| 1153 | static void setupForScreenCapture(CompositionTest* test) { |
| 1154 | setupCommon(test); |
| 1155 | |
| 1156 | Display::template setupCommonScreensCaptureCallExpectations<ThisCase>(test); |
| 1157 | CompositionResult::template setupCallExpectations<ThisCase>(test); |
| 1158 | } |
| 1159 | |
| 1160 | static void cleanup(CompositionTest* test) { |
| 1161 | Layer::cleanupInjectedLayers(test); |
| 1162 | |
Peiyong Lin | bdd08cc | 2019-12-17 21:35:14 -0800 | [diff] [blame] | 1163 | for (auto& displayData : test->mFlinger.mutableHwcDisplayData()) { |
| 1164 | static_cast<TestableSurfaceFlinger::HWC2Display*>(displayData.second.hwcDisplay.get()) |
| 1165 | ->mutableLayers() |
| 1166 | .clear(); |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1167 | } |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1168 | } |
| 1169 | }; |
| 1170 | |
| 1171 | /* ------------------------------------------------------------------------ |
| 1172 | * Composition cases to test |
| 1173 | */ |
| 1174 | |
| 1175 | TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyGeometry) { |
| 1176 | displayRefreshCompositionDirtyGeometry< |
| 1177 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1178 | NoCompositionResultVariant>>(); |
| 1179 | } |
| 1180 | |
| 1181 | TEST_F(CompositionTest, noLayersDoesMinimalWorkWithDirtyFrame) { |
| 1182 | displayRefreshCompositionDirtyFrame< |
| 1183 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1184 | NoCompositionResultVariant>>(); |
| 1185 | } |
| 1186 | |
| 1187 | TEST_F(CompositionTest, noLayersDoesMinimalWorkToCaptureScreen) { |
| 1188 | captureScreenComposition< |
| 1189 | CompositionCase<DefaultDisplaySetupVariant, NoLayerVariant, NoCompositionTypeVariant, |
| 1190 | EmptyScreenshotResultVariant>>(); |
| 1191 | } |
| 1192 | |
| 1193 | /* ------------------------------------------------------------------------ |
| 1194 | * Simple buffer layers |
| 1195 | */ |
| 1196 | |
| 1197 | TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyGeometry) { |
| 1198 | displayRefreshCompositionDirtyGeometry< |
| 1199 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1200 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1201 | HwcCompositionResultVariant>>(); |
| 1202 | } |
| 1203 | |
| 1204 | TEST_F(CompositionTest, HWCComposedNormalBufferLayerWithDirtyFrame) { |
| 1205 | displayRefreshCompositionDirtyFrame< |
| 1206 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1207 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1208 | HwcCompositionResultVariant>>(); |
| 1209 | } |
| 1210 | |
| 1211 | TEST_F(CompositionTest, REComposedNormalBufferLayer) { |
| 1212 | displayRefreshCompositionDirtyFrame< |
| 1213 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1214 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1215 | IComposerClient::Composition::CLIENT>, |
| 1216 | RECompositionResultVariant>>(); |
| 1217 | } |
| 1218 | |
| 1219 | TEST_F(CompositionTest, captureScreenNormalBufferLayer) { |
| 1220 | captureScreenComposition< |
| 1221 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1222 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1223 | } |
| 1224 | |
| 1225 | /* ------------------------------------------------------------------------ |
| 1226 | * Single-color layers |
| 1227 | */ |
| 1228 | |
| 1229 | TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyGeometry) { |
| 1230 | displayRefreshCompositionDirtyGeometry< |
| 1231 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1232 | KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>, |
| 1233 | HwcCompositionResultVariant>>(); |
| 1234 | } |
| 1235 | |
| 1236 | TEST_F(CompositionTest, HWCComposedColorLayerWithDirtyFrame) { |
| 1237 | displayRefreshCompositionDirtyFrame< |
| 1238 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1239 | KeepCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR>, |
| 1240 | HwcCompositionResultVariant>>(); |
| 1241 | } |
| 1242 | |
| 1243 | TEST_F(CompositionTest, REComposedColorLayer) { |
| 1244 | displayRefreshCompositionDirtyFrame< |
| 1245 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1246 | ChangeCompositionTypeVariant<IComposerClient::Composition::SOLID_COLOR, |
| 1247 | IComposerClient::Composition::CLIENT>, |
| 1248 | RECompositionResultVariant>>(); |
| 1249 | } |
| 1250 | |
| 1251 | TEST_F(CompositionTest, captureScreenColorLayer) { |
| 1252 | captureScreenComposition< |
| 1253 | CompositionCase<DefaultDisplaySetupVariant, ColorLayerVariant<ColorLayerProperties>, |
| 1254 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1255 | } |
| 1256 | |
| 1257 | /* ------------------------------------------------------------------------ |
| 1258 | * Layers with sideband buffers |
| 1259 | */ |
| 1260 | |
| 1261 | TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyGeometry) { |
| 1262 | displayRefreshCompositionDirtyGeometry< |
| 1263 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1264 | KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>, |
| 1265 | HwcCompositionResultVariant>>(); |
| 1266 | } |
| 1267 | |
| 1268 | TEST_F(CompositionTest, HWCComposedSidebandBufferLayerWithDirtyFrame) { |
| 1269 | displayRefreshCompositionDirtyFrame< |
| 1270 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1271 | KeepCompositionTypeVariant<IComposerClient::Composition::SIDEBAND>, |
| 1272 | HwcCompositionResultVariant>>(); |
| 1273 | } |
| 1274 | |
| 1275 | TEST_F(CompositionTest, REComposedSidebandBufferLayer) { |
| 1276 | displayRefreshCompositionDirtyFrame< |
| 1277 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1278 | ChangeCompositionTypeVariant<IComposerClient::Composition::SIDEBAND, |
| 1279 | IComposerClient::Composition::CLIENT>, |
| 1280 | RECompositionResultVariant>>(); |
| 1281 | } |
| 1282 | |
| 1283 | TEST_F(CompositionTest, captureScreenSidebandBufferLayer) { |
| 1284 | captureScreenComposition< |
| 1285 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SidebandLayerProperties>, |
| 1286 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1287 | } |
| 1288 | |
| 1289 | /* ------------------------------------------------------------------------ |
| 1290 | * Layers with ISurfaceComposerClient::eSecure, on a secure display |
| 1291 | */ |
| 1292 | |
| 1293 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyGeometry) { |
| 1294 | displayRefreshCompositionDirtyGeometry< |
| 1295 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1296 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1297 | HwcCompositionResultVariant>>(); |
| 1298 | } |
| 1299 | |
| 1300 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerWithDirtyFrame) { |
| 1301 | displayRefreshCompositionDirtyFrame< |
| 1302 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1303 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1304 | HwcCompositionResultVariant>>(); |
| 1305 | } |
| 1306 | |
| 1307 | TEST_F(CompositionTest, REComposedSecureBufferLayer) { |
| 1308 | displayRefreshCompositionDirtyFrame< |
| 1309 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1310 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1311 | IComposerClient::Composition::CLIENT>, |
| 1312 | RECompositionResultVariant>>(); |
| 1313 | } |
| 1314 | |
| 1315 | TEST_F(CompositionTest, captureScreenSecureBufferLayerOnSecureDisplay) { |
| 1316 | captureScreenComposition< |
| 1317 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1318 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1319 | } |
| 1320 | |
| 1321 | /* ------------------------------------------------------------------------ |
| 1322 | * Layers with ISurfaceComposerClient::eSecure, on a non-secure display |
| 1323 | */ |
| 1324 | |
| 1325 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyGeometry) { |
| 1326 | displayRefreshCompositionDirtyGeometry< |
| 1327 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1328 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1329 | ForcedClientCompositionResultVariant>>(); |
| 1330 | } |
| 1331 | |
| 1332 | TEST_F(CompositionTest, HWCComposedSecureBufferLayerOnInsecureDisplayWithDirtyFrame) { |
| 1333 | displayRefreshCompositionDirtyFrame< |
| 1334 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1335 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1336 | ForcedClientCompositionResultVariant>>(); |
| 1337 | } |
| 1338 | |
| 1339 | TEST_F(CompositionTest, captureScreenSecureBufferLayerOnInsecureDisplay) { |
| 1340 | captureScreenComposition< |
| 1341 | CompositionCase<InsecureDisplaySetupVariant, BufferLayerVariant<SecureLayerProperties>, |
| 1342 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1343 | } |
| 1344 | |
| 1345 | /* ------------------------------------------------------------------------ |
| 1346 | * Cursor layers |
| 1347 | */ |
| 1348 | |
| 1349 | TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyGeometry) { |
| 1350 | displayRefreshCompositionDirtyGeometry< |
| 1351 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1352 | KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>, |
| 1353 | HwcCompositionResultVariant>>(); |
| 1354 | } |
| 1355 | |
| 1356 | TEST_F(CompositionTest, HWCComposedCursorLayerWithDirtyFrame) { |
| 1357 | displayRefreshCompositionDirtyFrame< |
| 1358 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1359 | KeepCompositionTypeVariant<IComposerClient::Composition::CURSOR>, |
| 1360 | HwcCompositionResultVariant>>(); |
| 1361 | } |
| 1362 | |
| 1363 | TEST_F(CompositionTest, REComposedCursorLayer) { |
| 1364 | displayRefreshCompositionDirtyFrame< |
| 1365 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1366 | ChangeCompositionTypeVariant<IComposerClient::Composition::CURSOR, |
| 1367 | IComposerClient::Composition::CLIENT>, |
| 1368 | RECompositionResultVariant>>(); |
| 1369 | } |
| 1370 | |
| 1371 | TEST_F(CompositionTest, captureScreenCursorLayer) { |
| 1372 | captureScreenComposition< |
| 1373 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<CursorLayerProperties>, |
| 1374 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1375 | } |
| 1376 | |
| 1377 | /* ------------------------------------------------------------------------ |
| 1378 | * Simple buffer layer on a display which is powered off. |
| 1379 | */ |
| 1380 | |
| 1381 | TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyGeometry) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1382 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1383 | displayRefreshCompositionDirtyGeometry<CompositionCase< |
| 1384 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1385 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1386 | HwcCompositionResultVariant>>(); |
| 1387 | } |
| 1388 | |
| 1389 | TEST_F(CompositionTest, displayOffHWCComposedNormalBufferLayerWithDirtyFrame) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1390 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1391 | displayRefreshCompositionDirtyFrame<CompositionCase< |
| 1392 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1393 | KeepCompositionTypeVariant<IComposerClient::Composition::DEVICE>, |
| 1394 | HwcCompositionResultVariant>>(); |
| 1395 | } |
| 1396 | |
| 1397 | TEST_F(CompositionTest, displayOffREComposedNormalBufferLayer) { |
Alec Mouri | f9a2a2c | 2019-11-12 12:46:02 -0800 | [diff] [blame] | 1398 | mDisplayOff = true; |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1399 | displayRefreshCompositionDirtyFrame<CompositionCase< |
| 1400 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1401 | ChangeCompositionTypeVariant<IComposerClient::Composition::DEVICE, |
| 1402 | IComposerClient::Composition::CLIENT>, |
| 1403 | RECompositionResultVariant>>(); |
| 1404 | } |
| 1405 | |
| 1406 | TEST_F(CompositionTest, captureScreenNormalBufferLayerOnPoweredOffDisplay) { |
| 1407 | captureScreenComposition<CompositionCase< |
| 1408 | PoweredOffDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1409 | NoCompositionTypeVariant, REScreenshotResultVariant>>(); |
| 1410 | } |
| 1411 | |
Lloyd Pique | 4fe2940 | 2019-08-12 16:51:24 -0700 | [diff] [blame] | 1412 | /* ------------------------------------------------------------------------ |
| 1413 | * Client composition forced through debug/developer settings |
| 1414 | */ |
| 1415 | |
| 1416 | TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyGeometry) { |
| 1417 | displayRefreshCompositionDirtyGeometry< |
| 1418 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1419 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1420 | ForcedClientCompositionViaDebugOptionResultVariant>>(); |
| 1421 | } |
| 1422 | |
| 1423 | TEST_F(CompositionTest, DebugOptionForcingClientCompositionOfBufferLayerWithDirtyFrame) { |
| 1424 | displayRefreshCompositionDirtyFrame< |
| 1425 | CompositionCase<DefaultDisplaySetupVariant, BufferLayerVariant<DefaultLayerProperties>, |
| 1426 | KeepCompositionTypeVariant<IComposerClient::Composition::CLIENT>, |
| 1427 | ForcedClientCompositionViaDebugOptionResultVariant>>(); |
| 1428 | } |
| 1429 | |
Lloyd Pique | d6b579f | 2018-04-06 15:29:10 -0700 | [diff] [blame] | 1430 | } // namespace |
| 1431 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 1432 | |
| 1433 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 1434 | #pragma clang diagnostic pop // ignored "-Wconversion" |