blob: 8558a80d0df7f6281b8453b1a1d9db17a76ced77 [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
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050041#include <aidl/android/hardware/graphics/composer3/Composition.h>
42
43using aidl::android::hardware::graphics::composer3::Composition;
44
Lloyd Pique45a165a2018-10-19 11:54:47 -070045namespace android::compositionengine {
46namespace {
47
Peiyong Line9d809e2020-04-14 13:10:48 -070048namespace hal = android::hardware::graphics::composer::hal;
49
Lloyd Piquef5275482019-01-29 18:42:42 -080050using testing::_;
Lloyd Pique66d68602019-02-13 14:23:31 -080051using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070052using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080053using testing::InSequence;
54using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070055using testing::Pointee;
56using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070057using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070058using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080059using testing::Sequence;
60using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070061using testing::StrictMock;
62
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080063constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
64constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
65constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
Dominik Laskowskif1833852021-03-23 15:06:50 -070066
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080067constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080};
Lloyd Pique45a165a2018-10-19 11:54:47 -070068
Lloyd Piquede196652020-01-22 17:29:58 -080069struct Layer {
70 Layer() {
71 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
72 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
73 }
74
75 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
76 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
77 StrictMock<HWC2::mock::Layer> hwc2Layer;
78};
79
80struct LayerNoHWC2Layer {
81 LayerNoHWC2Layer() {
82 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
83 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
84 }
85
86 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
87 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
88};
89
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070090struct DisplayTestCommon : public testing::Test {
91 // Uses the full implementation of a display
92 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070093 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070094 using impl::Display::injectOutputLayerForTest;
95 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
96 };
97
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070098 // Uses a special implementation with key internal member functions set up
99 // as mock implementations, to allow for easier testing.
100 struct PartialMockDisplay : public impl::Display {
101 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
102 : mCompositionEngine(compositionEngine) {}
103
104 // compositionengine::Output overrides
105 const OutputCompositionState& getState() const override { return mState; }
106 OutputCompositionState& editState() override { return mState; }
107
108 // compositionengine::impl::Output overrides
109 const CompositionEngine& getCompositionEngine() const override {
110 return mCompositionEngine;
111 };
112
113 // Mock implementation overrides
114 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
115 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
116 compositionengine::OutputLayer*(size_t));
117 MOCK_METHOD2(ensureOutputLayer,
118 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
119 MOCK_METHOD0(finalizePendingOutputLayers, void());
120 MOCK_METHOD0(clearOutputLayers, void());
121 MOCK_CONST_METHOD1(dumpState, void(std::string&));
122 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
123 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
124 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
125 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
126 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
127 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
128 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
129
130 const compositionengine::CompositionEngine& mCompositionEngine;
131 impl::OutputCompositionState mState;
132 };
133
134 static std::string getDisplayNameFromCurrentTest() {
135 const ::testing::TestInfo* const test_info =
136 ::testing::UnitTest::GetInstance()->current_test_info();
137 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
138 }
139
140 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700141 static std::shared_ptr<Display> createDisplay(
142 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700143 compositionengine::DisplayCreationArgs args) {
144 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700145 return impl::createDisplayTemplated<Display>(compositionEngine, args);
146 }
147
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700148 template <typename Display>
149 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
150 const compositionengine::CompositionEngine& compositionEngine,
151 compositionengine::DisplayCreationArgs args) {
152 args.name = getDisplayNameFromCurrentTest();
153 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800154
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700155 display->setConfiguration(args);
156
157 return display;
158 }
159
160 DisplayTestCommon() {
161 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700162 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
163 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700164 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700165 }
166
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700167 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700168 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800169 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800170 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700171 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700172 .setPowerAdvisor(&mPowerAdvisor)
173 .build();
174 }
175
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800176 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700177 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800178 .setId(GPU_VIRTUAL_DISPLAY_ID)
179 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700180 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700181 .setPowerAdvisor(&mPowerAdvisor)
182 .build();
183 }
184
185 StrictMock<android::mock::HWComposer> mHwComposer;
186 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700187 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700188 StrictMock<mock::CompositionEngine> mCompositionEngine;
189 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
190};
191
192struct PartialMockDisplayTestCommon : public DisplayTestCommon {
193 using Display = DisplayTestCommon::PartialMockDisplay;
194 std::shared_ptr<Display> mDisplay =
195 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700196 getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700197};
198
199struct FullDisplayImplTestCommon : public DisplayTestCommon {
200 using Display = DisplayTestCommon::FullImplDisplay;
201 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700202 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700203};
204
205struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
206 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700207 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800208 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700209 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800210 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700211 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800212 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800213 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700214
Lloyd Piquede196652020-01-22 17:29:58 -0800215 Layer mLayer1;
216 Layer mLayer2;
217 LayerNoHWC2Layer mLayer3;
218 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700219 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700220 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700221};
222
Lloyd Pique66d68602019-02-13 14:23:31 -0800223/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700224 * Basic construction
225 */
226
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700227struct DisplayCreationTest : public DisplayTestCommon {
228 using Display = DisplayTestCommon::FullImplDisplay;
229};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700230
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700231TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
232 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700233 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700234 EXPECT_TRUE(display->isSecure());
235 EXPECT_FALSE(display->isVirtual());
236 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
237}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700238
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800239TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
240 auto display =
241 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700242 EXPECT_FALSE(display->isSecure());
243 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200244 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700245}
246
247/*
248 * Display::setConfiguration()
249 */
250
251using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
252
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700253TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800254 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
255 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800256 .setPixels(DEFAULT_RESOLUTION)
257 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800258 .setPowerAdvisor(&mPowerAdvisor)
259 .setName(getDisplayNameFromCurrentTest())
260 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700261
262 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
263 EXPECT_TRUE(mDisplay->isSecure());
264 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700265 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700266
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700267 const auto& filter = mDisplay->getState().layerFilter;
268 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
269 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700270}
271
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800272TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
273 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
274 .setId(HAL_VIRTUAL_DISPLAY_ID)
275 .setPixels(DEFAULT_RESOLUTION)
276 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800277 .setPowerAdvisor(&mPowerAdvisor)
278 .setName(getDisplayNameFromCurrentTest())
279 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700280
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800281 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700282 EXPECT_FALSE(mDisplay->isSecure());
283 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700284 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700285
286 const auto& filter = mDisplay->getState().layerFilter;
287 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
288 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700289}
290
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800291TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
292 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
293 .setId(GPU_VIRTUAL_DISPLAY_ID)
294 .setPixels(DEFAULT_RESOLUTION)
295 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800296 .setPowerAdvisor(&mPowerAdvisor)
297 .setName(getDisplayNameFromCurrentTest())
298 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700299
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800300 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700301 EXPECT_FALSE(mDisplay->isSecure());
302 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700303 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700304
305 const auto& filter = mDisplay->getState().layerFilter;
306 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
307 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700308}
309
Lloyd Pique66d68602019-02-13 14:23:31 -0800310/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700311 * Display::disconnect()
312 */
313
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700314using DisplayDisconnectTest = PartialMockDisplayTestCommon;
315
316TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200317 // The first call to disconnect will disconnect the display with the HWC.
318 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700319 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700320
321 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200322 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700323 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700324}
325
Lloyd Pique66d68602019-02-13 14:23:31 -0800326/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700327 * Display::setColorTransform()
328 */
329
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700330using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
331
332TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800333 // No change does nothing
334 CompositionRefreshArgs refreshArgs;
335 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700336 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800337
Lloyd Pique32cbe282018-10-19 13:09:22 -0700338 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800339 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700340
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200341 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
342 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700343
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800344 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700345 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700346
347 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800348 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700349
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200350 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
351 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700352
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800353 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700354 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700355}
356
Lloyd Pique66d68602019-02-13 14:23:31 -0800357/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700358 * Display::setColorMode()
359 */
360
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700361using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
362
363TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800364 using ColorProfile = Output::ColorProfile;
365
Lloyd Pique31cb2942018-10-19 17:23:03 -0700366 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700367 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800368 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700369 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700370
Lloyd Piquef5275482019-01-29 18:42:42 -0800371 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
372 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700373
374 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700375 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
376 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
377 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
378 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700379
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700380 // Otherwise if the values are unchanged, nothing happens
381 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
382 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700383
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700384 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
385 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
386 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
387 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700388
389 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800390 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700391 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800392 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700393 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
394 .Times(1);
395
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700396 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
397 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
398 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700399
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700400 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
401 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
402 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
403 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700404}
405
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700406TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800407 using ColorProfile = Output::ColorProfile;
408
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800409 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700410 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700411
Lloyd Piquef5275482019-01-29 18:42:42 -0800412 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700413 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800414 std::unique_ptr<DisplayColorProfile>(colorProfile));
415
416 EXPECT_CALL(*colorProfile,
417 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
418 ui::Dataspace::UNKNOWN))
419 .WillOnce(Return(ui::Dataspace::UNKNOWN));
420
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700421 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800422 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
423 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700424
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700425 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
426 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
427 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
428 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700429}
430
Lloyd Pique66d68602019-02-13 14:23:31 -0800431/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700432 * Display::createDisplayColorProfile()
433 */
434
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700435using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
436
437TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700438 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
439 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700440 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
441 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700442 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700443}
444
Lloyd Pique66d68602019-02-13 14:23:31 -0800445/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700446 * Display::createRenderSurface()
447 */
448
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700449using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
450
451TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700452 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700453 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700454 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
455 .setDisplayWidth(640)
456 .setDisplayHeight(480)
457 .setNativeWindow(mNativeWindow)
458 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700459 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700460}
461
Lloyd Pique66d68602019-02-13 14:23:31 -0800462/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800463 * Display::createOutputLayer()
464 */
465
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700466using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
467
468TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Lloyd Piquedf336d92019-03-07 21:38:42 -0800469 sp<mock::LayerFE> layerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquea516c002021-05-07 14:36:58 -0700470 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800471
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200472 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700473 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800474
Lloyd Piquede196652020-01-22 17:29:58 -0800475 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800476
Lloyd Piquea516c002021-05-07 14:36:58 -0700477 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800478
Lloyd Piquedf336d92019-03-07 21:38:42 -0800479 outputLayer.reset();
480}
481
482/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800483 * Display::setReleasedLayers()
484 */
485
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700486using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
487
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800488TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
489 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
490 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800491
492 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800493
494 {
495 Output::ReleasedLayers releasedLayers;
496 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800497 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800498 }
499
500 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800501 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800502
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800503 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800504
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800505 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
506 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800507}
508
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700509TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800510 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
511
512 {
513 Output::ReleasedLayers releasedLayers;
514 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700515 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800516 }
517
518 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700519 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800520
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700521 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800522 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800523}
524
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700525TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800526 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800527
528 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800529 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
530 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
531 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800532
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700533 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800534
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700535 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800536 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800537 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
538 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800539}
540
541/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800542 * Display::chooseCompositionStrategy()
543 */
544
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700545using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800546
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800547TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
548 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
549 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700550 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800551 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800552
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800553 gpuDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800554
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800555 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800556 EXPECT_TRUE(state.usesClientComposition);
557 EXPECT_FALSE(state.usesDeviceComposition);
558}
559
560TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700561 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200562 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800563 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800564 .WillOnce(Return(INVALID_OPERATION));
565
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700566 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800567
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700568 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800569 EXPECT_TRUE(state.usesClientComposition);
570 EXPECT_FALSE(state.usesDeviceComposition);
571}
572
573TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700574 // Since two calls are made to anyLayersRequireClientComposition with different return
575 // values, use a Sequence to control the matching so the values are returned in a known
576 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800577 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700578 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
579 .InSequence(s)
580 .WillOnce(Return(true));
581 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800582 .InSequence(s)
583 .WillOnce(Return(false));
584
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700585 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800586 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800587 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700588 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800589
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700590 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800591
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700592 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800593 EXPECT_FALSE(state.usesClientComposition);
594 EXPECT_TRUE(state.usesDeviceComposition);
595}
596
597TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
598 android::HWComposer::DeviceRequestedChanges changes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500599 {{nullptr, Composition::CLIENT}},
Peiyong Line9d809e2020-04-14 13:10:48 -0700600 hal::DisplayRequest::FLIP_CLIENT_TARGET,
601 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700602 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700603 -1.f,
Lloyd Pique66d68602019-02-13 14:23:31 -0800604 };
605
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700606 // Since two calls are made to anyLayersRequireClientComposition with different return
607 // values, use a Sequence to control the matching so the values are returned in a known
608 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800609 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700610 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
611 .InSequence(s)
612 .WillOnce(Return(true));
613 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800614 .InSequence(s)
615 .WillOnce(Return(false));
616
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700617 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800618 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
619 .WillOnce(DoAll(SetArgPointee<5>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700620 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
621 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
622 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
623 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800624
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700625 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800626
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700627 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800628 EXPECT_FALSE(state.usesClientComposition);
629 EXPECT_TRUE(state.usesDeviceComposition);
630}
631
632/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800633 * Display::getSkipColorTransform()
634 */
635
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700636using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500637using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700638
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800639TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700640 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700641 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800642 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
643 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
644 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800645}
646
Dominik Laskowski1162e472020-04-02 19:02:47 -0700647TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800648 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200649 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500650 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800651 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700652 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800653}
654
655/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800656 * Display::anyLayersRequireClientComposition()
657 */
658
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700659using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
660
661TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800662 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
663 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
664 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800665
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700666 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800667}
668
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700669TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800670 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
671 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800672
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700673 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800674}
675
676/*
677 * Display::allLayersRequireClientComposition()
678 */
679
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700680using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
681
682TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800683 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
684 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
685 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800686
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700687 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800688}
689
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700690TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800691 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
692 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800693
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700694 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800695}
696
697/*
698 * Display::applyChangedTypesToLayers()
699 */
700
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700701using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
702
703TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700704 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800705}
706
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700707TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500708 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800709 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500710 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800711 .Times(1);
712
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700713 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500714 {&mLayer1.hwc2Layer, Composition::CLIENT},
715 {&mLayer2.hwc2Layer, Composition::DEVICE},
716 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800717 });
718}
719
720/*
721 * Display::applyDisplayRequests()
722 */
723
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700724using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
725
726TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700727 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800728
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700729 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800730 EXPECT_FALSE(state.flipClientTarget);
731}
732
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700733TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700734 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800735
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700736 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800737 EXPECT_TRUE(state.flipClientTarget);
738}
739
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700740TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700741 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800742
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700743 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800744 EXPECT_FALSE(state.flipClientTarget);
745}
746
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700747TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700748 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800749
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700750 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800751 EXPECT_TRUE(state.flipClientTarget);
752}
753
754/*
755 * Display::applyLayerRequestsToLayers()
756 */
757
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700758using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
759
760TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800761 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
762 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
763 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800764
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700765 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800766}
767
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700768TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800769 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
770 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
771 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800772
Lloyd Piquede196652020-01-22 17:29:58 -0800773 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800774 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
775 .Times(1);
776
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700777 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700778 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
779 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800780 });
781}
782
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800783/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700784 * Display::applyClientTargetRequests()
785 */
786
787using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
788
789TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
790 Display::ClientTargetProperty clientTargetProperty = {
791 .pixelFormat = hal::PixelFormat::RGB_565,
792 .dataspace = hal::Dataspace::STANDARD_BT470M,
793 };
794
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700795 static constexpr float kWhitePointNits = 800.f;
796
Ady Abraham0094dc62021-06-03 10:08:33 -0700797 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
798 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
799
800 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
801 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700802 mDisplay->applyClientTargetRequests(clientTargetProperty, kWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700803
804 auto& state = mDisplay->getState();
805 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700806 EXPECT_EQ(kWhitePointNits, state.clientTargetWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700807}
808
809/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800810 * Display::presentAndGetFrameFences()
811 */
812
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700813using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
814
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800815TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
816 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
817 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800818
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800819 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800820
821 ASSERT_TRUE(result.presentFence.get());
822 EXPECT_FALSE(result.presentFence->isValid());
823 EXPECT_EQ(0u, result.layerFences.size());
824}
825
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700826TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800827 sp<Fence> presentFence = new Fence();
828 sp<Fence> layer1Fence = new Fence();
829 sp<Fence> layer2Fence = new Fence();
830
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700831 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700832 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200833 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
834 .WillOnce(Return(presentFence));
835 EXPECT_CALL(mHwComposer,
836 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800837 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200838 EXPECT_CALL(mHwComposer,
839 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800840 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200841 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800842
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700843 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800844
845 EXPECT_EQ(presentFence, result.presentFence);
846
847 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800848 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800849 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800850 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800851 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800852}
853
Lloyd Pique688abd42019-02-15 15:42:24 -0800854/*
855 * Display::setExpensiveRenderingExpected()
856 */
857
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700858using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
859
860TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800861 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700862 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800863
864 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700865 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800866}
867
Lloyd Piqued3d69882019-02-28 16:03:46 -0800868/*
869 * Display::finishFrame()
870 */
871
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700872using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
873
874TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800875 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700876 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800877
878 // We expect no calls to queueBuffer if composition was skipped.
879 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
880
Lloyd Piquea76ce462020-01-14 13:06:37 -0800881 // Expect a call to signal no expensive rendering since there is no client composition.
882 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
883
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700884 mDisplay->editState().isEnabled = true;
885 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000886 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700887 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800888
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700889 mDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800890}
891
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700892TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800893 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
894 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800895
896 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800897 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800898
899 // We expect no calls to queueBuffer if composition was skipped.
900 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
901
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800902 gpuDisplay->editState().isEnabled = true;
903 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000904 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800905 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800906
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700907 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800908}
909
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700910TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800911 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
912 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800913
914 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800915 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800916
917 // We expect a single call to queueBuffer when composition is not skipped.
918 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
919
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800920 gpuDisplay->editState().isEnabled = true;
921 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000922 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800923 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700924 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800925}
926
Lloyd Piquec6607552019-12-02 17:57:39 -0800927/*
928 * Display functional tests
929 */
930
931struct DisplayFunctionalTest : public testing::Test {
932 class Display : public impl::Display {
933 public:
Lloyd Piquec6607552019-12-02 17:57:39 -0800934 using impl::Display::injectOutputLayerForTest;
935 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
936 };
937
Lloyd Piquec6607552019-12-02 17:57:39 -0800938 DisplayFunctionalTest() {
939 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
940
941 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
942 }
943
944 NiceMock<android::mock::HWComposer> mHwComposer;
945 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
946 NiceMock<mock::CompositionEngine> mCompositionEngine;
947 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
948 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800949
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700950 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
951 Display>(mCompositionEngine,
952 DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800953 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800954 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700955 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700956 .setPowerAdvisor(&mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800957 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700958
Lloyd Piquec6607552019-12-02 17:57:39 -0800959 impl::RenderSurface* mRenderSurface =
960 new impl::RenderSurface{mCompositionEngine, *mDisplay,
Dominik Laskowski50121d52021-04-23 13:01:16 -0700961 RenderSurfaceCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800962 .setDisplayWidth(DEFAULT_RESOLUTION.width)
963 .setDisplayHeight(DEFAULT_RESOLUTION.height)
Dominik Laskowski50121d52021-04-23 13:01:16 -0700964 .setNativeWindow(mNativeWindow)
965 .setDisplaySurface(mDisplaySurface)
966 .build()};
Lloyd Piquec6607552019-12-02 17:57:39 -0800967};
968
969TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
970 InSequence seq;
971
972 mDisplay->editState().isEnabled = true;
973
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700974 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -0800975 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
976
977 mDisplay->postFramebuffer();
978}
979
Lloyd Pique45a165a2018-10-19 11:54:47 -0700980} // namespace
981} // namespace android::compositionengine