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