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