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