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