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