blob: b31e64ac0d2162afd6834b29ef59c1513a7dd9d9 [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);
525 mDisplay->createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr});
526 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700527}
528
Lloyd Pique66d68602019-02-13 14:23:31 -0800529/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800530 * Display::createOutputLayer()
531 */
532
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700533using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
534
535TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800536 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800537 StrictMock<HWC2::mock::Layer> hwcLayer;
538
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200539 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
540 .WillOnce(Return(&hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800541
Lloyd Piquede196652020-01-22 17:29:58 -0800542 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800543
544 EXPECT_EQ(&hwcLayer, outputLayer->getHwcLayer());
545
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200546 EXPECT_CALL(mHwComposer, destroyLayer(HalDisplayId(DEFAULT_DISPLAY_ID), &hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800547 outputLayer.reset();
548}
549
550/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800551 * Display::setReleasedLayers()
552 */
553
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700554using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
555
556TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNotHwcDisplay) {
557 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
558 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800559
560 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800561
562 {
563 Output::ReleasedLayers releasedLayers;
564 releasedLayers.emplace_back(layerXLayerFE);
565 nonHwcDisplay->setReleasedLayers(std::move(releasedLayers));
566 }
567
568 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800569 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800570
571 nonHwcDisplay->setReleasedLayers(refreshArgs);
572
573 const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest();
574 ASSERT_EQ(1, releasedLayers.size());
575}
576
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700577TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800578 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
579
580 {
581 Output::ReleasedLayers releasedLayers;
582 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700583 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800584 }
585
586 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700587 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800588
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700589 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800590 ASSERT_EQ(1, releasedLayers.size());
591}
592
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700593TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800594 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800595
596 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800597 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
598 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
599 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800600
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700601 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800602
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700603 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800604 ASSERT_EQ(2, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800605 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
606 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800607}
608
609/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800610 * Display::chooseCompositionStrategy()
611 */
612
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700613using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800614
615TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700616 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
617 std::shared_ptr<Display> nonHwcDisplay =
618 createPartialMockDisplay<Display>(mCompositionEngine, args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200619 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(nonHwcDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800620
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700621 nonHwcDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800622
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700623 auto& state = nonHwcDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800624 EXPECT_TRUE(state.usesClientComposition);
625 EXPECT_FALSE(state.usesDeviceComposition);
626}
627
628TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700629 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200630 EXPECT_CALL(mHwComposer,
631 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800632 .WillOnce(Return(INVALID_OPERATION));
633
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700634 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800635
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700636 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800637 EXPECT_TRUE(state.usesClientComposition);
638 EXPECT_FALSE(state.usesDeviceComposition);
639}
640
641TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700642 // Since two calls are made to anyLayersRequireClientComposition with different return
643 // values, use a Sequence to control the matching so the values are returned in a known
644 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800645 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700646 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
647 .InSequence(s)
648 .WillOnce(Return(true));
649 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800650 .InSequence(s)
651 .WillOnce(Return(false));
652
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200653 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800654 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700655 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800656
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700657 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800658
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700659 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800660 EXPECT_FALSE(state.usesClientComposition);
661 EXPECT_TRUE(state.usesDeviceComposition);
662}
663
664TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
665 android::HWComposer::DeviceRequestedChanges changes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700666 {{nullptr, hal::Composition::CLIENT}},
667 hal::DisplayRequest::FLIP_CLIENT_TARGET,
668 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700669 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Lloyd Pique66d68602019-02-13 14:23:31 -0800670 };
671
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700672 // Since two calls are made to anyLayersRequireClientComposition with different return
673 // values, use a Sequence to control the matching so the values are returned in a known
674 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800675 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700676 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
677 .InSequence(s)
678 .WillOnce(Return(true));
679 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800680 .InSequence(s)
681 .WillOnce(Return(false));
682
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200683 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800684 .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700685 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
686 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
687 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
688 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800689
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700690 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800691
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700692 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800693 EXPECT_FALSE(state.usesClientComposition);
694 EXPECT_TRUE(state.usesDeviceComposition);
695}
696
697/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800698 * Display::getSkipColorTransform()
699 */
700
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700701using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
702
Dominik Laskowski1162e472020-04-02 19:02:47 -0700703TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfNonHwcDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700704 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700705 .WillOnce(Return(true));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700706 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
707 auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)};
Dominik Laskowski1162e472020-04-02 19:02:47 -0700708 EXPECT_TRUE(nonHwcDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800709}
710
Dominik Laskowski1162e472020-04-02 19:02:47 -0700711TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800712 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200713 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Peiyong Line9d809e2020-04-14 13:10:48 -0700714 hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800715 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700716 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800717}
718
719/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800720 * Display::anyLayersRequireClientComposition()
721 */
722
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700723using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
724
725TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800726 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
727 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
728 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800729
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700730 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800731}
732
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700733TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800734 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
735 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800736
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700737 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800738}
739
740/*
741 * Display::allLayersRequireClientComposition()
742 */
743
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700744using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
745
746TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800747 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
748 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
749 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800750
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700751 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800752}
753
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700754TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800755 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
756 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800757
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700758 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800759}
760
761/*
762 * Display::applyChangedTypesToLayers()
763 */
764
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700765using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
766
767TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700768 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800769}
770
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700771TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Lloyd Piquede196652020-01-22 17:29:58 -0800772 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800773 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT))
774 .Times(1);
Lloyd Piquede196652020-01-22 17:29:58 -0800775 EXPECT_CALL(*mLayer2.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800776 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE))
777 .Times(1);
778
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700779 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700780 {&mLayer1.hwc2Layer, hal::Composition::CLIENT},
781 {&mLayer2.hwc2Layer, hal::Composition::DEVICE},
782 {&hwc2LayerUnknown, hal::Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800783 });
784}
785
786/*
787 * Display::applyDisplayRequests()
788 */
789
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700790using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
791
792TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700793 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800794
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700795 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800796 EXPECT_FALSE(state.flipClientTarget);
797}
798
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700799TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700800 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800801
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700802 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800803 EXPECT_TRUE(state.flipClientTarget);
804}
805
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700806TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700807 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800808
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700809 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800810 EXPECT_FALSE(state.flipClientTarget);
811}
812
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700813TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700814 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800815
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700816 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800817 EXPECT_TRUE(state.flipClientTarget);
818}
819
820/*
821 * Display::applyLayerRequestsToLayers()
822 */
823
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700824using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
825
826TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800827 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
828 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
829 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800830
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700831 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800832}
833
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700834TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800835 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
836 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
837 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800838
Lloyd Piquede196652020-01-22 17:29:58 -0800839 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800840 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
841 .Times(1);
842
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700843 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700844 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
845 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800846 });
847}
848
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800849/*
850 * Display::presentAndGetFrameFences()
851 */
852
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700853using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
854
855TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnNonHwcDisplay) {
856 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
857 auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800858
859 auto result = nonHwcDisplay->presentAndGetFrameFences();
860
861 ASSERT_TRUE(result.presentFence.get());
862 EXPECT_FALSE(result.presentFence->isValid());
863 EXPECT_EQ(0u, result.layerFences.size());
864}
865
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700866TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800867 sp<Fence> presentFence = new Fence();
868 sp<Fence> layer1Fence = new Fence();
869 sp<Fence> layer2Fence = new Fence();
870
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200871 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
872 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
873 .WillOnce(Return(presentFence));
874 EXPECT_CALL(mHwComposer,
875 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800876 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200877 EXPECT_CALL(mHwComposer,
878 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800879 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200880 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800881
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700882 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800883
884 EXPECT_EQ(presentFence, result.presentFence);
885
886 EXPECT_EQ(2u, result.layerFences.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800887 ASSERT_EQ(1, result.layerFences.count(&mLayer1.hwc2Layer));
888 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
889 ASSERT_EQ(1, result.layerFences.count(&mLayer2.hwc2Layer));
890 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800891}
892
Lloyd Pique688abd42019-02-15 15:42:24 -0800893/*
894 * Display::setExpensiveRenderingExpected()
895 */
896
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700897using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
898
899TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800900 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700901 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800902
903 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700904 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800905}
906
Lloyd Piqued3d69882019-02-28 16:03:46 -0800907/*
908 * Display::finishFrame()
909 */
910
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700911using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
912
913TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800914 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700915 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800916
917 // We expect no calls to queueBuffer if composition was skipped.
918 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
919
Lloyd Piquea76ce462020-01-14 13:06:37 -0800920 // Expect a call to signal no expensive rendering since there is no client composition.
921 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
922
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700923 mDisplay->editState().isEnabled = true;
924 mDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200925 mDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700926 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800927
928 CompositionRefreshArgs refreshArgs;
929 refreshArgs.repaintEverything = false;
930
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700931 mDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800932}
933
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700934TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
935 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
936 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800937
938 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
939 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
940
941 // We expect no calls to queueBuffer if composition was skipped.
942 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
943
944 nonHwcDisplay->editState().isEnabled = true;
945 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200946 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800947 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
948
949 CompositionRefreshArgs refreshArgs;
950 refreshArgs.repaintEverything = false;
951
952 nonHwcDisplay->finishFrame(refreshArgs);
953}
954
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700955TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
956 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
957 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800958
959 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
960 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
961
962 // We expect a single call to queueBuffer when composition is not skipped.
963 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
964
965 nonHwcDisplay->editState().isEnabled = true;
966 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200967 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800968 nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
969
970 CompositionRefreshArgs refreshArgs;
971 refreshArgs.repaintEverything = false;
972
973 nonHwcDisplay->finishFrame(refreshArgs);
974}
975
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700976TEST_F(DisplayFinishFrameTest, performsCompositionIfRepaintEverything) {
977 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
978 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800979
980 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
981 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
982
983 // We expect a single call to queueBuffer when composition is not skipped.
984 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
985
986 nonHwcDisplay->editState().isEnabled = true;
987 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200988 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800989 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
990
991 CompositionRefreshArgs refreshArgs;
992 refreshArgs.repaintEverything = true;
993
994 nonHwcDisplay->finishFrame(refreshArgs);
995}
996
Lloyd Piquec6607552019-12-02 17:57:39 -0800997/*
998 * Display functional tests
999 */
1000
1001struct DisplayFunctionalTest : public testing::Test {
1002 class Display : public impl::Display {
1003 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001004 using impl::Display::injectOutputLayerForTest;
1005 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1006 };
1007
Lloyd Piquec6607552019-12-02 17:57:39 -08001008 DisplayFunctionalTest() {
1009 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
1010
1011 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1012 }
1013
1014 NiceMock<android::mock::HWComposer> mHwComposer;
1015 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1016 NiceMock<mock::CompositionEngine> mCompositionEngine;
1017 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1018 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001019 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
1020 Display>(mCompositionEngine,
1021 DisplayCreationArgsBuilder()
Marin Shalamanov228f46b2021-01-28 21:11:45 +01001022 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001023 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
1024 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
1025 .setIsSecure(true)
1026 .setLayerStackId(DEFAULT_LAYER_STACK)
1027 .setPowerAdvisor(&mPowerAdvisor)
1028 .build()
1029
1030 );
Lloyd Piquec6607552019-12-02 17:57:39 -08001031 impl::RenderSurface* mRenderSurface =
1032 new impl::RenderSurface{mCompositionEngine, *mDisplay,
1033 RenderSurfaceCreationArgs{DEFAULT_DISPLAY_WIDTH,
1034 DEFAULT_DISPLAY_HEIGHT, mNativeWindow,
1035 mDisplaySurface}};
1036};
1037
1038TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1039 InSequence seq;
1040
1041 mDisplay->editState().isEnabled = true;
1042
1043 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_));
1044 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1045
1046 mDisplay->postFramebuffer();
1047}
1048
Lloyd Pique45a165a2018-10-19 11:54:47 -07001049} // namespace
1050} // namespace android::compositionengine
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001051
1052// TODO(b/129481165): remove the #pragma below and fix conversion issues
Dominik Laskowskif1833852021-03-23 15:06:50 -07001053#pragma clang diagnostic pop // ignored "-Wextra"