blob: d2c945c67b8febd1245de2822bca3f1b4408ec17 [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"
Alec Mouricdf16792021-12-10 13:16:06 -080040#include "ftl/future.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070041
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050042#include <aidl/android/hardware/graphics/composer3/Composition.h>
43
Ady Abrahamde549d42022-01-26 19:19:17 -080044using aidl::android::hardware::graphics::composer3::Capability;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050045using aidl::android::hardware::graphics::composer3::Composition;
46
Lloyd Pique45a165a2018-10-19 11:54:47 -070047namespace android::compositionengine {
48namespace {
49
Peiyong Line9d809e2020-04-14 13:10:48 -070050namespace hal = android::hardware::graphics::composer::hal;
51
Lloyd Piquef5275482019-01-29 18:42:42 -080052using testing::_;
Alec Mouricdf16792021-12-10 13:16:06 -080053using testing::ByMove;
Lloyd Pique66d68602019-02-13 14:23:31 -080054using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070055using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080056using testing::InSequence;
57using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070058using testing::Pointee;
59using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070060using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070061using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080062using testing::Sequence;
63using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070064using testing::StrictMock;
65
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080066constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
67constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
68constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
Dominik Laskowskif1833852021-03-23 15:06:50 -070069
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080070constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080};
Lloyd Pique45a165a2018-10-19 11:54:47 -070071
Lloyd Piquede196652020-01-22 17:29:58 -080072struct Layer {
73 Layer() {
74 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
75 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
76 }
77
Ady Abrahame0eafa82022-02-02 19:30:47 -080078 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080079 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
80 StrictMock<HWC2::mock::Layer> hwc2Layer;
81};
82
83struct LayerNoHWC2Layer {
84 LayerNoHWC2Layer() {
85 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
86 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
87 }
88
Ady Abrahame0eafa82022-02-02 19:30:47 -080089 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080090 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
91};
92
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070093struct DisplayTestCommon : public testing::Test {
94 // Uses the full implementation of a display
95 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070096 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070097 using impl::Display::injectOutputLayerForTest;
98 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
99 };
100
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700101 // Uses a special implementation with key internal member functions set up
102 // as mock implementations, to allow for easier testing.
103 struct PartialMockDisplay : public impl::Display {
104 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
105 : mCompositionEngine(compositionEngine) {}
106
107 // compositionengine::Output overrides
108 const OutputCompositionState& getState() const override { return mState; }
109 OutputCompositionState& editState() override { return mState; }
110
111 // compositionengine::impl::Output overrides
112 const CompositionEngine& getCompositionEngine() const override {
113 return mCompositionEngine;
114 };
115
116 // Mock implementation overrides
117 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
118 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
119 compositionengine::OutputLayer*(size_t));
120 MOCK_METHOD2(ensureOutputLayer,
121 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
122 MOCK_METHOD0(finalizePendingOutputLayers, void());
123 MOCK_METHOD0(clearOutputLayers, void());
124 MOCK_CONST_METHOD1(dumpState, void(std::string&));
125 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
126 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
127 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
128 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
129 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
130 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
131 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
132
133 const compositionengine::CompositionEngine& mCompositionEngine;
134 impl::OutputCompositionState mState;
135 };
136
137 static std::string getDisplayNameFromCurrentTest() {
138 const ::testing::TestInfo* const test_info =
139 ::testing::UnitTest::GetInstance()->current_test_info();
140 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
141 }
142
143 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700144 static std::shared_ptr<Display> createDisplay(
145 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700146 compositionengine::DisplayCreationArgs args) {
147 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700148 return impl::createDisplayTemplated<Display>(compositionEngine, args);
149 }
150
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700151 template <typename Display>
152 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
153 const compositionengine::CompositionEngine& compositionEngine,
154 compositionengine::DisplayCreationArgs args) {
155 args.name = getDisplayNameFromCurrentTest();
156 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800157
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700158 display->setConfiguration(args);
159
160 return display;
161 }
162
163 DisplayTestCommon() {
164 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700165 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
166 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700167 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700168 }
169
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700170 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700171 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800172 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800173 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700174 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700175 .setPowerAdvisor(&mPowerAdvisor)
176 .build();
177 }
178
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800179 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700180 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800181 .setId(GPU_VIRTUAL_DISPLAY_ID)
182 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700183 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700184 .setPowerAdvisor(&mPowerAdvisor)
185 .build();
186 }
187
188 StrictMock<android::mock::HWComposer> mHwComposer;
189 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700190 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700191 StrictMock<mock::CompositionEngine> mCompositionEngine;
192 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
193};
194
195struct PartialMockDisplayTestCommon : public DisplayTestCommon {
196 using Display = DisplayTestCommon::PartialMockDisplay;
197 std::shared_ptr<Display> mDisplay =
198 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700199 getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700200};
201
202struct FullDisplayImplTestCommon : public DisplayTestCommon {
203 using Display = DisplayTestCommon::FullImplDisplay;
204 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700205 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700206};
207
208struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
209 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700210 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800211 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700212 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800213 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700214 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800215 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800216 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700217
Lloyd Piquede196652020-01-22 17:29:58 -0800218 Layer mLayer1;
219 Layer mLayer2;
220 LayerNoHWC2Layer mLayer3;
221 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700222 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700223 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700224};
225
Lloyd Pique66d68602019-02-13 14:23:31 -0800226/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700227 * Basic construction
228 */
229
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700230struct DisplayCreationTest : public DisplayTestCommon {
231 using Display = DisplayTestCommon::FullImplDisplay;
232};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700233
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700234TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
235 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700236 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700237 EXPECT_TRUE(display->isSecure());
238 EXPECT_FALSE(display->isVirtual());
239 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
240}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700241
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800242TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
243 auto display =
244 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700245 EXPECT_FALSE(display->isSecure());
246 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200247 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700248}
249
250/*
251 * Display::setConfiguration()
252 */
253
254using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
255
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700256TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800257 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
258 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800259 .setPixels(DEFAULT_RESOLUTION)
260 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800261 .setPowerAdvisor(&mPowerAdvisor)
262 .setName(getDisplayNameFromCurrentTest())
263 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700264
265 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
266 EXPECT_TRUE(mDisplay->isSecure());
267 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700268 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700269
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700270 const auto& filter = mDisplay->getState().layerFilter;
271 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
272 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700273}
274
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800275TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
276 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
277 .setId(HAL_VIRTUAL_DISPLAY_ID)
278 .setPixels(DEFAULT_RESOLUTION)
279 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800280 .setPowerAdvisor(&mPowerAdvisor)
281 .setName(getDisplayNameFromCurrentTest())
282 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700283
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800284 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700285 EXPECT_FALSE(mDisplay->isSecure());
286 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700287 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700288
289 const auto& filter = mDisplay->getState().layerFilter;
290 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
291 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700292}
293
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800294TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
295 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
296 .setId(GPU_VIRTUAL_DISPLAY_ID)
297 .setPixels(DEFAULT_RESOLUTION)
298 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800299 .setPowerAdvisor(&mPowerAdvisor)
300 .setName(getDisplayNameFromCurrentTest())
301 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700302
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800303 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700304 EXPECT_FALSE(mDisplay->isSecure());
305 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700306 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700307
308 const auto& filter = mDisplay->getState().layerFilter;
309 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
310 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700311}
312
Lloyd Pique66d68602019-02-13 14:23:31 -0800313/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700314 * Display::disconnect()
315 */
316
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700317using DisplayDisconnectTest = PartialMockDisplayTestCommon;
318
319TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200320 // The first call to disconnect will disconnect the display with the HWC.
321 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700322 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700323
324 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200325 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700326 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700327}
328
Lloyd Pique66d68602019-02-13 14:23:31 -0800329/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700330 * Display::setColorTransform()
331 */
332
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700333using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
334
335TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800336 // No change does nothing
337 CompositionRefreshArgs refreshArgs;
338 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700339 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800340
Lloyd Pique32cbe282018-10-19 13:09:22 -0700341 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800342 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700343
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200344 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
345 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700346
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800347 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700348 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700349
350 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800351 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700352
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200353 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
354 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700355
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800356 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700357 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700358}
359
Lloyd Pique66d68602019-02-13 14:23:31 -0800360/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700361 * Display::setColorMode()
362 */
363
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700364using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
365
366TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800367 using ColorProfile = Output::ColorProfile;
368
Lloyd Pique31cb2942018-10-19 17:23:03 -0700369 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700370 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800371 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700372 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700373
Lloyd Piquef5275482019-01-29 18:42:42 -0800374 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
375 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700376
377 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700378 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
379 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
380 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
381 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700382
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700383 // Otherwise if the values are unchanged, nothing happens
384 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
385 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700386
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700387 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
388 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
389 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
390 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700391
392 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800393 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700394 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800395 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700396 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
397 .Times(1);
398
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700399 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
400 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
401 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700402
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700403 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
404 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
405 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
406 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700407}
408
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700409TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800410 using ColorProfile = Output::ColorProfile;
411
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800412 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700413 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700414
Lloyd Piquef5275482019-01-29 18:42:42 -0800415 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700416 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800417 std::unique_ptr<DisplayColorProfile>(colorProfile));
418
419 EXPECT_CALL(*colorProfile,
420 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
421 ui::Dataspace::UNKNOWN))
422 .WillOnce(Return(ui::Dataspace::UNKNOWN));
423
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700424 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800425 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
426 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700427
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700428 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
429 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
430 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
431 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700432}
433
Lloyd Pique66d68602019-02-13 14:23:31 -0800434/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700435 * Display::createDisplayColorProfile()
436 */
437
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700438using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
439
440TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700441 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
442 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700443 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
444 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700445 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700446}
447
Lloyd Pique66d68602019-02-13 14:23:31 -0800448/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700449 * Display::createRenderSurface()
450 */
451
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700452using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
453
454TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700455 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700456 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700457 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
458 .setDisplayWidth(640)
459 .setDisplayHeight(480)
460 .setNativeWindow(mNativeWindow)
461 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700462 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700463}
464
Lloyd Pique66d68602019-02-13 14:23:31 -0800465/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800466 * Display::createOutputLayer()
467 */
468
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700469using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
470
471TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800472 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea516c002021-05-07 14:36:58 -0700473 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800474
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200475 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700476 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800477
Lloyd Piquede196652020-01-22 17:29:58 -0800478 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800479
Lloyd Piquea516c002021-05-07 14:36:58 -0700480 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800481
Lloyd Piquedf336d92019-03-07 21:38:42 -0800482 outputLayer.reset();
483}
484
485/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800486 * Display::setReleasedLayers()
487 */
488
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700489using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
490
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800491TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
492 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
493 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800494
495 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800496
497 {
498 Output::ReleasedLayers releasedLayers;
499 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800500 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800501 }
502
503 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800504 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800505
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800506 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800507
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800508 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
509 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800510}
511
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700512TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800513 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
514
515 {
516 Output::ReleasedLayers releasedLayers;
517 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700518 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800519 }
520
521 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700522 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800523
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700524 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800525 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800526}
527
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700528TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800529 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800530
531 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800532 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
533 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
534 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800535
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700536 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800537
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700538 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800539 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800540 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
541 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800542}
543
544/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800545 * Display::chooseCompositionStrategy()
546 */
547
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700548using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800549
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800550TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
551 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
552 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700553 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800554 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800555
Robert Carr6fe2bef2022-03-09 13:49:41 -0800556 gpuDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800557
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800558 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800559 EXPECT_TRUE(state.usesClientComposition);
560 EXPECT_FALSE(state.usesDeviceComposition);
561}
562
563TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700564 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200565 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800566 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800567 .WillOnce(Return(INVALID_OPERATION));
568
Robert Carr6fe2bef2022-03-09 13:49:41 -0800569 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800570
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700571 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800572 EXPECT_TRUE(state.usesClientComposition);
573 EXPECT_FALSE(state.usesDeviceComposition);
574}
575
576TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700577 // Since two calls are made to anyLayersRequireClientComposition with different return
578 // values, use a Sequence to control the matching so the values are returned in a known
579 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800580 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700581 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
582 .InSequence(s)
583 .WillOnce(Return(true));
584 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800585 .InSequence(s)
586 .WillOnce(Return(false));
587
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700588 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800589 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Robert Carr6fe2bef2022-03-09 13:49:41 -0800590 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700591 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800592
Robert Carr6fe2bef2022-03-09 13:49:41 -0800593 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800594
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700595 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800596 EXPECT_FALSE(state.usesClientComposition);
597 EXPECT_TRUE(state.usesDeviceComposition);
598}
599
Alec Mouricdf16792021-12-10 13:16:06 -0800600TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithDisplayBrightness) {
601 // 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.
604 constexpr float kDisplayBrightness = 0.5f;
605 Sequence s;
606 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
607 .InSequence(s)
608 .WillOnce(Return(true));
609 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
610 .InSequence(s)
611 .WillOnce(Return(false));
612 EXPECT_CALL(mHwComposer,
613 setDisplayBrightness(DEFAULT_DISPLAY_ID, kDisplayBrightness,
614 Hwc2::Composer::DisplayBrightnessOptions{.applyImmediately =
615 false}))
616 .WillOnce(Return(ByMove(ftl::yield<status_t>(NO_ERROR))));
617
618 EXPECT_CALL(mHwComposer,
619 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Robert Carr6fe2bef2022-03-09 13:49:41 -0800620 .WillOnce(Return(NO_ERROR));
Alec Mouricdf16792021-12-10 13:16:06 -0800621 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
622
623 mDisplay->setNextBrightness(kDisplayBrightness);
Robert Carr6fe2bef2022-03-09 13:49:41 -0800624 mDisplay->chooseCompositionStrategy();
Alec Mouricdf16792021-12-10 13:16:06 -0800625
626 auto& state = mDisplay->getState();
627 EXPECT_FALSE(state.usesClientComposition);
628 EXPECT_TRUE(state.usesDeviceComposition);
629 EXPECT_FALSE(state.displayBrightness.has_value());
630}
631
Lloyd Pique66d68602019-02-13 14:23:31 -0800632TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
Robert Carr6fe2bef2022-03-09 13:49:41 -0800633 android::HWComposer::DeviceRequestedChanges changes{
634 {{nullptr, Composition::CLIENT}},
635 hal::DisplayRequest::FLIP_CLIENT_TARGET,
636 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Alec Mouri85065692022-03-18 00:58:26 +0000637 {.clientTargetProperty =
638 {aidl::android::hardware::graphics::common::PixelFormat::RGBA_8888,
639 aidl::android::hardware::graphics::common::Dataspace::UNKNOWN},
640 .brightness = -1.f,
641 .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::NONE},
Robert Carr6fe2bef2022-03-09 13:49:41 -0800642 };
643
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700644 // Since two calls are made to anyLayersRequireClientComposition with different return
645 // values, use a Sequence to control the matching so the values are returned in a known
646 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800647 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700648 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
649 .InSequence(s)
650 .WillOnce(Return(true));
651 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800652 .InSequence(s)
653 .WillOnce(Return(false));
654
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700655 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800656 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Robert Carr6fe2bef2022-03-09 13:49:41 -0800657 .WillOnce(DoAll(SetArgPointee<5>(changes), Return(NO_ERROR)));
658 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
659 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
660 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700661 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800662
Robert Carr6fe2bef2022-03-09 13:49:41 -0800663 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800664
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700665 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800666 EXPECT_FALSE(state.usesClientComposition);
667 EXPECT_TRUE(state.usesDeviceComposition);
668}
669
670/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800671 * Display::getSkipColorTransform()
672 */
673
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700674using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500675using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700676
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800677TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Ady Abrahamde549d42022-01-26 19:19:17 -0800678 EXPECT_CALL(mHwComposer, hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700679 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800680 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
681 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
682 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800683}
684
Dominik Laskowski1162e472020-04-02 19:02:47 -0700685TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800686 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200687 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500688 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800689 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700690 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800691}
692
693/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800694 * Display::anyLayersRequireClientComposition()
695 */
696
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700697using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
698
699TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800700 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
701 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
702 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800703
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700704 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800705}
706
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700707TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800708 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
709 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800710
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700711 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800712}
713
714/*
715 * Display::allLayersRequireClientComposition()
716 */
717
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700718using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
719
720TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800721 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
722 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
723 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800724
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700725 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800726}
727
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700728TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800729 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
730 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800731
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700732 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800733}
734
735/*
736 * Display::applyChangedTypesToLayers()
737 */
738
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700739using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
740
741TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700742 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800743}
744
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700745TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500746 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800747 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500748 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800749 .Times(1);
750
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700751 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500752 {&mLayer1.hwc2Layer, Composition::CLIENT},
753 {&mLayer2.hwc2Layer, Composition::DEVICE},
754 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800755 });
756}
757
758/*
759 * Display::applyDisplayRequests()
760 */
761
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700762using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
763
764TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700765 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800766
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700767 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800768 EXPECT_FALSE(state.flipClientTarget);
769}
770
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700771TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700772 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800773
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700774 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800775 EXPECT_TRUE(state.flipClientTarget);
776}
777
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700778TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700779 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800780
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700781 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800782 EXPECT_FALSE(state.flipClientTarget);
783}
784
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700785TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700786 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800787
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700788 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800789 EXPECT_TRUE(state.flipClientTarget);
790}
791
792/*
793 * Display::applyLayerRequestsToLayers()
794 */
795
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700796using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
797
798TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800799 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
800 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
801 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800802
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700803 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800804}
805
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700806TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800807 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
808 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
809 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800810
Lloyd Piquede196652020-01-22 17:29:58 -0800811 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800812 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
813 .Times(1);
814
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700815 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700816 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
817 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800818 });
819}
820
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800821/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700822 * Display::applyClientTargetRequests()
823 */
824
825using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
826
827TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700828 static constexpr float kWhitePointNits = 800.f;
829
Alec Mouri85065692022-03-18 00:58:26 +0000830 Display::ClientTargetProperty clientTargetProperty = {
831 .clientTargetProperty =
832 {
833 .pixelFormat =
834 aidl::android::hardware::graphics::common::PixelFormat::RGB_565,
835 .dataspace = aidl::android::hardware::graphics::common::Dataspace::
836 STANDARD_BT470M,
837 },
838 .brightness = kWhitePointNits,
839 .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
840 };
841
Ady Abraham0094dc62021-06-03 10:08:33 -0700842 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
843 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
844
Alec Mouri85065692022-03-18 00:58:26 +0000845 EXPECT_CALL(*renderSurface,
846 setBufferPixelFormat(static_cast<ui::PixelFormat>(
847 clientTargetProperty.clientTargetProperty.pixelFormat)));
848 EXPECT_CALL(*renderSurface,
849 setBufferDataspace(static_cast<ui::Dataspace>(
850 clientTargetProperty.clientTargetProperty.dataspace)));
851 mDisplay->applyClientTargetRequests(clientTargetProperty);
Ady Abraham0094dc62021-06-03 10:08:33 -0700852
853 auto& state = mDisplay->getState();
Alec Mouri85065692022-03-18 00:58:26 +0000854 EXPECT_EQ(clientTargetProperty.clientTargetProperty.dataspace,
855 static_cast<aidl::android::hardware::graphics::common::Dataspace>(state.dataspace));
Alec Mourif8d093d2022-02-10 15:16:59 -0800856 EXPECT_EQ(kWhitePointNits, state.clientTargetBrightness);
Alec Mouri85065692022-03-18 00:58:26 +0000857 EXPECT_EQ(aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
858 state.clientTargetDimmingStage);
Ady Abraham0094dc62021-06-03 10:08:33 -0700859}
860
861/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800862 * Display::presentAndGetFrameFences()
863 */
864
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700865using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
866
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800867TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
868 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
869 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800870
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800871 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800872
873 ASSERT_TRUE(result.presentFence.get());
874 EXPECT_FALSE(result.presentFence->isValid());
875 EXPECT_EQ(0u, result.layerFences.size());
876}
877
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700878TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800879 sp<Fence> presentFence = new Fence();
880 sp<Fence> layer1Fence = new Fence();
881 sp<Fence> layer2Fence = new Fence();
882
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700883 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700884 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200885 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
886 .WillOnce(Return(presentFence));
887 EXPECT_CALL(mHwComposer,
888 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800889 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200890 EXPECT_CALL(mHwComposer,
891 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800892 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200893 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800894
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700895 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800896
897 EXPECT_EQ(presentFence, result.presentFence);
898
899 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800900 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800901 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800902 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800903 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800904}
905
Lloyd Pique688abd42019-02-15 15:42:24 -0800906/*
907 * Display::setExpensiveRenderingExpected()
908 */
909
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700910using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
911
912TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800913 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700914 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800915
916 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700917 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800918}
919
Lloyd Piqued3d69882019-02-28 16:03:46 -0800920/*
921 * Display::finishFrame()
922 */
923
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700924using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
925
926TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800927 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700928 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800929
930 // We expect no calls to queueBuffer if composition was skipped.
931 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
932
Lloyd Piquea76ce462020-01-14 13:06:37 -0800933 // Expect a call to signal no expensive rendering since there is no client composition.
934 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
935
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700936 mDisplay->editState().isEnabled = true;
937 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000938 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700939 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800940
Robert Carr6fe2bef2022-03-09 13:49:41 -0800941 mDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800942}
943
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700944TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800945 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
946 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800947
948 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800949 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800950
951 // We expect no calls to queueBuffer if composition was skipped.
952 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
953
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800954 gpuDisplay->editState().isEnabled = true;
955 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000956 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800957 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800958
Robert Carr6fe2bef2022-03-09 13:49:41 -0800959 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800960}
961
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700962TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800963 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
964 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800965
966 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800967 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800968
969 // We expect a single call to queueBuffer when composition is not skipped.
970 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
971
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800972 gpuDisplay->editState().isEnabled = true;
973 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000974 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800975 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Robert Carr6fe2bef2022-03-09 13:49:41 -0800976 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800977}
978
Lloyd Piquec6607552019-12-02 17:57:39 -0800979/*
980 * Display functional tests
981 */
982
983struct DisplayFunctionalTest : public testing::Test {
984 class Display : public impl::Display {
985 public:
Lloyd Piquec6607552019-12-02 17:57:39 -0800986 using impl::Display::injectOutputLayerForTest;
987 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
988 };
989
Lloyd Piquec6607552019-12-02 17:57:39 -0800990 DisplayFunctionalTest() {
991 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Kriti Dang646f8ec2022-01-18 14:35:02 +0100992 mDisplay = createDisplay();
993 mRenderSurface = createRenderSurface();
Lloyd Piquec6607552019-12-02 17:57:39 -0800994 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
995 }
996
997 NiceMock<android::mock::HWComposer> mHwComposer;
998 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
999 NiceMock<mock::CompositionEngine> mCompositionEngine;
1000 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1001 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Kriti Dang646f8ec2022-01-18 14:35:02 +01001002 std::shared_ptr<Display> mDisplay;
1003 impl::RenderSurface* mRenderSurface;
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001004
Kriti Dang646f8ec2022-01-18 14:35:02 +01001005 std::shared_ptr<Display> createDisplay() {
1006 return impl::createDisplayTemplated<Display>(mCompositionEngine,
1007 DisplayCreationArgsBuilder()
1008 .setId(DEFAULT_DISPLAY_ID)
1009 .setPixels(DEFAULT_RESOLUTION)
1010 .setIsSecure(true)
1011 .setPowerAdvisor(&mPowerAdvisor)
1012 .build());
1013 ;
1014 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001015
Kriti Dang646f8ec2022-01-18 14:35:02 +01001016 impl::RenderSurface* createRenderSurface() {
1017 return new impl::RenderSurface{mCompositionEngine, *mDisplay,
1018 RenderSurfaceCreationArgsBuilder()
1019 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1020 .setDisplayHeight(DEFAULT_RESOLUTION.height)
1021 .setNativeWindow(mNativeWindow)
1022 .setDisplaySurface(mDisplaySurface)
1023 .build()};
1024 }
Lloyd Piquec6607552019-12-02 17:57:39 -08001025};
1026
1027TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1028 InSequence seq;
1029
1030 mDisplay->editState().isEnabled = true;
1031
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001032 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001033 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1034
1035 mDisplay->postFramebuffer();
1036}
1037
Lloyd Pique45a165a2018-10-19 11:54:47 -07001038} // namespace
1039} // namespace android::compositionengine