blob: 8a45f17e2f1ae7617a3860791909583bdc5d014d [file] [log] [blame]
Lloyd Pique4603f3c2020-02-11 12:06:56 -08001/*
2 * Copyright 2020 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
17// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
21#undef LOG_TAG
22#define LOG_TAG "LibSurfaceFlingerUnittests"
23
24#include <vector>
25
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070026// StrictMock<T> derives from T and is not marked final, so the destructor of T is expected to be
27// virtual in case StrictMock<T> is used as a polymorphic base class. That is not the case here.
28#pragma clang diagnostic push
29#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080030#include <gmock/gmock.h>
Dominik Laskowski8b01cc02020-07-14 19:02:41 -070031#pragma clang diagnostic pop
32
Lloyd Pique4603f3c2020-02-11 12:06:56 -080033#include <gui/LayerMetadata.h>
34#include <log/log.h>
35
Marin Shalamanov23c44202020-12-22 19:09:20 +010036#include "DisplayHardware/DisplayMode.h"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080037#include "DisplayHardware/HWComposer.h"
Marin Shalamanov12c9e5a2021-01-07 00:25:35 +010038#include "DisplayHardware/Hal.h"
Alec Mouriff793872022-01-13 17:45:06 -080039#include "DisplayIdentificationTestHelpers.h"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080040#include "mock/DisplayHardware/MockComposer.h"
Lloyd Piquea516c002021-05-07 14:36:58 -070041#include "mock/DisplayHardware/MockHWC2.h"
Lloyd Pique4603f3c2020-02-11 12:06:56 -080042
43// TODO(b/129481165): remove the #pragma below and fix conversion issues
44#pragma clang diagnostic pop // ignored "-Wconversion"
45
46namespace android {
47namespace {
48
Marin Shalamanov6e840172020-12-14 22:13:28 +010049namespace V2_1 = hardware::graphics::composer::V2_1;
50namespace V2_4 = hardware::graphics::composer::V2_4;
Ady Abrahamde549d42022-01-26 19:19:17 -080051namespace aidl = aidl::android::hardware::graphics::composer3;
Marin Shalamanov6e840172020-12-14 22:13:28 +010052
53using Hwc2::Config;
Peiyong Line9d809e2020-04-14 13:10:48 -070054
ramindani12bfe6b2023-02-03 13:29:19 -080055using ::aidl::android::hardware::graphics::composer3::RefreshRateChangedDebugData;
ramindani0cd1d8d2023-06-13 13:43:23 -070056using hal::IComposerClient;
Lloyd Pique4603f3c2020-02-11 12:06:56 -080057using ::testing::_;
58using ::testing::DoAll;
59using ::testing::ElementsAreArray;
60using ::testing::Return;
61using ::testing::SetArgPointee;
62using ::testing::StrictMock;
63
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070064struct HWComposerTest : testing::Test {
65 using HalError = hardware::graphics::composer::V2_1::Error;
Marin Shalamanov8b196592021-08-09 16:24:42 +020066
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070067 Hwc2::mock::Composer* const mHal = new StrictMock<Hwc2::mock::Composer>();
68 impl::HWComposer mHwc{std::unique_ptr<Hwc2::Composer>(mHal)};
Marin Shalamanov8b196592021-08-09 16:24:42 +020069
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070070 void expectHotplugConnect(hal::HWDisplayId hwcDisplayId) {
71 constexpr uint8_t kPort = 255;
72 EXPECT_CALL(*mHal, getDisplayIdentificationData(hwcDisplayId, _, _))
73 .WillOnce(DoAll(SetArgPointee<1>(kPort),
74 SetArgPointee<2>(getExternalEdid()), Return(HalError::NONE)));
Marin Shalamanov8b196592021-08-09 16:24:42 +020075
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070076 EXPECT_CALL(*mHal, setClientTargetSlotCount(_));
77 EXPECT_CALL(*mHal, setVsyncEnabled(hwcDisplayId, Hwc2::IComposerClient::Vsync::DISABLE));
Leon Scroggins IIIe24d78f2022-09-20 16:38:19 -040078 EXPECT_CALL(*mHal, onHotplugConnect(hwcDisplayId));
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070079 }
80};
Marin Shalamanov8b196592021-08-09 16:24:42 +020081
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070082TEST_F(HWComposerTest, isHeadless) {
83 ASSERT_TRUE(mHwc.isHeadless());
84
85 constexpr hal::HWDisplayId kHwcDisplayId = 1;
86 expectHotplugConnect(kHwcDisplayId);
87
88 const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED);
Marin Shalamanov8b196592021-08-09 16:24:42 +020089 ASSERT_TRUE(info);
Marin Shalamanov8b196592021-08-09 16:24:42 +020090
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -070091 ASSERT_FALSE(mHwc.isHeadless());
92
93 mHwc.disconnectDisplay(info->id);
94 ASSERT_TRUE(mHwc.isHeadless());
95}
96
97TEST_F(HWComposerTest, getActiveMode) {
98 // Unknown display.
99 EXPECT_EQ(mHwc.getActiveMode(PhysicalDisplayId::fromPort(0)), std::nullopt);
100
101 constexpr hal::HWDisplayId kHwcDisplayId = 2;
102 expectHotplugConnect(kHwcDisplayId);
103
104 const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED);
105 ASSERT_TRUE(info);
106
107 {
108 // Display is known to SF but not HWC, e.g. the hotplug disconnect is pending.
109 EXPECT_CALL(*mHal, getActiveConfig(kHwcDisplayId, _))
110 .WillOnce(Return(HalError::BAD_DISPLAY));
111
112 EXPECT_EQ(mHwc.getActiveMode(info->id), std::nullopt);
113 }
114 {
115 constexpr hal::HWConfigId kConfigId = 42;
116 EXPECT_CALL(*mHal, getActiveConfig(kHwcDisplayId, _))
117 .WillOnce(DoAll(SetArgPointee<1>(kConfigId), Return(HalError::NONE)));
118
119 EXPECT_EQ(mHwc.getActiveMode(info->id), kConfigId);
120 }
Marin Shalamanov8b196592021-08-09 16:24:42 +0200121}
122
ramindani0cd1d8d2023-06-13 13:43:23 -0700123TEST_F(HWComposerTest, getModesWithLegacyDisplayConfigs) {
124 constexpr hal::HWDisplayId kHwcDisplayId = 2;
125 constexpr hal::HWConfigId kConfigId = 42;
ramindani263a3f12023-07-18 20:44:49 -0700126 constexpr int32_t kMaxFrameIntervalNs = 50000000; // 20Fps
ramindani0cd1d8d2023-06-13 13:43:23 -0700127
128 expectHotplugConnect(kHwcDisplayId);
129 const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED);
130 ASSERT_TRUE(info);
131
132 EXPECT_CALL(*mHal, getDisplayConfigurationsSupported()).WillRepeatedly(Return(false));
133
134 {
135 EXPECT_CALL(*mHal, getDisplayConfigs(kHwcDisplayId, _))
136 .WillOnce(Return(HalError::BAD_DISPLAY));
ramindani263a3f12023-07-18 20:44:49 -0700137 EXPECT_TRUE(mHwc.getModes(info->id, kMaxFrameIntervalNs).empty());
ramindani0cd1d8d2023-06-13 13:43:23 -0700138 }
139 {
140 constexpr int32_t kWidth = 480;
141 constexpr int32_t kHeight = 720;
142 constexpr int32_t kConfigGroup = 1;
143 constexpr int32_t kVsyncPeriod = 16666667;
144
145 EXPECT_CALL(*mHal,
146 getDisplayAttribute(kHwcDisplayId, kConfigId, IComposerClient::Attribute::WIDTH,
147 _))
148 .WillRepeatedly(DoAll(SetArgPointee<3>(kWidth), Return(HalError::NONE)));
149 EXPECT_CALL(*mHal,
150 getDisplayAttribute(kHwcDisplayId, kConfigId,
151 IComposerClient::Attribute::HEIGHT, _))
152 .WillRepeatedly(DoAll(SetArgPointee<3>(kHeight), Return(HalError::NONE)));
153 EXPECT_CALL(*mHal,
154 getDisplayAttribute(kHwcDisplayId, kConfigId,
155 IComposerClient::Attribute::CONFIG_GROUP, _))
156 .WillRepeatedly(DoAll(SetArgPointee<3>(kConfigGroup), Return(HalError::NONE)));
157 EXPECT_CALL(*mHal,
158 getDisplayAttribute(kHwcDisplayId, kConfigId,
159 IComposerClient::Attribute::VSYNC_PERIOD, _))
160 .WillRepeatedly(DoAll(SetArgPointee<3>(kVsyncPeriod), Return(HalError::NONE)));
161
162 // Optional Parameters UNSUPPORTED
163 EXPECT_CALL(*mHal,
164 getDisplayAttribute(kHwcDisplayId, kConfigId, IComposerClient::Attribute::DPI_X,
165 _))
166 .WillOnce(Return(HalError::UNSUPPORTED));
167 EXPECT_CALL(*mHal,
168 getDisplayAttribute(kHwcDisplayId, kConfigId, IComposerClient::Attribute::DPI_Y,
169 _))
170 .WillOnce(Return(HalError::UNSUPPORTED));
171
172 EXPECT_CALL(*mHal, getDisplayConfigs(kHwcDisplayId, _))
173 .WillRepeatedly(DoAll(SetArgPointee<1>(std::vector<hal::HWConfigId>{kConfigId}),
174 Return(HalError::NONE)));
175
ramindani263a3f12023-07-18 20:44:49 -0700176 auto modes = mHwc.getModes(info->id, kMaxFrameIntervalNs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700177 EXPECT_EQ(modes.size(), size_t{1});
178 EXPECT_EQ(modes.front().hwcId, kConfigId);
179 EXPECT_EQ(modes.front().width, kWidth);
180 EXPECT_EQ(modes.front().height, kHeight);
181 EXPECT_EQ(modes.front().configGroup, kConfigGroup);
182 EXPECT_EQ(modes.front().vsyncPeriod, kVsyncPeriod);
183 EXPECT_EQ(modes.front().dpiX, -1);
184 EXPECT_EQ(modes.front().dpiY, -1);
185
186 // Optional parameters are supported
187 constexpr int32_t kDpi = 320;
188 EXPECT_CALL(*mHal,
189 getDisplayAttribute(kHwcDisplayId, kConfigId, IComposerClient::Attribute::DPI_X,
190 _))
191 .WillOnce(DoAll(SetArgPointee<3>(kDpi), Return(HalError::NONE)));
192 EXPECT_CALL(*mHal,
193 getDisplayAttribute(kHwcDisplayId, kConfigId, IComposerClient::Attribute::DPI_Y,
194 _))
195 .WillOnce(DoAll(SetArgPointee<3>(kDpi), Return(HalError::NONE)));
196
ramindani263a3f12023-07-18 20:44:49 -0700197 modes = mHwc.getModes(info->id, kMaxFrameIntervalNs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700198 EXPECT_EQ(modes.size(), size_t{1});
199 EXPECT_EQ(modes.front().hwcId, kConfigId);
200 EXPECT_EQ(modes.front().width, kWidth);
201 EXPECT_EQ(modes.front().height, kHeight);
202 EXPECT_EQ(modes.front().configGroup, kConfigGroup);
203 EXPECT_EQ(modes.front().vsyncPeriod, kVsyncPeriod);
204 // DPI values are scaled by 1000 in the legacy implementation.
205 EXPECT_EQ(modes.front().dpiX, kDpi / 1000.f);
206 EXPECT_EQ(modes.front().dpiY, kDpi / 1000.f);
207 }
208}
209
210TEST_F(HWComposerTest, getModesWithDisplayConfigurations) {
211 constexpr hal::HWDisplayId kHwcDisplayId = 2;
212 constexpr hal::HWConfigId kConfigId = 42;
ramindani263a3f12023-07-18 20:44:49 -0700213 constexpr int32_t kMaxFrameIntervalNs = 50000000; // 20Fps
ramindani0cd1d8d2023-06-13 13:43:23 -0700214 expectHotplugConnect(kHwcDisplayId);
215 const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED);
216 ASSERT_TRUE(info);
217
218 EXPECT_CALL(*mHal, getDisplayConfigurationsSupported()).WillRepeatedly(Return(true));
219
220 {
ramindani263a3f12023-07-18 20:44:49 -0700221 EXPECT_CALL(*mHal, getDisplayConfigurations(kHwcDisplayId, _, _))
ramindani0cd1d8d2023-06-13 13:43:23 -0700222 .WillOnce(Return(HalError::BAD_DISPLAY));
ramindani263a3f12023-07-18 20:44:49 -0700223 EXPECT_TRUE(mHwc.getModes(info->id, kMaxFrameIntervalNs).empty());
ramindani0cd1d8d2023-06-13 13:43:23 -0700224 }
225 {
226 constexpr int32_t kWidth = 480;
227 constexpr int32_t kHeight = 720;
228 constexpr int32_t kConfigGroup = 1;
229 constexpr int32_t kVsyncPeriod = 16666667;
230 hal::DisplayConfiguration displayConfiguration;
231 displayConfiguration.configId = kConfigId;
232 displayConfiguration.configGroup = kConfigGroup;
233 displayConfiguration.height = kHeight;
234 displayConfiguration.width = kWidth;
235 displayConfiguration.vsyncPeriod = kVsyncPeriod;
236
ramindani263a3f12023-07-18 20:44:49 -0700237 EXPECT_CALL(*mHal, getDisplayConfigurations(kHwcDisplayId, _, _))
238 .WillOnce(DoAll(SetArgPointee<2>(std::vector<hal::DisplayConfiguration>{
ramindani0cd1d8d2023-06-13 13:43:23 -0700239 displayConfiguration}),
240 Return(HalError::NONE)));
241
242 // Optional dpi not supported
ramindani263a3f12023-07-18 20:44:49 -0700243 auto modes = mHwc.getModes(info->id, kMaxFrameIntervalNs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700244 EXPECT_EQ(modes.size(), size_t{1});
245 EXPECT_EQ(modes.front().hwcId, kConfigId);
246 EXPECT_EQ(modes.front().width, kWidth);
247 EXPECT_EQ(modes.front().height, kHeight);
248 EXPECT_EQ(modes.front().configGroup, kConfigGroup);
249 EXPECT_EQ(modes.front().vsyncPeriod, kVsyncPeriod);
250 EXPECT_EQ(modes.front().dpiX, -1);
251 EXPECT_EQ(modes.front().dpiY, -1);
252
253 // Supports optional dpi parameter
254 constexpr int32_t kDpi = 320;
255 displayConfiguration.dpi = {kDpi, kDpi};
256
ramindani263a3f12023-07-18 20:44:49 -0700257 EXPECT_CALL(*mHal, getDisplayConfigurations(kHwcDisplayId, _, _))
258 .WillOnce(DoAll(SetArgPointee<2>(std::vector<hal::DisplayConfiguration>{
ramindani0cd1d8d2023-06-13 13:43:23 -0700259 displayConfiguration}),
260 Return(HalError::NONE)));
261
ramindani263a3f12023-07-18 20:44:49 -0700262 modes = mHwc.getModes(info->id, kMaxFrameIntervalNs);
ramindani0cd1d8d2023-06-13 13:43:23 -0700263 EXPECT_EQ(modes.size(), size_t{1});
264 EXPECT_EQ(modes.front().hwcId, kConfigId);
265 EXPECT_EQ(modes.front().width, kWidth);
266 EXPECT_EQ(modes.front().height, kHeight);
267 EXPECT_EQ(modes.front().configGroup, kConfigGroup);
268 EXPECT_EQ(modes.front().vsyncPeriod, kVsyncPeriod);
269 EXPECT_EQ(modes.front().dpiX, kDpi);
270 EXPECT_EQ(modes.front().dpiY, kDpi);
271 }
272}
273
Leon Scroggins III959a7ff2023-02-07 11:24:25 -0500274TEST_F(HWComposerTest, onVsync) {
275 constexpr hal::HWDisplayId kHwcDisplayId = 1;
276 expectHotplugConnect(kHwcDisplayId);
277
278 const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED);
279 ASSERT_TRUE(info);
280
281 const auto physicalDisplayId = info->id;
282
283 // Deliberately chosen not to match DisplayData.lastPresentTimestamp's
284 // initial value.
285 constexpr nsecs_t kTimestamp = 1;
286 auto displayIdOpt = mHwc.onVsync(kHwcDisplayId, kTimestamp);
287 ASSERT_TRUE(displayIdOpt);
288 EXPECT_EQ(physicalDisplayId, displayIdOpt);
289
290 // Attempt to send the same time stamp again.
291 displayIdOpt = mHwc.onVsync(kHwcDisplayId, kTimestamp);
292 EXPECT_FALSE(displayIdOpt);
293}
294
295TEST_F(HWComposerTest, onVsyncInvalid) {
296 constexpr hal::HWDisplayId kInvalidHwcDisplayId = 2;
297 constexpr nsecs_t kTimestamp = 1;
298 const auto displayIdOpt = mHwc.onVsync(kInvalidHwcDisplayId, kTimestamp);
299 EXPECT_FALSE(displayIdOpt);
300}
301
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700302struct MockHWC2ComposerCallback final : StrictMock<HWC2::ComposerCallback> {
Dominik Laskowski0deb06e2021-04-16 23:18:31 -0700303 MOCK_METHOD2(onComposerHalHotplug, void(hal::HWDisplayId, hal::Connection));
304 MOCK_METHOD1(onComposerHalRefresh, void(hal::HWDisplayId));
305 MOCK_METHOD3(onComposerHalVsync,
306 void(hal::HWDisplayId, int64_t timestamp, std::optional<hal::VsyncPeriodNanos>));
307 MOCK_METHOD2(onComposerHalVsyncPeriodTimingChanged,
308 void(hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline&));
309 MOCK_METHOD1(onComposerHalSeamlessPossible, void(hal::HWDisplayId));
Yichi Chen1a417af2022-01-21 15:29:52 +0800310 MOCK_METHOD1(onComposerHalVsyncIdle, void(hal::HWDisplayId));
ramindani12bfe6b2023-02-03 13:29:19 -0800311 MOCK_METHOD(void, onRefreshRateChangedDebug, (const RefreshRateChangedDebugData&), (override));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800312};
313
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -0700314struct HWComposerSetCallbackTest : HWComposerTest {
Dominik Laskowski8b01cc02020-07-14 19:02:41 -0700315 MockHWC2ComposerCallback mCallback;
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800316};
317
Dominik Laskowski0deb06e2021-04-16 23:18:31 -0700318TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) {
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800319 const std::string kMetadata1Name = "com.example.metadata.1";
320 constexpr bool kMetadata1Mandatory = false;
321 const std::string kMetadata2Name = "com.example.metadata.2";
322 constexpr bool kMetadata2Mandatory = true;
323
Ady Abrahamde549d42022-01-26 19:19:17 -0800324 EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<aidl::Capability>{}));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800325 EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
Peiyong Line9d809e2020-04-14 13:10:48 -0700326 .WillOnce(DoAll(SetArgPointee<0>(std::vector<hal::LayerGenericMetadataKey>{
327 {kMetadata1Name, kMetadata1Mandatory},
328 {kMetadata2Name, kMetadata2Mandatory},
329 }),
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800330 Return(hardware::graphics::composer::V2_4::Error::NONE)));
Sally Qibb866c12022-10-17 11:31:20 -0700331 EXPECT_CALL(*mHal, getOverlaySupport(_)).WillOnce(Return(HalError::NONE));
Kriti Dang674b9372022-11-18 10:58:44 +0100332 EXPECT_CALL(*mHal, getHdrConversionCapabilities(_)).WillOnce(Return(HalError::NONE));
Sally Qibb866c12022-10-17 11:31:20 -0700333
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800334 EXPECT_CALL(*mHal, registerCallback(_));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800335
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -0700336 mHwc.setCallback(mCallback);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800337
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -0700338 const auto& supported = mHwc.getSupportedLayerGenericMetadata();
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800339 EXPECT_EQ(2u, supported.size());
340 EXPECT_EQ(1u, supported.count(kMetadata1Name));
341 EXPECT_EQ(kMetadata1Mandatory, supported.find(kMetadata1Name)->second);
342 EXPECT_EQ(1u, supported.count(kMetadata2Name));
343 EXPECT_EQ(kMetadata2Mandatory, supported.find(kMetadata2Name)->second);
344}
345
Dominik Laskowski0deb06e2021-04-16 23:18:31 -0700346TEST_F(HWComposerSetCallbackTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) {
Ady Abrahamde549d42022-01-26 19:19:17 -0800347 EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<aidl::Capability>{}));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800348 EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_))
349 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
Sally Qibb866c12022-10-17 11:31:20 -0700350 EXPECT_CALL(*mHal, getOverlaySupport(_)).WillOnce(Return(HalError::UNSUPPORTED));
Kriti Dang674b9372022-11-18 10:58:44 +0100351 EXPECT_CALL(*mHal, getHdrConversionCapabilities(_)).WillOnce(Return(HalError::UNSUPPORTED));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800352 EXPECT_CALL(*mHal, registerCallback(_));
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800353
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -0700354 mHwc.setCallback(mCallback);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800355
Dominik Laskowskie2c5b0a2022-08-10 14:53:53 -0700356 const auto& supported = mHwc.getSupportedLayerGenericMetadata();
357 EXPECT_TRUE(supported.empty());
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800358}
359
360struct HWComposerLayerTest : public testing::Test {
Peiyong Line9d809e2020-04-14 13:10:48 -0700361 static constexpr hal::HWDisplayId kDisplayId = static_cast<hal::HWDisplayId>(1001);
362 static constexpr hal::HWLayerId kLayerId = static_cast<hal::HWLayerId>(1002);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800363
Ady Abrahamde549d42022-01-26 19:19:17 -0800364 HWComposerLayerTest(const std::unordered_set<aidl::Capability>& capabilities)
Lloyd Piquea516c002021-05-07 14:36:58 -0700365 : mCapabilies(capabilities) {
366 EXPECT_CALL(mDisplay, getId()).WillRepeatedly(Return(kDisplayId));
367 }
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800368
Lloyd Piquea516c002021-05-07 14:36:58 -0700369 ~HWComposerLayerTest() override {
370 EXPECT_CALL(mDisplay, onLayerDestroyed(kLayerId));
371 EXPECT_CALL(*mHal, destroyLayer(kDisplayId, kLayerId));
372 }
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800373
374 std::unique_ptr<Hwc2::mock::Composer> mHal{new StrictMock<Hwc2::mock::Composer>()};
Ady Abrahamde549d42022-01-26 19:19:17 -0800375 const std::unordered_set<aidl::Capability> mCapabilies;
Lloyd Piquea516c002021-05-07 14:36:58 -0700376 StrictMock<HWC2::mock::Display> mDisplay;
377 HWC2::impl::Layer mLayer{*mHal, mCapabilies, mDisplay, kLayerId};
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800378};
379
380struct HWComposerLayerGenericMetadataTest : public HWComposerLayerTest {
381 static const std::string kLayerGenericMetadata1Name;
382 static constexpr bool kLayerGenericMetadata1Mandatory = false;
383 static const std::vector<uint8_t> kLayerGenericMetadata1Value;
384 static const std::string kLayerGenericMetadata2Name;
385 static constexpr bool kLayerGenericMetadata2Mandatory = true;
386 static const std::vector<uint8_t> kLayerGenericMetadata2Value;
387
388 HWComposerLayerGenericMetadataTest() : HWComposerLayerTest({}) {}
389};
390
391const std::string HWComposerLayerGenericMetadataTest::kLayerGenericMetadata1Name =
392 "com.example.metadata.1";
393
394const std::vector<uint8_t> HWComposerLayerGenericMetadataTest::kLayerGenericMetadata1Value = {1u,
395 2u,
396 3u};
397
398const std::string HWComposerLayerGenericMetadataTest::kLayerGenericMetadata2Name =
399 "com.example.metadata.2";
400
401const std::vector<uint8_t> HWComposerLayerGenericMetadataTest::kLayerGenericMetadata2Value = {45u,
402 67u};
403
404TEST_F(HWComposerLayerGenericMetadataTest, forwardsSupportedMetadata) {
405 EXPECT_CALL(*mHal,
406 setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata1Name,
407 kLayerGenericMetadata1Mandatory,
408 kLayerGenericMetadata1Value))
409 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::NONE));
410 auto result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata1Name,
411 kLayerGenericMetadata1Mandatory,
412 kLayerGenericMetadata1Value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700413 EXPECT_EQ(hal::Error::NONE, result);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800414
415 EXPECT_CALL(*mHal,
416 setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata2Name,
417 kLayerGenericMetadata2Mandatory,
418 kLayerGenericMetadata2Value))
419 .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED));
420 result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata2Name,
421 kLayerGenericMetadata2Mandatory,
422 kLayerGenericMetadata2Value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700423 EXPECT_EQ(hal::Error::UNSUPPORTED, result);
Lloyd Pique4603f3c2020-02-11 12:06:56 -0800424}
425
426} // namespace
Dominik Laskowski3dce4f42021-03-08 20:48:28 -0800427} // namespace android