1 /*
2 * Copyright (c) 2023-2024 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 <filesystem>
17 #include "gtest/gtest.h"
18 #include "common/rs_singleton.h"
19 #include "pipeline/parallel_render/rs_sub_thread_manager.h"
20 #include "pipeline/round_corner_display/rs_message_bus.h"
21 #include "pipeline/round_corner_display/rs_round_corner_display.h"
22 #include "pipeline/round_corner_display/rs_round_corner_display_manager.h"
23 #include "pipeline/round_corner_display/rs_round_corner_config.h"
24 #include "pipeline/round_corner_display/rs_rcd_render_manager.h"
25 #include "pipeline/round_corner_display/rs_rcd_surface_render_node.h"
26 #include "pipeline/round_corner_display/rs_rcd_render_visitor.h"
27 #include "pipeline/rs_display_render_node.h"
28 #include "surface_buffer_impl.h"
29 #include "rs_test_util.h"
30
31 using namespace testing;
32 using namespace testing::ext;
33
34 namespace OHOS::Rosen {
35 class RSRoundCornerDisplayTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39
40 void SetUp() override;
41 void TearDown() override;
42 };
43
SetUpTestCase()44 void RSRoundCornerDisplayTest::SetUpTestCase() {}
TearDownTestCase()45 void RSRoundCornerDisplayTest::TearDownTestCase() {}
SetUp()46 void RSRoundCornerDisplayTest::SetUp() {}
TearDown()47 void RSRoundCornerDisplayTest::TearDown() {}
48
49 struct XMLProperty {
50 std::string name;
51 std::string value;
52 };
53
CreateNodeWithProperty(const std::string & nodeName,const XMLProperty & property)54 xmlNodePtr CreateNodeWithProperty(const std::string& nodeName, const XMLProperty& property)
55 {
56 auto xmlptr = xmlNewNode(NULL, BAD_CAST(nodeName.c_str()));
57 xmlNewProp(xmlptr, BAD_CAST(property.name.c_str()), BAD_CAST(property.value.c_str()));
58 return xmlptr;
59 }
60
CreateNodeWithProperties(const std::string & nodeName,const std::vector<XMLProperty> & properties)61 xmlNodePtr CreateNodeWithProperties(const std::string& nodeName, const std::vector<XMLProperty>& properties)
62 {
63 auto xmlptr = xmlNewNode(NULL, BAD_CAST(nodeName.c_str()));
64 for (auto& property : properties) {
65 xmlNewProp(xmlptr, BAD_CAST(property.name.c_str()), BAD_CAST(property.value.c_str()));
66 }
67 return xmlptr;
68 }
69
CreateRCDLayer(const std::string & nodeName,const rs_rcd::RoundCornerLayer & layer)70 xmlNodePtr CreateRCDLayer(const std::string& nodeName, const rs_rcd::RoundCornerLayer& layer)
71 {
72 std::vector<XMLProperty> properties = {
73 {rs_rcd::ATTR_FILENAME, layer.fileName},
74 {rs_rcd::ATTR_OFFSET_X, std::to_string(layer.offsetX)},
75 {rs_rcd::ATTR_OFFSET_Y, std::to_string(layer.offsetY)},
76 {rs_rcd::ATTR_BINFILENAME, layer.binFileName},
77 {rs_rcd::ATTR_BUFFERSIZE, std::to_string(layer.bufferSize)},
78 {rs_rcd::ATTR_CLDWIDTH, std::to_string(layer.cldWidth)},
79 {rs_rcd::ATTR_CLDHEIGHT, std::to_string(layer.cldHeight)}
80 };
81 return CreateNodeWithProperties(nodeName, properties);
82 }
83
84 /*
85 * @tc.name: RCDLoadConfigFileTest
86 * @tc.desc: Test RSRoundCornerDisplayTest.RCDLoadConfigFileTest
87 * @tc.type: FUNC
88 * @tc.require:
89 */
90 HWTEST_F(RSRoundCornerDisplayTest, RCDLoadConfigFileTest, TestSize.Level1)
91 {
92 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
93 auto res = rcdInstance.LoadConfigFile();
94 std::filesystem::path pathCheck(rs_rcd::PATH_CONFIG_FILE);
95 if (std::filesystem::exists(pathCheck)) {
96 EXPECT_TRUE(res == true);
97 } else {
98 EXPECT_TRUE(res == false);
99 }
100 }
101
102 /*
103 * @tc.name: RCDInitTest
104 * @tc.desc: Test RSRoundCornerDisplayTest.RCDInitTest
105 * @tc.type: FUNC
106 * @tc.require:
107 */
108 HWTEST_F(RSRoundCornerDisplayTest, RCDInitTest, TestSize.Level1)
109 {
110 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
111 auto res = rcdInstance.Init();
112 EXPECT_TRUE(res == true);
113 }
114
115 /*
116 * @tc.name: UpdateParameterTest
117 * @tc.desc: Test RSRoundCornerDisplayTest.UpdateParameterTest
118 * @tc.type: FUNC
119 * @tc.require:
120 */
121 HWTEST_F(RSRoundCornerDisplayTest, UpdateParameterTest, TestSize.Level1)
122 {
123 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
124 auto res = rcdInstance.Init();
125 EXPECT_TRUE(res == true);
126
127 ScreenRotation curOrientation = ScreenRotation::ROTATION_0;
128 rcdInstance.UpdateOrientationStatus(curOrientation);
129
130 uint32_t width = 1344;
131 uint32_t height = 2772;
132 rcdInstance.UpdateDisplayParameter(width, height);
133
134 std::map<std::string, bool> updateFlag = {
135 {"display", true},
136 {"notch", true},
137 {"orientation", true}
138 };
139 rcdInstance.UpdateParameter(updateFlag);
140
141 int notchStatus = WINDOW_NOTCH_DEFAULT;
142 rcdInstance.UpdateNotchStatus(notchStatus);
143 EXPECT_TRUE(rcdInstance.notchStatus_ == notchStatus);
144 }
145
146 /*
147 * @tc.name: RSDrawRoundCornerTest
148 * @tc.desc: Test RSRoundCornerDisplayTest.RSDrawRoundCornerTest
149 * @tc.type: FUNC
150 * @tc.require:
151 */
152 HWTEST_F(RSRoundCornerDisplayTest, RSDrawRoundCornerTest, TestSize.Level1)
153 {
154 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
155 auto res = rcdInstance.Init();
156 EXPECT_TRUE(res == true);
157
158 ScreenRotation curOrientation = ScreenRotation::ROTATION_0;
159 rcdInstance.UpdateOrientationStatus(curOrientation);
160
161 int notchStatus = WINDOW_NOTCH_DEFAULT;
162 rcdInstance.UpdateNotchStatus(notchStatus);
163 EXPECT_TRUE(rcdInstance.notchStatus_ == notchStatus);
164
165 uint32_t width = 1344;
166 uint32_t height = 2772;
167 rcdInstance.UpdateDisplayParameter(width, height);
168
169 std::unique_ptr<Drawing::Canvas> drawingCanvas = std::make_unique<Drawing::Canvas>(width, height);
170 std::shared_ptr<RSPaintFilterCanvas> canvas = std::make_shared<RSPaintFilterCanvas>(drawingCanvas.get());
171 ASSERT_NE(canvas, nullptr);
172 rcdInstance.DrawTopRoundCorner(canvas.get());
173 rcdInstance.DrawBottomRoundCorner(canvas.get());
174 }
175
176 /*
177 * @tc.name: RSLoadImgTest
178 * @tc.desc: Test RSRoundCornerDisplayTest.RSLoadImgTest
179 * @tc.type: FUNC
180 * @tc.require:
181 */
182 HWTEST_F(RSRoundCornerDisplayTest, RSLoadImgTest, TestSize.Level1)
183 {
184 std::shared_ptr<Drawing::Image> imgBottomPortrait;
185 Drawing::Bitmap bitmapBottomPortrait;
186 const char* path = "port_down.png";
187
188 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
189 auto res = rcdInstance.Init();
190
191 rcdInstance.LoadImg(path, imgBottomPortrait);
192 if (imgBottomPortrait == nullptr) {
193 std::cout << "RSRoundCornerDisplayTest: current os less rcd source" << std::endl;
194 EXPECT_TRUE(res == true);
195 return;
196 }
197 rcdInstance.DecodeBitmap(imgBottomPortrait, bitmapBottomPortrait);
198
199 std::shared_ptr<Drawing::Image> imgNoneImageLoaded = std::make_shared<Drawing::Image>();
200 res = rcdInstance.DecodeBitmap(imgNoneImageLoaded, bitmapBottomPortrait);
201 EXPECT_TRUE(res == false);
202 }
203
204 /*
205 * @tc.name: RSLoadImgTest001
206 * @tc.desc: Test RSRoundCornerDisplayTest.RSLoadImgTest001
207 * @tc.type: FUNC
208 * @tc.require:
209 */
210 HWTEST_F(RSRoundCornerDisplayTest, RSLoadImgTest001, TestSize.Level1)
211 {
212 std::shared_ptr<Drawing::Image> imgBottomPortrait;
213 Drawing::Bitmap bitmapBottomPortrait;
214 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
215 rcdInstance.Init();
216
217 // test waring path
218 const char* path1 = "test_waring_path.png";
219 bool flag1 = rcdInstance.LoadImg(path1, imgBottomPortrait);
220 EXPECT_TRUE(flag1 == false);
221
222 // test image is nullpr
223 bool flag2 = rcdInstance.DecodeBitmap(nullptr, bitmapBottomPortrait);
224 EXPECT_TRUE(flag2 == false);
225
226 // test correct path, but the file type is incorrect.
227 const char* path2 = "config.xml";
228 bool flag3 = rcdInstance.LoadImg(path2, imgBottomPortrait);
229 EXPECT_TRUE(flag3 == false);
230 }
231
232 /*
233 * @tc.name: RSGetSurfaceSourceTest
234 * @tc.desc: Test RSRoundCornerDisplayTest.RSGetSurfaceSourceTest
235 * @tc.type: FUNC
236 * @tc.require:
237 */
238 HWTEST_F(RSRoundCornerDisplayTest, RSGetSurfaceSourceTest, TestSize.Level1)
239 {
240 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
241 rcdInstance.InitOnce();
242 auto res = rcdInstance.Init();
243 rcdInstance.InitOnce();
244 EXPECT_TRUE(res == true);
245
246 uint32_t width = 1344;
247 uint32_t height = 2772;
248 rcdInstance.UpdateDisplayParameter(width, height);
249
250 rcdInstance.GetTopSurfaceSource();
251 rcdInstance.GetBottomSurfaceSource();
252 }
253
254 /*
255 * @tc.name: RSChooseResourceTest
256 * @tc.desc: Test RSRoundCornerDisplayTest.RSChooseResourceTest
257 * @tc.type: FUNC
258 * @tc.require:
259 */
260 HWTEST_F(RSRoundCornerDisplayTest, RSChooseResourceTest, TestSize.Level1)
261 {
262 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
263 rcdInstance.Init();
264
265 ScreenRotation curOrientation = ScreenRotation::ROTATION_90;
266 rcdInstance.UpdateOrientationStatus(curOrientation);
267
268 int notchStatus = WINDOW_NOTCH_HIDDEN;
269 rcdInstance.UpdateNotchStatus(notchStatus);
270 EXPECT_TRUE(rcdInstance.notchStatus_ == notchStatus);
271
272 uint32_t width = 1344;
273 uint32_t height = 2772;
274 rcdInstance.UpdateDisplayParameter(width, height);
275
276 rcdInstance.RcdChooseTopResourceType();
277
278 rcdInstance.RcdChooseRSResource();
279 rcdInstance.RcdChooseHardwareResource();
280 }
281
282 /*
283 * @tc.name: IsNotchNeedUpdate
284 * @tc.desc: Test RSRoundCornerDisplayTest.IsNotchNeedUpdate
285 * @tc.type: FUNC
286 * @tc.require:
287 */
288 HWTEST_F(RSRoundCornerDisplayTest, IsNotchNeedUpdate, TestSize.Level1)
289 {
290 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
291 rcdInstance.Init();
292 rcdInstance.IsNotchNeedUpdate(true);
293 bool ischange = rcdInstance.IsNotchNeedUpdate(false);
294 EXPECT_EQ(true, ischange);
295 }
296
297 /*
298 * @tc.name: RunHardwareTask
299 * @tc.desc: Test RSRoundCornerDisplayTest.RunHardwareTask
300 * @tc.type: FUNC
301 * @tc.require:
302 */
303 HWTEST_F(RSRoundCornerDisplayTest, RunHardwareTask, TestSize.Level1)
304 {
305 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
306 bool res = rcdInstance.Init();
307 rcdInstance.RunHardwareTask(
__anon1799e2660102() 308 []() {
309 std::cout << "do RSRoundCornerDisplayTest.RunHardwareTask1" << std::endl;
310 }
311 );
312 rcdInstance.RunHardwareTask(
__anon1799e2660202() 313 []() {
314 std::cout << "do RSRoundCornerDisplayTest.RunHardwareTask2" << std::endl;
315 }
316 );
317 EXPECT_EQ(true, res);
318 }
319
320 /*
321 * @tc.name: DrawRoundCorner
322 * @tc.desc: Test RSRoundCornerDisplayTest.DrawRoundCorner
323 * @tc.type: FUNC
324 * @tc.require:
325 */
326 HWTEST_F(RSRoundCornerDisplayTest, DrawRoundCorner, TestSize.Level1)
327 {
328 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
329 bool res = rcdInstance.Init();
330 rcdInstance.DrawTopRoundCorner(nullptr);
331 rcdInstance.DrawBottomRoundCorner(nullptr);
332
333 rcdInstance.DrawTopRoundCorner(nullptr);
334 rcdInstance.DrawBottomRoundCorner(nullptr);
335 EXPECT_EQ(true, res);
336 }
337
GetRogFromLcdModel(rs_rcd::LCDModel * lcdModel,int & width,int & height)338 rs_rcd::ROGSetting* GetRogFromLcdModel(rs_rcd::LCDModel* lcdModel, int& width, int& height)
339 {
340 if (lcdModel == nullptr) {
341 return nullptr;
342 }
343 int widthMate40 = 1344;
344 int heightMate40 = 2772;
345 int widthMate60 = 1260;
346 int heightMate60 = 2720;
347 width = widthMate40;
348 height = heightMate40;
349 rs_rcd::ROGSetting* rog = lcdModel->GetRog(width, height);
350 if (rog == nullptr) {
351 rog = lcdModel->GetRog(widthMate60, heightMate60);
352 width = widthMate60;
353 height = heightMate60;
354 }
355 return rog;
356 }
357
358 /*
359 * @tc.name: ProcessRcdSurfaceRenderNode1
360 * @tc.desc: Test ProcessRcdSurfaceRenderNode1
361 * @tc.type: FUNC
362 * @tc.require:
363 */
364 HWTEST_F(RSRoundCornerDisplayTest, ProcessRcdSurfaceRenderNode1, TestSize.Level1)
365 {
366 // prepare test
367 std::shared_ptr<Drawing::Image> imgBottomPortrait;
368 Drawing::Bitmap bitmapBottomPortrait;
369 const char* path = "port_down.png";
370
371 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
372 rcdInstance.Init();
373 rcdInstance.LoadImg(path, imgBottomPortrait);
374 if (imgBottomPortrait == nullptr) {
375 std::cout << "RSRoundCornerDisplayTest: current os less rcd source" << std::endl;
376 return;
377 }
378 rcdInstance.DecodeBitmap(imgBottomPortrait, bitmapBottomPortrait);
379
380 auto& rcdCfg = RSSingleton<rs_rcd::RCDConfig>::GetInstance();
381 rcdCfg.Load(std::string(rs_rcd::PATH_CONFIG_FILE));
382 rs_rcd::LCDModel* lcdModel = rcdCfg.GetLcdModel(std::string(rs_rcd::ATTR_DEFAULT));
383 if (lcdModel == nullptr) {
384 std::cout << "RSRoundCornerDisplayTest: current os less lcdModel source" << std::endl;
385 return;
386 }
387 int width = 0;
388 int height = 0;
389 rs_rcd::ROGSetting* rog = GetRogFromLcdModel(lcdModel, width, height);
390 if (rog == nullptr) {
391 std::cout << "RSRoundCornerDisplayTest: current os less rog source" << std::endl;
392 return;
393 }
394
395 rs_rcd::RoundCornerHardware hardInfo;
396 auto portrait = rog->GetPortrait(std::string(rs_rcd::NODE_PORTRAIT));
397 if (portrait == std::nullopt) {
398 std::cout << "RSRoundCornerDisplayTest: current os less bottomLayer source" << std::endl;
399 return;
400 }
401 hardInfo.bottomLayer = std::make_shared<rs_rcd::RoundCornerLayer>(portrait->layerDown);
402 hardInfo.bottomLayer->layerWidth = width;
403 hardInfo.bottomLayer->layerHeight = height;
404 hardInfo.bottomLayer->curBitmap = &bitmapBottomPortrait;
405
406 auto bottomSurfaceNode = RSRcdSurfaceRenderNode::Create(0, RCDSurfaceType::BOTTOM);
407 HardwareLayerInfo info{};
408 bottomSurfaceNode->FillHardwareResource(info, 0, 0);
409 auto visitor = std::make_shared<RSRcdRenderVisitor>();
410 // test
411 visitor->ProcessRcdSurfaceRenderNode(*bottomSurfaceNode, hardInfo.bottomLayer, true);
412 }
413
414 /*
415 * @tc.name: ConsumeAndUpdateBufferTest
416 * @tc.desc: Test RSRoundCornerDisplayTest.ConsumeAndUpdateBufferTest
417 * @tc.type: FUNC
418 * @tc.require:
419 */
420 HWTEST_F(RSRoundCornerDisplayTest, ConsumeAndUpdateBufferTest, TestSize.Level1)
421 {
422 std::shared_ptr<RSRcdSurfaceRenderNode> topSurfaceNode =
423 std::make_shared<RSRcdSurfaceRenderNode>(0, RCDSurfaceType::TOP);
424 std::shared_ptr<RSRcdSurfaceRenderNode> inValidSurfaceNode =
425 std::make_shared<RSRcdSurfaceRenderNode>(0, RCDSurfaceType::INVALID);
426 rs_rcd::RoundCornerHardware hardInfo{};
427 auto visitor = std::make_shared<RSRcdRenderVisitor>();
428
429 // 1 null processor
430 std::shared_ptr<RSProcessor> processorPtr = nullptr;
431 visitor->SetUniProcessor(processorPtr);
432 EXPECT_TRUE(visitor->uniProcessor_ == processorPtr);
433 visitor->ProcessRcdSurfaceRenderNode(*topSurfaceNode, hardInfo.bottomLayer, true);
434 visitor->ProcessRcdSurfaceRenderNodeMainThread(*topSurfaceNode, true);
435
436 // 2 invalid node
437 processorPtr =
438 RSProcessorFactory::CreateProcessor(RSDisplayRenderNode::CompositeType::HARDWARE_COMPOSITE);
439 visitor->SetUniProcessor(processorPtr);
440 visitor->ProcessRcdSurfaceRenderNode(*inValidSurfaceNode, hardInfo.bottomLayer, true);
441 visitor->ProcessRcdSurfaceRenderNodeMainThread(*inValidSurfaceNode, true);
442
443 // 3 resource not changed
444 visitor->ProcessRcdSurfaceRenderNode(*topSurfaceNode, hardInfo.bottomLayer, true);
445 visitor->ProcessRcdSurfaceRenderNodeMainThread(*topSurfaceNode, true);
446
447 // processor node changedTag Ok
448 visitor->ProcessRcdSurfaceRenderNode(*topSurfaceNode, hardInfo.bottomLayer, true);
449 visitor->ProcessRcdSurfaceRenderNodeMainThread(*topSurfaceNode, true);
450
451 ASSERT_EQ(true, visitor->ConsumeAndUpdateBuffer(*topSurfaceNode));
452 }
453
454 template<typename T1, typename T2, typename T3>
455 struct TestMsgBus {
456 T1 mA;
457 T2 mB;
458 T3 mC;
TestMsgBusOHOS::Rosen::TestMsgBus459 TestMsgBus(T1 a, T2 b, T3 c) : mA{a}, mB{b}, mC{c} {};
460
TestFunc1OHOS::Rosen::TestMsgBus461 void TestFunc1(T1 a)
462 {
463 std::cout << "TestMsg Bus Func1:" << sizeof(T1) << "," << &a << std::endl;
464 EXPECT_TRUE(mA == a);
465 }
466
TestFunc2OHOS::Rosen::TestMsgBus467 void TestFunc2(T1 a, T2 b)
468 {
469 std::cout << "TestMsg Bus Func2:" <<
470 sizeof(T1) << "," << &a << std::endl <<
471 sizeof(T2) << "," << &b << std::endl;
472 EXPECT_TRUE(mA == a);
473 EXPECT_TRUE(mB == b);
474 }
475
TestFunc3OHOS::Rosen::TestMsgBus476 void TestFunc3(T1 a, T2 b, T3 c)
477 {
478 std::cout << "TestMsg Bus Func3:" <<
479 sizeof(T1) << "," << &a << std::endl <<
480 sizeof(T2) << "," << &b << std::endl <<
481 sizeof(T3) << "," << &c << std::endl;
482 EXPECT_TRUE(mA == a);
483 EXPECT_TRUE(mB == b);
484 EXPECT_TRUE(mC == c);
485 }
486 };
487
488 template<typename T1, typename T2, typename T3>
TestMsgBusFunc()489 void TestMsgBusFunc()
490 {
491 std::string topic = "TEST_TOPIC";
492 auto& msgBus = RSSingleton<RsMessageBus>::GetInstance();
493 using TestMsgBusClass = TestMsgBus<T1, T2, T3>;
494 TestMsgBusClass* objPtr = nullptr;
495 int num1 = 1;
496 int num2 = 2;
497 int num3 = 3;
498 TestMsgBusClass obj(static_cast<T1>(num1), static_cast<T2>(num2), static_cast<T3>(num3));
499 msgBus.RegisterTopic<T1>(topic, objPtr, &TestMsgBusClass::TestFunc1);
500 msgBus.RegisterTopic<T1>(topic, &obj, &TestMsgBusClass::TestFunc1);
501 EXPECT_TRUE(msgBus.m_map.size() == 1);
502 msgBus.SendMsg(topic, static_cast<T1>(num1));
503 msgBus.RemoveTopic<T1>(topic);
504 EXPECT_TRUE(msgBus.m_map.size() == 0);
505 msgBus.RegisterTopic<T1, T2>(topic, &obj, &TestMsgBusClass::TestFunc2);
506 EXPECT_TRUE(msgBus.m_map.size() == 1);
507 msgBus.SendMsg(topic, static_cast<T1>(num1), static_cast<T2>(num2));
508 msgBus.RemoveTopic<T1, T2>(topic);
509 EXPECT_TRUE(msgBus.m_map.size() == 0);
510 msgBus.RegisterTopic<T1, T2, T3>(topic, &obj, &TestMsgBusClass::TestFunc3);
511 EXPECT_TRUE(msgBus.m_map.size() == 1);
512 msgBus.SendMsg(topic, static_cast<T1>(num1), static_cast<T2>(num2), static_cast<T3>(num3));
513 msgBus.RemoveTopic<T1, T2, T3>(topic);
514 EXPECT_TRUE(msgBus.m_map.size() == 0);
515 }
516
517 template<typename T1, typename T2>
TestMsgBusFunc3()518 void TestMsgBusFunc3()
519 {
520 TestMsgBusFunc<T1, T2, uint8_t>();
521 TestMsgBusFunc<T1, T2, uint16_t>();
522 TestMsgBusFunc<T1, T2, uint32_t>();
523 TestMsgBusFunc<T1, T2, uint64_t>();
524 TestMsgBusFunc<T1, T2, int>();
525 TestMsgBusFunc<T1, T2, float>();
526 TestMsgBusFunc<T1, T2, double>();
527 }
528
529 template<typename T1>
TestMsgBusFunc2()530 void TestMsgBusFunc2()
531 {
532 TestMsgBusFunc3<T1, uint8_t>();
533 TestMsgBusFunc3<T1, uint16_t>();
534 TestMsgBusFunc3<T1, uint32_t>();
535 TestMsgBusFunc3<T1, uint64_t>();
536 TestMsgBusFunc3<T1, int>();
537 TestMsgBusFunc3<T1, float>();
538 TestMsgBusFunc3<T1, double>();
539 }
540
541 /*
542 * @tc.name: MessageBus
543 * @tc.desc: Test RSRoundCornerDisplayTest.MessageBus
544 * @tc.type: FUNC
545 * @tc.require:
546 */
547 HWTEST_F(RSRoundCornerDisplayTest, MessageBus, TestSize.Level1)
548 {
549 auto& msgBus = RSSingleton<RsMessageBus>::GetInstance();
550 ASSERT_TRUE(msgBus.m_map.empty());
551 msgBus.RemoveTopic("NG_TOPIC");
552 TestMsgBusFunc2<uint8_t>();
553 TestMsgBusFunc2<uint16_t>();
554 TestMsgBusFunc2<uint32_t>();
555 TestMsgBusFunc2<uint64_t>();
556 TestMsgBusFunc2<int>();
557 TestMsgBusFunc2<float>();
558 TestMsgBusFunc2<double>();
559 EXPECT_TRUE(msgBus.m_map.size() == 0);
560 }
561
562 /*
563 * @tc.name: RCDConfig
564 * @tc.desc: Test RSRoundCornerDisplayTest.RCDConfig
565 * @tc.type: FUNC
566 * @tc.require:
567 */
568 HWTEST_F(RSRoundCornerDisplayTest, RCDConfig, TestSize.Level1)
569 {
570 auto& rcdCfg = RSSingleton<rs_rcd::RCDConfig>::GetInstance();
571 rcdCfg.Load(std::string("NG_PATH_CONFIG_FILE"));
572 rcdCfg.Load(std::string(rs_rcd::PATH_CONFIG_FILE));
573 auto invalidLcd = rcdCfg.GetLcdModel(std::string("invalideName"));
574 EXPECT_EQ(invalidLcd, nullptr);
575 rs_rcd::RCDConfig::PrintParseRog(nullptr);
576 rs_rcd::ROGSetting rog;
577 rs_rcd::RogPortrait rp;
578 rs_rcd::RogLandscape rl;
579 rog.portraitMap["a"] = rp;
580 rog.landscapeMap["b"] = rl;
581 rs_rcd::RCDConfig::PrintParseRog(&rog);
582 }
583
584 /*
585 * @tc.name: LCDModel
586 * @tc.desc: Test RSRoundCornerDisplayTest.LCDModel
587 * @tc.type: FUNC
588 * @tc.require:
589 */
590 HWTEST_F(RSRoundCornerDisplayTest, LCDModel, TestSize.Level1)
591 {
592 auto& rcdCfg = RSSingleton<rs_rcd::RCDConfig>::GetInstance();
593 rcdCfg.Load(std::string(rs_rcd::PATH_CONFIG_FILE));
594 auto defaultLcd = rcdCfg.GetLcdModel(std::string(rs_rcd::ATTR_DEFAULT));
595 if (defaultLcd == nullptr) {
596 std::cout << "OS less lcdModel resource" << std::endl;
597 return;
598 }
599 defaultLcd->GetRog(0, 0);
600 defaultLcd->GetHardwareComposerConfig();
601 defaultLcd->GetSideRegionConfig();
602 defaultLcd->GetSurfaceConfig();
603
604 xmlNodePtr xmlptr = nullptr;
605 auto res = defaultLcd->ReadXmlNode(xmlptr);
606 EXPECT_EQ(res, false);
607 }
608
609 /*
610 * @tc.name: HardwareComposerConfig
611 * @tc.desc: Test RSRoundCornerDisplayTest.HardwareComposerConfig
612 * @tc.type: FUNC
613 * @tc.require:
614 */
615 HWTEST_F(RSRoundCornerDisplayTest, HardwareComposerConfig, TestSize.Level1)
616 {
617 rs_rcd::HardwareComposerConfig cfg;
618 xmlNodePtr xmlptr = nullptr;
619 bool res = cfg.ReadXmlNode(xmlptr);
620 EXPECT_EQ(res, false);
621 xmlptr = xmlNewNode(NULL, BAD_CAST(rs_rcd::NODE_HARDWARECOMPOSERCONFIG));
622 auto child = xmlNewNode(NULL, BAD_CAST(rs_rcd::NODE_HARDWARECOMPOSER));
623 xmlNewProp(child, BAD_CAST(rs_rcd::ATTR_SUPPORT), BAD_CAST("true"));
624 xmlAddChild(xmlptr, child);
625 res = cfg.ReadXmlNode(xmlptr);
626 EXPECT_EQ(res, true);
627
628 if (xmlptr != nullptr) {
629 xmlFreeNode(xmlptr);
630 xmlptr = nullptr;
631 }
632 auto ngPtr = CreateNodeWithProperty(std::string("node"), XMLProperty{std::string("a1"), std::string("")});
633 rs_rcd::SupportConfig sc = {true, 1};
634 EXPECT_EQ(sc.ReadXmlNode(ngPtr, std::string("aa"), std::string("mm")), false);
635 if (ngPtr != nullptr) {
636 xmlFreeNode(ngPtr);
637 ngPtr = nullptr;
638 }
639 }
640
641 /*
642 * @tc.name: HardwareComposer
643 * @tc.desc: Test RSRoundCornerDisplayTest.HardwareComposer
644 * @tc.type: FUNC
645 * @tc.require:
646 */
647 HWTEST_F(RSRoundCornerDisplayTest, HardwareComposer, TestSize.Level1)
648 {
649 rs_rcd::HardwareComposer cfg;
650 xmlNodePtr xmlptr = nullptr;
651 bool res = cfg.ReadXmlNode(xmlptr, "ngAttr");
652 EXPECT_EQ(res, false);
653 }
654
655 /*
656 * @tc.name: SideRegionConfig
657 * @tc.desc: Test RSRoundCornerDisplayTest.SideRegionConfig
658 * @tc.type: FUNC
659 * @tc.require:
660 */
661 HWTEST_F(RSRoundCornerDisplayTest, SideRegionConfig, TestSize.Level1)
662 {
663 rs_rcd::SideRegionConfig cfg;
664 xmlNodePtr xmlptr = nullptr;
665 bool res = cfg.ReadXmlNode(xmlptr);
666 EXPECT_EQ(res, false);
667 }
668
669 /*
670 * @tc.name: SurfaceConfig
671 * @tc.desc: Test RSRoundCornerDisplayTest.SurfaceConfig
672 * @tc.type: FUNC
673 * @tc.require:
674 */
675 HWTEST_F(RSRoundCornerDisplayTest, SurfaceConfig, TestSize.Level1)
676 {
677 rs_rcd::SurfaceConfig cfg;
678 xmlNodePtr xmlptr = nullptr;
679 bool res = cfg.ReadXmlNode(xmlptr);
680 EXPECT_EQ(res, false);
681 }
682
683 /*
684 * @tc.name: ROGSetting
685 * @tc.desc: Test RSRoundCornerDisplayTest.ROGSetting
686 * @tc.type: FUNC
687 * @tc.require:
688 */
689 HWTEST_F(RSRoundCornerDisplayTest, ROGSetting, TestSize.Level1)
690 {
691 rs_rcd::ROGSetting cfg;
692 xmlNodePtr xmlptr = nullptr;
693 bool res = cfg.ReadXmlNode(xmlptr);
694 EXPECT_EQ(res, false);
695 }
696
697 /*
698 * @tc.name: RogLandscape
699 * @tc.desc: Test RSRoundCornerDisplayTest.RogLandscape
700 * @tc.type: FUNC
701 * @tc.require:
702 */
703 HWTEST_F(RSRoundCornerDisplayTest, RogLandscape, TestSize.Level1)
704 {
705 rs_rcd::RogLandscape cfg;
706 xmlNodePtr xmlptr = nullptr;
707 bool res = cfg.ReadXmlNode(xmlptr);
708 EXPECT_EQ(res, false);
709 }
710
711 /*
712 * @tc.name: RogPortrait
713 * @tc.desc: Test RSRoundCornerDisplayTest.RogPortrait
714 * @tc.type: FUNC
715 * @tc.require:
716 */
717 HWTEST_F(RSRoundCornerDisplayTest, RogPortrait, TestSize.Level1)
718 {
719 rs_rcd::RogPortrait cfg;
720 xmlNodePtr xmlptr = nullptr;
721 bool res = cfg.ReadXmlNode(xmlptr);
722 EXPECT_EQ(res, false);
723 }
724
725 /*
726 * @tc.name: RoundCornerLayer
727 * @tc.desc: Test RSRoundCornerDisplayTest.RoundCornerLayer
728 * @tc.type: FUNC
729 * @tc.require:
730 */
731 HWTEST_F(RSRoundCornerDisplayTest, RoundCornerLayer, TestSize.Level1)
732 {
733 rs_rcd::RoundCornerLayer cfg;
734 xmlNodePtr xmlptr = nullptr;
735 cfg.ReadXmlNode(xmlptr, {"a", "b"});
736
737 std::vector<std::string> properties = {
738 rs_rcd::ATTR_FILENAME,
739 rs_rcd::ATTR_OFFSET_X,
740 rs_rcd::ATTR_OFFSET_Y,
741 rs_rcd::ATTR_BINFILENAME,
742 rs_rcd::ATTR_BUFFERSIZE,
743 rs_rcd::ATTR_CLDWIDTH,
744 rs_rcd::ATTR_CLDHEIGHT
745 };
746
747 rs_rcd::RoundCornerLayer cfgData = {
748 "test", // fileName
749 1, // offsetX
750 1, // offsetY
751 "test.bin", // binFileName
752 10000, // bufferSize
753 2, // cldWidth
754 2, // cldHeight
755 0,
756 0,
757 nullptr
758 };
759 auto nodePtr = CreateRCDLayer(std::string("layer"), cfgData);
760 cfg.ReadXmlNode(nodePtr, properties);
761
762 EXPECT_EQ(cfg.fileName.compare(cfgData.fileName), int{0});
763 EXPECT_EQ(cfg.binFileName.compare(cfgData.binFileName), int{0});
764 EXPECT_EQ(cfg.bufferSize, cfgData.bufferSize);
765 EXPECT_EQ(cfg.offsetX, cfgData.offsetX);
766 EXPECT_EQ(cfg.offsetY, cfgData.offsetY);
767 EXPECT_EQ(cfg.cldWidth, cfgData.cldWidth);
768 EXPECT_EQ(cfg.cldHeight, cfgData.cldHeight);
769 xmlFreeNode(nodePtr);
770 nodePtr = nullptr;
771 }
772
773 /*
774 * @tc.name: XMLReader
775 * @tc.desc: Test RSRoundCornerDisplayTest.XMLReader
776 * @tc.type: FUNC
777 * @tc.require:
778 */
779 HWTEST_F(RSRoundCornerDisplayTest, XMLReader, TestSize.Level1)
780 {
781 xmlNodePtr nodePtr = nullptr;
782 rs_rcd::XMLReader::ReadAttrStr(nodePtr, std::string("a"));
783 rs_rcd::XMLReader::ReadAttrInt(nodePtr, std::string("a"));
784 rs_rcd::XMLReader::ReadAttrFloat(nodePtr, std::string("a"));
785 rs_rcd::XMLReader::ReadAttrBool(nodePtr, std::string("a"));
786
787 auto attrName = std::string("num");
788 auto numPtr = CreateNodeWithProperty(std::string("nodeName"), XMLProperty{attrName, std::string("")});
789 EXPECT_TRUE(rs_rcd::XMLReader::ReadAttrInt(numPtr, attrName) == int{0});
790 EXPECT_TRUE(rs_rcd::XMLReader::ReadAttrFloat(numPtr, attrName) < 1.0f);
791 xmlFreeNode(numPtr);
792 numPtr = CreateNodeWithProperty(std::string("nodeName"), XMLProperty{attrName, std::string("2.0")});
793 EXPECT_TRUE(rs_rcd::XMLReader::ReadAttrInt(numPtr, attrName) == int{2});
794 EXPECT_TRUE(rs_rcd::XMLReader::ReadAttrFloat(numPtr, attrName) > 1.0f);
795 xmlFreeNode(numPtr);
796 std::vector<std::string> okCase = { "0.0", "0", "123", "1230.0", "8192.0 ", "819200"};
797 for (auto& tmpCase : okCase) {
798 bool isOk = rs_rcd::XMLReader::RegexMatchNum(tmpCase);
799 EXPECT_EQ(isOk, true);
800 }
801
802 std::vector<std::string> ngCase = {"a0.0", "0a", "a123", "1230.0c", "a8192.0 "};
803 for (auto& tmpCase : ngCase) {
804 bool isOk = rs_rcd::XMLReader::RegexMatchNum(tmpCase);
805 EXPECT_EQ(isOk, false);
806 }
807 }
808
809 /*
810 * @tc.name: RcdExtInfo
811 * @tc.desc: Test RSRoundCornerDisplayTest.RcdExtInfo
812 * @tc.type: FUNC
813 * @tc.require:
814 */
815 HWTEST_F(RSRoundCornerDisplayTest, RcdExtInfo, TestSize.Level1)
816 {
817 RcdExtInfo info;
818 info.Clear();
819 bool res = info.GetFrameOffsetX() > -1;
820 EXPECT_EQ(res, true);
821 res = info.GetFrameOffsetY() > -1;
822 EXPECT_EQ(res, true);
823 }
824
825 /*
826 * @tc.name: RSRcdSurfaceRenderNode
827 * @tc.desc: Test RSRoundCornerDisplayTest.RSRcdSurfaceRenderNode
828 * @tc.type: FUNC
829 * @tc.require:
830 */
831 HWTEST_F(RSRoundCornerDisplayTest, RSRcdSurfaceRenderNode, TestSize.Level1)
832 {
833 for (int i = 0; i < 2; i++)
834 {
835 RSRcdSurfaceRenderNode rcdRenderNode(0, static_cast<RCDSurfaceType>(i));
836 rcdRenderNode.ClearBufferCache();
837 rcdRenderNode.ResetCurrFrameState();
838 rcdRenderNode.Reset();
839
840 rcdRenderNode.GetSrcRect();
841 rcdRenderNode.GetDstRect();
842 rcdRenderNode.IsSurfaceCreated();
843 rcdRenderNode.IsBottomSurface();
844 rcdRenderNode.IsTopSurface();
845 rcdRenderNode.IsInvalidSurface();
846 rcdRenderNode.GetFrameOffsetX();
847 rcdRenderNode.GetFrameOffsetY();
848 rcdRenderNode.GetRSSurface();
849 rcdRenderNode.GetHardenBufferRequestConfig();
850 auto comsumer = rcdRenderNode.GetConsumerListener();
851 rcdRenderNode.CreateSurface(comsumer);
852 rcdRenderNode.SetRcdBufferSize(0);
853 rcdRenderNode.SetRcdBufferHeight(0);
854 rcdRenderNode.SetRcdBufferWidth(0);
855 rcdRenderNode.SetHardwareResourceToBuffer();
856 rcdRenderNode.PrepareHardwareResourceBuffer(nullptr);
857 rs_rcd::RoundCornerLayer layer;
858 rcdRenderNode.PrepareHardwareResourceBuffer(std::make_shared<rs_rcd::RoundCornerLayer>(layer));
859 uint32_t size = 10;
860 rcdRenderNode.SetRcdBufferSize(size);
861 auto bufferSize = rcdRenderNode.GetRcdBufferSize();
862 EXPECT_EQ(bufferSize, size);
863
864 uint32_t height = 20;
865 rcdRenderNode.SetRcdBufferHeight(height);
866 auto bufferHeight = rcdRenderNode.GetRcdBufferHeight();
867 EXPECT_EQ(bufferHeight, height);
868
869 uint32_t width = 100;
870 rcdRenderNode.SetRcdBufferWidth(width);
871 auto bufferWidth = rcdRenderNode.GetRcdBufferWidth();
872 EXPECT_EQ(bufferWidth, width);
873 rcdRenderNode.GetHardenBufferRequestConfig();
874 rcdRenderNode.SetHardwareResourceToBuffer();
875 rcdRenderNode.PrepareHardwareResourceBuffer(nullptr);
876 rcdRenderNode.PrepareHardwareResourceBuffer(std::make_shared<rs_rcd::RoundCornerLayer>(layer));
877 width = 0;
878 rcdRenderNode.SetRcdBufferWidth(width);
879 rcdRenderNode.GetHardenBufferRequestConfig();
880 EXPECT_EQ(rcdRenderNode.GetRcdBufferWidth(), width);
881 rcdRenderNode.ClearBufferCache();
882 }
883 }
884
885 /*
886 * @tc.name: RcdChooseHardwareResourceTest
887 * @tc.desc: Test RSRoundCornerDisplay.RcdChooseHardwareResource
888 * @tc.type: FUNC
889 * @tc.require:
890 */
891 HWTEST_F(RSRoundCornerDisplayTest, RcdChooseHardwareResourceTest, TestSize.Level1)
892 {
893 GTEST_LOG_(INFO) << "RSSymbolAnimationTest RcdChooseHardwareResourceTest start";
894 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
895 rs_rcd::ROGSetting rog;
896 rog.height = 2772;
897 rog.width = 1344;
898 rcdInstance.rog_ = &rog;
899
900 rcdInstance.showResourceType_ = TOP_PORTRAIT;
901 rcdInstance.RcdChooseHardwareResource();
902
903 rcdInstance.showResourceType_ = TOP_HIDDEN;
904 rcdInstance.RcdChooseHardwareResource();
905
906 rcdInstance.showResourceType_ = TOP_LADS_ORIT;
907 rcdInstance.RcdChooseHardwareResource();
908
909 rcdInstance.showResourceType_ = 4;
910 rcdInstance.RcdChooseHardwareResource();
911 int type = 4;
912 EXPECT_EQ(rcdInstance.showResourceType_, type);
913 GTEST_LOG_(INFO) << "RSSymbolAnimationTest RcdChooseHardwareResourceTest end";
914 }
915
916 /*
917 * @tc.name: UpdateNotchStatusTest
918 * @tc.desc: Test RSRoundCornerDisplay.UpdateNotchStatus
919 * @tc.type: FUNC
920 * @tc.require:
921 */
922 HWTEST_F(RSRoundCornerDisplayTest, UpdateNotchStatusTest, TestSize.Level1)
923 {
924 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
925 rcdInstance.Init();
926 rcdInstance.UpdateNotchStatus(WINDOW_NOTCH_DEFAULT);
927 // test status is < 0
928 int notchStatus = -1;
929 rcdInstance.UpdateNotchStatus(notchStatus);
930 EXPECT_TRUE(rcdInstance.notchStatus_ == WINDOW_NOTCH_DEFAULT);
931
932 // test status is > 1
933 int notchStatusTwo = 2;
934 rcdInstance.UpdateNotchStatus(notchStatusTwo);
935 EXPECT_TRUE(rcdInstance.notchStatus_ == WINDOW_NOTCH_DEFAULT);
936 }
937
938 /*
939 * @tc.name: RcdChooseTopResourceTypeTest
940 * @tc.desc: Test RSRoundCornerDisplay.RcdChooseTopResourceType
941 * @tc.type: FUNC
942 * @tc.require:
943 */
944 HWTEST_F(RSRoundCornerDisplayTest, RcdChooseTopResourceTypeTest, TestSize.Level1)
945 {
946 auto& rcdInstance = RSSingleton<RoundCornerDisplay>::GetInstance();
947 rcdInstance.Init();
948 // test curOrientation is INVALID_SCREEN_ROTATION
949 ScreenRotation curOrientation = ScreenRotation::INVALID_SCREEN_ROTATION;
950 rcdInstance.UpdateOrientationStatus(curOrientation);
951 rcdInstance.RcdChooseTopResourceType();
952 EXPECT_TRUE(rcdInstance.curOrientation_ == ScreenRotation::INVALID_SCREEN_ROTATION);
953 EXPECT_TRUE(rcdInstance.showResourceType_ == TOP_PORTRAIT);
954
955 // test ScreenRotation::ROTATION_180, notchStatus is WINDOW_NOTCH_DEFAULT
956 curOrientation = ScreenRotation::ROTATION_180;
957 int notchStatus = WINDOW_NOTCH_DEFAULT;
958 rcdInstance.UpdateNotchStatus(notchStatus);
959 rcdInstance.UpdateOrientationStatus(curOrientation);
960 rcdInstance.RcdChooseTopResourceType();
961 EXPECT_TRUE(rcdInstance.curOrientation_ == ScreenRotation::ROTATION_180);
962 EXPECT_TRUE(rcdInstance.showResourceType_ == TOP_PORTRAIT);
963
964 // test ScreenRotation::ROTATION_270, notchStatus is WINDOW_NOTCH_DEFAULT
965 curOrientation = ScreenRotation::ROTATION_180;
966 rcdInstance.UpdateOrientationStatus(curOrientation);
967 rcdInstance.RcdChooseTopResourceType();
968 EXPECT_TRUE(rcdInstance.curOrientation_ == ScreenRotation::ROTATION_180);
969 EXPECT_TRUE(rcdInstance.showResourceType_ == TOP_PORTRAIT);
970 }
971
972 /*
973 * @tc.name: ProcessFillHardwareResource
974 * @tc.desc: Test RSRcdSurfaceRenderNode.FillHardwareResource
975 * @tc.type: FUNC
976 * @tc.require:
977 */
978 HWTEST_F(RSRoundCornerDisplayTest, ProcessFillHardwareResource, TestSize.Level1)
979 {
980 // prepare test
981 std::shared_ptr<RSRcdSurfaceRenderNode> bottomSurfaceNode =
982 std::make_shared<RSRcdSurfaceRenderNode>(0, RCDSurfaceType::BOTTOM);
983 if (bottomSurfaceNode == nullptr) {
984 std::cout << "RSRoundCornerDisplayTest: current os less bottomSurfaceNode source" << std::endl;
985 return;
986 }
987
988 HardwareLayerInfo info{};
989 sptr<SurfaceBufferImpl> surfaceBufferImpl = new SurfaceBufferImpl();
990 bottomSurfaceNode->buffer_.buffer = nullptr;
991 bool flag1 = bottomSurfaceNode->FillHardwareResource(info, 2, 2);
992 bottomSurfaceNode->buffer_.buffer = surfaceBufferImpl;
993 EXPECT_TRUE(flag1 == false);
994
995 BufferHandle* bufferHandle = AllocateBufferHandle(64, 128);
996 EXPECT_TRUE(bufferHandle != nullptr);
997 surfaceBufferImpl->SetBufferHandle(bufferHandle);
998 surfaceBufferImpl->handle_->stride = 1;
999 surfaceBufferImpl->handle_->size = 64 + 128 + sizeof(BufferHandle);
1000
1001 bool flag2 = true;
1002 info.bufferSize = -1;
1003 flag2 = flag2 && !bottomSurfaceNode->FillHardwareResource(info, 2, 2);
1004 info.bufferSize = 10000;
1005 info.cldWidth = -1;
1006 flag2 = flag2 && !bottomSurfaceNode->FillHardwareResource(info, 2, 2);
1007 info.cldWidth = 2;
1008 info.cldHeight = -1;
1009 flag2 = flag2 && !bottomSurfaceNode->FillHardwareResource(info, 2, 2);
1010 info.cldHeight = 2;
1011 flag2 = flag2 && !bottomSurfaceNode->FillHardwareResource(info, -1, 2);
1012 flag2 = flag2 && !bottomSurfaceNode->FillHardwareResource(info, 2, -1);
1013 info.pathBin = "";
1014 EXPECT_TRUE(flag2);
1015
1016 bool flag3 = true;
1017 flag3 = flag3 && !bottomSurfaceNode->FillHardwareResource(info, 2, 2);
1018 std::shared_ptr<uint8_t> buffer = std::make_shared<uint8_t>(10000);
1019 surfaceBufferImpl->handle_->virAddr = static_cast<void*>(buffer.get());
1020 surfaceBufferImpl->handle_->stride = -1;
1021 flag3 = flag3 && !bottomSurfaceNode->FillHardwareResource(info, 2, 2);
1022 surfaceBufferImpl->handle_->stride = 1;
1023 surfaceBufferImpl->handle_->size = 0;
1024 flag3 = flag3 && !bottomSurfaceNode->FillHardwareResource(info, 2, 2);
1025 EXPECT_TRUE(flag3);
1026
1027 surfaceBufferImpl->handle_= nullptr;
1028 FreeBufferHandle(bufferHandle);
1029 }
1030
1031 /*
1032 * @tc.name: RoundCornerDisplayManager
1033 * @tc.desc: Test RoundCornerDisplayManager.AddRoundCornerDisplay
1034 * @tc.type: FUNC
1035 * @tc.require:
1036 */
1037 HWTEST_F(RSRoundCornerDisplayTest, RoundCornerDisplayManager_AddRcd, TestSize.Level1)
1038 {
1039 auto& rcdInstance = RSSingleton<RoundCornerDisplayManager>::GetInstance();
1040 // 1.add and remove rcd module via nodeId
1041 auto res = rcdInstance.CheckExist(1);
1042 EXPECT_TRUE(res == false);
1043 rcdInstance.AddRoundCornerDisplay(1);
1044 rcdInstance.AddRoundCornerDisplay(1);
1045 res = rcdInstance.CheckExist(1);
1046 EXPECT_TRUE(res);
1047 rcdInstance.RemoveRoundCornerDisplay(0);
1048 res = rcdInstance.CheckExist(1);
1049 EXPECT_TRUE(res);
1050 rcdInstance.RemoveRoundCornerDisplay(1);
1051 res = rcdInstance.CheckExist(1);
1052 EXPECT_TRUE(res == false);
1053 rcdInstance.RemoveRCDResource(1);
1054 res = rcdInstance.CheckExist(1);
1055 EXPECT_TRUE(res == false);
1056 }
1057
1058 /*
1059 * @tc.name: RoundCornerDisplayManager
1060 * @tc.desc: Test RoundCornerDisplayManager.AddLayer
1061 * @tc.type: FUNC
1062 * @tc.require:
1063 */
1064 HWTEST_F(RSRoundCornerDisplayTest, RoundCornerDisplayManager_AddLayer, TestSize.Level1)
1065 {
1066 auto& rcdInstance = RSSingleton<RoundCornerDisplayManager>::GetInstance();
1067 // 1.add layerInfo via renderTarget nodeId
1068 NodeId id = 1;
1069 auto top = RoundCornerDisplayManager::RCDLayerType::TOP;
1070
1071 auto topName = std::string("TopLayer");
1072
1073 rcdInstance.AddLayer(topName, id, top);
1074 auto LayerInfo = rcdInstance.GetLayerPair(topName);
1075 EXPECT_TRUE(LayerInfo.first == id && LayerInfo.second == top);
1076 rcdInstance.RemoveRCDLayerInfo(id);
1077 rcdInstance.RemoveRCDResource(id);
1078 LayerInfo = rcdInstance.GetLayerPair(topName);
1079 EXPECT_TRUE(LayerInfo.second == RoundCornerDisplayManager::RCDLayerType::INVALID);
1080 }
1081
1082 /*
1083 * @tc.name: RoundCornerDisplayManager
1084 * @tc.desc: Test RoundCornerDisplayManager null rcd Case
1085 * @tc.type: FUNC
1086 * @tc.require:
1087 */
1088 HWTEST_F(RSRoundCornerDisplayTest, RoundCornerDisplayManagerNULLRcd, TestSize.Level1)
1089 {
1090 auto& rcdInstance = RSSingleton<RoundCornerDisplayManager>::GetInstance();
1091 // add layer and NodeId
1092 NodeId id = 1;
1093 int status = 1;
1094 uint32_t w = 1080, h = 1920;
1095 auto rot = ScreenRotation::ROTATION_90;
1096 rcdInstance.AddRoundCornerDisplay(id);
1097 auto res = rcdInstance.CheckExist(id);
1098 EXPECT_TRUE(res == true);
1099 rcdInstance.rcdMap_[id] = nullptr;
1100 rcdInstance.UpdateDisplayParameter(id, w, h);
1101 res = rcdInstance.CheckExist(id);
1102 EXPECT_TRUE(res == false);
1103 rcdInstance.rcdMap_[id] = nullptr;
1104 rcdInstance.UpdateNotchStatus(id, status);
1105 res = rcdInstance.CheckExist(id);
1106 EXPECT_TRUE(res == false);
1107 rcdInstance.rcdMap_[id] = nullptr;
1108 rcdInstance.UpdateOrientationStatus(id, rot);
1109 res = rcdInstance.CheckExist(id);
1110 EXPECT_TRUE(res == false);
1111 }
1112
1113 /*
1114 * @tc.name: RoundCornerDisplayManager
1115 * @tc.desc: Test RoundCornerDisplayManagerUpdate
1116 * @tc.type: FUNC
1117 * @tc.require:
1118 */
1119 HWTEST_F(RSRoundCornerDisplayTest, RoundCornerDisplayManagerUpdate, TestSize.Level1)
1120 {
1121 auto& rcdInstance = RSSingleton<RoundCornerDisplayManager>::GetInstance();
1122 // add layer and NodeId
1123 NodeId id = 1;
1124 int status = 1;
1125 uint32_t w = 1080, h = 1920;
1126 auto rot = ScreenRotation::ROTATION_90;
__anon1799e2660302() 1127 std::function<void()> task = []() {std::cout << "hardwareComposer RoundCornerDisplayManager Task" << std::endl;};
1128 // normal flow
1129 rcdInstance.AddRoundCornerDisplay(id);
1130 rcdInstance.UpdateDisplayParameter(id, w, h);
1131 rcdInstance.UpdateNotchStatus(id, status);
1132 rcdInstance.UpdateOrientationStatus(id, rot);
1133 auto hardInfo = rcdInstance.GetHardwareInfo(id);
1134 rcdInstance.RunHardwareTask(id, task);
1135 auto res = rcdInstance.CheckExist(id);
1136 EXPECT_TRUE(res == true);
1137 // no id flow
1138 rcdInstance.RemoveRoundCornerDisplay(id);
1139 rcdInstance.UpdateDisplayParameter(id, w, h);
1140 rcdInstance.UpdateNotchStatus(id, status);
1141 rcdInstance.UpdateOrientationStatus(id, rot);
1142 hardInfo = rcdInstance.GetHardwareInfo(id);
1143 rcdInstance.RunHardwareTask(id, task);
1144 res = rcdInstance.CheckExist(id);
1145 EXPECT_TRUE(res == false);
1146 }
1147
1148 /*
1149 * @tc.name: RoundCornerDisplayManager
1150 * @tc.desc: Test RoundCornerDisplayManagerDraw
1151 * @tc.type: FUNC
1152 * @tc.require:
1153 */
1154 HWTEST_F(RSRoundCornerDisplayTest, RoundCornerDisplayManagerDraw, TestSize.Level1)
1155 {
1156 auto& rcdInstance = RSSingleton<RoundCornerDisplayManager>::GetInstance();
1157 // add layer and NodeId
1158 NodeId id = 1;
1159 auto top = RoundCornerDisplayManager::RCDLayerType::TOP;
1160 auto bottom = RoundCornerDisplayManager::RCDLayerType::BOTTOM;
1161 auto topName = std::string("TopLayer");
1162 auto bottomName = std::string("BottomLayer");
1163 rcdInstance.AddRoundCornerDisplay(id);
1164 rcdInstance.AddLayer(topName, id, top);
1165 rcdInstance.AddLayer(bottomName, id, bottom);
1166 EXPECT_TRUE(rcdInstance.CheckLayerIsRCD(std::string("InvalidName")) == false);
1167 EXPECT_TRUE(rcdInstance.CheckLayerIsRCD(topName) == true);
1168 std::vector<std::string> renderLayersName = {topName, bottomName, std::string("InvalidName")};
1169 std::vector<std::pair<NodeId, RoundCornerDisplayManager::RCDLayerType>> renderTargetNodeInfoList;
1170 for (auto& layerName : renderLayersName) {
1171 auto nodeInfo = rcdInstance.GetLayerPair(layerName);
1172 renderTargetNodeInfoList.push_back(nodeInfo);
1173 }
1174 auto baseCanvas = std::make_shared<Drawing::Canvas>();
1175 auto canvas = std::make_shared<RSPaintFilterCanvas>(baseCanvas.get(), 1.0f);
__anon1799e2660402() 1176 std::function<void()> task = []() {std::cout << "hardwareComposer RoundCornerDisplayManager Task" << std::endl;};
1177 rcdInstance.DrawRoundCorner(renderTargetNodeInfoList, canvas.get());
1178 EXPECT_TRUE(rcdInstance.GetRcdEnable() == true);
1179 for (auto& info : renderTargetNodeInfoList) {
1180 auto nodeId = info.first;
1181 auto type = info.second;
1182 if (type == top) {
1183 rcdInstance.rcdMap_[nodeId] = nullptr;
1184 }
1185 rcdInstance.DrawTopRoundCorner(nodeId, canvas.get());
1186 rcdInstance.DrawTopRoundCorner(nodeId, canvas.get());
1187 if (type == bottom) {
1188 rcdInstance.rcdMap_[nodeId] = nullptr;
1189 }
1190 rcdInstance.DrawBottomRoundCorner(nodeId, canvas.get());
1191 rcdInstance.DrawBottomRoundCorner(nodeId, canvas.get());
1192 EXPECT_TRUE(rcdInstance.CheckExist(nodeId) == false);
1193 }
1194 }
1195
1196 /*
1197 * @tc.name: RSRcdRenderManager
1198 * @tc.desc: Test RSRcdRenderManager
1199 * @tc.type: FUNC
1200 * @tc.require:
1201 */
1202 HWTEST_F(RSRoundCornerDisplayTest, RSRcdRenderManager, TestSize.Level1)
1203 {
1204 auto& rcdManagerInstance = RSRcdRenderManager::GetInstance();
1205 rcdManagerInstance.InitInstance();
1206 NodeId id = 1;
1207 EXPECT_TRUE(rcdManagerInstance.GetRcdRenderEnabled() == true);
1208 auto topLayer = rcdManagerInstance.GetTopSurfaceNode(id);
1209 EXPECT_TRUE(topLayer == nullptr);
1210 auto bottomLayer = rcdManagerInstance.GetBottomSurfaceNode(id);
1211 EXPECT_TRUE(bottomLayer == nullptr);
1212
1213 RcdProcessInfo info{};
1214 rcdManagerInstance.DoProcessRenderMainThreadTask(id, info);
1215 rcdManagerInstance.DoProcessRenderTask(id, info);
1216 auto topNode = rcdManagerInstance.GetTopRenderNode(id);
1217 auto bottomNode = rcdManagerInstance.GetTopRenderNode(id);
1218 RSRenderNodeMap nodeMap;
1219 EXPECT_TRUE(RSRcdRenderManager::CheckExist(id, nodeMap) == false);
1220
1221 // to create layerInfo
1222 std::shared_ptr<Drawing::Bitmap> bitMap = std::make_shared<Drawing::Bitmap>();
1223 bitMap->Build(896, 1848,
1224 Drawing::BitmapFormat{Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_OPAQUE});
1225 rs_rcd::RoundCornerLayer layerTmp{"top.png", 0, 0, "top.bin", 8112, 2028, 1, 896, 1848, bitMap.get()};
1226 std::shared_ptr<rs_rcd::RoundCornerLayer> topPtr = std::make_shared<rs_rcd::RoundCornerLayer>(layerTmp);
1227 auto rsHardwareProcessor =
1228 RSProcessorFactory::CreateProcessor(RSDisplayRenderNode::CompositeType::HARDWARE_COMPOSITE);
1229 info = {rsHardwareProcessor, topPtr, topPtr, true};
1230 rcdManagerInstance.DoProcessRenderMainThreadTask(id, info);
1231 rcdManagerInstance.DoProcessRenderTask(id, info);
1232 auto context = std::make_shared<RSContext>();
1233 RSDisplayNodeConfig config{};
1234 context->nodeMap.UnregisterRenderNode(id);
1235 context->nodeMap.RegisterDisplayRenderNode(std::make_shared<RSDisplayRenderNode>(id, config, context));
1236 rcdManagerInstance.CheckRenderTargetNode(*context);
1237 context->nodeMap.UnregisterRenderNode(id);
1238 context->nodeMap.RegisterDisplayRenderNode(std::make_shared<RSDisplayRenderNode>(id + 1, config, context));
1239 rcdManagerInstance.CheckRenderTargetNode(*context);
1240 rcdManagerInstance.RemoveRcdResource(id);
1241 context->nodeMap.renderNodeMap_.clear();
1242 rcdManagerInstance.topSurfaceNodeMap_.clear();
1243 rcdManagerInstance.bottomSurfaceNodeMap_.clear();
1244 }
1245 } // OHOS::Rosen
1246