1 /**
2 * Copyright (c) 2022, 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 #include <aidl/Gtest.h>
18 #include <aidl/Vintf.h>
19 #include <aidl/android/hardware/graphics/common/BlendMode.h>
20 #include <aidl/android/hardware/graphics/common/BufferUsage.h>
21 #include <aidl/android/hardware/graphics/common/FRect.h>
22 #include <aidl/android/hardware/graphics/common/PixelFormat.h>
23 #include <aidl/android/hardware/graphics/common/Rect.h>
24 #include <aidl/android/hardware/graphics/composer3/Composition.h>
25 #include <aidl/android/hardware/graphics/composer3/IComposer.h>
26 #include <android-base/properties.h>
27 #include <android/binder_process.h>
28 #include <android/hardware/graphics/composer3/ComposerClientReader.h>
29 #include <android/hardware/graphics/composer3/ComposerClientWriter.h>
30 #include <binder/ProcessState.h>
31 #include <cutils/ashmem.h>
32 #include <gmock/gmock.h>
33 #include <gtest/gtest.h>
34 #include <ui/Fence.h>
35 #include <ui/GraphicBuffer.h>
36 #include <ui/PixelFormat.h>
37 #include <algorithm>
38 #include <iterator>
39 #include <mutex>
40 #include <numeric>
41 #include <string>
42 #include <thread>
43 #include <unordered_map>
44 #include "ComposerClientWrapper.h"
45 #include "GraphicsComposerCallback.h"
46
47 #undef LOG_TAG
48 #define LOG_TAG "VtsHalGraphicsComposer3_TargetTest"
49
50 using testing::Ge;
51
52 namespace aidl::android::hardware::graphics::composer3::vts {
53
54 using namespace std::chrono_literals;
55 using namespace aidl::android::hardware::graphics::composer3::libhwc_aidl_test;
56
57 using ::android::GraphicBuffer;
58 using ::android::sp;
59
60 class GraphicsComposerAidlTest : public ::testing::TestWithParam<std::string> {
61 protected:
SetUp()62 void SetUp() override {
63 mComposerClient = std::make_unique<ComposerClientWrapper>(GetParam());
64 ASSERT_TRUE(mComposerClient->createClient().isOk());
65
66 const auto& [status, displays] = mComposerClient->getDisplays();
67 ASSERT_TRUE(status.isOk());
68 mDisplays = displays;
69
70 // explicitly disable vsync
71 for (const auto& display : mDisplays) {
72 EXPECT_TRUE(mComposerClient->setVsync(display.getDisplayId(), false).isOk());
73 }
74 mComposerClient->setVsyncAllowed(false);
75 }
76
TearDown()77 void TearDown() override {
78 ASSERT_TRUE(
79 mComposerClient->tearDown(std::unordered_map<int64_t, ComposerClientWriter*>{}));
80 mComposerClient.reset();
81 }
82
assertServiceSpecificError(const ScopedAStatus & status,int32_t serviceSpecificError)83 void assertServiceSpecificError(const ScopedAStatus& status, int32_t serviceSpecificError) {
84 ASSERT_EQ(status.getExceptionCode(), EX_SERVICE_SPECIFIC);
85 ASSERT_EQ(status.getServiceSpecificError(), serviceSpecificError);
86 }
87
Test_setContentTypeForDisplay(int64_t display,const std::vector<ContentType> & supportedContentTypes,ContentType contentType,const char * contentTypeStr)88 void Test_setContentTypeForDisplay(int64_t display,
89 const std::vector<ContentType>& supportedContentTypes,
90 ContentType contentType, const char* contentTypeStr) {
91 const bool contentTypeSupport =
92 std::find(supportedContentTypes.begin(), supportedContentTypes.end(),
93 contentType) != supportedContentTypes.end();
94
95 if (!contentTypeSupport) {
96 const auto& status = mComposerClient->setContentType(display, contentType);
97 EXPECT_FALSE(status.isOk());
98 EXPECT_NO_FATAL_FAILURE(
99 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
100 GTEST_SUCCEED() << contentTypeStr << " content type is not supported on display "
101 << std::to_string(display) << ", skipping test";
102 return;
103 }
104
105 EXPECT_TRUE(mComposerClient->setContentType(display, contentType).isOk());
106 EXPECT_TRUE(mComposerClient->setContentType(display, ContentType::NONE).isOk());
107 }
108
Test_setContentType(ContentType contentType,const char * contentTypeStr)109 void Test_setContentType(ContentType contentType, const char* contentTypeStr) {
110 for (const auto& display : mDisplays) {
111 const auto& [status, supportedContentTypes] =
112 mComposerClient->getSupportedContentTypes(display.getDisplayId());
113 EXPECT_TRUE(status.isOk());
114 Test_setContentTypeForDisplay(display.getDisplayId(), supportedContentTypes,
115 contentType, contentTypeStr);
116 }
117 }
118
hasCapability(Capability capability)119 bool hasCapability(Capability capability) {
120 const auto& [status, capabilities] = mComposerClient->getCapabilities();
121 EXPECT_TRUE(status.isOk());
122 return std::any_of(
123 capabilities.begin(), capabilities.end(),
124 [&](const Capability& activeCapability) { return activeCapability == capability; });
125 }
126
getInterfaceVersion()127 int getInterfaceVersion() {
128 const auto& [versionStatus, version] = mComposerClient->getInterfaceVersion();
129 EXPECT_TRUE(versionStatus.isOk());
130 return version;
131 }
132
getInvalidDisplayId() const133 int64_t getInvalidDisplayId() const { return mComposerClient->getInvalidDisplayId(); }
134
135 struct TestParameters {
136 nsecs_t delayForChange;
137 bool refreshMiss;
138 };
139
140 std::unique_ptr<ComposerClientWrapper> mComposerClient;
141 std::vector<DisplayWrapper> mDisplays;
142 // use the slot count usually set by SF
143 static constexpr uint32_t kBufferSlotCount = 64;
144 };
145
TEST_P(GraphicsComposerAidlTest,GetDisplayCapabilities_BadDisplay)146 TEST_P(GraphicsComposerAidlTest, GetDisplayCapabilities_BadDisplay) {
147 const auto& [status, _] = mComposerClient->getDisplayCapabilities(getInvalidDisplayId());
148
149 EXPECT_FALSE(status.isOk());
150 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
151 }
152
TEST_P(GraphicsComposerAidlTest,GetDisplayCapabilities)153 TEST_P(GraphicsComposerAidlTest, GetDisplayCapabilities) {
154 for (const auto& display : mDisplays) {
155 const auto& [status, capabilities] =
156 mComposerClient->getDisplayCapabilities(display.getDisplayId());
157
158 EXPECT_TRUE(status.isOk());
159 }
160 }
161
TEST_P(GraphicsComposerAidlTest,DumpDebugInfo)162 TEST_P(GraphicsComposerAidlTest, DumpDebugInfo) {
163 ASSERT_TRUE(mComposerClient->dumpDebugInfo().isOk());
164 }
165
TEST_P(GraphicsComposerAidlTest,CreateClientSingleton)166 TEST_P(GraphicsComposerAidlTest, CreateClientSingleton) {
167 std::shared_ptr<IComposerClient> composerClient;
168 const auto& status = mComposerClient->createClient();
169
170 EXPECT_FALSE(status.isOk());
171 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_NO_RESOURCES));
172 }
173
TEST_P(GraphicsComposerAidlTest,GetDisplayIdentificationData)174 TEST_P(GraphicsComposerAidlTest, GetDisplayIdentificationData) {
175 for (const auto& display : mDisplays) {
176 const auto& [status0, displayIdentification0] =
177 mComposerClient->getDisplayIdentificationData(display.getDisplayId());
178 if (!status0.isOk() && status0.getExceptionCode() == EX_SERVICE_SPECIFIC &&
179 status0.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
180 GTEST_SUCCEED() << "Display identification data not supported, skipping test";
181 return;
182 }
183 ASSERT_TRUE(status0.isOk()) << "failed to get display identification data";
184 ASSERT_FALSE(displayIdentification0.data.empty());
185
186 constexpr size_t kEdidBlockSize = 128;
187 ASSERT_TRUE(displayIdentification0.data.size() % kEdidBlockSize == 0)
188 << "EDID blob length is not a multiple of " << kEdidBlockSize;
189
190 const uint8_t kEdidHeader[] = {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
191 ASSERT_TRUE(std::equal(std::begin(kEdidHeader), std::end(kEdidHeader),
192 displayIdentification0.data.begin()))
193 << "EDID blob doesn't start with the fixed EDID header";
194 ASSERT_EQ(0, std::accumulate(displayIdentification0.data.begin(),
195 displayIdentification0.data.begin() + kEdidBlockSize,
196 static_cast<uint8_t>(0)))
197 << "EDID base block doesn't checksum";
198
199 const auto& [status1, displayIdentification1] =
200 mComposerClient->getDisplayIdentificationData(display.getDisplayId());
201 ASSERT_TRUE(status1.isOk());
202
203 ASSERT_EQ(displayIdentification0.port, displayIdentification1.port)
204 << "ports are not stable";
205 ASSERT_TRUE(displayIdentification0.data.size() == displayIdentification1.data.size() &&
206 std::equal(displayIdentification0.data.begin(),
207 displayIdentification0.data.end(),
208 displayIdentification1.data.begin()))
209 << "data is not stable";
210 }
211 }
212
TEST_P(GraphicsComposerAidlTest,GetHdrCapabilities)213 TEST_P(GraphicsComposerAidlTest, GetHdrCapabilities) {
214 for (const auto& display : mDisplays) {
215 const auto& [status, hdrCapabilities] =
216 mComposerClient->getHdrCapabilities(display.getDisplayId());
217
218 ASSERT_TRUE(status.isOk());
219 EXPECT_TRUE(hdrCapabilities.maxLuminance >= hdrCapabilities.minLuminance);
220 }
221 }
222
TEST_P(GraphicsComposerAidlTest,GetPerFrameMetadataKeys)223 TEST_P(GraphicsComposerAidlTest, GetPerFrameMetadataKeys) {
224 for (const auto& display : mDisplays) {
225 const auto& [status, keys] =
226 mComposerClient->getPerFrameMetadataKeys(display.getDisplayId());
227 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
228 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
229 GTEST_SUCCEED() << "getPerFrameMetadataKeys is not supported";
230 return;
231 }
232
233 ASSERT_TRUE(status.isOk());
234 EXPECT_TRUE(keys.size() >= 0);
235 }
236 }
237
TEST_P(GraphicsComposerAidlTest,GetReadbackBufferAttributes)238 TEST_P(GraphicsComposerAidlTest, GetReadbackBufferAttributes) {
239 for (const auto& display : mDisplays) {
240 const auto& [status, _] =
241 mComposerClient->getReadbackBufferAttributes(display.getDisplayId());
242 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
243 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
244 GTEST_SUCCEED() << "getReadbackBufferAttributes is not supported";
245 return;
246 }
247 ASSERT_TRUE(status.isOk());
248 }
249 }
250
TEST_P(GraphicsComposerAidlTest,GetRenderIntents)251 TEST_P(GraphicsComposerAidlTest, GetRenderIntents) {
252 for (const auto& display : mDisplays) {
253 const auto& [status, modes] = mComposerClient->getColorModes(display.getDisplayId());
254 EXPECT_TRUE(status.isOk());
255
256 for (auto mode : modes) {
257 const auto& [intentStatus, intents] =
258 mComposerClient->getRenderIntents(display.getDisplayId(), mode);
259 EXPECT_TRUE(intentStatus.isOk());
260 bool isHdr;
261 switch (mode) {
262 case ColorMode::BT2100_PQ:
263 case ColorMode::BT2100_HLG:
264 isHdr = true;
265 break;
266 default:
267 isHdr = false;
268 break;
269 }
270 RenderIntent requiredIntent =
271 isHdr ? RenderIntent::TONE_MAP_COLORIMETRIC : RenderIntent::COLORIMETRIC;
272
273 const auto iter = std::find(intents.cbegin(), intents.cend(), requiredIntent);
274 EXPECT_NE(intents.cend(), iter);
275 }
276 }
277 }
278
TEST_P(GraphicsComposerAidlTest,GetRenderIntents_BadDisplay)279 TEST_P(GraphicsComposerAidlTest, GetRenderIntents_BadDisplay) {
280 for (const auto& display : mDisplays) {
281 const auto& [status, modes] = mComposerClient->getColorModes(display.getDisplayId());
282 ASSERT_TRUE(status.isOk());
283
284 for (auto mode : modes) {
285 const auto& [intentStatus, _] =
286 mComposerClient->getRenderIntents(getInvalidDisplayId(), mode);
287
288 EXPECT_FALSE(intentStatus.isOk());
289 EXPECT_NO_FATAL_FAILURE(
290 assertServiceSpecificError(intentStatus, IComposerClient::EX_BAD_DISPLAY));
291 }
292 }
293 }
294
TEST_P(GraphicsComposerAidlTest,GetRenderIntents_BadParameter)295 TEST_P(GraphicsComposerAidlTest, GetRenderIntents_BadParameter) {
296 for (const auto& display : mDisplays) {
297 const auto& [status, _] = mComposerClient->getRenderIntents(display.getDisplayId(),
298 static_cast<ColorMode>(-1));
299
300 EXPECT_FALSE(status.isOk());
301 EXPECT_NO_FATAL_FAILURE(
302 assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
303 }
304 }
305
TEST_P(GraphicsComposerAidlTest,GetColorModes)306 TEST_P(GraphicsComposerAidlTest, GetColorModes) {
307 for (const auto& display : mDisplays) {
308 const auto& [status, colorModes] = mComposerClient->getColorModes(display.getDisplayId());
309 ASSERT_TRUE(status.isOk());
310
311 const auto native = std::find(colorModes.cbegin(), colorModes.cend(), ColorMode::NATIVE);
312 EXPECT_NE(colorModes.cend(), native);
313 }
314 }
315
TEST_P(GraphicsComposerAidlTest,GetColorMode_BadDisplay)316 TEST_P(GraphicsComposerAidlTest, GetColorMode_BadDisplay) {
317 const auto& [status, _] = mComposerClient->getColorModes(getInvalidDisplayId());
318
319 EXPECT_FALSE(status.isOk());
320 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
321 }
322
TEST_P(GraphicsComposerAidlTest,SetColorMode)323 TEST_P(GraphicsComposerAidlTest, SetColorMode) {
324 for (const auto& display : mDisplays) {
325 const auto& [status, colorModes] = mComposerClient->getColorModes(display.getDisplayId());
326 EXPECT_TRUE(status.isOk());
327
328 for (auto mode : colorModes) {
329 const auto& [intentStatus, intents] =
330 mComposerClient->getRenderIntents(display.getDisplayId(), mode);
331 EXPECT_TRUE(intentStatus.isOk()) << "failed to get render intents";
332
333 for (auto intent : intents) {
334 const auto modeStatus =
335 mComposerClient->setColorMode(display.getDisplayId(), mode, intent);
336 EXPECT_TRUE(
337 modeStatus.isOk() ||
338 (modeStatus.getExceptionCode() == EX_SERVICE_SPECIFIC &&
339 IComposerClient::EX_UNSUPPORTED == modeStatus.getServiceSpecificError()))
340 << "failed to set color mode";
341 }
342 }
343
344 const auto modeStatus = mComposerClient->setColorMode(
345 display.getDisplayId(), ColorMode::NATIVE, RenderIntent::COLORIMETRIC);
346 EXPECT_TRUE(modeStatus.isOk() ||
347 (modeStatus.getExceptionCode() == EX_SERVICE_SPECIFIC &&
348 IComposerClient::EX_UNSUPPORTED == modeStatus.getServiceSpecificError()))
349 << "failed to set color mode";
350 }
351 }
352
TEST_P(GraphicsComposerAidlTest,SetColorMode_BadDisplay)353 TEST_P(GraphicsComposerAidlTest, SetColorMode_BadDisplay) {
354 for (const auto& display : mDisplays) {
355 const auto& [status, colorModes] = mComposerClient->getColorModes(display.getDisplayId());
356 ASSERT_TRUE(status.isOk());
357
358 for (auto mode : colorModes) {
359 const auto& [intentStatus, intents] =
360 mComposerClient->getRenderIntents(display.getDisplayId(), mode);
361 ASSERT_TRUE(intentStatus.isOk()) << "failed to get render intents";
362
363 for (auto intent : intents) {
364 auto const modeStatus =
365 mComposerClient->setColorMode(getInvalidDisplayId(), mode, intent);
366
367 EXPECT_FALSE(modeStatus.isOk());
368 EXPECT_NO_FATAL_FAILURE(
369 assertServiceSpecificError(modeStatus, IComposerClient::EX_BAD_DISPLAY));
370 }
371 }
372 }
373 }
374
TEST_P(GraphicsComposerAidlTest,SetColorMode_BadParameter)375 TEST_P(GraphicsComposerAidlTest, SetColorMode_BadParameter) {
376 for (const auto& display : mDisplays) {
377 auto status = mComposerClient->setColorMode(
378 display.getDisplayId(), static_cast<ColorMode>(-1), RenderIntent::COLORIMETRIC);
379
380 EXPECT_FALSE(status.isOk());
381 EXPECT_NO_FATAL_FAILURE(
382 assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
383
384 status = mComposerClient->setColorMode(display.getDisplayId(), ColorMode::NATIVE,
385 static_cast<RenderIntent>(-1));
386
387 EXPECT_FALSE(status.isOk());
388 EXPECT_NO_FATAL_FAILURE(
389 assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
390 }
391 }
392
TEST_P(GraphicsComposerAidlTest,GetDisplayedContentSamplingAttributes)393 TEST_P(GraphicsComposerAidlTest, GetDisplayedContentSamplingAttributes) {
394 int constexpr kInvalid = -1;
395 for (const auto& display : mDisplays) {
396 const auto& [status, format] =
397 mComposerClient->getDisplayedContentSamplingAttributes(display.getDisplayId());
398
399 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
400 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
401 SUCCEED() << "Device does not support optional extension. Test skipped";
402 return;
403 }
404
405 ASSERT_TRUE(status.isOk());
406 EXPECT_NE(kInvalid, static_cast<int>(format.format));
407 EXPECT_NE(kInvalid, static_cast<int>(format.dataspace));
408 EXPECT_NE(kInvalid, static_cast<int>(format.componentMask));
409 }
410 }
411
TEST_P(GraphicsComposerAidlTest,SetDisplayedContentSamplingEnabled)412 TEST_P(GraphicsComposerAidlTest, SetDisplayedContentSamplingEnabled) {
413 int constexpr kMaxFrames = 10;
414 FormatColorComponent enableAllComponents = FormatColorComponent::FORMAT_COMPONENT_0;
415
416 for (const auto& display : mDisplays) {
417 auto status = mComposerClient->setDisplayedContentSamplingEnabled(
418 display.getDisplayId(), /*isEnabled*/ true, enableAllComponents, kMaxFrames);
419 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
420 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
421 SUCCEED() << "Device does not support optional extension. Test skipped";
422 return;
423 }
424 EXPECT_TRUE(status.isOk());
425
426 status = mComposerClient->setDisplayedContentSamplingEnabled(
427 display.getDisplayId(), /*isEnabled*/ false, enableAllComponents, kMaxFrames);
428 EXPECT_TRUE(status.isOk());
429 }
430 }
431
TEST_P(GraphicsComposerAidlTest,GetDisplayedContentSample)432 TEST_P(GraphicsComposerAidlTest, GetDisplayedContentSample) {
433 for (const auto& display : mDisplays) {
434 const auto& [status, displayContentSamplingAttributes] =
435 mComposerClient->getDisplayedContentSamplingAttributes(display.getDisplayId());
436 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
437 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
438 SUCCEED() << "Sampling attributes aren't supported on this device, test skipped";
439 return;
440 }
441
442 int64_t constexpr kMaxFrames = 10;
443 int64_t constexpr kTimestamp = 0;
444 const auto& [sampleStatus, displayContentSample] =
445 mComposerClient->getDisplayedContentSample(display.getDisplayId(), kMaxFrames,
446 kTimestamp);
447 if (!sampleStatus.isOk() && sampleStatus.getExceptionCode() == EX_SERVICE_SPECIFIC &&
448 sampleStatus.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
449 SUCCEED() << "Device does not support optional extension. Test skipped";
450 return;
451 }
452
453 EXPECT_TRUE(sampleStatus.isOk());
454 const std::vector<std::vector<int64_t>> histogram = {
455 displayContentSample.sampleComponent0, displayContentSample.sampleComponent1,
456 displayContentSample.sampleComponent2, displayContentSample.sampleComponent3};
457
458 for (size_t i = 0; i < histogram.size(); i++) {
459 const bool shouldHaveHistogram =
460 static_cast<int>(displayContentSamplingAttributes.componentMask) & (1 << i);
461 EXPECT_EQ(shouldHaveHistogram, !histogram[i].empty());
462 }
463 }
464 }
465
TEST_P(GraphicsComposerAidlTest,GetDisplayConnectionType)466 TEST_P(GraphicsComposerAidlTest, GetDisplayConnectionType) {
467 const auto& [status, type] = mComposerClient->getDisplayConnectionType(getInvalidDisplayId());
468
469 EXPECT_FALSE(status.isOk());
470 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
471
472 for (const auto& display : mDisplays) {
473 const auto& [connectionTypeStatus, _] =
474 mComposerClient->getDisplayConnectionType(display.getDisplayId());
475 EXPECT_TRUE(connectionTypeStatus.isOk());
476 }
477 }
478
TEST_P(GraphicsComposerAidlTest,GetDisplayAttribute)479 TEST_P(GraphicsComposerAidlTest, GetDisplayAttribute) {
480 for (const auto& display : mDisplays) {
481 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
482 EXPECT_TRUE(status.isOk());
483
484 for (const auto& config : configs) {
485 const std::array<DisplayAttribute, 4> requiredAttributes = {{
486 DisplayAttribute::WIDTH,
487 DisplayAttribute::HEIGHT,
488 DisplayAttribute::VSYNC_PERIOD,
489 DisplayAttribute::CONFIG_GROUP,
490 }};
491 for (const auto& attribute : requiredAttributes) {
492 const auto& [attribStatus, value] = mComposerClient->getDisplayAttribute(
493 display.getDisplayId(), config, attribute);
494 EXPECT_TRUE(attribStatus.isOk());
495 EXPECT_NE(-1, value);
496 }
497
498 const std::array<DisplayAttribute, 2> optionalAttributes = {{
499 DisplayAttribute::DPI_X,
500 DisplayAttribute::DPI_Y,
501 }};
502 for (const auto& attribute : optionalAttributes) {
503 const auto& [attribStatus, value] = mComposerClient->getDisplayAttribute(
504 display.getDisplayId(), config, attribute);
505 EXPECT_TRUE(attribStatus.isOk() ||
506 (attribStatus.getExceptionCode() == EX_SERVICE_SPECIFIC &&
507 IComposerClient::EX_UNSUPPORTED ==
508 attribStatus.getServiceSpecificError()));
509 }
510 }
511 }
512 }
513
TEST_P(GraphicsComposerAidlTest,CheckConfigsAreValid)514 TEST_P(GraphicsComposerAidlTest, CheckConfigsAreValid) {
515 for (const auto& display : mDisplays) {
516 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
517 EXPECT_TRUE(status.isOk());
518
519 EXPECT_FALSE(std::any_of(configs.begin(), configs.end(), [](auto config) {
520 return config == IComposerClient::INVALID_CONFIGURATION;
521 }));
522 }
523 }
524
TEST_P(GraphicsComposerAidlTest,GetDisplayVsyncPeriod_BadDisplay)525 TEST_P(GraphicsComposerAidlTest, GetDisplayVsyncPeriod_BadDisplay) {
526 const auto& [status, vsyncPeriodNanos] =
527 mComposerClient->getDisplayVsyncPeriod(getInvalidDisplayId());
528
529 EXPECT_FALSE(status.isOk());
530 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
531 }
532
TEST_P(GraphicsComposerAidlTest,SetActiveConfigWithConstraints_BadDisplay)533 TEST_P(GraphicsComposerAidlTest, SetActiveConfigWithConstraints_BadDisplay) {
534 VsyncPeriodChangeConstraints constraints;
535 constraints.seamlessRequired = false;
536 constraints.desiredTimeNanos = systemTime();
537 auto invalidDisplay = DisplayWrapper(getInvalidDisplayId());
538
539 const auto& [status, timeline] = mComposerClient->setActiveConfigWithConstraints(
540 &invalidDisplay, /*config*/ 0, constraints);
541
542 EXPECT_FALSE(status.isOk());
543 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
544 }
545
TEST_P(GraphicsComposerAidlTest,SetActiveConfigWithConstraints_BadConfig)546 TEST_P(GraphicsComposerAidlTest, SetActiveConfigWithConstraints_BadConfig) {
547 VsyncPeriodChangeConstraints constraints;
548 constraints.seamlessRequired = false;
549 constraints.desiredTimeNanos = systemTime();
550
551 for (DisplayWrapper& display : mDisplays) {
552 int32_t constexpr kInvalidConfigId = IComposerClient::INVALID_CONFIGURATION;
553 const auto& [status, _] = mComposerClient->setActiveConfigWithConstraints(
554 &display, kInvalidConfigId, constraints);
555
556 EXPECT_FALSE(status.isOk());
557 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_CONFIG));
558 }
559 }
560
TEST_P(GraphicsComposerAidlTest,SetBootDisplayConfig_BadDisplay)561 TEST_P(GraphicsComposerAidlTest, SetBootDisplayConfig_BadDisplay) {
562 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
563 GTEST_SUCCEED() << "Boot Display Config not supported";
564 return;
565 }
566 const auto& status = mComposerClient->setBootDisplayConfig(getInvalidDisplayId(), /*config*/ 0);
567
568 EXPECT_FALSE(status.isOk());
569 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
570 }
571
TEST_P(GraphicsComposerAidlTest,SetBootDisplayConfig_BadConfig)572 TEST_P(GraphicsComposerAidlTest, SetBootDisplayConfig_BadConfig) {
573 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
574 GTEST_SUCCEED() << "Boot Display Config not supported";
575 return;
576 }
577 for (DisplayWrapper& display : mDisplays) {
578 int32_t constexpr kInvalidConfigId = IComposerClient::INVALID_CONFIGURATION;
579 const auto& status =
580 mComposerClient->setBootDisplayConfig(display.getDisplayId(), kInvalidConfigId);
581
582 EXPECT_FALSE(status.isOk());
583 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_CONFIG));
584 }
585 }
586
TEST_P(GraphicsComposerAidlTest,SetBootDisplayConfig)587 TEST_P(GraphicsComposerAidlTest, SetBootDisplayConfig) {
588 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
589 GTEST_SUCCEED() << "Boot Display Config not supported";
590 return;
591 }
592
593 for (const auto& display : mDisplays) {
594 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
595 EXPECT_TRUE(status.isOk());
596 for (const auto& config : configs) {
597 EXPECT_TRUE(
598 mComposerClient->setBootDisplayConfig(display.getDisplayId(), config).isOk());
599 }
600 }
601 }
602
TEST_P(GraphicsComposerAidlTest,ClearBootDisplayConfig_BadDisplay)603 TEST_P(GraphicsComposerAidlTest, ClearBootDisplayConfig_BadDisplay) {
604 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
605 GTEST_SUCCEED() << "Boot Display Config not supported";
606 return;
607 }
608 const auto& status = mComposerClient->clearBootDisplayConfig(getInvalidDisplayId());
609
610 EXPECT_FALSE(status.isOk());
611 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
612 }
613
TEST_P(GraphicsComposerAidlTest,ClearBootDisplayConfig)614 TEST_P(GraphicsComposerAidlTest, ClearBootDisplayConfig) {
615 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
616 GTEST_SUCCEED() << "Boot Display Config not supported";
617 return;
618 }
619
620 for (const auto& display : mDisplays) {
621 EXPECT_TRUE(mComposerClient->clearBootDisplayConfig(display.getDisplayId()).isOk());
622 }
623 }
624
TEST_P(GraphicsComposerAidlTest,GetPreferredBootDisplayConfig_BadDisplay)625 TEST_P(GraphicsComposerAidlTest, GetPreferredBootDisplayConfig_BadDisplay) {
626 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
627 GTEST_SUCCEED() << "Boot Display Config not supported";
628 return;
629 }
630 const auto& [status, _] = mComposerClient->getPreferredBootDisplayConfig(getInvalidDisplayId());
631
632 EXPECT_FALSE(status.isOk());
633 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
634 }
635
TEST_P(GraphicsComposerAidlTest,GetPreferredBootDisplayConfig)636 TEST_P(GraphicsComposerAidlTest, GetPreferredBootDisplayConfig) {
637 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
638 GTEST_SUCCEED() << "Boot Display Config not supported";
639 return;
640 }
641
642 for (const auto& display : mDisplays) {
643 const auto& [status, preferredDisplayConfig] =
644 mComposerClient->getPreferredBootDisplayConfig(display.getDisplayId());
645 EXPECT_TRUE(status.isOk());
646
647 const auto& [configStatus, configs] =
648 mComposerClient->getDisplayConfigs(display.getDisplayId());
649
650 EXPECT_TRUE(configStatus.isOk());
651 EXPECT_NE(configs.end(), std::find(configs.begin(), configs.end(), preferredDisplayConfig));
652 }
653 }
654
TEST_P(GraphicsComposerAidlTest,BootDisplayConfig_Unsupported)655 TEST_P(GraphicsComposerAidlTest, BootDisplayConfig_Unsupported) {
656 if (!hasCapability(Capability::BOOT_DISPLAY_CONFIG)) {
657 for (const auto& display : mDisplays) {
658 const auto& [configStatus, config] =
659 mComposerClient->getActiveConfig(display.getDisplayId());
660 EXPECT_TRUE(configStatus.isOk());
661
662 auto status = mComposerClient->setBootDisplayConfig(display.getDisplayId(), config);
663 EXPECT_FALSE(status.isOk());
664 EXPECT_NO_FATAL_FAILURE(
665 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
666
667 status = mComposerClient->getPreferredBootDisplayConfig(display.getDisplayId()).first;
668 EXPECT_FALSE(status.isOk());
669 EXPECT_NO_FATAL_FAILURE(
670 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
671
672 status = mComposerClient->clearBootDisplayConfig(display.getDisplayId());
673 EXPECT_FALSE(status.isOk());
674 EXPECT_NO_FATAL_FAILURE(
675 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
676 }
677 }
678 }
679
TEST_P(GraphicsComposerAidlTest,GetHdrConversionCapabilities)680 TEST_P(GraphicsComposerAidlTest, GetHdrConversionCapabilities) {
681 if (!hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG)) {
682 GTEST_SUCCEED() << "HDR output conversion not supported";
683 return;
684 }
685 const auto& [status, conversionCapabilities] = mComposerClient->getHdrConversionCapabilities();
686 EXPECT_TRUE(status.isOk());
687 }
688
TEST_P(GraphicsComposerAidlTest,SetHdrConversionStrategy_Passthrough)689 TEST_P(GraphicsComposerAidlTest, SetHdrConversionStrategy_Passthrough) {
690 if (!hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG)) {
691 GTEST_SUCCEED() << "HDR output conversion not supported";
692 return;
693 }
694 common::HdrConversionStrategy hdrConversionStrategy;
695 hdrConversionStrategy.set<common::HdrConversionStrategy::Tag::passthrough>(true);
696 const auto& [status, preferredHdrOutputType] =
697 mComposerClient->setHdrConversionStrategy(hdrConversionStrategy);
698 EXPECT_TRUE(status.isOk());
699 EXPECT_EQ(common::Hdr::INVALID, preferredHdrOutputType);
700 }
701
TEST_P(GraphicsComposerAidlTest,SetHdrConversionStrategy_Force)702 TEST_P(GraphicsComposerAidlTest, SetHdrConversionStrategy_Force) {
703 if (!hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG)) {
704 GTEST_SUCCEED() << "HDR output conversion not supported";
705 return;
706 }
707 const auto& [status, conversionCapabilities] = mComposerClient->getHdrConversionCapabilities();
708
709 for (const auto& display : mDisplays) {
710 const auto& [status2, hdrCapabilities] =
711 mComposerClient->getHdrCapabilities(display.getDisplayId());
712 const auto& hdrTypes = hdrCapabilities.types;
713 for (auto conversionCapability : conversionCapabilities) {
714 if (conversionCapability.outputType != common::Hdr::INVALID) {
715 if (std::find(hdrTypes.begin(), hdrTypes.end(), conversionCapability.outputType) ==
716 hdrTypes.end()) {
717 continue;
718 }
719 common::HdrConversionStrategy hdrConversionStrategy;
720 hdrConversionStrategy.set<common::HdrConversionStrategy::Tag::forceHdrConversion>(
721 conversionCapability.outputType);
722 const auto& [statusSet, preferredHdrOutputType] =
723 mComposerClient->setHdrConversionStrategy(hdrConversionStrategy);
724 EXPECT_TRUE(statusSet.isOk());
725 EXPECT_EQ(common::Hdr::INVALID, preferredHdrOutputType);
726 }
727 }
728 }
729 }
730
TEST_P(GraphicsComposerAidlTest,SetHdrConversionStrategy_Auto)731 TEST_P(GraphicsComposerAidlTest, SetHdrConversionStrategy_Auto) {
732 if (!hasCapability(Capability::HDR_OUTPUT_CONVERSION_CONFIG)) {
733 GTEST_SUCCEED() << "HDR output conversion not supported";
734 return;
735 }
736 const auto& [status, conversionCapabilities] = mComposerClient->getHdrConversionCapabilities();
737
738 for (const auto& display : mDisplays) {
739 const auto& [status2, hdrCapabilities] =
740 mComposerClient->getHdrCapabilities(display.getDisplayId());
741 if (hdrCapabilities.types.size() <= 0) {
742 return;
743 }
744 std::vector<aidl::android::hardware::graphics::common::Hdr> autoHdrTypes;
745 for (auto conversionCapability : conversionCapabilities) {
746 if (conversionCapability.outputType != common::Hdr::INVALID) {
747 autoHdrTypes.push_back(conversionCapability.outputType);
748 }
749 }
750 common::HdrConversionStrategy hdrConversionStrategy;
751 hdrConversionStrategy.set<common::HdrConversionStrategy::Tag::autoAllowedHdrTypes>(
752 autoHdrTypes);
753 const auto& [statusSet, preferredHdrOutputType] =
754 mComposerClient->setHdrConversionStrategy(hdrConversionStrategy);
755 EXPECT_TRUE(statusSet.isOk());
756 EXPECT_NE(common::Hdr::INVALID, preferredHdrOutputType);
757 }
758 }
759
TEST_P(GraphicsComposerAidlTest,SetAutoLowLatencyMode_BadDisplay)760 TEST_P(GraphicsComposerAidlTest, SetAutoLowLatencyMode_BadDisplay) {
761 auto status = mComposerClient->setAutoLowLatencyMode(getInvalidDisplayId(), /*isEnabled*/ true);
762 EXPECT_FALSE(status.isOk());
763 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
764
765 status = mComposerClient->setAutoLowLatencyMode(getInvalidDisplayId(), /*isEnabled*/ false);
766 EXPECT_FALSE(status.isOk());
767 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
768 }
769
TEST_P(GraphicsComposerAidlTest,SetAutoLowLatencyMode)770 TEST_P(GraphicsComposerAidlTest, SetAutoLowLatencyMode) {
771 for (const auto& display : mDisplays) {
772 const auto& [status, capabilities] =
773 mComposerClient->getDisplayCapabilities(display.getDisplayId());
774 ASSERT_TRUE(status.isOk());
775
776 const bool allmSupport =
777 std::find(capabilities.begin(), capabilities.end(),
778 DisplayCapability::AUTO_LOW_LATENCY_MODE) != capabilities.end();
779
780 if (!allmSupport) {
781 const auto& statusIsOn = mComposerClient->setAutoLowLatencyMode(display.getDisplayId(),
782 /*isEnabled*/ true);
783 EXPECT_FALSE(statusIsOn.isOk());
784 EXPECT_NO_FATAL_FAILURE(
785 assertServiceSpecificError(statusIsOn, IComposerClient::EX_UNSUPPORTED));
786 const auto& statusIsOff = mComposerClient->setAutoLowLatencyMode(display.getDisplayId(),
787 /*isEnabled*/ false);
788 EXPECT_FALSE(statusIsOff.isOk());
789 EXPECT_NO_FATAL_FAILURE(
790 assertServiceSpecificError(statusIsOff, IComposerClient::EX_UNSUPPORTED));
791 GTEST_SUCCEED() << "Auto Low Latency Mode is not supported on display "
792 << std::to_string(display.getDisplayId()) << ", skipping test";
793 return;
794 }
795
796 EXPECT_TRUE(mComposerClient->setAutoLowLatencyMode(display.getDisplayId(), true).isOk());
797 EXPECT_TRUE(mComposerClient->setAutoLowLatencyMode(display.getDisplayId(), false).isOk());
798 }
799 }
800
TEST_P(GraphicsComposerAidlTest,GetSupportedContentTypes_BadDisplay)801 TEST_P(GraphicsComposerAidlTest, GetSupportedContentTypes_BadDisplay) {
802 const auto& [status, _] = mComposerClient->getSupportedContentTypes(getInvalidDisplayId());
803
804 EXPECT_FALSE(status.isOk());
805 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
806 }
807
TEST_P(GraphicsComposerAidlTest,GetSupportedContentTypes)808 TEST_P(GraphicsComposerAidlTest, GetSupportedContentTypes) {
809 for (const auto& display : mDisplays) {
810 const auto& [status, supportedContentTypes] =
811 mComposerClient->getSupportedContentTypes(display.getDisplayId());
812 ASSERT_TRUE(status.isOk());
813
814 const bool noneSupported =
815 std::find(supportedContentTypes.begin(), supportedContentTypes.end(),
816 ContentType::NONE) != supportedContentTypes.end();
817
818 EXPECT_FALSE(noneSupported);
819 }
820 }
821
TEST_P(GraphicsComposerAidlTest,SetContentTypeNoneAlwaysAccepted)822 TEST_P(GraphicsComposerAidlTest, SetContentTypeNoneAlwaysAccepted) {
823 for (const auto& display : mDisplays) {
824 EXPECT_TRUE(
825 mComposerClient->setContentType(display.getDisplayId(), ContentType::NONE).isOk());
826 }
827 }
828
TEST_P(GraphicsComposerAidlTest,SetContentType_BadDisplay)829 TEST_P(GraphicsComposerAidlTest, SetContentType_BadDisplay) {
830 constexpr ContentType types[] = {ContentType::NONE, ContentType::GRAPHICS, ContentType::PHOTO,
831 ContentType::CINEMA, ContentType::GAME};
832 for (const auto& type : types) {
833 const auto& status = mComposerClient->setContentType(getInvalidDisplayId(), type);
834
835 EXPECT_FALSE(status.isOk());
836 EXPECT_NO_FATAL_FAILURE(
837 assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
838 }
839 }
840
TEST_P(GraphicsComposerAidlTest,SetGraphicsContentType)841 TEST_P(GraphicsComposerAidlTest, SetGraphicsContentType) {
842 Test_setContentType(ContentType::GRAPHICS, "GRAPHICS");
843 }
844
TEST_P(GraphicsComposerAidlTest,SetPhotoContentType)845 TEST_P(GraphicsComposerAidlTest, SetPhotoContentType) {
846 Test_setContentType(ContentType::PHOTO, "PHOTO");
847 }
848
TEST_P(GraphicsComposerAidlTest,SetCinemaContentType)849 TEST_P(GraphicsComposerAidlTest, SetCinemaContentType) {
850 Test_setContentType(ContentType::CINEMA, "CINEMA");
851 }
852
TEST_P(GraphicsComposerAidlTest,SetGameContentType)853 TEST_P(GraphicsComposerAidlTest, SetGameContentType) {
854 Test_setContentType(ContentType::GAME, "GAME");
855 }
856
TEST_P(GraphicsComposerAidlTest,CreateVirtualDisplay)857 TEST_P(GraphicsComposerAidlTest, CreateVirtualDisplay) {
858 const auto& [status, maxVirtualDisplayCount] = mComposerClient->getMaxVirtualDisplayCount();
859 EXPECT_TRUE(status.isOk());
860
861 if (maxVirtualDisplayCount == 0) {
862 GTEST_SUCCEED() << "no virtual display support";
863 return;
864 }
865
866 const auto& [virtualDisplayStatus, virtualDisplay] = mComposerClient->createVirtualDisplay(
867 /*width*/ 64, /*height*/ 64, common::PixelFormat::IMPLEMENTATION_DEFINED,
868 kBufferSlotCount);
869
870 ASSERT_TRUE(virtualDisplayStatus.isOk());
871 EXPECT_TRUE(mComposerClient->destroyVirtualDisplay(virtualDisplay.display).isOk());
872 }
873
TEST_P(GraphicsComposerAidlTest,DestroyVirtualDisplay_BadDisplay)874 TEST_P(GraphicsComposerAidlTest, DestroyVirtualDisplay_BadDisplay) {
875 const auto& [status, maxDisplayCount] = mComposerClient->getMaxVirtualDisplayCount();
876 EXPECT_TRUE(status.isOk());
877
878 if (maxDisplayCount == 0) {
879 GTEST_SUCCEED() << "no virtual display support";
880 return;
881 }
882
883 const auto& destroyStatus = mComposerClient->destroyVirtualDisplay(getInvalidDisplayId());
884
885 EXPECT_FALSE(destroyStatus.isOk());
886 EXPECT_NO_FATAL_FAILURE(
887 assertServiceSpecificError(destroyStatus, IComposerClient::EX_BAD_DISPLAY));
888 }
889
TEST_P(GraphicsComposerAidlTest,CreateLayer)890 TEST_P(GraphicsComposerAidlTest, CreateLayer) {
891 if (hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
892 GTEST_SKIP() << "Create layer will be tested in GraphicsComposerAidlBatchedCommandTest";
893 return;
894 }
895
896 for (const auto& display : mDisplays) {
897 const auto& [status, layer] =
898 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, nullptr);
899 EXPECT_TRUE(status.isOk());
900 EXPECT_TRUE(mComposerClient->destroyLayer(display.getDisplayId(), layer, nullptr).isOk());
901 }
902 }
903
TEST_P(GraphicsComposerAidlTest,CreateLayer_BadDisplay)904 TEST_P(GraphicsComposerAidlTest, CreateLayer_BadDisplay) {
905 if (hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
906 GTEST_SKIP() << "Create layer will be tested in GraphicsComposerAidlBatchedCommandTest";
907 return;
908 }
909
910 const auto& [status, _] =
911 mComposerClient->createLayer(getInvalidDisplayId(), kBufferSlotCount, nullptr);
912
913 EXPECT_FALSE(status.isOk());
914 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
915 }
916
TEST_P(GraphicsComposerAidlTest,DestroyLayer_BadDisplay)917 TEST_P(GraphicsComposerAidlTest, DestroyLayer_BadDisplay) {
918 if (hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
919 GTEST_SKIP() << "Destroy layer will be tested in GraphicsComposerAidlBatchedCommandTest";
920 return;
921 }
922
923 for (const auto& display : mDisplays) {
924 const auto& [status, layer] =
925 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, nullptr);
926 EXPECT_TRUE(status.isOk());
927
928 const auto& destroyStatus =
929 mComposerClient->destroyLayer(getInvalidDisplayId(), layer, nullptr);
930
931 EXPECT_FALSE(destroyStatus.isOk());
932 EXPECT_NO_FATAL_FAILURE(
933 assertServiceSpecificError(destroyStatus, IComposerClient::EX_BAD_DISPLAY));
934 ASSERT_TRUE(mComposerClient->destroyLayer(display.getDisplayId(), layer, nullptr).isOk());
935 }
936 }
937
TEST_P(GraphicsComposerAidlTest,DestroyLayer_BadLayerError)938 TEST_P(GraphicsComposerAidlTest, DestroyLayer_BadLayerError) {
939 if (hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
940 GTEST_SKIP() << "Destroy layer will be tested in GraphicsComposerAidlBatchedCommandTest";
941 return;
942 }
943
944 for (const auto& display : mDisplays) {
945 // We haven't created any layers yet, so any id should be invalid
946 const auto& status =
947 mComposerClient->destroyLayer(display.getDisplayId(), /*layer*/ 1, nullptr);
948
949 EXPECT_FALSE(status.isOk());
950 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_LAYER));
951 }
952 }
953
TEST_P(GraphicsComposerAidlTest,GetActiveConfig_BadDisplay)954 TEST_P(GraphicsComposerAidlTest, GetActiveConfig_BadDisplay) {
955 const auto& [status, _] = mComposerClient->getActiveConfig(getInvalidDisplayId());
956
957 EXPECT_FALSE(status.isOk());
958 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
959 }
960
TEST_P(GraphicsComposerAidlTest,GetDisplayConfig)961 TEST_P(GraphicsComposerAidlTest, GetDisplayConfig) {
962 for (const auto& display : mDisplays) {
963 const auto& [status, _] = mComposerClient->getDisplayConfigs(display.getDisplayId());
964 EXPECT_TRUE(status.isOk());
965 }
966 }
967
TEST_P(GraphicsComposerAidlTest,GetDisplayConfig_BadDisplay)968 TEST_P(GraphicsComposerAidlTest, GetDisplayConfig_BadDisplay) {
969 const auto& [status, _] = mComposerClient->getDisplayConfigs(getInvalidDisplayId());
970
971 EXPECT_FALSE(status.isOk());
972 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
973 }
974
TEST_P(GraphicsComposerAidlTest,GetDisplayName)975 TEST_P(GraphicsComposerAidlTest, GetDisplayName) {
976 for (const auto& display : mDisplays) {
977 const auto& [status, _] = mComposerClient->getDisplayName(display.getDisplayId());
978 EXPECT_TRUE(status.isOk());
979 }
980 }
981
TEST_P(GraphicsComposerAidlTest,GetDisplayPhysicalOrientation)982 TEST_P(GraphicsComposerAidlTest, GetDisplayPhysicalOrientation) {
983 const auto allowedDisplayOrientations = std::array<Transform, 4>{
984 Transform::NONE,
985 Transform::ROT_90,
986 Transform::ROT_180,
987 Transform::ROT_270,
988 };
989
990 for (const auto& display : mDisplays) {
991 const auto& [status, displayOrientation] =
992 mComposerClient->getDisplayPhysicalOrientation(display.getDisplayId());
993
994 EXPECT_TRUE(status.isOk());
995 EXPECT_NE(std::find(allowedDisplayOrientations.begin(), allowedDisplayOrientations.end(),
996 displayOrientation),
997 allowedDisplayOrientations.end());
998 }
999 }
1000
TEST_P(GraphicsComposerAidlTest,SetClientTargetSlotCount)1001 TEST_P(GraphicsComposerAidlTest, SetClientTargetSlotCount) {
1002 for (const auto& display : mDisplays) {
1003 EXPECT_TRUE(
1004 mComposerClient->setClientTargetSlotCount(display.getDisplayId(), kBufferSlotCount)
1005 .isOk());
1006 }
1007 }
1008
TEST_P(GraphicsComposerAidlTest,SetActiveConfig)1009 TEST_P(GraphicsComposerAidlTest, SetActiveConfig) {
1010 for (auto& display : mDisplays) {
1011 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
1012 EXPECT_TRUE(status.isOk());
1013
1014 for (const auto& config : configs) {
1015 EXPECT_TRUE(mComposerClient->setActiveConfig(&display, config).isOk());
1016 const auto& [configStatus, config1] =
1017 mComposerClient->getActiveConfig(display.getDisplayId());
1018 EXPECT_TRUE(configStatus.isOk());
1019 EXPECT_EQ(config, config1);
1020 }
1021 }
1022 }
1023
TEST_P(GraphicsComposerAidlTest,SetActiveConfigPowerCycle)1024 TEST_P(GraphicsComposerAidlTest, SetActiveConfigPowerCycle) {
1025 for (auto& display : mDisplays) {
1026 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::OFF).isOk());
1027 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
1028
1029 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
1030 EXPECT_TRUE(status.isOk());
1031
1032 for (const auto& config : configs) {
1033 EXPECT_TRUE(mComposerClient->setActiveConfig(&display, config).isOk());
1034 const auto& [config1Status, config1] =
1035 mComposerClient->getActiveConfig(display.getDisplayId());
1036 EXPECT_TRUE(config1Status.isOk());
1037 EXPECT_EQ(config, config1);
1038
1039 EXPECT_TRUE(
1040 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::OFF).isOk());
1041 EXPECT_TRUE(
1042 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
1043 const auto& [config2Status, config2] =
1044 mComposerClient->getActiveConfig(display.getDisplayId());
1045 EXPECT_TRUE(config2Status.isOk());
1046 EXPECT_EQ(config, config2);
1047 }
1048 }
1049 }
1050
TEST_P(GraphicsComposerAidlTest,SetPowerModeUnsupported)1051 TEST_P(GraphicsComposerAidlTest, SetPowerModeUnsupported) {
1052 for (const auto& display : mDisplays) {
1053 const auto& [status, capabilities] =
1054 mComposerClient->getDisplayCapabilities(display.getDisplayId());
1055 ASSERT_TRUE(status.isOk());
1056
1057 const bool isDozeSupported = std::find(capabilities.begin(), capabilities.end(),
1058 DisplayCapability::DOZE) != capabilities.end();
1059 const bool isSuspendSupported = std::find(capabilities.begin(), capabilities.end(),
1060 DisplayCapability::SUSPEND) != capabilities.end();
1061
1062 if (!isDozeSupported) {
1063 const auto& powerModeDozeStatus =
1064 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::DOZE);
1065 EXPECT_FALSE(powerModeDozeStatus.isOk());
1066 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(powerModeDozeStatus,
1067 IComposerClient::EX_UNSUPPORTED));
1068
1069 const auto& powerModeDozeSuspendStatus =
1070 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::DOZE_SUSPEND);
1071 EXPECT_FALSE(powerModeDozeSuspendStatus.isOk());
1072 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(powerModeDozeSuspendStatus,
1073 IComposerClient::EX_UNSUPPORTED));
1074 }
1075
1076 if (!isSuspendSupported) {
1077 const auto& powerModeSuspendStatus =
1078 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON_SUSPEND);
1079 EXPECT_FALSE(powerModeSuspendStatus.isOk());
1080 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(powerModeSuspendStatus,
1081 IComposerClient::EX_UNSUPPORTED));
1082
1083 const auto& powerModeDozeSuspendStatus =
1084 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::DOZE_SUSPEND);
1085 EXPECT_FALSE(powerModeDozeSuspendStatus.isOk());
1086 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(powerModeDozeSuspendStatus,
1087 IComposerClient::EX_UNSUPPORTED));
1088 }
1089 }
1090 }
1091
TEST_P(GraphicsComposerAidlTest,SetVsyncEnabled)1092 TEST_P(GraphicsComposerAidlTest, SetVsyncEnabled) {
1093 mComposerClient->setVsyncAllowed(true);
1094
1095 for (const auto& display : mDisplays) {
1096 EXPECT_TRUE(mComposerClient->setVsync(display.getDisplayId(), true).isOk());
1097 usleep(60 * 1000);
1098 EXPECT_TRUE(mComposerClient->setVsync(display.getDisplayId(), false).isOk());
1099 }
1100
1101 mComposerClient->setVsyncAllowed(false);
1102 }
1103
TEST_P(GraphicsComposerAidlTest,SetPowerMode)1104 TEST_P(GraphicsComposerAidlTest, SetPowerMode) {
1105 for (const auto& display : mDisplays) {
1106 const auto& [status, capabilities] =
1107 mComposerClient->getDisplayCapabilities(display.getDisplayId());
1108 ASSERT_TRUE(status.isOk());
1109
1110 const bool isDozeSupported = std::find(capabilities.begin(), capabilities.end(),
1111 DisplayCapability::DOZE) != capabilities.end();
1112 const bool isSuspendSupported = std::find(capabilities.begin(), capabilities.end(),
1113 DisplayCapability::SUSPEND) != capabilities.end();
1114
1115 std::vector<PowerMode> modes;
1116 modes.push_back(PowerMode::OFF);
1117 modes.push_back(PowerMode::ON);
1118
1119 if (isSuspendSupported) {
1120 modes.push_back(PowerMode::ON_SUSPEND);
1121 }
1122
1123 if (isDozeSupported) {
1124 modes.push_back(PowerMode::DOZE);
1125 }
1126
1127 if (isSuspendSupported && isDozeSupported) {
1128 modes.push_back(PowerMode::DOZE_SUSPEND);
1129 }
1130
1131 for (auto mode : modes) {
1132 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1133 }
1134 }
1135 }
1136
TEST_P(GraphicsComposerAidlTest,SetPowerModeVariations)1137 TEST_P(GraphicsComposerAidlTest, SetPowerModeVariations) {
1138 for (const auto& display : mDisplays) {
1139 const auto& [status, capabilities] =
1140 mComposerClient->getDisplayCapabilities(display.getDisplayId());
1141 ASSERT_TRUE(status.isOk());
1142
1143 const bool isDozeSupported = std::find(capabilities.begin(), capabilities.end(),
1144 DisplayCapability::DOZE) != capabilities.end();
1145 const bool isSuspendSupported = std::find(capabilities.begin(), capabilities.end(),
1146 DisplayCapability::SUSPEND) != capabilities.end();
1147
1148 std::vector<PowerMode> modes;
1149
1150 modes.push_back(PowerMode::OFF);
1151 modes.push_back(PowerMode::ON);
1152 modes.push_back(PowerMode::OFF);
1153 for (auto mode : modes) {
1154 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1155 }
1156 modes.clear();
1157
1158 modes.push_back(PowerMode::OFF);
1159 modes.push_back(PowerMode::OFF);
1160 for (auto mode : modes) {
1161 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1162 }
1163 modes.clear();
1164
1165 modes.push_back(PowerMode::ON);
1166 modes.push_back(PowerMode::ON);
1167 for (auto mode : modes) {
1168 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1169 }
1170 modes.clear();
1171
1172 if (isSuspendSupported) {
1173 modes.push_back(PowerMode::ON_SUSPEND);
1174 modes.push_back(PowerMode::ON_SUSPEND);
1175 for (auto mode : modes) {
1176 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1177 }
1178 modes.clear();
1179 }
1180
1181 if (isDozeSupported) {
1182 modes.push_back(PowerMode::DOZE);
1183 modes.push_back(PowerMode::DOZE);
1184 for (auto mode : modes) {
1185 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1186 }
1187 modes.clear();
1188 }
1189
1190 if (isSuspendSupported && isDozeSupported) {
1191 modes.push_back(PowerMode::DOZE_SUSPEND);
1192 modes.push_back(PowerMode::DOZE_SUSPEND);
1193 for (auto mode : modes) {
1194 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), mode).isOk());
1195 }
1196 modes.clear();
1197 }
1198 }
1199 }
1200
TEST_P(GraphicsComposerAidlTest,SetPowerMode_BadDisplay)1201 TEST_P(GraphicsComposerAidlTest, SetPowerMode_BadDisplay) {
1202 const auto& status = mComposerClient->setPowerMode(getInvalidDisplayId(), PowerMode::ON);
1203
1204 EXPECT_FALSE(status.isOk());
1205 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_DISPLAY));
1206 }
1207
TEST_P(GraphicsComposerAidlTest,SetPowerMode_BadParameter)1208 TEST_P(GraphicsComposerAidlTest, SetPowerMode_BadParameter) {
1209 for (const auto& display : mDisplays) {
1210 const auto& status =
1211 mComposerClient->setPowerMode(display.getDisplayId(), static_cast<PowerMode>(-1));
1212
1213 EXPECT_FALSE(status.isOk());
1214 EXPECT_NO_FATAL_FAILURE(
1215 assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
1216 }
1217 }
1218
TEST_P(GraphicsComposerAidlTest,GetDataspaceSaturationMatrix)1219 TEST_P(GraphicsComposerAidlTest, GetDataspaceSaturationMatrix) {
1220 const auto& [status, matrix] =
1221 mComposerClient->getDataspaceSaturationMatrix(common::Dataspace::SRGB_LINEAR);
1222 ASSERT_TRUE(status.isOk());
1223 ASSERT_EQ(16, matrix.size()); // matrix should not be empty if call succeeded.
1224
1225 // the last row is known
1226 EXPECT_EQ(0.0f, matrix[12]);
1227 EXPECT_EQ(0.0f, matrix[13]);
1228 EXPECT_EQ(0.0f, matrix[14]);
1229 EXPECT_EQ(1.0f, matrix[15]);
1230 }
1231
TEST_P(GraphicsComposerAidlTest,GetDataspaceSaturationMatrix_BadParameter)1232 TEST_P(GraphicsComposerAidlTest, GetDataspaceSaturationMatrix_BadParameter) {
1233 const auto& [status, matrix] =
1234 mComposerClient->getDataspaceSaturationMatrix(common::Dataspace::UNKNOWN);
1235
1236 EXPECT_FALSE(status.isOk());
1237 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
1238 }
1239
1240 /*
1241 * Test that no two display configs are exactly the same.
1242 */
TEST_P(GraphicsComposerAidlTest,GetDisplayConfigNoRepetitions)1243 TEST_P(GraphicsComposerAidlTest, GetDisplayConfigNoRepetitions) {
1244 for (const auto& display : mDisplays) {
1245 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
1246 for (std::vector<int>::size_type i = 0; i < configs.size(); i++) {
1247 for (std::vector<int>::size_type j = i + 1; j < configs.size(); j++) {
1248 const auto& [widthStatus1, width1] = mComposerClient->getDisplayAttribute(
1249 display.getDisplayId(), configs[i], DisplayAttribute::WIDTH);
1250 const auto& [heightStatus1, height1] = mComposerClient->getDisplayAttribute(
1251 display.getDisplayId(), configs[i], DisplayAttribute::HEIGHT);
1252 const auto& [vsyncPeriodStatus1, vsyncPeriod1] =
1253 mComposerClient->getDisplayAttribute(display.getDisplayId(), configs[i],
1254 DisplayAttribute::VSYNC_PERIOD);
1255 const auto& [groupStatus1, group1] = mComposerClient->getDisplayAttribute(
1256 display.getDisplayId(), configs[i], DisplayAttribute::CONFIG_GROUP);
1257
1258 const auto& [widthStatus2, width2] = mComposerClient->getDisplayAttribute(
1259 display.getDisplayId(), configs[j], DisplayAttribute::WIDTH);
1260 const auto& [heightStatus2, height2] = mComposerClient->getDisplayAttribute(
1261 display.getDisplayId(), configs[j], DisplayAttribute::HEIGHT);
1262 const auto& [vsyncPeriodStatus2, vsyncPeriod2] =
1263 mComposerClient->getDisplayAttribute(display.getDisplayId(), configs[j],
1264 DisplayAttribute::VSYNC_PERIOD);
1265 const auto& [groupStatus2, group2] = mComposerClient->getDisplayAttribute(
1266 display.getDisplayId(), configs[j], DisplayAttribute::CONFIG_GROUP);
1267
1268 ASSERT_FALSE(width1 == width2 && height1 == height2 &&
1269 vsyncPeriod1 == vsyncPeriod2 && group1 == group2);
1270 }
1271 }
1272 }
1273 }
1274
TEST_P(GraphicsComposerAidlTest,LayerLifecycleCapabilityNotSupportedOnOldVersions)1275 TEST_P(GraphicsComposerAidlTest, LayerLifecycleCapabilityNotSupportedOnOldVersions) {
1276 if (hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
1277 EXPECT_GE(getInterfaceVersion(), 3);
1278 }
1279 }
1280
1281 class GraphicsComposerAidlV2Test : public GraphicsComposerAidlTest {
1282 protected:
SetUp()1283 void SetUp() override {
1284 GraphicsComposerAidlTest::SetUp();
1285 if (getInterfaceVersion() <= 1) {
1286 GTEST_SKIP() << "Device interface version is expected to be >= 2";
1287 }
1288 }
1289 };
1290
TEST_P(GraphicsComposerAidlV2Test,GetOverlaySupport)1291 TEST_P(GraphicsComposerAidlV2Test, GetOverlaySupport) {
1292 const auto& [status, properties] = mComposerClient->getOverlaySupport();
1293 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
1294 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
1295 GTEST_SUCCEED() << "getOverlaySupport is not supported";
1296 return;
1297 }
1298
1299 ASSERT_TRUE(status.isOk());
1300 for (const auto& i : properties.combinations) {
1301 for (const auto standard : i.standards) {
1302 const auto val = static_cast<int32_t>(standard) &
1303 static_cast<int32_t>(common::Dataspace::STANDARD_MASK);
1304 ASSERT_TRUE(val == static_cast<int32_t>(standard));
1305 }
1306 for (const auto transfer : i.transfers) {
1307 const auto val = static_cast<int32_t>(transfer) &
1308 static_cast<int32_t>(common::Dataspace::TRANSFER_MASK);
1309 ASSERT_TRUE(val == static_cast<int32_t>(transfer));
1310 }
1311 for (const auto range : i.ranges) {
1312 const auto val = static_cast<int32_t>(range) &
1313 static_cast<int32_t>(common::Dataspace::RANGE_MASK);
1314 ASSERT_TRUE(val == static_cast<int32_t>(range));
1315 }
1316 }
1317 }
1318
1319 class GraphicsComposerAidlV3Test : public GraphicsComposerAidlTest {
1320 protected:
SetUp()1321 void SetUp() override {
1322 GraphicsComposerAidlTest::SetUp();
1323 if (getInterfaceVersion() <= 2) {
1324 GTEST_SKIP() << "Device interface version is expected to be >= 3";
1325 }
1326 }
1327 };
1328
TEST_P(GraphicsComposerAidlV3Test,GetDisplayConfigurations)1329 TEST_P(GraphicsComposerAidlV3Test, GetDisplayConfigurations) {
1330 for (const auto& display : mDisplays) {
1331 const auto& [status, displayConfigurations] =
1332 mComposerClient->getDisplayConfigurations(display.getDisplayId());
1333 EXPECT_TRUE(status.isOk());
1334 EXPECT_FALSE(displayConfigurations.empty());
1335
1336 const bool areAllModesARR =
1337 std::all_of(displayConfigurations.cbegin(), displayConfigurations.cend(),
1338 [](const auto& config) { return config.vrrConfig.has_value(); });
1339
1340 const bool areAllModesMRR =
1341 std::all_of(displayConfigurations.cbegin(), displayConfigurations.cend(),
1342 [](const auto& config) { return !config.vrrConfig.has_value(); });
1343
1344 EXPECT_TRUE(areAllModesARR || areAllModesMRR) << "Mixing MRR and ARR modes is not allowed";
1345
1346 for (const auto& displayConfig : displayConfigurations) {
1347 EXPECT_NE(-1, displayConfig.width);
1348 EXPECT_NE(-1, displayConfig.height);
1349 EXPECT_NE(-1, displayConfig.vsyncPeriod);
1350 EXPECT_NE(-1, displayConfig.configGroup);
1351 if (displayConfig.dpi) {
1352 EXPECT_NE(-1.f, displayConfig.dpi->x);
1353 EXPECT_NE(-1.f, displayConfig.dpi->y);
1354 }
1355 if (displayConfig.vrrConfig) {
1356 const auto& vrrConfig = *displayConfig.vrrConfig;
1357 EXPECT_GE(vrrConfig.minFrameIntervalNs, displayConfig.vsyncPeriod);
1358
1359 EXPECT_EQ(1, std::count_if(
1360 displayConfigurations.cbegin(), displayConfigurations.cend(),
1361 [displayConfig](const auto& config) {
1362 return config.configGroup == displayConfig.configGroup;
1363 }))
1364 << "There should be only one VRR mode in one ConfigGroup";
1365
1366 const auto verifyFrameIntervalIsDivisorOfVsync = [&](int32_t frameIntervalNs) {
1367 constexpr auto kThreshold = 0.05f; // 5%
1368 const auto ratio =
1369 static_cast<float>(frameIntervalNs) / displayConfig.vsyncPeriod;
1370 return ratio - std::round(ratio) <= kThreshold;
1371 };
1372
1373 EXPECT_TRUE(verifyFrameIntervalIsDivisorOfVsync(vrrConfig.minFrameIntervalNs));
1374
1375 if (vrrConfig.frameIntervalPowerHints) {
1376 const auto& frameIntervalPowerHints = *vrrConfig.frameIntervalPowerHints;
1377 EXPECT_FALSE(frameIntervalPowerHints.empty());
1378
1379 const auto minFrameInterval = *min_element(frameIntervalPowerHints.cbegin(),
1380 frameIntervalPowerHints.cend());
1381 EXPECT_LE(minFrameInterval->frameIntervalNs,
1382 ComposerClientWrapper::kMaxFrameIntervalNs);
1383 const auto maxFrameInterval = *max_element(frameIntervalPowerHints.cbegin(),
1384 frameIntervalPowerHints.cend());
1385 EXPECT_GE(maxFrameInterval->frameIntervalNs, vrrConfig.minFrameIntervalNs);
1386
1387 EXPECT_TRUE(std::all_of(frameIntervalPowerHints.cbegin(),
1388 frameIntervalPowerHints.cend(),
1389 [&](const auto& frameIntervalPowerHint) {
1390 return verifyFrameIntervalIsDivisorOfVsync(
1391 frameIntervalPowerHint->frameIntervalNs);
1392 }));
1393 }
1394
1395 if (vrrConfig.notifyExpectedPresentConfig) {
1396 const auto& notifyExpectedPresentConfig =
1397 *vrrConfig.notifyExpectedPresentConfig;
1398 EXPECT_GE(notifyExpectedPresentConfig.headsUpNs, 0);
1399 EXPECT_GE(notifyExpectedPresentConfig.timeoutNs, 0);
1400 }
1401 }
1402 }
1403 }
1404 }
1405
TEST_P(GraphicsComposerAidlV3Test,GetDisplayConfigsIsSubsetOfGetDisplayConfigurations)1406 TEST_P(GraphicsComposerAidlV3Test, GetDisplayConfigsIsSubsetOfGetDisplayConfigurations) {
1407 for (const auto& display : mDisplays) {
1408 const auto& [status, displayConfigurations] =
1409 mComposerClient->getDisplayConfigurations(display.getDisplayId());
1410 EXPECT_TRUE(status.isOk());
1411
1412 const auto& [legacyConfigStatus, legacyConfigs] =
1413 mComposerClient->getDisplayConfigs(display.getDisplayId());
1414 EXPECT_TRUE(legacyConfigStatus.isOk());
1415 EXPECT_FALSE(legacyConfigs.empty());
1416 EXPECT_TRUE(legacyConfigs.size() <= displayConfigurations.size());
1417
1418 for (const auto legacyConfigId : legacyConfigs) {
1419 const auto& legacyWidth = mComposerClient->getDisplayAttribute(
1420 display.getDisplayId(), legacyConfigId, DisplayAttribute::WIDTH);
1421 const auto& legacyHeight = mComposerClient->getDisplayAttribute(
1422 display.getDisplayId(), legacyConfigId, DisplayAttribute::HEIGHT);
1423 const auto& legacyVsyncPeriod = mComposerClient->getDisplayAttribute(
1424 display.getDisplayId(), legacyConfigId, DisplayAttribute::VSYNC_PERIOD);
1425 const auto& legacyConfigGroup = mComposerClient->getDisplayAttribute(
1426 display.getDisplayId(), legacyConfigId, DisplayAttribute::CONFIG_GROUP);
1427 const auto& legacyDpiX = mComposerClient->getDisplayAttribute(
1428 display.getDisplayId(), legacyConfigId, DisplayAttribute::DPI_X);
1429 const auto& legacyDpiY = mComposerClient->getDisplayAttribute(
1430 display.getDisplayId(), legacyConfigId, DisplayAttribute::DPI_Y);
1431
1432 EXPECT_TRUE(legacyWidth.first.isOk() && legacyHeight.first.isOk() &&
1433 legacyVsyncPeriod.first.isOk() && legacyConfigGroup.first.isOk());
1434
1435 EXPECT_TRUE(std::any_of(
1436 displayConfigurations.begin(), displayConfigurations.end(),
1437 [&](const auto& displayConfiguration) {
1438 const bool requiredAttributesPredicate =
1439 displayConfiguration.configId == legacyConfigId &&
1440 displayConfiguration.width == legacyWidth.second &&
1441 displayConfiguration.height == legacyHeight.second &&
1442 displayConfiguration.vsyncPeriod == legacyVsyncPeriod.second &&
1443 displayConfiguration.configGroup == legacyConfigGroup.second;
1444
1445 if (!requiredAttributesPredicate) {
1446 // Required attributes did not match
1447 return false;
1448 }
1449
1450 // Check optional attributes
1451 const auto& [legacyDpiXStatus, legacyDpiXValue] = legacyDpiX;
1452 const auto& [legacyDpiYStatus, legacyDpiYValue] = legacyDpiY;
1453 if (displayConfiguration.dpi) {
1454 if (!legacyDpiXStatus.isOk() || !legacyDpiYStatus.isOk()) {
1455 // getDisplayAttribute failed for optional attributes
1456 return false;
1457 }
1458
1459 // DPI values in DisplayConfigurations are not scaled (* 1000.f)
1460 // the way they are in the legacy DisplayConfigs.
1461 constexpr float kEpsilon = 0.001f;
1462 return std::abs(displayConfiguration.dpi->x -
1463 legacyDpiXValue / 1000.f) < kEpsilon &&
1464 std::abs(displayConfiguration.dpi->y -
1465 legacyDpiYValue / 1000.f) < kEpsilon;
1466 } else {
1467 return !legacyDpiXStatus.isOk() && !legacyDpiYStatus.isOk() &&
1468 EX_SERVICE_SPECIFIC == legacyDpiXStatus.getExceptionCode() &&
1469 EX_SERVICE_SPECIFIC == legacyDpiYStatus.getExceptionCode() &&
1470 IComposerClient::EX_UNSUPPORTED ==
1471 legacyDpiXStatus.getServiceSpecificError() &&
1472 IComposerClient::EX_UNSUPPORTED ==
1473 legacyDpiYStatus.getServiceSpecificError();
1474 }
1475 }));
1476 }
1477 }
1478 }
1479
1480 // Tests for Command.
1481 class GraphicsComposerAidlCommandTest : public GraphicsComposerAidlTest {
1482 protected:
TearDown()1483 void TearDown() override {
1484 ASSERT_FALSE(mDisplays.empty());
1485 std::unordered_map<int64_t, ComposerClientWriter*> displayWriters;
1486
1487 for (const auto& display : mDisplays) {
1488 auto& reader = getReader(display.getDisplayId());
1489 ASSERT_TRUE(reader.takeErrors().empty());
1490 ASSERT_TRUE(reader.takeChangedCompositionTypes(display.getDisplayId()).empty());
1491 displayWriters.emplace(display.getDisplayId(), &getWriter(display.getDisplayId()));
1492 }
1493 ASSERT_TRUE(mComposerClient->tearDown(displayWriters));
1494 ASSERT_NO_FATAL_FAILURE(GraphicsComposerAidlTest::TearDown());
1495 }
1496
execute()1497 void execute() {
1498 for (auto& [displayId, writer] : mWriters) {
1499 std::vector<CommandResultPayload> payloads;
1500 executeInternal(writer, payloads);
1501 getReader(displayId).parse(std::move(payloads));
1502 }
1503 }
1504
execute(ComposerClientWriter & writer,ComposerClientReader & reader)1505 void execute(ComposerClientWriter& writer, ComposerClientReader& reader) {
1506 std::vector<CommandResultPayload> payloads;
1507 executeInternal(writer, payloads);
1508 reader.parse(std::move(payloads));
1509 }
1510
toTimePoint(nsecs_t time)1511 static inline auto toTimePoint(nsecs_t time) {
1512 return std::chrono::time_point<std::chrono::steady_clock>(std::chrono::nanoseconds(time));
1513 }
1514
forEachTwoConfigs(int64_t display,std::function<void (int32_t,int32_t)> func)1515 void forEachTwoConfigs(int64_t display, std::function<void(int32_t, int32_t)> func) {
1516 const auto& [status, displayConfigs] = mComposerClient->getDisplayConfigs(display);
1517 ASSERT_TRUE(status.isOk());
1518 for (const int32_t config1 : displayConfigs) {
1519 for (const int32_t config2 : displayConfigs) {
1520 if (config1 != config2) {
1521 func(config1, config2);
1522 }
1523 }
1524 }
1525 }
1526
waitForVsyncPeriodChange(int64_t display,const VsyncPeriodChangeTimeline & timeline,int64_t desiredTimeNanos,int64_t oldPeriodNanos,int64_t newPeriodNanos)1527 void waitForVsyncPeriodChange(int64_t display, const VsyncPeriodChangeTimeline& timeline,
1528 int64_t desiredTimeNanos, int64_t oldPeriodNanos,
1529 int64_t newPeriodNanos) {
1530 const auto kChangeDeadline = toTimePoint(timeline.newVsyncAppliedTimeNanos) + 100ms;
1531 while (std::chrono::steady_clock::now() <= kChangeDeadline) {
1532 const auto& [status, vsyncPeriodNanos] =
1533 mComposerClient->getDisplayVsyncPeriod(display);
1534 EXPECT_TRUE(status.isOk());
1535 if (systemTime() <= desiredTimeNanos) {
1536 EXPECT_EQ(vsyncPeriodNanos, oldPeriodNanos);
1537 } else if (vsyncPeriodNanos == newPeriodNanos) {
1538 break;
1539 }
1540 std::this_thread::sleep_for(std::chrono::nanoseconds(oldPeriodNanos));
1541 }
1542 }
1543
checkIfCallbackRefreshRateChangedDebugEnabledReceived(std::function<bool (RefreshRateChangedDebugData)> filter)1544 bool checkIfCallbackRefreshRateChangedDebugEnabledReceived(
1545 std::function<bool(RefreshRateChangedDebugData)> filter) {
1546 const auto list = mComposerClient->takeListOfRefreshRateChangedDebugData();
1547 return std::any_of(list.begin(), list.end(), [&](auto refreshRateChangedDebugData) {
1548 return filter(refreshRateChangedDebugData);
1549 });
1550 }
1551
allocate(int32_t displayWidth,int32_t displayHeight,::android::PixelFormat pixelFormat)1552 sp<GraphicBuffer> allocate(int32_t displayWidth, int32_t displayHeight,
1553 ::android::PixelFormat pixelFormat) {
1554 return sp<GraphicBuffer>::make(
1555 static_cast<uint32_t>(displayWidth), static_cast<uint32_t>(displayHeight),
1556 pixelFormat,
1557 /*layerCount*/ 1U,
1558 static_cast<uint64_t>(common::BufferUsage::CPU_WRITE_OFTEN) |
1559 static_cast<uint64_t>(common::BufferUsage::CPU_READ_OFTEN) |
1560 static_cast<uint64_t>(common::BufferUsage::COMPOSER_OVERLAY),
1561 "VtsHalGraphicsComposer3_TargetTest");
1562 }
1563
sendRefreshFrame(const DisplayWrapper & display,const VsyncPeriodChangeTimeline * timeline)1564 void sendRefreshFrame(const DisplayWrapper& display,
1565 const VsyncPeriodChangeTimeline* timeline) {
1566 if (timeline != nullptr) {
1567 // Refresh time should be before newVsyncAppliedTimeNanos
1568 EXPECT_LT(timeline->refreshTimeNanos, timeline->newVsyncAppliedTimeNanos);
1569
1570 std::this_thread::sleep_until(toTimePoint(timeline->refreshTimeNanos));
1571 }
1572
1573 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
1574 EXPECT_TRUE(mComposerClient
1575 ->setColorMode(display.getDisplayId(), ColorMode::NATIVE,
1576 RenderIntent::COLORIMETRIC)
1577 .isOk());
1578
1579 auto& writer = getWriter(display.getDisplayId());
1580 const auto& [status, layer] =
1581 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
1582 EXPECT_TRUE(status.isOk());
1583 {
1584 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
1585 ::android::PIXEL_FORMAT_RGBA_8888);
1586 ASSERT_NE(nullptr, buffer);
1587 ASSERT_EQ(::android::OK, buffer->initCheck());
1588 ASSERT_NE(nullptr, buffer->handle);
1589
1590 configureLayer(display, layer, Composition::DEVICE, display.getFrameRect(),
1591 display.getCrop());
1592 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, buffer->handle,
1593 /*acquireFence*/ -1);
1594 writer.setLayerDataspace(display.getDisplayId(), layer, common::Dataspace::UNKNOWN);
1595
1596 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
1597 ComposerClientWrapper::kNoFrameIntervalNs);
1598 execute();
1599 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1600
1601 writer.presentDisplay(display.getDisplayId());
1602 execute();
1603 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1604 }
1605
1606 {
1607 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
1608 ::android::PIXEL_FORMAT_RGBA_8888);
1609 ASSERT_NE(nullptr, buffer->handle);
1610
1611 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, buffer->handle,
1612 /*acquireFence*/ -1);
1613 writer.setLayerSurfaceDamage(display.getDisplayId(), layer,
1614 std::vector<Rect>(1, {0, 0, 10, 10}));
1615 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
1616 ComposerClientWrapper::kNoFrameIntervalNs);
1617 execute();
1618 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1619
1620 writer.presentDisplay(display.getDisplayId());
1621 execute();
1622 }
1623
1624 EXPECT_TRUE(mComposerClient->destroyLayer(display.getDisplayId(), layer, &writer).isOk());
1625 }
1626
presentAndGetFence(std::optional<ClockMonotonicTimestamp> expectedPresentTime,int64_t displayId,int32_t frameIntervalNs=ComposerClientWrapper::kNoFrameIntervalNs)1627 sp<::android::Fence> presentAndGetFence(
1628 std::optional<ClockMonotonicTimestamp> expectedPresentTime, int64_t displayId,
1629 int32_t frameIntervalNs = ComposerClientWrapper::kNoFrameIntervalNs) {
1630 auto& writer = getWriter(displayId);
1631 writer.validateDisplay(displayId, expectedPresentTime, frameIntervalNs);
1632 execute();
1633 EXPECT_TRUE(getReader(displayId).takeErrors().empty());
1634
1635 writer.presentDisplay(displayId);
1636 execute();
1637 EXPECT_TRUE(getReader(displayId).takeErrors().empty());
1638
1639 auto presentFence = getReader(displayId).takePresentFence(displayId);
1640 // take ownership
1641 const int fenceOwner = presentFence.get();
1642 *presentFence.getR() = -1;
1643 EXPECT_NE(-1, fenceOwner);
1644 return sp<::android::Fence>::make(fenceOwner);
1645 }
1646
getVsyncPeriod(int64_t displayId)1647 int32_t getVsyncPeriod(int64_t displayId) {
1648 const auto& [status, activeConfig] = mComposerClient->getActiveConfig(displayId);
1649 EXPECT_TRUE(status.isOk());
1650
1651 const auto& [vsyncPeriodStatus, vsyncPeriod] = mComposerClient->getDisplayAttribute(
1652 displayId, activeConfig, DisplayAttribute::VSYNC_PERIOD);
1653 EXPECT_TRUE(vsyncPeriodStatus.isOk());
1654 return vsyncPeriod;
1655 }
1656
createOnScreenLayer(const DisplayWrapper & display,Composition composition=Composition::DEVICE)1657 int64_t createOnScreenLayer(const DisplayWrapper& display,
1658 Composition composition = Composition::DEVICE) {
1659 auto& writer = getWriter(display.getDisplayId());
1660 const auto& [status, layer] =
1661 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
1662 EXPECT_TRUE(status.isOk());
1663 Rect displayFrame{0, 0, display.getDisplayWidth(), display.getDisplayHeight()};
1664 FRect cropRect{0, 0, (float)display.getDisplayWidth(), (float)display.getDisplayHeight()};
1665 configureLayer(display, layer, composition, displayFrame, cropRect);
1666
1667 writer.setLayerDataspace(display.getDisplayId(), layer, common::Dataspace::UNKNOWN);
1668 return layer;
1669 }
1670
sendBufferUpdate(int64_t layer,int64_t displayId,int32_t displayWidth,int32_t displayHeight)1671 void sendBufferUpdate(int64_t layer, int64_t displayId, int32_t displayWidth,
1672 int32_t displayHeight) {
1673 const auto buffer =
1674 allocate(displayWidth, displayHeight, ::android::PIXEL_FORMAT_RGBA_8888);
1675 ASSERT_NE(nullptr, buffer->handle);
1676
1677 auto& writer = getWriter(displayId);
1678 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
1679 /*acquireFence*/ -1);
1680
1681 const sp<::android::Fence> presentFence =
1682 presentAndGetFence(ComposerClientWriter::kNoTimestamp, displayId);
1683 presentFence->waitForever(LOG_TAG);
1684 }
1685
hasDisplayCapability(int64_t display,DisplayCapability cap)1686 bool hasDisplayCapability(int64_t display, DisplayCapability cap) {
1687 const auto& [status, capabilities] = mComposerClient->getDisplayCapabilities(display);
1688 EXPECT_TRUE(status.isOk());
1689
1690 return std::find(capabilities.begin(), capabilities.end(), cap) != capabilities.end();
1691 }
1692
Test_setActiveConfigWithConstraints(const TestParameters & params)1693 void Test_setActiveConfigWithConstraints(const TestParameters& params) {
1694 for (DisplayWrapper& display : mDisplays) {
1695 forEachTwoConfigs(display.getDisplayId(), [&](int32_t config1, int32_t config2) {
1696 EXPECT_TRUE(mComposerClient->setActiveConfig(&display, config1).isOk());
1697 sendRefreshFrame(display, nullptr);
1698
1699 const auto displayConfig1 = display.getDisplayConfig(config1);
1700 int32_t vsyncPeriod1 = displayConfig1.vsyncPeriod;
1701 int32_t configGroup1 = displayConfig1.configGroup;
1702
1703 const auto displayConfig2 = display.getDisplayConfig(config2);
1704 int32_t vsyncPeriod2 = displayConfig2.vsyncPeriod;
1705 int32_t configGroup2 = displayConfig2.configGroup;
1706
1707 if (vsyncPeriod1 == vsyncPeriod2) {
1708 return; // continue
1709 }
1710
1711 if ((!displayConfig1.vrrConfigOpt && displayConfig2.vrrConfigOpt) ||
1712 (displayConfig1.vrrConfigOpt && !displayConfig2.vrrConfigOpt)) {
1713 // switching between vrr to non-vrr modes
1714 return; // continue
1715 }
1716
1717 // We don't allow delayed change when changing config groups
1718 if (params.delayForChange > 0 && configGroup1 != configGroup2) {
1719 return; // continue
1720 }
1721
1722 VsyncPeriodChangeConstraints constraints = {
1723 .desiredTimeNanos = systemTime() + params.delayForChange,
1724 .seamlessRequired = false};
1725 const auto& [status, timeline] = mComposerClient->setActiveConfigWithConstraints(
1726 &display, config2, constraints);
1727 EXPECT_TRUE(status.isOk());
1728
1729 EXPECT_TRUE(timeline.newVsyncAppliedTimeNanos >= constraints.desiredTimeNanos);
1730 // Refresh rate should change within a reasonable time
1731 constexpr std::chrono::nanoseconds kReasonableTimeForChange = 1s; // 1 second
1732 EXPECT_TRUE(timeline.newVsyncAppliedTimeNanos - constraints.desiredTimeNanos <=
1733 kReasonableTimeForChange.count());
1734
1735 if (timeline.refreshRequired) {
1736 if (params.refreshMiss) {
1737 // Miss the refresh frame on purpose to make sure the implementation sends a
1738 // callback
1739 std::this_thread::sleep_until(toTimePoint(timeline.refreshTimeNanos) +
1740 100ms);
1741 }
1742 sendRefreshFrame(display, &timeline);
1743 }
1744 waitForVsyncPeriodChange(display.getDisplayId(), timeline,
1745 constraints.desiredTimeNanos, vsyncPeriod1, vsyncPeriod2);
1746
1747 // At this point the refresh rate should have changed already, however in rare
1748 // cases the implementation might have missed the deadline. In this case a new
1749 // timeline should have been provided.
1750 auto newTimeline = mComposerClient->takeLastVsyncPeriodChangeTimeline();
1751 if (timeline.refreshRequired && params.refreshMiss) {
1752 EXPECT_TRUE(newTimeline.has_value());
1753 }
1754
1755 if (newTimeline.has_value()) {
1756 if (newTimeline->refreshRequired) {
1757 sendRefreshFrame(display, &newTimeline.value());
1758 }
1759 waitForVsyncPeriodChange(display.getDisplayId(), newTimeline.value(),
1760 constraints.desiredTimeNanos, vsyncPeriod1,
1761 vsyncPeriod2);
1762 }
1763
1764 const auto& [vsyncPeriodNanosStatus, vsyncPeriodNanos] =
1765 mComposerClient->getDisplayVsyncPeriod(display.getDisplayId());
1766 EXPECT_TRUE(vsyncPeriodNanosStatus.isOk());
1767 EXPECT_EQ(vsyncPeriodNanos, vsyncPeriod2);
1768 });
1769 }
1770 }
1771
Test_expectedPresentTime(std::optional<int> framesDelay)1772 void Test_expectedPresentTime(std::optional<int> framesDelay) {
1773 if (hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) {
1774 GTEST_SUCCEED() << "Device has unreliable present fences capability, skipping";
1775 return;
1776 }
1777
1778 for (const auto& display : mDisplays) {
1779 ASSERT_TRUE(
1780 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
1781
1782 const auto vsyncPeriod = getVsyncPeriod(display.getDisplayId());
1783
1784 const auto buffer1 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
1785 ::android::PIXEL_FORMAT_RGBA_8888);
1786 const auto buffer2 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
1787 ::android::PIXEL_FORMAT_RGBA_8888);
1788 ASSERT_NE(nullptr, buffer1);
1789 ASSERT_NE(nullptr, buffer2);
1790
1791 const auto layer = createOnScreenLayer(display);
1792 auto& writer = getWriter(display.getDisplayId());
1793 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, buffer1->handle,
1794 /*acquireFence*/ -1);
1795 const sp<::android::Fence> presentFence1 =
1796 presentAndGetFence(ComposerClientWriter::kNoTimestamp, display.getDisplayId());
1797 presentFence1->waitForever(LOG_TAG);
1798
1799 auto expectedPresentTime = presentFence1->getSignalTime() + vsyncPeriod;
1800 if (framesDelay.has_value()) {
1801 expectedPresentTime += *framesDelay * vsyncPeriod;
1802 }
1803
1804 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, buffer2->handle,
1805 /*acquireFence*/ -1);
1806 const auto setExpectedPresentTime = [&]() -> std::optional<ClockMonotonicTimestamp> {
1807 if (!framesDelay.has_value()) {
1808 return ComposerClientWriter::kNoTimestamp;
1809 } else if (*framesDelay == 0) {
1810 return ClockMonotonicTimestamp{0};
1811 }
1812 return ClockMonotonicTimestamp{expectedPresentTime};
1813 }();
1814
1815 const sp<::android::Fence> presentFence2 =
1816 presentAndGetFence(setExpectedPresentTime, display.getDisplayId());
1817 presentFence2->waitForever(LOG_TAG);
1818
1819 const auto actualPresentTime = presentFence2->getSignalTime();
1820 EXPECT_GE(actualPresentTime, expectedPresentTime - vsyncPeriod / 2);
1821
1822 ASSERT_TRUE(
1823 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::OFF).isOk());
1824 }
1825 }
1826
forEachNotifyExpectedPresentConfig(std::function<void (DisplayWrapper &,const DisplayConfiguration &)> func)1827 void forEachNotifyExpectedPresentConfig(
1828 std::function<void(DisplayWrapper&, const DisplayConfiguration&)> func) {
1829 for (DisplayWrapper& display : mDisplays) {
1830 const auto displayId = display.getDisplayId();
1831 EXPECT_TRUE(mComposerClient->setPowerMode(displayId, PowerMode::ON).isOk());
1832 const auto& [status, displayConfigurations] =
1833 mComposerClient->getDisplayConfigurations(displayId);
1834 EXPECT_TRUE(status.isOk());
1835 EXPECT_FALSE(displayConfigurations.empty());
1836 for (const auto& config : displayConfigurations) {
1837 if (config.vrrConfig && config.vrrConfig->notifyExpectedPresentConfig) {
1838 const auto [vsyncPeriodStatus, oldVsyncPeriod] =
1839 mComposerClient->getDisplayVsyncPeriod(displayId);
1840 ASSERT_TRUE(vsyncPeriodStatus.isOk());
1841 const auto& [timelineStatus, timeline] =
1842 mComposerClient->setActiveConfigWithConstraints(
1843 &display, config.configId,
1844 VsyncPeriodChangeConstraints{.seamlessRequired = false});
1845 ASSERT_TRUE(timelineStatus.isOk());
1846 if (timeline.refreshRequired) {
1847 sendRefreshFrame(display, &timeline);
1848 }
1849 waitForVsyncPeriodChange(displayId, timeline, systemTime(), oldVsyncPeriod,
1850 config.vsyncPeriod);
1851 func(display, config);
1852 }
1853 }
1854 EXPECT_TRUE(
1855 mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::OFF).isOk());
1856 }
1857 }
1858
configureLayer(const DisplayWrapper & display,int64_t layer,Composition composition,const Rect & displayFrame,const FRect & cropRect)1859 void configureLayer(const DisplayWrapper& display, int64_t layer, Composition composition,
1860 const Rect& displayFrame, const FRect& cropRect) {
1861 auto& writer = getWriter(display.getDisplayId());
1862 writer.setLayerCompositionType(display.getDisplayId(), layer, composition);
1863 writer.setLayerDisplayFrame(display.getDisplayId(), layer, displayFrame);
1864 writer.setLayerPlaneAlpha(display.getDisplayId(), layer, /*alpha*/ 1);
1865 writer.setLayerSourceCrop(display.getDisplayId(), layer, cropRect);
1866 writer.setLayerTransform(display.getDisplayId(), layer, static_cast<Transform>(0));
1867 writer.setLayerVisibleRegion(display.getDisplayId(), layer,
1868 std::vector<Rect>(1, displayFrame));
1869 writer.setLayerZOrder(display.getDisplayId(), layer, /*z*/ 10);
1870 writer.setLayerBlendMode(display.getDisplayId(), layer, BlendMode::NONE);
1871 writer.setLayerSurfaceDamage(display.getDisplayId(), layer,
1872 std::vector<Rect>(1, displayFrame));
1873 }
1874 // clang-format off
1875 const std::array<float, 16> kIdentity = {{
1876 1.0f, 0.0f, 0.0f, 0.0f,
1877 0.0f, 1.0f, 0.0f, 0.0f,
1878 0.0f, 0.0f, 1.0f, 0.0f,
1879 0.0f, 0.0f, 0.0f, 1.0f,
1880 }};
1881 // clang-format on
1882
getWriter(int64_t display)1883 ComposerClientWriter& getWriter(int64_t display) {
1884 std::lock_guard guard{mReadersWritersMutex};
1885 auto [it, _] = mWriters.try_emplace(display, display);
1886 return it->second;
1887 }
1888
getReader(int64_t display)1889 ComposerClientReader& getReader(int64_t display) {
1890 std::lock_guard guard{mReadersWritersMutex};
1891 auto [it, _] = mReaders.try_emplace(display, display);
1892 return it->second;
1893 }
1894
1895 private:
executeInternal(ComposerClientWriter & writer,std::vector<CommandResultPayload> & payloads)1896 void executeInternal(ComposerClientWriter& writer,
1897 std::vector<CommandResultPayload>& payloads) {
1898 auto commands = writer.takePendingCommands();
1899 if (commands.empty()) {
1900 return;
1901 }
1902
1903 auto [status, results] = mComposerClient->executeCommands(commands);
1904 ASSERT_TRUE(status.isOk()) << "executeCommands failed " << status.getDescription();
1905
1906 payloads.reserve(payloads.size() + results.size());
1907 payloads.insert(payloads.end(), std::make_move_iterator(results.begin()),
1908 std::make_move_iterator(results.end()));
1909 }
1910
1911 // Guards access to the map itself. Callers must ensure not to attempt to
1912 // - modify the same writer from multiple threads
1913 // - insert a new writer into the map during concurrent access, which would invalidate
1914 // references from other threads
1915 std::mutex mReadersWritersMutex;
1916 std::unordered_map<int64_t, ComposerClientWriter> mWriters GUARDED_BY(mReadersWritersMutex);
1917 std::unordered_map<int64_t, ComposerClientReader> mReaders GUARDED_BY(mReadersWritersMutex);
1918 };
1919
TEST_P(GraphicsComposerAidlCommandTest,SetColorTransform)1920 TEST_P(GraphicsComposerAidlCommandTest, SetColorTransform) {
1921 for (const auto& display : mDisplays) {
1922 auto& writer = getWriter(display.getDisplayId());
1923 writer.setColorTransform(display.getDisplayId(), kIdentity.data());
1924 execute();
1925 }
1926 }
1927
TEST_P(GraphicsComposerAidlCommandTest,SetLayerColorTransform)1928 TEST_P(GraphicsComposerAidlCommandTest, SetLayerColorTransform) {
1929 for (const auto& display : mDisplays) {
1930 auto& writer = getWriter(display.getDisplayId());
1931 const auto& [status, layer] =
1932 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
1933 EXPECT_TRUE(status.isOk());
1934 writer.setLayerColorTransform(display.getDisplayId(), layer, kIdentity.data());
1935 execute();
1936
1937 const auto errors = getReader(display.getDisplayId()).takeErrors();
1938 if (errors.size() == 1 && errors[0].errorCode == IComposerClient::EX_UNSUPPORTED) {
1939 ALOGI("setLayerColorTransform is not supported on display %" PRId64,
1940 display.getDisplayId());
1941 continue;
1942 }
1943 }
1944 }
1945
TEST_P(GraphicsComposerAidlCommandTest,SetDisplayBrightness)1946 TEST_P(GraphicsComposerAidlCommandTest, SetDisplayBrightness) {
1947 for (const auto& display : mDisplays) {
1948 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
1949 const auto& [status, capabilities] =
1950 mComposerClient->getDisplayCapabilities(display.getDisplayId());
1951 ASSERT_TRUE(status.isOk());
1952 bool brightnessSupport = std::find(capabilities.begin(), capabilities.end(),
1953 DisplayCapability::BRIGHTNESS) != capabilities.end();
1954 auto& writer = getWriter(display.getDisplayId());
1955 if (!brightnessSupport) {
1956 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ 0.5f, -1.f);
1957 execute();
1958 const auto errors = getReader(display.getDisplayId()).takeErrors();
1959 ASSERT_EQ(1, errors.size());
1960 EXPECT_EQ(IComposerClient::EX_UNSUPPORTED, errors[0].errorCode);
1961 ALOGI("SetDisplayBrightness is not supported on display %" PRId64,
1962 display.getDisplayId());
1963 continue;
1964 }
1965
1966 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ 0.0f, -1.f);
1967 execute();
1968 EXPECT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1969
1970 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ 0.5f, -1.f);
1971 execute();
1972 EXPECT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1973
1974 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ 1.0f, -1.f);
1975 execute();
1976 EXPECT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1977
1978 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ -1.0f, -1.f);
1979 execute();
1980 EXPECT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
1981
1982 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ 2.0f, -1.f);
1983 execute();
1984 {
1985 const auto errors = getReader(display.getDisplayId()).takeErrors();
1986 ASSERT_EQ(1, errors.size());
1987 EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
1988 }
1989
1990 writer.setDisplayBrightness(display.getDisplayId(), /*brightness*/ 2.0f, -1.f);
1991 execute();
1992 {
1993 const auto errors = getReader(display.getDisplayId()).takeErrors();
1994 ASSERT_EQ(1, errors.size());
1995 EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
1996 }
1997 }
1998 }
1999
TEST_P(GraphicsComposerAidlCommandTest,SetClientTarget)2000 TEST_P(GraphicsComposerAidlCommandTest, SetClientTarget) {
2001 for (const auto& display : mDisplays) {
2002 EXPECT_TRUE(
2003 mComposerClient->setClientTargetSlotCount(display.getDisplayId(), kBufferSlotCount)
2004 .isOk());
2005
2006 auto& writer = getWriter(display.getDisplayId());
2007 writer.setClientTarget(display.getDisplayId(), /*slot*/ 0, nullptr, /*acquireFence*/ -1,
2008 Dataspace::UNKNOWN, std::vector<Rect>(), 1.0f);
2009
2010 execute();
2011 }
2012 }
2013
TEST_P(GraphicsComposerAidlCommandTest,SetOutputBuffer)2014 TEST_P(GraphicsComposerAidlCommandTest, SetOutputBuffer) {
2015 const auto& [status, virtualDisplayCount] = mComposerClient->getMaxVirtualDisplayCount();
2016 EXPECT_TRUE(status.isOk());
2017 if (virtualDisplayCount == 0) {
2018 GTEST_SUCCEED() << "no virtual display support";
2019 return;
2020 }
2021
2022 const auto& [displayStatus, display] = mComposerClient->createVirtualDisplay(
2023 /*width*/ 64, /*height*/ 64, common::PixelFormat::IMPLEMENTATION_DEFINED,
2024 kBufferSlotCount);
2025 EXPECT_TRUE(displayStatus.isOk());
2026
2027 // Use dimensions from the primary display
2028 const DisplayWrapper& primary = mDisplays[0];
2029 const auto buffer = allocate(primary.getDisplayWidth(), primary.getDisplayHeight(),
2030 ::android::PIXEL_FORMAT_RGBA_8888);
2031 const auto handle = buffer->handle;
2032 auto& writer = getWriter(display.display);
2033 writer.setOutputBuffer(display.display, /*slot*/ 0, handle,
2034 /*releaseFence*/ -1);
2035 execute();
2036 }
2037
TEST_P(GraphicsComposerAidlCommandTest,ValidDisplay)2038 TEST_P(GraphicsComposerAidlCommandTest, ValidDisplay) {
2039 for (const auto& display : mDisplays) {
2040 auto& writer = getWriter(display.getDisplayId());
2041 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
2042 ComposerClientWrapper::kNoFrameIntervalNs);
2043 execute();
2044 }
2045 }
2046
TEST_P(GraphicsComposerAidlCommandTest,AcceptDisplayChanges)2047 TEST_P(GraphicsComposerAidlCommandTest, AcceptDisplayChanges) {
2048 for (const auto& display : mDisplays) {
2049 auto& writer = getWriter(display.getDisplayId());
2050 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
2051 ComposerClientWrapper::kNoFrameIntervalNs);
2052 writer.acceptDisplayChanges(display.getDisplayId());
2053 execute();
2054 }
2055 }
2056
TEST_P(GraphicsComposerAidlCommandTest,PresentDisplay)2057 TEST_P(GraphicsComposerAidlCommandTest, PresentDisplay) {
2058 for (const auto& display : mDisplays) {
2059 auto& writer = getWriter(display.getDisplayId());
2060 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
2061 ComposerClientWrapper::kNoFrameIntervalNs);
2062 writer.presentDisplay(display.getDisplayId());
2063 execute();
2064 }
2065 }
2066
2067 /**
2068 * Test IComposerClient::Command::PRESENT_DISPLAY
2069 *
2070 * Test that IComposerClient::Command::PRESENT_DISPLAY works without
2071 * additional call to validateDisplay when only the layer buffer handle and
2072 * surface damage have been set
2073 */
TEST_P(GraphicsComposerAidlCommandTest,PresentDisplayNoLayerStateChanges)2074 TEST_P(GraphicsComposerAidlCommandTest, PresentDisplayNoLayerStateChanges) {
2075 for (const auto& display : mDisplays) {
2076 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
2077
2078 const auto& [renderIntentsStatus, renderIntents] =
2079 mComposerClient->getRenderIntents(display.getDisplayId(), ColorMode::NATIVE);
2080 EXPECT_TRUE(renderIntentsStatus.isOk());
2081 auto& writer = getWriter(display.getDisplayId());
2082 for (auto intent : renderIntents) {
2083 EXPECT_TRUE(
2084 mComposerClient->setColorMode(display.getDisplayId(), ColorMode::NATIVE, intent)
2085 .isOk());
2086
2087 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2088 ::android::PIXEL_FORMAT_RGBA_8888);
2089 const auto handle = buffer->handle;
2090 ASSERT_NE(nullptr, handle);
2091
2092 const auto& [layerStatus, layer] =
2093 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2094 EXPECT_TRUE(layerStatus.isOk());
2095
2096 Rect displayFrame{0, 0, display.getDisplayWidth(), display.getDisplayHeight()};
2097 FRect cropRect{0, 0, (float)display.getDisplayWidth(),
2098 (float)display.getDisplayHeight()};
2099 configureLayer(display, layer, Composition::CURSOR, displayFrame, cropRect);
2100 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, handle,
2101 /*acquireFence*/ -1);
2102 writer.setLayerDataspace(display.getDisplayId(), layer, Dataspace::UNKNOWN);
2103 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
2104 ComposerClientWrapper::kNoFrameIntervalNs);
2105 execute();
2106 if (!getReader(display.getDisplayId())
2107 .takeChangedCompositionTypes(display.getDisplayId())
2108 .empty()) {
2109 GTEST_SUCCEED() << "Composition change requested, skipping test";
2110 return;
2111 }
2112
2113 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2114 writer.presentDisplay(display.getDisplayId());
2115 execute();
2116 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2117
2118 const auto buffer2 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2119 ::android::PIXEL_FORMAT_RGBA_8888);
2120 const auto handle2 = buffer2->handle;
2121 ASSERT_NE(nullptr, handle2);
2122 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, handle2,
2123 /*acquireFence*/ -1);
2124 writer.setLayerSurfaceDamage(display.getDisplayId(), layer,
2125 std::vector<Rect>(1, {0, 0, 10, 10}));
2126 writer.presentDisplay(display.getDisplayId());
2127 execute();
2128 }
2129 }
2130 }
2131
TEST_P(GraphicsComposerAidlCommandTest,SetLayerCursorPosition)2132 TEST_P(GraphicsComposerAidlCommandTest, SetLayerCursorPosition) {
2133 for (const auto& display : mDisplays) {
2134 auto& writer = getWriter(display.getDisplayId());
2135 const auto& [layerStatus, layer] =
2136 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2137 EXPECT_TRUE(layerStatus.isOk());
2138
2139 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2140 ::android::PIXEL_FORMAT_RGBA_8888);
2141 const auto handle = buffer->handle;
2142 ASSERT_NE(nullptr, handle);
2143
2144 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, handle,
2145 /*acquireFence*/ -1);
2146
2147 Rect displayFrame{0, 0, display.getDisplayWidth(), display.getDisplayHeight()};
2148 FRect cropRect{0, 0, (float)display.getDisplayWidth(), (float)display.getDisplayHeight()};
2149 configureLayer(display, layer, Composition::CURSOR, displayFrame, cropRect);
2150 writer.setLayerDataspace(display.getDisplayId(), layer, Dataspace::UNKNOWN);
2151 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
2152 ComposerClientWrapper::kNoFrameIntervalNs);
2153
2154 execute();
2155
2156 if (!getReader(display.getDisplayId())
2157 .takeChangedCompositionTypes(display.getDisplayId())
2158 .empty()) {
2159 continue; // Skip this display if composition change requested
2160 }
2161 writer.presentDisplay(display.getDisplayId());
2162 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2163
2164 writer.setLayerCursorPosition(display.getDisplayId(), layer, /*x*/ 1, /*y*/ 1);
2165 execute();
2166
2167 writer.setLayerCursorPosition(display.getDisplayId(), layer, /*x*/ 0, /*y*/ 0);
2168 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
2169 ComposerClientWrapper::kNoFrameIntervalNs);
2170 execute();
2171 }
2172 }
2173
TEST_P(GraphicsComposerAidlCommandTest,SetLayerBuffer)2174 TEST_P(GraphicsComposerAidlCommandTest, SetLayerBuffer) {
2175 for (const auto& display : mDisplays) {
2176 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2177 ::android::PIXEL_FORMAT_RGBA_8888);
2178 const auto handle = buffer->handle;
2179 ASSERT_NE(nullptr, handle);
2180
2181 auto& writer = getWriter(display.getDisplayId());
2182 const auto& [layerStatus, layer] =
2183 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2184 EXPECT_TRUE(layerStatus.isOk());
2185 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, handle,
2186 /*acquireFence*/ -1);
2187 execute();
2188 }
2189 }
2190
TEST_P(GraphicsComposerAidlCommandTest,SetLayerBufferMultipleTimes)2191 TEST_P(GraphicsComposerAidlCommandTest, SetLayerBufferMultipleTimes) {
2192 for (const auto& display : mDisplays) {
2193 auto& writer = getWriter(display.getDisplayId());
2194 const auto& [layerStatus, layer] =
2195 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2196 EXPECT_TRUE(layerStatus.isOk());
2197
2198 // Setup 3 buffers in the buffer cache, with the last buffer being active. Then, emulate the
2199 // Android platform code that clears all 3 buffer slots by setting all but the active buffer
2200 // slot to a placeholder buffer, and then restoring the active buffer.
2201
2202 // This is used on HALs that don't support setLayerBufferSlotsToClear (version <= 3.1).
2203
2204 const auto buffer1 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2205 ::android::PIXEL_FORMAT_RGBA_8888);
2206 ASSERT_NE(nullptr, buffer1);
2207 const auto handle1 = buffer1->handle;
2208 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, handle1,
2209 /*acquireFence*/ -1);
2210 execute();
2211 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2212
2213 const auto buffer2 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2214 ::android::PIXEL_FORMAT_RGBA_8888);
2215 ASSERT_NE(nullptr, buffer2);
2216 const auto handle2 = buffer2->handle;
2217 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 1, handle2,
2218 /*acquireFence*/ -1);
2219 execute();
2220 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2221
2222 const auto buffer3 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2223 ::android::PIXEL_FORMAT_RGBA_8888);
2224 ASSERT_NE(nullptr, buffer3);
2225 const auto handle3 = buffer3->handle;
2226 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 2, handle3,
2227 /*acquireFence*/ -1);
2228 execute();
2229 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2230
2231 // Older versions of the HAL clear all but the active buffer slot with a placeholder buffer,
2232 // and then restoring the current active buffer at the end
2233 auto clearSlotBuffer = allocate(1u, 1u, ::android::PIXEL_FORMAT_RGB_888);
2234 ASSERT_NE(nullptr, clearSlotBuffer);
2235 auto clearSlotBufferHandle = clearSlotBuffer->handle;
2236
2237 // clear buffer slots 0 and 1 with new layer commands... and then...
2238 writer.setLayerBufferWithNewCommand(display.getDisplayId(), layer, /* slot */ 0,
2239 clearSlotBufferHandle, /*acquireFence*/ -1);
2240 writer.setLayerBufferWithNewCommand(display.getDisplayId(), layer, /* slot */ 1,
2241 clearSlotBufferHandle, /*acquireFence*/ -1);
2242 // ...reset the layer buffer to the current active buffer slot with a final new command
2243 writer.setLayerBufferWithNewCommand(display.getDisplayId(), layer, /*slot*/ 2, nullptr,
2244 /*acquireFence*/ -1);
2245 execute();
2246 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2247 }
2248 }
2249
TEST_P(GraphicsComposerAidlCommandTest,SetLayerSurfaceDamage)2250 TEST_P(GraphicsComposerAidlCommandTest, SetLayerSurfaceDamage) {
2251 for (const auto& display : mDisplays) {
2252 auto& writer = getWriter(display.getDisplayId());
2253 const auto& [layerStatus, layer] =
2254 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2255 EXPECT_TRUE(layerStatus.isOk());
2256
2257 Rect empty{0, 0, 0, 0};
2258 Rect unit{0, 0, 1, 1};
2259
2260 writer.setLayerSurfaceDamage(display.getDisplayId(), layer, std::vector<Rect>(1, empty));
2261 execute();
2262 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2263
2264 writer.setLayerSurfaceDamage(display.getDisplayId(), layer, std::vector<Rect>(1, unit));
2265 execute();
2266 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2267
2268 writer.setLayerSurfaceDamage(display.getDisplayId(), layer, std::vector<Rect>());
2269 execute();
2270 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2271 }
2272 }
2273
TEST_P(GraphicsComposerAidlCommandTest,SetLayerBlockingRegion)2274 TEST_P(GraphicsComposerAidlCommandTest, SetLayerBlockingRegion) {
2275 for (const auto& display : mDisplays) {
2276 auto& writer = getWriter(display.getDisplayId());
2277 const auto& [layerStatus, layer] =
2278 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2279 EXPECT_TRUE(layerStatus.isOk());
2280
2281 Rect empty{0, 0, 0, 0};
2282 Rect unit{0, 0, 1, 1};
2283
2284 writer.setLayerBlockingRegion(display.getDisplayId(), layer, std::vector<Rect>(1, empty));
2285 execute();
2286 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2287
2288 writer.setLayerBlockingRegion(display.getDisplayId(), layer, std::vector<Rect>(1, unit));
2289 execute();
2290 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2291
2292 writer.setLayerBlockingRegion(display.getDisplayId(), layer, std::vector<Rect>());
2293 execute();
2294 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2295 }
2296 }
2297
TEST_P(GraphicsComposerAidlCommandTest,SetLayerBlendMode)2298 TEST_P(GraphicsComposerAidlCommandTest, SetLayerBlendMode) {
2299 for (const auto& display : mDisplays) {
2300 auto& writer = getWriter(display.getDisplayId());
2301 const auto& [layerStatus, layer] =
2302 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2303 EXPECT_TRUE(layerStatus.isOk());
2304
2305 writer.setLayerBlendMode(display.getDisplayId(), layer, BlendMode::NONE);
2306 execute();
2307 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2308
2309 writer.setLayerBlendMode(display.getDisplayId(), layer, BlendMode::PREMULTIPLIED);
2310 execute();
2311 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2312
2313 writer.setLayerBlendMode(display.getDisplayId(), layer, BlendMode::COVERAGE);
2314 execute();
2315 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2316 }
2317 }
2318
TEST_P(GraphicsComposerAidlCommandTest,SetLayerColor)2319 TEST_P(GraphicsComposerAidlCommandTest, SetLayerColor) {
2320 for (const auto& display : mDisplays) {
2321 auto& writer = getWriter(display.getDisplayId());
2322 const auto& [layerStatus, layer] =
2323 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2324 EXPECT_TRUE(layerStatus.isOk());
2325
2326 writer.setLayerColor(display.getDisplayId(), layer, Color{1.0f, 1.0f, 1.0f, 1.0f});
2327 execute();
2328 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2329
2330 writer.setLayerColor(display.getDisplayId(), layer, Color{0.0f, 0.0f, 0.0f, 0.0f});
2331 execute();
2332 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2333 }
2334 }
2335
TEST_P(GraphicsComposerAidlCommandTest,SetLayerCompositionType)2336 TEST_P(GraphicsComposerAidlCommandTest, SetLayerCompositionType) {
2337 for (const auto& display : mDisplays) {
2338 auto& writer = getWriter(display.getDisplayId());
2339 const auto& [layerStatus, layer] =
2340 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2341 EXPECT_TRUE(layerStatus.isOk());
2342
2343 writer.setLayerCompositionType(display.getDisplayId(), layer, Composition::CLIENT);
2344 execute();
2345 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2346
2347 writer.setLayerCompositionType(display.getDisplayId(), layer, Composition::DEVICE);
2348 execute();
2349 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2350
2351 writer.setLayerCompositionType(display.getDisplayId(), layer, Composition::SOLID_COLOR);
2352 execute();
2353 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2354
2355 writer.setLayerCompositionType(display.getDisplayId(), layer, Composition::CURSOR);
2356 execute();
2357 }
2358 }
2359
TEST_P(GraphicsComposerAidlCommandTest,DisplayDecoration)2360 TEST_P(GraphicsComposerAidlCommandTest, DisplayDecoration) {
2361 for (DisplayWrapper& display : mDisplays) {
2362 const auto displayId = display.getDisplayId();
2363 auto& writer = getWriter(displayId);
2364 const auto [layerStatus, layer] =
2365 mComposerClient->createLayer(displayId, kBufferSlotCount, &writer);
2366 ASSERT_TRUE(layerStatus.isOk());
2367
2368 const auto [error, support] = mComposerClient->getDisplayDecorationSupport(displayId);
2369
2370 const auto format = (error.isOk() && support) ? support->format
2371 : aidl::android::hardware::graphics::common::PixelFormat::RGBA_8888;
2372 const auto decorBuffer = allocate(display.getDisplayHeight(), display.getDisplayWidth(),
2373 static_cast<::android::PixelFormat>(format));
2374 ASSERT_NE(nullptr, decorBuffer);
2375 if (::android::OK != decorBuffer->initCheck()) {
2376 if (support) {
2377 FAIL() << "Device advertised display decoration support with format "
2378 << aidl::android::hardware::graphics::common::toString(format)
2379 << " but failed to allocate it!";
2380 } else {
2381 FAIL() << "Device advertised NO display decoration support, but it should "
2382 << "still be able to allocate "
2383 << aidl::android::hardware::graphics::common::toString(format);
2384 }
2385 }
2386
2387 configureLayer(display, layer, Composition::DISPLAY_DECORATION, display.getFrameRect(),
2388 display.getCrop());
2389 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, decorBuffer->handle,
2390 /*acquireFence*/ -1);
2391 writer.validateDisplay(displayId, ComposerClientWriter::kNoTimestamp,
2392 ComposerClientWrapper::kNoFrameIntervalNs);
2393 execute();
2394 if (support) {
2395 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2396 } else {
2397 const auto errors = getReader(display.getDisplayId()).takeErrors();
2398 ASSERT_EQ(1, errors.size());
2399 EXPECT_EQ(IComposerClient::EX_UNSUPPORTED, errors[0].errorCode);
2400 }
2401 EXPECT_TRUE(mComposerClient->destroyLayer(displayId, layer, &writer).isOk());
2402 }
2403 }
2404
TEST_P(GraphicsComposerAidlCommandTest,SetLayerDataspace)2405 TEST_P(GraphicsComposerAidlCommandTest, SetLayerDataspace) {
2406 for (const auto& display : mDisplays) {
2407 auto& writer = getWriter(display.getDisplayId());
2408 const auto& [layerStatus, layer] =
2409 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2410 EXPECT_TRUE(layerStatus.isOk());
2411 writer.setLayerDataspace(display.getDisplayId(), layer, Dataspace::UNKNOWN);
2412 execute();
2413 }
2414 }
2415
TEST_P(GraphicsComposerAidlCommandTest,SetLayerDisplayFrame)2416 TEST_P(GraphicsComposerAidlCommandTest, SetLayerDisplayFrame) {
2417 for (const auto& display : mDisplays) {
2418 auto& writer = getWriter(display.getDisplayId());
2419 const auto& [layerStatus, layer] =
2420 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2421 EXPECT_TRUE(layerStatus.isOk());
2422 writer.setLayerDisplayFrame(display.getDisplayId(), layer, Rect{0, 0, 1, 1});
2423 execute();
2424 }
2425 }
2426
TEST_P(GraphicsComposerAidlCommandTest,SetLayerPlaneAlpha)2427 TEST_P(GraphicsComposerAidlCommandTest, SetLayerPlaneAlpha) {
2428 for (const auto& display : mDisplays) {
2429 auto& writer = getWriter(display.getDisplayId());
2430 const auto& [layerStatus, layer] =
2431 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2432 EXPECT_TRUE(layerStatus.isOk());
2433
2434 writer.setLayerPlaneAlpha(display.getDisplayId(), layer, /*alpha*/ 0.0f);
2435 execute();
2436 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2437
2438 writer.setLayerPlaneAlpha(display.getDisplayId(), layer, /*alpha*/ 1.0f);
2439 execute();
2440 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2441 }
2442 }
2443
TEST_P(GraphicsComposerAidlCommandTest,SetLayerSidebandStream)2444 TEST_P(GraphicsComposerAidlCommandTest, SetLayerSidebandStream) {
2445 if (!hasCapability(Capability::SIDEBAND_STREAM)) {
2446 GTEST_SUCCEED() << "no sideband stream support";
2447 return;
2448 }
2449
2450 for (const auto& display : mDisplays) {
2451 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2452 ::android::PIXEL_FORMAT_RGBA_8888);
2453 const auto handle = buffer->handle;
2454 ASSERT_NE(nullptr, handle);
2455
2456 auto& writer = getWriter(display.getDisplayId());
2457 const auto& [layerStatus, layer] =
2458 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2459 EXPECT_TRUE(layerStatus.isOk());
2460
2461 writer.setLayerSidebandStream(display.getDisplayId(), layer, handle);
2462 execute();
2463 }
2464 }
2465
TEST_P(GraphicsComposerAidlCommandTest,SetLayerSourceCrop)2466 TEST_P(GraphicsComposerAidlCommandTest, SetLayerSourceCrop) {
2467 for (const auto& display : mDisplays) {
2468 auto& writer = getWriter(display.getDisplayId());
2469 const auto& [layerStatus, layer] =
2470 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2471 EXPECT_TRUE(layerStatus.isOk());
2472
2473 writer.setLayerSourceCrop(display.getDisplayId(), layer, FRect{0.0f, 0.0f, 1.0f, 1.0f});
2474 execute();
2475 }
2476 }
2477
TEST_P(GraphicsComposerAidlCommandTest,SetLayerTransform)2478 TEST_P(GraphicsComposerAidlCommandTest, SetLayerTransform) {
2479 for (const auto& display : mDisplays) {
2480 auto& writer = getWriter(display.getDisplayId());
2481 const auto& [layerStatus, layer] =
2482 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2483 EXPECT_TRUE(layerStatus.isOk());
2484
2485 writer.setLayerTransform(display.getDisplayId(), layer, static_cast<Transform>(0));
2486 execute();
2487 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2488
2489 writer.setLayerTransform(display.getDisplayId(), layer, Transform::FLIP_H);
2490 execute();
2491 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2492
2493 writer.setLayerTransform(display.getDisplayId(), layer, Transform::FLIP_V);
2494 execute();
2495 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2496
2497 writer.setLayerTransform(display.getDisplayId(), layer, Transform::ROT_90);
2498 execute();
2499 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2500
2501 writer.setLayerTransform(display.getDisplayId(), layer, Transform::ROT_180);
2502 execute();
2503 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2504
2505 writer.setLayerTransform(display.getDisplayId(), layer, Transform::ROT_270);
2506 execute();
2507 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2508
2509 writer.setLayerTransform(display.getDisplayId(), layer,
2510 static_cast<Transform>(static_cast<int>(Transform::FLIP_H) |
2511 static_cast<int>(Transform::ROT_90)));
2512 execute();
2513 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2514
2515 writer.setLayerTransform(display.getDisplayId(), layer,
2516 static_cast<Transform>(static_cast<int>(Transform::FLIP_V) |
2517 static_cast<int>(Transform::ROT_90)));
2518 execute();
2519 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2520 }
2521 }
2522
TEST_P(GraphicsComposerAidlCommandTest,SetLayerVisibleRegion)2523 TEST_P(GraphicsComposerAidlCommandTest, SetLayerVisibleRegion) {
2524 for (const auto& display : mDisplays) {
2525 auto& writer = getWriter(display.getDisplayId());
2526 const auto& [layerStatus, layer] =
2527 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2528 EXPECT_TRUE(layerStatus.isOk());
2529
2530 Rect empty{0, 0, 0, 0};
2531 Rect unit{0, 0, 1, 1};
2532
2533 writer.setLayerVisibleRegion(display.getDisplayId(), layer, std::vector<Rect>(1, empty));
2534 execute();
2535 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2536
2537 writer.setLayerVisibleRegion(display.getDisplayId(), layer, std::vector<Rect>(1, unit));
2538 execute();
2539 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2540
2541 writer.setLayerVisibleRegion(display.getDisplayId(), layer, std::vector<Rect>());
2542 execute();
2543 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2544 }
2545 }
2546
TEST_P(GraphicsComposerAidlCommandTest,SetLayerZOrder)2547 TEST_P(GraphicsComposerAidlCommandTest, SetLayerZOrder) {
2548 for (const auto& display : mDisplays) {
2549 auto& writer = getWriter(display.getDisplayId());
2550
2551 const auto& [layerStatus, layer] =
2552 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2553 EXPECT_TRUE(layerStatus.isOk());
2554
2555 writer.setLayerZOrder(display.getDisplayId(), layer, /*z*/ 10);
2556 execute();
2557 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2558
2559 writer.setLayerZOrder(display.getDisplayId(), layer, /*z*/ 0);
2560 execute();
2561 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2562 }
2563 }
2564
TEST_P(GraphicsComposerAidlCommandTest,SetLayerPerFrameMetadata)2565 TEST_P(GraphicsComposerAidlCommandTest, SetLayerPerFrameMetadata) {
2566 for (const auto& display : mDisplays) {
2567 auto& writer = getWriter(display.getDisplayId());
2568 const auto& [layerStatus, layer] =
2569 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2570 EXPECT_TRUE(layerStatus.isOk());
2571
2572 /**
2573 * DISPLAY_P3 is a color space that uses the DCI_P3 primaries,
2574 * the D65 white point and the SRGB transfer functions.
2575 * Rendering Intent: Colorimetric
2576 * Primaries:
2577 * x y
2578 * green 0.265 0.690
2579 * blue 0.150 0.060
2580 * red 0.680 0.320
2581 * white (D65) 0.3127 0.3290
2582 */
2583
2584 std::vector<PerFrameMetadata> aidlMetadata;
2585 aidlMetadata.push_back({PerFrameMetadataKey::DISPLAY_RED_PRIMARY_X, 0.680f});
2586 aidlMetadata.push_back({PerFrameMetadataKey::DISPLAY_RED_PRIMARY_Y, 0.320f});
2587 aidlMetadata.push_back({PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_X, 0.265f});
2588 aidlMetadata.push_back({PerFrameMetadataKey::DISPLAY_GREEN_PRIMARY_Y, 0.690f});
2589 aidlMetadata.push_back({PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_X, 0.150f});
2590 aidlMetadata.push_back({PerFrameMetadataKey::DISPLAY_BLUE_PRIMARY_Y, 0.060f});
2591 aidlMetadata.push_back({PerFrameMetadataKey::WHITE_POINT_X, 0.3127f});
2592 aidlMetadata.push_back({PerFrameMetadataKey::WHITE_POINT_Y, 0.3290f});
2593 aidlMetadata.push_back({PerFrameMetadataKey::MAX_LUMINANCE, 100.0f});
2594 aidlMetadata.push_back({PerFrameMetadataKey::MIN_LUMINANCE, 0.1f});
2595 aidlMetadata.push_back({PerFrameMetadataKey::MAX_CONTENT_LIGHT_LEVEL, 78.0});
2596 aidlMetadata.push_back({PerFrameMetadataKey::MAX_FRAME_AVERAGE_LIGHT_LEVEL, 62.0});
2597 writer.setLayerPerFrameMetadata(display.getDisplayId(), layer, aidlMetadata);
2598 execute();
2599
2600 const auto errors = getReader(display.getDisplayId()).takeErrors();
2601 if (errors.size() == 1 && errors[0].errorCode == EX_UNSUPPORTED_OPERATION) {
2602 GTEST_SUCCEED() << "SetLayerPerFrameMetadata is not supported";
2603 EXPECT_TRUE(
2604 mComposerClient->destroyLayer(display.getDisplayId(), layer, &writer).isOk());
2605 return;
2606 }
2607
2608 EXPECT_TRUE(mComposerClient->destroyLayer(display.getDisplayId(), layer, &writer).isOk());
2609 }
2610 }
2611
TEST_P(GraphicsComposerAidlCommandTest,setLayerBrightness)2612 TEST_P(GraphicsComposerAidlCommandTest, setLayerBrightness) {
2613 for (const auto& display : mDisplays) {
2614 auto& writer = getWriter(display.getDisplayId());
2615
2616 const auto& [layerStatus, layer] =
2617 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2618
2619 writer.setLayerBrightness(display.getDisplayId(), layer, 0.2f);
2620 execute();
2621 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2622
2623 writer.setLayerBrightness(display.getDisplayId(), layer, 1.f);
2624 execute();
2625 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2626
2627 writer.setLayerBrightness(display.getDisplayId(), layer, 0.f);
2628 execute();
2629 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2630
2631 writer.setLayerBrightness(display.getDisplayId(), layer, -1.f);
2632 execute();
2633 {
2634 const auto errors = getReader(display.getDisplayId()).takeErrors();
2635 ASSERT_EQ(1, errors.size());
2636 EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
2637 }
2638
2639 writer.setLayerBrightness(display.getDisplayId(), layer, std::nanf(""));
2640 execute();
2641 {
2642 const auto errors = getReader(display.getDisplayId()).takeErrors();
2643 ASSERT_EQ(1, errors.size());
2644 EXPECT_EQ(IComposerClient::EX_BAD_PARAMETER, errors[0].errorCode);
2645 }
2646 }
2647 }
2648
TEST_P(GraphicsComposerAidlCommandTest,SetActiveConfigWithConstraints)2649 TEST_P(GraphicsComposerAidlCommandTest, SetActiveConfigWithConstraints) {
2650 Test_setActiveConfigWithConstraints({.delayForChange = 0, .refreshMiss = false});
2651 }
2652
TEST_P(GraphicsComposerAidlCommandTest,SetActiveConfigWithConstraints_Delayed)2653 TEST_P(GraphicsComposerAidlCommandTest, SetActiveConfigWithConstraints_Delayed) {
2654 Test_setActiveConfigWithConstraints({.delayForChange = 300'000'000, // 300ms
2655 .refreshMiss = false});
2656 }
2657
TEST_P(GraphicsComposerAidlCommandTest,SetActiveConfigWithConstraints_MissRefresh)2658 TEST_P(GraphicsComposerAidlCommandTest, SetActiveConfigWithConstraints_MissRefresh) {
2659 Test_setActiveConfigWithConstraints({.delayForChange = 0, .refreshMiss = true});
2660 }
2661
TEST_P(GraphicsComposerAidlCommandTest,GetDisplayVsyncPeriod)2662 TEST_P(GraphicsComposerAidlCommandTest, GetDisplayVsyncPeriod) {
2663 for (DisplayWrapper& display : mDisplays) {
2664 const auto& [status, configs] = mComposerClient->getDisplayConfigs(display.getDisplayId());
2665 EXPECT_TRUE(status.isOk());
2666
2667 for (int32_t config : configs) {
2668 int32_t expectedVsyncPeriodNanos = display.getDisplayConfig(config).vsyncPeriod;
2669
2670 VsyncPeriodChangeConstraints constraints;
2671
2672 constraints.desiredTimeNanos = systemTime();
2673 constraints.seamlessRequired = false;
2674
2675 const auto& [timelineStatus, timeline] =
2676 mComposerClient->setActiveConfigWithConstraints(&display, config, constraints);
2677 EXPECT_TRUE(timelineStatus.isOk());
2678
2679 if (timeline.refreshRequired) {
2680 sendRefreshFrame(display, &timeline);
2681 }
2682 waitForVsyncPeriodChange(display.getDisplayId(), timeline, constraints.desiredTimeNanos,
2683 /*odPeriodNanos*/ 0, expectedVsyncPeriodNanos);
2684
2685 int32_t vsyncPeriodNanos;
2686 int retryCount = 100;
2687 do {
2688 std::this_thread::sleep_for(10ms);
2689 const auto& [vsyncPeriodNanosStatus, vsyncPeriodNanosValue] =
2690 mComposerClient->getDisplayVsyncPeriod(display.getDisplayId());
2691
2692 EXPECT_TRUE(vsyncPeriodNanosStatus.isOk());
2693 vsyncPeriodNanos = vsyncPeriodNanosValue;
2694 --retryCount;
2695 } while (vsyncPeriodNanos != expectedVsyncPeriodNanos && retryCount > 0);
2696
2697 EXPECT_EQ(vsyncPeriodNanos, expectedVsyncPeriodNanos);
2698
2699 // Make sure that the vsync period stays the same if the active config is not
2700 // changed.
2701 auto timeout = 1ms;
2702 for (int i = 0; i < 10; i++) {
2703 std::this_thread::sleep_for(timeout);
2704 timeout *= 2;
2705 vsyncPeriodNanos = 0;
2706 const auto& [vsyncPeriodNanosStatus, vsyncPeriodNanosValue] =
2707 mComposerClient->getDisplayVsyncPeriod(display.getDisplayId());
2708
2709 EXPECT_TRUE(vsyncPeriodNanosStatus.isOk());
2710 vsyncPeriodNanos = vsyncPeriodNanosValue;
2711 EXPECT_EQ(vsyncPeriodNanos, expectedVsyncPeriodNanos);
2712 }
2713 }
2714 }
2715 }
2716
TEST_P(GraphicsComposerAidlCommandTest,SetActiveConfigWithConstraints_SeamlessNotAllowed)2717 TEST_P(GraphicsComposerAidlCommandTest, SetActiveConfigWithConstraints_SeamlessNotAllowed) {
2718 VsyncPeriodChangeConstraints constraints;
2719 constraints.seamlessRequired = true;
2720 constraints.desiredTimeNanos = systemTime();
2721
2722 for (DisplayWrapper& display : mDisplays) {
2723 forEachTwoConfigs(display.getDisplayId(), [&](int32_t config1, int32_t config2) {
2724 int32_t configGroup1 = display.getDisplayConfig(config1).configGroup;
2725 int32_t configGroup2 = display.getDisplayConfig(config2).configGroup;
2726 if (configGroup1 != configGroup2) {
2727 EXPECT_TRUE(mComposerClient->setActiveConfig(&display, config1).isOk());
2728 sendRefreshFrame(display, nullptr);
2729 const auto& [status, _] = mComposerClient->setActiveConfigWithConstraints(
2730 &display, config2, constraints);
2731 EXPECT_FALSE(status.isOk());
2732 EXPECT_NO_FATAL_FAILURE(assertServiceSpecificError(
2733 status, IComposerClient::EX_SEAMLESS_NOT_ALLOWED));
2734 }
2735 });
2736 }
2737 }
2738
TEST_P(GraphicsComposerAidlCommandTest,ExpectedPresentTime_NoTimestamp)2739 TEST_P(GraphicsComposerAidlCommandTest, ExpectedPresentTime_NoTimestamp) {
2740 ASSERT_NO_FATAL_FAILURE(Test_expectedPresentTime(/*framesDelay*/ std::nullopt));
2741 }
2742
TEST_P(GraphicsComposerAidlCommandTest,ExpectedPresentTime_0)2743 TEST_P(GraphicsComposerAidlCommandTest, ExpectedPresentTime_0) {
2744 ASSERT_NO_FATAL_FAILURE(Test_expectedPresentTime(/*framesDelay*/ 0));
2745 }
2746
TEST_P(GraphicsComposerAidlCommandTest,ExpectedPresentTime_5)2747 TEST_P(GraphicsComposerAidlCommandTest, ExpectedPresentTime_5) {
2748 ASSERT_NO_FATAL_FAILURE(Test_expectedPresentTime(/*framesDelay*/ 5));
2749 }
2750
TEST_P(GraphicsComposerAidlCommandTest,SetIdleTimerEnabled_Unsupported)2751 TEST_P(GraphicsComposerAidlCommandTest, SetIdleTimerEnabled_Unsupported) {
2752 for (const DisplayWrapper& display : mDisplays) {
2753 const bool hasDisplayIdleTimerSupport =
2754 hasDisplayCapability(display.getDisplayId(), DisplayCapability::DISPLAY_IDLE_TIMER);
2755 if (!hasDisplayIdleTimerSupport) {
2756 const auto& status =
2757 mComposerClient->setIdleTimerEnabled(display.getDisplayId(), /*timeout*/ 0);
2758 EXPECT_FALSE(status.isOk());
2759 EXPECT_NO_FATAL_FAILURE(
2760 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
2761 }
2762 }
2763 }
2764
TEST_P(GraphicsComposerAidlCommandTest,SetIdleTimerEnabled_BadParameter)2765 TEST_P(GraphicsComposerAidlCommandTest, SetIdleTimerEnabled_BadParameter) {
2766 for (const DisplayWrapper& display : mDisplays) {
2767 const bool hasDisplayIdleTimerSupport =
2768 hasDisplayCapability(display.getDisplayId(), DisplayCapability::DISPLAY_IDLE_TIMER);
2769 if (!hasDisplayIdleTimerSupport) {
2770 continue; // DisplayCapability::DISPLAY_IDLE_TIMER is not supported
2771 }
2772
2773 const auto& status =
2774 mComposerClient->setIdleTimerEnabled(display.getDisplayId(), /*timeout*/ -1);
2775 EXPECT_FALSE(status.isOk());
2776 EXPECT_NO_FATAL_FAILURE(
2777 assertServiceSpecificError(status, IComposerClient::EX_BAD_PARAMETER));
2778 }
2779 }
2780
TEST_P(GraphicsComposerAidlCommandTest,SetIdleTimerEnabled_Disable)2781 TEST_P(GraphicsComposerAidlCommandTest, SetIdleTimerEnabled_Disable) {
2782 for (const DisplayWrapper& display : mDisplays) {
2783 const bool hasDisplayIdleTimerSupport =
2784 hasDisplayCapability(display.getDisplayId(), DisplayCapability::DISPLAY_IDLE_TIMER);
2785 if (!hasDisplayIdleTimerSupport) {
2786 continue; // DisplayCapability::DISPLAY_IDLE_TIMER is not supported
2787 }
2788
2789 EXPECT_TRUE(
2790 mComposerClient->setIdleTimerEnabled(display.getDisplayId(), /*timeout*/ 0).isOk());
2791 std::this_thread::sleep_for(1s);
2792 EXPECT_EQ(0, mComposerClient->getVsyncIdleCount());
2793 }
2794 }
2795
TEST_P(GraphicsComposerAidlCommandTest,SetIdleTimerEnabled_Timeout_2)2796 TEST_P(GraphicsComposerAidlCommandTest, SetIdleTimerEnabled_Timeout_2) {
2797 for (const DisplayWrapper& display : mDisplays) {
2798 const bool hasDisplayIdleTimerSupport =
2799 hasDisplayCapability(display.getDisplayId(), DisplayCapability::DISPLAY_IDLE_TIMER);
2800 if (!hasDisplayIdleTimerSupport) {
2801 GTEST_SUCCEED() << "DisplayCapability::DISPLAY_IDLE_TIMER is not supported";
2802 return;
2803 }
2804
2805 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::ON).isOk());
2806 EXPECT_TRUE(
2807 mComposerClient->setIdleTimerEnabled(display.getDisplayId(), /*timeout*/ 0).isOk());
2808
2809 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2810 ::android::PIXEL_FORMAT_RGBA_8888);
2811 ASSERT_NE(nullptr, buffer->handle);
2812
2813 const auto layer = createOnScreenLayer(display);
2814 auto& writer = getWriter(display.getDisplayId());
2815 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, buffer->handle,
2816 /*acquireFence*/ -1);
2817 int32_t vsyncIdleCount = mComposerClient->getVsyncIdleCount();
2818 auto earlyVsyncIdleTime = systemTime() + std::chrono::nanoseconds(2s).count();
2819 EXPECT_TRUE(mComposerClient->setIdleTimerEnabled(display.getDisplayId(), /*timeout*/ 2000)
2820 .isOk());
2821
2822 const sp<::android::Fence> presentFence =
2823 presentAndGetFence(ComposerClientWriter::kNoTimestamp, display.getDisplayId());
2824 presentFence->waitForever(LOG_TAG);
2825
2826 std::this_thread::sleep_for(3s);
2827 if (vsyncIdleCount < mComposerClient->getVsyncIdleCount()) {
2828 EXPECT_GE(mComposerClient->getVsyncIdleTime(), earlyVsyncIdleTime);
2829 }
2830
2831 EXPECT_TRUE(mComposerClient->setPowerMode(display.getDisplayId(), PowerMode::OFF).isOk());
2832 }
2833 }
2834
2835 class GraphicsComposerAidlCommandV2Test : public GraphicsComposerAidlCommandTest {
2836 protected:
SetUp()2837 void SetUp() override {
2838 GraphicsComposerAidlTest::SetUp();
2839 if (getInterfaceVersion() <= 1) {
2840 GTEST_SKIP() << "Device interface version is expected to be >= 2";
2841 }
2842 }
2843 };
2844
2845 /**
2846 * Test Capability::SKIP_VALIDATE
2847 *
2848 * Capability::SKIP_VALIDATE has been deprecated and should not be enabled.
2849 */
TEST_P(GraphicsComposerAidlCommandV2Test,SkipValidateDeprecatedTest)2850 TEST_P(GraphicsComposerAidlCommandV2Test, SkipValidateDeprecatedTest) {
2851 #pragma clang diagnostic push
2852 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
2853 ASSERT_FALSE(hasCapability(Capability::SKIP_VALIDATE))
2854 << "Found Capability::SKIP_VALIDATE capability.";
2855 #pragma clang diagnostic pop
2856 }
2857
TEST_P(GraphicsComposerAidlCommandV2Test,SetLayerBufferSlotsToClear)2858 TEST_P(GraphicsComposerAidlCommandV2Test, SetLayerBufferSlotsToClear) {
2859 for (const DisplayWrapper& display : mDisplays) {
2860 auto& writer = getWriter(display.getDisplayId());
2861 // Older HAL versions use a backwards compatible way of clearing buffer slots
2862 // HAL at version 1 or lower does not have LayerCommand::bufferSlotsToClear
2863 const auto& [layerStatus, layer] =
2864 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
2865 EXPECT_TRUE(layerStatus.isOk());
2866
2867 // setup 3 buffers in the buffer cache, with the last buffer being active
2868 // then emulate the Android platform code that clears all 3 buffer slots
2869
2870 const auto buffer1 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2871 ::android::PIXEL_FORMAT_RGBA_8888);
2872 ASSERT_NE(nullptr, buffer1);
2873 const auto handle1 = buffer1->handle;
2874 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, handle1,
2875 /*acquireFence*/ -1);
2876 execute();
2877 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2878
2879 const auto buffer2 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2880 ::android::PIXEL_FORMAT_RGBA_8888);
2881 ASSERT_NE(nullptr, buffer2);
2882 const auto handle2 = buffer2->handle;
2883 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 1, handle2,
2884 /*acquireFence*/ -1);
2885 execute();
2886 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2887
2888 const auto buffer3 = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
2889 ::android::PIXEL_FORMAT_RGBA_8888);
2890 ASSERT_NE(nullptr, buffer3);
2891 const auto handle3 = buffer3->handle;
2892 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 2, handle3,
2893 /*acquireFence*/ -1);
2894 execute();
2895 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2896
2897 // Ensure we can clear all 3 buffer slots, even the active buffer - it is assumed the
2898 // current active buffer's slot will be cleared, but still remain the active buffer and no
2899 // errors will occur.
2900 writer.setLayerBufferSlotsToClear(display.getDisplayId(), layer, {0, 1, 2});
2901 execute();
2902 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
2903 }
2904 }
2905
TEST_P(GraphicsComposerAidlCommandV2Test,SetRefreshRateChangedCallbackDebug_Unsupported)2906 TEST_P(GraphicsComposerAidlCommandV2Test, SetRefreshRateChangedCallbackDebug_Unsupported) {
2907 if (!hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG)) {
2908 for (const DisplayWrapper& display : mDisplays) {
2909 auto status = mComposerClient->setRefreshRateChangedCallbackDebugEnabled(
2910 display.getDisplayId(), /*enabled*/ true);
2911 EXPECT_FALSE(status.isOk());
2912 EXPECT_NO_FATAL_FAILURE(
2913 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
2914
2915 status = mComposerClient->setRefreshRateChangedCallbackDebugEnabled(
2916 display.getDisplayId(),
2917 /*enabled*/ false);
2918 EXPECT_FALSE(status.isOk());
2919 EXPECT_NO_FATAL_FAILURE(
2920 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
2921 }
2922 }
2923 }
2924
TEST_P(GraphicsComposerAidlCommandV2Test,SetRefreshRateChangedCallbackDebug_Enabled)2925 TEST_P(GraphicsComposerAidlCommandV2Test, SetRefreshRateChangedCallbackDebug_Enabled) {
2926 if (!hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG)) {
2927 GTEST_SUCCEED() << "Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG is not supported";
2928 return;
2929 }
2930
2931 for (DisplayWrapper& display : mDisplays) {
2932 const auto displayId = display.getDisplayId();
2933 EXPECT_TRUE(mComposerClient->setPowerMode(displayId, PowerMode::ON).isOk());
2934 // Enable the callback
2935 ASSERT_TRUE(mComposerClient
2936 ->setRefreshRateChangedCallbackDebugEnabled(displayId,
2937 /*enabled*/ true)
2938 .isOk());
2939 std::this_thread::sleep_for(100ms);
2940
2941 const auto [status, configId] = mComposerClient->getActiveConfig(display.getDisplayId());
2942 EXPECT_TRUE(status.isOk());
2943
2944 const auto displayFilter = [&](auto refreshRateChangedDebugData) {
2945 bool nonVrrRateMatching = true;
2946 if (std::optional<VrrConfig> vrrConfigOpt =
2947 display.getDisplayConfig(configId).vrrConfigOpt;
2948 getInterfaceVersion() >= 3 && !vrrConfigOpt) {
2949 nonVrrRateMatching = refreshRateChangedDebugData.refreshPeriodNanos ==
2950 refreshRateChangedDebugData.vsyncPeriodNanos;
2951 }
2952 const bool isDisplaySame =
2953 display.getDisplayId() == refreshRateChangedDebugData.display;
2954 return nonVrrRateMatching && isDisplaySame;
2955 };
2956
2957 // Check that we immediately got a callback
2958 EXPECT_TRUE(checkIfCallbackRefreshRateChangedDebugEnabledReceived(displayFilter));
2959
2960 ASSERT_TRUE(mComposerClient
2961 ->setRefreshRateChangedCallbackDebugEnabled(displayId,
2962 /*enabled*/ false)
2963 .isOk());
2964 }
2965 }
2966
TEST_P(GraphicsComposerAidlCommandV2Test,SetRefreshRateChangedCallbackDebugEnabled_noCallbackWhenIdle)2967 TEST_P(GraphicsComposerAidlCommandV2Test,
2968 SetRefreshRateChangedCallbackDebugEnabled_noCallbackWhenIdle) {
2969 if (!hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG)) {
2970 GTEST_SUCCEED() << "Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG is not supported";
2971 return;
2972 }
2973
2974 for (DisplayWrapper& display : mDisplays) {
2975 const auto displayId = display.getDisplayId();
2976
2977 if (!hasDisplayCapability(displayId, DisplayCapability::DISPLAY_IDLE_TIMER)) {
2978 GTEST_SUCCEED() << "DisplayCapability::DISPLAY_IDLE_TIMER is not supported";
2979 return;
2980 }
2981
2982 EXPECT_TRUE(mComposerClient->setPowerMode(displayId, PowerMode::ON).isOk());
2983 EXPECT_TRUE(mComposerClient->setPeakRefreshRateConfig(&display).isOk());
2984
2985 ASSERT_TRUE(mComposerClient->setIdleTimerEnabled(displayId, /*timeoutMs*/ 500).isOk());
2986 // Enable the callback
2987 ASSERT_TRUE(mComposerClient
2988 ->setRefreshRateChangedCallbackDebugEnabled(displayId,
2989 /*enabled*/ true)
2990 .isOk());
2991
2992 const auto displayFilter = [displayId](auto refreshRateChangedDebugData) {
2993 return displayId == refreshRateChangedDebugData.display;
2994 };
2995
2996 int retryCount = 3;
2997 do {
2998 // Wait for 1s so that we enter the idle state
2999 std::this_thread::sleep_for(1s);
3000 if (!checkIfCallbackRefreshRateChangedDebugEnabledReceived(displayFilter)) {
3001 // DID NOT receive a callback, we are in the idle state.
3002 break;
3003 }
3004 } while (--retryCount > 0);
3005
3006 if (retryCount == 0) {
3007 GTEST_SUCCEED() << "Unable to enter the idle mode";
3008 return;
3009 }
3010
3011 // Send the REFRESH_RATE_INDICATOR update
3012 ASSERT_NO_FATAL_FAILURE(
3013 sendBufferUpdate(createOnScreenLayer(display, Composition::REFRESH_RATE_INDICATOR),
3014 displayId, display.getDisplayWidth(), display.getDisplayHeight()));
3015 std::this_thread::sleep_for(1s);
3016 EXPECT_FALSE(checkIfCallbackRefreshRateChangedDebugEnabledReceived(displayFilter))
3017 << "A callback should not be received for REFRESH_RATE_INDICATOR";
3018
3019 EXPECT_TRUE(mComposerClient
3020 ->setRefreshRateChangedCallbackDebugEnabled(displayId,
3021 /*enabled*/ false)
3022 .isOk());
3023 }
3024 }
3025
TEST_P(GraphicsComposerAidlCommandV2Test,SetRefreshRateChangedCallbackDebugEnabled_SetActiveConfigWithConstraints)3026 TEST_P(GraphicsComposerAidlCommandV2Test,
3027 SetRefreshRateChangedCallbackDebugEnabled_SetActiveConfigWithConstraints) {
3028 if (!hasCapability(Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG)) {
3029 GTEST_SUCCEED() << "Capability::REFRESH_RATE_CHANGED_CALLBACK_DEBUG is not supported";
3030 return;
3031 }
3032
3033 VsyncPeriodChangeConstraints constraints;
3034 constraints.seamlessRequired = false;
3035 constraints.desiredTimeNanos = systemTime();
3036
3037 for (DisplayWrapper& display : mDisplays) {
3038 const auto displayId = display.getDisplayId();
3039 EXPECT_TRUE(mComposerClient->setPowerMode(displayId, PowerMode::ON).isOk());
3040
3041 // Enable the callback
3042 ASSERT_TRUE(mComposerClient
3043 ->setRefreshRateChangedCallbackDebugEnabled(displayId, /*enabled*/ true)
3044 .isOk());
3045
3046 forEachTwoConfigs(displayId, [&](int32_t config1, int32_t config2) {
3047 if (display.isRateSameBetweenConfigs(config1, config2)) {
3048 return; // continue
3049 }
3050
3051 EXPECT_TRUE(mComposerClient->setActiveConfig(&display, config1).isOk());
3052 sendRefreshFrame(display, nullptr);
3053
3054 const auto& [status, timeline] =
3055 mComposerClient->setActiveConfigWithConstraints(&display, config2, constraints);
3056 EXPECT_TRUE(status.isOk());
3057
3058 if (timeline.refreshRequired) {
3059 sendRefreshFrame(display, &timeline);
3060 }
3061
3062 const int32_t vsyncPeriod2 = display.getDisplayConfig(config2).vsyncPeriod;
3063 const auto callbackFilter = [displayId,
3064 vsyncPeriod2](auto refreshRateChangedDebugData) {
3065 constexpr int kVsyncThreshold = 1000;
3066 return displayId == refreshRateChangedDebugData.display &&
3067 std::abs(vsyncPeriod2 - refreshRateChangedDebugData.vsyncPeriodNanos) <=
3068 kVsyncThreshold;
3069 };
3070
3071 int retryCount = 3;
3072 do {
3073 std::this_thread::sleep_for(100ms);
3074 if (checkIfCallbackRefreshRateChangedDebugEnabledReceived(callbackFilter)) {
3075 GTEST_SUCCEED() << "Received a callback successfully";
3076 break;
3077 }
3078 } while (--retryCount > 0);
3079
3080 if (retryCount == 0) {
3081 GTEST_FAIL() << "Failed to get a callback for Display " << displayId
3082 << " switching from " << display.printConfig(config1)
3083 << " to " << display.printConfig(config2);
3084 }
3085 });
3086
3087 EXPECT_TRUE(
3088 mComposerClient
3089 ->setRefreshRateChangedCallbackDebugEnabled(displayId, /*enabled*/ false)
3090 .isOk());
3091 }
3092 }
3093
TEST_P(GraphicsComposerAidlCommandTest,MultiThreadedPresent)3094 TEST_P(GraphicsComposerAidlCommandTest, MultiThreadedPresent) {
3095 std::vector<DisplayWrapper*> displays;
3096 for (auto& display : mDisplays) {
3097 if (hasDisplayCapability(display.getDisplayId(),
3098 DisplayCapability::MULTI_THREADED_PRESENT)) {
3099 displays.push_back(&display);
3100 }
3101 }
3102
3103 const size_t numDisplays = displays.size();
3104 if (numDisplays <= 1u) {
3105 GTEST_SKIP();
3106 }
3107
3108 // When multi-threaded, use a reader per display. As with mWriters, this mutex
3109 // guards access to the map.
3110 std::mutex readersMutex;
3111 std::unordered_map<int64_t, ComposerClientReader> readers;
3112 std::vector<std::thread> threads;
3113 threads.reserve(numDisplays);
3114
3115 // Each display will have a layer to present. This maps from the display to
3116 // the layer, so we can properly destroy each layer at the end.
3117 std::unordered_map<int64_t, int64_t> layers;
3118
3119 for (auto* const display : displays) {
3120 const int64_t displayId = display->getDisplayId();
3121
3122 // Ensure that all writers and readers have been added to their respective
3123 // maps initially, so that the following loop never modifies the maps. The
3124 // maps are accessed from different threads, and if the maps were modified,
3125 // this would invalidate their iterators, and therefore references to the
3126 // writers and readers.
3127 auto& writer = getWriter(displayId);
3128 {
3129 std::lock_guard guard{readersMutex};
3130 readers.try_emplace(displayId, displayId);
3131 }
3132
3133 EXPECT_TRUE(mComposerClient->setPowerMode(displayId, PowerMode::ON).isOk());
3134
3135 const auto& [status, layer] =
3136 mComposerClient->createLayer(displayId, kBufferSlotCount, &writer);
3137 const auto buffer = allocate(display->getDisplayWidth(), display->getDisplayHeight(),
3138 ::android::PIXEL_FORMAT_RGBA_8888);
3139 ASSERT_NE(nullptr, buffer);
3140 ASSERT_EQ(::android::OK, buffer->initCheck());
3141 ASSERT_NE(nullptr, buffer->handle);
3142
3143 configureLayer(*display, layer, Composition::DEVICE, display->getFrameRect(),
3144 display->getCrop());
3145 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3146 /*acquireFence*/ -1);
3147 writer.setLayerDataspace(displayId, layer, common::Dataspace::UNKNOWN);
3148 layers.try_emplace(displayId, layer);
3149 }
3150
3151 for (auto* const display : displays) {
3152 const int64_t displayId = display->getDisplayId();
3153 auto& writer = getWriter(displayId);
3154 std::unique_lock lock{readersMutex};
3155 auto& reader = readers.at(displayId);
3156 lock.unlock();
3157
3158 writer.validateDisplay(displayId, ComposerClientWriter::kNoTimestamp,
3159 ComposerClientWrapper::kNoFrameIntervalNs);
3160 execute(writer, reader);
3161
3162 threads.emplace_back([this, displayId, &readers, &readersMutex]() {
3163 auto& writer = getWriter(displayId);
3164 std::unique_lock lock{readersMutex};
3165 ComposerClientReader& reader = readers.at(displayId);
3166 lock.unlock();
3167
3168 writer.presentDisplay(displayId);
3169 execute(writer, reader);
3170 ASSERT_TRUE(reader.takeErrors().empty());
3171
3172 auto presentFence = reader.takePresentFence(displayId);
3173 // take ownership
3174 const int fenceOwner = presentFence.get();
3175 *presentFence.getR() = -1;
3176 EXPECT_NE(-1, fenceOwner);
3177 const auto presentFence2 = sp<::android::Fence>::make(fenceOwner);
3178 presentFence2->waitForever(LOG_TAG);
3179 });
3180 }
3181
3182 for (auto& thread : threads) {
3183 thread.join();
3184 }
3185
3186 for (auto& [displayId, layer] : layers) {
3187 auto& writer = getWriter(displayId);
3188 EXPECT_TRUE(mComposerClient->destroyLayer(displayId, layer, &writer).isOk());
3189 }
3190
3191 std::lock_guard guard{readersMutex};
3192 for (auto& [displayId, reader] : readers) {
3193 ASSERT_TRUE(reader.takeErrors().empty());
3194 ASSERT_TRUE(reader.takeChangedCompositionTypes(displayId).empty());
3195 }
3196 }
3197
3198 class GraphicsComposerAidlCommandV3Test : public GraphicsComposerAidlCommandTest {
3199 protected:
SetUp()3200 void SetUp() override {
3201 GraphicsComposerAidlTest::SetUp();
3202 if (getInterfaceVersion() <= 2) {
3203 GTEST_SKIP() << "Device interface version is expected to be >= 3";
3204 }
3205 }
3206 };
3207
TEST_P(GraphicsComposerAidlCommandV3Test,CreateBatchedCommand)3208 TEST_P(GraphicsComposerAidlCommandV3Test, CreateBatchedCommand) {
3209 if (!hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
3210 GTEST_SKIP() << "LAYER_LIFECYCLE_BATCH_COMMAND not supported by the implementation";
3211 return;
3212 }
3213 for (const DisplayWrapper& display : mDisplays) {
3214 auto& writer = getWriter(display.getDisplayId());
3215 const auto& [status, layer] =
3216 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
3217 EXPECT_TRUE(status.isOk());
3218 execute();
3219 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
3220 }
3221 }
3222
TEST_P(GraphicsComposerAidlCommandV3Test,CreateBatchedCommand_BadDisplay)3223 TEST_P(GraphicsComposerAidlCommandV3Test, CreateBatchedCommand_BadDisplay) {
3224 if (!hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
3225 GTEST_SKIP() << "LAYER_LIFECYCLE_BATCH_COMMAND not supported by the implementation";
3226 return;
3227 }
3228
3229 int64_t invalidDisplayId = getInvalidDisplayId();
3230 auto& writer = getWriter(invalidDisplayId);
3231 int64_t layer = 5;
3232 writer.setLayerLifecycleBatchCommandType(invalidDisplayId, layer,
3233 LayerLifecycleBatchCommandType::CREATE);
3234 writer.setNewBufferSlotCount(invalidDisplayId, layer, 1);
3235 execute();
3236
3237 const auto errors = getReader(invalidDisplayId).takeErrors();
3238 ASSERT_TRUE(errors.size() == 1 && errors[0].errorCode == IComposerClient::EX_BAD_DISPLAY);
3239 }
3240
TEST_P(GraphicsComposerAidlCommandV3Test,DestroyBatchedCommand)3241 TEST_P(GraphicsComposerAidlCommandV3Test, DestroyBatchedCommand) {
3242 if (!hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
3243 GTEST_SKIP() << "LAYER_LIFECYCLE_BATCH_COMMAND not supported by the implementation";
3244 return;
3245 }
3246
3247 for (const DisplayWrapper& display : mDisplays) {
3248 auto& writer = getWriter(display.getDisplayId());
3249 const auto& [status, layer] =
3250 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
3251 EXPECT_TRUE(status.isOk());
3252 execute();
3253 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
3254 EXPECT_TRUE(mComposerClient->destroyLayer(display.getDisplayId(), layer, &writer).isOk());
3255 execute();
3256 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
3257 }
3258 }
3259
TEST_P(GraphicsComposerAidlCommandV3Test,DestroyBatchedCommand_BadDisplay)3260 TEST_P(GraphicsComposerAidlCommandV3Test, DestroyBatchedCommand_BadDisplay) {
3261 if (!hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
3262 GTEST_SKIP() << "LAYER_LIFECYCLE_BATCH_COMMAND not supported by the implementation";
3263 return;
3264 }
3265
3266 for (const DisplayWrapper& display : mDisplays) {
3267 auto& writer = getWriter(display.getDisplayId());
3268 const auto& [status, layer] =
3269 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
3270
3271 EXPECT_TRUE(status.isOk());
3272 execute();
3273 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
3274
3275 auto& invalid_writer = getWriter(getInvalidDisplayId());
3276 invalid_writer.setLayerLifecycleBatchCommandType(getInvalidDisplayId(), layer,
3277 LayerLifecycleBatchCommandType::DESTROY);
3278 execute();
3279 const auto errors = getReader(getInvalidDisplayId()).takeErrors();
3280 ASSERT_TRUE(errors.size() == 1 && errors[0].errorCode == IComposerClient::EX_BAD_DISPLAY);
3281 }
3282 }
3283
TEST_P(GraphicsComposerAidlCommandV3Test,NoCreateDestroyBatchedCommandIncorrectLayer)3284 TEST_P(GraphicsComposerAidlCommandV3Test, NoCreateDestroyBatchedCommandIncorrectLayer) {
3285 if (!hasCapability(Capability::LAYER_LIFECYCLE_BATCH_COMMAND)) {
3286 GTEST_SKIP() << "LAYER_LIFECYCLE_BATCH_COMMAND not supported by the implementation";
3287 return;
3288 }
3289
3290 for (const DisplayWrapper& display : mDisplays) {
3291 auto& writer = getWriter(display.getDisplayId());
3292 int64_t layer = 5;
3293 writer.setLayerLifecycleBatchCommandType(display.getDisplayId(), layer,
3294 LayerLifecycleBatchCommandType::DESTROY);
3295 execute();
3296 const auto errors = getReader(display.getDisplayId()).takeErrors();
3297 ASSERT_TRUE(errors.size() == 1 && errors[0].errorCode == IComposerClient::EX_BAD_LAYER);
3298 }
3299 }
3300
TEST_P(GraphicsComposerAidlCommandV3Test,notifyExpectedPresentTimeout)3301 TEST_P(GraphicsComposerAidlCommandV3Test, notifyExpectedPresentTimeout) {
3302 if (hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) {
3303 GTEST_SUCCEED() << "Device has unreliable present fences capability, skipping";
3304 return;
3305 }
3306 forEachNotifyExpectedPresentConfig([&](DisplayWrapper& display,
3307 const DisplayConfiguration& config) {
3308 const auto displayId = display.getDisplayId();
3309 auto minFrameIntervalNs = config.vrrConfig->minFrameIntervalNs;
3310 const auto timeoutNs = config.vrrConfig->notifyExpectedPresentConfig->timeoutNs;
3311
3312 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3313 ::android::PIXEL_FORMAT_RGBA_8888);
3314 ASSERT_NE(nullptr, buffer);
3315 const auto layer = createOnScreenLayer(display);
3316 auto& writer = getWriter(displayId);
3317 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3318 /*acquireFence*/ -1);
3319 sp<::android::Fence> presentFence = presentAndGetFence(ComposerClientWriter::kNoTimestamp,
3320 displayId, minFrameIntervalNs);
3321 presentFence->waitForever(LOG_TAG);
3322 auto lastPresentTimeNs = presentFence->getSignalTime();
3323
3324 // Frame presents 30ms after timeout
3325 const auto timeout = static_cast<const std::chrono::nanoseconds>(timeoutNs);
3326 const auto vsyncPeriod = config.vsyncPeriod;
3327 int32_t frameAfterTimeoutNs =
3328 vsyncPeriod * static_cast<int32_t>((timeout + 30ms).count() / vsyncPeriod);
3329 auto expectedPresentTimestamp =
3330 ClockMonotonicTimestamp{lastPresentTimeNs + frameAfterTimeoutNs};
3331 std::this_thread::sleep_for(timeout);
3332 mComposerClient->notifyExpectedPresent(displayId, expectedPresentTimestamp,
3333 minFrameIntervalNs);
3334 presentFence = presentAndGetFence(expectedPresentTimestamp, displayId, minFrameIntervalNs);
3335 presentFence->waitForever(LOG_TAG);
3336 lastPresentTimeNs = presentFence->getSignalTime();
3337 ASSERT_GE(lastPresentTimeNs, expectedPresentTimestamp.timestampNanos - vsyncPeriod / 2);
3338 mComposerClient->destroyLayer(displayId, layer, &writer);
3339 });
3340 }
3341
TEST_P(GraphicsComposerAidlCommandV3Test,notifyExpectedPresentFrameIntervalChange)3342 TEST_P(GraphicsComposerAidlCommandV3Test, notifyExpectedPresentFrameIntervalChange) {
3343 if (hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) {
3344 GTEST_SUCCEED() << "Device has unreliable present fences capability, skipping";
3345 return;
3346 }
3347 forEachNotifyExpectedPresentConfig([&](DisplayWrapper& display,
3348 const DisplayConfiguration& config) {
3349 const auto displayId = display.getDisplayId();
3350 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3351 ::android::PIXEL_FORMAT_RGBA_8888);
3352 ASSERT_NE(nullptr, buffer);
3353 const auto layer = createOnScreenLayer(display);
3354 auto& writer = getWriter(displayId);
3355 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3356 /*acquireFence*/ -1);
3357 auto minFrameIntervalNs = config.vrrConfig->minFrameIntervalNs;
3358 sp<::android::Fence> presentFence = presentAndGetFence(ComposerClientWriter::kNoTimestamp,
3359 displayId, minFrameIntervalNs);
3360 presentFence->waitForever(LOG_TAG);
3361 auto lastPresentTimeNs = presentFence->getSignalTime();
3362
3363 auto vsyncPeriod = config.vsyncPeriod;
3364 int32_t highestDivisor = ComposerClientWrapper::kMaxFrameIntervalNs / vsyncPeriod;
3365 int32_t lowestDivisor = minFrameIntervalNs / vsyncPeriod;
3366 const auto headsUpNs = config.vrrConfig->notifyExpectedPresentConfig->headsUpNs;
3367 float totalDivisorsPassed = 0.f;
3368 for (int divisor = lowestDivisor; divisor <= highestDivisor; divisor++) {
3369 const auto frameIntervalNs = vsyncPeriod * divisor;
3370 const auto frameAfterHeadsUp = frameIntervalNs * (headsUpNs / frameIntervalNs);
3371 auto presentTime = lastPresentTimeNs + frameIntervalNs + frameAfterHeadsUp;
3372 const auto expectedPresentTimestamp = ClockMonotonicTimestamp{presentTime};
3373 ASSERT_TRUE(mComposerClient
3374 ->notifyExpectedPresent(displayId, expectedPresentTimestamp,
3375 frameIntervalNs)
3376 .isOk());
3377 presentFence = presentAndGetFence(expectedPresentTimestamp, displayId, frameIntervalNs);
3378 presentFence->waitForever(LOG_TAG);
3379 lastPresentTimeNs = presentFence->getSignalTime();
3380 if (lastPresentTimeNs >= expectedPresentTimestamp.timestampNanos - vsyncPeriod / 2) {
3381 ++totalDivisorsPassed;
3382 }
3383 }
3384 EXPECT_TRUE(totalDivisorsPassed >
3385 (static_cast<float>(highestDivisor - lowestDivisor)) * 0.75f);
3386 mComposerClient->destroyLayer(displayId, layer, &writer);
3387 });
3388 }
3389
TEST_P(GraphicsComposerAidlCommandV3Test,frameIntervalChangeAtPresentFrame)3390 TEST_P(GraphicsComposerAidlCommandV3Test, frameIntervalChangeAtPresentFrame) {
3391 if (hasCapability(Capability::PRESENT_FENCE_IS_NOT_RELIABLE)) {
3392 GTEST_SUCCEED() << "Device has unreliable present fences capability, skipping";
3393 return;
3394 }
3395 forEachNotifyExpectedPresentConfig([&](DisplayWrapper& display,
3396 const DisplayConfiguration& config) {
3397 const auto displayId = display.getDisplayId();
3398 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3399 ::android::PIXEL_FORMAT_RGBA_8888);
3400 ASSERT_NE(nullptr, buffer);
3401 const auto layer = createOnScreenLayer(display);
3402 auto& writer = getWriter(displayId);
3403 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3404 /*acquireFence*/ -1);
3405 auto minFrameIntervalNs = config.vrrConfig->minFrameIntervalNs;
3406
3407 auto vsyncPeriod = config.vsyncPeriod;
3408 int32_t highestDivisor = ComposerClientWrapper::kMaxFrameIntervalNs / vsyncPeriod;
3409 int32_t lowestDivisor = minFrameIntervalNs / vsyncPeriod;
3410 const auto headsUpNs = config.vrrConfig->notifyExpectedPresentConfig->headsUpNs;
3411 float totalDivisorsPassed = 0.f;
3412 int divisor = lowestDivisor;
3413 auto frameIntervalNs = vsyncPeriod * divisor;
3414 sp<::android::Fence> presentFence =
3415 presentAndGetFence(ComposerClientWriter::kNoTimestamp, displayId, frameIntervalNs);
3416 presentFence->waitForever(LOG_TAG);
3417 auto lastPresentTimeNs = presentFence->getSignalTime();
3418 do {
3419 frameIntervalNs = vsyncPeriod * divisor;
3420 ++divisor;
3421 const auto nextFrameIntervalNs = vsyncPeriod * divisor;
3422 const auto frameAfterHeadsUp = frameIntervalNs * (headsUpNs / frameIntervalNs);
3423 auto presentTime = lastPresentTimeNs + frameIntervalNs + frameAfterHeadsUp;
3424 const auto expectedPresentTimestamp = ClockMonotonicTimestamp{presentTime};
3425 presentFence =
3426 presentAndGetFence(expectedPresentTimestamp, displayId, nextFrameIntervalNs);
3427 presentFence->waitForever(LOG_TAG);
3428 lastPresentTimeNs = presentFence->getSignalTime();
3429 if (lastPresentTimeNs >= expectedPresentTimestamp.timestampNanos - vsyncPeriod / 2) {
3430 ++totalDivisorsPassed;
3431 }
3432 } while (divisor < highestDivisor);
3433 EXPECT_TRUE(totalDivisorsPassed >
3434 (static_cast<float>(highestDivisor - lowestDivisor)) * 0.75f);
3435 mComposerClient->destroyLayer(displayId, layer, &writer);
3436 });
3437 }
3438
3439 class GraphicsComposerAidlCommandV4Test : public GraphicsComposerAidlCommandTest {
3440 protected:
SetUp()3441 void SetUp() override {
3442 GraphicsComposerAidlTest::SetUp();
3443 if (getInterfaceVersion() <= 3) {
3444 GTEST_SKIP() << "Device interface version is expected to be >= 4";
3445 }
3446 }
3447 };
3448
TEST_P(GraphicsComposerAidlCommandV4Test,getMaxLayerPictureProfiles_success)3449 TEST_P(GraphicsComposerAidlCommandV4Test, getMaxLayerPictureProfiles_success) {
3450 for (auto& display : mDisplays) {
3451 int64_t displayId = display.getDisplayId();
3452 if (!hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING)) {
3453 continue;
3454 }
3455 const auto& [status, maxProfiles] =
3456 mComposerClient->getMaxLayerPictureProfiles(displayId);
3457 EXPECT_TRUE(status.isOk());
3458 EXPECT_THAT(maxProfiles, Ge(0));
3459 }
3460 }
3461
TEST_P(GraphicsComposerAidlCommandV4Test,getMaxLayerPictureProfiles_unsupported)3462 TEST_P(GraphicsComposerAidlCommandV4Test, getMaxLayerPictureProfiles_unsupported) {
3463 for (auto& display : mDisplays) {
3464 int64_t displayId = display.getDisplayId();
3465 if (hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING)) {
3466 continue;
3467 }
3468 const auto& [status, maxProfiles] =
3469 mComposerClient->getMaxLayerPictureProfiles(displayId);
3470 EXPECT_FALSE(status.isOk());
3471 EXPECT_NO_FATAL_FAILURE(
3472 assertServiceSpecificError(status, IComposerClient::EX_UNSUPPORTED));
3473 }
3474 }
3475
TEST_P(GraphicsComposerAidlCommandV4Test,setDisplayPictureProfileId_success)3476 TEST_P(GraphicsComposerAidlCommandV4Test, setDisplayPictureProfileId_success) {
3477 for (auto& display : mDisplays) {
3478 int64_t displayId = display.getDisplayId();
3479 if (!hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING)) {
3480 continue;
3481 }
3482
3483 auto& writer = getWriter(displayId);
3484 const auto layer = createOnScreenLayer(display);
3485 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3486 ::android::PIXEL_FORMAT_RGBA_8888);
3487 ASSERT_NE(nullptr, buffer->handle);
3488 // TODO(b/337330263): Lookup profile IDs from MediaQualityManager
3489 writer.setDisplayPictureProfileId(displayId, PictureProfileId(1));
3490 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3491 /*acquireFence*/ -1);
3492 execute();
3493 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
3494 }
3495 }
3496
TEST_P(GraphicsComposerAidlCommandV4Test,setLayerPictureProfileId_success)3497 TEST_P(GraphicsComposerAidlCommandV4Test, setLayerPictureProfileId_success) {
3498 for (auto& display : mDisplays) {
3499 int64_t displayId = display.getDisplayId();
3500 if (!hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING)) {
3501 continue;
3502 }
3503 const auto& [status, maxProfiles] = mComposerClient->getMaxLayerPictureProfiles(displayId);
3504 EXPECT_TRUE(status.isOk());
3505 if (maxProfiles == 0) {
3506 continue;
3507 }
3508
3509 auto& writer = getWriter(displayId);
3510 const auto layer = createOnScreenLayer(display);
3511 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3512 ::android::PIXEL_FORMAT_RGBA_8888);
3513 ASSERT_NE(nullptr, buffer->handle);
3514 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3515 /*acquireFence*/ -1);
3516 // TODO(b/337330263): Lookup profile IDs from MediaQualityManager
3517 writer.setLayerPictureProfileId(displayId, layer, PictureProfileId(1));
3518 execute();
3519 ASSERT_TRUE(getReader(display.getDisplayId()).takeErrors().empty());
3520 }
3521 }
3522
TEST_P(GraphicsComposerAidlCommandV4Test,setLayerPictureProfileId_failsWithTooManyProfiles)3523 TEST_P(GraphicsComposerAidlCommandV4Test, setLayerPictureProfileId_failsWithTooManyProfiles) {
3524 for (auto& display : mDisplays) {
3525 int64_t displayId = display.getDisplayId();
3526 if (!hasDisplayCapability(displayId, DisplayCapability::PICTURE_PROCESSING)) {
3527 continue;
3528 }
3529 const auto& [status, maxProfiles] = mComposerClient->getMaxLayerPictureProfiles(displayId);
3530 EXPECT_TRUE(status.isOk());
3531 if (maxProfiles == 0) {
3532 continue;
3533 }
3534
3535 auto& writer = getWriter(displayId);
3536 for (int profileId = 1; profileId <= maxProfiles + 1; ++profileId) {
3537 const auto layer = createOnScreenLayer(display);
3538 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3539 ::android::PIXEL_FORMAT_RGBA_8888);
3540 ASSERT_NE(nullptr, buffer->handle);
3541 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3542 /*acquireFence*/ -1);
3543 // TODO(b/337330263): Lookup profile IDs from MediaQualityManager
3544 writer.setLayerPictureProfileId(displayId, layer, PictureProfileId(profileId));
3545 }
3546 execute();
3547 const auto errors = getReader(display.getDisplayId()).takeErrors();
3548 ASSERT_TRUE(errors.size() == 1 &&
3549 errors[0].errorCode == IComposerClient::EX_PICTURE_PROFILE_MAX_EXCEEDED);
3550 }
3551 }
3552
3553 // @NonApiTest = check the status if calling getLuts
TEST_P(GraphicsComposerAidlCommandV4Test,GetLuts)3554 TEST_P(GraphicsComposerAidlCommandV4Test, GetLuts) {
3555 for (auto& display : mDisplays) {
3556 int64_t displayId = display.getDisplayId();
3557 auto& writer = getWriter(displayId);
3558 const auto layer = createOnScreenLayer(display);
3559 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3560 ::android::PIXEL_FORMAT_RGBA_8888);
3561 ASSERT_NE(nullptr, buffer->handle);
3562 writer.setLayerBuffer(displayId, layer, /*slot*/ 0, buffer->handle,
3563 /*acquireFence*/ -1);
3564 Buffer aidlbuffer;
3565 aidlbuffer.handle = ::android::dupToAidl(buffer->handle);
3566 std::vector<Buffer> buffers;
3567 buffers.push_back(std::move(aidlbuffer));
3568 const auto& [status, _] = mComposerClient->getLuts(displayId, buffers);
3569 if (!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
3570 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) {
3571 GTEST_SKIP() << "getLuts is not supported";
3572 return;
3573 }
3574 ASSERT_TRUE(status.isOk());
3575 }
3576 }
3577
TEST_P(GraphicsComposerAidlCommandV4Test,SetUnsupportedLayerLuts)3578 TEST_P(GraphicsComposerAidlCommandV4Test, SetUnsupportedLayerLuts) {
3579 for (const DisplayWrapper& display : mDisplays) {
3580 auto& writer = getWriter(display.getDisplayId());
3581 const auto& [layerStatus, layer] =
3582 mComposerClient->createLayer(display.getDisplayId(), kBufferSlotCount, &writer);
3583 EXPECT_TRUE(layerStatus.isOk());
3584 const auto& [status, properties] = mComposerClient->getOverlaySupport();
3585
3586 // TODO (b/362319189): add Lut VTS enforcement
3587 if ((!status.isOk() && status.getExceptionCode() == EX_SERVICE_SPECIFIC &&
3588 status.getServiceSpecificError() == IComposerClient::EX_UNSUPPORTED) ||
3589 (status.isOk() && !properties.lutProperties)) {
3590 int32_t size = 7;
3591 size_t bufferSize = static_cast<size_t>(size) * sizeof(float);
3592 int32_t fd = ashmem_create_region("lut_shared_mem", bufferSize);
3593 void* ptr = mmap(nullptr, bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
3594 std::vector<float> buffers = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
3595 memcpy(ptr, buffers.data(), bufferSize);
3596 munmap(ptr, bufferSize);
3597 Luts luts;
3598 luts.offsets = {0};
3599 luts.lutProperties = {
3600 {LutProperties::Dimension::ONE_D, size, {LutProperties::SamplingKey::RGB}}};
3601 luts.pfd = ndk::ScopedFileDescriptor(fd);
3602
3603 const auto layer = createOnScreenLayer(display);
3604 const auto buffer = allocate(display.getDisplayWidth(), display.getDisplayHeight(),
3605 ::android::PIXEL_FORMAT_RGBA_8888);
3606 ASSERT_NE(nullptr, buffer->handle);
3607 writer.setLayerBuffer(display.getDisplayId(), layer, /*slot*/ 0, buffer->handle,
3608 /*acquireFence*/ -1);
3609 writer.setLayerLuts(display.getDisplayId(), layer, luts);
3610 writer.validateDisplay(display.getDisplayId(), ComposerClientWriter::kNoTimestamp,
3611 ComposerClientWrapper::kNoFrameIntervalNs);
3612 execute();
3613 const auto errors = getReader(display.getDisplayId()).takeErrors();
3614 if (errors.size() == 1 && errors[0].errorCode == IComposerClient::EX_UNSUPPORTED) {
3615 GTEST_SUCCEED() << "setLayerLuts is not supported";
3616 return;
3617 }
3618 // change to client composition
3619 ASSERT_FALSE(getReader(display.getDisplayId())
3620 .takeChangedCompositionTypes(display.getDisplayId())
3621 .empty());
3622 }
3623 }
3624 }
3625
TEST_P(GraphicsComposerAidlCommandV4Test,GetDisplayConfigurations_hasHdrType)3626 TEST_P(GraphicsComposerAidlCommandV4Test, GetDisplayConfigurations_hasHdrType) {
3627 for (const auto& display : mDisplays) {
3628 const auto& [status, displayConfigurations] =
3629 mComposerClient->getDisplayConfigurations(display.getDisplayId());
3630 EXPECT_TRUE(status.isOk());
3631 EXPECT_FALSE(displayConfigurations.empty());
3632
3633 for (const auto& displayConfig : displayConfigurations) {
3634 EXPECT_NE(displayConfig.hdrOutputType, OutputType::INVALID);
3635 }
3636 }
3637 }
3638
3639 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlCommandTest);
3640 INSTANTIATE_TEST_SUITE_P(
3641 PerInstance, GraphicsComposerAidlCommandTest,
3642 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3643 ::android::PrintInstanceNameToString);
3644 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlTest);
3645 INSTANTIATE_TEST_SUITE_P(
3646 PerInstance, GraphicsComposerAidlTest,
3647 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3648 ::android::PrintInstanceNameToString);
3649 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlV2Test);
3650 INSTANTIATE_TEST_SUITE_P(
3651 PerInstance, GraphicsComposerAidlV2Test,
3652 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3653 ::android::PrintInstanceNameToString);
3654 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlV3Test);
3655 INSTANTIATE_TEST_SUITE_P(
3656 PerInstance, GraphicsComposerAidlV3Test,
3657 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3658 ::android::PrintInstanceNameToString);
3659 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlCommandV2Test);
3660 INSTANTIATE_TEST_SUITE_P(
3661 PerInstance, GraphicsComposerAidlCommandV2Test,
3662 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3663 ::android::PrintInstanceNameToString);
3664 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlCommandV3Test);
3665 INSTANTIATE_TEST_SUITE_P(
3666 PerInstance, GraphicsComposerAidlCommandV3Test,
3667 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3668 ::android::PrintInstanceNameToString);
3669 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GraphicsComposerAidlCommandV4Test);
3670 INSTANTIATE_TEST_SUITE_P(
3671 PerInstance, GraphicsComposerAidlCommandV4Test,
3672 testing::ValuesIn(::android::getAidlHalInstanceNames(IComposer::descriptor)),
3673 ::android::PrintInstanceNameToString);
3674 } // namespace aidl::android::hardware::graphics::composer3::vts
3675
main(int argc,char ** argv)3676 int main(int argc, char** argv) {
3677 ::testing::InitGoogleTest(&argc, argv);
3678
3679 using namespace std::chrono_literals;
3680 if (!android::base::WaitForProperty("init.svc.surfaceflinger", "stopped", 10s)) {
3681 ALOGE("Failed to stop init.svc.surfaceflinger");
3682 return -1;
3683 }
3684
3685 android::ProcessState::self()->setThreadPoolMaxThreadCount(4);
3686
3687 // The binder threadpool we start will inherit sched policy and priority
3688 // of (this) creating thread. We want the binder thread pool to have
3689 // SCHED_FIFO policy and priority 1 (lowest RT priority)
3690 // Once the pool is created we reset this thread's priority back to
3691 // original.
3692 // This thread policy is based on what we do in the SurfaceFlinger while starting
3693 // the thread pool and we need to replicate that for the VTS tests.
3694 int newPriority = 0;
3695 int origPolicy = sched_getscheduler(0);
3696 struct sched_param origSchedParam;
3697
3698 int errorInPriorityModification = sched_getparam(0, &origSchedParam);
3699 if (errorInPriorityModification == 0) {
3700 int policy = SCHED_FIFO;
3701 newPriority = sched_get_priority_min(policy);
3702
3703 struct sched_param param;
3704 param.sched_priority = newPriority;
3705
3706 errorInPriorityModification = sched_setscheduler(0, policy, ¶m);
3707 }
3708
3709 // start the thread pool
3710 android::ProcessState::self()->startThreadPool();
3711
3712 // Reset current thread's policy and priority
3713 if (errorInPriorityModification == 0) {
3714 errorInPriorityModification = sched_setscheduler(0, origPolicy, &origSchedParam);
3715 } else {
3716 ALOGE("Failed to set VtsHalGraphicsComposer3_TargetTest binder threadpool priority to "
3717 "SCHED_FIFO");
3718 }
3719
3720 return RUN_ALL_TESTS();
3721 }
3722