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