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