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