blob: 36b04d909f4c330faa0e925ba30c42e9a24772e0 [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 Nair7234fa52022-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 Nair7234fa52022-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;
48
Lloyd Pique45a165a2018-10-19 11:54:47 -070049namespace android::compositionengine {
50namespace {
51
Peiyong Line9d809e2020-04-14 13:10:48 -070052namespace hal = android::hardware::graphics::composer::hal;
53
Lloyd Piquef5275482019-01-29 18:42:42 -080054using testing::_;
Alec Mouricdf16792021-12-10 13:16:06 -080055using testing::ByMove;
Lloyd Pique66d68602019-02-13 14:23:31 -080056using testing::DoAll;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070057using testing::Eq;
Lloyd Piquec6607552019-12-02 17:57:39 -080058using testing::InSequence;
59using testing::NiceMock;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070060using testing::Pointee;
61using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070062using testing::Return;
Lloyd Pique45a165a2018-10-19 11:54:47 -070063using testing::ReturnRef;
Lloyd Pique66d68602019-02-13 14:23:31 -080064using testing::Sequence;
65using testing::SetArgPointee;
Lloyd Pique45a165a2018-10-19 11:54:47 -070066using testing::StrictMock;
67
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080068constexpr PhysicalDisplayId DEFAULT_DISPLAY_ID = PhysicalDisplayId::fromPort(123u);
69constexpr HalVirtualDisplayId HAL_VIRTUAL_DISPLAY_ID{456u};
70constexpr GpuVirtualDisplayId GPU_VIRTUAL_DISPLAY_ID{789u};
Dominik Laskowskif1833852021-03-23 15:06:50 -070071
Dominik Laskowski3dce4f42021-03-08 20:48:28 -080072constexpr ui::Size DEFAULT_RESOLUTION{1920, 1080};
Lloyd Pique45a165a2018-10-19 11:54:47 -070073
Lloyd Piquede196652020-01-22 17:29:58 -080074struct Layer {
75 Layer() {
76 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
77 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
78 }
79
Ady Abrahame0eafa82022-02-02 19:30:47 -080080 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080081 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
82 StrictMock<HWC2::mock::Layer> hwc2Layer;
83};
84
85struct LayerNoHWC2Layer {
86 LayerNoHWC2Layer() {
87 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
88 EXPECT_CALL(*outputLayer, getHwcLayer()).WillRepeatedly(Return(nullptr));
89 }
90
Ady Abrahame0eafa82022-02-02 19:30:47 -080091 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -080092 StrictMock<mock::OutputLayer>* outputLayer = new StrictMock<mock::OutputLayer>();
93};
94
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -070095struct DisplayTestCommon : public testing::Test {
96 // Uses the full implementation of a display
97 class FullImplDisplay : public impl::Display {
Lloyd Pique01c77c12019-04-17 12:48:32 -070098 public:
Lloyd Pique01c77c12019-04-17 12:48:32 -070099 using impl::Display::injectOutputLayerForTest;
100 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
101 };
102
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700103 // Uses a special implementation with key internal member functions set up
104 // as mock implementations, to allow for easier testing.
105 struct PartialMockDisplay : public impl::Display {
106 PartialMockDisplay(const compositionengine::CompositionEngine& compositionEngine)
107 : mCompositionEngine(compositionEngine) {}
108
109 // compositionengine::Output overrides
110 const OutputCompositionState& getState() const override { return mState; }
111 OutputCompositionState& editState() override { return mState; }
112
113 // compositionengine::impl::Output overrides
114 const CompositionEngine& getCompositionEngine() const override {
115 return mCompositionEngine;
116 };
117
118 // Mock implementation overrides
119 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
120 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex,
121 compositionengine::OutputLayer*(size_t));
122 MOCK_METHOD2(ensureOutputLayer,
123 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
124 MOCK_METHOD0(finalizePendingOutputLayers, void());
125 MOCK_METHOD0(clearOutputLayers, void());
126 MOCK_CONST_METHOD1(dumpState, void(std::string&));
127 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
128 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
129 MOCK_CONST_METHOD0(anyLayersRequireClientComposition, bool());
130 MOCK_CONST_METHOD0(allLayersRequireClientComposition, bool());
131 MOCK_METHOD1(applyChangedTypesToLayers, void(const impl::Display::ChangedTypes&));
132 MOCK_METHOD1(applyDisplayRequests, void(const impl::Display::DisplayRequests&));
133 MOCK_METHOD1(applyLayerRequestsToLayers, void(const impl::Display::LayerRequests&));
134
135 const compositionengine::CompositionEngine& mCompositionEngine;
136 impl::OutputCompositionState mState;
137 };
138
139 static std::string getDisplayNameFromCurrentTest() {
140 const ::testing::TestInfo* const test_info =
141 ::testing::UnitTest::GetInstance()->current_test_info();
142 return std::string("display for ") + test_info->test_case_name() + "." + test_info->name();
143 }
144
145 template <typename Display>
Lloyd Pique01c77c12019-04-17 12:48:32 -0700146 static std::shared_ptr<Display> createDisplay(
147 const compositionengine::CompositionEngine& compositionEngine,
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700148 compositionengine::DisplayCreationArgs args) {
149 args.name = getDisplayNameFromCurrentTest();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700150 return impl::createDisplayTemplated<Display>(compositionEngine, args);
151 }
152
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700153 template <typename Display>
154 static std::shared_ptr<StrictMock<Display>> createPartialMockDisplay(
155 const compositionengine::CompositionEngine& compositionEngine,
156 compositionengine::DisplayCreationArgs args) {
157 args.name = getDisplayNameFromCurrentTest();
158 auto display = std::make_shared<StrictMock<Display>>(compositionEngine);
Lloyd Pique66d68602019-02-13 14:23:31 -0800159
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700160 display->setConfiguration(args);
161
162 return display;
163 }
164
165 DisplayTestCommon() {
166 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Lloyd Piquee9eff972020-05-05 12:36:44 -0700167 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
168 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -0700169 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Kriti Dang646f8ec2022-01-18 14:35:02 +0100170 EXPECT_CALL(mHwComposer, getBootDisplayModeSupport()).WillRepeatedly(Return(false));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700171 }
172
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700173 DisplayCreationArgs getDisplayCreationArgsForPhysicalDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700174 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800175 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800176 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700177 .setIsSecure(true)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700178 .setPowerAdvisor(&mPowerAdvisor)
179 .build();
180 }
181
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800182 DisplayCreationArgs getDisplayCreationArgsForGpuVirtualDisplay() {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700183 return DisplayCreationArgsBuilder()
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800184 .setId(GPU_VIRTUAL_DISPLAY_ID)
185 .setPixels(DEFAULT_RESOLUTION)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700186 .setIsSecure(false)
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700187 .setPowerAdvisor(&mPowerAdvisor)
188 .build();
189 }
190
191 StrictMock<android::mock::HWComposer> mHwComposer;
192 StrictMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
Lloyd Piquee9eff972020-05-05 12:36:44 -0700193 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700194 StrictMock<mock::CompositionEngine> mCompositionEngine;
195 sp<mock::NativeWindow> mNativeWindow = new StrictMock<mock::NativeWindow>();
196};
197
198struct PartialMockDisplayTestCommon : public DisplayTestCommon {
199 using Display = DisplayTestCommon::PartialMockDisplay;
200 std::shared_ptr<Display> mDisplay =
201 createPartialMockDisplay<Display>(mCompositionEngine,
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700202 getDisplayCreationArgsForPhysicalDisplay());
Vishnu Nair7234fa52022-02-24 14:07:11 -0800203
204 android::HWComposer::DeviceRequestedChanges mDeviceRequestedChanges{
205 {{nullptr, Composition::CLIENT}},
206 hal::DisplayRequest::FLIP_CLIENT_TARGET,
207 {{nullptr, hal::LayerRequest::CLEAR_CLIENT_TARGET}},
208 {hal::PixelFormat::RGBA_8888, hal::Dataspace::UNKNOWN},
209 -1.f,
210 };
211
212 void chooseCompositionStrategy(Display* display) {
213 std::optional<android::HWComposer::DeviceRequestedChanges> changes =
214 display->chooseCompositionStrategy();
215 if (changes) {
216 display->applyCompositionStrategy(changes);
217 }
218 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700219};
220
221struct FullDisplayImplTestCommon : public DisplayTestCommon {
222 using Display = DisplayTestCommon::FullImplDisplay;
223 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700224 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700225};
226
227struct DisplayWithLayersTestCommon : public FullDisplayImplTestCommon {
228 DisplayWithLayersTestCommon() {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700229 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800230 std::unique_ptr<compositionengine::OutputLayer>(mLayer1.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700231 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800232 std::unique_ptr<compositionengine::OutputLayer>(mLayer2.outputLayer));
Lloyd Pique01c77c12019-04-17 12:48:32 -0700233 mDisplay->injectOutputLayerForTest(
Lloyd Piquede196652020-01-22 17:29:58 -0800234 std::unique_ptr<compositionengine::OutputLayer>(mLayer3.outputLayer));
Vishnu Nair7234fa52022-02-24 14:07:11 -0800235 mResultWithBuffer.buffer = std::make_shared<
236 renderengine::mock::FakeExternalTexture>(1U /*width*/, 1U /*height*/,
237 1ULL /* bufferId */,
238 HAL_PIXEL_FORMAT_RGBA_8888,
239 0ULL /*usage*/);
Lloyd Pique66d68602019-02-13 14:23:31 -0800240 }
Lloyd Pique45a165a2018-10-19 11:54:47 -0700241
Lloyd Piquede196652020-01-22 17:29:58 -0800242 Layer mLayer1;
243 Layer mLayer2;
244 LayerNoHWC2Layer mLayer3;
245 StrictMock<HWC2::mock::Layer> hwc2LayerUnknown;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700246 std::shared_ptr<Display> mDisplay =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700247 createDisplay<Display>(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Vishnu Nair7234fa52022-02-24 14:07:11 -0800248 impl::GpuCompositionResult mResultWithBuffer;
249 impl::GpuCompositionResult mResultWithoutBuffer;
Lloyd Pique45a165a2018-10-19 11:54:47 -0700250};
251
Lloyd Pique66d68602019-02-13 14:23:31 -0800252/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700253 * Basic construction
254 */
255
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700256struct DisplayCreationTest : public DisplayTestCommon {
257 using Display = DisplayTestCommon::FullImplDisplay;
258};
Lloyd Pique45a165a2018-10-19 11:54:47 -0700259
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700260TEST_F(DisplayCreationTest, createPhysicalInternalDisplay) {
261 auto display =
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700262 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForPhysicalDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700263 EXPECT_TRUE(display->isSecure());
264 EXPECT_FALSE(display->isVirtual());
265 EXPECT_EQ(DEFAULT_DISPLAY_ID, display->getId());
266}
Lloyd Pique45a165a2018-10-19 11:54:47 -0700267
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800268TEST_F(DisplayCreationTest, createGpuVirtualDisplay) {
269 auto display =
270 impl::createDisplay(mCompositionEngine, getDisplayCreationArgsForGpuVirtualDisplay());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700271 EXPECT_FALSE(display->isSecure());
272 EXPECT_TRUE(display->isVirtual());
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200273 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(display->getId()));
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700274}
275
276/*
277 * Display::setConfiguration()
278 */
279
280using DisplaySetConfigurationTest = PartialMockDisplayTestCommon;
281
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700282TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800283 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
284 .setId(DEFAULT_DISPLAY_ID)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800285 .setPixels(DEFAULT_RESOLUTION)
286 .setIsSecure(true)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800287 .setPowerAdvisor(&mPowerAdvisor)
288 .setName(getDisplayNameFromCurrentTest())
289 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700290
291 EXPECT_EQ(DEFAULT_DISPLAY_ID, mDisplay->getId());
292 EXPECT_TRUE(mDisplay->isSecure());
293 EXPECT_FALSE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700294 EXPECT_FALSE(mDisplay->isValid());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700295
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700296 const auto& filter = mDisplay->getState().layerFilter;
297 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
298 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700299}
300
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800301TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
302 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
303 .setId(HAL_VIRTUAL_DISPLAY_ID)
304 .setPixels(DEFAULT_RESOLUTION)
305 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800306 .setPowerAdvisor(&mPowerAdvisor)
307 .setName(getDisplayNameFromCurrentTest())
308 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700309
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800310 EXPECT_EQ(HAL_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700311 EXPECT_FALSE(mDisplay->isSecure());
312 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700313 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700314
315 const auto& filter = mDisplay->getState().layerFilter;
316 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
317 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700318}
319
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800320TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
321 mDisplay->setConfiguration(DisplayCreationArgsBuilder()
322 .setId(GPU_VIRTUAL_DISPLAY_ID)
323 .setPixels(DEFAULT_RESOLUTION)
324 .setIsSecure(false)
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800325 .setPowerAdvisor(&mPowerAdvisor)
326 .setName(getDisplayNameFromCurrentTest())
327 .build());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700328
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800329 EXPECT_EQ(GPU_VIRTUAL_DISPLAY_ID, mDisplay->getId());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700330 EXPECT_FALSE(mDisplay->isSecure());
331 EXPECT_TRUE(mDisplay->isVirtual());
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700332 EXPECT_FALSE(mDisplay->isValid());
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700333
334 const auto& filter = mDisplay->getState().layerFilter;
335 EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
336 EXPECT_FALSE(filter.toInternalDisplay);
Lloyd Pique45a165a2018-10-19 11:54:47 -0700337}
338
Lloyd Pique66d68602019-02-13 14:23:31 -0800339/*
Lloyd Pique45a165a2018-10-19 11:54:47 -0700340 * Display::disconnect()
341 */
342
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700343using DisplayDisconnectTest = PartialMockDisplayTestCommon;
344
345TEST_F(DisplayDisconnectTest, disconnectsDisplay) {
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200346 // The first call to disconnect will disconnect the display with the HWC.
347 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700348 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700349
350 // Subsequent calls will do nothing,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200351 EXPECT_CALL(mHwComposer, disconnectDisplay(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(0);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700352 mDisplay->disconnect();
Lloyd Pique45a165a2018-10-19 11:54:47 -0700353}
354
Lloyd Pique66d68602019-02-13 14:23:31 -0800355/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700356 * Display::setColorTransform()
357 */
358
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700359using DisplaySetColorTransformTest = PartialMockDisplayTestCommon;
360
361TEST_F(DisplaySetColorTransformTest, setsTransform) {
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800362 // No change does nothing
363 CompositionRefreshArgs refreshArgs;
364 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700365 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800366
Lloyd Pique32cbe282018-10-19 13:09:22 -0700367 // Identity matrix sets an identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800368 const mat4 kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700369
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200370 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kIdentity))
371 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700372
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800373 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700374 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700375
376 // Non-identity matrix sets a non-identity state value
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800377 const mat4 kNonIdentity = mat4() * 2;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700378
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200379 EXPECT_CALL(mHwComposer, setColorTransform(HalDisplayId(DEFAULT_DISPLAY_ID), kNonIdentity))
380 .Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700381
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800382 refreshArgs.colorTransformMatrix = kNonIdentity;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700383 mDisplay->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700384}
385
Lloyd Pique66d68602019-02-13 14:23:31 -0800386/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700387 * Display::setColorMode()
388 */
389
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700390using DisplaySetColorModeTest = PartialMockDisplayTestCommon;
391
392TEST_F(DisplaySetColorModeTest, setsModeUnlessNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800393 using ColorProfile = Output::ColorProfile;
394
Lloyd Pique31cb2942018-10-19 17:23:03 -0700395 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700396 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piquef5275482019-01-29 18:42:42 -0800397 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700398 mDisplay->setDisplayColorProfileForTest(std::unique_ptr<DisplayColorProfile>(colorProfile));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700399
Lloyd Piquef5275482019-01-29 18:42:42 -0800400 EXPECT_CALL(*colorProfile, getTargetDataspace(_, _, _))
401 .WillRepeatedly(Return(ui::Dataspace::UNKNOWN));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700402
403 // These values are expected to be the initial state.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700404 ASSERT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
405 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
406 ASSERT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
407 ASSERT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700408
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700409 // Otherwise if the values are unchanged, nothing happens
410 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
411 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700412
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700413 EXPECT_EQ(ui::ColorMode::NATIVE, mDisplay->getState().colorMode);
414 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().dataspace);
415 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, mDisplay->getState().renderIntent);
416 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700417
418 // Otherwise if the values are different, updates happen
Lloyd Piqueef958122019-02-05 18:00:12 -0800419 EXPECT_CALL(*renderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700420 EXPECT_CALL(mHwComposer,
Lloyd Piqueef958122019-02-05 18:00:12 -0800421 setActiveColorMode(DEFAULT_DISPLAY_ID, ui::ColorMode::DISPLAY_P3,
Lloyd Pique32cbe282018-10-19 13:09:22 -0700422 ui::RenderIntent::TONE_MAP_COLORIMETRIC))
423 .Times(1);
424
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700425 mDisplay->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
426 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
427 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700428
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700429 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mDisplay->getState().colorMode);
430 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mDisplay->getState().dataspace);
431 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mDisplay->getState().renderIntent);
432 EXPECT_EQ(ui::Dataspace::UNKNOWN, mDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700433}
434
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700435TEST_F(DisplaySetColorModeTest, doesNothingForVirtualDisplay) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800436 using ColorProfile = Output::ColorProfile;
437
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800438 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700439 std::shared_ptr<impl::Display> virtualDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700440
Lloyd Piquef5275482019-01-29 18:42:42 -0800441 mock::DisplayColorProfile* colorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700442 virtualDisplay->setDisplayColorProfileForTest(
Lloyd Piquef5275482019-01-29 18:42:42 -0800443 std::unique_ptr<DisplayColorProfile>(colorProfile));
444
445 EXPECT_CALL(*colorProfile,
446 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
447 ui::Dataspace::UNKNOWN))
448 .WillOnce(Return(ui::Dataspace::UNKNOWN));
449
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700450 virtualDisplay->setColorProfile(
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800451 ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
452 ui::RenderIntent::TONE_MAP_COLORIMETRIC, ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700453
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700454 EXPECT_EQ(ui::ColorMode::NATIVE, virtualDisplay->getState().colorMode);
455 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().dataspace);
456 EXPECT_EQ(ui::RenderIntent::COLORIMETRIC, virtualDisplay->getState().renderIntent);
457 EXPECT_EQ(ui::Dataspace::UNKNOWN, virtualDisplay->getState().targetDataspace);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700458}
459
Lloyd Pique66d68602019-02-13 14:23:31 -0800460/*
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700461 * Display::createDisplayColorProfile()
462 */
463
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700464using DisplayCreateColorProfileTest = PartialMockDisplayTestCommon;
465
466TEST_F(DisplayCreateColorProfileTest, setsDisplayColorProfile) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700467 EXPECT_TRUE(mDisplay->getDisplayColorProfile() == nullptr);
468 mDisplay->createDisplayColorProfile(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700469 DisplayColorProfileCreationArgs{false, HdrCapabilities(), 0,
470 DisplayColorProfileCreationArgs::HwcColorModes()});
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700471 EXPECT_TRUE(mDisplay->getDisplayColorProfile() != nullptr);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700472}
473
Lloyd Pique66d68602019-02-13 14:23:31 -0800474/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700475 * Display::createRenderSurface()
476 */
477
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700478using DisplayCreateRenderSurfaceTest = PartialMockDisplayTestCommon;
479
480TEST_F(DisplayCreateRenderSurfaceTest, setsRenderSurface) {
chaviw8beb4142019-04-11 13:09:05 -0700481 EXPECT_CALL(*mNativeWindow, disconnect(NATIVE_WINDOW_API_EGL)).WillRepeatedly(Return(NO_ERROR));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700482 EXPECT_TRUE(mDisplay->getRenderSurface() == nullptr);
Dominik Laskowski50121d52021-04-23 13:01:16 -0700483 mDisplay->createRenderSurface(RenderSurfaceCreationArgsBuilder()
484 .setDisplayWidth(640)
485 .setDisplayHeight(480)
486 .setNativeWindow(mNativeWindow)
487 .build());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700488 EXPECT_TRUE(mDisplay->getRenderSurface() != nullptr);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700489}
490
Lloyd Pique66d68602019-02-13 14:23:31 -0800491/*
Lloyd Piquedf336d92019-03-07 21:38:42 -0800492 * Display::createOutputLayer()
493 */
494
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700495using DisplayCreateOutputLayerTest = FullDisplayImplTestCommon;
496
497TEST_F(DisplayCreateOutputLayerTest, setsHwcLayer) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800498 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea516c002021-05-07 14:36:58 -0700499 auto hwcLayer = std::make_shared<StrictMock<HWC2::mock::Layer>>();
Lloyd Piquedf336d92019-03-07 21:38:42 -0800500
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200501 EXPECT_CALL(mHwComposer, createLayer(HalDisplayId(DEFAULT_DISPLAY_ID)))
Lloyd Piquea516c002021-05-07 14:36:58 -0700502 .WillOnce(Return(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -0800503
Lloyd Piquede196652020-01-22 17:29:58 -0800504 auto outputLayer = mDisplay->createOutputLayer(layerFE);
Lloyd Piquedf336d92019-03-07 21:38:42 -0800505
Lloyd Piquea516c002021-05-07 14:36:58 -0700506 EXPECT_EQ(hwcLayer.get(), outputLayer->getHwcLayer());
Lloyd Piquedf336d92019-03-07 21:38:42 -0800507
Lloyd Piquedf336d92019-03-07 21:38:42 -0800508 outputLayer.reset();
509}
510
511/*
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800512 * Display::setReleasedLayers()
513 */
514
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700515using DisplaySetReleasedLayersTest = DisplayWithLayersTestCommon;
516
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800517TEST_F(DisplaySetReleasedLayersTest, doesNothingIfGpuDisplay) {
518 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
519 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800520
521 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800522
523 {
524 Output::ReleasedLayers releasedLayers;
525 releasedLayers.emplace_back(layerXLayerFE);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800526 gpuDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800527 }
528
529 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800530 refreshArgs.layersWithQueuedFrames.push_back(layerXLayerFE);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800531
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800532 gpuDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800533
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800534 const auto& releasedLayers = gpuDisplay->getReleasedLayersForTest();
535 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800536}
537
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700538TEST_F(DisplaySetReleasedLayersTest, doesNothingIfNoLayersWithQueuedFrames) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800539 sp<mock::LayerFE> layerXLayerFE = new StrictMock<mock::LayerFE>();
540
541 {
542 Output::ReleasedLayers releasedLayers;
543 releasedLayers.emplace_back(layerXLayerFE);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700544 mDisplay->setReleasedLayers(std::move(releasedLayers));
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800545 }
546
547 CompositionRefreshArgs refreshArgs;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700548 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800549
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700550 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800551 ASSERT_EQ(1u, releasedLayers.size());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800552}
553
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700554TEST_F(DisplaySetReleasedLayersTest, setReleasedLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800555 sp<mock::LayerFE> unknownLayer = new StrictMock<mock::LayerFE>();
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800556
557 CompositionRefreshArgs refreshArgs;
Lloyd Piquede196652020-01-22 17:29:58 -0800558 refreshArgs.layersWithQueuedFrames.push_back(mLayer1.layerFE);
559 refreshArgs.layersWithQueuedFrames.push_back(mLayer2.layerFE);
560 refreshArgs.layersWithQueuedFrames.push_back(unknownLayer);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800561
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700562 mDisplay->setReleasedLayers(refreshArgs);
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800563
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700564 const auto& releasedLayers = mDisplay->getReleasedLayersForTest();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800565 ASSERT_EQ(2u, releasedLayers.size());
Lloyd Piquede196652020-01-22 17:29:58 -0800566 ASSERT_EQ(mLayer1.layerFE.get(), releasedLayers[0].promote().get());
567 ASSERT_EQ(mLayer2.layerFE.get(), releasedLayers[1].promote().get());
Lloyd Piquec29e4c62019-03-07 21:48:19 -0800568}
569
570/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800571 * Display::chooseCompositionStrategy()
572 */
573
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700574using DisplayChooseCompositionStrategyTest = PartialMockDisplayTestCommon;
Lloyd Pique66d68602019-02-13 14:23:31 -0800575
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800576TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutIfGpuDisplay) {
577 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
578 std::shared_ptr<Display> gpuDisplay =
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700579 createPartialMockDisplay<Display>(mCompositionEngine, args);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800580 EXPECT_TRUE(GpuVirtualDisplayId::tryCast(gpuDisplay->getId()));
Lloyd Pique66d68602019-02-13 14:23:31 -0800581
Vishnu Nair7234fa52022-02-24 14:07:11 -0800582 chooseCompositionStrategy(gpuDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800583
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800584 auto& state = gpuDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800585 EXPECT_TRUE(state.usesClientComposition);
586 EXPECT_FALSE(state.usesDeviceComposition);
587}
588
589TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700590 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200591 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800592 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
Lloyd Pique66d68602019-02-13 14:23:31 -0800593 .WillOnce(Return(INVALID_OPERATION));
594
Vishnu Nair7234fa52022-02-24 14:07:11 -0800595 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800596
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700597 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800598 EXPECT_TRUE(state.usesClientComposition);
599 EXPECT_FALSE(state.usesDeviceComposition);
Vishnu Nair7234fa52022-02-24 14:07:11 -0800600 EXPECT_FALSE(state.previousDeviceRequestedChanges.has_value());
Lloyd Pique66d68602019-02-13 14:23:31 -0800601}
602
603TEST_F(DisplayChooseCompositionStrategyTest, normalOperation) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700604 // Since two calls are made to anyLayersRequireClientComposition with different return
605 // values, use a Sequence to control the matching so the values are returned in a known
606 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800607 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700608 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
609 .InSequence(s)
610 .WillOnce(Return(true));
611 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800612 .InSequence(s)
613 .WillOnce(Return(false));
614
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700615 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800616 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Nair7234fa52022-02-24 14:07:11 -0800617 .WillOnce(testing::DoAll(testing::SetArgPointee<5>(mDeviceRequestedChanges),
618 Return(NO_ERROR)));
619 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
620 .Times(1);
621 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
622 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
623 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700624 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800625
Vishnu Nair7234fa52022-02-24 14:07:11 -0800626 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800627
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700628 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800629 EXPECT_FALSE(state.usesClientComposition);
630 EXPECT_TRUE(state.usesDeviceComposition);
631}
632
Alec Mouricdf16792021-12-10 13:16:06 -0800633TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithDisplayBrightness) {
634 // Since two calls are made to anyLayersRequireClientComposition with different return
635 // values, use a Sequence to control the matching so the values are returned in a known
636 // order.
637 constexpr float kDisplayBrightness = 0.5f;
638 Sequence s;
639 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
640 .InSequence(s)
641 .WillOnce(Return(true));
642 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
643 .InSequence(s)
644 .WillOnce(Return(false));
645 EXPECT_CALL(mHwComposer,
646 setDisplayBrightness(DEFAULT_DISPLAY_ID, kDisplayBrightness,
647 Hwc2::Composer::DisplayBrightnessOptions{.applyImmediately =
648 false}))
649 .WillOnce(Return(ByMove(ftl::yield<status_t>(NO_ERROR))));
650
651 EXPECT_CALL(mHwComposer,
652 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Nair7234fa52022-02-24 14:07:11 -0800653 .WillOnce(testing::DoAll(testing::SetArgPointee<5>(mDeviceRequestedChanges),
654 Return(NO_ERROR)));
655 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
656 .Times(1);
657 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
658 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
659 .Times(1);
Alec Mouricdf16792021-12-10 13:16:06 -0800660 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
661
662 mDisplay->setNextBrightness(kDisplayBrightness);
Vishnu Nair7234fa52022-02-24 14:07:11 -0800663 chooseCompositionStrategy(mDisplay.get());
Alec Mouricdf16792021-12-10 13:16:06 -0800664
665 auto& state = mDisplay->getState();
666 EXPECT_FALSE(state.usesClientComposition);
667 EXPECT_TRUE(state.usesDeviceComposition);
668 EXPECT_FALSE(state.displayBrightness.has_value());
669}
670
Lloyd Pique66d68602019-02-13 14:23:31 -0800671TEST_F(DisplayChooseCompositionStrategyTest, normalOperationWithChanges) {
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700672 // Since two calls are made to anyLayersRequireClientComposition with different return
673 // values, use a Sequence to control the matching so the values are returned in a known
674 // order.
Lloyd Pique66d68602019-02-13 14:23:31 -0800675 Sequence s;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700676 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
677 .InSequence(s)
678 .WillOnce(Return(true));
679 EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition())
Lloyd Pique66d68602019-02-13 14:23:31 -0800680 .InSequence(s)
681 .WillOnce(Return(false));
682
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700683 EXPECT_CALL(mHwComposer,
Ady Abraham43065bd2021-12-10 17:22:15 -0800684 getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
Vishnu Nair7234fa52022-02-24 14:07:11 -0800685 .WillOnce(DoAll(SetArgPointee<5>(mDeviceRequestedChanges), Return(NO_ERROR)));
686 EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(mDeviceRequestedChanges.changedTypes))
687 .Times(1);
688 EXPECT_CALL(*mDisplay, applyDisplayRequests(mDeviceRequestedChanges.displayRequests)).Times(1);
689 EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(mDeviceRequestedChanges.layerRequests))
690 .Times(1);
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700691 EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800692
Vishnu Nair7234fa52022-02-24 14:07:11 -0800693 chooseCompositionStrategy(mDisplay.get());
Lloyd Pique66d68602019-02-13 14:23:31 -0800694
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700695 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800696 EXPECT_FALSE(state.usesClientComposition);
697 EXPECT_TRUE(state.usesDeviceComposition);
698}
699
700/*
Lloyd Pique688abd42019-02-15 15:42:24 -0800701 * Display::getSkipColorTransform()
702 */
703
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700704using DisplayGetSkipColorTransformTest = DisplayWithLayersTestCommon;
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500705using aidl::android::hardware::graphics::composer3::DisplayCapability;
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700706
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800707TEST_F(DisplayGetSkipColorTransformTest, checksCapabilityIfGpuDisplay) {
Ady Abrahamde549d42022-01-26 19:19:17 -0800708 EXPECT_CALL(mHwComposer, hasCapability(Capability::SKIP_CLIENT_COLOR_TRANSFORM))
Dominik Laskowski1162e472020-04-02 19:02:47 -0700709 .WillOnce(Return(true));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800710 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
711 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
712 EXPECT_TRUE(gpuDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800713}
714
Dominik Laskowski1162e472020-04-02 19:02:47 -0700715TEST_F(DisplayGetSkipColorTransformTest, checksDisplayCapability) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800716 EXPECT_CALL(mHwComposer,
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200717 hasDisplayCapability(HalDisplayId(DEFAULT_DISPLAY_ID),
Leon Scroggins III5967aec2021-12-29 11:14:22 -0500718 DisplayCapability::SKIP_CLIENT_COLOR_TRANSFORM))
Lloyd Pique688abd42019-02-15 15:42:24 -0800719 .WillOnce(Return(true));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700720 EXPECT_TRUE(mDisplay->getSkipColorTransform());
Lloyd Pique688abd42019-02-15 15:42:24 -0800721}
722
723/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800724 * Display::anyLayersRequireClientComposition()
725 */
726
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700727using DisplayAnyLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
728
729TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800730 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
731 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
732 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800733
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700734 EXPECT_FALSE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800735}
736
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700737TEST_F(DisplayAnyLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800738 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(false));
739 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800740
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700741 EXPECT_TRUE(mDisplay->anyLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800742}
743
744/*
745 * Display::allLayersRequireClientComposition()
746 */
747
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700748using DisplayAllLayersRequireClientCompositionTest = DisplayWithLayersTestCommon;
749
750TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsTrue) {
Lloyd Piquede196652020-01-22 17:29:58 -0800751 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
752 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(true));
753 EXPECT_CALL(*mLayer3.outputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Pique66d68602019-02-13 14:23:31 -0800754
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700755 EXPECT_TRUE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800756}
757
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700758TEST_F(DisplayAllLayersRequireClientCompositionTest, returnsFalse) {
Lloyd Piquede196652020-01-22 17:29:58 -0800759 EXPECT_CALL(*mLayer1.outputLayer, requiresClientComposition()).WillOnce(Return(true));
760 EXPECT_CALL(*mLayer2.outputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique66d68602019-02-13 14:23:31 -0800761
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700762 EXPECT_FALSE(mDisplay->allLayersRequireClientComposition());
Lloyd Pique66d68602019-02-13 14:23:31 -0800763}
764
765/*
766 * Display::applyChangedTypesToLayers()
767 */
768
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700769using DisplayApplyChangedTypesToLayersTest = DisplayWithLayersTestCommon;
770
771TEST_F(DisplayApplyChangedTypesToLayersTest, takesEarlyOutIfNoChangedLayers) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700772 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes());
Lloyd Pique66d68602019-02-13 14:23:31 -0800773}
774
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700775TEST_F(DisplayApplyChangedTypesToLayersTest, appliesChanges) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500776 EXPECT_CALL(*mLayer1.outputLayer, applyDeviceCompositionTypeChange(Composition::CLIENT))
Lloyd Pique66d68602019-02-13 14:23:31 -0800777 .Times(1);
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500778 EXPECT_CALL(*mLayer2.outputLayer, applyDeviceCompositionTypeChange(Composition::DEVICE))
Lloyd Pique66d68602019-02-13 14:23:31 -0800779 .Times(1);
780
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700781 mDisplay->applyChangedTypesToLayers(impl::Display::ChangedTypes{
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500782 {&mLayer1.hwc2Layer, Composition::CLIENT},
783 {&mLayer2.hwc2Layer, Composition::DEVICE},
784 {&hwc2LayerUnknown, Composition::SOLID_COLOR},
Lloyd Pique66d68602019-02-13 14:23:31 -0800785 });
786}
787
788/*
789 * Display::applyDisplayRequests()
790 */
791
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700792using DisplayApplyDisplayRequestsTest = DisplayWithLayersTestCommon;
793
794TEST_F(DisplayApplyDisplayRequestsTest, handlesNoRequests) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700795 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800796
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700797 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800798 EXPECT_FALSE(state.flipClientTarget);
799}
800
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700801TEST_F(DisplayApplyDisplayRequestsTest, handlesFlipClientTarget) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700802 mDisplay->applyDisplayRequests(hal::DisplayRequest::FLIP_CLIENT_TARGET);
Lloyd Pique66d68602019-02-13 14:23:31 -0800803
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700804 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800805 EXPECT_TRUE(state.flipClientTarget);
806}
807
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700808TEST_F(DisplayApplyDisplayRequestsTest, handlesWriteClientTargetToOutput) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700809 mDisplay->applyDisplayRequests(hal::DisplayRequest::WRITE_CLIENT_TARGET_TO_OUTPUT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800810
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700811 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800812 EXPECT_FALSE(state.flipClientTarget);
813}
814
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700815TEST_F(DisplayApplyDisplayRequestsTest, handlesAllRequestFlagsSet) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700816 mDisplay->applyDisplayRequests(static_cast<hal::DisplayRequest>(~0));
Lloyd Pique66d68602019-02-13 14:23:31 -0800817
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700818 auto& state = mDisplay->getState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800819 EXPECT_TRUE(state.flipClientTarget);
820}
821
822/*
823 * Display::applyLayerRequestsToLayers()
824 */
825
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700826using DisplayApplyLayerRequestsToLayersTest = DisplayWithLayersTestCommon;
827
828TEST_F(DisplayApplyLayerRequestsToLayersTest, preparesAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800829 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
830 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
831 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800832
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700833 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests());
Lloyd Pique66d68602019-02-13 14:23:31 -0800834}
835
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700836TEST_F(DisplayApplyLayerRequestsToLayersTest, appliesDeviceLayerRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -0800837 EXPECT_CALL(*mLayer1.outputLayer, prepareForDeviceLayerRequests()).Times(1);
838 EXPECT_CALL(*mLayer2.outputLayer, prepareForDeviceLayerRequests()).Times(1);
839 EXPECT_CALL(*mLayer3.outputLayer, prepareForDeviceLayerRequests()).Times(1);
Lloyd Pique66d68602019-02-13 14:23:31 -0800840
Lloyd Piquede196652020-01-22 17:29:58 -0800841 EXPECT_CALL(*mLayer1.outputLayer,
Lloyd Pique66d68602019-02-13 14:23:31 -0800842 applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET))
843 .Times(1);
844
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700845 mDisplay->applyLayerRequestsToLayers(impl::Display::LayerRequests{
Peiyong Line9d809e2020-04-14 13:10:48 -0700846 {&mLayer1.hwc2Layer, hal::LayerRequest::CLEAR_CLIENT_TARGET},
847 {&hwc2LayerUnknown, hal::LayerRequest::CLEAR_CLIENT_TARGET},
Lloyd Pique66d68602019-02-13 14:23:31 -0800848 });
849}
850
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800851/*
Ady Abraham0094dc62021-06-03 10:08:33 -0700852 * Display::applyClientTargetRequests()
853 */
854
855using DisplayApplyClientTargetRequests = DisplayWithLayersTestCommon;
856
857TEST_F(DisplayApplyLayerRequestsToLayersTest, applyClientTargetRequests) {
858 Display::ClientTargetProperty clientTargetProperty = {
859 .pixelFormat = hal::PixelFormat::RGB_565,
860 .dataspace = hal::Dataspace::STANDARD_BT470M,
861 };
862
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700863 static constexpr float kWhitePointNits = 800.f;
864
Ady Abraham0094dc62021-06-03 10:08:33 -0700865 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
866 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
867
868 EXPECT_CALL(*renderSurface, setBufferPixelFormat(clientTargetProperty.pixelFormat));
869 EXPECT_CALL(*renderSurface, setBufferDataspace(clientTargetProperty.dataspace));
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700870 mDisplay->applyClientTargetRequests(clientTargetProperty, kWhitePointNits);
Ady Abraham0094dc62021-06-03 10:08:33 -0700871
872 auto& state = mDisplay->getState();
873 EXPECT_EQ(clientTargetProperty.dataspace, state.dataspace);
Alec Mourif8d093d2022-02-10 15:16:59 -0800874 EXPECT_EQ(kWhitePointNits, state.clientTargetBrightness);
Ady Abraham0094dc62021-06-03 10:08:33 -0700875}
876
877/*
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800878 * Display::presentAndGetFrameFences()
879 */
880
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700881using DisplayPresentAndGetFrameFencesTest = DisplayWithLayersTestCommon;
882
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800883TEST_F(DisplayPresentAndGetFrameFencesTest, returnsNoFencesOnGpuDisplay) {
884 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
885 auto gpuDisplay{impl::createDisplay(mCompositionEngine, args)};
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800886
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800887 auto result = gpuDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800888
889 ASSERT_TRUE(result.presentFence.get());
890 EXPECT_FALSE(result.presentFence->isValid());
891 EXPECT_EQ(0u, result.layerFences.size());
892}
893
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700894TEST_F(DisplayPresentAndGetFrameFencesTest, returnsPresentAndLayerFences) {
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800895 sp<Fence> presentFence = new Fence();
896 sp<Fence> layer1Fence = new Fence();
897 sp<Fence> layer2Fence = new Fence();
898
Ady Abrahamec7aa8a2021-06-28 12:37:09 -0700899 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID), _, _))
Ady Abrahamb42cdc12021-05-11 14:31:26 -0700900 .Times(1);
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200901 EXPECT_CALL(mHwComposer, getPresentFence(HalDisplayId(DEFAULT_DISPLAY_ID)))
902 .WillOnce(Return(presentFence));
903 EXPECT_CALL(mHwComposer,
904 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer1.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800905 .WillOnce(Return(layer1Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200906 EXPECT_CALL(mHwComposer,
907 getLayerReleaseFence(HalDisplayId(DEFAULT_DISPLAY_ID), &mLayer2.hwc2Layer))
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800908 .WillOnce(Return(layer2Fence));
Marin Shalamanov0f10d0d2020-08-06 20:04:06 +0200909 EXPECT_CALL(mHwComposer, clearReleaseFences(HalDisplayId(DEFAULT_DISPLAY_ID))).Times(1);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800910
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700911 auto result = mDisplay->presentAndGetFrameFences();
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800912
913 EXPECT_EQ(presentFence, result.presentFence);
914
915 EXPECT_EQ(2u, result.layerFences.size());
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800916 ASSERT_EQ(1u, result.layerFences.count(&mLayer1.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800917 EXPECT_EQ(layer1Fence, result.layerFences[&mLayer1.hwc2Layer]);
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800918 ASSERT_EQ(1u, result.layerFences.count(&mLayer2.hwc2Layer));
Lloyd Piquede196652020-01-22 17:29:58 -0800919 EXPECT_EQ(layer2Fence, result.layerFences[&mLayer2.hwc2Layer]);
Lloyd Pique35fca9d2019-02-13 14:24:11 -0800920}
921
Lloyd Pique688abd42019-02-15 15:42:24 -0800922/*
923 * Display::setExpensiveRenderingExpected()
924 */
925
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700926using DisplaySetExpensiveRenderingExpectedTest = DisplayWithLayersTestCommon;
927
928TEST_F(DisplaySetExpensiveRenderingExpectedTest, forwardsToPowerAdvisor) {
Lloyd Pique688abd42019-02-15 15:42:24 -0800929 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, true)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700930 mDisplay->setExpensiveRenderingExpected(true);
Lloyd Pique688abd42019-02-15 15:42:24 -0800931
932 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false)).Times(1);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700933 mDisplay->setExpensiveRenderingExpected(false);
Lloyd Pique688abd42019-02-15 15:42:24 -0800934}
935
Lloyd Piqued3d69882019-02-28 16:03:46 -0800936/*
937 * Display::finishFrame()
938 */
939
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700940using DisplayFinishFrameTest = DisplayWithLayersTestCommon;
941
942TEST_F(DisplayFinishFrameTest, doesNotSkipCompositionIfNotDirtyOnHwcDisplay) {
Lloyd Piqued3d69882019-02-28 16:03:46 -0800943 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700944 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800945
946 // We expect no calls to queueBuffer if composition was skipped.
947 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
948
Lloyd Piquea76ce462020-01-14 13:06:37 -0800949 // Expect a call to signal no expensive rendering since there is no client composition.
950 EXPECT_CALL(mPowerAdvisor, setExpensiveRenderingExpected(DEFAULT_DISPLAY_ID, false));
951
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700952 mDisplay->editState().isEnabled = true;
953 mDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000954 mDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700955 mDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800956
Vishnu Nair7234fa52022-02-24 14:07:11 -0800957 mDisplay->finishFrame({}, std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800958}
959
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700960TEST_F(DisplayFinishFrameTest, skipsCompositionIfNotDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800961 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
962 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800963
964 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800965 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800966
967 // We expect no calls to queueBuffer if composition was skipped.
968 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(0);
969
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800970 gpuDisplay->editState().isEnabled = true;
971 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000972 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800973 gpuDisplay->editState().dirtyRegion = Region::INVALID_REGION;
Lloyd Piqued3d69882019-02-28 16:03:46 -0800974
Vishnu Nair7234fa52022-02-24 14:07:11 -0800975 gpuDisplay->finishFrame({}, std::move(mResultWithoutBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800976}
977
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -0700978TEST_F(DisplayFinishFrameTest, performsCompositionIfDirty) {
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800979 auto args = getDisplayCreationArgsForGpuVirtualDisplay();
980 std::shared_ptr<impl::Display> gpuDisplay = impl::createDisplay(mCompositionEngine, args);
Lloyd Piqued3d69882019-02-28 16:03:46 -0800981
982 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800983 gpuDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800984
985 // We expect a single call to queueBuffer when composition is not skipped.
986 EXPECT_CALL(*renderSurface, queueBuffer(_)).Times(1);
987
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800988 gpuDisplay->editState().isEnabled = true;
989 gpuDisplay->editState().usesClientComposition = false;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000990 gpuDisplay->editState().layerStackSpace.setContent(Rect(0, 0, 1, 1));
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800991 gpuDisplay->editState().dirtyRegion = Region(Rect(0, 0, 1, 1));
Vishnu Nair7234fa52022-02-24 14:07:11 -0800992 gpuDisplay->finishFrame({}, std::move(mResultWithBuffer));
Lloyd Piqued3d69882019-02-28 16:03:46 -0800993}
994
Lloyd Piquec6607552019-12-02 17:57:39 -0800995/*
996 * Display functional tests
997 */
998
999struct DisplayFunctionalTest : public testing::Test {
1000 class Display : public impl::Display {
1001 public:
Lloyd Piquec6607552019-12-02 17:57:39 -08001002 using impl::Display::injectOutputLayerForTest;
1003 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
1004 };
1005
Lloyd Piquec6607552019-12-02 17:57:39 -08001006 DisplayFunctionalTest() {
1007 EXPECT_CALL(mCompositionEngine, getHwComposer()).WillRepeatedly(ReturnRef(mHwComposer));
Kriti Dang646f8ec2022-01-18 14:35:02 +01001008 mDisplay = createDisplay();
1009 mRenderSurface = createRenderSurface();
Lloyd Piquec6607552019-12-02 17:57:39 -08001010 mDisplay->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1011 }
1012
1013 NiceMock<android::mock::HWComposer> mHwComposer;
1014 NiceMock<Hwc2::mock::PowerAdvisor> mPowerAdvisor;
1015 NiceMock<mock::CompositionEngine> mCompositionEngine;
1016 sp<mock::NativeWindow> mNativeWindow = new NiceMock<mock::NativeWindow>();
1017 sp<mock::DisplaySurface> mDisplaySurface = new NiceMock<mock::DisplaySurface>();
Kriti Dang646f8ec2022-01-18 14:35:02 +01001018 std::shared_ptr<Display> mDisplay;
1019 impl::RenderSurface* mRenderSurface;
Dominik Laskowski3dce4f42021-03-08 20:48:28 -08001020
Kriti Dang646f8ec2022-01-18 14:35:02 +01001021 std::shared_ptr<Display> createDisplay() {
1022 return impl::createDisplayTemplated<Display>(mCompositionEngine,
1023 DisplayCreationArgsBuilder()
1024 .setId(DEFAULT_DISPLAY_ID)
1025 .setPixels(DEFAULT_RESOLUTION)
1026 .setIsSecure(true)
1027 .setPowerAdvisor(&mPowerAdvisor)
1028 .build());
1029 ;
1030 }
Lloyd Piqueaad4ebf2019-10-03 17:58:30 -07001031
Kriti Dang646f8ec2022-01-18 14:35:02 +01001032 impl::RenderSurface* createRenderSurface() {
1033 return new impl::RenderSurface{mCompositionEngine, *mDisplay,
1034 RenderSurfaceCreationArgsBuilder()
1035 .setDisplayWidth(DEFAULT_RESOLUTION.width)
1036 .setDisplayHeight(DEFAULT_RESOLUTION.height)
1037 .setNativeWindow(mNativeWindow)
1038 .setDisplaySurface(mDisplaySurface)
1039 .build()};
1040 }
Lloyd Piquec6607552019-12-02 17:57:39 -08001041};
1042
1043TEST_F(DisplayFunctionalTest, postFramebufferCriticalCallsAreOrdered) {
1044 InSequence seq;
1045
1046 mDisplay->editState().isEnabled = true;
1047
Ady Abrahamec7aa8a2021-06-28 12:37:09 -07001048 EXPECT_CALL(mHwComposer, presentAndGetReleaseFences(_, _, _));
Lloyd Piquec6607552019-12-02 17:57:39 -08001049 EXPECT_CALL(*mDisplaySurface, onFrameCommitted());
1050
1051 mDisplay->postFramebuffer();
1052}
1053
Lloyd Pique45a165a2018-10-19 11:54:47 -07001054} // namespace
1055} // namespace android::compositionengine