blob: 0e5a7b6a99e98b975d06cf408a0d5022d3820403 [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));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700172 }
173
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700174 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700175 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800176 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800177 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700178 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700179 .setPowerAdvisor(&mPowerAdvisor)
180 .build();
181 }
182
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800183 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700184 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800185 .setId(GPU_VIRTUAL_DISPLAY_ID)
186 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700187 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700188 .setPowerAdvisor(&mPowerAdvisor)
189 .build();
190 }
191
192 StrictMock<android::mock::HWComposer> mHwComposer;
193 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700194 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700195 StrictMock<mock::CompositionEngine> mCompositionEngine;
196 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
197};
198
199struct PartialMockDisplayTestCommon : public DisplayTestCommon {
200 using Display = DisplayTestCommon::PartialMockDisplay;
201 std::shared_ptr<Display> mDisplay =
202 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700203 getDisplayCreationArgsForPhysicalDisplay());
Vishnu Naira3140382022-02-24 14:07:11 -0800204
205 android::HWComposer::DeviceRequestedChanges mDeviceRequestedChanges{
206 {{nullptr, Composition::CLIENT}},
207 hal::DisplayRequest::FLIP_CLIENT_TARGET,
208 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
209 {DEFAULT_DISPLAY_ID.value,
210 {aidl::android::hardware::graphics::common::PixelFormat::RGBA_8888,
211 aidl::android::hardware::graphics::common::Dataspace::UNKNOWN},
212 -1.f,
213 DimmingStage::NONE},
214 };
215
216 void chooseCompositionStrategy(Display* display) {
217 std::optional<android::HWComposer::DeviceRequestedChanges> changes;
218 bool success = display->chooseCompositionStrategy(&changes);
219 display->resetCompositionStrategy();
220 if (success) {
221 display->applyCompositionStrategy(changes);
222 }
223 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700224};
225
226struct FullDisplayImplTestCommon : public DisplayTestCommon {
227 using Display = DisplayTestCommon::FullImplDisplay;
228 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700229 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700230};
231
232struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
233 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700234 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800235 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700236 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800237 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700238 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800239 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Vishnu Naira3140382022-02-24 14:07:11 -0800240 mResultWithBuffer.buffer = std::make_shared<
241 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
242 1ULL /* bufferId */,
243 HAL_PIXEL_FORMAT_RGBA_8888,
244 0ULL /*usage*/);
Lloyd Pique66d68602019-02-13 14:23:31 -0800245 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700246
Lloyd Piquede196652020-01-22 17:29:58 -0800247 Layer mLayer1;
248 Layer mLayer2;
249 LayerNoHWC2Layer mLayer3;
250 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700251 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700252 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Vishnu Naira3140382022-02-24 14:07:11 -0800253 impl::GpuCompositionResult mResultWithBuffer;
254 impl::GpuCompositionResult mResultWithoutBuffer;
Lloyd Pique45a165a2018-10-19 11:54:47 -0700255};
256
Lloyd Pique66d68602019-02-13 14:23:31 -0800257/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700258 * Basic construction
259 */
260
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700261struct DisplayCreationTest : public DisplayTestCommon {
262 using Display = DisplayTestCommon::FullImplDisplay;
263};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700264
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700265TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
266 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700267 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700268 EXPECT_TRUE(display->isSecure());
269 EXPECT_FALSE(display->isVirtual());
270 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
271}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700272
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800273TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
274 auto display =
275 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700276 EXPECT_FALSE(display->isSecure());
277 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200278 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700279}
280
281/*
282 * Display::setConfiguration()
283 */
284
285using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
286
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700287TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800288 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
289 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800290 .setPixels(DEFAULT_RESOLUTION)
291 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800292 .setPowerAdvisor(&mPowerAdvisor)
293 .setName(getDisplayNameFromCurrentTest())
294 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700295
296 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
297 EXPECT_TRUE(mDisplay->isSecure());
298 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700299 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700300
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700301 const auto& filter = mDisplay->getState().layerFilter;
302 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
303 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700304}
305
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800306TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
307 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
308 .setId(HAL_VIRTUAL_DISPLAY_ID)
309 .setPixels(DEFAULT_RESOLUTION)
310 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800311 .setPowerAdvisor(&mPowerAdvisor)
312 .setName(getDisplayNameFromCurrentTest())
313 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700314
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800315 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700316 EXPECT_FALSE(mDisplay->isSecure());
317 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700318 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700319
320 const auto& filter = mDisplay->getState().layerFilter;
321 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
322 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700323}
324
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800325TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
326 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
327 .setId(GPU_VIRTUAL_DISPLAY_ID)
328 .setPixels(DEFAULT_RESOLUTION)
329 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800330 .setPowerAdvisor(&mPowerAdvisor)
331 .setName(getDisplayNameFromCurrentTest())
332 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700333
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800334 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700335 EXPECT_FALSE(mDisplay->isSecure());
336 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700337 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700338
339 const auto& filter = mDisplay->getState().layerFilter;
340 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
341 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700342}
343
Lloyd Pique66d68602019-02-13 14:23:31 -0800344/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700345 * Display::disconnect()
346 */
347
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700348using DisplayDisconnectTest = PartialMockDisplayTestCommon;
349
350TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200351 // The first call to disconnect will disconnect the display with the HWC.
352 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700353 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700354
355 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200356 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700357 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700358}
359
Lloyd Pique66d68602019-02-13 14:23:31 -0800360/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700361 * Display::setColorTransform()
362 */
363
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700364using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
365
366TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800367 // No change does nothing
368 CompositionRefreshArgs refreshArgs;
369 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700370 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800371
Lloyd Pique32cbe282018-10-19 13:09:22 -0700372 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800373 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700374
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200375 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
376 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700377
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800378 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700379 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700380
381 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800382 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700383
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200384 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
385 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700386
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800387 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700388 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700389}
390
Lloyd Pique66d68602019-02-13 14:23:31 -0800391/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700392 * Display::setColorMode()
393 */
394
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700395using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
396
397TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800398 using ColorProfile = Output::ColorProfile;
399
Lloyd Pique31cb2942018-10-19 17:23:03 -0700400 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700401 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800402 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700403 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700404
Lloyd Piquef5275482019-01-29 18:42:42 -0800405 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
406 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700407
408 // 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);
412 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700413
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700414 // Otherwise if the values are unchanged, nothing happens
415 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
416 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700417
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700418 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
419 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
420 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
421 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700422
423 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800424 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700425 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800426 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700427 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
428 .Times(1);
429
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700430 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
431 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
432 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700433
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700434 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
435 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
436 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
437 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700438}
439
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700440TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800441 using ColorProfile = Output::ColorProfile;
442
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800443 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700444 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700445
Lloyd Piquef5275482019-01-29 18:42:42 -0800446 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700447 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800448 std::unique_ptr<DisplayColorProfile>(colorProfile));
449
450 EXPECT_CALL(*colorProfile,
451 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
452 ui::Dataspace::UNKNOWN))
453 .WillOnce(Return(ui::Dataspace::UNKNOWN));
454
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800456 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
457 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700458
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700459 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
460 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
461 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
462 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700463}
464
Lloyd Pique66d68602019-02-13 14:23:31 -0800465/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700466 * Display::createDisplayColorProfile()
467 */
468
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700469using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
470
471TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700472 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
473 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700474 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
475 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700476 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700477}
478
Lloyd Pique66d68602019-02-13 14:23:31 -0800479/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700480 * Display::createRenderSurface()
481 */
482
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700483using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
484
485TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700486 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700487 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700488 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
489 .setDisplayWidth(640)
490 .setDisplayHeight(480)
491 .setNativeWindow(mNativeWindow)
492 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700493 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700494}
495
Lloyd Pique66d68602019-02-13 14:23:31 -0800496/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800497 * Display::createOutputLayer()
498 */
499
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700500using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
501
502TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800503 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea516c002021-05-07 14:36:58 -0700504 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800505
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200506 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700507 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800508
Lloyd Piquede196652020-01-22 17:29:58 -0800509 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800510
Lloyd Piquea516c002021-05-07 14:36:58 -0700511 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800512
Lloyd Piquedf336d92019-03-07 21:38:42 -0800513 outputLayer.reset();
514}
515
516/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800517 * Display::setReleasedLayers()
518 */
519
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700520using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
521
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800522TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
523 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
524 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800525
526 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800527
528 {
529 Output::ReleasedLayers releasedLayers;
530 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800531 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800532 }
533
534 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800535 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800536
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800537 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800538
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800539 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
540 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800541}
542
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700543TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800544 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
545
546 {
547 Output::ReleasedLayers releasedLayers;
548 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700549 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800550 }
551
552 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700553 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800554
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700555 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800556 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800557}
558
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700559TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800560 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800561
562 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800563 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
564 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
565 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800566
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700567 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800568
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700569 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800570 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800571 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
572 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800573}
574
575/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800576 * Display::chooseCompositionStrategy()
577 */
578
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700579using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800580
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800581TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
582 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
583 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700584 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800585 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800586
Vishnu Naira3140382022-02-24 14:07:11 -0800587 chooseCompositionStrategy(gpuDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800588
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800589 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800590 EXPECT_TRUE(state.usesClientComposition);
591 EXPECT_FALSE(state.usesDeviceComposition);
592}
593
594TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700595 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200596 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800597 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800598 .WillOnce(Return(INVALID_OPERATION));
599
Vishnu Naira3140382022-02-24 14:07:11 -0800600 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800601
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700602 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800603 EXPECT_TRUE(state.usesClientComposition);
604 EXPECT_FALSE(state.usesDeviceComposition);
Vishnu Naira3140382022-02-24 14:07:11 -0800605 EXPECT_FALSE(state.previousDeviceRequestedChanges.has_value());
Lloyd Pique66d68602019-02-13 14:23:31 -0800606}
607
608TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700609 // Since two calls are made to anyLayersRequireClientComposition with different return
610 // values, use a Sequence to control the matching so the values are returned in a known
611 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800612 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700613 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
614 .InSequence(s)
615 .WillOnce(Return(true));
616 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800617 .InSequence(s)
618 .WillOnce(Return(false));
619
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700620 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800621 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Naira3140382022-02-24 14:07:11 -0800622 .WillOnce(testing::DoAll(testing::SetArgPointee<5>(mDeviceRequestedChanges),
623 Return(NO_ERROR)));
624 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
625 .Times(1);
626 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
627 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
628 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700629 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800630
Vishnu Naira3140382022-02-24 14:07:11 -0800631 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800632
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700633 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800634 EXPECT_FALSE(state.usesClientComposition);
635 EXPECT_TRUE(state.usesDeviceComposition);
636}
637
Alec Mouricdf16792021-12-10 13:16:06 -0800638TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithDisplayBrightness) {
639 // Since two calls are made to anyLayersRequireClientComposition with different return
640 // values, use a Sequence to control the matching so the values are returned in a known
641 // order.
642 constexpr float kDisplayBrightness = 0.5f;
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000643 constexpr float kDisplayBrightnessNits = 200.f;
Alec Mouricdf16792021-12-10 13:16:06 -0800644 EXPECT_CALL(mHwComposer,
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000645 setDisplayBrightness(DEFAULT_DISPLAY_ID, kDisplayBrightness, kDisplayBrightnessNits,
Alec Mouricdf16792021-12-10 13:16:06 -0800646 Hwc2::Composer::DisplayBrightnessOptions{.applyImmediately =
647 false}))
648 .WillOnce(Return(ByMove(ftl::yield<status_t>(NO_ERROR))));
649
Alec Mouricdf16792021-12-10 13:16:06 -0800650 mDisplay->setNextBrightness(kDisplayBrightness);
Vishnu Naira3140382022-02-24 14:07:11 -0800651 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
652 EXPECT_CALL(*renderSurface, beginFrame(_)).Times(1);
653 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Alec Mouri4d8a05d2022-03-23 18:14:26 +0000654 mDisplay->editState().displayBrightnessNits = kDisplayBrightnessNits;
Vishnu Naira3140382022-02-24 14:07:11 -0800655 mDisplay->beginFrame();
Alec Mouricdf16792021-12-10 13:16:06 -0800656
657 auto& state = mDisplay->getState();
Alec Mouricdf16792021-12-10 13:16:06 -0800658 EXPECT_FALSE(state.displayBrightness.has_value());
659}
660
Lloyd Pique66d68602019-02-13 14:23:31 -0800661TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700662 // Since two calls are made to anyLayersRequireClientComposition with different return
663 // values, use a Sequence to control the matching so the values are returned in a known
664 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800665 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700666 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
667 .InSequence(s)
668 .WillOnce(Return(true));
669 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800670 .InSequence(s)
671 .WillOnce(Return(false));
672
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700673 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800674 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Naira3140382022-02-24 14:07:11 -0800675 .WillOnce(DoAll(SetArgPointee<5>(mDeviceRequestedChanges), Return(NO_ERROR)));
676 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
677 .Times(1);
678 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
679 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
680 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700681 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800682
Vishnu Naira3140382022-02-24 14:07:11 -0800683 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800684
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700685 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800686 EXPECT_FALSE(state.usesClientComposition);
687 EXPECT_TRUE(state.usesDeviceComposition);
688}
689
690/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800691 * Display::getSkipColorTransform()
692 */
693
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700694using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500695using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700696
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800697TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Ady Abrahamde549d42022-01-26 19:19:17 -0800698 EXPECT_CALL(mHwComposer, hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700699 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800700 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
701 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
702 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800703}
704
Dominik Laskowski1162e472020-04-02 19:02:47 -0700705TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800706 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200707 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500708 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800709 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700710 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800711}
712
713/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800714 * Display::anyLayersRequireClientComposition()
715 */
716
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700717using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
718
719TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800720 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
721 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
722 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800723
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700724 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800725}
726
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700727TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800728 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
729 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800730
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700731 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800732}
733
734/*
735 * Display::allLayersRequireClientComposition()
736 */
737
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700738using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
739
740TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800741 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
742 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
743 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800744
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700745 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800746}
747
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700748TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800749 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
750 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800751
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700752 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800753}
754
755/*
756 * Display::applyChangedTypesToLayers()
757 */
758
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700759using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
760
761TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700762 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800763}
764
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700765TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500766 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800767 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500768 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800769 .Times(1);
770
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700771 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500772 {&mLayer1.hwc2Layer, Composition::CLIENT},
773 {&mLayer2.hwc2Layer, Composition::DEVICE},
774 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800775 });
776}
777
778/*
779 * Display::applyDisplayRequests()
780 */
781
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700782using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
783
784TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700785 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800786
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700787 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800788 EXPECT_FALSE(state.flipClientTarget);
789}
790
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700791TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700792 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800793
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700794 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800795 EXPECT_TRUE(state.flipClientTarget);
796}
797
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700798TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700799 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800800
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700801 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800802 EXPECT_FALSE(state.flipClientTarget);
803}
804
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700805TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700806 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800807
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700808 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800809 EXPECT_TRUE(state.flipClientTarget);
810}
811
812/*
813 * Display::applyLayerRequestsToLayers()
814 */
815
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700816using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
817
818TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
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 Piquea38ea7e2019-04-16 18:10:26 -0700823 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800824}
825
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700826TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800827 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
828 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
829 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800830
Lloyd Piquede196652020-01-22 17:29:58 -0800831 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800832 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
833 .Times(1);
834
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700835 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700836 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
837 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800838 });
839}
840
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800841/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700842 * Display::applyClientTargetRequests()
843 */
844
845using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
846
847TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700848 static constexpr float kWhitePointNits = 800.f;
849
Alec Mouri85065692022-03-18 00:58:26 +0000850 Display::ClientTargetProperty clientTargetProperty = {
851 .clientTargetProperty =
852 {
853 .pixelFormat =
854 aidl::android::hardware::graphics::common::PixelFormat::RGB_565,
855 .dataspace = aidl::android::hardware::graphics::common::Dataspace::
856 STANDARD_BT470M,
857 },
858 .brightness = kWhitePointNits,
859 .dimmingStage = aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
860 };
861
Ady Abraham0094dc62021-06-03 10:08:33 -0700862 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
863 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
864
Alec Mouri85065692022-03-18 00:58:26 +0000865 EXPECT_CALL(*renderSurface,
866 setBufferPixelFormat(static_cast<ui::PixelFormat>(
867 clientTargetProperty.clientTargetProperty.pixelFormat)));
868 EXPECT_CALL(*renderSurface,
869 setBufferDataspace(static_cast<ui::Dataspace>(
870 clientTargetProperty.clientTargetProperty.dataspace)));
871 mDisplay->applyClientTargetRequests(clientTargetProperty);
Ady Abraham0094dc62021-06-03 10:08:33 -0700872
873 auto& state = mDisplay->getState();
Alec Mouri85065692022-03-18 00:58:26 +0000874 EXPECT_EQ(clientTargetProperty.clientTargetProperty.dataspace,
875 static_cast<aidl::android::hardware::graphics::common::Dataspace>(state.dataspace));
Alec Mourif8d093d2022-02-10 15:16:59 -0800876 EXPECT_EQ(kWhitePointNits, state.clientTargetBrightness);
Alec Mouri85065692022-03-18 00:58:26 +0000877 EXPECT_EQ(aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
878 state.clientTargetDimmingStage);
Ady Abraham0094dc62021-06-03 10:08:33 -0700879}
880
881/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800882 * Display::presentAndGetFrameFences()
883 */
884
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700885using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
886
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800887TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
888 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
889 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800890
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800891 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800892
893 ASSERT_TRUE(result.presentFence.get());
894 EXPECT_FALSE(result.presentFence->isValid());
895 EXPECT_EQ(0u, result.layerFences.size());
896}
897
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700898TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800899 sp<Fence> presentFence = new Fence();
900 sp<Fence> layer1Fence = new Fence();
901 sp<Fence> layer2Fence = new Fence();
902
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700903 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700904 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200905 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
906 .WillOnce(Return(presentFence));
907 EXPECT_CALL(mHwComposer,
908 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800909 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200910 EXPECT_CALL(mHwComposer,
911 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800912 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200913 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800914
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700915 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800916
917 EXPECT_EQ(presentFence, result.presentFence);
918
919 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800920 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800921 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800922 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800923 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800924}
925
Lloyd Pique688abd42019-02-15 15:42:24 -0800926/*
927 * Display::setExpensiveRenderingExpected()
928 */
929
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700930using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
931
932TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800933 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700934 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800935
936 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700937 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800938}
939
Lloyd Piqued3d69882019-02-28 16:03:46 -0800940/*
941 * Display::finishFrame()
942 */
943
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700944using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
945
946TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800947 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700948 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800949
950 // We expect no calls to queueBuffer if composition was skipped.
951 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
952
Lloyd Piquea76ce462020-01-14 13:06:37 -0800953 // Expect a call to signal no expensive rendering since there is no client composition.
954 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
955
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700956 mDisplay->editState().isEnabled = true;
957 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000958 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700959 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800960
Vishnu Naira3140382022-02-24 14:07:11 -0800961 mDisplay->finishFrame({}, std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800962}
963
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700964TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800965 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
966 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800967
968 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800969 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800970
971 // We expect no calls to queueBuffer if composition was skipped.
972 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
973
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800974 gpuDisplay->editState().isEnabled = true;
975 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000976 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800977 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800978
Vishnu Naira3140382022-02-24 14:07:11 -0800979 gpuDisplay->finishFrame({}, std::move(mResultWithoutBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800980}
981
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700982TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800983 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
984 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800985
986 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800987 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800988
989 // We expect a single call to queueBuffer when composition is not skipped.
990 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
991
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800992 gpuDisplay->editState().isEnabled = true;
993 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000994 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800995 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Vishnu Naira3140382022-02-24 14:07:11 -0800996 gpuDisplay->finishFrame({}, std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800997}
998
Lloyd Piquec6607552019-12-02 17:57:39 -0800999/*
1000 * Display functional tests
1001 */
1002
1003struct DisplayFunctionalTest : public testing::Test {
1004 class Display : public impl::Display {
1005 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001006 using impl::Display::injectOutputLayerForTest;
1007 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1008 };
1009
Lloyd Piquec6607552019-12-02 17:57:39 -08001010 DisplayFunctionalTest() {
1011 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Kriti Dang646f8ec2022-01-18 14:35:02 +01001012 mDisplay = createDisplay();
1013 mRenderSurface = createRenderSurface();
Lloyd Piquec6607552019-12-02 17:57:39 -08001014 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1015 }
1016
1017 NiceMock<android::mock::HWComposer> mHwComposer;
1018 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1019 NiceMock<mock::CompositionEngine> mCompositionEngine;
1020 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1021 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Kriti Dang646f8ec2022-01-18 14:35:02 +01001022 std::shared_ptr<Display> mDisplay;
1023 impl::RenderSurface* mRenderSurface;
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001024
Kriti Dang646f8ec2022-01-18 14:35:02 +01001025 std::shared_ptr<Display> createDisplay() {
1026 return impl::createDisplayTemplated<Display>(mCompositionEngine,
1027 DisplayCreationArgsBuilder()
1028 .setId(DEFAULT_DISPLAY_ID)
1029 .setPixels(DEFAULT_RESOLUTION)
1030 .setIsSecure(true)
1031 .setPowerAdvisor(&mPowerAdvisor)
1032 .build());
1033 ;
1034 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001035
Kriti Dang646f8ec2022-01-18 14:35:02 +01001036 impl::RenderSurface* createRenderSurface() {
1037 return new impl::RenderSurface{mCompositionEngine, *mDisplay,
1038 RenderSurfaceCreationArgsBuilder()
1039 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1040 .setDisplayHeight(DEFAULT_RESOLUTION.height)
1041 .setNativeWindow(mNativeWindow)
1042 .setDisplaySurface(mDisplaySurface)
1043 .build()};
1044 }
Lloyd Piquec6607552019-12-02 17:57:39 -08001045};
1046
1047TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1048 InSequence seq;
1049
1050 mDisplay->editState().isEnabled = true;
1051
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001052 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001053 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1054
1055 mDisplay->postFramebuffer();
1056}
1057
Lloyd Pique45a165a2018-10-19 11:54:47 -07001058} // namespace
1059} // namespace android::compositionengine