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