blob: f2978f904d848cc6170cfcdeedd1792a8e307921 [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>
Lloyd Piquec6607552019-12-02 17:57:39 -080024#include <compositionengine/impl/RenderSurface.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070025#include <compositionengine/mock/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080026#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquec6607552019-12-02 17:57:39 -080027#include <compositionengine/mock/DisplaySurface.h>
Lloyd Piquedf336d92019-03-07 21:38:42 -080028#include <compositionengine/mock/LayerFE.h>
chaviw8beb4142019-04-11 13:09:05 -070029#include <compositionengine/mock/NativeWindow.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080030#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070031#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070032#include <gtest/gtest.h>
Lloyd Piquee9eff972020-05-05 12:36:44 -070033#include <renderengine/mock/RenderEngine.h>
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070034#include <ui/Rect.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010035#include <ui/StaticDisplayInfo.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070036
Lloyd Pique66d68602019-02-13 14:23:31 -080037#include "MockHWC2.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070038#include "MockHWComposer.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080039#include "MockPowerAdvisor.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070040
41namespace android::compositionengine {
42namespace {
43
Peiyong Line9d809e2020-04-14 13:10:48 -070044namespace hal = android::hardware::graphics::composer::hal;
45
Lloyd Piquef5275482019-01-29 18:42:42 -080046using testing::_;
Lloyd Pique66d68602019-02-13 14:23:31 -080047using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070048using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080049using testing::InSequence;
50using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070051using testing::Pointee;
52using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070053using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070054using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080055using testing::Sequence;
56using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070057using testing::StrictMock;
58
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080059constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
60constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
61constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
Dominik Laskowskif1833852021-03-23 15:06:50 -070062
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080063constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080};
Lloyd Pique45a165a2018-10-19 11:54:47 -070064
Lloyd Piquede196652020-01-22 17:29:58 -080065struct Layer {
66 Layer() {
67 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
68 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
69 }
70
71 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
72 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
73 StrictMock<HWC2::mock::Layer> hwc2Layer;
74};
75
76struct LayerNoHWC2Layer {
77 LayerNoHWC2Layer() {
78 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
79 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
80 }
81
82 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
83 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
84};
85
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070086struct DisplayTestCommon : public testing::Test {
87 // Uses the full implementation of a display
88 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070089 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070090 using impl::Display::injectOutputLayerForTest;
91 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
92 };
93
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070094 // Uses a special implementation with key internal member functions set up
95 // as mock implementations, to allow for easier testing.
96 struct PartialMockDisplay : public impl::Display {
97 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
98 : mCompositionEngine(compositionEngine) {}
99
100 // compositionengine::Output overrides
101 const OutputCompositionState& getState() const override { return mState; }
102 OutputCompositionState& editState() override { return mState; }
103
104 // compositionengine::impl::Output overrides
105 const CompositionEngine& getCompositionEngine() const override {
106 return mCompositionEngine;
107 };
108
109 // Mock implementation overrides
110 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
111 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
112 compositionengine::OutputLayer*(size_t));
113 MOCK_METHOD2(ensureOutputLayer,
114 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
115 MOCK_METHOD0(finalizePendingOutputLayers, void());
116 MOCK_METHOD0(clearOutputLayers, void());
117 MOCK_CONST_METHOD1(dumpState, void(std::string&));
118 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
119 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
120 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
121 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
122 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
123 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
124 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
125
126 const compositionengine::CompositionEngine& mCompositionEngine;
127 impl::OutputCompositionState mState;
128 };
129
130 static std::string getDisplayNameFromCurrentTest() {
131 const ::testing::TestInfo* const test_info =
132 ::testing::UnitTest::GetInstance()->current_test_info();
133 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
134 }
135
136 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700137 static std::shared_ptr<Display> createDisplay(
138 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700139 compositionengine::DisplayCreationArgs args) {
140 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700141 return impl::createDisplayTemplated<Display>(compositionEngine, args);
142 }
143
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700144 template <typename Display>
145 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
146 const compositionengine::CompositionEngine& compositionEngine,
147 compositionengine::DisplayCreationArgs args) {
148 args.name = getDisplayNameFromCurrentTest();
149 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800150
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700151 display->setConfiguration(args);
152
153 return display;
154 }
155
156 DisplayTestCommon() {
157 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700158 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
159 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700160 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700161 }
162
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700163 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700164 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800165 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800166 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700167 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700168 .setPowerAdvisor(&mPowerAdvisor)
169 .build();
170 }
171
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800172 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700173 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800174 .setId(GPU_VIRTUAL_DISPLAY_ID)
175 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700176 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700177 .setPowerAdvisor(&mPowerAdvisor)
178 .build();
179 }
180
181 StrictMock<android::mock::HWComposer> mHwComposer;
182 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700183 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700184 StrictMock<mock::CompositionEngine> mCompositionEngine;
185 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
186};
187
188struct PartialMockDisplayTestCommon : public DisplayTestCommon {
189 using Display = DisplayTestCommon::PartialMockDisplay;
190 std::shared_ptr<Display> mDisplay =
191 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700192 getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700193};
194
195struct FullDisplayImplTestCommon : public DisplayTestCommon {
196 using Display = DisplayTestCommon::FullImplDisplay;
197 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700198 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700199};
200
201struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
202 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700203 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800204 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700205 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800206 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700207 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800208 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800209 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700210
Lloyd Piquede196652020-01-22 17:29:58 -0800211 Layer mLayer1;
212 Layer mLayer2;
213 LayerNoHWC2Layer mLayer3;
214 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700215 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700216 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700217};
218
Lloyd Pique66d68602019-02-13 14:23:31 -0800219/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700220 * Basic construction
221 */
222
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700223struct DisplayCreationTest : public DisplayTestCommon {
224 using Display = DisplayTestCommon::FullImplDisplay;
225};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700226
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700227TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
228 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700229 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700230 EXPECT_TRUE(display->isSecure());
231 EXPECT_FALSE(display->isVirtual());
232 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
233}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700234
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800235TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
236 auto display =
237 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700238 EXPECT_FALSE(display->isSecure());
239 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200240 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700241}
242
243/*
244 * Display::setConfiguration()
245 */
246
247using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
248
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700249TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800250 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
251 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800252 .setPixels(DEFAULT_RESOLUTION)
253 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800254 .setPowerAdvisor(&mPowerAdvisor)
255 .setName(getDisplayNameFromCurrentTest())
256 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700257
258 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
259 EXPECT_TRUE(mDisplay->isSecure());
260 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700261 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700262
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700263 const auto& filter = mDisplay->getState().layerFilter;
264 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
265 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700266}
267
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800268TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
269 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
270 .setId(HAL_VIRTUAL_DISPLAY_ID)
271 .setPixels(DEFAULT_RESOLUTION)
272 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800273 .setPowerAdvisor(&mPowerAdvisor)
274 .setName(getDisplayNameFromCurrentTest())
275 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700276
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800277 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700278 EXPECT_FALSE(mDisplay->isSecure());
279 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700280 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700281
282 const auto& filter = mDisplay->getState().layerFilter;
283 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
284 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700285}
286
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800287TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
288 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
289 .setId(GPU_VIRTUAL_DISPLAY_ID)
290 .setPixels(DEFAULT_RESOLUTION)
291 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800292 .setPowerAdvisor(&mPowerAdvisor)
293 .setName(getDisplayNameFromCurrentTest())
294 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700295
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800296 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700297 EXPECT_FALSE(mDisplay->isSecure());
298 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700299 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700300
301 const auto& filter = mDisplay->getState().layerFilter;
302 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
303 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700304}
305
Lloyd Pique66d68602019-02-13 14:23:31 -0800306/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700307 * Display::disconnect()
308 */
309
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700310using DisplayDisconnectTest = PartialMockDisplayTestCommon;
311
312TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200313 // The first call to disconnect will disconnect the display with the HWC.
314 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700315 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700316
317 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200318 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700319 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700320}
321
Lloyd Pique66d68602019-02-13 14:23:31 -0800322/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700323 * Display::setColorTransform()
324 */
325
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700326using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
327
328TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800329 // No change does nothing
330 CompositionRefreshArgs refreshArgs;
331 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700332 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800333
Lloyd Pique32cbe282018-10-19 13:09:22 -0700334 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800335 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700336
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200337 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
338 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700339
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800340 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700341 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700342
343 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800344 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700345
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200346 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
347 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700348
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800349 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700350 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700351}
352
Lloyd Pique66d68602019-02-13 14:23:31 -0800353/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700354 * Display::setColorMode()
355 */
356
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700357using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
358
359TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800360 using ColorProfile = Output::ColorProfile;
361
Lloyd Pique31cb2942018-10-19 17:23:03 -0700362 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700363 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800364 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700365 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700366
Lloyd Piquef5275482019-01-29 18:42:42 -0800367 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
368 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700369
370 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700371 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
372 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
373 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
374 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700375
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700376 // Otherwise if the values are unchanged, nothing happens
377 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
378 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700379
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700380 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
381 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
382 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
383 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700384
385 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800386 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700387 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800388 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700389 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
390 .Times(1);
391
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700392 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
393 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
394 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700395
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700396 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
397 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
398 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
399 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700400}
401
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700402TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800403 using ColorProfile = Output::ColorProfile;
404
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800405 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700406 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700407
Lloyd Piquef5275482019-01-29 18:42:42 -0800408 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700409 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800410 std::unique_ptr<DisplayColorProfile>(colorProfile));
411
412 EXPECT_CALL(*colorProfile,
413 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
414 ui::Dataspace::UNKNOWN))
415 .WillOnce(Return(ui::Dataspace::UNKNOWN));
416
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700417 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800418 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
419 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700420
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700421 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
422 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
423 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
424 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700425}
426
Lloyd Pique66d68602019-02-13 14:23:31 -0800427/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700428 * Display::createDisplayColorProfile()
429 */
430
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700431using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
432
433TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700434 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
435 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700436 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
437 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700438 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700439}
440
Lloyd Pique66d68602019-02-13 14:23:31 -0800441/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700442 * Display::createRenderSurface()
443 */
444
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700445using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
446
447TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700448 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700449 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700450 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
451 .setDisplayWidth(640)
452 .setDisplayHeight(480)
453 .setNativeWindow(mNativeWindow)
454 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700456}
457
Lloyd Pique66d68602019-02-13 14:23:31 -0800458/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800459 * Display::createOutputLayer()
460 */
461
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700462using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
463
464TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800465 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquea516c002021-05-07 14:36:58 -0700466 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800467
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200468 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700469 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800470
Lloyd Piquede196652020-01-22 17:29:58 -0800471 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800472
Lloyd Piquea516c002021-05-07 14:36:58 -0700473 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800474
Lloyd Piquedf336d92019-03-07 21:38:42 -0800475 outputLayer.reset();
476}
477
478/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800479 * Display::setReleasedLayers()
480 */
481
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700482using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
483
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800484TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
485 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
486 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800487
488 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800489
490 {
491 Output::ReleasedLayers releasedLayers;
492 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800493 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800494 }
495
496 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800497 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800498
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800499 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800500
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800501 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
502 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800503}
504
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700505TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800506 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
507
508 {
509 Output::ReleasedLayers releasedLayers;
510 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700511 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800512 }
513
514 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700515 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800516
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700517 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800518 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800519}
520
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700521TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800522 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800523
524 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800525 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
526 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
527 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800528
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700529 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800530
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700531 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800532 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800533 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
534 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800535}
536
537/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800538 * Display::chooseCompositionStrategy()
539 */
540
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700541using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800542
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800543TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
544 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
545 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700546 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800547 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800548
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800549 gpuDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800550
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800551 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800552 EXPECT_TRUE(state.usesClientComposition);
553 EXPECT_FALSE(state.usesDeviceComposition);
554}
555
556TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700557 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200558 EXPECT_CALL(mHwComposer,
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700559 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800560 .WillOnce(Return(INVALID_OPERATION));
561
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700562 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800563
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700564 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800565 EXPECT_TRUE(state.usesClientComposition);
566 EXPECT_FALSE(state.usesDeviceComposition);
567}
568
569TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700570 // Since two calls are made to anyLayersRequireClientComposition with different return
571 // values, use a Sequence to control the matching so the values are returned in a known
572 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800573 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700574 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
575 .InSequence(s)
576 .WillOnce(Return(true));
577 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800578 .InSequence(s)
579 .WillOnce(Return(false));
580
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700581 EXPECT_CALL(mHwComposer,
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700582 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800583 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700584 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800585
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700586 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800587
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700588 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800589 EXPECT_FALSE(state.usesClientComposition);
590 EXPECT_TRUE(state.usesDeviceComposition);
591}
592
593TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
594 android::HWComposer::DeviceRequestedChanges changes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700595 {{nullptr, hal::Composition::CLIENT}},
596 hal::DisplayRequest::FLIP_CLIENT_TARGET,
597 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700598 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Lloyd Pique66d68602019-02-13 14:23:31 -0800599 };
600
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700601 // Since two calls are made to anyLayersRequireClientComposition with different return
602 // values, use a Sequence to control the matching so the values are returned in a known
603 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800604 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700605 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
606 .InSequence(s)
607 .WillOnce(Return(true));
608 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800609 .InSequence(s)
610 .WillOnce(Return(false));
611
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700612 EXPECT_CALL(mHwComposer,
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700613 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _))
614 .WillOnce(DoAll(SetArgPointee<4>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700615 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
616 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
617 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
618 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800619
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700620 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800621
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700622 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800623 EXPECT_FALSE(state.usesClientComposition);
624 EXPECT_TRUE(state.usesDeviceComposition);
625}
626
627/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800628 * Display::getSkipColorTransform()
629 */
630
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700631using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
632
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800633TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700634 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700635 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800636 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
637 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
638 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800639}
640
Dominik Laskowski1162e472020-04-02 19:02:47 -0700641TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800642 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200643 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Peiyong Line9d809e2020-04-14 13:10:48 -0700644 hal::DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800645 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700646 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800647}
648
649/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800650 * Display::anyLayersRequireClientComposition()
651 */
652
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700653using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
654
655TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800656 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
657 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
658 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800659
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700660 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800661}
662
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700663TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800664 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
665 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800666
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700667 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800668}
669
670/*
671 * Display::allLayersRequireClientComposition()
672 */
673
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700674using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
675
676TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800677 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
678 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
679 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800680
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700681 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800682}
683
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700684TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800685 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
686 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800687
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700688 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800689}
690
691/*
692 * Display::applyChangedTypesToLayers()
693 */
694
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700695using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
696
697TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700698 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800699}
700
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700701TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Lloyd Piquede196652020-01-22 17:29:58 -0800702 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800703 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::CLIENT))
704 .Times(1);
Lloyd Piquede196652020-01-22 17:29:58 -0800705 EXPECT_CALL(*mLayer2.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800706 applyDeviceCompositionTypeChange(Hwc2::IComposerClient::Composition::DEVICE))
707 .Times(1);
708
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700709 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Peiyong Line9d809e2020-04-14 13:10:48 -0700710 {&mLayer1.hwc2Layer, hal::Composition::CLIENT},
711 {&mLayer2.hwc2Layer, hal::Composition::DEVICE},
712 {&hwc2LayerUnknown, hal::Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800713 });
714}
715
716/*
717 * Display::applyDisplayRequests()
718 */
719
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700720using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
721
722TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700723 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800724
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700725 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800726 EXPECT_FALSE(state.flipClientTarget);
727}
728
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700729TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700730 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800731
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700732 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800733 EXPECT_TRUE(state.flipClientTarget);
734}
735
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700736TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700737 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800738
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700739 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800740 EXPECT_FALSE(state.flipClientTarget);
741}
742
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700743TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700744 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800745
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700746 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800747 EXPECT_TRUE(state.flipClientTarget);
748}
749
750/*
751 * Display::applyLayerRequestsToLayers()
752 */
753
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700754using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
755
756TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800757 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
758 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
759 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800760
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700761 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800762}
763
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700764TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800765 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
766 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
767 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800768
Lloyd Piquede196652020-01-22 17:29:58 -0800769 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800770 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
771 .Times(1);
772
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700773 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700774 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
775 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800776 });
777}
778
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800779/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700780 * Display::applyClientTargetRequests()
781 */
782
783using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
784
785TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
786 Display::ClientTargetProperty clientTargetProperty = {
787 .pixelFormat = hal::PixelFormat::RGB_565,
788 .dataspace = hal::Dataspace::STANDARD_BT470M,
789 };
790
791 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
792 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
793
794 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
795 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
796 mDisplay->applyClientTargetRequests(clientTargetProperty);
797
798 auto& state = mDisplay->getState();
799 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
800}
801
802/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800803 * Display::presentAndGetFrameFences()
804 */
805
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700806using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
807
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800808TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
809 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
810 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800811
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800812 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800813
814 ASSERT_TRUE(result.presentFence.get());
815 EXPECT_FALSE(result.presentFence->isValid());
816 EXPECT_EQ(0u, result.layerFences.size());
817}
818
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700819TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800820 sp<Fence> presentFence = new Fence();
821 sp<Fence> layer1Fence = new Fence();
822 sp<Fence> layer2Fence = new Fence();
823
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700824 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700825 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200826 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
827 .WillOnce(Return(presentFence));
828 EXPECT_CALL(mHwComposer,
829 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800830 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200831 EXPECT_CALL(mHwComposer,
832 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800833 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200834 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800835
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700836 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800837
838 EXPECT_EQ(presentFence, result.presentFence);
839
840 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800841 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800842 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800843 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800844 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800845}
846
Lloyd Pique688abd42019-02-15 15:42:24 -0800847/*
848 * Display::setExpensiveRenderingExpected()
849 */
850
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700851using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
852
853TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800854 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700855 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800856
857 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700858 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800859}
860
Lloyd Piqued3d69882019-02-28 16:03:46 -0800861/*
862 * Display::finishFrame()
863 */
864
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700865using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
866
867TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800868 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700869 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800870
871 // We expect no calls to queueBuffer if composition was skipped.
872 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
873
Lloyd Piquea76ce462020-01-14 13:06:37 -0800874 // Expect a call to signal no expensive rendering since there is no client composition.
875 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
876
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700877 mDisplay->editState().isEnabled = true;
878 mDisplay->editState().usesClientComposition = false;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200879 mDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700880 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800881
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700882 mDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800883}
884
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700885TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800886 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
887 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800888
889 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800890 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800891
892 // We expect no calls to queueBuffer if composition was skipped.
893 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
894
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800895 gpuDisplay->editState().isEnabled = true;
896 gpuDisplay->editState().usesClientComposition = false;
897 gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
898 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800899
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700900 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800901}
902
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700903TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800904 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
905 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800906
907 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800908 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800909
910 // We expect a single call to queueBuffer when composition is not skipped.
911 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
912
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800913 gpuDisplay->editState().isEnabled = true;
914 gpuDisplay->editState().usesClientComposition = false;
915 gpuDisplay->editState().layerStackSpace.content = Rect(0, 0, 1, 1);
916 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800917
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700918 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800919}
920
Lloyd Piquec6607552019-12-02 17:57:39 -0800921/*
922 * Display functional tests
923 */
924
925struct DisplayFunctionalTest : public testing::Test {
926 class Display : public impl::Display {
927 public:
Lloyd Piquec6607552019-12-02 17:57:39 -0800928 using impl::Display::injectOutputLayerForTest;
929 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
930 };
931
Lloyd Piquec6607552019-12-02 17:57:39 -0800932 DisplayFunctionalTest() {
933 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
934
935 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
936 }
937
938 NiceMock<android::mock::HWComposer> mHwComposer;
939 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
940 NiceMock<mock::CompositionEngine> mCompositionEngine;
941 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
942 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800943
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700944 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
945 Display>(mCompositionEngine,
946 DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800947 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800948 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700949 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700950 .setPowerAdvisor(&mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800951 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700952
Lloyd Piquec6607552019-12-02 17:57:39 -0800953 impl::RenderSurface* mRenderSurface =
954 new impl::RenderSurface{mCompositionEngine, *mDisplay,
Dominik Laskowski50121d52021-04-23 13:01:16 -0700955 RenderSurfaceCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800956 .setDisplayWidth(DEFAULT_RESOLUTION.width)
957 .setDisplayHeight(DEFAULT_RESOLUTION.height)
Dominik Laskowski50121d52021-04-23 13:01:16 -0700958 .setNativeWindow(mNativeWindow)
959 .setDisplaySurface(mDisplaySurface)
960 .build()};
Lloyd Piquec6607552019-12-02 17:57:39 -0800961};
962
963TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
964 InSequence seq;
965
966 mDisplay->editState().isEnabled = true;
967
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700968 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -0800969 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
970
971 mDisplay->postFramebuffer();
972}
973
Lloyd Pique45a165a2018-10-19 11:54:47 -0700974} // namespace
975} // namespace android::compositionengine