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