blob: dbd1f842bbe300342e9d8af19824e53118fb9bb7 [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
Marin Shalamanova524a092020-07-27 21:39:55 +020063constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId{42};
64// TODO(b/160679868) Use VirtualDisplayId
65constexpr PhysicalDisplayId VIRTUAL_DISPLAY_ID = PhysicalDisplayId{43};
Lloyd Piquec6607552019-12-02 17:57:39 -080066constexpr int32_t DEFAULT_DISPLAY_WIDTH = 1920;
67constexpr int32_t DEFAULT_DISPLAY_HEIGHT = 1080;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070068constexpr int32_t DEFAULT_LAYER_STACK = 123;
Lloyd Pique45a165a2018-10-19 11:54:47 -070069
Lloyd Piquede196652020-01-22 17:29:58 -080070struct Layer {
71 Layer() {
72 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
73 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
74 }
75
76 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
77 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
78 StrictMock<HWC2::mock::Layer> hwc2Layer;
79};
80
81struct LayerNoHWC2Layer {
82 LayerNoHWC2Layer() {
83 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
84 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
85 }
86
87 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
88 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
89};
90
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070091struct DisplayTestCommon : public testing::Test {
92 // Uses the full implementation of a display
93 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070094 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070095 using impl::Display::injectOutputLayerForTest;
96 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070097
98 using impl::Display::maybeAllocateDisplayIdForVirtualDisplay;
Lloyd Pique01c77c12019-04-17 12:48:32 -070099 };
100
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700101 // Uses a special implementation with key internal member functions set up
102 // as mock implementations, to allow for easier testing.
103 struct PartialMockDisplay : public impl::Display {
104 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
105 : mCompositionEngine(compositionEngine) {}
106
107 // compositionengine::Output overrides
108 const OutputCompositionState& getState() const override { return mState; }
109 OutputCompositionState& editState() override { return mState; }
110
111 // compositionengine::impl::Output overrides
112 const CompositionEngine& getCompositionEngine() const override {
113 return mCompositionEngine;
114 };
115
116 // Mock implementation overrides
117 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
118 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
119 compositionengine::OutputLayer*(size_t));
120 MOCK_METHOD2(ensureOutputLayer,
121 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
122 MOCK_METHOD0(finalizePendingOutputLayers, void());
123 MOCK_METHOD0(clearOutputLayers, void());
124 MOCK_CONST_METHOD1(dumpState, void(std::string&));
125 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
126 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
127 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
128 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
129 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
130 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
131 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
132
133 const compositionengine::CompositionEngine& mCompositionEngine;
134 impl::OutputCompositionState mState;
135 };
136
137 static std::string getDisplayNameFromCurrentTest() {
138 const ::testing::TestInfo* const test_info =
139 ::testing::UnitTest::GetInstance()->current_test_info();
140 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
141 }
142
143 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700144 static std::shared_ptr<Display> createDisplay(
145 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700146 compositionengine::DisplayCreationArgs args) {
147 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700148 return impl::createDisplayTemplated<Display>(compositionEngine, args);
149 }
150
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700151 template <typename Display>
152 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
153 const compositionengine::CompositionEngine& compositionEngine,
154 compositionengine::DisplayCreationArgs args) {
155 args.name = getDisplayNameFromCurrentTest();
156 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800157
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700158 display->setConfiguration(args);
159
160 return display;
161 }
162
163 DisplayTestCommon() {
164 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700165 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
166 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700167 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700168 }
169
170 DisplayCreationArgs getDisplayCreationArgsForPhysicalHWCDisplay() {
171 return DisplayCreationArgsBuilder()
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100172 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700173 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
174 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
175 .setIsSecure(true)
176 .setLayerStackId(DEFAULT_LAYER_STACK)
177 .setPowerAdvisor(&mPowerAdvisor)
178 .build();
179 }
180
181 DisplayCreationArgs getDisplayCreationArgsForNonHWCVirtualDisplay() {
182 return DisplayCreationArgsBuilder()
183 .setUseHwcVirtualDisplays(false)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200184 .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700185 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
186 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
187 .setIsSecure(false)
188 .setLayerStackId(DEFAULT_LAYER_STACK)
189 .setPowerAdvisor(&mPowerAdvisor)
190 .build();
191 }
192
193 StrictMock<android::mock::HWComposer> mHwComposer;
194 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700195 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700196 StrictMock<mock::CompositionEngine> mCompositionEngine;
197 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200198 RandomDisplayIdGenerator<GpuVirtualDisplayId> mGpuDisplayIdGenerator;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700199};
200
201struct PartialMockDisplayTestCommon : public DisplayTestCommon {
202 using Display = DisplayTestCommon::PartialMockDisplay;
203 std::shared_ptr<Display> mDisplay =
204 createPartialMockDisplay<Display>(mCompositionEngine,
205 getDisplayCreationArgsForPhysicalHWCDisplay());
206};
207
208struct FullDisplayImplTestCommon : public DisplayTestCommon {
209 using Display = DisplayTestCommon::FullImplDisplay;
210 std::shared_ptr<Display> mDisplay =
211 createDisplay<Display>(mCompositionEngine,
212 getDisplayCreationArgsForPhysicalHWCDisplay());
213};
214
215struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
216 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700217 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800218 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700219 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800220 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700221 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800222 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800223 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700224
Lloyd Piquede196652020-01-22 17:29:58 -0800225 Layer mLayer1;
226 Layer mLayer2;
227 LayerNoHWC2Layer mLayer3;
228 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700229 std::shared_ptr<Display> mDisplay =
230 createDisplay<Display>(mCompositionEngine,
231 getDisplayCreationArgsForPhysicalHWCDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700232};
233
Lloyd Pique66d68602019-02-13 14:23:31 -0800234/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700235 * Basic construction
236 */
237
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700238struct DisplayCreationTest : public DisplayTestCommon {
239 using Display = DisplayTestCommon::FullImplDisplay;
240};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700241
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700242TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
243 auto display =
244 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalHWCDisplay());
245 EXPECT_TRUE(display->isSecure());
246 EXPECT_FALSE(display->isVirtual());
247 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
248}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700249
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700250TEST_F(DisplayCreationTest, createNonHwcVirtualDisplay) {
251 auto display = impl::createDisplay(mCompositionEngine,
252 getDisplayCreationArgsForNonHWCVirtualDisplay());
253 EXPECT_FALSE(display->isSecure());
254 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200255 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700256}
257
258/*
259 * Display::setConfiguration()
260 */
261
262using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
263
264TEST_F(DisplaySetConfigurationTest, configuresInternalSecurePhysicalDisplay) {
265 mDisplay->setConfiguration(
266 DisplayCreationArgsBuilder()
267 .setUseHwcVirtualDisplays(true)
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100268 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700269 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
270 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
271 .setIsSecure(true)
272 .setLayerStackId(DEFAULT_LAYER_STACK)
273 .setPowerAdvisor(&mPowerAdvisor)
274 .setName(getDisplayNameFromCurrentTest())
275 .build());
276
277 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
278 EXPECT_TRUE(mDisplay->isSecure());
279 EXPECT_FALSE(mDisplay->isVirtual());
280 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
281 EXPECT_TRUE(mDisplay->getState().layerStackInternal);
282 EXPECT_FALSE(mDisplay->isValid());
283}
284
285TEST_F(DisplaySetConfigurationTest, configuresExternalInsecurePhysicalDisplay) {
286 mDisplay->setConfiguration(
287 DisplayCreationArgsBuilder()
288 .setUseHwcVirtualDisplays(true)
Marin Shalamanov228f46b2021-01-28 21:11:45 +0100289 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::External})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700290 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
291 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
292 .setIsSecure(false)
293 .setLayerStackId(DEFAULT_LAYER_STACK)
294 .setPowerAdvisor(&mPowerAdvisor)
295 .setName(getDisplayNameFromCurrentTest())
296 .build());
297
298 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
299 EXPECT_FALSE(mDisplay->isSecure());
300 EXPECT_FALSE(mDisplay->isVirtual());
301 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
302 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
303 EXPECT_FALSE(mDisplay->isValid());
304}
305
306TEST_F(DisplaySetConfigurationTest, configuresHwcBackedVirtualDisplay) {
307 EXPECT_CALL(mHwComposer,
308 allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH,
309 Pointee(Eq(static_cast<ui::PixelFormat>(
310 PIXEL_FORMAT_RGBA_8888)))))
311 .WillOnce(Return(VIRTUAL_DISPLAY_ID));
312
313 mDisplay->setConfiguration(
314 DisplayCreationArgsBuilder()
315 .setUseHwcVirtualDisplays(true)
316 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
317 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
318 .setIsSecure(false)
319 .setLayerStackId(DEFAULT_LAYER_STACK)
320 .setPowerAdvisor(&mPowerAdvisor)
321 .setName(getDisplayNameFromCurrentTest())
322 .build());
323
324 EXPECT_EQ(VIRTUAL_DISPLAY_ID, mDisplay->getId());
325 EXPECT_FALSE(mDisplay->isSecure());
326 EXPECT_TRUE(mDisplay->isVirtual());
327 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
328 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
329 EXPECT_FALSE(mDisplay->isValid());
330}
331
332TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfHwcAllocationFails) {
333 EXPECT_CALL(mHwComposer,
334 allocateVirtualDisplay(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH,
335 Pointee(Eq(static_cast<ui::PixelFormat>(
336 PIXEL_FORMAT_RGBA_8888)))))
337 .WillOnce(Return(std::nullopt));
338
339 mDisplay->setConfiguration(
340 DisplayCreationArgsBuilder()
341 .setUseHwcVirtualDisplays(true)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200342 .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700343 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
344 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
345 .setIsSecure(false)
346 .setLayerStackId(DEFAULT_LAYER_STACK)
347 .setPowerAdvisor(&mPowerAdvisor)
348 .setName(getDisplayNameFromCurrentTest())
349 .build());
350
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200351 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(mDisplay->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700352 EXPECT_FALSE(mDisplay->isSecure());
353 EXPECT_TRUE(mDisplay->isVirtual());
354 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
355 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
356 EXPECT_FALSE(mDisplay->isValid());
357}
358
359TEST_F(DisplaySetConfigurationTest, configuresNonHwcBackedVirtualDisplayIfShouldNotUseHwc) {
360 mDisplay->setConfiguration(
361 DisplayCreationArgsBuilder()
362 .setUseHwcVirtualDisplays(false)
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200363 .setGpuVirtualDisplayIdGenerator(mGpuDisplayIdGenerator)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700364 .setPixels(ui::Size(DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_WIDTH))
365 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
366 .setIsSecure(false)
367 .setLayerStackId(DEFAULT_LAYER_STACK)
368 .setPowerAdvisor(&mPowerAdvisor)
369 .setName(getDisplayNameFromCurrentTest())
370 .build());
371
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200372 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(mDisplay->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700373 EXPECT_FALSE(mDisplay->isSecure());
374 EXPECT_TRUE(mDisplay->isVirtual());
375 EXPECT_EQ(DEFAULT_LAYER_STACK, mDisplay->getState().layerStackId);
376 EXPECT_FALSE(mDisplay->getState().layerStackInternal);
377 EXPECT_FALSE(mDisplay->isValid());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700378}
379
Lloyd Pique66d68602019-02-13 14:23:31 -0800380/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700381 * Display::disconnect()
382 */
383
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700384using DisplayDisconnectTest = PartialMockDisplayTestCommon;
385
386TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200387 // The first call to disconnect will disconnect the display with the HWC.
388 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700389 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700390
391 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200392 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700393 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700394}
395
Lloyd Pique66d68602019-02-13 14:23:31 -0800396/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700397 * Display::setColorTransform()
398 */
399
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700400using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
401
402TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800403 // No change does nothing
404 CompositionRefreshArgs refreshArgs;
405 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700406 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800407
Lloyd Pique32cbe282018-10-19 13:09:22 -0700408 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800409 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700410
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200411 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
412 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700413
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800414 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700415 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700416
417 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800418 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700419
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200420 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
421 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700422
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800423 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700424 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700425}
426
Lloyd Pique66d68602019-02-13 14:23:31 -0800427/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700428 * Display::setColorMode()
429 */
430
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700431using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
432
433TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800434 using ColorProfile = Output::ColorProfile;
435
Lloyd Pique31cb2942018-10-19 17:23:03 -0700436 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700437 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800438 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700439 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700440
Lloyd Piquef5275482019-01-29 18:42:42 -0800441 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
442 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700443
444 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700445 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
446 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
447 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
448 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700449
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700450 // Otherwise if the values are unchanged, nothing happens
451 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
452 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700453
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700454 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
455 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
456 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
457 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700458
459 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800460 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700461 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800462 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700463 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
464 .Times(1);
465
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700466 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
467 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
468 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700469
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700470 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
471 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
472 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
473 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700474}
475
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700476TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800477 using ColorProfile = Output::ColorProfile;
478
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700479 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
480 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700481
Lloyd Piquef5275482019-01-29 18:42:42 -0800482 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700483 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800484 std::unique_ptr<DisplayColorProfile>(colorProfile));
485
486 EXPECT_CALL(*colorProfile,
487 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
488 ui::Dataspace::UNKNOWN))
489 .WillOnce(Return(ui::Dataspace::UNKNOWN));
490
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700491 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800492 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
493 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700494
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700495 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
496 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
497 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
498 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700499}
500
Lloyd Pique66d68602019-02-13 14:23:31 -0800501/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700502 * Display::createDisplayColorProfile()
503 */
504
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700505using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
506
507TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700508 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
509 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700510 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
511 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700512 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700513}
514
Lloyd Pique66d68602019-02-13 14:23:31 -0800515/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700516 * Display::createRenderSurface()
517 */
518
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700519using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
520
521TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700522 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700523 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -0700524 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
525 .setDisplayWidth(640)
526 .setDisplayHeight(480)
527 .setNativeWindow(mNativeWindow)
528 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700529 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700530}
531
Lloyd Pique66d68602019-02-13 14:23:31 -0800532/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800533 * Display::createOutputLayer()
534 */
535
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700536using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
537
538TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800539 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700540 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800541
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200542 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700543 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800544
Lloyd Piquede196652020-01-22 17:29:58 -0800545 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800546
Lloyd Pique1b33fc32021-05-07 14:36:58 -0700547 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800548
Lloyd Piquedf336d92019-03-07 21:38:42 -0800549 outputLayer.reset();
550}
551
552/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800553 * Display::setReleasedLayers()
554 */
555
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700556using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
557
558TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNotHwcDisplay) {
559 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
560 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800561
562 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800563
564 {
565 Output::ReleasedLayers releasedLayers;
566 releasedLayers.emplace_back(layerXLayerFE);
567 nonHwcDisplay->setReleasedLayers(std::move(releasedLayers));
568 }
569
570 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800571 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800572
573 nonHwcDisplay->setReleasedLayers(refreshArgs);
574
575 const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest();
576 ASSERT_EQ(1, releasedLayers.size());
577}
578
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700579TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800580 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
581
582 {
583 Output::ReleasedLayers releasedLayers;
584 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700585 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800586 }
587
588 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700589 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800590
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700591 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800592 ASSERT_EQ(1, releasedLayers.size());
593}
594
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700595TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800596 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800597
598 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800599 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
600 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
601 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800602
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700603 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800604
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700605 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800606 ASSERT_EQ(2, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800607 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
608 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800609}
610
611/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800612 * Display::chooseCompositionStrategy()
613 */
614
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700615using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800616
617TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700618 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
619 std::shared_ptr<Display> nonHwcDisplay =
620 createPartialMockDisplay<Display>(mCompositionEngine, args);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200621 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(nonHwcDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800622
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700623 nonHwcDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800624
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700625 auto& state = nonHwcDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800626 EXPECT_TRUE(state.usesClientComposition);
627 EXPECT_FALSE(state.usesDeviceComposition);
628}
629
630TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700631 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200632 EXPECT_CALL(mHwComposer,
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700633 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800634 .WillOnce(Return(INVALID_OPERATION));
635
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700636 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800637
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700638 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800639 EXPECT_TRUE(state.usesClientComposition);
640 EXPECT_FALSE(state.usesDeviceComposition);
641}
642
643TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700644 // Since two calls are made to anyLayersRequireClientComposition with different return
645 // values, use a Sequence to control the matching so the values are returned in a known
646 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800647 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700648 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
649 .InSequence(s)
650 .WillOnce(Return(true));
651 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800652 .InSequence(s)
653 .WillOnce(Return(false));
654
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700655 EXPECT_CALL(mHwComposer,
656 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800657 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700658 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800659
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700660 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800661
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700662 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800663 EXPECT_FALSE(state.usesClientComposition);
664 EXPECT_TRUE(state.usesDeviceComposition);
665}
666
667TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
668 android::HWComposer::DeviceRequestedChanges changes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700669 {{nullptr, hal::Composition::CLIENT}},
670 hal::DisplayRequest::FLIP_CLIENT_TARGET,
671 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700672 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Lloyd Pique66d68602019-02-13 14:23:31 -0800673 };
674
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700675 // Since two calls are made to anyLayersRequireClientComposition with different return
676 // values, use a Sequence to control the matching so the values are returned in a known
677 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800678 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700679 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
680 .InSequence(s)
681 .WillOnce(Return(true));
682 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800683 .InSequence(s)
684 .WillOnce(Return(false));
685
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700686 EXPECT_CALL(mHwComposer,
687 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _))
688 .WillOnce(DoAll(SetArgPointee<3>(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/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700854 * Display::applyClientTargetRequests()
855 */
856
857using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
858
859TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
860 Display::ClientTargetProperty clientTargetProperty = {
861 .pixelFormat = hal::PixelFormat::RGB_565,
862 .dataspace = hal::Dataspace::STANDARD_BT470M,
863 };
864
865 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
866 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
867
868 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
869 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
870 mDisplay->applyClientTargetRequests(clientTargetProperty);
871
872 auto& state = mDisplay->getState();
873 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
874}
875
876/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800877 * Display::presentAndGetFrameFences()
878 */
879
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700880using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
881
882TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnNonHwcDisplay) {
883 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
884 auto nonHwcDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800885
886 auto result = nonHwcDisplay->presentAndGetFrameFences();
887
888 ASSERT_TRUE(result.presentFence.get());
889 EXPECT_FALSE(result.presentFence->isValid());
890 EXPECT_EQ(0u, result.layerFences.size());
891}
892
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700893TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800894 sp<Fence> presentFence = new Fence();
895 sp<Fence> layer1Fence = new Fence();
896 sp<Fence> layer2Fence = new Fence();
897
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700898 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _))
899 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200900 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
901 .WillOnce(Return(presentFence));
902 EXPECT_CALL(mHwComposer,
903 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800904 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200905 EXPECT_CALL(mHwComposer,
906 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800907 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200908 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800909
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700910 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800911
912 EXPECT_EQ(presentFence, result.presentFence);
913
914 EXPECT_EQ(2u, result.layerFences.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800915 ASSERT_EQ(1, result.layerFences.count(&mLayer1.hwc2Layer));
916 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
917 ASSERT_EQ(1, result.layerFences.count(&mLayer2.hwc2Layer));
918 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800919}
920
Lloyd Pique688abd42019-02-15 15:42:24 -0800921/*
922 * Display::setExpensiveRenderingExpected()
923 */
924
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700925using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
926
927TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800928 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700929 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800930
931 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700932 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800933}
934
Lloyd Piqued3d69882019-02-28 16:03:46 -0800935/*
936 * Display::finishFrame()
937 */
938
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700939using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
940
941TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800942 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700943 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800944
945 // We expect no calls to queueBuffer if composition was skipped.
946 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
947
Lloyd Piquea76ce462020-01-14 13:06:37 -0800948 // Expect a call to signal no expensive rendering since there is no client composition.
949 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
950
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700951 mDisplay->editState().isEnabled = true;
952 mDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200953 mDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700954 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800955
956 CompositionRefreshArgs refreshArgs;
957 refreshArgs.repaintEverything = false;
958
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700959 mDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800960}
961
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700962TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
963 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
964 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800965
966 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
967 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
968
969 // We expect no calls to queueBuffer if composition was skipped.
970 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
971
972 nonHwcDisplay->editState().isEnabled = true;
973 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200974 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800975 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
976
977 CompositionRefreshArgs refreshArgs;
978 refreshArgs.repaintEverything = false;
979
980 nonHwcDisplay->finishFrame(refreshArgs);
981}
982
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700983TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
984 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
985 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800986
987 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
988 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
989
990 // We expect a single call to queueBuffer when composition is not skipped.
991 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
992
993 nonHwcDisplay->editState().isEnabled = true;
994 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200995 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800996 nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
997
998 CompositionRefreshArgs refreshArgs;
999 refreshArgs.repaintEverything = false;
1000
1001 nonHwcDisplay->finishFrame(refreshArgs);
1002}
1003
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001004TEST_F(DisplayFinishFrameTest, performsCompositionIfRepaintEverything) {
1005 auto args = getDisplayCreationArgsForNonHWCVirtualDisplay();
1006 std::shared_ptr<impl::Display> nonHwcDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -08001007
1008 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
1009 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
1010
1011 // We expect a single call to queueBuffer when composition is not skipped.
1012 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
1013
1014 nonHwcDisplay->editState().isEnabled = true;
1015 nonHwcDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +02001016 nonHwcDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piqued3d69882019-02-28 16:03:46 -08001017 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
1018
1019 CompositionRefreshArgs refreshArgs;
1020 refreshArgs.repaintEverything = true;
1021
1022 nonHwcDisplay->finishFrame(refreshArgs);
1023}
1024
Lloyd Piquec6607552019-12-02 17:57:39 -08001025/*
1026 * Display functional tests
1027 */
1028
1029struct DisplayFunctionalTest : public testing::Test {
1030 class Display : public impl::Display {
1031 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001032 using impl::Display::injectOutputLayerForTest;
1033 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1034 };
1035
Lloyd Piquec6607552019-12-02 17:57:39 -08001036 DisplayFunctionalTest() {
1037 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
1038
1039 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1040 }
1041
1042 NiceMock<android::mock::HWComposer> mHwComposer;
1043 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1044 NiceMock<mock::CompositionEngine> mCompositionEngine;
1045 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1046 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001047 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
1048 Display>(mCompositionEngine,
1049 DisplayCreationArgsBuilder()
Marin Shalamanov228f46b2021-01-28 21:11:45 +01001050 .setPhysical({DEFAULT_DISPLAY_ID, ui::DisplayConnectionType::Internal})
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001051 .setPixels({DEFAULT_DISPLAY_WIDTH, DEFAULT_DISPLAY_HEIGHT})
1052 .setPixelFormat(static_cast<ui::PixelFormat>(PIXEL_FORMAT_RGBA_8888))
1053 .setIsSecure(true)
1054 .setLayerStackId(DEFAULT_LAYER_STACK)
1055 .setPowerAdvisor(&mPowerAdvisor)
1056 .build()
1057
1058 );
Lloyd Piquec6607552019-12-02 17:57:39 -08001059 impl::RenderSurface* mRenderSurface =
1060 new impl::RenderSurface{mCompositionEngine, *mDisplay,
Dominik Laskowskib9ac3e12021-04-23 13:01:16 -07001061 RenderSurfaceCreationArgsBuilder()
1062 .setDisplayWidth(DEFAULT_DISPLAY_WIDTH)
1063 .setDisplayHeight(DEFAULT_DISPLAY_HEIGHT)
1064 .setNativeWindow(mNativeWindow)
1065 .setDisplaySurface(mDisplaySurface)
1066 .build()};
Lloyd Piquec6607552019-12-02 17:57:39 -08001067};
1068
1069TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1070 InSequence seq;
1071
1072 mDisplay->editState().isEnabled = true;
1073
Ady Abrahamb42cdc12021-05-11 14:31:26 -07001074 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001075 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1076
1077 mDisplay->postFramebuffer();
1078}
1079
Lloyd Pique45a165a2018-10-19 11:54:47 -07001080} // namespace
1081} // namespace android::compositionengine
Marin Shalamanovbed7fd32020-12-21 20:02:20 +01001082
1083// TODO(b/129481165): remove the #pragma below and fix conversion issues
1084#pragma clang diagnostic pop // ignored "-Wextra"