blob: 492db431da35edb65dbfc7d005f9e9f91074af4f [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
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wextra"
20
Lloyd Pique45a165a2018-10-19 11:54:47 -070021#include <cmath>
22
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070023#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070024#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070025#include <compositionengine/DisplaySurface.h>
26#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070027#include <compositionengine/impl/Display.h>
Lloyd Piquec6607552019-12-02 17:57:39 -080028#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070029#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080030#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquec6607552019-12-02 17:57:39 -080031#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquedf336d92019-03-07 21:38:42 -080032#include <compositionengine/mock/LayerFE.h>
chaviw8beb4142019-04-11 13:09:05 -070033#include <compositionengine/mock/NativeWindow.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080034#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070035#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070036#include <gtest/gtest.h>
Lloyd Piquee9eff972020-05-05 12:36:44 -070037#include <renderengine/mock/RenderEngine.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070038#include <ui/Rect.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010039#include <ui/StaticDisplayInfo.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070040
Lloyd Pique66d68602019-02-13 14:23:31 -080041#include "MockHWC2.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070042#include "MockHWComposer.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080043#include "MockPowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070044
45namespace android::compositionengine {
46namespace {
47
Peiyong Line9d809e2020-04-14 13:10:48 -070048namespace hal = android::hardware::graphics::composer::hal;
49
Lloyd Piquef5275482019-01-29 18:42:42 -080050using testing::_;
Lloyd Pique66d68602019-02-13 14:23:31 -080051using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070052using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080053using testing::InSequence;
54using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070055using testing::Pointee;
56using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070057using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070058using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080059using testing::Sequence;
60using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070061using testing::StrictMock;
62
Dominik Laskowskif1833852021-03-23 15:06:50 -070063constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(42u);
Marin Shalamanova524a092020-07-27 21:39:55 +020064// TODO(b/160679868) Use VirtualDisplayId
Dominik Laskowskif1833852021-03-23 15:06:50 -070065constexpr PhysicalDisplayId VIRTUAL_DISPLAY_ID = PhysicalDisplayId::fromPort(43u);
66
Lloyd Piquec6607552019-12-02 17:57:39 -080067constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920;
68constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070069constexpr int32_t DEFAULT_LAYER_STACK = 123;
Lloyd Pique45a165a2018-10-19 11:54:47 -070070
Lloyd Piquede196652020-01-22 17:29:58 -080071struct Layer {
72 Layer() {
73 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
74 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
75 }
76
77 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
78 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
79 StrictMock<HWC2::mock::Layer> hwc2Layer;
80};
81
82struct LayerNoHWC2Layer {
83 LayerNoHWC2Layer() {
84 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
85 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
86 }
87
88 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
89 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
90};
91
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070092struct DisplayTestCommon : public testing::Test {
93 // Uses the full implementation of a display
94 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070095 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070096 using impl::Display::injectOutputLayerForTest;
97 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070098
99 using impl::Display::maybeAllocateDisplayIdForVirtualDisplay;
Lloyd Pique01c77c12019-04-17 12:48:32 -0700100 };
101
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700102 // Uses a special implementation with key internal member functions set up
103 // as mock implementations, to allow for easier testing.
104 struct PartialMockDisplay : public impl::Display {
105 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
106 : mCompositionEngine(compositionEngine) {}
107
108 // compositionengine::Output overrides
109 const OutputCompositionState& getState() const override { return mState; }
110 OutputCompositionState& editState() override { return mState; }
111
112 // compositionengine::impl::Output overrides
113 const CompositionEngine& getCompositionEngine() const override {
114 return mCompositionEngine;
115 };
116
117 // Mock implementation overrides
118 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
119 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
120 compositionengine::OutputLayer*(size_t));
121 MOCK_METHOD2(ensureOutputLayer,
122 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
123 MOCK_METHOD0(finalizePendingOutputLayers, void());
124 MOCK_METHOD0(clearOutputLayers, void());
125 MOCK_CONST_METHOD1(dumpState, void(std::string&));
126 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
127 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
128 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
129 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
130 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
131 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
132 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
133
134 const compositionengine::CompositionEngine& mCompositionEngine;
135 impl::OutputCompositionState mState;
136 };
137
138 static std::string getDisplayNameFromCurrentTest() {
139 const ::testing::TestInfo* const test_info =
140 ::testing::UnitTest::GetInstance()->current_test_info();
141 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
142 }
143
144 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700145 static std::shared_ptr<Display> createDisplay(
146 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700147 compositionengine::DisplayCreationArgs args) {
148 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700149 return impl::createDisplayTemplated<Display>(compositionEngine, args);
150 }
151
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700152 template <typename Display>
153 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
154 const compositionengine::CompositionEngine& compositionEngine,
155 compositionengine::DisplayCreationArgs args) {
156 args.name = getDisplayNameFromCurrentTest();
157 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800158
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700159 display->setConfiguration(args);
160
161 return display;
162 }
163
164 DisplayTestCommon() {
165 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700166 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
167 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700168 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700169 }
170
171 DisplayCreationArgs getDisplayCreationArgsForPhysicalHWCDisplay() {
172 return DisplayCreationArgsBuilder()
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100173 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700174 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
175 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
176 .setIsSecure(true)
177 .setLayerStackId(DEFAULT_LAYER_STACK)
178 .setPowerAdvisor(&mPowerAdvisor)
179 .build();
180 }
181
182 DisplayCreationArgs getDisplayCreationArgsForNonHWCVirtualDisplay() {
183 return DisplayCreationArgsBuilder()
184 .setUseHwcVirtualDisplays(false)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200185 .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700186 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
187 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
188 .setIsSecure(false)
189 .setLayerStackId(DEFAULT_LAYER_STACK)
190 .setPowerAdvisor(&mPowerAdvisor)
191 .build();
192 }
193
194 StrictMock<android::mock::HWComposer> mHwComposer;
195 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700196 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700197 StrictMock<mock::CompositionEngine> mCompositionEngine;
198 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200199 RandomDisplayIdGenerator<GpuVirtualDisplayId> mGpuDisplayIdGenerator;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700200};
201
202struct PartialMockDisplayTestCommon : public DisplayTestCommon {
203 using Display = DisplayTestCommon::PartialMockDisplay;
204 std::shared_ptr<Display> mDisplay =
205 createPartialMockDisplay<Display>(mCompositionEngine,
206 getDisplayCreationArgsForPhysicalHWCDisplay());
207};
208
209struct FullDisplayImplTestCommon : public DisplayTestCommon {
210 using Display = DisplayTestCommon::FullImplDisplay;
211 std::shared_ptr<Display> mDisplay =
212 createDisplay<Display>(mCompositionEngine,
213 getDisplayCreationArgsForPhysicalHWCDisplay());
214};
215
216struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
217 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700218 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800219 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700220 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800221 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700222 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800223 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800224 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700225
Lloyd Piquede196652020-01-22 17:29:58 -0800226 Layer mLayer1;
227 Layer mLayer2;
228 LayerNoHWC2Layer mLayer3;
229 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700230 std::shared_ptr<Display> mDisplay =
231 createDisplay<Display>(mCompositionEngine,
232 getDisplayCreationArgsForPhysicalHWCDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700233};
234
Lloyd Pique66d68602019-02-13 14:23:31 -0800235/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700236 * Basic construction
237 */
238
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700239struct DisplayCreationTest : public DisplayTestCommon {
240 using Display = DisplayTestCommon::FullImplDisplay;
241};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700242
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700243TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
244 auto display =
245 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalHWCDisplay());
246 EXPECT_TRUE(display->isSecure());
247 EXPECT_FALSE(display->isVirtual());
248 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
249}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700250
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700251TEST_F(DisplayCreationTest, createNonHwcVirtualDisplay) {
252 auto display = impl::createDisplay(mCompositionEngine,
253 getDisplayCreationArgsForNonHWCVirtualDisplay());
254 EXPECT_FALSE(display->isSecure());
255 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200256 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700257}
258
259/*
260 * Display::setConfiguration()
261 */
262
263using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
264
265TEST_F(DisplaySetConfigurationTest, configuresInternalSecurePhysicalDisplay) {
266 mDisplay->setConfiguration(
267 DisplayCreationArgsBuilder()
268 .setUseHwcVirtualDisplays(true)
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100269 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700270 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
271 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
272 .setIsSecure(true)
273 .setLayerStackId(DEFAULT_LAYER_STACK)
274 .setPowerAdvisor(&mPowerAdvisor)
275 .setName(getDisplayNameFromCurrentTest())
276 .build());
277
278 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
279 EXPECT_TRUE(mDisplay->isSecure());
280 EXPECT_FALSE(mDisplay->isVirtual());
281 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
282 EXPECT_TRUE(mDisplay->getState().layerStackInternal);
283 EXPECT_FALSE(mDisplay->isValid());
284}
285
286TEST_F(DisplaySetConfigurationTest, configuresExternalInsecurePhysicalDisplay) {
287 mDisplay->setConfiguration(
288 DisplayCreationArgsBuilder()
289 .setUseHwcVirtualDisplays(true)
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100290 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::External})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700291 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
292 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
293 .setIsSecure(false)
294 .setLayerStackId(DEFAULT_LAYER_STACK)
295 .setPowerAdvisor(&mPowerAdvisor)
296 .setName(getDisplayNameFromCurrentTest())
297 .build());
298
299 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
300 EXPECT_FALSE(mDisplay->isSecure());
301 EXPECT_FALSE(mDisplay->isVirtual());
302 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
303 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
304 EXPECT_FALSE(mDisplay->isValid());
305}
306
307TEST_F(DisplaySetConfigurationTest, configuresHwcBackedVirtualDisplay) {
308 EXPECT_CALL(mHwComposer,
309 allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH,
310 Pointee(Eq(static_cast<ui::PixelFormat>(
311 PIXEL_FORMAT_RGBA_8888)))))
312 .WillOnce(Return(VIRTUAL_DISPLAY_ID));
313
314 mDisplay->setConfiguration(
315 DisplayCreationArgsBuilder()
316 .setUseHwcVirtualDisplays(true)
317 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
318 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
319 .setIsSecure(false)
320 .setLayerStackId(DEFAULT_LAYER_STACK)
321 .setPowerAdvisor(&mPowerAdvisor)
322 .setName(getDisplayNameFromCurrentTest())
323 .build());
324
325 EXPECT_EQ(VIRTUAL_DISPLAY_ID, mDisplay->getId());
326 EXPECT_FALSE(mDisplay->isSecure());
327 EXPECT_TRUE(mDisplay->isVirtual());
328 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
329 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
330 EXPECT_FALSE(mDisplay->isValid());
331}
332
333TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfHwcAllocationFails) {
334 EXPECT_CALL(mHwComposer,
335 allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH,
336 Pointee(Eq(static_cast<ui::PixelFormat>(
337 PIXEL_FORMAT_RGBA_8888)))))
338 .WillOnce(Return(std::nullopt));
339
340 mDisplay->setConfiguration(
341 DisplayCreationArgsBuilder()
342 .setUseHwcVirtualDisplays(true)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200343 .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700344 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
345 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
346 .setIsSecure(false)
347 .setLayerStackId(DEFAULT_LAYER_STACK)
348 .setPowerAdvisor(&mPowerAdvisor)
349 .setName(getDisplayNameFromCurrentTest())
350 .build());
351
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200352 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(mDisplay->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700353 EXPECT_FALSE(mDisplay->isSecure());
354 EXPECT_TRUE(mDisplay->isVirtual());
355 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
356 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
357 EXPECT_FALSE(mDisplay->isValid());
358}
359
360TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfShouldNotUseHwc) {
361 mDisplay->setConfiguration(
362 DisplayCreationArgsBuilder()
363 .setUseHwcVirtualDisplays(false)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200364 .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700365 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
366 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
367 .setIsSecure(false)
368 .setLayerStackId(DEFAULT_LAYER_STACK)
369 .setPowerAdvisor(&mPowerAdvisor)
370 .setName(getDisplayNameFromCurrentTest())
371 .build());
372
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200373 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(mDisplay->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700374 EXPECT_FALSE(mDisplay->isSecure());
375 EXPECT_TRUE(mDisplay->isVirtual());
376 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
377 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
378 EXPECT_FALSE(mDisplay->isValid());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700379}
380
Lloyd Pique66d68602019-02-13 14:23:31 -0800381/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700382 * Display::disconnect()
383 */
384
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700385using DisplayDisconnectTest = PartialMockDisplayTestCommon;
386
387TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200388 // The first call to disconnect will disconnect the display with the HWC.
389 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700390 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700391
392 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200393 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700394 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700395}
396
Lloyd Pique66d68602019-02-13 14:23:31 -0800397/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700398 * Display::setColorTransform()
399 */
400
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700401using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
402
403TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800404 // No change does nothing
405 CompositionRefreshArgs refreshArgs;
406 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700407 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800408
Lloyd Pique32cbe282018-10-19 13:09:22 -0700409 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800410 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700411
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200412 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
413 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700414
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800415 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700416 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700417
418 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800419 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700420
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200421 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
422 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700423
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800424 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700425 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700426}
427
Lloyd Pique66d68602019-02-13 14:23:31 -0800428/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700429 * Display::setColorMode()
430 */
431
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700432using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
433
434TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800435 using ColorProfile = Output::ColorProfile;
436
Lloyd Pique31cb2942018-10-19 17:23:03 -0700437 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700438 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800439 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700440 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700441
Lloyd Piquef5275482019-01-29 18:42:42 -0800442 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
443 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700444
445 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700446 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
447 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
448 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
449 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700450
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700451 // Otherwise if the values are unchanged, nothing happens
452 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
453 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700454
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
456 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
457 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
458 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700459
460 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800461 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700462 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800463 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700464 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
465 .Times(1);
466
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700467 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
468 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
469 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700470
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700471 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
472 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
473 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
474 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700475}
476
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700477TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800478 using ColorProfile = Output::ColorProfile;
479
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700480 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
481 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700482
Lloyd Piquef5275482019-01-29 18:42:42 -0800483 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700484 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800485 std::unique_ptr<DisplayColorProfile>(colorProfile));
486
487 EXPECT_CALL(*colorProfile,
488 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
489 ui::Dataspace::UNKNOWN))
490 .WillOnce(Return(ui::Dataspace::UNKNOWN));
491
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700492 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800493 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
494 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700495
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700496 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
497 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
498 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
499 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700500}
501
Lloyd Pique66d68602019-02-13 14:23:31 -0800502/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700503 * Display::createDisplayColorProfile()
504 */
505
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700506using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
507
508TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700509 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
510 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700511 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
512 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700513 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700514}
515
Lloyd Pique66d68602019-02-13 14:23:31 -0800516/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700517 * Display::createRenderSurface()
518 */
519
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700520using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
521
522TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700523 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700524 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700525 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
526 .setDisplayWidth(640)
527 .setDisplayHeight(480)
528 .setNativeWindow(mNativeWindow)
529 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700530 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700531}
532
Lloyd Pique66d68602019-02-13 14:23:31 -0800533/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800534 * Display::createOutputLayer()
535 */
536
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700537using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
538
539TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800540 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800541 StrictMock<HWC2::mock::Layer> hwcLayer;
542
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200543 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
544 .WillOnce(Return(&hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800545
Lloyd Piquede196652020-01-22 17:29:58 -0800546 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800547
548 EXPECT_EQ(&hwcLayer, outputLayer->getHwcLayer());
549
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200550 EXPECT_CALL(mHwComposer, destroyLayer(HalDisplayId(DEFAULT_DISPLAY_ID), &hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800551 outputLayer.reset();
552}
553
554/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800555 * Display::setReleasedLayers()
556 */
557
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700558using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
559
560TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNotHwcDisplay) {
561 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
562 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800563
564 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800565
566 {
567 Output::ReleasedLayers releasedLayers;
568 releasedLayers.emplace_back(layerXLayerFE);
569 nonHwcDisplay->setReleasedLayers(std::move(releasedLayers));
570 }
571
572 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800573 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800574
575 nonHwcDisplay->setReleasedLayers(refreshArgs);
576
577 const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest();
578 ASSERT_EQ(1, releasedLayers.size());
579}
580
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700581TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800582 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
583
584 {
585 Output::ReleasedLayers releasedLayers;
586 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700587 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800588 }
589
590 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700591 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800592
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700593 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800594 ASSERT_EQ(1, releasedLayers.size());
595}
596
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700597TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800598 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800599
600 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800601 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
602 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
603 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800604
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700605 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800606
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700607 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800608 ASSERT_EQ(2, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800609 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
610 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800611}
612
613/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800614 * Display::chooseCompositionStrategy()
615 */
616
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700617using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800618
619TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700620 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
621 std::shared_ptr<Display> nonHwcDisplay =
622 createPartialMockDisplay<Display>(mCompositionEngine, args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200623 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(nonHwcDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800624
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700625 nonHwcDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800626
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700627 auto& state = nonHwcDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800628 EXPECT_TRUE(state.usesClientComposition);
629 EXPECT_FALSE(state.usesDeviceComposition);
630}
631
632TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700633 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200634 EXPECT_CALL(mHwComposer,
635 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800636 .WillOnce(Return(INVALID_OPERATION));
637
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700638 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800639
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700640 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800641 EXPECT_TRUE(state.usesClientComposition);
642 EXPECT_FALSE(state.usesDeviceComposition);
643}
644
645TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700646 // Since two calls are made to anyLayersRequireClientComposition with different return
647 // values, use a Sequence to control the matching so the values are returned in a known
648 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800649 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700650 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
651 .InSequence(s)
652 .WillOnce(Return(true));
653 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800654 .InSequence(s)
655 .WillOnce(Return(false));
656
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200657 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800658 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700659 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800660
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700661 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800662
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700663 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800664 EXPECT_FALSE(state.usesClientComposition);
665 EXPECT_TRUE(state.usesDeviceComposition);
666}
667
668TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
669 android::HWComposer::DeviceRequestedChanges changes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700670 {{nullptr, hal::Composition::CLIENT}},
671 hal::DisplayRequest::FLIP_CLIENT_TARGET,
672 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700673 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Lloyd Pique66d68602019-02-13 14:23:31 -0800674 };
675
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700676 // Since two calls are made to anyLayersRequireClientComposition with different return
677 // values, use a Sequence to control the matching so the values are returned in a known
678 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800679 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700680 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
681 .InSequence(s)
682 .WillOnce(Return(true));
683 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800684 .InSequence(s)
685 .WillOnce(Return(false));
686
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200687 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800688 .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700689 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
690 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
691 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
692 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800693
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700694 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800695
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700696 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800697 EXPECT_FALSE(state.usesClientComposition);
698 EXPECT_TRUE(state.usesDeviceComposition);
699}
700
701/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800702 * Display::getSkipColorTransform()
703 */
704
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700705using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
706
Dominik Laskowski1162e472020-04-02 19:02:47 -0700707TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfNonHwcDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700708 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700709 .WillOnce(Return(true));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700710 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
711 auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)};
Dominik Laskowski1162e472020-04-02 19:02:47 -0700712 EXPECT_TRUE(nonHwcDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800713}
714
Dominik Laskowski1162e472020-04-02 19:02:47 -0700715TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800716 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200717 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Peiyong Line9d809e2020-04-14 13:10:48 -0700718 hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800719 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700720 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800721}
722
723/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800724 * Display::anyLayersRequireClientComposition()
725 */
726
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700727using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
728
729TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800730 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
731 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
732 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800733
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700734 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800735}
736
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700737TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800738 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
739 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800740
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700741 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800742}
743
744/*
745 * Display::allLayersRequireClientComposition()
746 */
747
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700748using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
749
750TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800751 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
752 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
753 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800754
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700755 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800756}
757
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700758TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800759 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
760 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800761
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700762 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800763}
764
765/*
766 * Display::applyChangedTypesToLayers()
767 */
768
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700769using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
770
771TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700772 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800773}
774
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700775TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Lloyd Piquede196652020-01-22 17:29:58 -0800776 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800777 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT))
778 .Times(1);
Lloyd Piquede196652020-01-22 17:29:58 -0800779 EXPECT_CALL(*mLayer2.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800780 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE))
781 .Times(1);
782
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700783 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700784 {&mLayer1.hwc2Layer, hal::Composition::CLIENT},
785 {&mLayer2.hwc2Layer, hal::Composition::DEVICE},
786 {&hwc2LayerUnknown, hal::Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800787 });
788}
789
790/*
791 * Display::applyDisplayRequests()
792 */
793
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700794using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
795
796TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700797 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800798
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700799 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800800 EXPECT_FALSE(state.flipClientTarget);
801}
802
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700803TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700804 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800805
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700806 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800807 EXPECT_TRUE(state.flipClientTarget);
808}
809
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700810TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700811 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800812
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700813 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800814 EXPECT_FALSE(state.flipClientTarget);
815}
816
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700817TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700818 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800819
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700820 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800821 EXPECT_TRUE(state.flipClientTarget);
822}
823
824/*
825 * Display::applyLayerRequestsToLayers()
826 */
827
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700828using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
829
830TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800831 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
832 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
833 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800834
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700835 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800836}
837
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700838TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800839 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
840 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
841 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800842
Lloyd Piquede196652020-01-22 17:29:58 -0800843 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800844 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
845 .Times(1);
846
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700847 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700848 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
849 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800850 });
851}
852
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800853/*
854 * Display::presentAndGetFrameFences()
855 */
856
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700857using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
858
859TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnNonHwcDisplay) {
860 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
861 auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800862
863 auto result = nonHwcDisplay->presentAndGetFrameFences();
864
865 ASSERT_TRUE(result.presentFence.get());
866 EXPECT_FALSE(result.presentFence->isValid());
867 EXPECT_EQ(0u, result.layerFences.size());
868}
869
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700870TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800871 sp<Fence> presentFence = new Fence();
872 sp<Fence> layer1Fence = new Fence();
873 sp<Fence> layer2Fence = new Fence();
874
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200875 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
876 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
877 .WillOnce(Return(presentFence));
878 EXPECT_CALL(mHwComposer,
879 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800880 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200881 EXPECT_CALL(mHwComposer,
882 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800883 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200884 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800885
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700886 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800887
888 EXPECT_EQ(presentFence, result.presentFence);
889
890 EXPECT_EQ(2u, result.layerFences.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800891 ASSERT_EQ(1, result.layerFences.count(&mLayer1.hwc2Layer));
892 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
893 ASSERT_EQ(1, result.layerFences.count(&mLayer2.hwc2Layer));
894 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800895}
896
Lloyd Pique688abd42019-02-15 15:42:24 -0800897/*
898 * Display::setExpensiveRenderingExpected()
899 */
900
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700901using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
902
903TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800904 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700905 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800906
907 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700908 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800909}
910
Lloyd Piqued3d69882019-02-28 16:03:46 -0800911/*
912 * Display::finishFrame()
913 */
914
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700915using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
916
917TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800918 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700919 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800920
921 // We expect no calls to queueBuffer if composition was skipped.
922 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
923
Lloyd Piquea76ce462020-01-14 13:06:37 -0800924 // Expect a call to signal no expensive rendering since there is no client composition.
925 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
926
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700927 mDisplay->editState().isEnabled = true;
928 mDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200929 mDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700930 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800931
932 CompositionRefreshArgs refreshArgs;
933 refreshArgs.repaintEverything = false;
934
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700935 mDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800936}
937
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700938TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
939 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
940 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800941
942 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
943 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
944
945 // We expect no calls to queueBuffer if composition was skipped.
946 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
947
948 nonHwcDisplay->editState().isEnabled = true;
949 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200950 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800951 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
952
953 CompositionRefreshArgs refreshArgs;
954 refreshArgs.repaintEverything = false;
955
956 nonHwcDisplay->finishFrame(refreshArgs);
957}
958
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700959TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
960 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
961 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800962
963 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
964 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
965
966 // We expect a single call to queueBuffer when composition is not skipped.
967 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
968
969 nonHwcDisplay->editState().isEnabled = true;
970 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200971 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800972 nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
973
974 CompositionRefreshArgs refreshArgs;
975 refreshArgs.repaintEverything = false;
976
977 nonHwcDisplay->finishFrame(refreshArgs);
978}
979
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700980TEST_F(DisplayFinishFrameTest, performsCompositionIfRepaintEverything) {
981 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
982 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800983
984 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
985 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
986
987 // We expect a single call to queueBuffer when composition is not skipped.
988 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
989
990 nonHwcDisplay->editState().isEnabled = true;
991 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200992 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800993 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
994
995 CompositionRefreshArgs refreshArgs;
996 refreshArgs.repaintEverything = true;
997
998 nonHwcDisplay->finishFrame(refreshArgs);
999}
1000
Lloyd Piquec6607552019-12-02 17:57:39 -08001001/*
1002 * Display functional tests
1003 */
1004
1005struct DisplayFunctionalTest : public testing::Test {
1006 class Display : public impl::Display {
1007 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001008 using impl::Display::injectOutputLayerForTest;
1009 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1010 };
1011
Lloyd Piquec6607552019-12-02 17:57:39 -08001012 DisplayFunctionalTest() {
1013 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
1014
1015 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1016 }
1017
1018 NiceMock<android::mock::HWComposer> mHwComposer;
1019 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1020 NiceMock<mock::CompositionEngine> mCompositionEngine;
1021 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1022 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001023 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
1024 Display>(mCompositionEngine,
1025 DisplayCreationArgsBuilder()
Marin Shalamanov228f46b2021-01-28 21:11:45 +01001026 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001027 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
1028 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
1029 .setIsSecure(true)
1030 .setLayerStackId(DEFAULT_LAYER_STACK)
1031 .setPowerAdvisor(&mPowerAdvisor)
1032 .build()
1033
1034 );
Lloyd Piquec6607552019-12-02 17:57:39 -08001035 impl::RenderSurface* mRenderSurface =
1036 new impl::RenderSurface{mCompositionEngine, *mDisplay,
Dominik Laskowski50121d52021-04-23 13:01:16 -07001037 RenderSurfaceCreationArgsBuilder()
1038 .setDisplayWidth(DEFAULT_DISPLAY_WIDTH)
1039 .setDisplayHeight(DEFAULT_DISPLAY_HEIGHT)
1040 .setNativeWindow(mNativeWindow)
1041 .setDisplaySurface(mDisplaySurface)
1042 .build()};
Lloyd Piquec6607552019-12-02 17:57:39 -08001043};
1044
1045TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1046 InSequence seq;
1047
1048 mDisplay->editState().isEnabled = true;
1049
1050 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_));
1051 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1052
1053 mDisplay->postFramebuffer();
1054}
1055
Lloyd Pique45a165a2018-10-19 11:54:47 -07001056} // namespace
1057} // namespace android::compositionengine
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001058
1059// TODO(b/129481165): remove the #pragma below and fix conversion issues
Dominik Laskowskif1833852021-03-23 15:06:50 -07001060#pragma clang diagnostic pop // ignored "-Wextra"