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