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