blob: b27e30cd6307aae6caf2559160ebda447a92d645 [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));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700167 }
168
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700169 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700170 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800171 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800172 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700173 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700174 .setPowerAdvisor(&mPowerAdvisor)
175 .build();
176 }
177
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800178 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700179 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800180 .setId(GPU_VIRTUAL_DISPLAY_ID)
181 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700182 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700183 .setPowerAdvisor(&mPowerAdvisor)
184 .build();
185 }
186
187 StrictMock<android::mock::HWComposer> mHwComposer;
188 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700189 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700190 StrictMock<mock::CompositionEngine> mCompositionEngine;
191 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
192};
193
194struct PartialMockDisplayTestCommon : public DisplayTestCommon {
195 using Display = DisplayTestCommon::PartialMockDisplay;
196 std::shared_ptr<Display> mDisplay =
197 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700198 getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700199};
200
201struct FullDisplayImplTestCommon : public DisplayTestCommon {
202 using Display = DisplayTestCommon::FullImplDisplay;
203 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700204 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700205};
206
207struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
208 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700209 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800210 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700211 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800212 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700213 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800214 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Lloyd Pique66d68602019-02-13 14:23:31 -0800215 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700216
Lloyd Piquede196652020-01-22 17:29:58 -0800217 Layer mLayer1;
218 Layer mLayer2;
219 LayerNoHWC2Layer mLayer3;
220 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700221 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700222 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Pique45a165a2018-10-19 11:54:47 -0700223};
224
Lloyd Pique66d68602019-02-13 14:23:31 -0800225/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700226 * Basic construction
227 */
228
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700229struct DisplayCreationTest : public DisplayTestCommon {
230 using Display = DisplayTestCommon::FullImplDisplay;
231};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700232
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700233TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
234 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700235 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700236 EXPECT_TRUE(display->isSecure());
237 EXPECT_FALSE(display->isVirtual());
238 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
239}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700240
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800241TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
242 auto display =
243 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700244 EXPECT_FALSE(display->isSecure());
245 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200246 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700247}
248
249/*
250 * Display::setConfiguration()
251 */
252
253using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
254
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700255TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800256 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
257 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800258 .setPixels(DEFAULT_RESOLUTION)
259 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800260 .setPowerAdvisor(&mPowerAdvisor)
261 .setName(getDisplayNameFromCurrentTest())
262 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700263
264 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
265 EXPECT_TRUE(mDisplay->isSecure());
266 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700267 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700268
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700269 const auto& filter = mDisplay->getState().layerFilter;
270 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
271 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700272}
273
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800274TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
275 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
276 .setId(HAL_VIRTUAL_DISPLAY_ID)
277 .setPixels(DEFAULT_RESOLUTION)
278 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800279 .setPowerAdvisor(&mPowerAdvisor)
280 .setName(getDisplayNameFromCurrentTest())
281 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700282
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800283 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700284 EXPECT_FALSE(mDisplay->isSecure());
285 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700286 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700287
288 const auto& filter = mDisplay->getState().layerFilter;
289 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
290 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700291}
292
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800293TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
294 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
295 .setId(GPU_VIRTUAL_DISPLAY_ID)
296 .setPixels(DEFAULT_RESOLUTION)
297 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800298 .setPowerAdvisor(&mPowerAdvisor)
299 .setName(getDisplayNameFromCurrentTest())
300 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700301
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800302 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700303 EXPECT_FALSE(mDisplay->isSecure());
304 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700305 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700306
307 const auto& filter = mDisplay->getState().layerFilter;
308 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
309 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700310}
311
Lloyd Pique66d68602019-02-13 14:23:31 -0800312/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700313 * Display::disconnect()
314 */
315
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700316using DisplayDisconnectTest = PartialMockDisplayTestCommon;
317
318TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200319 // The first call to disconnect will disconnect the display with the HWC.
320 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700321 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700322
323 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200324 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700325 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700326}
327
Lloyd Pique66d68602019-02-13 14:23:31 -0800328/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700329 * Display::setColorTransform()
330 */
331
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700332using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
333
334TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800335 // No change does nothing
336 CompositionRefreshArgs refreshArgs;
337 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700338 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800339
Lloyd Pique32cbe282018-10-19 13:09:22 -0700340 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800341 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700342
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200343 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
344 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700345
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800346 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700347 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700348
349 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800350 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700351
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200352 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
353 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700354
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800355 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700356 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700357}
358
Lloyd Pique66d68602019-02-13 14:23:31 -0800359/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700360 * Display::setColorMode()
361 */
362
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700363using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
364
365TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800366 using ColorProfile = Output::ColorProfile;
367
Lloyd Pique31cb2942018-10-19 17:23:03 -0700368 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700369 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800370 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700371 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700372
Lloyd Piquef5275482019-01-29 18:42:42 -0800373 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
374 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700375
376 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700377 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
378 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
379 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
380 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700381
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700382 // Otherwise if the values are unchanged, nothing happens
383 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
384 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700385
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700386 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
387 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
388 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
389 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700390
391 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800392 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700393 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800394 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700395 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
396 .Times(1);
397
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700398 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
399 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
400 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700401
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700402 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
403 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
404 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
405 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700406}
407
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700408TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800409 using ColorProfile = Output::ColorProfile;
410
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800411 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700412 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700413
Lloyd Piquef5275482019-01-29 18:42:42 -0800414 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700415 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800416 std::unique_ptr<DisplayColorProfile>(colorProfile));
417
418 EXPECT_CALL(*colorProfile,
419 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
420 ui::Dataspace::UNKNOWN))
421 .WillOnce(Return(ui::Dataspace::UNKNOWN));
422
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700423 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800424 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
425 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700426
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700427 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
428 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
429 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
430 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700431}
432
Lloyd Pique66d68602019-02-13 14:23:31 -0800433/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700434 * Display::createDisplayColorProfile()
435 */
436
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700437using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
438
439TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700440 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
441 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700442 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
443 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700444 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700445}
446
Lloyd Pique66d68602019-02-13 14:23:31 -0800447/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700448 * Display::createRenderSurface()
449 */
450
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700451using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
452
453TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700454 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700456 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
457 .setDisplayWidth(640)
458 .setDisplayHeight(480)
459 .setNativeWindow(mNativeWindow)
460 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700461 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700462}
463
Lloyd Pique66d68602019-02-13 14:23:31 -0800464/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800465 * Display::createOutputLayer()
466 */
467
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700468using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
469
470TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800471 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea516c002021-05-07 14:36:58 -0700472 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800473
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200474 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700475 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800476
Lloyd Piquede196652020-01-22 17:29:58 -0800477 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800478
Lloyd Piquea516c002021-05-07 14:36:58 -0700479 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800480
Lloyd Piquedf336d92019-03-07 21:38:42 -0800481 outputLayer.reset();
482}
483
484/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800485 * Display::setReleasedLayers()
486 */
487
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700488using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
489
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800490TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
491 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
492 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800493
494 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800495
496 {
497 Output::ReleasedLayers releasedLayers;
498 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800499 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800500 }
501
502 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800503 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800504
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800505 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800506
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800507 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
508 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800509}
510
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700511TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800512 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
513
514 {
515 Output::ReleasedLayers releasedLayers;
516 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700517 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800518 }
519
520 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700521 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800522
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700523 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800524 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800525}
526
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700527TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800528 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800529
530 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800531 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
532 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
533 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800534
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700535 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800536
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700537 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800538 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800539 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
540 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800541}
542
543/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800544 * Display::chooseCompositionStrategy()
545 */
546
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700547using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800548
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800549TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
550 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
551 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700552 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800553 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800554
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800555 gpuDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800556
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800557 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800558 EXPECT_TRUE(state.usesClientComposition);
559 EXPECT_FALSE(state.usesDeviceComposition);
560}
561
562TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700563 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200564 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800565 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800566 .WillOnce(Return(INVALID_OPERATION));
567
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700568 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800569
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700570 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800571 EXPECT_TRUE(state.usesClientComposition);
572 EXPECT_FALSE(state.usesDeviceComposition);
573}
574
575TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700576 // Since two calls are made to anyLayersRequireClientComposition with different return
577 // values, use a Sequence to control the matching so the values are returned in a known
578 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800579 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700580 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
581 .InSequence(s)
582 .WillOnce(Return(true));
583 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800584 .InSequence(s)
585 .WillOnce(Return(false));
586
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700587 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800588 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800589 .WillOnce(Return(NO_ERROR));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700590 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800591
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700592 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800593
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700594 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800595 EXPECT_FALSE(state.usesClientComposition);
596 EXPECT_TRUE(state.usesDeviceComposition);
597}
598
Alec Mouricdf16792021-12-10 13:16:06 -0800599TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithDisplayBrightness) {
600 // Since two calls are made to anyLayersRequireClientComposition with different return
601 // values, use a Sequence to control the matching so the values are returned in a known
602 // order.
603 constexpr float kDisplayBrightness = 0.5f;
604 Sequence s;
605 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
606 .InSequence(s)
607 .WillOnce(Return(true));
608 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
609 .InSequence(s)
610 .WillOnce(Return(false));
611 EXPECT_CALL(mHwComposer,
612 setDisplayBrightness(DEFAULT_DISPLAY_ID, kDisplayBrightness,
613 Hwc2::Composer::DisplayBrightnessOptions{.applyImmediately =
614 false}))
615 .WillOnce(Return(ByMove(ftl::yield<status_t>(NO_ERROR))));
616
617 EXPECT_CALL(mHwComposer,
618 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
619 .WillOnce(Return(NO_ERROR));
620 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
621
622 mDisplay->setNextBrightness(kDisplayBrightness);
623 mDisplay->chooseCompositionStrategy();
624
625 auto& state = mDisplay->getState();
626 EXPECT_FALSE(state.usesClientComposition);
627 EXPECT_TRUE(state.usesDeviceComposition);
628 EXPECT_FALSE(state.displayBrightness.has_value());
629}
630
Lloyd Pique66d68602019-02-13 14:23:31 -0800631TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
632 android::HWComposer::DeviceRequestedChanges changes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500633 {{nullptr, Composition::CLIENT}},
Peiyong Line9d809e2020-04-14 13:10:48 -0700634 hal::DisplayRequest::FLIP_CLIENT_TARGET,
635 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
Peiyong Lindfc3f7c2020-05-07 20:15:50 -0700636 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700637 -1.f,
Lloyd Pique66d68602019-02-13 14:23:31 -0800638 };
639
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700640 // Since two calls are made to anyLayersRequireClientComposition with different return
641 // values, use a Sequence to control the matching so the values are returned in a known
642 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800643 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700644 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
645 .InSequence(s)
646 .WillOnce(Return(true));
647 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800648 .InSequence(s)
649 .WillOnce(Return(false));
650
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700651 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800652 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
653 .WillOnce(DoAll(SetArgPointee<5>(changes), Return(NO_ERROR)));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700654 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
655 EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
656 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
657 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800658
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700659 mDisplay->chooseCompositionStrategy();
Lloyd Pique66d68602019-02-13 14:23:31 -0800660
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700661 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800662 EXPECT_FALSE(state.usesClientComposition);
663 EXPECT_TRUE(state.usesDeviceComposition);
664}
665
666/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800667 * Display::getSkipColorTransform()
668 */
669
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700670using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500671using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700672
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800673TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700674 EXPECT_CALL(mHwComposer, hasCapability(hal::Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700675 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800676 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
677 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
678 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800679}
680
Dominik Laskowski1162e472020-04-02 19:02:47 -0700681TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800682 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200683 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500684 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800685 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700686 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800687}
688
689/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800690 * Display::anyLayersRequireClientComposition()
691 */
692
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700693using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
694
695TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800696 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
697 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
698 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800699
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700700 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800701}
702
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700703TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800704 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
705 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800706
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700707 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800708}
709
710/*
711 * Display::allLayersRequireClientComposition()
712 */
713
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700714using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
715
716TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800717 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
718 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
719 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800720
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700721 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800722}
723
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700724TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800725 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
726 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800727
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700728 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800729}
730
731/*
732 * Display::applyChangedTypesToLayers()
733 */
734
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700735using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
736
737TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700738 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800739}
740
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700741TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500742 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800743 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500744 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800745 .Times(1);
746
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700747 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500748 {&mLayer1.hwc2Layer, Composition::CLIENT},
749 {&mLayer2.hwc2Layer, Composition::DEVICE},
750 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800751 });
752}
753
754/*
755 * Display::applyDisplayRequests()
756 */
757
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700758using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
759
760TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700761 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800762
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700763 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800764 EXPECT_FALSE(state.flipClientTarget);
765}
766
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700767TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700768 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800769
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700770 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800771 EXPECT_TRUE(state.flipClientTarget);
772}
773
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700774TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700775 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800776
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700777 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800778 EXPECT_FALSE(state.flipClientTarget);
779}
780
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700781TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700782 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800783
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700784 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800785 EXPECT_TRUE(state.flipClientTarget);
786}
787
788/*
789 * Display::applyLayerRequestsToLayers()
790 */
791
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700792using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
793
794TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800795 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
796 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
797 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800798
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700799 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800800}
801
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700802TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800803 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
804 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
805 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800806
Lloyd Piquede196652020-01-22 17:29:58 -0800807 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800808 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
809 .Times(1);
810
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700811 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700812 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
813 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800814 });
815}
816
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800817/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700818 * Display::applyClientTargetRequests()
819 */
820
821using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
822
823TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
824 Display::ClientTargetProperty clientTargetProperty = {
825 .pixelFormat = hal::PixelFormat::RGB_565,
826 .dataspace = hal::Dataspace::STANDARD_BT470M,
827 };
828
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700829 static constexpr float kWhitePointNits = 800.f;
830
Ady Abraham0094dc62021-06-03 10:08:33 -0700831 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
832 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
833
834 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
835 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700836 mDisplay->applyClientTargetRequests(clientTargetProperty, kWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700837
838 auto& state = mDisplay->getState();
839 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700840 EXPECT_EQ(kWhitePointNits, state.clientTargetWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700841}
842
843/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800844 * Display::presentAndGetFrameFences()
845 */
846
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700847using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
848
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800849TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
850 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
851 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800852
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800853 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800854
855 ASSERT_TRUE(result.presentFence.get());
856 EXPECT_FALSE(result.presentFence->isValid());
857 EXPECT_EQ(0u, result.layerFences.size());
858}
859
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700860TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800861 sp<Fence> presentFence = new Fence();
862 sp<Fence> layer1Fence = new Fence();
863 sp<Fence> layer2Fence = new Fence();
864
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700865 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700866 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200867 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
868 .WillOnce(Return(presentFence));
869 EXPECT_CALL(mHwComposer,
870 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800871 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200872 EXPECT_CALL(mHwComposer,
873 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800874 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200875 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800876
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700877 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800878
879 EXPECT_EQ(presentFence, result.presentFence);
880
881 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800882 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800883 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800884 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800885 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800886}
887
Lloyd Pique688abd42019-02-15 15:42:24 -0800888/*
889 * Display::setExpensiveRenderingExpected()
890 */
891
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700892using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
893
894TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800895 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700896 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800897
898 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700899 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800900}
901
Lloyd Piqued3d69882019-02-28 16:03:46 -0800902/*
903 * Display::finishFrame()
904 */
905
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700906using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
907
908TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800909 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700910 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800911
912 // We expect no calls to queueBuffer if composition was skipped.
913 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
914
Lloyd Piquea76ce462020-01-14 13:06:37 -0800915 // Expect a call to signal no expensive rendering since there is no client composition.
916 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
917
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700918 mDisplay->editState().isEnabled = true;
919 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000920 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700921 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800922
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700923 mDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800924}
925
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700926TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800927 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
928 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800929
930 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800931 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800932
933 // We expect no calls to queueBuffer if composition was skipped.
934 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
935
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800936 gpuDisplay->editState().isEnabled = true;
937 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000938 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800939 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800940
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700941 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800942}
943
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700944TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
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 a single call to queueBuffer when composition is not skipped.
952 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
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(Rect(0, 0, 1, 1));
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700958 gpuDisplay->finishFrame({});
Lloyd Piqued3d69882019-02-28 16:03:46 -0800959}
960
Lloyd Piquec6607552019-12-02 17:57:39 -0800961/*
962 * Display functional tests
963 */
964
965struct DisplayFunctionalTest : public testing::Test {
966 class Display : public impl::Display {
967 public:
Lloyd Piquec6607552019-12-02 17:57:39 -0800968 using impl::Display::injectOutputLayerForTest;
969 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
970 };
971
Lloyd Piquec6607552019-12-02 17:57:39 -0800972 DisplayFunctionalTest() {
973 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
974
975 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
976 }
977
978 NiceMock<android::mock::HWComposer> mHwComposer;
979 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
980 NiceMock<mock::CompositionEngine> mCompositionEngine;
981 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
982 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800983
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700984 std::shared_ptr<Display> mDisplay = impl::createDisplayTemplated<
985 Display>(mCompositionEngine,
986 DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800987 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800988 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700989 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700990 .setPowerAdvisor(&mPowerAdvisor)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800991 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700992
Lloyd Piquec6607552019-12-02 17:57:39 -0800993 impl::RenderSurface* mRenderSurface =
994 new impl::RenderSurface{mCompositionEngine, *mDisplay,
Dominik Laskowski50121d52021-04-23 13:01:16 -0700995 RenderSurfaceCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800996 .setDisplayWidth(DEFAULT_RESOLUTION.width)
997 .setDisplayHeight(DEFAULT_RESOLUTION.height)
Dominik Laskowski50121d52021-04-23 13:01:16 -0700998 .setNativeWindow(mNativeWindow)
999 .setDisplaySurface(mDisplaySurface)
1000 .build()};
Lloyd Piquec6607552019-12-02 17:57:39 -08001001};
1002
1003TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1004 InSequence seq;
1005
1006 mDisplay->editState().isEnabled = true;
1007
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001008 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001009 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1010
1011 mDisplay->postFramebuffer();
1012}
1013
Lloyd Pique45a165a2018-10-19 11:54:47 -07001014} // namespace
1015} // namespace android::compositionengine