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