blob: 4d71d4370a4aaff4f956b30f619d3ea8c4a572c5 [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>
Lloyd Piquedf336d92019-03-07 21:38:42 -080026#include <compositionengine/mock/Layer.h>
27#include <compositionengine/mock/LayerFE.h>
chaviw8beb4142019-04-11 13:09:05 -070028#include <compositionengine/mock/NativeWindow.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080029#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070030#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070031#include <gtest/gtest.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070032
Lloyd Pique66d68602019-02-13 14:23:31 -080033#include "MockHWC2.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070034#include "MockHWComposer.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080035#include "MockPowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070036
37namespace android::compositionengine {
38namespace {
39
Lloyd Piquef5275482019-01-29 18:42:42 -080040using testing::_;
Lloyd Pique66d68602019-02-13 14:23:31 -080041using testing::DoAll;
Lloyd Pique31cb2942018-10-19 17:23:03 -070042using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070043using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080044using testing::Sequence;
45using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070046using testing::StrictMock;
47
48constexpr DisplayId DEFAULT_DISPLAY_ID = DisplayId{42};
49
Lloyd Pique66d68602019-02-13 14:23:31 -080050struct DisplayTest : public testing::Test {
Lloyd Pique01c77c12019-04-17 12:48:32 -070051 class Display : public impl::Display {
52 public:
53 explicit Display(const compositionengine::DisplayCreationArgs& args)
54 : impl::Display(args) {}
55
56 using impl::Display::injectOutputLayerForTest;
57 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
58 };
59
60 static std::shared_ptr<Display> createDisplay(
61 const compositionengine::CompositionEngine& compositionEngine,
62 compositionengine::DisplayCreationArgs&& args) {
63 return impl::createDisplayTemplated<Display>(compositionEngine, args);
64 }
65
Lloyd Pique66d68602019-02-13 14:23:31 -080066 DisplayTest() {
67 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
68 EXPECT_CALL(*mLayer1, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer1));
69 EXPECT_CALL(*mLayer2, getHwcLayer()).WillRepeatedly(Return(&mHWC2Layer2));
70 EXPECT_CALL(*mLayer3, getHwcLayer()).WillRepeatedly(Return(nullptr));
71
Lloyd Pique01c77c12019-04-17 12:48:32 -070072 mDisplay->injectOutputLayerForTest(
73 std::unique_ptr<compositionengine::OutputLayer>(mLayer1));
74 mDisplay->injectOutputLayerForTest(
75 std::unique_ptr<compositionengine::OutputLayer>(mLayer2));
76 mDisplay->injectOutputLayerForTest(
77 std::unique_ptr<compositionengine::OutputLayer>(mLayer3));
Lloyd Pique66d68602019-02-13 14:23:31 -080078 }
Lloyd Pique45a165a2018-10-19 11:54:47 -070079
80 StrictMock<android::mock::HWComposer> mHwComposer;
Lloyd Pique688abd42019-02-15 15:42:24 -080081 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Pique45a165a2018-10-19 11:54:47 -070082 StrictMock<mock::CompositionEngine> mCompositionEngine;
chaviw8beb4142019-04-11 13:09:05 -070083 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
Lloyd Pique66d68602019-02-13 14:23:31 -080084 StrictMock<HWC2::mock::Layer> mHWC2Layer1;
85 StrictMock<HWC2::mock::Layer> mHWC2Layer2;
86 StrictMock<HWC2::mock::Layer> mHWC2LayerUnknown;
87 mock::OutputLayer* mLayer1 = new StrictMock<mock::OutputLayer>();
88 mock::OutputLayer* mLayer2 = new StrictMock<mock::OutputLayer>();
89 mock::OutputLayer* mLayer3 = new StrictMock<mock::OutputLayer>();
Lloyd Pique01c77c12019-04-17 12:48:32 -070090 std::shared_ptr<Display> mDisplay = createDisplay(mCompositionEngine,
91 DisplayCreationArgsBuilder()
92 .setDisplayId(DEFAULT_DISPLAY_ID)
93 .setPowerAdvisor(&mPowerAdvisor)
94 .build());
Lloyd Pique45a165a2018-10-19 11:54:47 -070095};
96
Lloyd Pique66d68602019-02-13 14:23:31 -080097/*
Lloyd Pique45a165a2018-10-19 11:54:47 -070098 * Basic construction
99 */
100
101TEST_F(DisplayTest, canInstantiateDisplay) {
102 {
103 constexpr DisplayId display1 = DisplayId{123u};
104 auto display =
105 impl::createDisplay(mCompositionEngine,
106 DisplayCreationArgsBuilder().setDisplayId(display1).build());
107 EXPECT_FALSE(display->isSecure());
108 EXPECT_FALSE(display->isVirtual());
109 EXPECT_EQ(display1, display->getId());
110 }
111
112 {
113 constexpr DisplayId display2 = DisplayId{546u};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700114 auto display =
115 impl::createDisplay(mCompositionEngine,
116 DisplayCreationArgsBuilder().setDisplayId(display2).build());
117 EXPECT_FALSE(display->isSecure());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700118 EXPECT_FALSE(display->isVirtual());
119 EXPECT_EQ(display2, display->getId());
120 }
121
122 {
123 constexpr DisplayId display3 = DisplayId{789u};
124 auto display = impl::createDisplay(mCompositionEngine,
125 DisplayCreationArgsBuilder()
126 .setIsVirtual(true)
127 .setDisplayId(display3)
128 .build());
129 EXPECT_FALSE(display->isSecure());
130 EXPECT_TRUE(display->isVirtual());
131 EXPECT_EQ(display3, display->getId());
132 }
133}
134
Lloyd Pique66d68602019-02-13 14:23:31 -0800135/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700136 * Display::disconnect()
137 */
138
139TEST_F(DisplayTest, disconnectDisconnectsDisplay) {
Lloyd Pique45a165a2018-10-19 11:54:47 -0700140 // The first call to disconnect will disconnect the display with the HWC and
141 // set mHwcId to -1.
142 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700143 mDisplay->disconnect();
144 EXPECT_FALSE(mDisplay->getId());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700145
146 // Subsequent calls will do nothing,
147 EXPECT_CALL(mHwComposer, disconnectDisplay(DEFAULT_DISPLAY_ID)).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700148 mDisplay->disconnect();
149 EXPECT_FALSE(mDisplay->getId());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700150}
151
Lloyd Pique66d68602019-02-13 14:23:31 -0800152/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700153 * Display::setColorTransform()
154 */
155
156TEST_F(DisplayTest, setColorTransformSetsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800157 // No change does nothing
158 CompositionRefreshArgs refreshArgs;
159 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700160 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800161
Lloyd Pique32cbe282018-10-19 13:09:22 -0700162 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800163 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700164
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800165 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kIdentity)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700166
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800167 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700168 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700169
170 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800171 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700172
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800173 EXPECT_CALL(mHwComposer, setColorTransform(DEFAULT_DISPLAY_ID, kNonIdentity)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700174
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800175 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700176 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700177}
178
Lloyd Pique66d68602019-02-13 14:23:31 -0800179/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700180 * Display::setColorMode()
181 */
182
183TEST_F(DisplayTest, setColorModeSetsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800184 using ColorProfile = Output::ColorProfile;
185
Lloyd Pique31cb2942018-10-19 17:23:03 -0700186 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700187 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800188 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700189 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700190
Lloyd Piquef5275482019-01-29 18:42:42 -0800191 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
192 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700193
194 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700195 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
196 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
197 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
198 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700199
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700200 // Otherwise if the values are unchanged, nothing happens
201 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
202 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700203
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700204 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
205 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
206 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
207 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700208
209 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800210 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700211 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800212 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700213 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
214 .Times(1);
215
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700216 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
217 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
218 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700219
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700220 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
221 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
222 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
223 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700224}
225
226TEST_F(DisplayTest, setColorModeDoesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800227 using ColorProfile = Output::ColorProfile;
228
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700229 std::shared_ptr<impl::Display> virtualDisplay{
230 impl::createDisplay(mCompositionEngine, DisplayCreationArgs{true, DEFAULT_DISPLAY_ID})};
Lloyd Pique32cbe282018-10-19 13:09:22 -0700231
Lloyd Piquef5275482019-01-29 18:42:42 -0800232 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700233 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800234 std::unique_ptr<DisplayColorProfile>(colorProfile));
235
236 EXPECT_CALL(*colorProfile,
237 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
238 ui::Dataspace::UNKNOWN))
239 .WillOnce(Return(ui::Dataspace::UNKNOWN));
240
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700241 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800242 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
243 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700244
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700245 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
246 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
247 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
248 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700249}
250
Lloyd Pique66d68602019-02-13 14:23:31 -0800251/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700252 * Display::createDisplayColorProfile()
253 */
254
255TEST_F(DisplayTest, createDisplayColorProfileSetsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700256 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
257 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700258 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
259 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700260 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700261}
262
Lloyd Pique66d68602019-02-13 14:23:31 -0800263/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700264 * Display::createRenderSurface()
265 */
266
267TEST_F(DisplayTest, createRenderSurfaceSetsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700268 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700269 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
270 mDisplay->createRenderSurface(RenderSurfaceCreationArgs{640, 480, mNativeWindow, nullptr});
271 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700272}
273
Lloyd Pique66d68602019-02-13 14:23:31 -0800274/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800275 * Display::createOutputLayer()
276 */
277
278TEST_F(DisplayTest, createOutputLayerSetsHwcLayer) {
279 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
280 auto layer = std::make_shared<StrictMock<mock::Layer>>();
281 StrictMock<HWC2::mock::Layer> hwcLayer;
282
283 EXPECT_CALL(mHwComposer, createLayer(DEFAULT_DISPLAY_ID)).WillOnce(Return(&hwcLayer));
284
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700285 auto outputLayer = mDisplay->createOutputLayer(layer, layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800286
287 EXPECT_EQ(&hwcLayer, outputLayer->getHwcLayer());
288
289 EXPECT_CALL(mHwComposer, destroyLayer(DEFAULT_DISPLAY_ID, &hwcLayer));
290 outputLayer.reset();
291}
292
293/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800294 * Display::setReleasedLayers()
295 */
296
297TEST_F(DisplayTest, setReleasedLayersDoesNothingIfNotHwcDisplay) {
298 std::shared_ptr<impl::Display> nonHwcDisplay{
299 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
300
301 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
302 mock::Layer layerXLayer;
303
304 {
305 Output::ReleasedLayers releasedLayers;
306 releasedLayers.emplace_back(layerXLayerFE);
307 nonHwcDisplay->setReleasedLayers(std::move(releasedLayers));
308 }
309
310 CompositionRefreshArgs refreshArgs;
311 refreshArgs.layersWithQueuedFrames.push_back(&layerXLayer);
312
313 nonHwcDisplay->setReleasedLayers(refreshArgs);
314
315 const auto& releasedLayers = nonHwcDisplay->getReleasedLayersForTest();
316 ASSERT_EQ(1, releasedLayers.size());
317}
318
319TEST_F(DisplayTest, setReleasedLayersDoesNothingIfNoLayersWithQueuedFrames) {
320 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
321
322 {
323 Output::ReleasedLayers releasedLayers;
324 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700325 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800326 }
327
328 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700329 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800330
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700331 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800332 ASSERT_EQ(1, releasedLayers.size());
333}
334
335TEST_F(DisplayTest, setReleasedLayers) {
336 sp<mock::LayerFE> layer1LayerFE = new StrictMock<mock::LayerFE>();
337 sp<mock::LayerFE> layer2LayerFE = new StrictMock<mock::LayerFE>();
338 sp<mock::LayerFE> layer3LayerFE = new StrictMock<mock::LayerFE>();
339 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
340 mock::Layer layer1Layer;
341 mock::Layer layer2Layer;
342 mock::Layer layer3Layer;
343 mock::Layer layerXLayer;
344
345 EXPECT_CALL(*mLayer1, getLayer()).WillRepeatedly(ReturnRef(layer1Layer));
346 EXPECT_CALL(*mLayer1, getLayerFE()).WillRepeatedly(ReturnRef(*layer1LayerFE.get()));
347 EXPECT_CALL(*mLayer2, getLayer()).WillRepeatedly(ReturnRef(layer2Layer));
348 EXPECT_CALL(*mLayer2, getLayerFE()).WillRepeatedly(ReturnRef(*layer2LayerFE.get()));
349 EXPECT_CALL(*mLayer3, getLayer()).WillRepeatedly(ReturnRef(layer3Layer));
350 EXPECT_CALL(*mLayer3, getLayerFE()).WillRepeatedly(ReturnRef(*layer3LayerFE.get()));
351
352 CompositionRefreshArgs refreshArgs;
353 refreshArgs.layersWithQueuedFrames.push_back(&layer1Layer);
354 refreshArgs.layersWithQueuedFrames.push_back(&layer2Layer);
355 refreshArgs.layersWithQueuedFrames.push_back(&layerXLayer);
356 refreshArgs.layersWithQueuedFrames.push_back(nullptr);
357
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700358 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800359
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700360 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800361 ASSERT_EQ(2, releasedLayers.size());
362 ASSERT_EQ(layer1LayerFE.get(), releasedLayers[0].promote().get());
363 ASSERT_EQ(layer2LayerFE.get(), releasedLayers[1].promote().get());
364}
365
366/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800367 * Display::chooseCompositionStrategy()
368 */
369
370struct DisplayChooseCompositionStrategyTest : public testing::Test {
371 struct DisplayPartialMock : public impl::Display {
372 DisplayPartialMock(const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700373 const compositionengine::DisplayCreationArgs& args)
374 : impl::Display(args), mCompositionEngine(compositionEngine) {}
Lloyd Pique66d68602019-02-13 14:23:31 -0800375
376 // Sets up the helper functions called by chooseCompositionStrategy to
377 // use a mock implementations.
378 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
379 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
380 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
381 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
382 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700383
384 // compositionengine::Output overrides
385 const OutputCompositionState& getState() const override { return mState; }
386 OutputCompositionState& editState() override { return mState; }
387
388 // compositionengine::impl::Output overrides
389 const CompositionEngine& getCompositionEngine() const override {
390 return mCompositionEngine;
391 };
392
393 // These need implementations though are not expected to be called.
Lloyd Pique01c77c12019-04-17 12:48:32 -0700394 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
395 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
396 compositionengine::OutputLayer*(size_t));
397 MOCK_METHOD3(ensureOutputLayer,
398 compositionengine::OutputLayer*(
399 std::optional<size_t>,
400 const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&));
401 MOCK_METHOD0(finalizePendingOutputLayers, void());
402 MOCK_METHOD0(clearOutputLayers, void());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700403 MOCK_CONST_METHOD1(dumpState, void(std::string&));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700404 MOCK_METHOD2(injectOutputLayerForTest,
405 compositionengine::OutputLayer*(
406 const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&));
407 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700408
409 const compositionengine::CompositionEngine& mCompositionEngine;
410 impl::OutputCompositionState mState;
Lloyd Pique66d68602019-02-13 14:23:31 -0800411 };
412
413 DisplayChooseCompositionStrategyTest() {
414 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
415 }
416
417 StrictMock<android::mock::HWComposer> mHwComposer;
418 StrictMock<mock::CompositionEngine> mCompositionEngine;
419 StrictMock<DisplayPartialMock>
420 mDisplay{mCompositionEngine,
421 DisplayCreationArgsBuilder().setDisplayId(DEFAULT_DISPLAY_ID).build()};
422};
423
424TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfNotAHwcDisplay) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700425 std::shared_ptr<impl::Display> nonHwcDisplay{
426 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
427 EXPECT_FALSE(nonHwcDisplay->getId());
Lloyd Pique66d68602019-02-13 14:23:31 -0800428
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700429 nonHwcDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800430
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700431 auto& state = nonHwcDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800432 EXPECT_TRUE(state.usesClientComposition);
433 EXPECT_FALSE(state.usesDeviceComposition);
434}
435
436TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
437 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
438 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, false, _))
439 .WillOnce(Return(INVALID_OPERATION));
440
441 mDisplay.chooseCompositionStrategy();
442
443 auto& state = mDisplay.getState();
444 EXPECT_TRUE(state.usesClientComposition);
445 EXPECT_FALSE(state.usesDeviceComposition);
446}
447
448TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
449 // Since two calls are made to anyLayersRequireClientComposition with different return values,
450 // use a Sequence to control the matching so the values are returned in a known order.
451 Sequence s;
452 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true));
453 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition())
454 .InSequence(s)
455 .WillOnce(Return(false));
456
457 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _))
458 .WillOnce(Return(NO_ERROR));
459 EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
460
461 mDisplay.chooseCompositionStrategy();
462
463 auto& state = mDisplay.getState();
464 EXPECT_FALSE(state.usesClientComposition);
465 EXPECT_TRUE(state.usesDeviceComposition);
466}
467
468TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
469 android::HWComposer::DeviceRequestedChanges changes{
470 {{nullptr, HWC2::Composition::Client}},
471 HWC2::DisplayRequest::FlipClientTarget,
472 {{nullptr, HWC2::LayerRequest::ClearClientTarget}},
473 };
474
475 // Since two calls are made to anyLayersRequireClientComposition with different return values,
476 // use a Sequence to control the matching so the values are returned in a known order.
477 Sequence s;
478 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition()).InSequence(s).WillOnce(Return(true));
479 EXPECT_CALL(mDisplay, anyLayersRequireClientComposition())
480 .InSequence(s)
481 .WillOnce(Return(false));
482
483 EXPECT_CALL(mHwComposer, getDeviceCompositionChanges(DEFAULT_DISPLAY_ID, true, _))
484 .WillOnce(DoAll(SetArgPointee<2>(changes), Return(NO_ERROR)));
485 EXPECT_CALL(mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
486 EXPECT_CALL(mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
487 EXPECT_CALL(mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
488 EXPECT_CALL(mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
489
490 mDisplay.chooseCompositionStrategy();
491
492 auto& state = mDisplay.getState();
493 EXPECT_FALSE(state.usesClientComposition);
494 EXPECT_TRUE(state.usesDeviceComposition);
495}
496
497/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800498 * Display::getSkipColorTransform()
499 */
500
501TEST_F(DisplayTest, getSkipColorTransformDoesNothingIfNonHwcDisplay) {
502 auto nonHwcDisplay{
503 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
504 EXPECT_FALSE(nonHwcDisplay->getSkipColorTransform());
505}
506
507TEST_F(DisplayTest, getSkipColorTransformChecksHwcCapability) {
508 EXPECT_CALL(mHwComposer,
509 hasDisplayCapability(std::make_optional(DEFAULT_DISPLAY_ID),
510 HWC2::DisplayCapability::SkipClientColorTransform))
511 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700512 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800513}
514
515/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800516 * Display::anyLayersRequireClientComposition()
517 */
518
519TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsFalse) {
520 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false));
521 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false));
522 EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(false));
523
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700524 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800525}
526
527TEST_F(DisplayTest, anyLayersRequireClientCompositionReturnsTrue) {
528 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(false));
529 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true));
530
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700531 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800532}
533
534/*
535 * Display::allLayersRequireClientComposition()
536 */
537
538TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsTrue) {
539 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true));
540 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(true));
541 EXPECT_CALL(*mLayer3, requiresClientComposition()).WillOnce(Return(true));
542
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700543 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800544}
545
546TEST_F(DisplayTest, allLayersRequireClientCompositionReturnsFalse) {
547 EXPECT_CALL(*mLayer1, requiresClientComposition()).WillOnce(Return(true));
548 EXPECT_CALL(*mLayer2, requiresClientComposition()).WillOnce(Return(false));
549
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700550 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800551}
552
553/*
554 * Display::applyChangedTypesToLayers()
555 */
556
557TEST_F(DisplayTest, applyChangedTypesToLayersTakesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700558 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800559}
560
561TEST_F(DisplayTest, applyChangedTypesToLayersAppliesChanges) {
562 EXPECT_CALL(*mLayer1,
563 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT))
564 .Times(1);
565 EXPECT_CALL(*mLayer2,
566 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE))
567 .Times(1);
568
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700569 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Lloyd Pique66d68602019-02-13 14:23:31 -0800570 {&mHWC2Layer1, HWC2::Composition::Client},
571 {&mHWC2Layer2, HWC2::Composition::Device},
572 {&mHWC2LayerUnknown, HWC2::Composition::SolidColor},
573 });
574}
575
576/*
577 * Display::applyDisplayRequests()
578 */
579
580TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesNoRequests) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700581 mDisplay->applyDisplayRequests(static_cast<HWC2::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800582
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700583 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800584 EXPECT_FALSE(state.flipClientTarget);
585}
586
587TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesFlipClientTarget) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700588 mDisplay->applyDisplayRequests(HWC2::DisplayRequest::FlipClientTarget);
Lloyd Pique66d68602019-02-13 14:23:31 -0800589
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700590 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800591 EXPECT_TRUE(state.flipClientTarget);
592}
593
594TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesWriteClientTargetToOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700595 mDisplay->applyDisplayRequests(HWC2::DisplayRequest::WriteClientTargetToOutput);
Lloyd Pique66d68602019-02-13 14:23:31 -0800596
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700597 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800598 EXPECT_FALSE(state.flipClientTarget);
599}
600
601TEST_F(DisplayTest, applyDisplayRequestsToLayersHandlesAllRequestFlagsSet) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700602 mDisplay->applyDisplayRequests(static_cast<HWC2::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800603
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700604 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800605 EXPECT_TRUE(state.flipClientTarget);
606}
607
608/*
609 * Display::applyLayerRequestsToLayers()
610 */
611
612TEST_F(DisplayTest, applyLayerRequestsToLayersPreparesAllLayers) {
613 EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1);
614 EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1);
615 EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1);
616
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700617 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800618}
619
620TEST_F(DisplayTest, applyLayerRequestsToLayers2) {
621 EXPECT_CALL(*mLayer1, prepareForDeviceLayerRequests()).Times(1);
622 EXPECT_CALL(*mLayer2, prepareForDeviceLayerRequests()).Times(1);
623 EXPECT_CALL(*mLayer3, prepareForDeviceLayerRequests()).Times(1);
624
625 EXPECT_CALL(*mLayer1,
626 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
627 .Times(1);
628
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700629 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Lloyd Pique66d68602019-02-13 14:23:31 -0800630 {&mHWC2Layer1, HWC2::LayerRequest::ClearClientTarget},
631 {&mHWC2LayerUnknown, HWC2::LayerRequest::ClearClientTarget},
632 });
633}
634
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800635/*
636 * Display::presentAndGetFrameFences()
637 */
638
639TEST_F(DisplayTest, presentAndGetFrameFencesReturnsNoFencesOnNonHwcDisplay) {
640 auto nonHwcDisplay{
641 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
642
643 auto result = nonHwcDisplay->presentAndGetFrameFences();
644
645 ASSERT_TRUE(result.presentFence.get());
646 EXPECT_FALSE(result.presentFence->isValid());
647 EXPECT_EQ(0u, result.layerFences.size());
648}
649
650TEST_F(DisplayTest, presentAndGetFrameFencesReturnsPresentAndLayerFences) {
651 sp<Fence> presentFence = new Fence();
652 sp<Fence> layer1Fence = new Fence();
653 sp<Fence> layer2Fence = new Fence();
654
655 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(DEFAULT_DISPLAY_ID)).Times(1);
656 EXPECT_CALL(mHwComposer, getPresentFence(DEFAULT_DISPLAY_ID)).WillOnce(Return(presentFence));
657 EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mHWC2Layer1))
658 .WillOnce(Return(layer1Fence));
659 EXPECT_CALL(mHwComposer, getLayerReleaseFence(DEFAULT_DISPLAY_ID, &mHWC2Layer2))
660 .WillOnce(Return(layer2Fence));
661 EXPECT_CALL(mHwComposer, clearReleaseFences(DEFAULT_DISPLAY_ID)).Times(1);
662
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700663 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800664
665 EXPECT_EQ(presentFence, result.presentFence);
666
667 EXPECT_EQ(2u, result.layerFences.size());
668 ASSERT_EQ(1, result.layerFences.count(&mHWC2Layer1));
669 EXPECT_EQ(layer1Fence, result.layerFences[&mHWC2Layer1]);
670 ASSERT_EQ(1, result.layerFences.count(&mHWC2Layer2));
671 EXPECT_EQ(layer2Fence, result.layerFences[&mHWC2Layer2]);
672}
673
Lloyd Pique688abd42019-02-15 15:42:24 -0800674/*
675 * Display::setExpensiveRenderingExpected()
676 */
677
678TEST_F(DisplayTest, setExpensiveRenderingExpectedForwardsToPowerAdvisor) {
679 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700680 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800681
682 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700683 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800684}
685
Lloyd Piqued3d69882019-02-28 16:03:46 -0800686/*
687 * Display::finishFrame()
688 */
689
690TEST_F(DisplayTest, finishFrameDoesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
691 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700692 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800693
694 // We expect no calls to queueBuffer if composition was skipped.
695 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
696
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700697 mDisplay->editState().isEnabled = true;
698 mDisplay->editState().usesClientComposition = false;
699 mDisplay->editState().viewport = Rect(0, 0, 1, 1);
700 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800701
702 CompositionRefreshArgs refreshArgs;
703 refreshArgs.repaintEverything = false;
704
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700705 mDisplay->finishFrame(refreshArgs);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800706}
707
708TEST_F(DisplayTest, finishFrameSkipsCompositionIfNotDirty) {
709 std::shared_ptr<impl::Display> nonHwcDisplay{
710 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
711
712 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
713 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
714
715 // We expect no calls to queueBuffer if composition was skipped.
716 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
717
718 nonHwcDisplay->editState().isEnabled = true;
719 nonHwcDisplay->editState().usesClientComposition = false;
720 nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1);
721 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
722
723 CompositionRefreshArgs refreshArgs;
724 refreshArgs.repaintEverything = false;
725
726 nonHwcDisplay->finishFrame(refreshArgs);
727}
728
729TEST_F(DisplayTest, finishFramePerformsCompositionIfDirty) {
730 std::shared_ptr<impl::Display> nonHwcDisplay{
731 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
732
733 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
734 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
735
736 // We expect a single call to queueBuffer when composition is not skipped.
737 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
738
739 nonHwcDisplay->editState().isEnabled = true;
740 nonHwcDisplay->editState().usesClientComposition = false;
741 nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1);
742 nonHwcDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
743
744 CompositionRefreshArgs refreshArgs;
745 refreshArgs.repaintEverything = false;
746
747 nonHwcDisplay->finishFrame(refreshArgs);
748}
749
750TEST_F(DisplayTest, finishFramePerformsCompositionIfRepaintEverything) {
751 std::shared_ptr<impl::Display> nonHwcDisplay{
752 impl::createDisplay(mCompositionEngine, DisplayCreationArgsBuilder().build())};
753
754 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
755 nonHwcDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
756
757 // We expect a single call to queueBuffer when composition is not skipped.
758 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
759
760 nonHwcDisplay->editState().isEnabled = true;
761 nonHwcDisplay->editState().usesClientComposition = false;
762 nonHwcDisplay->editState().viewport = Rect(0, 0, 1, 1);
763 nonHwcDisplay->editState().dirtyRegion = Region::INVALID_REGION;
764
765 CompositionRefreshArgs refreshArgs;
766 refreshArgs.repaintEverything = true;
767
768 nonHwcDisplay->finishFrame(refreshArgs);
769}
770
Lloyd Pique45a165a2018-10-19 11:54:47 -0700771} // namespace
772} // namespace android::compositionengine