1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hdi_composer_ut.h"
17 #include <chrono>
18 #include <cinttypes>
19 #include <algorithm>
20 #include "v1_0/include/idisplay_composer_interface.h"
21 #include "v1_0/display_composer_type.h"
22 #include "v1_0/display_buffer_type.h"
23 #include "display_test.h"
24 #include "display_test_utils.h"
25 #include "hdi_composition_check.h"
26 #include "hdi_test_device.h"
27 #include "hdi_test_device_common.h"
28 #include "hdi_test_display.h"
29 #include "hdi_test_render_utils.h"
30
31 using namespace OHOS::HDI::Display::Buffer::V1_0;
32 using namespace OHOS::HDI::Display::Composer::V1_0;
33 using namespace OHOS::HDI::Display::TEST;
34 using namespace testing::ext;
35
36 static sptr<IDisplayComposerInterface> g_composerDevice = nullptr;
37 static std::shared_ptr<IDisplayBuffer> g_gralloc = nullptr;
38 static std::vector<uint32_t> g_displayIds;
39 const int SLEEP_CONT_100 = 100;
40 const int SLEEP_CONT_2000 = 2000;
41
GetFirstDisplay()42 static inline std::shared_ptr<HdiTestDisplay> GetFirstDisplay()
43 {
44 return HdiTestDevice::GetInstance().GetFirstDisplay();
45 }
46
CheckComposition(std::vector<LayerSettings> & layers,BufferHandle * clientBuffer,uint32_t checkType=HdiCompositionCheck::CHECK_VERTEX)47 static int32_t CheckComposition(std::vector<LayerSettings> &layers, BufferHandle* clientBuffer,
48 uint32_t checkType = HdiCompositionCheck::CHECK_VERTEX)
49 {
50 DISPLAY_TEST_CHK_RETURN((clientBuffer == nullptr), DISPLAY_NULL_PTR, DISPLAY_TEST_LOGE("client buffer is nullptr"));
51 return HdiCompositionCheck::GetInstance().Check(layers, *clientBuffer, checkType);
52 }
53
CreateTestLayer(LayerSettings setting,uint32_t zorder)54 static std::shared_ptr<HdiTestLayer> CreateTestLayer(LayerSettings setting, uint32_t zorder)
55 {
56 int ret;
57 HdiTestDevice::GetInstance();
58 DISPLAY_TEST_LOGD("color 0x%x", setting.color);
59 std::shared_ptr<HdiTestDisplay> display = HdiTestDevice::GetInstance().GetFirstDisplay();
60 DISPLAY_TEST_CHK_RETURN((display == nullptr), nullptr, DISPLAY_TEST_LOGE("can not get display"));
61
62 std::shared_ptr<HdiTestLayer> layer = display->CreateHdiTestLayer(setting.bufferSize.w, setting.bufferSize.h);
63 DISPLAY_TEST_CHK_RETURN((layer == nullptr), nullptr, DISPLAY_TEST_LOGE("can not create hdi test layer"));
64
65 layer->SetLayerPosition(setting.displayRect);
66
67 layer->SetCompType(setting.compositionType);
68
69 if ((setting.alpha >= 0) && (setting.alpha <= 0xff)) { // alpha rang 0x00 ~ 0xff
70 LayerAlpha alpha = { 0 };
71 alpha.gAlpha = setting.alpha;
72 alpha.enGlobalAlpha = true;
73 layer->SetAlpha(alpha);
74 }
75 HdiGrallocBuffer* handle = layer->GetFrontBuffer();
76 DISPLAY_TEST_CHK_RETURN((handle == nullptr), nullptr, DISPLAY_TEST_LOGE("can not get front buffer"));
77 ClearColor(*(handle->Get()), setting.color);
78 ret = layer->SwapFrontToBackQ();
79 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), nullptr, DISPLAY_TEST_LOGE("SwapFrontToBackQ failed"));
80 layer->SetZorder(zorder);
81 layer->SetBlendType(setting.blendType);
82 layer->SetTransform(setting.rotate);
83 return layer;
84 }
85
PrepareAndPrensent()86 static int PrepareAndPrensent()
87 {
88 int ret;
89 DISPLAY_TEST_LOGD();
90 std::shared_ptr<HdiTestDisplay> display = HdiTestDevice::GetInstance().GetFirstDisplay();
91 DISPLAY_TEST_CHK_RETURN((display == nullptr), DISPLAY_FAILURE, DISPLAY_TEST_LOGE("can not get display"));
92
93 ret = display->PrepareDisplayLayers();
94 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE,
95 DISPLAY_TEST_LOGE("PrepareDisplayLayers failed"));
96
97 ret = display->Commit();
98 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_TEST_LOGE("Commit failed"));
99 return DISPLAY_SUCCESS;
100 }
101
TestVBlankCallback(unsigned int sequence,uint64_t ns,void * data)102 static void TestVBlankCallback(unsigned int sequence, uint64_t ns, void* data)
103 {
104 static uint64_t lastns;
105 DISPLAY_TEST_LOGD("seq %{public}d ns %" PRId64 " duration %" PRId64 " ns", sequence, ns, (ns - lastns));
106 lastns = ns;
107 VblankCtr::GetInstance().NotifyVblank(sequence, ns, data);
108 }
109
AdjustLayerSettings(std::vector<LayerSettings> & settings,uint32_t w,uint32_t h)110 static void AdjustLayerSettings(std::vector<LayerSettings> &settings, uint32_t w, uint32_t h)
111 {
112 DISPLAY_TEST_LOGD();
113 for (uint32_t i = 0; i < settings.size(); i++) {
114 LayerSettings& setting = settings[i];
115 DISPLAY_TEST_LOGD(" ratio w: %f ratio h: %f", setting.rectRatio.w, setting.rectRatio.h);
116 if ((setting.rectRatio.w > 0.0f) && (setting.rectRatio.h > 0.0f)) {
117 setting.displayRect.h = static_cast<uint32_t>(setting.rectRatio.h * h);
118 setting.displayRect.w = static_cast<uint32_t>(setting.rectRatio.w * w);
119 setting.displayRect.x = static_cast<uint32_t>(setting.rectRatio.x * w);
120 setting.displayRect.y = static_cast<uint32_t>(setting.rectRatio.y * h);
121 DISPLAY_TEST_LOGD("display rect adust form %f %f %f %f to %{public}d %{public}d %{public}d %{public}d ",
122 setting.rectRatio.x, setting.rectRatio.y, setting.rectRatio.w, setting.rectRatio.h,
123 setting.displayRect.x, setting.displayRect.y, setting.displayRect.w, setting.displayRect.h);
124 }
125
126 if ((setting.bufferRatio.h > 0.0f) || (setting.bufferRatio.w > 0.0f)) {
127 setting.bufferSize.h = static_cast<uint32_t>(setting.bufferRatio.h * h);
128 setting.bufferSize.w = static_cast<uint32_t>(setting.bufferRatio.w * w);
129 DISPLAY_TEST_LOGD("buffer size adjust for %f %f to %{public}d %{public}d",
130 setting.bufferRatio.w, setting.bufferRatio.h, setting.bufferSize.w, setting.bufferSize.h);
131 }
132
133 if ((setting.bufferSize.w == 0) || (setting.bufferSize.h == 0)) {
134 DISPLAY_TEST_LOGD("buffer size adjust for %{public}d %{public}d to %{public}d %{public}d",
135 setting.bufferSize.w, setting.bufferSize.h, setting.displayRect.w, setting.displayRect.h);
136
137 setting.bufferSize.w = setting.displayRect.w;
138 setting.bufferSize.h = setting.displayRect.h;
139 }
140 }
141 }
142
CreateLayers(std::vector<LayerSettings> & settings)143 static std::vector<std::shared_ptr<HdiTestLayer>> CreateLayers(std::vector<LayerSettings> &settings)
144 {
145 DISPLAY_TEST_LOGD("settings %{public}zd", settings.size());
146 std::vector<std::shared_ptr<HdiTestLayer>> layers;
147 DisplayModeInfo mode = GetFirstDisplay()->GetCurrentMode();
148 AdjustLayerSettings(settings, mode.width, mode.height);
149 for (uint32_t i = 0; i < settings.size(); i++) {
150 LayerSettings setting = settings[i];
151
152 auto layer = CreateTestLayer(setting, i);
153 layers.push_back(layer);
154 }
155
156 return layers;
157 }
158
PresentAndCheck(std::vector<LayerSettings> & layerSettings,uint32_t checkType=HdiCompositionCheck::CHECK_VERTEX)159 static inline void PresentAndCheck(std::vector<LayerSettings> &layerSettings,
160 uint32_t checkType = HdiCompositionCheck::CHECK_VERTEX)
161 {
162 int ret = PrepareAndPrensent();
163 ASSERT_TRUE((ret == DISPLAY_SUCCESS));
164 if ((GetFirstDisplay()->SnapShot()) != nullptr) {
165 HdiTestDevice::GetInstance().GetGrallocInterface()->InvalidateCache(*(GetFirstDisplay()->SnapShot()));
166 ret = CheckComposition(layerSettings, GetFirstDisplay()->SnapShot(), checkType);
167 ASSERT_TRUE((ret == DISPLAY_SUCCESS));
168 }
169 }
170
SetUpTestCase()171 void DeviceTest::SetUpTestCase()
172 {
173 int ret = HdiTestDevice::GetInstance().InitDevice();
174 ASSERT_TRUE(ret == DISPLAY_SUCCESS);
175
176 g_composerDevice = HdiTestDevice::GetInstance().GetDeviceInterface();
177 ASSERT_TRUE(g_composerDevice != nullptr);
178
179 g_gralloc.reset(IDisplayBuffer::Get());
180 ASSERT_TRUE(g_gralloc != nullptr);
181
182 g_displayIds = HdiTestDevice::GetInstance().GetDevIds();
183 ASSERT_TRUE(g_displayIds.size() > 0);
184 }
185
TearDownTestCase()186 void DeviceTest::TearDownTestCase()
187 {
188 HdiTestDevice::GetInstance().Clear();
189 HdiTestDevice::GetInstance().GetFirstDisplay()->ResetClientLayer();
190 }
191
NotifyVblank(unsigned int sequence,uint64_t ns,const void * data)192 void VblankCtr::NotifyVblank(unsigned int sequence, uint64_t ns, const void* data)
193 {
194 DISPLAY_TEST_LOGD();
195 if (data != nullptr) {
196 DISPLAY_TEST_LOGD("sequence = %{public}u, ns = %" PRIu64 "", sequence, ns);
197 }
198 std::unique_lock<std::mutex> lg(vblankMutex_);
199 hasVblank_ = true;
200 vblankCondition_.notify_one();
201 DISPLAY_TEST_LOGD();
202 }
203
~VblankCtr()204 VblankCtr::~VblankCtr() {}
205
WaitVblank(uint32_t ms)206 int32_t VblankCtr::WaitVblank(uint32_t ms)
207 {
208 bool ret = false;
209 DISPLAY_TEST_LOGD();
210 std::unique_lock<std::mutex> lck(vblankMutex_);
211 hasVblank_ = false; // must wait next vblank
212 ret = vblankCondition_.wait_for(lck, std::chrono::milliseconds(ms), [=] { return hasVblank_; });
213 DISPLAY_TEST_LOGD();
214 if (!ret) {
215 return DISPLAY_FAILURE;
216 }
217 return DISPLAY_SUCCESS;
218 }
219
220 HWTEST_F(DeviceTest, test_SetClientBufferCacheCount, TestSize.Level1)
221 {
222 const uint32_t CACHE_COUNT = 5;
223 auto ret = g_composerDevice->SetClientBufferCacheCount(g_displayIds[0], CACHE_COUNT);
224 EXPECT_EQ(DISPLAY_SUCCESS, ret);
225 }
226
227 HWTEST_F(DeviceTest, test_GetDisplayCapability, TestSize.Level1)
228 {
229 DisplayCapability info;
230 auto ret = g_composerDevice->GetDisplayCapability(g_displayIds[0], info);
231 EXPECT_EQ(DISPLAY_SUCCESS, ret);
232 }
233
234 HWTEST_F(DeviceTest, test_GetDisplaySupportedModes, TestSize.Level1)
235 {
236 std::vector<DisplayModeInfo> modes;
237 auto ret = g_composerDevice->GetDisplaySupportedModes(g_displayIds[0], modes);
238 EXPECT_EQ(DISPLAY_SUCCESS, ret);
239 }
240
241 HWTEST_F(DeviceTest, test_GetDisplayMode, TestSize.Level1)
242 {
243 uint32_t MODE = 0;
244 auto ret = g_composerDevice->GetDisplayMode(g_displayIds[0], MODE);
245 EXPECT_EQ(DISPLAY_SUCCESS, ret);
246 }
247
248 HWTEST_F(DeviceTest, test_SetDisplayMode, TestSize.Level1)
249 {
250 const uint32_t MODE = 0;
251 auto ret = g_composerDevice->SetDisplayMode(g_displayIds[0], MODE);
252 EXPECT_EQ(DISPLAY_SUCCESS, ret);
253 }
254
255 HWTEST_F(DeviceTest, test_GetDisplayPowerStatus, TestSize.Level1)
256 {
257 DispPowerStatus powerStatus = DispPowerStatus::POWER_STATUS_OFF;
258 auto ret = g_composerDevice->GetDisplayPowerStatus(g_displayIds[0], powerStatus);
259 EXPECT_EQ(DISPLAY_SUCCESS, ret);
260 }
261
262 HWTEST_F(DeviceTest, test_SetDisplayPowerStatus, TestSize.Level1)
263 {
264 auto ret = g_composerDevice->SetDisplayPowerStatus(g_displayIds[0], DispPowerStatus::POWER_STATUS_STANDBY);
265 EXPECT_EQ(DISPLAY_SUCCESS, ret);
266
267 ret = g_composerDevice->SetDisplayPowerStatus(g_displayIds[0], DispPowerStatus::POWER_STATUS_ON);
268 EXPECT_EQ(DISPLAY_SUCCESS, ret);
269 }
270
271 #ifdef DISPLAY_COMMUNITY
272 HWTEST_F(DeviceTest, test_GetDisplayBacklight, TestSize.Level1)
273 {
274 uint32_t level;
275 auto ret = g_composerDevice->GetDisplayBacklight(g_displayIds[0], level);
276 EXPECT_EQ(DISPLAY_SUCCESS, ret);
277 }
278 #endif
279
280 HWTEST_F(DeviceTest, test_SetDisplayBacklight, TestSize.Level1)
281 {
282 const uint32_t LEVEL = 10;
283 auto ret = g_composerDevice->SetDisplayBacklight(g_displayIds[0], LEVEL);
284 EXPECT_EQ(DISPLAY_SUCCESS, ret);
285 }
286
287 HWTEST_F(DeviceTest, test_GetDisplayProperty, TestSize.Level1)
288 {
289 const uint32_t PROPERTY_ID = 1;
290 uint64_t propertyValue = 0;
291 auto ret = g_composerDevice->GetDisplayProperty(g_displayIds[0], PROPERTY_ID, propertyValue);
292 // not support
293 EXPECT_EQ(DISPLAY_FAILURE, ret);
294 }
295
296 HWTEST_F(DeviceTest, test_GetDisplayCompChange, TestSize.Level1)
297 {
298 std::vector<uint32_t> layers {};
299 std::vector<int32_t> type {};
300 auto ret = g_composerDevice->GetDisplayCompChange(g_displayIds[0], layers, type);
301 EXPECT_EQ(DISPLAY_SUCCESS, ret);
302 }
303
304 HWTEST_F(DeviceTest, test_SetDisplayClientCrop, TestSize.Level1)
305 {
306 const int32_t WIDTH = 1920;
307 const int32_t HEIGHT = 1080;
308 IRect rect = {0, 0, WIDTH, HEIGHT};
309 auto ret = g_composerDevice->SetDisplayClientCrop(g_displayIds[0], rect);
310 // not support
311 EXPECT_EQ(DISPLAY_FAILURE, ret);
312 }
313
314 HWTEST_F(DeviceTest, test_GetDisplayReleaseFence, TestSize.Level1)
315 {
316 std::vector<uint32_t> layers {};
317 std::vector<int32_t> fences {};
318 auto ret = g_composerDevice->GetDisplayReleaseFence(g_displayIds[0], layers, fences);
319 EXPECT_EQ(DISPLAY_SUCCESS, ret);
320 }
321
322 HWTEST_F(DeviceTest, test_SetDisplayClientBuffer, TestSize.Level1)
323 {
324 BufferHandle* buffer = nullptr;
325 const int32_t WIDTH = 800;
326 const int32_t HEIGHT = 600;
327
328 AllocInfo info;
329 info.width = WIDTH;
330 info.height = HEIGHT;
331 info.usage = OHOS::HDI::Display::Composer::V1_0::HBM_USE_MEM_DMA |
332 OHOS::HDI::Display::Composer::V1_0::HBM_USE_CPU_READ |
333 OHOS::HDI::Display::Composer::V1_0::HBM_USE_CPU_WRITE;
334 info.format = PIXEL_FMT_RGBA_8888;
335
336 g_gralloc->AllocMem(info, buffer);
337 ASSERT_TRUE(buffer != nullptr);
338
339 uint32_t bufferSeq = 1;
340 auto ret = g_composerDevice->SetDisplayClientBuffer(g_displayIds[0], buffer, bufferSeq, -1);
341 g_gralloc->FreeMem(*buffer);
342 EXPECT_EQ(DISPLAY_SUCCESS, ret);
343 }
344
345 HWTEST_F(DeviceTest, test_SetDisplayClientDamage, TestSize.Level1)
346 {
347 const int32_t WIDTH = 1920;
348 const int32_t HEIGHT = 1080;
349 IRect rect = {0, 0, WIDTH, HEIGHT};
350 std::vector<IRect> vRects;
351 vRects.push_back(rect);
352 auto ret = g_composerDevice->SetDisplayClientDamage(g_displayIds[0], vRects);
353 // not support
354 EXPECT_EQ(DISPLAY_SUCCESS, ret);
355 }
356
357 HWTEST_F(DeviceTest, test_CreateVirtualDisplay, TestSize.Level1)
358 {
359 const uint32_t WIDTH = 1920;
360 const uint32_t HEIGHT = 1080;
361 int32_t format = 0;
362 uint32_t devId = 0;
363 auto ret = g_composerDevice->CreateVirtualDisplay(WIDTH, HEIGHT, format, devId);
364 // not support
365 EXPECT_EQ(DISPLAY_FAILURE, ret);
366 }
367
368 HWTEST_F(DeviceTest, test_DestroyVirtualDisplay, TestSize.Level1)
369 {
370 uint32_t devId = 0;
371 auto ret = g_composerDevice->DestroyVirtualDisplay(devId);
372 // not support
373 EXPECT_EQ(DISPLAY_FAILURE, ret);
374 }
375
376 HWTEST_F(DeviceTest, test_SetVirtualDisplayBuffer, TestSize.Level1)
377 {
378 BufferHandle* buffer = nullptr;
379 int32_t fence = -1;
380 const int32_t WIDTH = 800;
381 const int32_t HEIGHT = 600;
382
383 AllocInfo info;
384 info.width = WIDTH;
385 info.height = HEIGHT;
386 info.usage = OHOS::HDI::Display::Composer::V1_0::HBM_USE_MEM_DMA |
387 OHOS::HDI::Display::Composer::V1_0::HBM_USE_CPU_READ |
388 OHOS::HDI::Display::Composer::V1_0::HBM_USE_CPU_WRITE;
389 info.format = PIXEL_FMT_RGBA_8888;
390
391 g_gralloc->AllocMem(info, buffer);
392 ASSERT_TRUE(buffer != nullptr);
393
394 auto ret = g_composerDevice->SetVirtualDisplayBuffer(g_displayIds[0], *buffer, fence);
395 g_gralloc->FreeMem(*buffer);
396 // not support
397 EXPECT_EQ(DISPLAY_FAILURE, ret);
398 }
399
400 HWTEST_F(DeviceTest, test_SetDisplayProperty, TestSize.Level1)
401 {
402 const uint32_t PROPERTY_ID = 1;
403 const uint64_t PROPERTY_VALUE = 0;
404 auto ret = g_composerDevice->SetDisplayProperty(g_displayIds[0], PROPERTY_ID, PROPERTY_VALUE);
405 // not support
406 EXPECT_EQ(DISPLAY_FAILURE, ret);
407 }
408
409 HWTEST_F(DeviceTest, test_SetLayerCrop, TestSize.Level1)
410 {
411 std::vector<LayerSettings> settings = {
412 {
413 .rectRatio = { 0, 0, 1.0f, 1.0f },
414 .color = RED
415 },
416 };
417 std::vector<uint32_t> splitColors = { { RED, GREEN, YELLOW, BLUE, PINK, PURPLE, CYAN, TRANSPARENT } };
418
419 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
420 ASSERT_TRUE((layers.size() > 0));
421 // split the buffer
422 auto layer = layers[0];
423 HdiGrallocBuffer* handle = layer->GetBackBuffer(); // the backbuffer has not present now
424 ASSERT_TRUE((handle != nullptr));
425 auto splitRects = SplitBuffer(*(handle->Get()), splitColors);
426 PrepareAndPrensent();
427 for (uint32_t i = 0; i < splitRects.size(); i++) {
428 settings[0].color = splitColors[i];
429 layer->SetLayerCrop(splitRects[i]);
430 PresentAndCheck(settings);
431 }
432 }
433
434 HWTEST_F(DeviceTest, test_SetLayerZorder, TestSize.Level1)
435 {
436 std::vector<LayerSettings> settings = {
437 {
438 .rectRatio = { 0, 0, 1.0f, 1.0f },
439 .color = RED
440 },
441 {
442 .rectRatio = { 0, 0, 1.0f, 1.0f },
443 .color = GREEN
444 },
445 {
446 .rectRatio = { 0, 0, 1.0f, 1.0f },
447 .color = YELLOW
448 },
449 };
450
451 std::vector<std::vector<int>> zorders = {
452 { 3, 2, 1 }, { 1, 3, 2 }, { 3, 1, 2 }, { 1, 2, 3 }, { 2, 1, 3 }, { 2, 3, 1 },
453 };
454 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
455
456 for (const auto& zorderList : zorders) {
457 // adjust the zorder
458 for (uint32_t i = 0; i < zorderList.size(); i++) {
459 settings[i].zorder = zorderList[i];
460 layers[i]->SetZorder(zorderList[i]);
461 }
462 std::vector<LayerSettings> tempSettings = settings;
463 std::sort(tempSettings.begin(), tempSettings.end(),
__anon3f4469800202(const auto& l, auto const & r) 464 [=](const auto& l, auto const & r) { return l.zorder < r.zorder; });
465 // present and check
466 PresentAndCheck(tempSettings);
467 }
468 HdiTestDevice::GetInstance().Clear();
469 }
470
471 HWTEST_F(DeviceTest, test_SetLayerPreMulti, TestSize.Level1)
472 {
473 std::vector<LayerSettings> settings = {
474 {
475 .rectRatio = { 0, 0, 1.0f, 1.0f },
476 .color = GREEN
477 },
478 };
479
480 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
481 ASSERT_TRUE((layers.size() > 0));
482 PrepareAndPrensent();
483
484 auto layer = layers[0];
485 bool preMul = true;
486 auto ret = g_composerDevice->SetLayerPreMulti(g_displayIds[0], layer->GetId(), preMul);
487
488 PrepareAndPrensent();
489 HdiTestDevice::GetInstance().Clear();
490 EXPECT_EQ(DISPLAY_SUCCESS, ret);
491 }
492
493 HWTEST_F(DeviceTest, test_SetLayerAlpha, TestSize.Level1)
494 {
495 std::vector<LayerSettings> settings = {
496 {
497 .rectRatio = { 0, 0, 1.0f, 1.0f },
498 .color = GREEN
499 },
500 {
501 .rectRatio = { 0, 0, 1.0f, 1.0f },
502 .color = RED
503 },
504 };
505
506 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
507 ASSERT_TRUE((layers.size() > 0));
508
509 auto layer = layers[1];
510 LayerAlpha alpha = { 0 };
511 alpha.enGlobalAlpha = true;
512 alpha.enPixelAlpha = true;
513 alpha.gAlpha = 0;
514 alpha.alpha0 = 0;
515 alpha.alpha1 = 0;
516 layer->SetAlpha(alpha);
517
518 PrepareAndPrensent();
519 HdiTestDevice::GetInstance().Clear();
520 }
521
522 HWTEST_F(DeviceTest, test_SetLayerRegion, TestSize.Level1)
523 {
524 std::vector<LayerSettings> settings = {
525 {.rectRatio = {0, 0, 1.0f, 1.0f}, .color = GREEN, .alpha = 0xFF}
526 };
527
528 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
529 ASSERT_TRUE((layers.size() > 0));
530
531 const int32_t WIDTH = 100;
532 const int32_t HEIGHT = 100;
533 auto layer = layers[0];
534 IRect rect = {0, 0, WIDTH, HEIGHT};
535 auto ret = g_composerDevice->SetLayerRegion(g_displayIds[0], layer->GetId(), rect);
536
537 PrepareAndPrensent();
538 EXPECT_EQ(DISPLAY_SUCCESS, ret);
539 }
540
541 HWTEST_F(DeviceTest, test_SetLayerDirtyRegion, TestSize.Level1)
542 {
543 std::vector<LayerSettings> settings = {
544 {
545 .rectRatio = { 0, 0, 1.0f, 1.0f },
546 .color = BLUE
547 }
548 };
549
550 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
551 ASSERT_TRUE((layers.size() > 0));
552
553 auto layer = layers[0];
554
555 const int32_t WIDTH = 100;
556 const int32_t HEIGHT = 100;
557 IRect rect = {0, 0, WIDTH, HEIGHT};
558 std::vector<IRect> vRects;
559 vRects.push_back(rect);
560 auto ret = g_composerDevice->SetLayerDirtyRegion(g_displayIds[0], layer->GetId(), vRects);
561
562 PrepareAndPrensent();
563 HdiTestDevice::GetInstance().Clear();
564
565 EXPECT_EQ(DISPLAY_SUCCESS, ret);
566 }
567
568 HWTEST_F(DeviceTest, test_SetLayerTransformMode, TestSize.Level1)
569 {
570 std::vector<LayerSettings> settings = {
571 {
572 .rectRatio = { 0, 0, 1.0f, 1.0f },
573 .color = RED
574 }
575 };
576
577 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
578 ASSERT_TRUE((layers.size() > 0));
579
580 PrepareAndPrensent();
581
582 auto layer = layers[0];
583
584 TransformType type = TransformType::ROTATE_90;
585 auto ret = g_composerDevice->SetLayerTransformMode(g_displayIds[0], layer->GetId(), type);
586 PrepareAndPrensent();
587
588 type = TransformType::ROTATE_180;
589 ret = g_composerDevice->SetLayerTransformMode(g_displayIds[0], layer->GetId(), type);
590 PrepareAndPrensent();
591
592 type = TransformType::ROTATE_270;
593 ret = g_composerDevice->SetLayerTransformMode(g_displayIds[0], layer->GetId(), type);
594 PrepareAndPrensent();
595
596 EXPECT_EQ(DISPLAY_SUCCESS, ret);
597 }
598
599 HWTEST_F(DeviceTest, test_SetLayerVisibleRegion, TestSize.Level1)
600 {
601 std::vector<LayerSettings> settings = {
602 {
603 .rectRatio = { 0, 0, 1.0f, 1.0f },
604 .color = BLUE
605 }
606 };
607
608 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
609 ASSERT_TRUE((layers.size() > 0));
610 PrepareAndPrensent();
611 auto layer = layers[0];
612
613 const int32_t WIDTH = 500;
614 const int32_t HEIGHT = 500;
615 IRect region = {0, 0, WIDTH, HEIGHT};
616 std::vector<IRect> regions = {};
617 regions.push_back(region);
618 auto ret = g_composerDevice->SetLayerVisibleRegion(g_displayIds[0], layer->GetId(), regions);
619 PrepareAndPrensent();
620
621 EXPECT_EQ(DISPLAY_SUCCESS, ret);
622 }
623
624 HWTEST_F(DeviceTest, test_SetLayerBuffer, TestSize.Level1)
625 {
626 std::vector<LayerSettings> settings = {
627 {
628 .rectRatio = { 0, 0, 1.0f, 1.0f },
629 .color = GREEN
630 }
631 };
632
633 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
634 ASSERT_TRUE((layers.size() > 0));
635
636 auto layer = layers[0];
637
638 auto graphicBuffer = layer->AcquireBackBuffer();
__anon3f4469800302(const BufferHandle* buffer, uint32_t seqNo) 639 int32_t ret = graphicBuffer->SetGraphicBuffer([&](const BufferHandle* buffer, uint32_t seqNo) -> int32_t {
640 std::vector<uint32_t> deletingList;
641 int32_t result = g_composerDevice->SetLayerBuffer(g_displayIds[0], layer->GetId(), buffer, seqNo, -1,
642 deletingList);
643 return result;
644 });
645 PrepareAndPrensent();
646
647 EXPECT_EQ(DISPLAY_SUCCESS, ret);
648 }
649
650 HWTEST_F(DeviceTest, test_SetLayerCompositionType, TestSize.Level1)
651 {
652 std::vector<LayerSettings> settings = {
653 {
654 .rectRatio = { 0, 0, 1.0f, 1.0f },
655 .color = BLUE
656 }
657 };
658
659 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
660 ASSERT_TRUE((layers.size() > 0));
661
662 auto layer = layers[0];
663
664 CompositionType type = CompositionType::COMPOSITION_CLIENT;
665 auto ret = g_composerDevice->SetLayerCompositionType(g_displayIds[0], layer->GetId(), type);
666
667 PrepareAndPrensent();
668
669 EXPECT_EQ(DISPLAY_SUCCESS, ret);
670 }
671
672 HWTEST_F(DeviceTest, test_SetLayerBlendType, TestSize.Level1)
673 {
674 std::vector<LayerSettings> settings = {
675 {
676 .rectRatio = { 0, 0, 1.0f, 1.0f },
677 .color = GREEN
678 }
679 };
680
681 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
682 ASSERT_TRUE((layers.size() > 0));
683
684 auto layer = layers[0];
685
686 BlendType type = BlendType::BLEND_NONE;
687 auto ret = g_composerDevice->SetLayerBlendType(g_displayIds[0], layer->GetId(), type);
688
689 PrepareAndPrensent();
690
691 EXPECT_EQ(DISPLAY_SUCCESS, ret);
692 }
693
694 HWTEST_F(DeviceTest, test_SetLayerMaskInfo, TestSize.Level1)
695 {
696 std::vector<LayerSettings> settings = {
697 {
698 .rectRatio = { 0, 0, 1.0f, 1.0f },
699 .color = GREEN
700 }
701 };
702
703 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
704 ASSERT_TRUE((layers.size() > 0));
705
706 auto layer = layers[0];
707
708 MaskInfo maskInfo = MaskInfo::LAYER_HBM_SYNC;
709 auto ret = g_composerDevice->SetLayerMaskInfo(g_displayIds[0], layer->GetId(), maskInfo);
710
711 PrepareAndPrensent();
712
713 EXPECT_EQ(DISPLAY_SUCCESS, ret);
714 }
715
716 HWTEST_F(DeviceTest, test_SetLayerColor, TestSize.Level1)
717 {
718 std::vector<LayerSettings> settings = {
719 {
720 .rectRatio = { 0, 0, 1.0f, 1.0f },
721 .color = GREEN
722 }
723 };
724
725 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
726 ASSERT_TRUE((layers.size() > 0));
727
728 auto layer = layers[0];
729 const uint32_t COLOR_R = 155;
730 const uint32_t COLOR_G = 224;
731 const uint32_t COLOR_B = 88;
732 const uint32_t COLOR_A = 128;
733
734 LayerColor layerColor = {
735 .r = COLOR_R,
736 .g = COLOR_G,
737 .b = COLOR_B,
738 .a = COLOR_A
739 };
740
741 auto ret = g_composerDevice->SetLayerColor(g_displayIds[0], layer->GetId(), layerColor);
742
743 PrepareAndPrensent();
744
745 EXPECT_EQ(DISPLAY_SUCCESS, ret);
746 }
747
748 HWTEST_F(DeviceTest, test_DestroyLayer, TestSize.Level1)
749 {
750 std::vector<LayerSettings> settings = {
751 {
752 .rectRatio = { 0, 0, 1.0f, 1.0f },
753 .color = PURPLE
754 }
755 };
756
757 std::vector<std::shared_ptr<HdiTestLayer>> layers = CreateLayers(settings);
758 ASSERT_TRUE((layers.size() > 0));
759
760 auto layer = layers[0];
761
762 PrepareAndPrensent();
763 sleep(1);
764 auto ret = g_composerDevice->DestroyLayer(g_displayIds[0], layer->GetId());
765 PrepareAndPrensent();
766
767 EXPECT_EQ(DISPLAY_SUCCESS, ret);
768 }
769
770 HWTEST_F(DeviceTest, test_RegDisplayVBlankCallback, TestSize.Level1)
771 {
772 int ret;
773 DISPLAY_TEST_LOGD();
774 std::shared_ptr<HdiTestDisplay> display = HdiTestDevice::GetInstance().GetFirstDisplay();
775 ASSERT_TRUE(display != nullptr) << "get display failed";
776 ret = display->RegDisplayVBlankCallback(TestVBlankCallback, nullptr);
777 ASSERT_TRUE(ret == DISPLAY_SUCCESS) << "RegDisplayVBlankCallback failed";
778 ret = display->SetDisplayVsyncEnabled(true);
779 ASSERT_TRUE(ret == DISPLAY_SUCCESS) << "SetDisplayVsyncEnabled failed";
780 ret = VblankCtr::GetInstance().WaitVblank(SLEEP_CONT_2000); // 2000ms
781 ASSERT_TRUE(ret == DISPLAY_SUCCESS) << "WaitVblank timeout";
782 ret = display->SetDisplayVsyncEnabled(false);
783 ASSERT_TRUE(ret == DISPLAY_SUCCESS) << "SetDisplayVsyncEnabled failed";
784 usleep(SLEEP_CONT_100 * SLEEP_CONT_2000); // wait for 100ms avoid the last vsync.
785 ret = VblankCtr::GetInstance().WaitVblank(SLEEP_CONT_2000); // 2000ms
786 ASSERT_TRUE(ret != DISPLAY_SUCCESS) << "vblank do not disable";
787 }
788