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