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