blob: 743da8207a6fa06a37d3a6bb84d32caf3dfd4b2d [file] [log] [blame]
Lloyd Pique45a165a2018-10-19 11:54:47 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Lloyd Pique45a165a2018-10-19 11:54:47 -070017#include <cmath>
18
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070019#include <compositionengine/DisplayColorProfileCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070020#include <compositionengine/DisplayCreationArgs.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070021#include <compositionengine/DisplaySurface.h>
22#include <compositionengine/RenderSurfaceCreationArgs.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070023#include <compositionengine/impl/Display.h>
24#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080025#include <compositionengine/mock/DisplayColorProfile.h>
chaviw8beb4142019-04-11 13:09:05 -070026#include <compositionengine/mock/NativeWindow.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080027#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070028#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070029#include <gtest/gtest.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070030
Lloyd Pique66d68602019-02-13 14:23:31 -080031#include "MockHWC2.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070032#include "MockHWComposer.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080033#include "MockPowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070034
35namespace android::compositionengine {
36namespace {
37
Lloyd Piquef5275482019-01-29 18:42:42 -080038using testing::_;
Lloyd Pique66d68602019-02-13 14:23:31 -080039using testing::DoAll;
Lloyd Pique31cb2942018-10-19 17:23:03 -070040using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070041using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080042using testing::Sequence;
43using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070044using testing::StrictMock;
45
46constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
47
Lloyd Pique66d68602019-02-13 14:23:31 -080048struct DisplayTest : public testing::Test {
49 DisplayTest() {
50 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
51 EXPECT_CALL(*mLayer1, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer1));
52 EXPECT_CALL(*mLayer2, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer2));
53 EXPECT_CALL(*mLayer3, getHwcLayer()).WillRepeatedly(Return(nullptr));
54
55 std::vector<std::unique_ptr<OutputLayer>> layers;
56 layers.emplace_back(mLayer1);
57 layers.emplace_back(mLayer2);
58 layers.emplace_back(mLayer3);
59 mDisplay.setOutputLayersOrderedByZ(std::move(layers));
60 }
Lloyd Pique45a165a2018-10-19 11:54:47 -070061
62 StrictMock<android::mock::HWComposer> mHwComposer;
Lloyd Pique688abd42019-02-15 15:42:24 -080063 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Pique45a165a2018-10-19 11:54:47 -070064 StrictMock<mock::CompositionEngine> mCompositionEngine;
chaviw8beb4142019-04-11 13:09:05 -070065 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
Lloyd Pique66d68602019-02-13 14:23:31 -080066 StrictMock<HWC2::mock::Layer> mHWC2Layer1;
67 StrictMock<HWC2::mock::Layer> mHWC2Layer2;
68 StrictMock<HWC2::mock::Layer> mHWC2LayerUnknown;
69 mock::OutputLayer* mLayer1 = new StrictMock<mock::OutputLayer>();
70 mock::OutputLayer* mLayer2 = new StrictMock<mock::OutputLayer>();
71 mock::OutputLayer* mLayer3 = new StrictMock<mock::OutputLayer>();
Lloyd Pique45a165a2018-10-19 11:54:47 -070072 impl::Display mDisplay{mCompositionEngine,
Lloyd Pique688abd42019-02-15 15:42:24 -080073 DisplayCreationArgsBuilder()
74 .setDisplayId(DEFAULT_DISPLAY_ID)
75 .setPowerAdvisor(&mPowerAdvisor)
76 .build()};
Lloyd Pique45a165a2018-10-19 11:54:47 -070077};
78
Lloyd Pique66d68602019-02-13 14:23:31 -080079/*
Lloyd Pique45a165a2018-10-19 11:54:47 -070080 * Basic construction
81 */
82
83TEST_F(DisplayTest, canInstantiateDisplay) {
84 {
85 constexpr DisplayId display1 = DisplayId{123u};
86 auto display =
87 impl::createDisplay(mCompositionEngine,
88 DisplayCreationArgsBuilder().setDisplayId(display1).build());
89 EXPECT_FALSE(display->isSecure());
90 EXPECT_FALSE(display->isVirtual());
91 EXPECT_EQ(display1, display->getId());
92 }
93
94 {
95 constexpr DisplayId display2 = DisplayId{546u};
96 auto display = impl::createDisplay(mCompositionEngine,
97 DisplayCreationArgsBuilder()
98 .setIsSecure(true)
99 .setDisplayId(display2)
100 .build());
101 EXPECT_TRUE(display->isSecure());
102 EXPECT_FALSE(display->isVirtual());
103 EXPECT_EQ(display2, display->getId());
104 }
105
106 {
107 constexpr DisplayId display3 = DisplayId{789u};
108 auto display = impl::createDisplay(mCompositionEngine,
109 DisplayCreationArgsBuilder()
110 .setIsVirtual(true)
111 .setDisplayId(display3)
112 .build());
113 EXPECT_FALSE(display->isSecure());
114 EXPECT_TRUE(display->isVirtual());
115 EXPECT_EQ(display3, display->getId());
116 }
117}
118
Lloyd Pique66d68602019-02-13 14:23:31 -0800119/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700120 * Display::disconnect()
121 */
122
123TEST_F(DisplayTest, disconnectDisconnectsDisplay) {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700124 // The first call to disconnect will disconnect the display with the HWC and
125 // set mHwcId to -1.
126 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1);
127 mDisplay.disconnect();
128 EXPECT_FALSE(mDisplay.getId());
129
130 // Subsequent calls will do nothing,
131 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0);
132 mDisplay.disconnect();
133 EXPECT_FALSE(mDisplay.getId());
134}
135
Lloyd Pique66d68602019-02-13 14:23:31 -0800136/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700137 * Display::setColorTransform()
138 */
139
140TEST_F(DisplayTest, setColorTransformSetsTransform) {
141 // Identity matrix sets an identity state value
142 const mat4 identity;
143
Lloyd Pique32cbe282018-10-19 13:09:22 -0700144 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, identity)).Times(1);
145
146 mDisplay.setColorTransform(identity);
147
148 EXPECT_EQ(HAL_COLOR_TRANSFORM_IDENTITY, mDisplay.getState().colorTransform);
149
150 // Non-identity matrix sets a non-identity state value
151 const mat4 nonIdentity = mat4() * 2;
152
153 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, nonIdentity)).Times(1);
154
155 mDisplay.setColorTransform(nonIdentity);
156
157 EXPECT_EQ(HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX, mDisplay.getState().colorTransform);
158}
159
Lloyd Pique66d68602019-02-13 14:23:31 -0800160/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700161 * Display::setColorMode()
162 */
163
164TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) {
Lloyd Pique31cb2942018-10-19 17:23:03 -0700165 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
166 mDisplay.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800167 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
168 mDisplay.setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700169
Lloyd Piquef5275482019-01-29 18:42:42 -0800170 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
171 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700172
173 // These values are expected to be the initial state.
174 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
175 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
176 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent);
Lloyd Piquef5275482019-01-29 18:42:42 -0800177 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700178
Lloyd Piquef5275482019-01-29 18:42:42 -0800179 // If the set values are unchanged, nothing happens
Lloyd Pique32cbe282018-10-19 13:09:22 -0700180 mDisplay.setColorMode(ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
Lloyd Piquef5275482019-01-29 18:42:42 -0800181 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700182
183 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay.getState().colorMode);
184 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().dataspace);
185 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay.getState().renderIntent);
Lloyd Piquef5275482019-01-29 18:42:42 -0800186 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700187
188 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800189 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700190 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800191 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700192 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
193 .Times(1);
194
Lloyd Piqueef958122019-02-05 18:00:12 -0800195 mDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Lloyd Piquef5275482019-01-29 18:42:42 -0800196 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700197
Lloyd Piqueef958122019-02-05 18:00:12 -0800198 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay.getState().colorMode);
199 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay.getState().dataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700200 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay.getState().renderIntent);
Lloyd Piquef5275482019-01-29 18:42:42 -0800201 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700202}
203
204TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) {
205 impl::Display virtualDisplay{mCompositionEngine,
206 DisplayCreationArgs{false, true, DEFAULT_DISPLAY_ID}};
207
Lloyd Piquef5275482019-01-29 18:42:42 -0800208 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
209 virtualDisplay.setDisplayColorProfileForTest(
210 std::unique_ptr<DisplayColorProfile>(colorProfile));
211
212 EXPECT_CALL(*colorProfile,
213 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
214 ui::Dataspace::UNKNOWN))
215 .WillOnce(Return(ui::Dataspace::UNKNOWN));
216
Lloyd Piqueef958122019-02-05 18:00:12 -0800217 virtualDisplay.setColorMode(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Lloyd Piquef5275482019-01-29 18:42:42 -0800218 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700219
220 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay.getState().colorMode);
221 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay.getState().dataspace);
222 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay.getState().renderIntent);
Lloyd Piquef5275482019-01-29 18:42:42 -0800223 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay.getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700224}
225
Lloyd Pique66d68602019-02-13 14:23:31 -0800226/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700227 * Display::createDisplayColorProfile()
228 */
229
230TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) {
231 EXPECT_TRUE(mDisplay.getDisplayColorProfile() == nullptr);
232 mDisplay.createDisplayColorProfile(
233 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
234 DisplayColorProfileCreationArgs::HwcColorModes()});
235 EXPECT_TRUE(mDisplay.getDisplayColorProfile() != nullptr);
236}
237
Lloyd Pique66d68602019-02-13 14:23:31 -0800238/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700239 * Display::createRenderSurface()
240 */
241
242TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700243 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700244 EXPECT_TRUE(mDisplay.getRenderSurface() == nullptr);
chaviw8beb4142019-04-11 13:09:05 -0700245 mDisplay.createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr});
Lloyd Pique31cb2942018-10-19 17:23:03 -0700246 EXPECT_TRUE(mDisplay.getRenderSurface() != nullptr);
247}
248
Lloyd Pique66d68602019-02-13 14:23:31 -0800249/*
250 * Display::chooseCompositionStrategy()
251 */
252
253struct DisplayChooseCompositionStrategyTest : public testing::Test {
254 struct DisplayPartialMock : public impl::Display {
255 DisplayPartialMock(const compositionengine::CompositionEngine& compositionEngine,
256 compositionengine::DisplayCreationArgs&& args)
257 : impl::Display(compositionEngine, std::move(args)) {}
258
259 // Sets up the helper functions called by chooseCompositionStrategy to
260 // use a mock implementations.
261 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
262 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
263 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
264 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
265 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
266 };
267
268 DisplayChooseCompositionStrategyTest() {
269 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
270 }
271
272 StrictMock<android::mock::HWComposer> mHwComposer;
273 StrictMock<mock::CompositionEngine> mCompositionEngine;
274 StrictMock<DisplayPartialMock>
275 mDisplay{mCompositionEngine,
276 DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()};
277};
278
279TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) {
280 impl::Display nonHwcDisplay{mCompositionEngine, DisplayCreationArgsBuilder().build()};
281 EXPECT_FALSE(nonHwcDisplay.getId());
282
283 nonHwcDisplay.chooseCompositionStrategy();
284
285 auto& state = nonHwcDisplay.getState();
286 EXPECT_TRUE(state.usesClientComposition);
287 EXPECT_FALSE(state.usesDeviceComposition);
288}
289
290TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
291 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
292 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, false, _))
293 .WillOnce(Return(INVALID_OPERATION));
294
295 mDisplay.chooseCompositionStrategy();
296
297 auto& state = mDisplay.getState();
298 EXPECT_TRUE(state.usesClientComposition);
299 EXPECT_FALSE(state.usesDeviceComposition);
300}
301
302TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
303 // Since two calls are made to anyLayersRequireClientComposition with different return values,
304 // use a Sequence to control the matching so the values are returned in a known order.
305 Sequence s;
306 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true));
307 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition())
308 .InSequence(s)
309 .WillOnce(Return(false));
310
311 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _))
312 .WillOnce(Return(NO_ERROR));
313 EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
314
315 mDisplay.chooseCompositionStrategy();
316
317 auto& state = mDisplay.getState();
318 EXPECT_FALSE(state.usesClientComposition);
319 EXPECT_TRUE(state.usesDeviceComposition);
320}
321
322TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
323 android::HWComposer::DeviceRequestedChanges changes{
324 {{nullptr, HWC2::Composition::Client}},
325 HWC2::DisplayRequest::FlipClientTarget,
326 {{nullptr, HWC2::LayerRequest::ClearClientTarget}},
327 };
328
329 // Since two calls are made to anyLayersRequireClientComposition with different return values,
330 // use a Sequence to control the matching so the values are returned in a known order.
331 Sequence s;
332 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true));
333 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition())
334 .InSequence(s)
335 .WillOnce(Return(false));
336
337 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _))
338 .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR)));
339 EXPECT_CALL(mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
340 EXPECT_CALL(mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
341 EXPECT_CALL(mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
342 EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
343
344 mDisplay.chooseCompositionStrategy();
345
346 auto& state = mDisplay.getState();
347 EXPECT_FALSE(state.usesClientComposition);
348 EXPECT_TRUE(state.usesDeviceComposition);
349}
350
351/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800352 * Display::getSkipColorTransform()
353 */
354
355TEST_F(DisplayTest, getSkipColorTransformDoesNothingIfNonHwcDisplay) {
356 auto nonHwcDisplay{
357 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
358 EXPECT_FALSE(nonHwcDisplay->getSkipColorTransform());
359}
360
361TEST_F(DisplayTest, getSkipColorTransformChecksHwcCapability) {
362 EXPECT_CALL(mHwComposer,
363 hasDisplayCapability(std::make_optional(DEFAULT_DISPLAY_ID),
364 HWC2::DisplayCapability::SkipClientColorTransform))
365 .WillOnce(Return(true));
366 EXPECT_TRUE(mDisplay.getSkipColorTransform());
367}
368
369/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800370 * Display::anyLayersRequireClientComposition()
371 */
372
373TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsFalse) {
374 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false));
375 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false));
376 EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(false));
377
378 EXPECT_FALSE(mDisplay.anyLayersRequireClientComposition());
379}
380
381TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsTrue) {
382 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false));
383 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true));
384
385 EXPECT_TRUE(mDisplay.anyLayersRequireClientComposition());
386}
387
388/*
389 * Display::allLayersRequireClientComposition()
390 */
391
392TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsTrue) {
393 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true));
394 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true));
395 EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(true));
396
397 EXPECT_TRUE(mDisplay.allLayersRequireClientComposition());
398}
399
400TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsFalse) {
401 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true));
402 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false));
403
404 EXPECT_FALSE(mDisplay.allLayersRequireClientComposition());
405}
406
407/*
408 * Display::applyChangedTypesToLayers()
409 */
410
411TEST_F(DisplayTest, applyChangedTypesToLayersTakesEarlyOutIfNoChangedLayers) {
412 mDisplay.applyChangedTypesToLayers(impl::Display::ChangedTypes());
413}
414
415TEST_F(DisplayTest, applyChangedTypesToLayersAppliesChanges) {
416 EXPECT_CALL(*mLayer1,
417 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT))
418 .Times(1);
419 EXPECT_CALL(*mLayer2,
420 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE))
421 .Times(1);
422
423 mDisplay.applyChangedTypesToLayers(impl::Display::ChangedTypes{
424 {&mHWC2Layer1, HWC2::Composition::Client},
425 {&mHWC2Layer2, HWC2::Composition::Device},
426 {&mHWC2LayerUnknown, HWC2::Composition::SolidColor},
427 });
428}
429
430/*
431 * Display::applyDisplayRequests()
432 */
433
434TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesNoRequests) {
435 mDisplay.applyDisplayRequests(static_cast<HWC2::DisplayRequest>(0));
436
437 auto& state = mDisplay.getState();
438 EXPECT_FALSE(state.flipClientTarget);
439}
440
441TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesFlipClientTarget) {
442 mDisplay.applyDisplayRequests(HWC2::DisplayRequest::FlipClientTarget);
443
444 auto& state = mDisplay.getState();
445 EXPECT_TRUE(state.flipClientTarget);
446}
447
448TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesWriteClientTargetToOutput) {
449 mDisplay.applyDisplayRequests(HWC2::DisplayRequest::WriteClientTargetToOutput);
450
451 auto& state = mDisplay.getState();
452 EXPECT_FALSE(state.flipClientTarget);
453}
454
455TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesAllRequestFlagsSet) {
456 mDisplay.applyDisplayRequests(static_cast<HWC2::DisplayRequest>(~0));
457
458 auto& state = mDisplay.getState();
459 EXPECT_TRUE(state.flipClientTarget);
460}
461
462/*
463 * Display::applyLayerRequestsToLayers()
464 */
465
466TEST_F(DisplayTest, applyLayerRequestsToLayersPreparesAllLayers) {
467 EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1);
468 EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1);
469 EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1);
470
471 mDisplay.applyLayerRequestsToLayers(impl::Display::LayerRequests());
472}
473
474TEST_F(DisplayTest, applyLayerRequestsToLayers2) {
475 EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1);
476 EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1);
477 EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1);
478
479 EXPECT_CALL(*mLayer1,
480 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
481 .Times(1);
482
483 mDisplay.applyLayerRequestsToLayers(impl::Display::LayerRequests{
484 {&mHWC2Layer1, HWC2::LayerRequest::ClearClientTarget},
485 {&mHWC2LayerUnknown, HWC2::LayerRequest::ClearClientTarget},
486 });
487}
488
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800489/*
490 * Display::presentAndGetFrameFences()
491 */
492
493TEST_F(DisplayTest, presentAndGetFrameFencesReturnsNoFencesOnNonHwcDisplay) {
494 auto nonHwcDisplay{
495 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
496
497 auto result = nonHwcDisplay->presentAndGetFrameFences();
498
499 ASSERT_TRUE(result.presentFence.get());
500 EXPECT_FALSE(result.presentFence->isValid());
501 EXPECT_EQ(0u, result.layerFences.size());
502}
503
504TEST_F(DisplayTest, presentAndGetFrameFencesReturnsPresentAndLayerFences) {
505 sp<Fence> presentFence = new Fence();
506 sp<Fence> layer1Fence = new Fence();
507 sp<Fence> layer2Fence = new Fence();
508
509 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(DEFAULT_DISPLAY_ID)).Times(1);
510 EXPECT_CALL(mHwComposer, getPresentFence(DEFAULT_DISPLAY_ID)).WillOnce(Return(presentFence));
511 EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mHWC2Layer1))
512 .WillOnce(Return(layer1Fence));
513 EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mHWC2Layer2))
514 .WillOnce(Return(layer2Fence));
515 EXPECT_CALL(mHwComposer, clearReleaseFences(DEFAULT_DISPLAY_ID)).Times(1);
516
517 auto result = mDisplay.presentAndGetFrameFences();
518
519 EXPECT_EQ(presentFence, result.presentFence);
520
521 EXPECT_EQ(2u, result.layerFences.size());
522 ASSERT_EQ(1, result.layerFences.count(&mHWC2Layer1));
523 EXPECT_EQ(layer1Fence, result.layerFences[&mHWC2Layer1]);
524 ASSERT_EQ(1, result.layerFences.count(&mHWC2Layer2));
525 EXPECT_EQ(layer2Fence, result.layerFences[&mHWC2Layer2]);
526}
527
Lloyd Pique688abd42019-02-15 15:42:24 -0800528/*
529 * Display::setExpensiveRenderingExpected()
530 */
531
532TEST_F(DisplayTest, setExpensiveRenderingExpectedForwardsToPowerAdvisor) {
533 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
534 mDisplay.setExpensiveRenderingExpected(true);
535
536 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
537 mDisplay.setExpensiveRenderingExpected(false);
538}
539
Lloyd Pique45a165a2018-10-19 11:54:47 -0700540} // namespace
541} // namespace android::compositionengine