blob: 344fea3331454a38c6cd41c335d828bfad028867 [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>
Vishnu Naira3140382022-02-24 14:07:11 -080033#include <renderengine/mock/FakeExternalTexture.h>
Lloyd Piquee9eff972020-05-05 12:36:44 -070034#include <renderengine/mock/RenderEngine.h>
Vishnu Naira3140382022-02-24 14:07:11 -080035
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070036#include <ui/Rect.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010037#include <ui/StaticDisplayInfo.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070038
Lloyd Pique66d68602019-02-13 14:23:31 -080039#include "MockHWC2.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070040#include "MockHWComposer.h"
Lloyd Pique688abd42019-02-15 15:42:24 -080041#include "MockPowerAdvisor.h"
Alec Mouricdf16792021-12-10 13:16:06 -080042#include "ftl/future.h"
Lloyd Pique45a165a2018-10-19 11:54:47 -070043
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050044#include <aidl/android/hardware/graphics/composer3/Composition.h>
45
Ady Abrahamde549d42022-01-26 19:19:17 -080046using aidl::android::hardware::graphics::composer3::Capability;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050047using aidl::android::hardware::graphics::composer3::Composition;
Vishnu Naira3140382022-02-24 14:07:11 -080048using aidl::android::hardware::graphics::composer3::DimmingStage;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050049
Lloyd Pique45a165a2018-10-19 11:54:47 -070050namespace android::compositionengine {
51namespace {
52
Peiyong Line9d809e2020-04-14 13:10:48 -070053namespace hal = android::hardware::graphics::composer::hal;
54
Lloyd Piquef5275482019-01-29 18:42:42 -080055using testing::_;
Alec Mouricdf16792021-12-10 13:16:06 -080056using testing::ByMove;
Lloyd Pique66d68602019-02-13 14:23:31 -080057using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070058using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080059using testing::InSequence;
60using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070061using testing::Pointee;
62using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070063using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070064using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080065using testing::Sequence;
66using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070067using testing::StrictMock;
68
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080069constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
70constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
71constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
Dominik Laskowskif1833852021-03-23 15:06:50 -070072
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080073constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080};
Lloyd Pique45a165a2018-10-19 11:54:47 -070074
Lloyd Piquede196652020-01-22 17:29:58 -080075struct Layer {
76 Layer() {
77 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
78 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
79 }
80
Ady Abrahame0eafa82022-02-02 19:30:47 -080081 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080082 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
83 StrictMock<HWC2::mock::Layer> hwc2Layer;
84};
85
86struct LayerNoHWC2Layer {
87 LayerNoHWC2Layer() {
88 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
89 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
90 }
91
Ady Abrahame0eafa82022-02-02 19:30:47 -080092 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080093 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
94};
95
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070096struct DisplayTestCommon : public testing::Test {
97 // Uses the full implementation of a display
98 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070099 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -0700100 using impl::Display::injectOutputLayerForTest;
101 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
102 };
103
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700104 // Uses a special implementation with key internal member functions set up
105 // as mock implementations, to allow for easier testing.
106 struct PartialMockDisplay : public impl::Display {
107 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
108 : mCompositionEngine(compositionEngine) {}
109
110 // compositionengine::Output overrides
111 const OutputCompositionState& getState() const override { return mState; }
112 OutputCompositionState& editState() override { return mState; }
113
114 // compositionengine::impl::Output overrides
115 const CompositionEngine& getCompositionEngine() const override {
116 return mCompositionEngine;
117 };
118
Vishnu Naira3140382022-02-24 14:07:11 -0800119 size_t getOutputLayerCount() const override { return 1u; }
120
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700121 // Mock implementation overrides
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700122 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
123 compositionengine::OutputLayer*(size_t));
124 MOCK_METHOD2(ensureOutputLayer,
125 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
126 MOCK_METHOD0(finalizePendingOutputLayers, void());
127 MOCK_METHOD0(clearOutputLayers, void());
128 MOCK_CONST_METHOD1(dumpState, void(std::string&));
129 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
130 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
131 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
132 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
133 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
134 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
135 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
136
137 const compositionengine::CompositionEngine& mCompositionEngine;
138 impl::OutputCompositionState mState;
139 };
140
141 static std::string getDisplayNameFromCurrentTest() {
142 const ::testing::TestInfo* const test_info =
143 ::testing::UnitTest::GetInstance()->current_test_info();
144 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
145 }
146
147 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700148 static std::shared_ptr<Display> createDisplay(
149 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700150 compositionengine::DisplayCreationArgs args) {
151 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700152 return impl::createDisplayTemplated<Display>(compositionEngine, args);
153 }
154
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700155 template <typename Display>
156 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
157 const compositionengine::CompositionEngine& compositionEngine,
158 compositionengine::DisplayCreationArgs args) {
159 args.name = getDisplayNameFromCurrentTest();
160 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800161
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700162 display->setConfiguration(args);
163
164 return display;
165 }
166
167 DisplayTestCommon() {
168 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700169 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
170 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700171 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Matt Buckley50c44062022-01-17 20:48:10 +0000172 EXPECT_CALL(mPowerAdvisor, usePowerHintSession()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700173 }
174
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700175 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700176 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800177 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800178 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700179 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700180 .setPowerAdvisor(&mPowerAdvisor)
181 .build();
182 }
183
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800184 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700185 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800186 .setId(GPU_VIRTUAL_DISPLAY_ID)
187 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700188 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700189 .setPowerAdvisor(&mPowerAdvisor)
190 .build();
191 }
192
193 StrictMock<android::mock::HWComposer> mHwComposer;
194 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700195 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700196 StrictMock<mock::CompositionEngine> mCompositionEngine;
197 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
198};
199
200struct PartialMockDisplayTestCommon : public DisplayTestCommon {
201 using Display = DisplayTestCommon::PartialMockDisplay;
202 std::shared_ptr<Display> mDisplay =
203 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700204 getDisplayCreationArgsForPhysicalDisplay());
Vishnu Naira3140382022-02-24 14:07:11 -0800205
206 android::HWComposer::DeviceRequestedChanges mDeviceRequestedChanges{
207 {{nullptr, Composition::CLIENT}},
208 hal::DisplayRequest::FLIP_CLIENT_TARGET,
209 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
210 {DEFAULT_DISPLAY_ID.value,
211 {aidl::android::hardware::graphics::common::PixelFormat::RGBA_8888,
212 aidl::android::hardware::graphics::common::Dataspace::UNKNOWN},
213 -1.f,
214 DimmingStage::NONE},
215 };
216
217 void chooseCompositionStrategy(Display* display) {
218 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
219 bool success = display->chooseCompositionStrategy(&changes);
220 display->resetCompositionStrategy();
221 if (success) {
222 display->applyCompositionStrategy(changes);
223 }
224 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700225};
226
227struct FullDisplayImplTestCommon : public DisplayTestCommon {
228 using Display = DisplayTestCommon::FullImplDisplay;
229 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700230 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700231};
232
233struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
234 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700235 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800236 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700237 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800238 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700239 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800240 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Vishnu Naira3140382022-02-24 14:07:11 -0800241 mResultWithBuffer.buffer = std::make_shared<
242 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
243 1ULL /* bufferId */,
244 HAL_PIXEL_FORMAT_RGBA_8888,
245 0ULL /*usage*/);
Lloyd Pique66d68602019-02-13 14:23:31 -0800246 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700247
Lloyd Piquede196652020-01-22 17:29:58 -0800248 Layer mLayer1;
249 Layer mLayer2;
250 LayerNoHWC2Layer mLayer3;
251 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700252 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700253 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Vishnu Naira3140382022-02-24 14:07:11 -0800254 impl::GpuCompositionResult mResultWithBuffer;
255 impl::GpuCompositionResult mResultWithoutBuffer;
Lloyd Pique45a165a2018-10-19 11:54:47 -0700256};
257
Lloyd Pique66d68602019-02-13 14:23:31 -0800258/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700259 * Basic construction
260 */
261
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700262struct DisplayCreationTest : public DisplayTestCommon {
263 using Display = DisplayTestCommon::FullImplDisplay;
264};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700265
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700266TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
267 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700268 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700269 EXPECT_TRUE(display->isSecure());
270 EXPECT_FALSE(display->isVirtual());
271 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
272}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700273
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800274TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
275 auto display =
276 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700277 EXPECT_FALSE(display->isSecure());
278 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200279 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700280}
281
282/*
283 * Display::setConfiguration()
284 */
285
286using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
287
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700288TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800289 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
290 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800291 .setPixels(DEFAULT_RESOLUTION)
292 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800293 .setPowerAdvisor(&mPowerAdvisor)
294 .setName(getDisplayNameFromCurrentTest())
295 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700296
297 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
298 EXPECT_TRUE(mDisplay->isSecure());
299 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700300 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700301
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700302 const auto& filter = mDisplay->getState().layerFilter;
303 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
304 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700305}
306
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800307TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
308 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
309 .setId(HAL_VIRTUAL_DISPLAY_ID)
310 .setPixels(DEFAULT_RESOLUTION)
311 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800312 .setPowerAdvisor(&mPowerAdvisor)
313 .setName(getDisplayNameFromCurrentTest())
314 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700315
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800316 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700317 EXPECT_FALSE(mDisplay->isSecure());
318 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700319 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700320
321 const auto& filter = mDisplay->getState().layerFilter;
322 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
323 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700324}
325
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800326TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
327 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
328 .setId(GPU_VIRTUAL_DISPLAY_ID)
329 .setPixels(DEFAULT_RESOLUTION)
330 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800331 .setPowerAdvisor(&mPowerAdvisor)
332 .setName(getDisplayNameFromCurrentTest())
333 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700334
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800335 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700336 EXPECT_FALSE(mDisplay->isSecure());
337 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700338 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700339
340 const auto& filter = mDisplay->getState().layerFilter;
341 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
342 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700343}
344
Lloyd Pique66d68602019-02-13 14:23:31 -0800345/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700346 * Display::disconnect()
347 */
348
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700349using DisplayDisconnectTest = PartialMockDisplayTestCommon;
350
351TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200352 // The first call to disconnect will disconnect the display with the HWC.
353 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700354 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700355
356 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200357 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700358 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700359}
360
Lloyd Pique66d68602019-02-13 14:23:31 -0800361/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700362 * Display::setColorTransform()
363 */
364
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700365using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
366
367TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800368 // No change does nothing
369 CompositionRefreshArgs refreshArgs;
370 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700371 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800372
Lloyd Pique32cbe282018-10-19 13:09:22 -0700373 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800374 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700375
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200376 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
377 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700378
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800379 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700380 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700381
382 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800383 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700384
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200385 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
386 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700387
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800388 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700389 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700390}
391
Lloyd Pique66d68602019-02-13 14:23:31 -0800392/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700393 * Display::setColorMode()
394 */
395
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700396using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
397
398TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800399 using ColorProfile = Output::ColorProfile;
400
Lloyd Pique31cb2942018-10-19 17:23:03 -0700401 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700402 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800403 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700404 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700405
Lloyd Piquef5275482019-01-29 18:42:42 -0800406 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
407 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700408
409 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700410 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
411 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
412 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
413 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700414
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700415 // Otherwise if the values are unchanged, nothing happens
416 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
417 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700418
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700419 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
420 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
421 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
422 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700423
424 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800425 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700426 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800427 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700428 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
429 .Times(1);
430
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700431 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
432 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
433 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700434
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700435 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
436 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
437 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
438 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700439}
440
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700441TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800442 using ColorProfile = Output::ColorProfile;
443
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800444 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700445 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700446
Lloyd Piquef5275482019-01-29 18:42:42 -0800447 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700448 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800449 std::unique_ptr<DisplayColorProfile>(colorProfile));
450
451 EXPECT_CALL(*colorProfile,
452 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
453 ui::Dataspace::UNKNOWN))
454 .WillOnce(Return(ui::Dataspace::UNKNOWN));
455
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700456 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800457 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
458 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700459
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700460 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
461 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
462 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
463 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700464}
465
Lloyd Pique66d68602019-02-13 14:23:31 -0800466/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700467 * Display::createDisplayColorProfile()
468 */
469
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700470using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
471
472TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700473 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
474 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700475 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
476 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700477 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700478}
479
Lloyd Pique66d68602019-02-13 14:23:31 -0800480/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700481 * Display::createRenderSurface()
482 */
483
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700484using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
485
486TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700487 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700488 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700489 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
490 .setDisplayWidth(640)
491 .setDisplayHeight(480)
492 .setNativeWindow(mNativeWindow)
493 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700494 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700495}
496
Lloyd Pique66d68602019-02-13 14:23:31 -0800497/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800498 * Display::createOutputLayer()
499 */
500
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700501using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
502
503TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800504 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea516c002021-05-07 14:36:58 -0700505 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800506
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200507 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700508 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800509
Lloyd Piquede196652020-01-22 17:29:58 -0800510 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800511
Lloyd Piquea516c002021-05-07 14:36:58 -0700512 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800513
Lloyd Piquedf336d92019-03-07 21:38:42 -0800514 outputLayer.reset();
515}
516
517/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800518 * Display::setReleasedLayers()
519 */
520
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700521using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
522
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800523TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
524 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
525 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800526
527 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800528
529 {
530 Output::ReleasedLayers releasedLayers;
531 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800532 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800533 }
534
535 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800536 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800537
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800538 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800539
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800540 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
541 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800542}
543
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700544TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800545 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
546
547 {
548 Output::ReleasedLayers releasedLayers;
549 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700550 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800551 }
552
553 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700554 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800555
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700556 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800557 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800558}
559
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700560TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800561 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800562
563 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800564 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
565 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
566 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800567
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700568 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800569
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700570 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800571 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800572 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
573 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800574}
575
576/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800577 * Display::chooseCompositionStrategy()
578 */
579
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700580using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800581
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800582TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
583 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
584 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700585 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800586 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800587
Vishnu Naira3140382022-02-24 14:07:11 -0800588 chooseCompositionStrategy(gpuDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800589
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800590 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800591 EXPECT_TRUE(state.usesClientComposition);
592 EXPECT_FALSE(state.usesDeviceComposition);
593}
594
595TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700596 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200597 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800598 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800599 .WillOnce(Return(INVALID_OPERATION));
600
Vishnu Naira3140382022-02-24 14:07:11 -0800601 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800602
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700603 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800604 EXPECT_TRUE(state.usesClientComposition);
605 EXPECT_FALSE(state.usesDeviceComposition);
Vishnu Naira3140382022-02-24 14:07:11 -0800606 EXPECT_FALSE(state.previousDeviceRequestedChanges.has_value());
Lloyd Pique66d68602019-02-13 14:23:31 -0800607}
608
609TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700610 // Since two calls are made to anyLayersRequireClientComposition with different return
611 // values, use a Sequence to control the matching so the values are returned in a known
612 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800613 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700614 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
615 .InSequence(s)
616 .WillOnce(Return(true));
617 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800618 .InSequence(s)
619 .WillOnce(Return(false));
620
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700621 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800622 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Naira3140382022-02-24 14:07:11 -0800623 .WillOnce(testing::DoAll(testing::SetArgPointee<5>(mDeviceRequestedChanges),
624 Return(NO_ERROR)));
625 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
626 .Times(1);
627 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
628 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
629 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700630 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800631
Vishnu Naira3140382022-02-24 14:07:11 -0800632 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800633
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700634 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800635 EXPECT_FALSE(state.usesClientComposition);
636 EXPECT_TRUE(state.usesDeviceComposition);
637}
638
Alec Mouricdf16792021-12-10 13:16:06 -0800639TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithDisplayBrightness) {
640 // 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.
643 constexpr float kDisplayBrightness = 0.5f;
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000644 constexpr float kDisplayBrightnessNits = 200.f;
Alec Mouricdf16792021-12-10 13:16:06 -0800645 EXPECT_CALL(mHwComposer,
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000646 setDisplayBrightness(DEFAULT_DISPLAY_ID, kDisplayBrightness, kDisplayBrightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -0800647 Hwc2::Composer::DisplayBrightnessOptions{.applyImmediately =
648 false}))
649 .WillOnce(Return(ByMove(ftl::yield<status_t>(NO_ERROR))));
650
Alec Mouricdf16792021-12-10 13:16:06 -0800651 mDisplay->setNextBrightness(kDisplayBrightness);
Vishnu Naira3140382022-02-24 14:07:11 -0800652 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
653 EXPECT_CALL(*renderSurface, beginFrame(_)).Times(1);
654 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000655 mDisplay->editState().displayBrightnessNits = kDisplayBrightnessNits;
Vishnu Naira3140382022-02-24 14:07:11 -0800656 mDisplay->beginFrame();
Alec Mouricdf16792021-12-10 13:16:06 -0800657
658 auto& state = mDisplay->getState();
Alec Mouricdf16792021-12-10 13:16:06 -0800659 EXPECT_FALSE(state.displayBrightness.has_value());
660}
661
Lloyd Pique66d68602019-02-13 14:23:31 -0800662TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700663 // Since two calls are made to anyLayersRequireClientComposition with different return
664 // values, use a Sequence to control the matching so the values are returned in a known
665 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800666 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700667 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
668 .InSequence(s)
669 .WillOnce(Return(true));
670 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800671 .InSequence(s)
672 .WillOnce(Return(false));
673
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700674 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800675 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Naira3140382022-02-24 14:07:11 -0800676 .WillOnce(DoAll(SetArgPointee<5>(mDeviceRequestedChanges), Return(NO_ERROR)));
677 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
678 .Times(1);
679 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
680 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
681 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700682 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800683
Vishnu Naira3140382022-02-24 14:07:11 -0800684 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800685
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700686 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800687 EXPECT_FALSE(state.usesClientComposition);
688 EXPECT_TRUE(state.usesDeviceComposition);
689}
690
691/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800692 * Display::getSkipColorTransform()
693 */
694
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700695using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500696using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700697
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800698TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Ady Abrahamde549d42022-01-26 19:19:17 -0800699 EXPECT_CALL(mHwComposer, hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700700 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800701 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
702 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
703 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800704}
705
Dominik Laskowski1162e472020-04-02 19:02:47 -0700706TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800707 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200708 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500709 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800710 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700711 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800712}
713
714/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800715 * Display::anyLayersRequireClientComposition()
716 */
717
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700718using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
719
720TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800721 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
722 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
723 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800724
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700725 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800726}
727
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700728TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800729 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
730 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800731
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700732 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800733}
734
735/*
736 * Display::allLayersRequireClientComposition()
737 */
738
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700739using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
740
741TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800742 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
743 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
744 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800745
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700746 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800747}
748
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700749TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800750 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
751 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800752
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700753 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800754}
755
756/*
757 * Display::applyChangedTypesToLayers()
758 */
759
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700760using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
761
762TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700763 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800764}
765
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700766TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500767 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800768 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500769 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800770 .Times(1);
771
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700772 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500773 {&mLayer1.hwc2Layer, Composition::CLIENT},
774 {&mLayer2.hwc2Layer, Composition::DEVICE},
775 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800776 });
777}
778
779/*
780 * Display::applyDisplayRequests()
781 */
782
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700783using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
784
785TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700786 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800787
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700788 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800789 EXPECT_FALSE(state.flipClientTarget);
790}
791
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700792TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700793 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800794
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700795 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800796 EXPECT_TRUE(state.flipClientTarget);
797}
798
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700799TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700800 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800801
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700802 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800803 EXPECT_FALSE(state.flipClientTarget);
804}
805
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700806TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700807 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800808
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700809 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800810 EXPECT_TRUE(state.flipClientTarget);
811}
812
813/*
814 * Display::applyLayerRequestsToLayers()
815 */
816
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700817using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
818
819TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800820 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
821 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
822 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800823
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700824 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800825}
826
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700827TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800828 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
829 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
830 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800831
Lloyd Piquede196652020-01-22 17:29:58 -0800832 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800833 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
834 .Times(1);
835
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700836 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700837 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
838 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800839 });
840}
841
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800842/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700843 * Display::applyClientTargetRequests()
844 */
845
846using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
847
848TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700849 static constexpr float kWhitePointNits = 800.f;
850
Alec Mouri85065692022-03-18 00:58:26 +0000851 Display::ClientTargetProperty clientTargetProperty = {
852 .clientTargetProperty =
853 {
854 .pixelFormat =
855 aidl::android::hardware::graphics::common::PixelFormat::RGB_565,
856 .dataspace = aidl::android::hardware::graphics::common::Dataspace::
857 STANDARD_BT470M,
858 },
859 .brightness = kWhitePointNits,
860 .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
861 };
862
Ady Abraham0094dc62021-06-03 10:08:33 -0700863 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
864 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
865
Alec Mouri85065692022-03-18 00:58:26 +0000866 EXPECT_CALL(*renderSurface,
867 setBufferPixelFormat(static_cast<ui::PixelFormat>(
868 clientTargetProperty.clientTargetProperty.pixelFormat)));
869 EXPECT_CALL(*renderSurface,
870 setBufferDataspace(static_cast<ui::Dataspace>(
871 clientTargetProperty.clientTargetProperty.dataspace)));
872 mDisplay->applyClientTargetRequests(clientTargetProperty);
Ady Abraham0094dc62021-06-03 10:08:33 -0700873
874 auto& state = mDisplay->getState();
Alec Mouri85065692022-03-18 00:58:26 +0000875 EXPECT_EQ(clientTargetProperty.clientTargetProperty.dataspace,
876 static_cast<aidl::android::hardware::graphics::common::Dataspace>(state.dataspace));
Alec Mourif8d093d2022-02-10 15:16:59 -0800877 EXPECT_EQ(kWhitePointNits, state.clientTargetBrightness);
Alec Mouri85065692022-03-18 00:58:26 +0000878 EXPECT_EQ(aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
879 state.clientTargetDimmingStage);
Ady Abraham0094dc62021-06-03 10:08:33 -0700880}
881
882/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800883 * Display::presentAndGetFrameFences()
884 */
885
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700886using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
887
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800888TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
889 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
890 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800891
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800892 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800893
894 ASSERT_TRUE(result.presentFence.get());
895 EXPECT_FALSE(result.presentFence->isValid());
896 EXPECT_EQ(0u, result.layerFences.size());
897}
898
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700899TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800900 sp<Fence> presentFence = new Fence();
901 sp<Fence> layer1Fence = new Fence();
902 sp<Fence> layer2Fence = new Fence();
903
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700904 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700905 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200906 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
907 .WillOnce(Return(presentFence));
908 EXPECT_CALL(mHwComposer,
909 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800910 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200911 EXPECT_CALL(mHwComposer,
912 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800913 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200914 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800915
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700916 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800917
918 EXPECT_EQ(presentFence, result.presentFence);
919
920 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800921 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800922 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800923 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800924 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800925}
926
Lloyd Pique688abd42019-02-15 15:42:24 -0800927/*
928 * Display::setExpensiveRenderingExpected()
929 */
930
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700931using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
932
933TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800934 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700935 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800936
937 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700938 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800939}
940
Lloyd Piqued3d69882019-02-28 16:03:46 -0800941/*
942 * Display::finishFrame()
943 */
944
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700945using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
946
947TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800948 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700949 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800950
951 // We expect no calls to queueBuffer if composition was skipped.
952 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
953
Lloyd Piquea76ce462020-01-14 13:06:37 -0800954 // Expect a call to signal no expensive rendering since there is no client composition.
955 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
956
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700957 mDisplay->editState().isEnabled = true;
958 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000959 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700960 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800961
Vishnu Naira3140382022-02-24 14:07:11 -0800962 mDisplay->finishFrame({}, std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800963}
964
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700965TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800966 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
967 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800968
969 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800970 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800971
972 // We expect no calls to queueBuffer if composition was skipped.
973 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
974
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800975 gpuDisplay->editState().isEnabled = true;
976 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000977 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800978 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800979
Vishnu Naira3140382022-02-24 14:07:11 -0800980 gpuDisplay->finishFrame({}, std::move(mResultWithoutBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800981}
982
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700983TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800984 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
985 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800986
987 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800988 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800989
990 // We expect a single call to queueBuffer when composition is not skipped.
991 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
992
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800993 gpuDisplay->editState().isEnabled = true;
994 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000995 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800996 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Vishnu Naira3140382022-02-24 14:07:11 -0800997 gpuDisplay->finishFrame({}, std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800998}
999
Lloyd Piquec6607552019-12-02 17:57:39 -08001000/*
1001 * Display functional tests
1002 */
1003
1004struct DisplayFunctionalTest : public testing::Test {
1005 class Display : public impl::Display {
1006 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001007 using impl::Display::injectOutputLayerForTest;
1008 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1009 };
1010
Lloyd Piquec6607552019-12-02 17:57:39 -08001011 DisplayFunctionalTest() {
1012 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Kriti Dang646f8ec2022-01-18 14:35:02 +01001013 mDisplay = createDisplay();
1014 mRenderSurface = createRenderSurface();
Lloyd Piquec6607552019-12-02 17:57:39 -08001015 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1016 }
1017
1018 NiceMock<android::mock::HWComposer> mHwComposer;
1019 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1020 NiceMock<mock::CompositionEngine> mCompositionEngine;
1021 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1022 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Kriti Dang646f8ec2022-01-18 14:35:02 +01001023 std::shared_ptr<Display> mDisplay;
1024 impl::RenderSurface* mRenderSurface;
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001025
Kriti Dang646f8ec2022-01-18 14:35:02 +01001026 std::shared_ptr<Display> createDisplay() {
1027 return impl::createDisplayTemplated<Display>(mCompositionEngine,
1028 DisplayCreationArgsBuilder()
1029 .setId(DEFAULT_DISPLAY_ID)
1030 .setPixels(DEFAULT_RESOLUTION)
1031 .setIsSecure(true)
1032 .setPowerAdvisor(&mPowerAdvisor)
1033 .build());
1034 ;
1035 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001036
Kriti Dang646f8ec2022-01-18 14:35:02 +01001037 impl::RenderSurface* createRenderSurface() {
1038 return new impl::RenderSurface{mCompositionEngine, *mDisplay,
1039 RenderSurfaceCreationArgsBuilder()
1040 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1041 .setDisplayHeight(DEFAULT_RESOLUTION.height)
1042 .setNativeWindow(mNativeWindow)
1043 .setDisplaySurface(mDisplaySurface)
1044 .build()};
1045 }
Lloyd Piquec6607552019-12-02 17:57:39 -08001046};
1047
1048TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1049 InSequence seq;
1050
1051 mDisplay->editState().isEnabled = true;
1052
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001053 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001054 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1055
1056 mDisplay->postFramebuffer();
1057}
1058
Lloyd Pique45a165a2018-10-19 11:54:47 -07001059} // namespace
1060} // namespace android::compositionengine