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