blob: c037cc61738f4e57174a6ab3ed4e3d295973e61a [file] [log] [blame]
Lloyd Pique45a165a2018-10-19 11:54:47 -07001/*
2 * Copyright 2019 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
Lloyd Pique45a165a2018-10-19 11:54:47 -070017#include <cmath>
18
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070019#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070020#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070021#include <compositionengine/DisplaySurface.h>
22#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070023#include <compositionengine/impl/Display.h>
Lloyd Piquec6607552019-12-02 17:57:39 -080024#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070025#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080026#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquec6607552019-12-02 17:57:39 -080027#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquedf336d92019-03-07 21:38:42 -080028#include <compositionengine/mock/LayerFE.h>
chaviw8beb4142019-04-11 13:09:05 -070029#include <compositionengine/mock/NativeWindow.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080030#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070031#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070032#include <gtest/gtest.h>
Lloyd Piquee9eff972020-05-05 12:36:44 -070033#include <renderengine/mock/RenderEngine.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070034#include <ui/Rect.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010035#include <ui/StaticDisplayInfo.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070036
Lloyd Pique66d68602019-02-13 14:23:31 -080037#include "MockHWC2.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070038#include "MockHWComposer.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080039#include "MockPowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070040
41namespace android::compositionengine {
42namespace {
43
Peiyong Line9d809e2020-04-14 13:10:48 -070044namespace hal = android::hardware::graphics::composer::hal;
45
Lloyd Piquef5275482019-01-29 18:42:42 -080046using testing::_;
Lloyd Pique66d68602019-02-13 14:23:31 -080047using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070048using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080049using testing::InSequence;
50using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070051using testing::Pointee;
52using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070053using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070054using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080055using testing::Sequence;
56using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070057using testing::StrictMock;
58
Dominik Laskowski13948602021-03-08 20:48:28 -080059constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
60constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
61constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
62
63const ui::Size DEFAULT_RESOLUTION{1920, 1080};
64constexpr uint32_t DEFAULT_LAYER_STACK = 42;
Lloyd Pique45a165a2018-10-19 11:54:47 -070065
Lloyd Piquede196652020-01-22 17:29:58 -080066struct Layer {
67 Layer() {
68 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
69 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
70 }
71
72 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
73 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
74 StrictMock<HWC2::mock::Layer> hwc2Layer;
75};
76
77struct LayerNoHWC2Layer {
78 LayerNoHWC2Layer() {
79 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
80 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
81 }
82
83 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
84 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
85};
86
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070087struct DisplayTestCommon : public testing::Test {
88 // Uses the full implementation of a display
89 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070090 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070091 using impl::Display::injectOutputLayerForTest;
92 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
93 };
94
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070095 // Uses a special implementation with key internal member functions set up
96 // as mock implementations, to allow for easier testing.
97 struct PartialMockDisplay : public impl::Display {
98 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
99 : mCompositionEngine(compositionEngine) {}
100
101 // compositionengine::Output overrides
102 const OutputCompositionState& getState() const override { return mState; }
103 OutputCompositionState& editState() override { return mState; }
104
105 // compositionengine::impl::Output overrides
106 const CompositionEngine& getCompositionEngine() const override {
107 return mCompositionEngine;
108 };
109
110 // Mock implementation overrides
111 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
112 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
113 compositionengine::OutputLayer*(size_t));
114 MOCK_METHOD2(ensureOutputLayer,
115 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
116 MOCK_METHOD0(finalizePendingOutputLayers, void());
117 MOCK_METHOD0(clearOutputLayers, void());
118 MOCK_CONST_METHOD1(dumpState, void(std::string&));
119 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
120 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
121 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
122 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
123 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
124 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
125 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
126
127 const compositionengine::CompositionEngine& mCompositionEngine;
128 impl::OutputCompositionState mState;
129 };
130
131 static std::string getDisplayNameFromCurrentTest() {
132 const ::testing::TestInfo* const test_info =
133 ::testing::UnitTest::GetInstance()->current_test_info();
134 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
135 }
136
137 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700138 static std::shared_ptr<Display> createDisplay(
139 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700140 compositionengine::DisplayCreationArgs args) {
141 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700142 return impl::createDisplayTemplated<Display>(compositionEngine, args);
143 }
144
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700145 template <typename Display>
146 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
147 const compositionengine::CompositionEngine& compositionEngine,
148 compositionengine::DisplayCreationArgs args) {
149 args.name = getDisplayNameFromCurrentTest();
150 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800151
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700152 display->setConfiguration(args);
153
154 return display;
155 }
156
157 DisplayTestCommon() {
158 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700159 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
160 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700161 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700162 }
163
164 DisplayCreationArgs getDisplayCreationArgsForPhysicalHWCDisplay() {
165 return DisplayCreationArgsBuilder()
Dominik Laskowski13948602021-03-08 20:48:28 -0800166 .setId(DEFAULT_DISPLAY_ID)
167 .setConnectionType(ui::DisplayConnectionType::Internal)
168 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700169 .setIsSecure(true)
170 .setLayerStackId(DEFAULT_LAYER_STACK)
171 .setPowerAdvisor(&mPowerAdvisor)
172 .build();
173 }
174
Dominik Laskowski13948602021-03-08 20:48:28 -0800175 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700176 return DisplayCreationArgsBuilder()
Dominik Laskowski13948602021-03-08 20:48:28 -0800177 .setId(GPU_VIRTUAL_DISPLAY_ID)
178 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700179 .setIsSecure(false)
180 .setLayerStackId(DEFAULT_LAYER_STACK)
181 .setPowerAdvisor(&mPowerAdvisor)
182 .build();
183 }
184
185 StrictMock<android::mock::HWComposer> mHwComposer;
186 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700187 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700188 StrictMock<mock::CompositionEngine> mCompositionEngine;
189 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
190};
191
192struct PartialMockDisplayTestCommon : public DisplayTestCommon {
193 using Display = DisplayTestCommon::PartialMockDisplay;
194 std::shared_ptr<Display> mDisplay =
195 createPartialMockDisplay<Display>(mCompositionEngine,
196 getDisplayCreationArgsForPhysicalHWCDisplay());
197};
198
199struct FullDisplayImplTestCommon : public DisplayTestCommon {
200 using Display = DisplayTestCommon::FullImplDisplay;
201 std::shared_ptr<Display> mDisplay =
202 createDisplay<Display>(mCompositionEngine,
203 getDisplayCreationArgsForPhysicalHWCDisplay());
204};
205
206struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
207 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700208 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800209 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700210 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800211 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700212 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800213 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800214 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700215
Lloyd Piquede196652020-01-22 17:29:58 -0800216 Layer mLayer1;
217 Layer mLayer2;
218 LayerNoHWC2Layer mLayer3;
219 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700220 std::shared_ptr<Display> mDisplay =
221 createDisplay<Display>(mCompositionEngine,
222 getDisplayCreationArgsForPhysicalHWCDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700223};
224
Lloyd Pique66d68602019-02-13 14:23:31 -0800225/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700226 * Basic construction
227 */
228
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700229struct DisplayCreationTest : public DisplayTestCommon {
230 using Display = DisplayTestCommon::FullImplDisplay;
231};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700232
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700233TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
234 auto display =
235 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalHWCDisplay());
236 EXPECT_TRUE(display->isSecure());
237 EXPECT_FALSE(display->isVirtual());
238 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
239}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700240
Dominik Laskowski13948602021-03-08 20:48:28 -0800241TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
242 auto display =
243 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700244 EXPECT_FALSE(display->isSecure());
245 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200246 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700247}
248
249/*
250 * Display::setConfiguration()
251 */
252
253using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
254
255TEST_F(DisplaySetConfigurationTest, configuresInternalSecurePhysicalDisplay) {
Dominik Laskowski13948602021-03-08 20:48:28 -0800256 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
257 .setId(DEFAULT_DISPLAY_ID)
258 .setConnectionType(ui::DisplayConnectionType::Internal)
259 .setPixels(DEFAULT_RESOLUTION)
260 .setIsSecure(true)
261 .setLayerStackId(DEFAULT_LAYER_STACK)
262 .setPowerAdvisor(&mPowerAdvisor)
263 .setName(getDisplayNameFromCurrentTest())
264 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700265
266 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
267 EXPECT_TRUE(mDisplay->isSecure());
268 EXPECT_FALSE(mDisplay->isVirtual());
269 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
270 EXPECT_TRUE(mDisplay->getState().layerStackInternal);
271 EXPECT_FALSE(mDisplay->isValid());
272}
273
274TEST_F(DisplaySetConfigurationTest, configuresExternalInsecurePhysicalDisplay) {
Dominik Laskowski13948602021-03-08 20:48:28 -0800275 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
276 .setId(DEFAULT_DISPLAY_ID)
277 .setConnectionType(ui::DisplayConnectionType::External)
278 .setPixels(DEFAULT_RESOLUTION)
279 .setIsSecure(false)
280 .setLayerStackId(DEFAULT_LAYER_STACK)
281 .setPowerAdvisor(&mPowerAdvisor)
282 .setName(getDisplayNameFromCurrentTest())
283 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700284
285 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
286 EXPECT_FALSE(mDisplay->isSecure());
287 EXPECT_FALSE(mDisplay->isVirtual());
288 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
289 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
290 EXPECT_FALSE(mDisplay->isValid());
291}
292
Dominik Laskowski13948602021-03-08 20:48:28 -0800293TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
294 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
295 .setId(HAL_VIRTUAL_DISPLAY_ID)
296 .setPixels(DEFAULT_RESOLUTION)
297 .setIsSecure(false)
298 .setLayerStackId(DEFAULT_LAYER_STACK)
299 .setPowerAdvisor(&mPowerAdvisor)
300 .setName(getDisplayNameFromCurrentTest())
301 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700302
Dominik Laskowski13948602021-03-08 20:48:28 -0800303 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700304 EXPECT_FALSE(mDisplay->isSecure());
305 EXPECT_TRUE(mDisplay->isVirtual());
306 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
307 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
308 EXPECT_FALSE(mDisplay->isValid());
309}
310
Dominik Laskowski13948602021-03-08 20:48:28 -0800311TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
312 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
313 .setId(GPU_VIRTUAL_DISPLAY_ID)
314 .setPixels(DEFAULT_RESOLUTION)
315 .setIsSecure(false)
316 .setLayerStackId(DEFAULT_LAYER_STACK)
317 .setPowerAdvisor(&mPowerAdvisor)
318 .setName(getDisplayNameFromCurrentTest())
319 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700320
Dominik Laskowski13948602021-03-08 20:48:28 -0800321 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700322 EXPECT_FALSE(mDisplay->isSecure());
323 EXPECT_TRUE(mDisplay->isVirtual());
324 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
325 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
326 EXPECT_FALSE(mDisplay->isValid());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700327}
328
Lloyd Pique66d68602019-02-13 14:23:31 -0800329/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700330 * Display::disconnect()
331 */
332
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700333using DisplayDisconnectTest = PartialMockDisplayTestCommon;
334
335TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200336 // The first call to disconnect will disconnect the display with the HWC.
337 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700338 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700339
340 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200341 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700342 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700343}
344
Lloyd Pique66d68602019-02-13 14:23:31 -0800345/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700346 * Display::setColorTransform()
347 */
348
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700349using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
350
351TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800352 // No change does nothing
353 CompositionRefreshArgs refreshArgs;
354 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700355 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800356
Lloyd Pique32cbe282018-10-19 13:09:22 -0700357 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800358 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700359
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200360 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
361 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700362
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800363 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700364 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700365
366 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800367 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700368
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200369 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
370 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700371
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800372 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700373 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700374}
375
Lloyd Pique66d68602019-02-13 14:23:31 -0800376/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700377 * Display::setColorMode()
378 */
379
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700380using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
381
382TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800383 using ColorProfile = Output::ColorProfile;
384
Lloyd Pique31cb2942018-10-19 17:23:03 -0700385 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700386 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800387 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700388 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700389
Lloyd Piquef5275482019-01-29 18:42:42 -0800390 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
391 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700392
393 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700394 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
395 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
396 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
397 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700398
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700399 // Otherwise if the values are unchanged, nothing happens
400 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
401 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700402
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700403 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
404 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
405 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
406 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700407
408 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800409 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700410 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800411 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700412 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
413 .Times(1);
414
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700415 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
416 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
417 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700418
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700419 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
420 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
421 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
422 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700423}
424
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700425TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800426 using ColorProfile = Output::ColorProfile;
427
Dominik Laskowski13948602021-03-08 20:48:28 -0800428 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700429 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700430
Lloyd Piquef5275482019-01-29 18:42:42 -0800431 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700432 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800433 std::unique_ptr<DisplayColorProfile>(colorProfile));
434
435 EXPECT_CALL(*colorProfile,
436 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
437 ui::Dataspace::UNKNOWN))
438 .WillOnce(Return(ui::Dataspace::UNKNOWN));
439
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700440 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800441 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
442 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700443
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700444 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
445 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
446 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
447 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700448}
449
Lloyd Pique66d68602019-02-13 14:23:31 -0800450/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700451 * Display::createDisplayColorProfile()
452 */
453
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700454using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
455
456TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700457 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
458 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700459 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
460 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700461 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700462}
463
Lloyd Pique66d68602019-02-13 14:23:31 -0800464/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700465 * Display::createRenderSurface()
466 */
467
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700468using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
469
470TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700471 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700472 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -0700473 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
474 .setDisplayWidth(640)
475 .setDisplayHeight(480)
476 .setNativeWindow(mNativeWindow)
477 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700478 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700479}
480
Lloyd Pique66d68602019-02-13 14:23:31 -0800481/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800482 * Display::createOutputLayer()
483 */
484
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700485using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
486
487TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800488 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700489 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800490
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200491 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700492 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800493
Lloyd Piquede196652020-01-22 17:29:58 -0800494 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800495
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700496 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800497
Lloyd Piquedf336d92019-03-07 21:38:42 -0800498 outputLayer.reset();
499}
500
501/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800502 * Display::setReleasedLayers()
503 */
504
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700505using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
506
Dominik Laskowski13948602021-03-08 20:48:28 -0800507TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
508 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
509 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800510
511 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800512
513 {
514 Output::ReleasedLayers releasedLayers;
515 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski13948602021-03-08 20:48:28 -0800516 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800517 }
518
519 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800520 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800521
Dominik Laskowski13948602021-03-08 20:48:28 -0800522 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800523
Dominik Laskowski13948602021-03-08 20:48:28 -0800524 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
525 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800526}
527
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700528TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800529 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
530
531 {
532 Output::ReleasedLayers releasedLayers;
533 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700534 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800535 }
536
537 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700538 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800539
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700540 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski13948602021-03-08 20:48:28 -0800541 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800542}
543
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700544TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800545 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800546
547 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800548 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
549 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
550 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800551
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700552 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800553
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700554 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski13948602021-03-08 20:48:28 -0800555 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800556 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
557 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800558}
559
560/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800561 * Display::chooseCompositionStrategy()
562 */
563
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700564using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800565
Dominik Laskowski13948602021-03-08 20:48:28 -0800566TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
567 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
568 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700569 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski13948602021-03-08 20:48:28 -0800570 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800571
Dominik Laskowski13948602021-03-08 20:48:28 -0800572 gpuDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800573
Dominik Laskowski13948602021-03-08 20:48:28 -0800574 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800575 EXPECT_TRUE(state.usesClientComposition);
576 EXPECT_FALSE(state.usesDeviceComposition);
577}
578
579TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700580 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200581 EXPECT_CALL(mHwComposer,
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700582 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800583 .WillOnce(Return(INVALID_OPERATION));
584
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700585 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800586
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700587 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800588 EXPECT_TRUE(state.usesClientComposition);
589 EXPECT_FALSE(state.usesDeviceComposition);
590}
591
592TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700593 // Since two calls are made to anyLayersRequireClientComposition with different return
594 // values, use a Sequence to control the matching so the values are returned in a known
595 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800596 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700597 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
598 .InSequence(s)
599 .WillOnce(Return(true));
600 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800601 .InSequence(s)
602 .WillOnce(Return(false));
603
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700604 EXPECT_CALL(mHwComposer,
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700605 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800606 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700607 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800608
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700609 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800610
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700611 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800612 EXPECT_FALSE(state.usesClientComposition);
613 EXPECT_TRUE(state.usesDeviceComposition);
614}
615
616TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
617 android::HWComposer::DeviceRequestedChanges changes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700618 {{nullptr, hal::Composition::CLIENT}},
619 hal::DisplayRequest::FLIP_CLIENT_TARGET,
620 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700621 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Lloyd Pique66d68602019-02-13 14:23:31 -0800622 };
623
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700624 // Since two calls are made to anyLayersRequireClientComposition with different return
625 // values, use a Sequence to control the matching so the values are returned in a known
626 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800627 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700628 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
629 .InSequence(s)
630 .WillOnce(Return(true));
631 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800632 .InSequence(s)
633 .WillOnce(Return(false));
634
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700635 EXPECT_CALL(mHwComposer,
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700636 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _))
637 .WillOnce(DoAll(SetArgPointee<4>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700638 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
639 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
640 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
641 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800642
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700643 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800644
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700645 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800646 EXPECT_FALSE(state.usesClientComposition);
647 EXPECT_TRUE(state.usesDeviceComposition);
648}
649
650/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800651 * Display::getSkipColorTransform()
652 */
653
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700654using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
655
Dominik Laskowski13948602021-03-08 20:48:28 -0800656TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700657 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700658 .WillOnce(Return(true));
Dominik Laskowski13948602021-03-08 20:48:28 -0800659 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
660 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
661 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800662}
663
Dominik Laskowski1162e472020-04-02 19:02:47 -0700664TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800665 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200666 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Peiyong Line9d809e2020-04-14 13:10:48 -0700667 hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800668 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700669 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800670}
671
672/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800673 * Display::anyLayersRequireClientComposition()
674 */
675
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700676using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
677
678TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800679 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
680 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
681 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800682
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700683 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800684}
685
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700686TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800687 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
688 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800689
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700690 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800691}
692
693/*
694 * Display::allLayersRequireClientComposition()
695 */
696
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700697using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
698
699TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800700 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
701 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
702 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800703
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700704 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800705}
706
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700707TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800708 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
709 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800710
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700711 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800712}
713
714/*
715 * Display::applyChangedTypesToLayers()
716 */
717
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700718using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
719
720TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700721 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800722}
723
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700724TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Lloyd Piquede196652020-01-22 17:29:58 -0800725 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800726 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT))
727 .Times(1);
Lloyd Piquede196652020-01-22 17:29:58 -0800728 EXPECT_CALL(*mLayer2.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800729 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE))
730 .Times(1);
731
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700732 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700733 {&mLayer1.hwc2Layer, hal::Composition::CLIENT},
734 {&mLayer2.hwc2Layer, hal::Composition::DEVICE},
735 {&hwc2LayerUnknown, hal::Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800736 });
737}
738
739/*
740 * Display::applyDisplayRequests()
741 */
742
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700743using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
744
745TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700746 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800747
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700748 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800749 EXPECT_FALSE(state.flipClientTarget);
750}
751
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700752TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700753 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800754
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700755 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800756 EXPECT_TRUE(state.flipClientTarget);
757}
758
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700759TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700760 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800761
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700762 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800763 EXPECT_FALSE(state.flipClientTarget);
764}
765
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700766TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700767 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800768
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700769 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800770 EXPECT_TRUE(state.flipClientTarget);
771}
772
773/*
774 * Display::applyLayerRequestsToLayers()
775 */
776
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700777using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
778
779TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800780 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
781 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
782 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800783
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700784 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800785}
786
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700787TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800788 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
789 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
790 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800791
Lloyd Piquede196652020-01-22 17:29:58 -0800792 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800793 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
794 .Times(1);
795
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700796 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700797 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
798 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800799 });
800}
801
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800802/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700803 * Display::applyClientTargetRequests()
804 */
805
806using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
807
808TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
809 Display::ClientTargetProperty clientTargetProperty = {
810 .pixelFormat = hal::PixelFormat::RGB_565,
811 .dataspace = hal::Dataspace::STANDARD_BT470M,
812 };
813
814 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
815 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
816
817 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
818 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
819 mDisplay->applyClientTargetRequests(clientTargetProperty);
820
821 auto& state = mDisplay->getState();
822 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
823}
824
825/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800826 * Display::presentAndGetFrameFences()
827 */
828
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700829using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
830
Dominik Laskowski13948602021-03-08 20:48:28 -0800831TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
832 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
833 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800834
Dominik Laskowski13948602021-03-08 20:48:28 -0800835 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800836
837 ASSERT_TRUE(result.presentFence.get());
838 EXPECT_FALSE(result.presentFence->isValid());
839 EXPECT_EQ(0u, result.layerFences.size());
840}
841
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700842TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800843 sp<Fence> presentFence = new Fence();
844 sp<Fence> layer1Fence = new Fence();
845 sp<Fence> layer2Fence = new Fence();
846
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700847 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700848 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200849 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
850 .WillOnce(Return(presentFence));
851 EXPECT_CALL(mHwComposer,
852 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800853 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200854 EXPECT_CALL(mHwComposer,
855 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800856 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200857 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800858
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700859 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800860
861 EXPECT_EQ(presentFence, result.presentFence);
862
863 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski13948602021-03-08 20:48:28 -0800864 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800865 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski13948602021-03-08 20:48:28 -0800866 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800867 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800868}
869
Lloyd Pique688abd42019-02-15 15:42:24 -0800870/*
871 * Display::setExpensiveRenderingExpected()
872 */
873
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700874using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
875
876TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800877 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700878 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800879
880 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700881 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800882}
883
Lloyd Piqued3d69882019-02-28 16:03:46 -0800884/*
885 * Display::finishFrame()
886 */
887
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700888using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
889
890TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800891 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700892 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800893
894 // We expect no calls to queueBuffer if composition was skipped.
895 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
896
Lloyd Piquea76ce462020-01-14 13:06:37 -0800897 // Expect a call to signal no expensive rendering since there is no client composition.
898 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
899
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700900 mDisplay->editState().isEnabled = true;
901 mDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200902 mDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700903 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800904
905 CompositionRefreshArgs refreshArgs;
906 refreshArgs.repaintEverything = false;
907
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700908 mDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800909}
910
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700911TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski13948602021-03-08 20:48:28 -0800912 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
913 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800914
915 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski13948602021-03-08 20:48:28 -0800916 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800917
918 // We expect no calls to queueBuffer if composition was skipped.
919 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
920
Dominik Laskowski13948602021-03-08 20:48:28 -0800921 gpuDisplay->editState().isEnabled = true;
922 gpuDisplay->editState().usesClientComposition = false;
923 gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
924 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800925
926 CompositionRefreshArgs refreshArgs;
927 refreshArgs.repaintEverything = false;
928
Dominik Laskowski13948602021-03-08 20:48:28 -0800929 gpuDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800930}
931
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700932TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski13948602021-03-08 20:48:28 -0800933 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
934 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800935
936 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski13948602021-03-08 20:48:28 -0800937 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800938
939 // We expect a single call to queueBuffer when composition is not skipped.
940 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
941
Dominik Laskowski13948602021-03-08 20:48:28 -0800942 gpuDisplay->editState().isEnabled = true;
943 gpuDisplay->editState().usesClientComposition = false;
944 gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
945 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800946
947 CompositionRefreshArgs refreshArgs;
948 refreshArgs.repaintEverything = false;
949
Dominik Laskowski13948602021-03-08 20:48:28 -0800950 gpuDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800951}
952
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700953TEST_F(DisplayFinishFrameTest, performsCompositionIfRepaintEverything) {
Dominik Laskowski13948602021-03-08 20:48:28 -0800954 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
955 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800956
957 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski13948602021-03-08 20:48:28 -0800958 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800959
960 // We expect a single call to queueBuffer when composition is not skipped.
961 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
962
Dominik Laskowski13948602021-03-08 20:48:28 -0800963 gpuDisplay->editState().isEnabled = true;
964 gpuDisplay->editState().usesClientComposition = false;
965 gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
966 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800967
968 CompositionRefreshArgs refreshArgs;
969 refreshArgs.repaintEverything = true;
970
Dominik Laskowski13948602021-03-08 20:48:28 -0800971 gpuDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800972}
973
Lloyd Piquec6607552019-12-02 17:57:39 -0800974/*
975 * Display functional tests
976 */
977
978struct DisplayFunctionalTest : public testing::Test {
979 class Display : public impl::Display {
980 public:
Lloyd Piquec6607552019-12-02 17:57:39 -0800981 using impl::Display::injectOutputLayerForTest;
982 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
983 };
984
Lloyd Piquec6607552019-12-02 17:57:39 -0800985 DisplayFunctionalTest() {
986 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
987
988 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
989 }
990
991 NiceMock<android::mock::HWComposer> mHwComposer;
992 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
993 NiceMock<mock::CompositionEngine> mCompositionEngine;
994 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
995 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Dominik Laskowski13948602021-03-08 20:48:28 -0800996
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700997 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
998 Display>(mCompositionEngine,
999 DisplayCreationArgsBuilder()
Dominik Laskowski13948602021-03-08 20:48:28 -08001000 .setId(DEFAULT_DISPLAY_ID)
1001 .setConnectionType(ui::DisplayConnectionType::Internal)
1002 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001003 .setIsSecure(true)
1004 .setLayerStackId(DEFAULT_LAYER_STACK)
1005 .setPowerAdvisor(&mPowerAdvisor)
Dominik Laskowski13948602021-03-08 20:48:28 -08001006 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001007
Lloyd Piquec6607552019-12-02 17:57:39 -08001008 impl::RenderSurface* mRenderSurface =
1009 new impl::RenderSurface{mCompositionEngine, *mDisplay,
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -07001010 RenderSurfaceCreationArgsBuilder()
Dominik Laskowski13948602021-03-08 20:48:28 -08001011 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1012 .setDisplayHeight(DEFAULT_RESOLUTION.height)
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -07001013 .setNativeWindow(mNativeWindow)
1014 .setDisplaySurface(mDisplaySurface)
1015 .build()};
Lloyd Piquec6607552019-12-02 17:57:39 -08001016};
1017
1018TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1019 InSequence seq;
1020
1021 mDisplay->editState().isEnabled = true;
1022
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001023 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001024 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1025
1026 mDisplay->postFramebuffer();
1027}
1028
Lloyd Pique45a165a2018-10-19 11:54:47 -07001029} // namespace
1030} // namespace android::compositionengine