blob: 9c0e62c6439dd9fac17fe0fa45b5afe967a91518 [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&));
Sally Qi95f669a2024-08-27 11:31:42 -0700136 MOCK_METHOD1(applyLayerLutsToLayers, void(const impl::Display::LayerLuts&));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700137
138 const compositionengine::CompositionEngine& mCompositionEngine;
139 impl::OutputCompositionState mState;
140 };
141
142 static std::string getDisplayNameFromCurrentTest() {
143 const ::testing::TestInfo* const test_info =
144 ::testing::UnitTest::GetInstance()->current_test_info();
145 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
146 }
147
148 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700149 static std::shared_ptr<Display> createDisplay(
150 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700151 compositionengine::DisplayCreationArgs args) {
152 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700153 return impl::createDisplayTemplated<Display>(compositionEngine, args);
154 }
155
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700156 template <typename Display>
157 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
158 const compositionengine::CompositionEngine& compositionEngine,
159 compositionengine::DisplayCreationArgs args) {
160 args.name = getDisplayNameFromCurrentTest();
161 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800162
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700163 display->setConfiguration(args);
164
165 return display;
166 }
167
168 DisplayTestCommon() {
169 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700170 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
171 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700172 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Matt Buckley50c44062022-01-17 20:48:10 +0000173 EXPECT_CALL(mPowerAdvisor, usePowerHintSession()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700174 }
175
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700176 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700177 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800178 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800179 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700180 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700181 .setPowerAdvisor(&mPowerAdvisor)
182 .build();
183 }
184
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800185 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700186 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800187 .setId(GPU_VIRTUAL_DISPLAY_ID)
188 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700189 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700190 .setPowerAdvisor(&mPowerAdvisor)
191 .build();
192 }
193
194 StrictMock<android::mock::HWComposer> mHwComposer;
195 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700196 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700197 StrictMock<mock::CompositionEngine> mCompositionEngine;
Ady Abrahamd11bade2022-08-01 16:18:03 -0700198 sp<mock::NativeWindow> mNativeWindow = sp<StrictMock<mock::NativeWindow>>::make();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700199};
200
201struct PartialMockDisplayTestCommon : public DisplayTestCommon {
202 using Display = DisplayTestCommon::PartialMockDisplay;
203 std::shared_ptr<Display> mDisplay =
204 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700205 getDisplayCreationArgsForPhysicalDisplay());
Vishnu Naira3140382022-02-24 14:07:11 -0800206
207 android::HWComposer::DeviceRequestedChanges mDeviceRequestedChanges{
208 {{nullptr, Composition::CLIENT}},
209 hal::DisplayRequest::FLIP_CLIENT_TARGET,
210 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
211 {DEFAULT_DISPLAY_ID.value,
212 {aidl::android::hardware::graphics::common::PixelFormat::RGBA_8888,
213 aidl::android::hardware::graphics::common::Dataspace::UNKNOWN},
214 -1.f,
215 DimmingStage::NONE},
Sally Qi95f669a2024-08-27 11:31:42 -0700216 {},
Vishnu Naira3140382022-02-24 14:07:11 -0800217 };
218
219 void chooseCompositionStrategy(Display* display) {
220 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
221 bool success = display->chooseCompositionStrategy(&changes);
222 display->resetCompositionStrategy();
223 if (success) {
224 display->applyCompositionStrategy(changes);
225 }
226 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700227};
228
229struct FullDisplayImplTestCommon : public DisplayTestCommon {
230 using Display = DisplayTestCommon::FullImplDisplay;
231 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700232 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700233};
234
235struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
236 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700237 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800238 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700239 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800240 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700241 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800242 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Vishnu Naira3140382022-02-24 14:07:11 -0800243 mResultWithBuffer.buffer = std::make_shared<
244 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
245 1ULL /* bufferId */,
246 HAL_PIXEL_FORMAT_RGBA_8888,
247 0ULL /*usage*/);
Lloyd Pique66d68602019-02-13 14:23:31 -0800248 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700249
Lloyd Piquede196652020-01-22 17:29:58 -0800250 Layer mLayer1;
251 Layer mLayer2;
252 LayerNoHWC2Layer mLayer3;
253 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700254 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700255 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Vishnu Naira3140382022-02-24 14:07:11 -0800256 impl::GpuCompositionResult mResultWithBuffer;
257 impl::GpuCompositionResult mResultWithoutBuffer;
Lloyd Pique45a165a2018-10-19 11:54:47 -0700258};
259
Lloyd Pique66d68602019-02-13 14:23:31 -0800260/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700261 * Basic construction
262 */
263
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700264struct DisplayCreationTest : public DisplayTestCommon {
265 using Display = DisplayTestCommon::FullImplDisplay;
266};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700267
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700268TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
269 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700270 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700271 EXPECT_TRUE(display->isSecure());
272 EXPECT_FALSE(display->isVirtual());
273 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
274}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700275
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800276TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
277 auto display =
278 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700279 EXPECT_FALSE(display->isSecure());
280 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200281 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700282}
283
284/*
285 * Display::setConfiguration()
286 */
287
288using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
289
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700290TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800291 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
292 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800293 .setPixels(DEFAULT_RESOLUTION)
294 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800295 .setPowerAdvisor(&mPowerAdvisor)
296 .setName(getDisplayNameFromCurrentTest())
297 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700298
299 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
300 EXPECT_TRUE(mDisplay->isSecure());
301 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700302 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700303
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700304 const auto& filter = mDisplay->getState().layerFilter;
305 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
306 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700307}
308
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800309TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
310 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
311 .setId(HAL_VIRTUAL_DISPLAY_ID)
312 .setPixels(DEFAULT_RESOLUTION)
313 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800314 .setPowerAdvisor(&mPowerAdvisor)
315 .setName(getDisplayNameFromCurrentTest())
316 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700317
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800318 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700319 EXPECT_FALSE(mDisplay->isSecure());
320 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700321 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700322
323 const auto& filter = mDisplay->getState().layerFilter;
324 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
325 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700326}
327
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800328TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
329 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
330 .setId(GPU_VIRTUAL_DISPLAY_ID)
331 .setPixels(DEFAULT_RESOLUTION)
332 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800333 .setPowerAdvisor(&mPowerAdvisor)
334 .setName(getDisplayNameFromCurrentTest())
335 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700336
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800337 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700338 EXPECT_FALSE(mDisplay->isSecure());
339 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700340 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700341
342 const auto& filter = mDisplay->getState().layerFilter;
343 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
344 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700345}
346
Lloyd Pique66d68602019-02-13 14:23:31 -0800347/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700348 * Display::disconnect()
349 */
350
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700351using DisplayDisconnectTest = PartialMockDisplayTestCommon;
352
353TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200354 // The first call to disconnect will disconnect the display with the HWC.
355 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700356 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700357
358 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200359 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700360 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700361}
362
Lloyd Pique66d68602019-02-13 14:23:31 -0800363/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700364 * Display::setColorTransform()
365 */
366
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700367using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
368
369TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800370 // No change does nothing
371 CompositionRefreshArgs refreshArgs;
372 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700373 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800374
Lloyd Pique32cbe282018-10-19 13:09:22 -0700375 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800376 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700377
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200378 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
379 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700380
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800381 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700382 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700383
384 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800385 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700386
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200387 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
388 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700389
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800390 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700391 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700392}
393
Lloyd Pique66d68602019-02-13 14:23:31 -0800394/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700395 * Display::setColorMode()
396 */
397
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700398using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
399
400TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800401 using ColorProfile = Output::ColorProfile;
402
Lloyd Pique31cb2942018-10-19 17:23:03 -0700403 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700404 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800405 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700406 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700407
Lloyd Pique32cbe282018-10-19 13:09:22 -0700408 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700409 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
410 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
411 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700412
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700413 // Otherwise if the values are unchanged, nothing happens
414 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
Alec Mouri88790f32023-07-21 01:25:14 +0000415 ui::RenderIntent::COLORIMETRIC});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700416
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700417 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
418 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
419 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700420
421 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800422 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700423 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800424 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700425 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
426 .Times(1);
427
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700428 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Alec Mouri88790f32023-07-21 01:25:14 +0000429 ui::RenderIntent::TONE_MAP_COLORIMETRIC});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700430
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700431 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
432 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
433 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700434}
435
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700436TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800437 using ColorProfile = Output::ColorProfile;
438
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800439 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700440 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700441
Lloyd Piquef5275482019-01-29 18:42:42 -0800442 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700443 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800444 std::unique_ptr<DisplayColorProfile>(colorProfile));
445
Alec Mouri88790f32023-07-21 01:25:14 +0000446 virtualDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3,
447 ui::Dataspace::DISPLAY_P3,
448 ui::RenderIntent::TONE_MAP_COLORIMETRIC});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700449
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700450 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
451 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
452 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700453}
454
Lloyd Pique66d68602019-02-13 14:23:31 -0800455/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700456 * Display::createDisplayColorProfile()
457 */
458
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700459using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
460
461TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700462 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
463 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700464 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
465 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700466 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700467}
468
Lloyd Pique66d68602019-02-13 14:23:31 -0800469/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700470 * Display::createRenderSurface()
471 */
472
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700473using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
474
475TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700476 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700477 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700478 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
479 .setDisplayWidth(640)
480 .setDisplayHeight(480)
481 .setNativeWindow(mNativeWindow)
482 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700483 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700484}
485
Lloyd Pique66d68602019-02-13 14:23:31 -0800486/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800487 * Display::createOutputLayer()
488 */
489
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700490using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
491
492TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800493 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea516c002021-05-07 14:36:58 -0700494 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800495
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200496 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700497 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800498
Lloyd Piquede196652020-01-22 17:29:58 -0800499 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800500
Lloyd Piquea516c002021-05-07 14:36:58 -0700501 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800502
Lloyd Piquedf336d92019-03-07 21:38:42 -0800503 outputLayer.reset();
504}
505
506/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800507 * Display::setReleasedLayers()
508 */
509
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700510using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
511
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800512TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
513 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
514 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800515
Ady Abrahamd11bade2022-08-01 16:18:03 -0700516 sp<mock::LayerFE> layerXLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800517
518 {
519 Output::ReleasedLayers releasedLayers;
520 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800521 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800522 }
523
524 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800525 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800526
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800527 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800528
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800529 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
530 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800531}
532
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700533TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700534 sp<mock::LayerFE> layerXLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800535
536 {
537 Output::ReleasedLayers releasedLayers;
538 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700539 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800540 }
541
542 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700543 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800544
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700545 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800546 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800547}
548
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700549TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700550 sp<mock::LayerFE> unknownLayer = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800551
552 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800553 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
554 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
555 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800556
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700557 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800558
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700559 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800560 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800561 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
562 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800563}
564
565/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800566 * Display::chooseCompositionStrategy()
567 */
568
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700569using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800570
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800571TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
572 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
573 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700574 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800575 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800576
Vishnu Naira3140382022-02-24 14:07:11 -0800577 chooseCompositionStrategy(gpuDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800578
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800579 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800580 EXPECT_TRUE(state.usesClientComposition);
581 EXPECT_FALSE(state.usesDeviceComposition);
582}
583
584TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700585 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200586 EXPECT_CALL(mHwComposer,
ramindani4aac32c2023-10-30 14:13:30 -0700587 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800588 .WillOnce(Return(INVALID_OPERATION));
589
Vishnu Naira3140382022-02-24 14:07:11 -0800590 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800591
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700592 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800593 EXPECT_TRUE(state.usesClientComposition);
594 EXPECT_FALSE(state.usesDeviceComposition);
Vishnu Naira3140382022-02-24 14:07:11 -0800595 EXPECT_FALSE(state.previousDeviceRequestedChanges.has_value());
Lloyd Pique66d68602019-02-13 14:23:31 -0800596}
597
598TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700599 // Since two calls are made to anyLayersRequireClientComposition with different return
600 // values, use a Sequence to control the matching so the values are returned in a known
601 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800602 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700603 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
604 .InSequence(s)
605 .WillOnce(Return(true));
606 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800607 .InSequence(s)
608 .WillOnce(Return(false));
609
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700610 EXPECT_CALL(mHwComposer,
ramindani4aac32c2023-10-30 14:13:30 -0700611 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
612 .WillOnce(testing::DoAll(testing::SetArgPointee<5>(mDeviceRequestedChanges),
Vishnu Naira3140382022-02-24 14:07:11 -0800613 Return(NO_ERROR)));
614 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
615 .Times(1);
616 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
617 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
618 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700619 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Sally Qi95f669a2024-08-27 11:31:42 -0700620 EXPECT_CALL(*mDisplay, applyLayerLutsToLayers(mDeviceRequestedChanges.layerLuts)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800621
Vishnu Naira3140382022-02-24 14:07:11 -0800622 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800623
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700624 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800625 EXPECT_FALSE(state.usesClientComposition);
626 EXPECT_TRUE(state.usesDeviceComposition);
627}
628
Alec Mouricdf16792021-12-10 13:16:06 -0800629TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithDisplayBrightness) {
630 // Since two calls are made to anyLayersRequireClientComposition with different return
631 // values, use a Sequence to control the matching so the values are returned in a known
632 // order.
633 constexpr float kDisplayBrightness = 0.5f;
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000634 constexpr float kDisplayBrightnessNits = 200.f;
Alec Mouricdf16792021-12-10 13:16:06 -0800635 EXPECT_CALL(mHwComposer,
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000636 setDisplayBrightness(DEFAULT_DISPLAY_ID, kDisplayBrightness, kDisplayBrightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -0800637 Hwc2::Composer::DisplayBrightnessOptions{.applyImmediately =
638 false}))
639 .WillOnce(Return(ByMove(ftl::yield<status_t>(NO_ERROR))));
640
Alec Mouricdf16792021-12-10 13:16:06 -0800641 mDisplay->setNextBrightness(kDisplayBrightness);
Vishnu Naira3140382022-02-24 14:07:11 -0800642 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
643 EXPECT_CALL(*renderSurface, beginFrame(_)).Times(1);
644 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000645 mDisplay->editState().displayBrightnessNits = kDisplayBrightnessNits;
Vishnu Naira3140382022-02-24 14:07:11 -0800646 mDisplay->beginFrame();
Alec Mouricdf16792021-12-10 13:16:06 -0800647
648 auto& state = mDisplay->getState();
Alec Mouricdf16792021-12-10 13:16:06 -0800649 EXPECT_FALSE(state.displayBrightness.has_value());
650}
651
Lloyd Pique66d68602019-02-13 14:23:31 -0800652TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700653 // Since two calls are made to anyLayersRequireClientComposition with different return
654 // values, use a Sequence to control the matching so the values are returned in a known
655 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800656 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700657 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
658 .InSequence(s)
659 .WillOnce(Return(true));
660 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800661 .InSequence(s)
662 .WillOnce(Return(false));
663
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700664 EXPECT_CALL(mHwComposer,
ramindani4aac32c2023-10-30 14:13:30 -0700665 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
666 .WillOnce(DoAll(SetArgPointee<5>(mDeviceRequestedChanges), Return(NO_ERROR)));
Vishnu Naira3140382022-02-24 14:07:11 -0800667 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
668 .Times(1);
669 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
670 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
671 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700672 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Sally Qi95f669a2024-08-27 11:31:42 -0700673 EXPECT_CALL(*mDisplay, applyLayerLutsToLayers(mDeviceRequestedChanges.layerLuts)).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800674
Vishnu Naira3140382022-02-24 14:07:11 -0800675 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800676
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700677 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800678 EXPECT_FALSE(state.usesClientComposition);
679 EXPECT_TRUE(state.usesDeviceComposition);
680}
681
682/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800683 * Display::getSkipColorTransform()
684 */
685
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700686using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500687using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700688
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800689TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Ady Abrahamde549d42022-01-26 19:19:17 -0800690 EXPECT_CALL(mHwComposer, hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700691 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800692 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
693 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
694 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800695}
696
Dominik Laskowski1162e472020-04-02 19:02:47 -0700697TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800698 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200699 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500700 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800701 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700702 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800703}
704
705/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800706 * Display::anyLayersRequireClientComposition()
707 */
708
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700709using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
710
711TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800712 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
713 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
714 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800715
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700716 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800717}
718
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700719TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800720 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
721 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800722
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700723 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800724}
725
726/*
727 * Display::allLayersRequireClientComposition()
728 */
729
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700730using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
731
732TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800733 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
734 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
735 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800736
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700737 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800738}
739
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700740TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800741 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
742 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800743
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700744 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800745}
746
747/*
748 * Display::applyChangedTypesToLayers()
749 */
750
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700751using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
752
753TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700754 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800755}
756
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700757TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500758 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800759 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500760 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800761 .Times(1);
762
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700763 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500764 {&mLayer1.hwc2Layer, Composition::CLIENT},
765 {&mLayer2.hwc2Layer, Composition::DEVICE},
766 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800767 });
768}
769
770/*
771 * Display::applyDisplayRequests()
772 */
773
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700774using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
775
776TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700777 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800778
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700779 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800780 EXPECT_FALSE(state.flipClientTarget);
781}
782
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700783TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700784 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800785
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700786 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800787 EXPECT_TRUE(state.flipClientTarget);
788}
789
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700790TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700791 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800792
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700793 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800794 EXPECT_FALSE(state.flipClientTarget);
795}
796
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700797TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700798 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800799
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700800 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800801 EXPECT_TRUE(state.flipClientTarget);
802}
803
804/*
805 * Display::applyLayerRequestsToLayers()
806 */
807
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700808using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
809
810TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800811 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
812 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
813 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800814
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700815 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800816}
817
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700818TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800819 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
820 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
821 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800822
Lloyd Piquede196652020-01-22 17:29:58 -0800823 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800824 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
825 .Times(1);
826
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700827 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700828 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
829 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800830 });
831}
832
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800833/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700834 * Display::applyClientTargetRequests()
835 */
836
837using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
838
839TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700840 static constexpr float kWhitePointNits = 800.f;
841
Alec Mouri85065692022-03-18 00:58:26 +0000842 Display::ClientTargetProperty clientTargetProperty = {
843 .clientTargetProperty =
844 {
845 .pixelFormat =
846 aidl::android::hardware::graphics::common::PixelFormat::RGB_565,
847 .dataspace = aidl::android::hardware::graphics::common::Dataspace::
848 STANDARD_BT470M,
849 },
850 .brightness = kWhitePointNits,
851 .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
852 };
853
Ady Abraham0094dc62021-06-03 10:08:33 -0700854 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
855 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
856
Alec Mouri85065692022-03-18 00:58:26 +0000857 EXPECT_CALL(*renderSurface,
858 setBufferPixelFormat(static_cast<ui::PixelFormat>(
859 clientTargetProperty.clientTargetProperty.pixelFormat)));
860 EXPECT_CALL(*renderSurface,
861 setBufferDataspace(static_cast<ui::Dataspace>(
862 clientTargetProperty.clientTargetProperty.dataspace)));
863 mDisplay->applyClientTargetRequests(clientTargetProperty);
Ady Abraham0094dc62021-06-03 10:08:33 -0700864
865 auto& state = mDisplay->getState();
Alec Mouri85065692022-03-18 00:58:26 +0000866 EXPECT_EQ(clientTargetProperty.clientTargetProperty.dataspace,
867 static_cast<aidl::android::hardware::graphics::common::Dataspace>(state.dataspace));
Alec Mourif8d093d2022-02-10 15:16:59 -0800868 EXPECT_EQ(kWhitePointNits, state.clientTargetBrightness);
Alec Mouri85065692022-03-18 00:58:26 +0000869 EXPECT_EQ(aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
870 state.clientTargetDimmingStage);
Ady Abraham0094dc62021-06-03 10:08:33 -0700871}
872
873/*
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -0500874 * Display::presentFrame()
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800875 */
876
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700877using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
878
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800879TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
880 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
881 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800882
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -0500883 auto result = gpuDisplay->presentFrame();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800884
885 ASSERT_TRUE(result.presentFence.get());
886 EXPECT_FALSE(result.presentFence->isValid());
887 EXPECT_EQ(0u, result.layerFences.size());
888}
889
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700890TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Ady Abrahamd11bade2022-08-01 16:18:03 -0700891 sp<Fence> presentFence = sp<Fence>::make();
892 sp<Fence> layer1Fence = sp<Fence>::make();
893 sp<Fence> layer2Fence = sp<Fence>::make();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800894
Ady Abrahamf1db8032023-03-24 17:52:34 -0700895 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700896 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200897 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
898 .WillOnce(Return(presentFence));
899 EXPECT_CALL(mHwComposer,
900 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800901 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200902 EXPECT_CALL(mHwComposer,
903 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800904 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200905 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800906
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -0500907 auto result = mDisplay->presentFrame();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800908
909 EXPECT_EQ(presentFence, result.presentFence);
910
911 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800912 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800913 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800914 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800915 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800916}
917
Lloyd Pique688abd42019-02-15 15:42:24 -0800918/*
919 * Display::setExpensiveRenderingExpected()
920 */
921
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700922using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
923
924TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800925 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700926 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800927
928 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700929 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800930}
931
Lloyd Piqued3d69882019-02-28 16:03:46 -0800932/*
933 * Display::finishFrame()
934 */
935
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700936using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
937
938TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800939 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700940 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800941
942 // We expect no calls to queueBuffer if composition was skipped.
Alec Mourif97df4d2023-09-06 02:10:05 +0000943 EXPECT_CALL(*renderSurface, queueBuffer(_, _)).Times(1);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800944
Lloyd Piquea76ce462020-01-14 13:06:37 -0800945 // Expect a call to signal no expensive rendering since there is no client composition.
946 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
947
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700948 mDisplay->editState().isEnabled = true;
949 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000950 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700951 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800952
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000953 mDisplay->finishFrame(std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800954}
955
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700956TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800957 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
958 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800959
960 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800961 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800962
963 // We expect no calls to queueBuffer if composition was skipped.
Alec Mourif97df4d2023-09-06 02:10:05 +0000964 EXPECT_CALL(*renderSurface, queueBuffer(_, _)).Times(0);
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000965 EXPECT_CALL(*renderSurface, beginFrame(false));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800966
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800967 gpuDisplay->editState().isEnabled = true;
968 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000969 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800970 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000971 gpuDisplay->editState().lastCompositionHadVisibleLayers = true;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800972
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000973 gpuDisplay->beginFrame();
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000974 gpuDisplay->finishFrame(std::move(mResultWithoutBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800975}
976
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000977TEST_F(DisplayFinishFrameTest, skipsCompositionIfEmpty) {
978 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
979 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
980
981 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
982 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
983
984 // We expect no calls to queueBuffer if composition was skipped.
Alec Mourif97df4d2023-09-06 02:10:05 +0000985 EXPECT_CALL(*renderSurface, queueBuffer(_, _)).Times(0);
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000986 EXPECT_CALL(*renderSurface, beginFrame(false));
987
988 gpuDisplay->editState().isEnabled = true;
989 gpuDisplay->editState().usesClientComposition = false;
990 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
991 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
992 gpuDisplay->editState().lastCompositionHadVisibleLayers = false;
993
994 gpuDisplay->beginFrame();
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000995 gpuDisplay->finishFrame(std::move(mResultWithoutBuffer));
Chavi Weingarten09fa1d62022-08-17 21:57:04 +0000996}
997
998TEST_F(DisplayFinishFrameTest, performsCompositionIfDirtyAndNotEmpty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800999 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
1000 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -08001001
1002 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001003 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -08001004
1005 // We expect a single call to queueBuffer when composition is not skipped.
Alec Mourif97df4d2023-09-06 02:10:05 +00001006 EXPECT_CALL(*renderSurface, queueBuffer(_, _)).Times(1);
Chavi Weingarten09fa1d62022-08-17 21:57:04 +00001007 EXPECT_CALL(*renderSurface, beginFrame(true));
Lloyd Piqued3d69882019-02-28 16:03:46 -08001008
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001009 gpuDisplay->editState().isEnabled = true;
1010 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +00001011 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001012 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Chavi Weingarten09fa1d62022-08-17 21:57:04 +00001013 gpuDisplay->editState().lastCompositionHadVisibleLayers = true;
1014
1015 gpuDisplay->beginFrame();
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001016 gpuDisplay->finishFrame(std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -08001017}
1018
Lloyd Piquec6607552019-12-02 17:57:39 -08001019/*
1020 * Display functional tests
1021 */
1022
1023struct DisplayFunctionalTest : public testing::Test {
1024 class Display : public impl::Display {
1025 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001026 using impl::Display::injectOutputLayerForTest;
1027 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1028 };
1029
Lloyd Piquec6607552019-12-02 17:57:39 -08001030 DisplayFunctionalTest() {
1031 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Kriti Dang646f8ec2022-01-18 14:35:02 +01001032 mDisplay = createDisplay();
1033 mRenderSurface = createRenderSurface();
Lloyd Piquec6607552019-12-02 17:57:39 -08001034 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1035 }
1036
1037 NiceMock<android::mock::HWComposer> mHwComposer;
1038 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1039 NiceMock<mock::CompositionEngine> mCompositionEngine;
Ady Abrahamd11bade2022-08-01 16:18:03 -07001040 sp<mock::NativeWindow> mNativeWindow = sp<NiceMock<mock::NativeWindow>>::make();
1041 sp<mock::DisplaySurface> mDisplaySurface = sp<NiceMock<mock::DisplaySurface>>::make();
Kriti Dang646f8ec2022-01-18 14:35:02 +01001042 std::shared_ptr<Display> mDisplay;
1043 impl::RenderSurface* mRenderSurface;
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001044
Kriti Dang646f8ec2022-01-18 14:35:02 +01001045 std::shared_ptr<Display> createDisplay() {
1046 return impl::createDisplayTemplated<Display>(mCompositionEngine,
1047 DisplayCreationArgsBuilder()
1048 .setId(DEFAULT_DISPLAY_ID)
1049 .setPixels(DEFAULT_RESOLUTION)
1050 .setIsSecure(true)
1051 .setPowerAdvisor(&mPowerAdvisor)
1052 .build());
1053 ;
1054 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001055
Kriti Dang646f8ec2022-01-18 14:35:02 +01001056 impl::RenderSurface* createRenderSurface() {
1057 return new impl::RenderSurface{mCompositionEngine, *mDisplay,
1058 RenderSurfaceCreationArgsBuilder()
1059 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1060 .setDisplayHeight(DEFAULT_RESOLUTION.height)
1061 .setNativeWindow(mNativeWindow)
1062 .setDisplaySurface(mDisplaySurface)
1063 .build()};
1064 }
Lloyd Piquec6607552019-12-02 17:57:39 -08001065};
1066
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05001067TEST_F(DisplayFunctionalTest, presentFrameAndReleaseLayersCriticalCallsAreOrdered) {
Lloyd Piquec6607552019-12-02 17:57:39 -08001068 InSequence seq;
1069
1070 mDisplay->editState().isEnabled = true;
1071
Ady Abrahamf1db8032023-03-24 17:52:34 -07001072 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001073 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
Leon Scroggins IIIa3ba7fa2024-05-22 16:34:52 -04001074 constexpr bool kFlushEvenWhenDisabled = false;
1075 mDisplay->presentFrameAndReleaseLayers(kFlushEvenWhenDisabled);
Lloyd Piquec6607552019-12-02 17:57:39 -08001076}
1077
Lloyd Pique45a165a2018-10-19 11:54:47 -07001078} // namespace
1079} // namespace android::compositionengine