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