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