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