blob: 125ce7468e09db9b8eea4e5bb1f3d710e4a628f7 [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
44using aidl::android::hardware::graphics::composer3::Composition;
45
Lloyd Pique45a165a2018-10-19 11:54:47 -070046namespace android::compositionengine {
47namespace {
48
Peiyong Line9d809e2020-04-14 13:10:48 -070049namespace hal = android::hardware::graphics::composer::hal;
50
Lloyd Piquef5275482019-01-29 18:42:42 -080051using testing::_;
Alec Mouricdf16792021-12-10 13:16:06 -080052using testing::ByMove;
Lloyd Pique66d68602019-02-13 14:23:31 -080053using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070054using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080055using testing::InSequence;
56using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070057using testing::Pointee;
58using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070059using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070060using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080061using testing::Sequence;
62using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070063using testing::StrictMock;
64
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080065constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
66constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
67constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
Dominik Laskowskif1833852021-03-23 15:06:50 -070068
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080069constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080};
Lloyd Pique45a165a2018-10-19 11:54:47 -070070
Lloyd Piquede196652020-01-22 17:29:58 -080071struct Layer {
72 Layer() {
73 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
74 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
75 }
76
Ady Abrahame0eafa82022-02-02 19:30:47 -080077 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080078 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
79 StrictMock<HWC2::mock::Layer> hwc2Layer;
80};
81
82struct LayerNoHWC2Layer {
83 LayerNoHWC2Layer() {
84 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
85 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
86 }
87
Ady Abrahame0eafa82022-02-02 19:30:47 -080088 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080089 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
90};
91
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070092struct DisplayTestCommon : public testing::Test {
93 // Uses the full implementation of a display
94 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070095 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070096 using impl::Display::injectOutputLayerForTest;
97 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
98 };
99
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700100 // Uses a special implementation with key internal member functions set up
101 // as mock implementations, to allow for easier testing.
102 struct PartialMockDisplay : public impl::Display {
103 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
104 : mCompositionEngine(compositionEngine) {}
105
106 // compositionengine::Output overrides
107 const OutputCompositionState& getState() const override { return mState; }
108 OutputCompositionState& editState() override { return mState; }
109
110 // compositionengine::impl::Output overrides
111 const CompositionEngine& getCompositionEngine() const override {
112 return mCompositionEngine;
113 };
114
115 // Mock implementation overrides
116 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
117 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
118 compositionengine::OutputLayer*(size_t));
119 MOCK_METHOD2(ensureOutputLayer,
120 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
121 MOCK_METHOD0(finalizePendingOutputLayers, void());
122 MOCK_METHOD0(clearOutputLayers, void());
123 MOCK_CONST_METHOD1(dumpState, void(std::string&));
124 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
125 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
126 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
127 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
128 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
129 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
130 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
131
132 const compositionengine::CompositionEngine& mCompositionEngine;
133 impl::OutputCompositionState mState;
134 };
135
136 static std::string getDisplayNameFromCurrentTest() {
137 const ::testing::TestInfo* const test_info =
138 ::testing::UnitTest::GetInstance()->current_test_info();
139 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
140 }
141
142 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700143 static std::shared_ptr<Display> createDisplay(
144 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700145 compositionengine::DisplayCreationArgs args) {
146 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700147 return impl::createDisplayTemplated<Display>(compositionEngine, args);
148 }
149
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700150 template <typename Display>
151 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
152 const compositionengine::CompositionEngine& compositionEngine,
153 compositionengine::DisplayCreationArgs args) {
154 args.name = getDisplayNameFromCurrentTest();
155 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800156
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700157 display->setConfiguration(args);
158
159 return display;
160 }
161
162 DisplayTestCommon() {
163 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700164 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
165 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700166 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Kriti Dang646f8ec2022-01-18 14:35:02 +0100167 EXPECT_CALL(mHwComposer, getBootDisplayModeSupport()).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
Dominik Laskowski3dce4f42021-03-08 20:48:28 -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
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700569 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, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -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
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700593 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, _, _, _, _))
620 .WillOnce(Return(NO_ERROR));
621 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
622
623 mDisplay->setNextBrightness(kDisplayBrightness);
624 mDisplay->chooseCompositionStrategy();
625
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) {
633 android::HWComposer::DeviceRequestedChanges changes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500634 {{nullptr, Composition::CLIENT}},
Peiyong Line9d809e2020-04-14 13:10:48 -0700635 hal::DisplayRequest::FLIP_CLIENT_TARGET,
636 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700637 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700638 -1.f,
Lloyd Pique66d68602019-02-13 14:23:31 -0800639 };
640
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700641 // Since two calls are made to anyLayersRequireClientComposition with different return
642 // values, use a Sequence to control the matching so the values are returned in a known
643 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800644 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700645 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
646 .InSequence(s)
647 .WillOnce(Return(true));
648 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800649 .InSequence(s)
650 .WillOnce(Return(false));
651
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700652 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800653 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
654 .WillOnce(DoAll(SetArgPointee<5>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700655 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
656 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
657 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
658 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800659
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700660 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800661
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700662 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800663 EXPECT_FALSE(state.usesClientComposition);
664 EXPECT_TRUE(state.usesDeviceComposition);
665}
666
667/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800668 * Display::getSkipColorTransform()
669 */
670
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700671using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500672using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700673
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800674TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700675 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700676 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800677 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
678 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
679 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800680}
681
Dominik Laskowski1162e472020-04-02 19:02:47 -0700682TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800683 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200684 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500685 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800686 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700687 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800688}
689
690/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800691 * Display::anyLayersRequireClientComposition()
692 */
693
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700694using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
695
696TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800697 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
698 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
699 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800700
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700701 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800702}
703
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700704TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800705 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
706 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800707
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700708 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800709}
710
711/*
712 * Display::allLayersRequireClientComposition()
713 */
714
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700715using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
716
717TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800718 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
719 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
720 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800721
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700722 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800723}
724
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700725TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800726 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
727 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800728
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700729 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800730}
731
732/*
733 * Display::applyChangedTypesToLayers()
734 */
735
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700736using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
737
738TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700739 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800740}
741
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700742TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500743 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800744 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500745 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800746 .Times(1);
747
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700748 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500749 {&mLayer1.hwc2Layer, Composition::CLIENT},
750 {&mLayer2.hwc2Layer, Composition::DEVICE},
751 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800752 });
753}
754
755/*
756 * Display::applyDisplayRequests()
757 */
758
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700759using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
760
761TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700762 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800763
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700764 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800765 EXPECT_FALSE(state.flipClientTarget);
766}
767
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700768TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700769 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800770
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700771 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800772 EXPECT_TRUE(state.flipClientTarget);
773}
774
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700775TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700776 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800777
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700778 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800779 EXPECT_FALSE(state.flipClientTarget);
780}
781
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700782TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700783 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800784
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700785 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800786 EXPECT_TRUE(state.flipClientTarget);
787}
788
789/*
790 * Display::applyLayerRequestsToLayers()
791 */
792
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700793using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
794
795TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800796 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
797 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
798 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800799
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700800 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800801}
802
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700803TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800804 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
805 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
806 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800807
Lloyd Piquede196652020-01-22 17:29:58 -0800808 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800809 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
810 .Times(1);
811
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700812 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700813 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
814 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800815 });
816}
817
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800818/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700819 * Display::applyClientTargetRequests()
820 */
821
822using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
823
824TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
825 Display::ClientTargetProperty clientTargetProperty = {
826 .pixelFormat = hal::PixelFormat::RGB_565,
827 .dataspace = hal::Dataspace::STANDARD_BT470M,
828 };
829
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700830 static constexpr float kWhitePointNits = 800.f;
831
Ady Abraham0094dc62021-06-03 10:08:33 -0700832 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
833 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
834
835 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
836 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700837 mDisplay->applyClientTargetRequests(clientTargetProperty, kWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700838
839 auto& state = mDisplay->getState();
840 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700841 EXPECT_EQ(kWhitePointNits, state.clientTargetWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700842}
843
844/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800845 * Display::presentAndGetFrameFences()
846 */
847
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700848using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
849
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800850TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
851 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
852 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800853
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800854 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800855
856 ASSERT_TRUE(result.presentFence.get());
857 EXPECT_FALSE(result.presentFence->isValid());
858 EXPECT_EQ(0u, result.layerFences.size());
859}
860
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700861TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800862 sp<Fence> presentFence = new Fence();
863 sp<Fence> layer1Fence = new Fence();
864 sp<Fence> layer2Fence = new Fence();
865
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700866 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700867 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200868 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
869 .WillOnce(Return(presentFence));
870 EXPECT_CALL(mHwComposer,
871 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800872 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200873 EXPECT_CALL(mHwComposer,
874 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800875 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200876 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800877
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700878 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800879
880 EXPECT_EQ(presentFence, result.presentFence);
881
882 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800883 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800884 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800885 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800886 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800887}
888
Lloyd Pique688abd42019-02-15 15:42:24 -0800889/*
890 * Display::setExpensiveRenderingExpected()
891 */
892
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700893using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
894
895TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800896 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700897 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800898
899 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700900 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800901}
902
Lloyd Piqued3d69882019-02-28 16:03:46 -0800903/*
904 * Display::finishFrame()
905 */
906
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700907using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
908
909TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800910 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700911 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800912
913 // We expect no calls to queueBuffer if composition was skipped.
914 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
915
Lloyd Piquea76ce462020-01-14 13:06:37 -0800916 // Expect a call to signal no expensive rendering since there is no client composition.
917 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
918
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700919 mDisplay->editState().isEnabled = true;
920 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000921 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700922 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800923
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700924 mDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800925}
926
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700927TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800928 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
929 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800930
931 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800932 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800933
934 // We expect no calls to queueBuffer if composition was skipped.
935 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
936
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800937 gpuDisplay->editState().isEnabled = true;
938 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000939 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800940 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800941
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700942 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800943}
944
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700945TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800946 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
947 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800948
949 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800950 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800951
952 // We expect a single call to queueBuffer when composition is not skipped.
953 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
954
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800955 gpuDisplay->editState().isEnabled = true;
956 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000957 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800958 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700959 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800960}
961
Lloyd Piquec6607552019-12-02 17:57:39 -0800962/*
963 * Display functional tests
964 */
965
966struct DisplayFunctionalTest : public testing::Test {
967 class Display : public impl::Display {
968 public:
Lloyd Piquec6607552019-12-02 17:57:39 -0800969 using impl::Display::injectOutputLayerForTest;
970 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
971 };
972
Lloyd Piquec6607552019-12-02 17:57:39 -0800973 DisplayFunctionalTest() {
974 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Kriti Dang646f8ec2022-01-18 14:35:02 +0100975 mDisplay = createDisplay();
976 mRenderSurface = createRenderSurface();
Lloyd Piquec6607552019-12-02 17:57:39 -0800977 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
978 }
979
980 NiceMock<android::mock::HWComposer> mHwComposer;
981 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
982 NiceMock<mock::CompositionEngine> mCompositionEngine;
983 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
984 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Kriti Dang646f8ec2022-01-18 14:35:02 +0100985 std::shared_ptr<Display> mDisplay;
986 impl::RenderSurface* mRenderSurface;
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800987
Kriti Dang646f8ec2022-01-18 14:35:02 +0100988 std::shared_ptr<Display> createDisplay() {
989 return impl::createDisplayTemplated<Display>(mCompositionEngine,
990 DisplayCreationArgsBuilder()
991 .setId(DEFAULT_DISPLAY_ID)
992 .setPixels(DEFAULT_RESOLUTION)
993 .setIsSecure(true)
994 .setPowerAdvisor(&mPowerAdvisor)
995 .build());
996 ;
997 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700998
Kriti Dang646f8ec2022-01-18 14:35:02 +0100999 impl::RenderSurface* createRenderSurface() {
1000 return new impl::RenderSurface{mCompositionEngine, *mDisplay,
1001 RenderSurfaceCreationArgsBuilder()
1002 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1003 .setDisplayHeight(DEFAULT_RESOLUTION.height)
1004 .setNativeWindow(mNativeWindow)
1005 .setDisplaySurface(mDisplaySurface)
1006 .build()};
1007 }
Lloyd Piquec6607552019-12-02 17:57:39 -08001008};
1009
1010TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1011 InSequence seq;
1012
1013 mDisplay->editState().isEnabled = true;
1014
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001015 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001016 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1017
1018 mDisplay->postFramebuffer();
1019}
1020
Lloyd Pique45a165a2018-10-19 11:54:47 -07001021} // namespace
1022} // namespace android::compositionengine