1 /*
2 * Copyright (c) 2022 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, Hardware
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 #include <parameter.h>
16 #include <parameters.h>
17
18 #include "gtest/gtest.h"
19 #include "limit_number.h"
20 #include "rs_test_util.h"
21
22 #include "pipeline/rs_main_thread.h"
23 #include "pipeline/rs_render_engine.h"
24 #include "pipeline/rs_root_render_node.h"
25 #include "pipeline/rs_uni_render_engine.h"
26 #include "platform/common/rs_innovation.h"
27 #include "platform/common/rs_system_properties.h"
28 #if defined(ACCESSIBILITY_ENABLE)
29 #include "accessibility_config.h"
30 #endif
31
32 using namespace testing;
33 using namespace testing::ext;
34
35 namespace OHOS::Rosen {
36 constexpr uint64_t REFRESH_PERIOD = 16666667;
37 constexpr uint64_t SKIP_COMMAND_FREQ_LIMIT = 30;
38 constexpr uint32_t MULTI_WINDOW_PERF_START_NUM = 2;
39 constexpr uint32_t MULTI_WINDOW_PERF_END_NUM = 4;
40 constexpr int32_t SIMI_VISIBLE_RATE = 2;
41 constexpr int32_t SYSTEM_ANIMATED_SCENES_RATE = 2;
42 constexpr int32_t INVISBLE_WINDOW_RATE = 10;
43 constexpr int32_t DEFAULT_RATE = 1;
44 constexpr int32_t INVALID_VALUE = -1;
45 constexpr ScreenId DEFAULT_DISPLAY_SCREEN_ID = 0;
46 class RSMainThreadTest : public testing::Test {
47 public:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 void SetUp() override;
51 void TearDown() override;
52 static void* CreateParallelSyncSignal(uint32_t count);
53
54 private:
55 static inline BufferRequestConfig requestConfig = {
56 .width = 0x100,
57 .height = 0x100,
58 .strideAlignment = 0x8,
59 .format = GRAPHIC_PIXEL_FMT_YCRCB_420_SP,
60 .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA,
61 .timeout = 0,
62 };
63 static inline BufferFlushConfig flushConfig = {
64 .damage = { .w = 0x100, .h = 0x100, },
65 };
66 };
67
SetUpTestCase()68 void RSMainThreadTest::SetUpTestCase()
69 {
70 RSTestUtil::InitRenderNodeGC();
71 }
TearDownTestCase()72 void RSMainThreadTest::TearDownTestCase() {}
SetUp()73 void RSMainThreadTest::SetUp() {}
TearDown()74 void RSMainThreadTest::TearDown() {}
CreateParallelSyncSignal(uint32_t count)75 void* RSMainThreadTest::CreateParallelSyncSignal(uint32_t count)
76 {
77 (void)(count);
78 return nullptr;
79 }
80
81 class ApplicationAgentImpl : public IRemoteStub<IApplicationAgent> {
82 public:
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)83 int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override
84 {
85 return 0;
86 }
OnTransaction(std::shared_ptr<RSTransactionData> transactionData)87 void OnTransaction(std::shared_ptr<RSTransactionData> transactionData) override
88 {
89 }
90 };
91
92 /**
93 * @tc.name: Start001
94 * @tc.desc: Test RSMainThreadTest.Start
95 * @tc.type: FUNC
96 * @tc.require: issueI60QXK
97 */
98 HWTEST_F(RSMainThreadTest, Start001, TestSize.Level1)
99 {
100 auto mainThread = RSMainThread::Instance();
101 ASSERT_NE(mainThread, nullptr);
102 mainThread->Start();
103 }
104
105 /**
106 * @tc.name: Start002
107 * @tc.desc: Test RSMainThreadTest.Start
108 * @tc.type: FUNC
109 * @tc.require: issueI60QXK
110 */
111 HWTEST_F(RSMainThreadTest, Start002, TestSize.Level1)
112 {
113 auto mainThread = RSMainThread::Instance();
114 ASSERT_NE(mainThread, nullptr);
115 mainThread->runner_ = nullptr;
116 mainThread->Start();
117 }
118
119 /**
120 * @tc.name: ProcessCommand
121 * @tc.desc: Test RSMainThreadTest.ProcessCommand
122 * @tc.type: FUNC
123 * @tc.require: issueI60QXK
124 */
125 HWTEST_F(RSMainThreadTest, ProcessCommand, TestSize.Level1)
126 {
127 auto mainThread = RSMainThread::Instance();
128 ASSERT_NE(mainThread, nullptr);
129 auto isUniRender = mainThread->isUniRender_;
130 mainThread->isUniRender_ = false;
131 mainThread->ProcessCommand();
132 mainThread->isUniRender_ = true;
133 mainThread->lastAnimateTimestamp_ = 0;
134 mainThread->timestamp_ = REFRESH_PERIOD + 1;
135 mainThread->context_->purgeType_ = RSContext::PurgeType::GENTLY;
136 mainThread->ProcessCommand();
137 mainThread->context_->purgeType_ = RSContext::PurgeType::STRONGLY;
138 mainThread->isUniRender_ = isUniRender;
139 }
140
141 /**
142 * @tc.name: RsEventParamDump
143 * @tc.desc: Test RSMainThreadTest.RsEventParamDump
144 * @tc.type: FUNC
145 * @tc.require: issueI60QXK
146 */
147 HWTEST_F(RSMainThreadTest, RsEventParamDump, TestSize.Level1)
148 {
149 auto mainThread = RSMainThread::Instance();
150 ASSERT_NE(mainThread, nullptr);
151 std::string str = "";
152 mainThread->RsEventParamDump(str);
153 ASSERT_TRUE(str.empty());
154 }
155
156 /**
157 * @tc.name: RemoveRSEventDetector001
158 * @tc.desc: Test RSMainThreadTest.RemoveRSEventDetector, with init
159 * @tc.type: FUNC
160 * @tc.require: issueI60QXK
161 */
162 HWTEST_F(RSMainThreadTest, RemoveRSEventDetector001, TestSize.Level1)
163 {
164 auto mainThread = RSMainThread::Instance();
165 ASSERT_NE(mainThread, nullptr);
166 mainThread->InitRSEventDetector();
167 mainThread->RemoveRSEventDetector();
168 }
169
170 /**
171 * @tc.name: RemoveRSEventDetector002
172 * @tc.desc: Test RSMainThreadTest.RemoveRSEventDetector, without init
173 * @tc.type: FUNC
174 * @tc.require: issueI60QXK
175 */
176 HWTEST_F(RSMainThreadTest, RemoveRSEventDetector002, TestSize.Level1)
177 {
178 auto mainThread = RSMainThread::Instance();
179 ASSERT_NE(mainThread, nullptr);
180 mainThread->RemoveRSEventDetector();
181 }
182
183 /**
184 * @tc.name: InitRSEventDetector
185 * @tc.desc: Test RSMainThreadTest.InitRSEventDetector, without init
186 * @tc.type: FUNC
187 * @tc.require: issueI60QXK
188 */
189 HWTEST_F(RSMainThreadTest, InitRSEventDetector, TestSize.Level1)
190 {
191 auto mainThread = RSMainThread::Instance();
192 ASSERT_NE(mainThread, nullptr);
193 mainThread->rsCompositionTimeoutDetector_ = nullptr;
194 mainThread->InitRSEventDetector();
195 }
196
197 /**
198 * @tc.name: SetRSEventDetectorLoopStartTag001
199 * @tc.desc: Test RSMainThreadTest.SetRSEventDetectorLoopStartTag, with init
200 * @tc.type: FUNC
201 * @tc.require: issueI60QXK
202 */
203 HWTEST_F(RSMainThreadTest, SetRSEventDetectorLoopStartTag001, TestSize.Level1)
204 {
205 auto mainThread = RSMainThread::Instance();
206 ASSERT_NE(mainThread, nullptr);
207 mainThread->InitRSEventDetector();
208 mainThread->SetRSEventDetectorLoopStartTag();
209 }
210
211 /**
212 * @tc.name: SetRSEventDetectorLoopStartTag002
213 * @tc.desc: Test RSMainThreadTest.SetRSEventDetectorLoopStartTag, without init
214 * @tc.type: FUNC
215 * @tc.require: issueI60QXK
216 */
217 HWTEST_F(RSMainThreadTest, SetRSEventDetectorLoopStartTag002, TestSize.Level1)
218 {
219 auto mainThread = RSMainThread::Instance();
220 ASSERT_NE(mainThread, nullptr);
221 mainThread->rsCompositionTimeoutDetector_ = nullptr;
222 mainThread->SetRSEventDetectorLoopStartTag();
223 }
224
225 /**
226 * @tc.name: SetRSEventDetectorLoopFinishTag001
227 * @tc.desc: Test RSMainThreadTest.SetRSEventDetectorLoopFinishTag, with init
228 * @tc.type: FUNC
229 * @tc.require: issueI60QXK
230 */
231 HWTEST_F(RSMainThreadTest, SetRSEventDetectorLoopFinishTag001, TestSize.Level1)
232 {
233 auto mainThread = RSMainThread::Instance();
234 ASSERT_NE(mainThread, nullptr);
235 mainThread->InitRSEventDetector();
236 auto isUniRender = mainThread->isUniRender_;
237 mainThread->isUniRender_ = false;
238 mainThread->SetRSEventDetectorLoopFinishTag();
239 mainThread->isUniRender_ = true;
240 mainThread->SetRSEventDetectorLoopFinishTag();
241 mainThread->isUniRender_ = isUniRender;
242 }
243
244 /**
245 * @tc.name: SetRSEventDetectorLoopFinishTag002
246 * @tc.desc: Test RSMainThreadTest.SetRSEventDetectorLoopFinishTag, without init
247 * @tc.type: FUNC
248 * @tc.require: issueI60QXK
249 */
250 HWTEST_F(RSMainThreadTest, SetRSEventDetectorLoopFinishTag002, TestSize.Level1)
251 {
252 auto mainThread = RSMainThread::Instance();
253 ASSERT_NE(mainThread, nullptr);
254 mainThread->rsCompositionTimeoutDetector_ = nullptr;
255 mainThread->SetRSEventDetectorLoopFinishTag();
256 }
257
258 /**
259 * @tc.name: WaitUtilUniRenderFinished
260 * @tc.desc: Test RSMainThreadTest.WaitUtilUniRenderFinished
261 * @tc.type: FUNC
262 * @tc.require: issueI60QXK
263 */
264 HWTEST_F(RSMainThreadTest, WaitUtilUniRenderFinished, TestSize.Level1)
265 {
266 auto mainThread = RSMainThread::Instance();
267 ASSERT_NE(mainThread, nullptr);
268 mainThread->NotifyUniRenderFinish();
269 mainThread->WaitUtilUniRenderFinished();
270 ASSERT_EQ(mainThread->uniRenderFinished_, true);
271 }
272
273 /**
274 * @tc.name: ProcessCommandForDividedRender001
275 * @tc.desc: Test RSMainThreadTest.ProcessCommandForDividedRender
276 * @tc.type: FUNC
277 * @tc.require: issueI60QXK
278 */
279 HWTEST_F(RSMainThreadTest, ProcessCommandForDividedRender001, TestSize.Level1)
280 {
281 auto mainThread = RSMainThread::Instance();
282 ASSERT_NE(mainThread, nullptr);
283 mainThread->ProcessCommandForDividedRender();
284 }
285
286 /**
287 * @tc.name: CalcOcclusion
288 * @tc.desc: Test RSMainThreadTest.CalcOcclusion, doWindowAnimate_ is false, isUniRender_ is true
289 * @tc.type: FUNC
290 * @tc.require: issueI60QXK
291 */
292 HWTEST_F(RSMainThreadTest, CalcOcclusion, TestSize.Level1)
293 {
294 auto mainThread = RSMainThread::Instance();
295 ASSERT_NE(mainThread, nullptr);
296 mainThread->doWindowAnimate_ = false;
297 mainThread->isUniRender_ = true;
298 mainThread->CalcOcclusion();
299 }
300
301 /**
302 * @tc.name: Animate001
303 * @tc.desc: Test RSMainThreadTest.Animate, doWindowAnimate_ is false
304 * @tc.type: FUNC
305 * @tc.require: issueI60QXK
306 */
307 HWTEST_F(RSMainThreadTest, Animate001, TestSize.Level1)
308 {
309 auto mainThread = RSMainThread::Instance();
310 ASSERT_NE(mainThread, nullptr);
311 mainThread->doWindowAnimate_ = false;
312 mainThread->Animate(0);
313 }
314
315 /**
316 * @tc.name: Animate002
317 * @tc.desc: Test RSMainThreadTest.Animate, doWindowAnimate_ is true
318 * @tc.type: FUNC
319 * @tc.require: issueI60QXK
320 */
321 HWTEST_F(RSMainThreadTest, Animate002, TestSize.Level1)
322 {
323 auto mainThread = RSMainThread::Instance();
324 ASSERT_NE(mainThread, nullptr);
325 mainThread->doWindowAnimate_ = true;
326 mainThread->Animate(0);
327 }
328
329 /**
330 * @tc.name: UnRegisterOcclusionChangeCallback
331 * @tc.desc: Test RSMainThreadTest.Animate
332 * @tc.type: FUNC
333 * @tc.require: issueI60QXK
334 */
335 HWTEST_F(RSMainThreadTest, UnRegisterOcclusionChangeCallback, TestSize.Level1)
336 {
337 auto mainThread = RSMainThread::Instance();
338 ASSERT_NE(mainThread, nullptr);
339 mainThread->UnRegisterOcclusionChangeCallback(0);
340 }
341
342 /**
343 * @tc.name: RenderServiceTreeDump
344 * @tc.desc: Test RSMainThreadTest.RenderServiceTreeDump, str is an empty string
345 * @tc.type: FUNC
346 * @tc.require: issueI60QXK
347 */
348 HWTEST_F(RSMainThreadTest, RenderServiceTreeDump, TestSize.Level1)
349 {
350 auto mainThread = RSMainThread::Instance();
351 std::string str = "";
352 mainThread->RenderServiceTreeDump(str);
353 }
354
355 /**
356 * @tc.name: SetFocusAppInfo
357 * @tc.desc: Test RSMainThreadTest.SetFocusAppInfo, input pid, uid is -1, str is an empty string
358 * @tc.type: FUNC
359 * @tc.require: issueI60QXK
360 */
361 HWTEST_F(RSMainThreadTest, SetFocusAppInfo, TestSize.Level1)
362 {
363 auto mainThread = RSMainThread::Instance();
364 std::string str = "";
365 int32_t pid = INVALID_VALUE;
366 int32_t uid = INVALID_VALUE;
367 mainThread->SetFocusAppInfo(pid, uid, str, str, 0);
368 }
369
370 /**
371 * @tc.name: SetFocusAppInfo002
372 * @tc.desc: Test SetFocusAppInfo while change focus node
373 * @tc.type: FUNC
374 * @tc.require: issueI9LOXQ
375 */
376 HWTEST_F(RSMainThreadTest, SetFocusAppInfo002, TestSize.Level2)
377 {
378 auto mainThread = RSMainThread::Instance();
379 ASSERT_NE(mainThread, nullptr);
380
381 NodeId id = 0;
382 auto oldFocusNode = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
383 auto newFocusNode = std::make_shared<RSSurfaceRenderNode>(id + 1, mainThread->context_);
384 mainThread->focusNodeId_ = oldFocusNode->GetId();
385
386 std::string str = "";
387 int32_t pid = INVALID_VALUE;
388 int32_t uid = INVALID_VALUE;
389 mainThread->SetFocusAppInfo(pid, uid, str, str, newFocusNode->GetId());
390 ASSERT_EQ(mainThread->GetFocusNodeId(), newFocusNode->GetId());
391 }
392
393 /**
394 * @tc.name: ProcessSyncRSTransactionData001
395 * @tc.desc: Test ProcessSyncRSTransactionData when TransactionData do not need sync
396 * @tc.type: FUNC
397 * @tc.require: issueI6Q9A2
398 */
399 HWTEST_F(RSMainThreadTest, ProcessSyncRSTransactionData001, TestSize.Level1)
400 {
401 // when IsNeedSync() is false
402 auto mainThread = RSMainThread::Instance();
403 auto rsTransactionData = std::make_unique<RSTransactionData>();
404 pid_t pid = 0;
405 rsTransactionData->SetSyncId(1);
406 mainThread->ProcessSyncRSTransactionData(rsTransactionData, pid);
407 ASSERT_EQ(mainThread->syncTransactionData_.empty(), false);
408
409 // when syncTransactionData_ is not empty and SyncId is larger
410 rsTransactionData = std::make_unique<RSTransactionData>();
411 rsTransactionData->MarkNeedSync();
412 rsTransactionData->SetSyncId(0);
413 mainThread->ProcessSyncRSTransactionData(rsTransactionData, pid);
414 ASSERT_EQ(mainThread->syncTransactionData_.empty(), false);
415
416 // when syncTransactionData_ is not empty and SyncId is equal or smaller
417 rsTransactionData->SetSyncTransactionNum(1);
418 rsTransactionData->SetSyncId(1);
419 mainThread->ProcessSyncRSTransactionData(rsTransactionData, pid);
420 ASSERT_EQ(mainThread->syncTransactionData_.empty(), false);
421 }
422
423 /**
424 * @tc.name: ProcessSyncRSTransactionData002
425 * @tc.desc: Test ProcessSyncRSTransactionData when TransactionData do not need sync
426 * @tc.type: FUNC
427 * @tc.require: issueI6Q9A2
428 */
429 HWTEST_F(RSMainThreadTest, ProcessSyncRSTransactionData002, TestSize.Level1)
430 {
431 // when IsNeedSync() is true & syncTransactionData_ is empty & isNeedCloseSync is true
432 auto mainThread = RSMainThread::Instance();
433 auto rsTransactionData = std::make_unique<RSTransactionData>();
434 pid_t pid = 0;
435 rsTransactionData->MarkNeedSync();
436 rsTransactionData->MarkNeedCloseSync();
437 rsTransactionData->SetSyncTransactionNum(1);
438 mainThread->ProcessSyncRSTransactionData(rsTransactionData, pid);
439 ASSERT_EQ(mainThread->syncTransactionData_.empty(), false);
440 }
441
442 /**
443 * @tc.name: ProcessSyncTransactionCount
444 * @tc.desc: Test ProcessSyncTransactionCount
445 * @tc.type: FUNC
446 * @tc.require: issueI6Q9A2
447 */
448 HWTEST_F(RSMainThreadTest, ProcessSyncTransactionCount, TestSize.Level1)
449 {
450 auto mainThread = RSMainThread::Instance();
451 auto rsTransactionData = std::make_unique<RSTransactionData>();
452
453 rsTransactionData->SetParentPid(-1);
454 mainThread->ProcessSyncTransactionCount(rsTransactionData);
455 auto parentPid = rsTransactionData->GetParentPid();
456 ASSERT_EQ(parentPid, -1);
457
458 rsTransactionData->SetSyncTransactionNum(1);
459 mainThread->ProcessSyncTransactionCount(rsTransactionData);
460 ASSERT_EQ(rsTransactionData->GetSyncTransactionNum(), 1);
461
462 rsTransactionData->MarkNeedCloseSync();
463 mainThread->ProcessSyncTransactionCount(rsTransactionData);
464 mainThread->StartSyncTransactionFallbackTask(rsTransactionData);
465 ASSERT_EQ(rsTransactionData->IsNeedCloseSync(), true);
466 }
467
468 /**
469 * @tc.name: GetContext
470 * @tc.desc: Test if context has been initialized
471 * @tc.type: FUNC
472 * @tc.require: issueI6Q9A2
473 */
474 HWTEST_F(RSMainThreadTest, GetContext, TestSize.Level1)
475 {
476 auto mainThread = RSMainThread::Instance();
477 auto& context = mainThread->GetContext();
478 uint64_t time = 0;
479 ASSERT_EQ(context.GetTransactionTimestamp(), time);
480 }
481
482 /**
483 * @tc.name: ClassifyRSTransactionData001
484 * @tc.desc: Test ClassifyRSTransactionData when nodeId is 0
485 * @tc.type: FUNC
486 * @tc.require: issueI6Q9A2
487 */
488 HWTEST_F(RSMainThreadTest, ClassifyRSTransactionData001, TestSize.Level1)
489 {
490 auto mainThread = RSMainThread::Instance();
491 mainThread->pendingEffectiveCommands_.clear();
492 auto rsTransactionData = std::make_unique<RSTransactionData>();
493 std::unique_ptr<RSCommand> command = nullptr;
494 NodeId nodeId = 0;
495 FollowType followType = FollowType::NONE;
496 rsTransactionData->AddCommand(command, nodeId, followType);
497 mainThread->ClassifyRSTransactionData(rsTransactionData);
498 ASSERT_EQ(mainThread->pendingEffectiveCommands_.empty(), true);
499 }
500
501 /**
502 * @tc.name: ClassifyRSTransactionData002
503 * @tc.desc: Test ClassifyRSTransactionData when nodeId is 1
504 * @tc.type: FUNC
505 * @tc.require: issueI6R34I
506 */
507 HWTEST_F(RSMainThreadTest, ClassifyRSTransactionData002, TestSize.Level1)
508 {
509 auto mainThread = RSMainThread::Instance();
510 mainThread->pendingEffectiveCommands_.clear();
511 auto rsTransactionData = std::make_unique<RSTransactionData>();
512 std::unique_ptr<RSCommand> command = nullptr;
513 NodeId nodeId = 1;
514 FollowType followType = FollowType::NONE;
515 rsTransactionData->AddCommand(command, nodeId, followType);
516 mainThread->ClassifyRSTransactionData(rsTransactionData);
517 ASSERT_EQ(mainThread->pendingEffectiveCommands_.empty(), true);
518 }
519
520 /**
521 * @tc.name: ClassifyRSTransactionData003
522 * @tc.desc: Test ClassifyRSTransactionData when followType is FOLLOW_TO_PARENT
523 * @tc.type: FUNC
524 * @tc.require: issueI6R34I
525 */
526 HWTEST_F(RSMainThreadTest, ClassifyRSTransactionData003, TestSize.Level1)
527 {
528 auto mainThread = RSMainThread::Instance();
529 mainThread->pendingEffectiveCommands_.clear();
530 auto rsTransactionData = std::make_unique<RSTransactionData>();
531 std::unique_ptr<RSCommand> command = nullptr;
532 NodeId nodeId = 1;
533 FollowType followType = FollowType::FOLLOW_TO_PARENT;
534 rsTransactionData->AddCommand(command, nodeId, followType);
535 mainThread->ClassifyRSTransactionData(rsTransactionData);
536 ASSERT_EQ(mainThread->cachedCommands_[nodeId].empty(), true);
537 }
538
539 /**
540 * @tc.name: ClassifyRSTransactionData004
541 * @tc.desc: Test ClassifyRSTransactionData when followType is FOLLOW_TO_PARENT
542 * @tc.type: FUNC
543 * @tc.require: issueI6R34I
544 */
545 HWTEST_F(RSMainThreadTest, ClassifyRSTransactionData004, TestSize.Level1)
546 {
547 auto mainThread = RSMainThread::Instance();
548 // build the NodeTree
549 NodeId nodeId = 1;
550 std::weak_ptr<RSContext> context = {};
551 auto node = std::make_shared<RSBaseRenderNode>(nodeId, context);
552 auto childNode = std::make_shared<RSBaseRenderNode>(nodeId + 1, context);
553 int index = 0;
554 node->SetIsOnTheTree(true);
555 node->AddChild(node, index);
556 ASSERT_EQ(static_cast<int>(node->GetChildrenCount()), 0);
557 node->AddChild(childNode, index);
558 ASSERT_EQ(static_cast<int>(node->GetChildrenCount()), 1);
559 ASSERT_TRUE(childNode->IsOnTheTree());
560
561 mainThread->cachedCommands_.clear();
562 auto rsTransactionData = std::make_unique<RSTransactionData>();
563 std::unique_ptr<RSCommand> command = nullptr;
564 FollowType followType = FollowType::FOLLOW_TO_SELF;
565 rsTransactionData->AddCommand(command, nodeId, followType);
566 mainThread->ClassifyRSTransactionData(rsTransactionData);
567 ASSERT_EQ(mainThread->cachedCommands_[nodeId].empty(), true);
568
569 mainThread->cachedCommands_.clear();
570 rsTransactionData = std::make_unique<RSTransactionData>();
571 command = nullptr;
572 followType = FollowType::FOLLOW_TO_PARENT;
573 rsTransactionData->AddCommand(command, nodeId + 1, followType);
574 mainThread->ClassifyRSTransactionData(rsTransactionData);
575 ASSERT_EQ(mainThread->cachedCommands_[nodeId + 1].empty(), true);
576 }
577
578 /**
579 * @tc.name: AddActiveNode
580 * @tc.desc: Test AddActiveNode, add invalid node id, check if fails
581 * @tc.type: FUNC
582 * @tc.require: issueI6Q9A2
583 */
584 HWTEST_F(RSMainThreadTest, AddActiveNode, TestSize.Level1)
585 {
586 auto mainThread = RSMainThread::Instance();
587 mainThread->context_->activeNodesInRoot_.clear();
588 // invalid nodeid
589 NodeId id = INVALID_NODEID;
590 auto node = std::make_shared<RSRenderNode>(id, mainThread->context_);
591 mainThread->context_->AddActiveNode(node);
592 ASSERT_EQ(static_cast<int>(mainThread->context_->activeNodesInRoot_.size()), 0);
593 }
594
595 /**
596 * @tc.name: CheckAndUpdateInstanceContentStaticStatus01
597 * @tc.desc: Test static instance(no dirty) would be classify as only basic geo transform
598 * @tc.type: FUNC
599 * @tc.require: issueI8IXTX
600 */
601 HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus01, TestSize.Level1)
602 {
603 auto mainThread = RSMainThread::Instance();
604 mainThread->context_->activeNodesInRoot_.clear();
605 // valid nodeid
606 NodeId id = 1;
607 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
608 ASSERT_NE(node, nullptr);
609 mainThread->CheckAndUpdateInstanceContentStaticStatus(node);
610 ASSERT_EQ(node->GetSurfaceCacheContentStatic(), true);
611 }
612
613 /**
614 * @tc.name: CheckAndUpdateInstanceContentStaticStatus02
615 * @tc.desc: Test new instance would not be classify as only basic geo transform
616 * @tc.type: FUNC
617 * @tc.require: issueI8IXTX
618 */
619 HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus02, TestSize.Level1)
620 {
621 auto mainThread = RSMainThread::Instance();
622 mainThread->context_->activeNodesInRoot_.clear();
623 // valid nodeid
624 NodeId id = 1;
625 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
626 ASSERT_NE(node, nullptr);
627 node->SetIsOnTheTree(true, id, id);
628 node->SetContentDirty();
629 mainThread->context_->AddActiveNode(node);
630 ASSERT_EQ(static_cast<int>(mainThread->context_->activeNodesInRoot_.size()), 1);
631 mainThread->CheckAndUpdateInstanceContentStaticStatus(node);
632 ASSERT_EQ(node->GetSurfaceCacheContentStatic(), false);
633 }
634
635 /**
636 * @tc.name: IsNeedProcessBySingleFrameComposerTest001
637 * @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when TransactionData is null
638 * @tc.type: FUNC
639 * @tc.require: issueI9HPBS
640 */
641 HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest001, TestSize.Level1)
642 {
643 auto mainThread = RSMainThread::Instance();
644 std::unique_ptr<RSTransactionData> transactionData = nullptr;
645 ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
646 transactionData = std::make_unique<RSTransactionData>();
647 mainThread->isUniRender_ = true;
648 ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
649 }
650
651 /**
652 * @tc.name: IsNeedProcessBySingleFrameComposerTest002
653 * @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when SingleFrameComposer enabled by app process
654 * @tc.type: FUNC
655 * @tc.require: issueI9HPBS
656 */
657 HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest002, TestSize.Level1)
658 {
659 auto mainThread = RSMainThread::Instance();
660 auto transactionData = std::make_unique<RSTransactionData>();
661 mainThread->isUniRender_ = true;
662 pid_t pid = 1;
663 transactionData->SetSendingPid(pid);
664 RSSingleFrameComposer::AddOrRemoveAppPidToMap(true, pid);
665 ASSERT_TRUE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
666 }
667
668 /**
669 * @tc.name: IsNeedProcessBySingleFrameComposerTest003
670 * @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when animation node exists
671 * @tc.type: FUNC
672 * @tc.require: issueI9HPBS
673 */
674 HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest003, TestSize.Level1)
675 {
676 auto mainThread = RSMainThread::Instance();
677 auto transactionData = std::make_unique<RSTransactionData>();
678 mainThread->isUniRender_ = true;
679 pid_t pid = 1;
680 transactionData->SetSendingPid(pid);
681 RSSingleFrameComposer::AddOrRemoveAppPidToMap(true, pid);
682
683 NodeId id = 1;
684 auto node = std::make_shared<RSRenderNode>(id, mainThread->context_);
685 mainThread->context_->RegisterAnimatingRenderNode(node);
686 ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
687 }
688
689 /**
690 * @tc.name: IsNeedProcessBySingleFrameComposerTest004
691 * @tc.desc: Test IsNeedProcessBySingleFrameComposerTest when multi-window shown on screen
692 * @tc.type: FUNC
693 * @tc.require: issueI9HPBS
694 */
695 HWTEST_F(RSMainThreadTest, IsNeedProcessBySingleFrameComposerTest004, TestSize.Level1)
696 {
697 auto mainThread = RSMainThread::Instance();
698 auto transactionData = std::make_unique<RSTransactionData>();
699 mainThread->isUniRender_ = true;
700 pid_t pid = 1;
701 transactionData->SetSendingPid(pid);
702 RSSingleFrameComposer::AddOrRemoveAppPidToMap(true, pid);
703
704 NodeId firstWindowNodeId = 2;
705 auto firstWindowNode = std::make_shared<RSSurfaceRenderNode>(firstWindowNodeId, mainThread->context_);
706 firstWindowNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
707 NodeId firstWindowChildNodeId = 3;
708 auto firstWindowChildNode = std::make_shared<RSSurfaceRenderNode>(firstWindowChildNodeId, mainThread->context_);
709 firstWindowChildNode->MarkUIHidden(false);
710 firstWindowNode->AddChild(firstWindowChildNode);
711 firstWindowNode->GenerateFullChildrenList();
712 mainThread->context_->nodeMap.RegisterRenderNode(firstWindowNode);
713
714 NodeId secondWindowNodeId = 2;
715 auto secondWindowNode = std::make_shared<RSSurfaceRenderNode>(secondWindowNodeId, mainThread->context_);
716 secondWindowNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
717 NodeId secondWindowChildNodeId = 3;
718 auto secondWindowChildNode = std::make_shared<RSSurfaceRenderNode>(secondWindowChildNodeId, mainThread->context_);
719 secondWindowChildNode->MarkUIHidden(false);
720 secondWindowNode->AddChild(secondWindowChildNode);
721 secondWindowNode->GenerateFullChildrenList();
722 mainThread->context_->nodeMap.RegisterRenderNode(secondWindowNode);
723 ASSERT_FALSE(mainThread->IsNeedProcessBySingleFrameComposer(transactionData));
724 }
725
726 /**
727 * @tc.name: RecvAndProcessRSTransactionDataImmediatelyTest
728 * @tc.desc: Test ecvAndProcessRSTransactionDataImmediately when transactionData is null
729 * @tc.type: FUNC
730 * @tc.require: issueI9HPBS
731 */
732 HWTEST_F(RSMainThreadTest, RecvAndProcessRSTransactionDataImmediatelyTest, TestSize.Level1)
733 {
734 auto mainThread = RSMainThread::Instance();
735 std::unique_ptr<RSTransactionData> transactionData = nullptr;
736 mainThread->RecvAndProcessRSTransactionDataImmediately(transactionData);
737 ASSERT_EQ(transactionData, nullptr);
738 }
739
740
741 /**
742 * @tc.name: RecvRSTransactionData
743 * @tc.desc: Test RecvRSTransactionData, when TransactionData is null
744 * @tc.type: FUNC
745 * @tc.require: issueI6R34I
746 */
747 HWTEST_F(RSMainThreadTest, RecvRSTransactionData, TestSize.Level1)
748 {
749 auto mainThread = RSMainThread::Instance();
750 std::unique_ptr<RSTransactionData> transactionData = nullptr;
751 mainThread->RecvRSTransactionData(transactionData);
752 ASSERT_EQ(transactionData, nullptr);
753 }
754
755 /**
756 * @tc.name: PostSyncTask
757 * @tc.desc: Test PostSyncTask when handler is null or not
758 * @tc.type: FUNC
759 * @tc.require: issueI6R34I
760 */
761 HWTEST_F(RSMainThreadTest, PostSyncTask, TestSize.Level1)
762 {
763 auto mainThread = RSMainThread::Instance();
__anon22dae5050102() 764 RSTaskMessage::RSTask task = []() -> void { return; };
765 mainThread->PostSyncTask(task);
766 }
767
768 /**
769 * @tc.name: ShowWatermark
770 * @tc.desc: ShowWatermark test
771 * @tc.type: FUNC
772 * @tc.require: issueI78T3Z
773 */
774 HWTEST_F(RSMainThreadTest, ShowWatermark, TestSize.Level1)
775 {
776 auto mainThread = RSMainThread::Instance();
777 const uint32_t color[8] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 };
778 uint32_t colorLength = sizeof(color) / sizeof(color[0]);
779 const int32_t offset = 0;
780 Media::InitializationOptions opts;
781 int32_t stride = 3;
782 std::unique_ptr<Media::PixelMap> pixelMap1 = Media::PixelMap::Create(color, colorLength, offset, stride, opts);
783 mainThread->ShowWatermark(std::move(pixelMap1), true);
784 ASSERT_EQ(mainThread->GetWatermarkFlag(), true);
785 mainThread->ShowWatermark(nullptr, false);
786 ASSERT_EQ(mainThread->GetWatermarkFlag(), false);
787 }
788
789 /**
790 * @tc.name: MergeToEffectiveTransactionDataMap001
791 * @tc.desc: Test RSMainThreadTest.MergeToEffectiveTransactionDataMap
792 * @tc.type: FUNC
793 * @tc.require: issueI8V6MD
794 */
795 HWTEST_F(RSMainThreadTest, MergeToEffectiveTransactionDataMap001, TestSize.Level1)
796 {
797 auto mainThread = RSMainThread::Instance();
798 mainThread->Start();
799 ASSERT_EQ(mainThread->effectiveTransactionDataIndexMap_.empty(), true);
800 mainThread->effectiveTransactionDataIndexMap_[0].first = 0;
801 TransactionDataMap dataMap;
802 auto data = std::make_unique<RSTransactionData>();
803 ASSERT_NE(data, nullptr);
804 data->SetIndex(1);
805 dataMap[0].emplace_back(std::move(data));
806 data = std::make_unique<RSTransactionData>();
807 ASSERT_NE(data, nullptr);
808 data->SetIndex(3);
809 dataMap[0].emplace_back(std::move(data));
810 dataMap[0].emplace_back(nullptr);
811 mainThread->MergeToEffectiveTransactionDataMap(dataMap);
812 mainThread->effectiveTransactionDataIndexMap_.clear();
813 }
814
815 /**
816 * @tc.name: ProcessCommandForUniRender
817 * @tc.desc: ProcessCommandForUniRender test with invalid data
818 * @tc.type: FUNC
819 * @tc.require: issueI7A39J
820 */
821 HWTEST_F(RSMainThreadTest, ProcessCommandForUniRender, TestSize.Level1)
822 {
823 auto mainThread = RSMainThread::Instance();
824 ASSERT_EQ(mainThread->effectiveTransactionDataIndexMap_.empty(), true);
825
826 // // let lastindex same as timeout index and test timeout case at first
827 mainThread->transactionDataLastWaitTime_[0] = 0;
828 mainThread->timestamp_ = REFRESH_PERIOD * SKIP_COMMAND_FREQ_LIMIT + 1;
829 mainThread->effectiveTransactionDataIndexMap_[0].first = 0;
830 if (mainThread->rsVSyncDistributor_ == nullptr) {
831 auto vsyncGenerator = CreateVSyncGenerator();
832 auto vsyncController = new VSyncController(vsyncGenerator, 0);
833 mainThread->rsVSyncDistributor_ = new VSyncDistributor(vsyncController, "rs");
834 vsyncGenerator->SetRSDistributor(mainThread->rsVSyncDistributor_);
835 }
836 // default data with index 0
837 auto data = std::make_unique<RSTransactionData>();
838 ASSERT_NE(data, nullptr);
839 data->SetIndex(1);
840 mainThread->effectiveTransactionDataIndexMap_[0].second.emplace_back(std::move(data));
841 data = std::make_unique<RSTransactionData>();
842 ASSERT_NE(data, nullptr);
843 data->SetIndex(3);
844 mainThread->effectiveTransactionDataIndexMap_[0].second.emplace_back(std::move(data));
845 data = std::make_unique<RSTransactionData>();
846 ASSERT_NE(data, nullptr);
847 data->SetIndex(2);
848 mainThread->effectiveTransactionDataIndexMap_[0].second.emplace_back(std::move(data));
849 // empty data
850 mainThread->effectiveTransactionDataIndexMap_[0].second.emplace_back(nullptr);
851 mainThread->ProcessCommandForUniRender();
852 }
853
854 /**
855 * @tc.name: GetWatermarkImg
856 * @tc.desc: GetWatermarkImg test
857 * @tc.type: FUNC
858 * @tc.require: issueI7HDVG
859 */
860 HWTEST_F(RSMainThreadTest, GetWatermarkImg, TestSize.Level1)
861 {
862 auto mainThread = RSMainThread::Instance();
863 mainThread->GetWatermarkImg();
864 }
865
866 /**
867 * @tc.name: IsWatermarkFlagChanged
868 * @tc.desc: IsWatermarkFlagChanged test
869 * @tc.type: FUNC
870 * @tc.require: issuesIA8LNR
871 */
872 HWTEST_F(RSMainThreadTest, IsWatermarkFlagChanged, TestSize.Level1)
873 {
874 auto mainThread = RSMainThread::Instance();
875 ASSERT_NE(mainThread, nullptr);
876 mainThread->IsWatermarkFlagChanged();
877 }
878
879 /**
880 * @tc.name: DoParallelComposition
881 * @tc.desc: DoParallelComposition test
882 * @tc.type: FUNC
883 * @tc.require: issueI7HDVG
884 */
885 HWTEST_F(RSMainThreadTest, DoParallelComposition, TestSize.Level1)
886 {
887 NodeId nodeId = 1;
888 std::weak_ptr<RSContext> context = {};
889 auto node = std::make_shared<RSBaseRenderNode>(nodeId, context);
890 auto childNode = std::make_shared<RSBaseRenderNode>(nodeId + 1, context);
891 int index = 0;
892 node->SetIsOnTheTree(true);
893 node->AddChild(childNode, index);
894 ASSERT_EQ(static_cast<int>(node->GetChildrenCount()), 1);
895 ASSERT_TRUE(childNode->IsOnTheTree());
896
897 auto mainThread = RSMainThread::Instance();
898 RSInnovation::_s_createParallelSyncSignal = (void*)RSMainThreadTest::CreateParallelSyncSignal;
899 if (RSInnovation::GetParallelCompositionEnabled(mainThread->isUniRender_)) {
900 mainThread->DoParallelComposition(node);
901 }
902 }
903
904 /**
905 * @tc.name: SetIdleTimerExpiredFlag
906 * @tc.desc: SetIdleTimerExpiredFlag test
907 * @tc.type: FUNC
908 * @tc.require: issueI7HDVG
909 */
910 HWTEST_F(RSMainThreadTest, SetIdleTimerExpiredFlag, TestSize.Level1)
911 {
912 auto mainThread = RSMainThread::Instance();
913 mainThread->SetIdleTimerExpiredFlag(true);
914 }
915
916 /**
917 * @tc.name: SetFocusLeashWindowId
918 * @tc.desc: Test RSMainThreadTest.SetFocusLeashWindowId
919 * @tc.type: FUNC
920 * @tc.require: issueI8V6MD
921 */
922 HWTEST_F(RSMainThreadTest, SetFocusLeashWindowId, TestSize.Level1)
923 {
924 auto mainThread = RSMainThread::Instance();
925 mainThread->Start();
926 NodeId id = 1;
927 auto node1 = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
928 ASSERT_NE(node1, nullptr);
929 RSSurfaceRenderNodeConfig config;
930 auto node2 = std::make_shared<RSSurfaceRenderNode>(config);
931 ASSERT_NE(node2, nullptr);
932 node1->SetParent(node2);
933 node1->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
934 node2->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
935
936 mainThread->context_ = std::make_shared<RSContext>();
937 mainThread->context_->nodeMap.renderNodeMap_[0] = node1;
938 mainThread->focusNodeId_ = 0;
939 mainThread->SetFocusLeashWindowId();
940 }
941
942 /**
943 * @tc.name: SetFocusLeashWindowId002
944 * @tc.desc: Test SetFocusLeashWindowId while nodeMap is empty
945 * @tc.type: FUNC
946 * @tc.require: issueI98VTC
947 */
948 HWTEST_F(RSMainThreadTest, SetFocusLeashWindowId002, TestSize.Level2)
949 {
950 auto mainThread = RSMainThread::Instance();
951 ASSERT_NE(mainThread, nullptr);
952
953 mainThread->SetFocusLeashWindowId();
954 ASSERT_EQ(mainThread->GetFocusLeashWindowId(), INVALID_NODEID);
955 }
956
957 /**
958 * @tc.name: SetFocusLeashWindowId003
959 * @tc.desc: Test SetFocusLeashWindowId while focus node don't have parent
960 * @tc.type: FUNC
961 * @tc.require: issueI98VTC
962 */
963 HWTEST_F(RSMainThreadTest, SetFocusLeashWindowId003, TestSize.Level2)
964 {
965 auto mainThread = RSMainThread::Instance();
966 auto node = RSTestUtil::CreateSurfaceNode();
967 ASSERT_NE(mainThread, nullptr);
968 ASSERT_NE(node, nullptr);
969
970 ASSERT_NE(mainThread->context_, nullptr);
971 mainThread->context_->nodeMap.renderNodeMap_[node->GetId()] = node;
972 std::string str = "";
973 mainThread->SetFocusAppInfo(-1, -1, str, str, node->GetId());
974 mainThread->SetFocusLeashWindowId();
975 ASSERT_EQ(mainThread->GetFocusLeashWindowId(), INVALID_NODEID);
976 }
977
978 /**
979 * @tc.name: SetFocusLeashWindowId004
980 * @tc.desc: Test SetFocusLeashWindowId while focus node's type don't match
981 * @tc.type: FUNC
982 * @tc.require: issueI98VTC
983 */
984 HWTEST_F(RSMainThreadTest, SetFocusLeashWindowId004, TestSize.Level2)
985 {
986 auto mainThread = RSMainThread::Instance();
987 auto childNode = RSTestUtil::CreateSurfaceNode();
988 auto parentNode = RSTestUtil::CreateSurfaceNode();
989 ASSERT_NE(mainThread, nullptr);
990 ASSERT_NE(childNode, nullptr);
991 ASSERT_NE(parentNode, nullptr);
992
993 parentNode->AddChild(parentNode);
994 childNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
995 parentNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
996
997 mainThread->context_->nodeMap.renderNodeMap_[childNode->GetId()] = childNode;
998 mainThread->context_->nodeMap.renderNodeMap_[parentNode->GetId()] = parentNode;
999 std::string str = "";
1000 mainThread->SetFocusAppInfo(-1, -1, str, str, childNode->GetId());
1001 mainThread->SetFocusLeashWindowId();
1002 ASSERT_EQ(mainThread->GetFocusLeashWindowId(), INVALID_NODEID);
1003 }
1004
1005 /**
1006 * @tc.name: SetFocusLeashWindowId005
1007 * @tc.desc: Test SetFocusLeashWindowId while focus node's parent's type don't match
1008 * @tc.type: FUNC
1009 * @tc.require: issueI98VTC
1010 */
1011 HWTEST_F(RSMainThreadTest, SetFocusLeashWindowId005, TestSize.Level2)
1012 {
1013 auto mainThread = RSMainThread::Instance();
1014 auto childNode = RSTestUtil::CreateSurfaceNode();
1015 auto parentNode = RSTestUtil::CreateSurfaceNode();
1016 ASSERT_NE(mainThread, nullptr);
1017 ASSERT_NE(childNode, nullptr);
1018 ASSERT_NE(parentNode, nullptr);
1019
1020 parentNode->AddChild(parentNode);
1021 childNode->SetSurfaceNodeType(RSSurfaceNodeType::APP_WINDOW_NODE);
1022 parentNode->SetSurfaceNodeType(RSSurfaceNodeType::APP_WINDOW_NODE);
1023
1024 mainThread->context_->nodeMap.renderNodeMap_[childNode->GetId()] = childNode;
1025 mainThread->context_->nodeMap.renderNodeMap_[parentNode->GetId()] = parentNode;
1026 std::string str = "";
1027 mainThread->SetFocusAppInfo(-1, -1, str, str, childNode->GetId());
1028 mainThread->SetFocusLeashWindowId();
1029 ASSERT_EQ(mainThread->GetFocusLeashWindowId(), INVALID_NODEID);
1030 }
1031
1032 /**
1033 * @tc.name: SetIsCachedSurfaceUpdated
1034 * @tc.desc: Test RSMainThreadTest.SetIsCachedSurfaceUpdated
1035 * @tc.type: FUNC
1036 * @tc.require: issueI8V6MD
1037 */
1038 HWTEST_F(RSMainThreadTest, SetIsCachedSurfaceUpdated, TestSize.Level1)
1039 {
1040 auto mainThread = RSMainThread::Instance();
1041 ASSERT_NE(mainThread, nullptr);
1042 mainThread->SetIsCachedSurfaceUpdated(true);
1043 }
1044
1045 /**
1046 * @tc.name: PrintCurrentStatus
1047 * @tc.desc: Test RSMainThreadTest.PrintCurrentStatus
1048 * @tc.type: FUNC
1049 * @tc.require: issueI8V6MD
1050 */
1051 HWTEST_F(RSMainThreadTest, PrintCurrentStatus, TestSize.Level1)
1052 {
1053 auto mainThread = RSMainThread::Instance();
1054 ASSERT_NE(mainThread, nullptr);
1055 mainThread->PrintCurrentStatus();
1056 }
1057
1058 /**
1059 * @tc.name: SetDeviceType
1060 * @tc.desc: Test RSMainThreadTest.SetDeviceType
1061 * @tc.type: FUNC
1062 * @tc.require: issueI8V6MD
1063 */
1064 HWTEST_F(RSMainThreadTest, SetDeviceType, TestSize.Level1)
1065 {
1066 auto mainThread = RSMainThread::Instance();
1067 ASSERT_NE(mainThread, nullptr);
1068 system::SetParameter("const.product.devicetype", "pc");
1069 mainThread->SetDeviceType();
1070 system::SetParameter("const.product.devicetype", "tablet");
1071 mainThread->SetDeviceType();
1072 system::SetParameter("const.product.devicetype", "others");
1073 mainThread->SetDeviceType();
1074 system::SetParameter("const.product.devicetype", "phone");
1075 mainThread->SetDeviceType();
1076 }
1077
1078 /**
1079 * @tc.name: CacheCommands
1080 * @tc.desc: Test RSMainThreadTest.CacheCommands
1081 * @tc.type: FUNC
1082 * @tc.require: issueI8V6MD
1083 */
1084 HWTEST_F(RSMainThreadTest, CacheCommands, TestSize.Level1)
1085 {
1086 auto mainThread = RSMainThread::Instance();
1087 ASSERT_NE(mainThread, nullptr);
1088 auto data = std::make_unique<RSTransactionData>();
1089 ASSERT_NE(data, nullptr);
1090 data->SetIndex(1);
1091 mainThread->cachedSkipTransactionDataMap_[0].emplace_back(std::move(data));
1092 data = std::make_unique<RSTransactionData>();
1093 ASSERT_NE(data, nullptr);
1094 data->SetIndex(2);
1095 mainThread->cachedSkipTransactionDataMap_[0].emplace_back(std::move(data));
1096 mainThread->CacheCommands();
1097 }
1098
1099 /**
1100 * @tc.name: CheckIfNodeIsBundle
1101 * @tc.desc: Test RSMainThreadTest.CheckIfNodeIsBundle
1102 * @tc.type: FUNC
1103 * @tc.require: issueI8V6MD
1104 */
1105 HWTEST_F(RSMainThreadTest, CheckIfNodeIsBundle, TestSize.Level1)
1106 {
1107 auto mainThread = RSMainThread::Instance();
1108 ASSERT_NE(mainThread, nullptr);
1109 RSSurfaceRenderNodeConfig config;
1110 auto node = std::make_shared<RSSurfaceRenderNode>(config);
1111 node->name_ = "WallpaperView";
1112 mainThread->CheckIfNodeIsBundle(node);
1113 ASSERT_TRUE(mainThread->noBundle_);
1114 }
1115
1116 /**
1117 * @tc.name: InformHgmNodeInfo
1118 * @tc.desc: Test RSMainThreadTest.InformHgmNodeInfo
1119 * @tc.type: FUNC
1120 * @tc.require: issueI8V6MD
1121 */
1122 HWTEST_F(RSMainThreadTest, InformHgmNodeInfo, TestSize.Level1)
1123 {
1124 auto mainThread = RSMainThread::Instance();
1125 ASSERT_NE(mainThread, nullptr);
1126 mainThread->currentBundleName_ = "test";
1127 mainThread->InformHgmNodeInfo();
1128 mainThread->currentBundleName_ = "";
1129 mainThread->noBundle_ = true;
1130 mainThread->InformHgmNodeInfo();
1131 }
1132
1133 /**
1134 * @tc.name: CheckParallelSubThreadNodesStatus
1135 * @tc.desc: Test RSMainThreadTest.CheckParallelSubThreadNodesStatus
1136 * @tc.type: FUNC
1137 * @tc.require: issueI8V6MD
1138 */
1139 HWTEST_F(RSMainThreadTest, CheckParallelSubThreadNodesStatus, TestSize.Level1)
1140 {
1141 auto mainThread = RSMainThread::Instance();
1142 ASSERT_NE(mainThread, nullptr);
1143 mainThread->subThreadNodes_.clear();
1144 mainThread->subThreadNodes_.push_back(nullptr);
1145 mainThread->isUiFirstOn_ = false;
1146 mainThread->CheckParallelSubThreadNodesStatus();
1147
1148 auto node1 = std::make_shared<RSSurfaceRenderNode>(0xFFFFFFFFFFFFFFFF);
1149 node1->cacheProcessStatus_ = CacheProcessStatus::DOING;
1150 node1->name_ = "node1";
1151 node1->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1152 node1->hasAbilityComponent_ = true;
1153 node1->abilityNodeIds_.emplace(10);
1154 node1->abilityNodeIds_.emplace(11);
1155 auto node2 = std::make_shared<RSSurfaceRenderNode>(2);
1156 node2->cacheProcessStatus_ = CacheProcessStatus::DOING;
1157 node2->name_ = "node2";
1158 node2->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
1159 auto node3 = std::make_shared<RSSurfaceRenderNode>(0xFFFFFFFFFFFFFFF0);
1160 node3->cacheProcessStatus_ = CacheProcessStatus::DOING;
1161 node3->name_ = "node3";
1162 node3->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1163 node3->hasAbilityComponent_ = false;
1164 // create child nodes
1165 auto childNode1 = std::make_shared<RSSurfaceRenderNode>(3);
1166 childNode1->name_ = "childNode1";
1167 childNode1->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1168 auto childNode2 = std::make_shared<RSSurfaceRenderNode>(4);
1169 childNode2->name_ = "childNode2";
1170 childNode2->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1171 auto childNode3 = std::make_shared<RSSurfaceRenderNode>(5);
1172 childNode3->name_ = "childNode3";
1173
1174 node2->AddChild(childNode1);
1175 node2->AddChild(childNode2);
1176 node2->AddChild(childNode3);
1177 mainThread->subThreadNodes_.push_back(node1);
1178 mainThread->subThreadNodes_.push_back(node2);
1179 mainThread->subThreadNodes_.push_back(node3);
1180
1181 mainThread->cacheCmdSkippedInfo_.clear();
1182 mainThread->CheckParallelSubThreadNodesStatus();
1183 }
1184
1185 /**
1186 * @tc.name: IsNeedSkip
1187 * @tc.desc: IsNeedSkip test
1188 * @tc.type: FUNC
1189 * @tc.require: issueI7HDVG
1190 */
1191 HWTEST_F(RSMainThreadTest, IsNeedSkip, TestSize.Level1)
1192 {
1193 auto mainThread = RSMainThread::Instance();
1194 ASSERT_NE(mainThread, nullptr);
1195 mainThread->IsNeedSkip(0, 0);
1196 }
1197
1198 /**
1199 * @tc.name: SkipCommandByNodeId001
1200 * @tc.desc: SkipCommandByNodeId test
1201 * @tc.type: FUNC
1202 * @tc.require: issueI7HDVG
1203 */
1204 HWTEST_F(RSMainThreadTest, SkipCommandByNodeId001, TestSize.Level1)
1205 {
1206 auto mainThread = RSMainThread::Instance();
1207 ASSERT_NE(mainThread, nullptr);
1208 std::vector<std::unique_ptr<RSTransactionData>> transactionVec;
1209 mainThread->SkipCommandByNodeId(transactionVec, -1);
1210 }
1211
1212 /**
1213 * @tc.name: SkipCommandByNodeId002
1214 * @tc.desc: SkipCommandByNodeId test
1215 * @tc.type: FUNC
1216 * @tc.require: issueI7HDVG
1217 */
1218 HWTEST_F(RSMainThreadTest, SkipCommandByNodeId002, TestSize.Level1)
1219 {
1220 auto mainThread = RSMainThread::Instance();
1221 ASSERT_NE(mainThread, nullptr);
1222 // prepare transactionVec
1223 std::vector<std::unique_ptr<RSTransactionData>> transactionVec;
1224 auto data = std::make_unique<RSTransactionData>();
1225 data->SetIndex(1);
1226 transactionVec.emplace_back(std::move(data));
1227 data = std::make_unique<RSTransactionData>();
1228 data->SetIndex(2);
1229 data->payload_.resize(2);
1230 data->payload_[0] = std::tuple<NodeId, FollowType, std::unique_ptr<RSCommand>>(0, FollowType::NONE, nullptr);
1231 transactionVec.emplace_back(std::move(data));
1232 std::pair<std::vector<NodeId>, bool> info = {{0}, true};
1233 mainThread->cacheCmdSkippedInfo_.insert({0, info});
1234 mainThread->SkipCommandByNodeId(transactionVec, 0);
1235 }
1236
1237 /**
1238 * @tc.name: ConsumeAndUpdateAllNodes001
1239 * @tc.desc: ConsumeAndUpdateAllNodes test
1240 * @tc.type: FUNC
1241 * @tc.require: issueI7HDVG
1242 */
1243 HWTEST_F(RSMainThreadTest, ConsumeAndUpdateAllNodes001, TestSize.Level1)
1244 {
1245 auto mainThread = RSMainThread::Instance();
1246 ASSERT_NE(mainThread, nullptr);
1247 bool isUniRender = mainThread->isUniRender_;
1248 mainThread->isUniRender_ = false;
1249 mainThread->ConsumeAndUpdateAllNodes();
1250 mainThread->isUniRender_ = isUniRender;
1251 }
1252
1253 /**
1254 * @tc.name: ConsumeAndUpdateAllNodes002
1255 * @tc.desc: ConsumeAndUpdateAllNodes test
1256 * @tc.type: FUNC
1257 * @tc.require: issueI7HDVG
1258 */
1259 HWTEST_F(RSMainThreadTest, ConsumeAndUpdateAllNodes002, TestSize.Level1)
1260 {
1261 auto mainThread = RSMainThread::Instance();
1262 ASSERT_NE(mainThread, nullptr);
1263 bool isUniRender = mainThread->isUniRender_;
1264 mainThread->isUniRender_ = false;
1265 mainThread->ConsumeAndUpdateAllNodes();
1266 mainThread->isUniRender_ = isUniRender;
1267 }
1268
1269 /**
1270 * @tc.name: CheckSubThreadNodeStatusIsDoing001
1271 * @tc.desc: CheckSubThreadNodeStatusIsDoing test
1272 * @tc.type: FUNC
1273 * @tc.require: issueI7HDVG
1274 */
1275 HWTEST_F(RSMainThreadTest, CheckSubThreadNodeStatusIsDoing001, TestSize.Level1)
1276 {
1277 auto mainThread = RSMainThread::Instance();
1278 ASSERT_NE(mainThread, nullptr);
1279 mainThread->subThreadNodes_.clear();
1280 auto rsSurfaceRenderNode1 = RSTestUtil::CreateSurfaceNode();
1281 rsSurfaceRenderNode1->SetCacheSurfaceProcessedStatus(CacheProcessStatus::WAITING);
1282 auto rsSurfaceRenderNode2 = RSTestUtil::CreateSurfaceNode();
1283 rsSurfaceRenderNode2->SetCacheSurfaceProcessedStatus(CacheProcessStatus::DOING);
1284 mainThread->subThreadNodes_.emplace_back(rsSurfaceRenderNode1);
1285 mainThread->subThreadNodes_.emplace_back(rsSurfaceRenderNode2);
1286 mainThread->CheckSubThreadNodeStatusIsDoing(rsSurfaceRenderNode2->GetId());
1287 }
1288
1289 /**
1290 * @tc.name: CheckSubThreadNodeStatusIsDoing002
1291 * @tc.desc: CheckSubThreadNodeStatusIsDoing test
1292 * @tc.type: FUNC
1293 * @tc.require: issueI7HDVG
1294 */
1295 HWTEST_F(RSMainThreadTest, CheckSubThreadNodeStatusIsDoing002, TestSize.Level1)
1296 {
1297 auto mainThread = RSMainThread::Instance();
1298 ASSERT_NE(mainThread, nullptr);
1299 mainThread->subThreadNodes_.clear();
1300 auto rsSurfaceRenderNode1 = RSTestUtil::CreateSurfaceNode();
1301 rsSurfaceRenderNode1->SetCacheSurfaceProcessedStatus(CacheProcessStatus::DOING);
1302 auto rsSurfaceRenderNode2 = RSTestUtil::CreateSurfaceNode();
1303 rsSurfaceRenderNode1->AddChild(rsSurfaceRenderNode2);
1304 mainThread->subThreadNodes_.emplace_back(rsSurfaceRenderNode1);
1305 mainThread->CheckSubThreadNodeStatusIsDoing(rsSurfaceRenderNode2->GetId());
1306 }
1307
1308 /**
1309 * @tc.name: CollectInfoForHardwareComposer001
1310 * @tc.desc: CheckSubThreadNodeStatusIsDoing test
1311 * @tc.type: FUNC
1312 * @tc.require: issueI7HDVG
1313 */
1314 HWTEST_F(RSMainThreadTest, CollectInfoForHardwareComposer001, TestSize.Level1)
1315 {
1316 auto mainThread = RSMainThread::Instance();
1317 ASSERT_NE(mainThread, nullptr);
1318 bool isUniRender = mainThread->isUniRender_;
1319 mainThread->isUniRender_ = false;
1320 mainThread->CollectInfoForHardwareComposer();
1321 mainThread->isUniRender_ = isUniRender;
1322 }
1323
1324 /**
1325 * @tc.name: CollectInfoForHardwareComposer002
1326 * @tc.desc: CheckSubThreadNodeStatusIsDoing test
1327 * @tc.type: FUNC
1328 * @tc.require: issueI7HDVG
1329 */
1330 HWTEST_F(RSMainThreadTest, CollectInfoForHardwareComposer002, TestSize.Level1)
1331 {
1332 auto mainThread = RSMainThread::Instance();
1333 ASSERT_NE(mainThread, nullptr);
1334 bool isUniRender = mainThread->isUniRender_;
1335 mainThread->isUniRender_ = true;
1336 mainThread->CollectInfoForHardwareComposer();
1337 mainThread->isUniRender_ = isUniRender;
1338 }
1339
1340 /**
1341 * @tc.name: IsLastFrameUIFirstEnbaled001
1342 * @tc.desc: IsLastFrameUIFirstEnbaled test
1343 * @tc.type: FUNC
1344 * @tc.require: issueI7HDVG
1345 */
1346 HWTEST_F(RSMainThreadTest, IsLastFrameUIFirstEnbaled001, TestSize.Level1)
1347 {
1348 auto mainThread = RSMainThread::Instance();
1349 ASSERT_NE(mainThread, nullptr);
1350 mainThread->subThreadNodes_.clear();
1351 // not app window
1352 NodeId id = 1;
1353 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
1354 node->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
1355 mainThread->subThreadNodes_.push_back(node);
1356 mainThread->IsLastFrameUIFirstEnabled(0);
1357 // app window
1358 id = 2;
1359 node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
1360 node->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1361 mainThread->subThreadNodes_.push_back(node);
1362 mainThread->IsLastFrameUIFirstEnabled(2);
1363 }
1364
1365
1366 /**
1367 * @tc.name: IsLastFrameUIFirstEnbaled002
1368 * @tc.desc: IsLastFrameUIFirstEnbaled test
1369 * @tc.type: FUNC
1370 * @tc.require: issueI7HDVG
1371 */
1372 HWTEST_F(RSMainThreadTest, IsLastFrameUIFirstEnbaled002, TestSize.Level1)
1373 {
1374 auto mainThread = RSMainThread::Instance();
1375 ASSERT_NE(mainThread, nullptr);
1376 mainThread->subThreadNodes_.clear();
1377 // parent
1378 NodeId id = 1;
1379 auto node1 = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
1380 node1->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
1381 // child
1382 id = 2;
1383 auto node2 = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
1384 node2->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1385 node1->AddChild(node2);
1386 mainThread->subThreadNodes_.push_back(node1);
1387 mainThread->IsLastFrameUIFirstEnabled(2);
1388 }
1389
1390 /**
1391 * @tc.name: CheckIfHardwareForcedDisabled
1392 * @tc.desc: CheckIfHardwareForcedDisabled test
1393 * @tc.type: FUNC
1394 * @tc.require: issueI7HDVG
1395 */
1396 HWTEST_F(RSMainThreadTest, CheckIfHardwareForcedDisabled, TestSize.Level1)
1397 {
1398 auto mainThread = RSMainThread::Instance();
1399 ASSERT_NE(mainThread, nullptr);
1400 mainThread->CheckIfHardwareForcedDisabled();
1401 }
1402
1403 /**
1404 * @tc.name: WaitUntilUnmarshallingTaskFinished001
1405 * @tc.desc: WaitUntilUnmarshallingTaskFinished test
1406 * @tc.type: FUNC
1407 * @tc.require: issueI7HDVG
1408 */
1409 HWTEST_F(RSMainThreadTest, WaitUntilUnmarshallingTaskFinished001, TestSize.Level1)
1410 {
1411 auto mainThread = RSMainThread::Instance();
1412 bool isUniRender = mainThread->isUniRender_;
1413 mainThread->isUniRender_ = false;
1414 mainThread->WaitUntilUnmarshallingTaskFinished();
1415 mainThread->isUniRender_ = isUniRender;
1416 }
1417
1418 /**
1419 * @tc.name: MergeToEffectiveTransactionDataMap
1420 * @tc.desc: MergeToEffectiveTransactionDataMap test
1421 * @tc.type: FUNC
1422 * @tc.require: issueI7HDVG
1423 */
1424 HWTEST_F(RSMainThreadTest, MergeToEffectiveTransactionDataMap, TestSize.Level1)
1425 {
1426 auto mainThread = RSMainThread::Instance();
1427 TransactionDataMap tsDataMap;
1428 tsDataMap.emplace(0, std::vector<std::unique_ptr<RSTransactionData>>());
1429 auto data = std::make_unique<RSTransactionData>();
1430 data->SetIndex(1);
1431 tsDataMap[0].emplace_back(std::move(data));
1432 mainThread->MergeToEffectiveTransactionDataMap(tsDataMap);
1433 }
1434
1435 /**
1436 * @tc.name: UniRender001
1437 * @tc.desc: UniRender test
1438 * @tc.type: FUNC
1439 * @tc.require: issueI7HDVG
1440 */
1441 HWTEST_F(RSMainThreadTest, UniRender001, TestSize.Level1)
1442 {
1443 auto mainThread = RSMainThread::Instance();
1444 ASSERT_NE(mainThread, nullptr);
1445 auto& uniRenderThread = RSUniRenderThread::Instance();
1446 uniRenderThread.uniRenderEngine_ = std::make_shared<RSUniRenderEngine>();
1447 mainThread->renderThreadParams_ = std::make_unique<RSRenderThreadParams>();
1448 // prepare nodes
1449 std::shared_ptr<RSContext> context = std::make_shared<RSContext>();
1450 const std::shared_ptr<RSBaseRenderNode> rootNode = context->GetGlobalRootRenderNode();
1451 NodeId id = 1;
1452 RSDisplayNodeConfig config;
1453 auto childDisplayNode = std::make_shared<RSDisplayRenderNode>(id, config);
1454 rootNode->AddChild(childDisplayNode, 0);
1455 rootNode->InitRenderParams();
1456 childDisplayNode->InitRenderParams();
1457 mainThread->UniRender(rootNode);
1458 }
1459
1460 /**
1461 * @tc.name: UniRender002
1462 * @tc.desc: UniRender test
1463 * @tc.type: FUNC
1464 * @tc.require: issueI7HDVG
1465 */
1466 HWTEST_F(RSMainThreadTest, UniRender002, TestSize.Level1)
1467 {
1468 auto mainThread = RSMainThread::Instance();
1469 ASSERT_NE(mainThread, nullptr);
1470 auto& uniRenderThread = RSUniRenderThread::Instance();
1471 uniRenderThread.uniRenderEngine_ = std::make_shared<RSUniRenderEngine>();
1472 mainThread->renderThreadParams_ = std::make_unique<RSRenderThreadParams>();
1473 // prepare nodes
1474 std::shared_ptr<RSContext> context = std::make_shared<RSContext>();
1475 const std::shared_ptr<RSBaseRenderNode> rootNode = context->GetGlobalRootRenderNode();
1476 NodeId id = 1;
1477 RSDisplayNodeConfig config;
1478 auto childDisplayNode = std::make_shared<RSDisplayRenderNode>(id, config);
1479 rootNode->AddChild(childDisplayNode, 0);
1480 // prepare status
1481 bool doDirectComposition = mainThread->doDirectComposition_;
1482 bool isDirty = mainThread->isDirty_;
1483 bool isAccessibilityConfigChanged = mainThread->isAccessibilityConfigChanged_;
1484 bool isCachedSurfaceUpdated = mainThread->isCachedSurfaceUpdated_;
1485 bool isHardwareEnabledBufferUpdated = mainThread->isHardwareEnabledBufferUpdated_;
1486 mainThread->doDirectComposition_ = true;
1487 mainThread->isDirty_ = false;
1488 mainThread->isAccessibilityConfigChanged_ = false;
1489 mainThread->isCachedSurfaceUpdated_ = false;
1490 mainThread->isHardwareEnabledBufferUpdated_ = true;
1491 rootNode->InitRenderParams();
1492 childDisplayNode->InitRenderParams();
1493 mainThread->UniRender(rootNode);
1494 // status recover
1495 mainThread->doDirectComposition_ = doDirectComposition;
1496 mainThread->isDirty_ = isDirty;
1497 mainThread->isAccessibilityConfigChanged_ = isAccessibilityConfigChanged;
1498 mainThread->isCachedSurfaceUpdated_ = isCachedSurfaceUpdated;
1499 mainThread->isHardwareEnabledBufferUpdated_ = isHardwareEnabledBufferUpdated;
1500 }
1501
1502 /**
1503 * @tc.name: IsFirstFrameOfOverdrawSwitch
1504 * @tc.desc: test IsFirstFrameOfOverdrawSwitch
1505 * @tc.type: FUNC
1506 * @tc.require: issueIAKQC3
1507 */
1508 HWTEST_F(RSMainThreadTest, IsFirstFrameOfOverdrawSwitch, TestSize.Level1)
1509 {
1510 auto mainThread = RSMainThread::Instance();
1511 ASSERT_NE(mainThread, nullptr);
1512 mainThread->isOverDrawEnabledOfCurFrame_ = true;
1513 ASSERT_TRUE(mainThread->IsFirstFrameOfOverdrawSwitch());
1514 }
1515
1516 /**
1517 * @tc.name: Render
1518 * @tc.desc: Render test
1519 * @tc.type: FUNC
1520 * @tc.require: issueI7HDVG
1521 */
1522 HWTEST_F(RSMainThreadTest, Render, TestSize.Level1)
1523 {
1524 auto mainThread = RSMainThread::Instance();
1525 ASSERT_NE(mainThread, nullptr);
1526 auto& uniRenderThread = RSUniRenderThread::Instance();
1527 uniRenderThread.uniRenderEngine_ = std::make_shared<RSUniRenderEngine>();
1528 mainThread->renderThreadParams_ = std::make_unique<RSRenderThreadParams>();
1529 const std::shared_ptr<RSBaseRenderNode> rootNode = mainThread->context_->globalRootRenderNode_;
1530 NodeId id = 1;
1531 RSDisplayNodeConfig config;
1532 auto childDisplayNode = std::make_shared<RSDisplayRenderNode>(id, config);
1533 rootNode->AddChild(childDisplayNode);
1534 bool isUniRender = mainThread->isUniRender_;
1535 mainThread->runner_ = AppExecFwk::EventRunner::Create(false);
1536 mainThread->handler_ = std::make_shared<AppExecFwk::EventHandler>(mainThread->runner_);
1537 // uni render
1538 mainThread->isUniRender_ = true;
1539 rootNode->InitRenderParams();
1540 childDisplayNode->InitRenderParams();
1541 mainThread->Render();
1542 mainThread->runner_ = nullptr;
1543 mainThread->handler_ = nullptr;
1544 mainThread->isUniRender_ = isUniRender;
1545 }
1546
1547 /**
1548 * @tc.name: CallbackDrawContextStatusToWMS
1549 * @tc.desc: CallbackDrawContextStatusToWMS test
1550 * @tc.type: FUNC
1551 * @tc.require: issueI7HDVG
1552 */
1553 HWTEST_F(RSMainThreadTest, CallbackDrawContextStatusToWMS, TestSize.Level1)
1554 {
1555 auto mainThread = RSMainThread::Instance();
1556 ASSERT_NE(mainThread, nullptr);
1557 mainThread->curDrawStatusVec_.push_back(0);
1558 mainThread->curDrawStatusVec_.push_back(1);
1559 mainThread->lastDrawStatusMap_.insert({1, 0});
1560 mainThread->occlusionListeners_.insert({0, nullptr});
1561 mainThread->CallbackDrawContextStatusToWMS();
1562 mainThread->curDrawStatusVec_.clear();
1563 mainThread->lastDrawStatusMap_.clear();
1564 mainThread->occlusionListeners_.clear();
1565 }
1566
1567 /**
1568 * @tc.name: CheckSurfaceNeedProcess
1569 * @tc.desc: CheckSurfaceNeedProcess test
1570 * @tc.type: FUNC
1571 * @tc.require: issueI7HDVG
1572 */
1573 HWTEST_F(RSMainThreadTest, CheckSurfaceNeedProcess, TestSize.Level1)
1574 {
1575 auto mainThread = RSMainThread::Instance();
1576 ASSERT_NE(mainThread, nullptr);
1577 OcclusionRectISet occRectISet;
1578 // not focus node
1579 NodeId id = 1;
1580 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
1581 mainThread->CheckSurfaceNeedProcess(occRectISet, node);
1582 // focus node
1583 id = mainThread->focusNodeId_;
1584 node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
1585 mainThread->CheckSurfaceNeedProcess(occRectISet, node);
1586 }
1587
1588 /**
1589 * @tc.name: GetRegionVisibleLevel001
1590 * @tc.desc: GetRegionVisibleLevel test
1591 * @tc.type: FUNC
1592 * @tc.require: issueI7HDVG
1593 */
1594 HWTEST_F(RSMainThreadTest, GetRegionVisibleLevel001, TestSize.Level1)
1595 {
1596 auto mainThread = RSMainThread::Instance();
1597 ASSERT_NE(mainThread, nullptr);
1598 // empty region
1599 Occlusion::Region occRegion;
1600 mainThread->GetRegionVisibleLevel(occRegion, occRegion);
1601 }
1602
1603 /**
1604 * @tc.name: GetRegionVisibleLevel002
1605 * @tc.desc: GetRegionVisibleLevel test
1606 * @tc.type: FUNC
1607 * @tc.require: issueI7HDVG
1608 */
1609 HWTEST_F(RSMainThreadTest, GetRegionVisibleLevel002, TestSize.Level1)
1610 {
1611 auto mainThread = RSMainThread::Instance();
1612 ASSERT_NE(mainThread, nullptr);
1613 // equal region
1614 Occlusion::Region occRegion;
1615 occRegion.rects_.emplace_back(Occlusion::Rect(0, 1, 1, 0));
1616 mainThread->GetRegionVisibleLevel(occRegion, occRegion);
1617 }
1618
1619 /**
1620 * @tc.name: GetRegionVisibleLevel003
1621 * @tc.desc: GetRegionVisibleLevel test
1622 * @tc.type: FUNC
1623 * @tc.require: issueI7HDVG
1624 */
1625 HWTEST_F(RSMainThreadTest, GetRegionVisibleLevel003, TestSize.Level1)
1626 {
1627 auto mainThread = RSMainThread::Instance();
1628 ASSERT_NE(mainThread, nullptr);
1629 Occlusion::Region occRegion1;
1630 occRegion1.rects_.emplace_back(Occlusion::Rect(0, 1, 1, 0));
1631 Occlusion::Region occRegion2;
1632 occRegion2.rects_.emplace_back(Occlusion::Rect(0, 2, 2, 0));
1633 mainThread->GetRegionVisibleLevel(occRegion1, occRegion2);
1634 }
1635
1636 /**
1637 * @tc.name: CalcOcclusionImplementation
1638 * @tc.desc: CalcOcclusionImplementation test
1639 * @tc.type: FUNC
1640 * @tc.require: issueI7HDVG
1641 */
1642 HWTEST_F(RSMainThreadTest, CalcOcclusionImplementation, TestSize.Level1)
1643 {
1644 auto mainThread = RSMainThread::Instance();
1645 ASSERT_NE(mainThread, nullptr);
1646 RSDisplayNodeConfig config;
1647 NodeId displayNodeId = 0;
1648 auto displayNode = std::make_shared<RSDisplayRenderNode>(displayNodeId, config, mainThread->context_);
1649
1650 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
1651 NodeId surfaceNodeId = 0;
1652 auto surfaceNode = std::make_shared<RSSurfaceRenderNode>(surfaceNodeId, mainThread->context_);
1653 curAllSurfaces.emplace_back(nullptr);
1654 curAllSurfaces.emplace_back(surfaceNode);
1655 VisibleData dstCurVisVec;
1656 std::map<NodeId, RSVisibleLevel> dstPidVisMap;
1657 mainThread->CalcOcclusionImplementation(displayNode, curAllSurfaces, dstCurVisVec, dstPidVisMap);
1658 }
1659
1660 /**
1661 * @tc.name: CallbackToWMS001
1662 * @tc.desc: CallbackToWMS test visible not changed
1663 * @tc.type: FUNC
1664 * @tc.require: issueI7HDVG
1665 */
1666 HWTEST_F(RSMainThreadTest, CallbackToWMS001, TestSize.Level1)
1667 {
1668 auto mainThread = RSMainThread::Instance();
1669 ASSERT_NE(mainThread, nullptr);
1670 VisibleData curVisVec;
1671 curVisVec.push_back({0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE});
1672 mainThread->lastVisVec_ = curVisVec;
1673 mainThread->CallbackToWMS(curVisVec);
1674 mainThread->lastVisVec_.clear();
1675 }
1676
1677 /**
1678 * @tc.name: CallbackToWMS002
1679 * @tc.desc: CallbackToWMS test visible changed
1680 * @tc.type: FUNC
1681 * @tc.require: issueI7HDVG
1682 */
1683 HWTEST_F(RSMainThreadTest, CallbackToWMS002, TestSize.Level1)
1684 {
1685 auto mainThread = RSMainThread::Instance();
1686 ASSERT_NE(mainThread, nullptr);
1687 VisibleData curVisVec;
1688 curVisVec.push_back({0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE});
1689 curVisVec.push_back({1, WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE});
1690 mainThread->lastVisVec_.push_back({0, WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE});
1691 mainThread->lastVisVec_.push_back({1, WINDOW_LAYER_INFO_TYPE::INVISIBLE});
1692 mainThread->occlusionListeners_.insert({0, nullptr});
1693 mainThread->CallbackToWMS(curVisVec);
1694 mainThread->occlusionListeners_.clear();
1695 mainThread->lastVisVec_.clear();
1696 }
1697
1698 /**
1699 * @tc.name: SurfaceOcclusionCallback001
1700 * @tc.desc: SurfaceOcclusionCallback with empty nodemap
1701 * @tc.type: FUNC
1702 * @tc.require: issueI7HDVG
1703 */
1704 HWTEST_F(RSMainThreadTest, SurfaceOcclusionCallback001, TestSize.Level1)
1705 {
1706 auto mainThread = RSMainThread::Instance();
1707 ASSERT_NE(mainThread, nullptr);
1708 // prepare listeners
1709 std::tuple<pid_t, sptr<RSISurfaceOcclusionChangeCallback>,
1710 std::vector<float>, uint8_t> info(0, nullptr, {}, 0);
1711 mainThread->surfaceOcclusionListeners_.insert({0, info});
1712 // run
1713 mainThread->SurfaceOcclusionCallback();
1714 mainThread->surfaceOcclusionListeners_.clear();
1715 }
1716
1717 /**
1718 * @tc.name: SurfaceOcclusionCallback002
1719 * @tc.desc: SurfaceOcclusionCallback with corresponding nodemap
1720 * @tc.type: FUNC
1721 * @tc.require: issueI7HDVG
1722 */
1723 HWTEST_F(RSMainThreadTest, SurfaceOcclusionCallback002, TestSize.Level1)
1724 {
1725 auto mainThread = RSMainThread::Instance();
1726 ASSERT_NE(mainThread, nullptr);
1727 // prepare listeners
1728 std::tuple<pid_t, sptr<RSISurfaceOcclusionChangeCallback>,
1729 std::vector<float>, uint8_t> info(0, nullptr, {}, 0);
1730 mainThread->surfaceOcclusionListeners_.insert({1, info});
1731 mainThread->surfaceOcclusionListeners_.insert({2, info});
1732 mainThread->surfaceOcclusionListeners_.insert({3, info});
1733 //prepare nodemap
1734 RSSurfaceRenderNodeConfig config;
1735 config.id = 1;
1736 auto node1 = std::make_shared<RSSurfaceRenderNode>(config);
1737 node1->SetIsOnTheTree(true);
1738 config.id = 2;
1739 auto node2 = std::make_shared<RSSurfaceRenderNode>(config);
1740 node2->SetIsOnTheTree(true);
1741 node2->instanceRootNodeId_ = INVALID_NODEID;
1742 config.id = 3;
1743 auto node3 = std::make_shared<RSSurfaceRenderNode>(config);
1744 node3->SetIsOnTheTree(true);
1745 node3->instanceRootNodeId_ = 1;
1746 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node1);
1747 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node2);
1748 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node3);
1749 // run
1750 mainThread->SurfaceOcclusionCallback();
1751 mainThread->surfaceOcclusionListeners_.clear();
1752 }
1753
1754 /**
1755 * @tc.name: CalcOcclusion002
1756 * @tc.desc: CalcOcclusion Test
1757 * @tc.type: FUNC
1758 * @tc.require: issueI7HDVG
1759 */
1760 HWTEST_F(RSMainThreadTest, CalcOcclusion002, TestSize.Level1)
1761 {
1762 auto mainThread = RSMainThread::Instance();
1763 ASSERT_NE(mainThread, nullptr);
1764 // prepare states
1765 bool doWindowAnimate = mainThread->doWindowAnimate_;
1766 mainThread->doWindowAnimate_ = false;
1767 auto globalRootRenderNode = mainThread->context_->globalRootRenderNode_;
1768 // run with nullptr
1769 mainThread->context_->globalRootRenderNode_ = nullptr;
1770 mainThread->CalcOcclusion();
1771 // run with one child node
1772 auto node1 = std::make_shared<RSRenderNode>(0, true);
1773 auto node2 = std::make_shared<RSRenderNode>(1, true);
1774 node1->AddChild(node2);
1775 mainThread->context_->globalRootRenderNode_ = node1;
1776 mainThread->CalcOcclusion();
1777 // run with more than one node
1778 auto node3 = std::make_shared<RSRenderNode>(0, true);
1779 RSDisplayNodeConfig config1;
1780 auto node4 = std::make_shared<RSDisplayRenderNode>(1, config1);
1781 RSSurfaceRenderNodeConfig config2;
1782 auto node5 = std::make_shared<RSSurfaceRenderNode>(config2);
1783 node3->AddChild(node4);
1784 node4->curAllSurfaces_.push_back(nullptr);
1785 node4->curAllSurfaces_.push_back(node5);
1786 mainThread->context_->globalRootRenderNode_ = node3;
1787 mainThread->CalcOcclusion();
1788 // recover
1789 mainThread->doWindowAnimate_ = doWindowAnimate;
1790 mainThread->context_->globalRootRenderNode_ = globalRootRenderNode;
1791 }
1792
1793 /**
1794 * @tc.name: Aniamte
1795 * @tc.desc: Aniamte Test
1796 * @tc.type: FUNC
1797 * @tc.require: issueI7HDVG
1798 */
1799 HWTEST_F(RSMainThreadTest, Aniamte, TestSize.Level1)
1800 {
1801 auto mainThread = RSMainThread::Instance();
1802 ASSERT_NE(mainThread, nullptr);
1803 NodeId id = 0;
1804 auto node = std::make_shared<RSRenderNode>(id);
1805 mainThread->context_->RegisterAnimatingRenderNode(node);
1806 mainThread->Animate(mainThread->timestamp_);
1807 }
1808
1809 /**
1810 * @tc.name: RecvRSTransactionData002
1811 * @tc.desc: RecvRSTransactionData002 Test
1812 * @tc.type: FUNC
1813 * @tc.require: issueI7HDVG
1814 */
1815 HWTEST_F(RSMainThreadTest, RecvRSTransactionData002, TestSize.Level1)
1816 {
1817 auto mainThread = RSMainThread::Instance();
1818 ASSERT_NE(mainThread, nullptr);
1819 bool isUniRender = mainThread->isUniRender_;
1820 auto transactionData1 = std::make_unique<RSTransactionData>();
1821 mainThread->isUniRender_ = true;
1822 mainThread->RecvRSTransactionData(transactionData1);
1823 auto transactionData2 = std::make_unique<RSTransactionData>();
1824 mainThread->isUniRender_ = false;
1825 mainThread->RecvRSTransactionData(transactionData2);
1826 mainThread->isUniRender_ = isUniRender;
1827 }
1828
1829 /**
1830 * @tc.name: ConsumeAndUpdateAllNodes003
1831 * @tc.desc: ConsumeAndUpdateAllNodes003 Test
1832 * @tc.type: FUNC
1833 * @tc.require: issueI7HDVG
1834 */
1835 HWTEST_F(RSMainThreadTest, ConsumeAndUpdateAllNodes003, TestSize.Level1)
1836 {
1837 auto mainThread = RSMainThread::Instance();
1838 ASSERT_NE(mainThread, nullptr);
1839 bool isUniRender = mainThread->isUniRender_;
1840 mainThread->isUniRender_ = true;
1841 // prepare nodemap
1842 mainThread->context_->GetMutableNodeMap().renderNodeMap_.clear();
1843 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.clear();
1844 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.emplace(1, nullptr);
1845 RSSurfaceRenderNodeConfig config;
1846 config.id = 2;
1847 auto node1 = std::make_shared<RSSurfaceRenderNode>(config);
1848 node1->nodeType_ = RSSurfaceNodeType::APP_WINDOW_NODE;
1849 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node1);
1850 config.id = 3;
1851 auto node2 = std::make_shared<RSSurfaceRenderNode>(config);
1852 node2->nodeType_ = RSSurfaceNodeType::LEASH_WINDOW_NODE;
1853 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node2);
1854 config.id = 4;
1855 auto node3 = std::make_shared<RSSurfaceRenderNode>(config);
1856 node3->nodeType_ = RSSurfaceNodeType::SELF_DRAWING_NODE;
1857 node3->isHardwareEnabledNode_ = true;
1858 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node3);
1859 mainThread->ConsumeAndUpdateAllNodes();
1860 mainThread->isUniRender_ = isUniRender;
1861 }
1862
1863 /**
1864 * @tc.name: ConsumeAndUpdateAllNodes004
1865 * @tc.desc: ConsumeAndUpdateAllNodes004 Test
1866 * @tc.type: FUNC
1867 * @tc.require: issueIANQPF
1868 */
1869 HWTEST_F(RSMainThreadTest, ConsumeAndUpdateAllNodes004, TestSize.Level1)
1870 {
1871 #ifndef ROSEN_CROSS_PLATFORM
1872 if (!RSSystemProperties::GetUniRenderEnabled()) {
1873 return;
1874 }
1875 auto mainThread = RSMainThread::Instance();
1876 ASSERT_NE(mainThread, nullptr);
1877 bool isUniRender = mainThread->isUniRender_;
1878 mainThread->isUniRender_ = true;
1879 mainThread->timestamp_ = 1000;
1880 // prepare nodemap
1881 mainThread->context_->GetMutableNodeMap().renderNodeMap_.clear();
1882 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.clear();
1883 auto rsSurfaceRenderNode = RSTestUtil::CreateSurfaceNode();
1884 rsSurfaceRenderNode->isHardwareEnabledNode_ = true;
1885 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(rsSurfaceRenderNode);
1886 auto rsSurfaceHandlerPtr_ = rsSurfaceRenderNode->GetRSSurfaceHandler();
1887 ASSERT_NE(rsSurfaceHandlerPtr_, nullptr);
1888 auto surfaceConsumer = rsSurfaceRenderNode->GetRSSurfaceHandler()->GetConsumer();
1889 ASSERT_NE(surfaceConsumer, nullptr);
1890 auto producer = surfaceConsumer->GetProducer();
1891 ASSERT_NE(producer, nullptr);
1892 sptr<Surface> psurf = Surface::CreateSurfaceAsProducer(producer);
1893 ASSERT_NE(psurf, nullptr);
1894 psurf->SetQueueSize(5);
1895 sptr<SurfaceBuffer> buffer;
1896 sptr<SyncFence> requestFence = SyncFence::INVALID_FENCE;
1897 GSError ret = psurf->RequestBuffer(buffer, requestFence, requestConfig);
1898 ASSERT_EQ(ret, GSERROR_OK);
1899 sptr<SyncFence> flushFence = SyncFence::INVALID_FENCE;
1900 ret = psurf->FlushBuffer(buffer, flushFence, flushConfig);
1901 ASSERT_EQ(ret, GSERROR_OK);
1902 RSSurfaceHandler::SurfaceBufferEntry bufferEntry;
1903 bufferEntry.timestamp = 0;
1904 ret = psurf->RequestBuffer(bufferEntry.buffer, requestFence, requestConfig);
1905 ASSERT_EQ(ret, GSERROR_OK);
1906 rsSurfaceHandlerPtr_->SetBufferTransformTypeChanged(true);
1907 ASSERT_TRUE(rsSurfaceHandlerPtr_->GetBufferTransformTypeChanged());
1908 mainThread->ConsumeAndUpdateAllNodes();
1909 mainThread->isUniRender_ = isUniRender;
1910 #endif
1911 }
1912
1913 /**
1914 * @tc.name: CollectInfoForHardwareComposer003
1915 * @tc.desc: CollectInfoForHardwareComposer003 Test
1916 * @tc.type: FUNC
1917 * @tc.require: issueI7HDVG
1918 */
1919 HWTEST_F(RSMainThreadTest, CollectInfoForHardwareComposer003, TestSize.Level1)
1920 {
1921 auto mainThread = RSMainThread::Instance();
1922 ASSERT_NE(mainThread, nullptr);
1923 bool isUniRender = mainThread->isUniRender_;
1924 mainThread->isUniRender_ = true;
1925 // prepare nodemap
1926 mainThread->context_->GetMutableNodeMap().renderNodeMap_.clear();
1927 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.clear();
1928 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.emplace(1, nullptr);
1929 RSSurfaceRenderNodeConfig config;
1930 config.id = 2;
1931 auto node2 = std::make_shared<RSSurfaceRenderNode>(config);
1932 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node2);
1933 config.id = 3;
1934 auto node3 = std::make_shared<RSSurfaceRenderNode>(config);
1935 node3->SetIsOnTheTree(true);
1936 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node3);
1937 auto node4 = RSTestUtil::CreateSurfaceNodeWithBuffer();
1938 node4->SetIsOnTheTree(true);
1939 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node4);
1940 auto node5 = RSTestUtil::CreateSurfaceNodeWithBuffer();
1941 node5->SetIsOnTheTree(true);
1942 node5->nodeType_ = RSSurfaceNodeType::SELF_DRAWING_NODE;
1943 node5->isHardwareEnabledNode_ = true;
1944 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node5);
1945 mainThread->CollectInfoForHardwareComposer();
1946 mainThread->isUniRender_ = isUniRender;
1947 }
1948
1949 /**
1950 * @tc.name: ClassifyRSTransactionData005
1951 * @tc.desc: ClassifyRSTransactionData005 Test
1952 * @tc.type: FUNC
1953 * @tc.require: issueI7HDVG
1954 */
1955 HWTEST_F(RSMainThreadTest, ClassifyRSTransactionData005, TestSize.Level1)
1956 {
1957 auto mainThread = RSMainThread::Instance();
1958 ASSERT_NE(mainThread, nullptr);
1959 bool isUniRender = mainThread->isUniRender_;
1960 mainThread->isUniRender_ = true;
1961 // prepare nodemap
1962 mainThread->context_->GetMutableNodeMap().renderNodeMap_.clear();
1963 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.clear();
1964 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.emplace(1, nullptr);
1965 RSSurfaceRenderNodeConfig config;
1966 config.id = 2;
1967 auto node2 = std::make_shared<RSSurfaceRenderNode>(config);
1968 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node2);
1969 // prepare transactionData
1970 auto data = std::make_unique<RSTransactionData>();
1971 int dataIndex = 1;
1972 data->SetIndex(dataIndex);
1973 int dataPayloadSize = 3;
1974 data->payload_.resize(dataPayloadSize);
1975 NodeId id = 0;
1976 data->payload_[id] = std::tuple<NodeId,
1977 FollowType, std::unique_ptr<RSCommand>>(id, FollowType::NONE, nullptr);
1978 id = 1;
1979 data->payload_[id] = std::tuple<NodeId,
1980 FollowType, std::unique_ptr<RSCommand>>(id, FollowType::FOLLOW_TO_SELF, nullptr);
1981 id = 2;
1982 data->payload_[id] = std::tuple<NodeId,
1983 FollowType, std::unique_ptr<RSCommand>>(id, FollowType::FOLLOW_TO_PARENT, nullptr);
1984 mainThread->ClassifyRSTransactionData(data);
1985 mainThread->isUniRender_ = isUniRender;
1986 }
1987
1988 /**
1989 * @tc.name: ReleaseAllNodesBuffer
1990 * @tc.desc: ReleaseAllNodesBuffer Test
1991 * @tc.type: FUNC
1992 * @tc.require: issueI7HDVG
1993 */
1994 HWTEST_F(RSMainThreadTest, ReleaseAllNodesBuffer, TestSize.Level1)
1995 {
1996 auto mainThread = RSMainThread::Instance();
1997 ASSERT_NE(mainThread, nullptr);
1998 bool isUniRender = mainThread->isUniRender_;
1999 mainThread->isUniRender_ = true;
2000 // prepare nodemap
2001 mainThread->context_->GetMutableNodeMap().renderNodeMap_.clear();
2002 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.clear();
2003 mainThread->context_->GetMutableNodeMap().surfaceNodeMap_.emplace(1, nullptr);
2004 RSSurfaceRenderNodeConfig config;
2005 config.id = 2;
2006 auto node2 = std::make_shared<RSSurfaceRenderNode>(config);
2007 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node2);
2008 config.id = 3;
2009 auto node3 = std::make_shared<RSSurfaceRenderNode>(config);
2010 node3->nodeType_ = RSSurfaceNodeType::SELF_DRAWING_NODE;
2011 node3->isHardwareEnabledNode_ = true;
2012 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node3);
2013 config.id = 4;
2014 auto node4 = std::make_shared<RSSurfaceRenderNode>(config);
2015 node4->nodeType_ = RSSurfaceNodeType::SELF_DRAWING_NODE;
2016 node4->isHardwareEnabledNode_ = true;
2017 node4->isLastFrameHardwareEnabled_ = true;
2018 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node4);
2019 config.id = 5;
2020 auto node5 = std::make_shared<RSSurfaceRenderNode>(config);
2021 node5->nodeType_ = RSSurfaceNodeType::SELF_DRAWING_NODE;
2022 node5->isHardwareEnabledNode_ = true;
2023 node5->isLastFrameHardwareEnabled_ = true;
2024 node5->isCurrentFrameHardwareEnabled_ = false;
2025 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node5);
2026 mainThread->ReleaseAllNodesBuffer();
2027 mainThread->isUniRender_ = isUniRender;
2028 }
2029
2030 /**
2031 * @tc.name: PostTask001
2032 * @tc.desc: PostTask Test
2033 * @tc.type: FUNC
2034 * @tc.require: issueI7HDVG
2035 */
2036 HWTEST_F(RSMainThreadTest, PostTask001, TestSize.Level1)
2037 {
2038 auto mainThread = RSMainThread::Instance();
2039 ASSERT_NE(mainThread, nullptr);
2040 mainThread->runner_ = AppExecFwk::EventRunner::Create(false);
2041 mainThread->handler_ = std::make_shared<AppExecFwk::EventHandler>(mainThread->runner_);
__anon22dae5050202() 2042 RSTaskMessage::RSTask task = []() -> void { return; };
2043 mainThread->PostTask(task);
2044 mainThread->runner_ = nullptr;
2045 mainThread->handler_ = nullptr;
2046 }
2047
2048 /**
2049 * @tc.name: PostTask002
2050 * @tc.desc: PostTask Test with IMMEDIATE Priority
2051 * @tc.type: FUNC
2052 * @tc.require: issueI7HDVG
2053 */
2054 HWTEST_F(RSMainThreadTest, PostTask002, TestSize.Level1)
2055 {
2056 auto mainThread = RSMainThread::Instance();
2057 ASSERT_NE(mainThread, nullptr);
2058 mainThread->runner_ = AppExecFwk::EventRunner::Create(false);
2059 mainThread->handler_ = std::make_shared<AppExecFwk::EventHandler>(mainThread->runner_);
__anon22dae5050302() 2060 RSTaskMessage::RSTask task = []() -> void { return; };
2061 std::string name = "test";
2062 int64_t delayTime = 0;
2063 AppExecFwk::EventQueue::Priority priority = AppExecFwk::EventQueue::Priority::IMMEDIATE;
2064 mainThread->PostTask(task, name, delayTime, priority);
2065 mainThread->runner_ = nullptr;
2066 mainThread->handler_ = nullptr;
2067 }
2068
2069 /**
2070 * @tc.name: RemoveTask
2071 * @tc.desc: RemoveTask Test
2072 * @tc.type: FUNC
2073 * @tc.require: issueI7HDVG
2074 */
2075 HWTEST_F(RSMainThreadTest, RemoveTask, TestSize.Level1)
2076 {
2077 auto mainThread = RSMainThread::Instance();
2078 ASSERT_NE(mainThread, nullptr);
2079 mainThread->runner_ = AppExecFwk::EventRunner::Create(false);
2080 mainThread->handler_ = std::make_shared<AppExecFwk::EventHandler>(mainThread->runner_);
2081 std::string name = "test";
2082 mainThread->RemoveTask(name);
2083 mainThread->runner_ = nullptr;
2084 mainThread->handler_ = nullptr;
2085 }
2086
2087 /**
2088 * @tc.name: PostSyncTask002
2089 * @tc.desc: PostSyncTask Test
2090 * @tc.type: FUNC
2091 * @tc.require: issueI7HDVG
2092 */
2093 HWTEST_F(RSMainThreadTest, PostSyncTask002, TestSize.Level1)
2094 {
2095 auto mainThread = RSMainThread::Instance();
2096 ASSERT_NE(mainThread, nullptr);
2097 mainThread->runner_ = AppExecFwk::EventRunner::Create(false);
2098 mainThread->handler_ = std::make_shared<AppExecFwk::EventHandler>(mainThread->runner_);
__anon22dae5050402() 2099 RSTaskMessage::RSTask task = []() -> void { return; };
2100 mainThread->PostSyncTask(task);
2101 mainThread->runner_ = nullptr;
2102 mainThread->handler_ = nullptr;
2103 }
2104
2105 /**
2106 * @tc.name: RegisterSurfaceOcclusionChangeCallBack001
2107 * @tc.desc: RegisterSurfaceOcclusionChangeCallBack001 Test
2108 * @tc.type: FUNC
2109 * @tc.require: issueI7HDVG
2110 */
2111 HWTEST_F(RSMainThreadTest, RegisterSurfaceOcclusionChangeCallBack001, TestSize.Level1)
2112 {
2113 auto mainThread = RSMainThread::Instance();
2114 ASSERT_NE(mainThread, nullptr);
2115 NodeId id = 0;
2116 pid_t pid = 0;
2117 sptr<RSISurfaceOcclusionChangeCallback> callback = nullptr;
2118 std::vector<float> partitionPoints = {};
2119 mainThread->RegisterSurfaceOcclusionChangeCallback(id, pid, callback, partitionPoints);
2120 ASSERT_NE(mainThread->surfaceOcclusionListeners_.size(), 0);
2121 mainThread->surfaceOcclusionListeners_.clear();
2122 }
2123
2124 /**
2125 * @tc.name: RegisterSurfaceOcclusionChangeCallBack002
2126 * @tc.desc: RegisterSurfaceOcclusionChangeCallBack002 Test
2127 * @tc.type: FUNC
2128 * @tc.require: issueI7HDVG
2129 */
2130 HWTEST_F(RSMainThreadTest, RegisterSurfaceOcclusionChangeCallBack002, TestSize.Level1)
2131 {
2132 auto mainThread = RSMainThread::Instance();
2133 ASSERT_NE(mainThread, nullptr);
2134 NodeId id = 0;
2135 pid_t pid = 0;
2136 sptr<RSISurfaceOcclusionChangeCallback> callback = nullptr;
2137 std::vector<float> partitionPoints = {1.0f};
2138 mainThread->RegisterSurfaceOcclusionChangeCallback(id, pid, callback, partitionPoints);
2139 ASSERT_NE(mainThread->surfaceOcclusionListeners_.size(), 0);
2140 mainThread->surfaceOcclusionListeners_.clear();
2141 }
2142
2143 /**
2144 * @tc.name: ClearSurfaceOcclusionChangeCallBack
2145 * @tc.desc: RegisterSurfaceOcclusionChangeCallBack Test
2146 * @tc.type: FUNC
2147 * @tc.require: issueI7HDVG
2148 */
2149 HWTEST_F(RSMainThreadTest, ClearSurfaceOcclusionChangeCallback, TestSize.Level1)
2150 {
2151 auto mainThread = RSMainThread::Instance();
2152 ASSERT_NE(mainThread, nullptr);
2153 // prepare listeners
2154 pid_t pid = 1;
2155 int level = 0;
2156 NodeId id = 1;
2157 std::tuple<pid_t, sptr<RSISurfaceOcclusionChangeCallback>,
2158 std::vector<float>, uint8_t> info1(pid, nullptr, {}, level);
2159 mainThread->surfaceOcclusionListeners_.insert({id, info1});
2160 id = 2;
2161 pid = 2;
2162 std::tuple<pid_t, sptr<RSISurfaceOcclusionChangeCallback>,
2163 std::vector<float>, uint8_t> info2(pid, nullptr, {}, level);
2164 mainThread->surfaceOcclusionListeners_.insert({id, info2});
2165 mainThread->ClearSurfaceOcclusionChangeCallback(pid);
2166 mainThread->surfaceOcclusionListeners_.clear();
2167 }
2168
2169 /**
2170 * @tc.name: SendCommands
2171 * @tc.desc: SendCommands Test
2172 * @tc.type: FUNC
2173 * @tc.require: issueI7HDVG
2174 */
2175 HWTEST_F(RSMainThreadTest, SendCommands, TestSize.Level1)
2176 {
2177 auto mainThread = RSMainThread::Instance();
2178 ASSERT_NE(mainThread, nullptr);
2179 mainThread->SendCommands();
2180 }
2181
2182 /**
2183 * @tc.name: SendCommands001
2184 * @tc.desc: SendCommands Test
2185 * @tc.type: FUNC
2186 */
2187 HWTEST_F(RSMainThreadTest, SendCommands001, TestSize.Level1)
2188 {
2189 auto mainThread = RSMainThread::Instance();
2190 ASSERT_NE(mainThread, nullptr);
2191 NodeId id = 1;
2192 AnimationId animationId = 1;
2193 mainThread->context_->AddSyncFinishAnimationList(id, animationId);
2194 mainThread->SendCommands();
2195 }
2196
2197 /**
2198 * @tc.name: ClearTransactionDataPidInfo001
2199 * @tc.desc: ClearTransactionDataPidInfo Test, remotePid = 0
2200 * @tc.type: FUNC
2201 * @tc.require: issueI7HDVG
2202 */
2203 HWTEST_F(RSMainThreadTest, ClearTransactionDataPidInfo001, TestSize.Level1)
2204 {
2205 auto mainThread = RSMainThread::Instance();
2206 ASSERT_NE(mainThread, nullptr);
2207 int remotePid = 0;
2208 mainThread->ClearTransactionDataPidInfo(remotePid);
2209 }
2210
2211 /**
2212 * @tc.name: ClearTransactionDataPidInfo002
2213 * @tc.desc: ClearTransactionDataPidInfo Test, remotePid > 0
2214 * @tc.type: FUNC
2215 * @tc.require: issueI7HDVG
2216 */
2217 HWTEST_F(RSMainThreadTest, ClearTransactionDataPidInfo002, TestSize.Level1)
2218 {
2219 auto mainThread = RSMainThread::Instance();
2220 ASSERT_NE(mainThread, nullptr);
2221 int remotePid = 1;
2222 mainThread->ClearTransactionDataPidInfo(remotePid);
2223 }
2224
2225 /**
2226 * @tc.name: AddTransactionDataPidInfo001
2227 * @tc.desc: AddTransactionDataPidInfo Test, no UniRender
2228 * @tc.type: FUNC
2229 * @tc.require: issueI7HDVG
2230 */
2231 HWTEST_F(RSMainThreadTest, AddTransactionDataPidInfo001, TestSize.Level1)
2232 {
2233 auto mainThread = RSMainThread::Instance();
2234 ASSERT_NE(mainThread, nullptr);
2235 auto isUniRender = mainThread->isUniRender_;
2236 mainThread->isUniRender_ = false;
2237 pid_t pid = 0;
2238 mainThread->AddTransactionDataPidInfo(pid);
2239 mainThread->isUniRender_ = isUniRender;
2240 }
2241
2242 /**
2243 * @tc.name: AddTransactionDataPidInfo002
2244 * @tc.desc: AddTransactionDataPidInfo Test, UniRender
2245 * @tc.type: FUNC
2246 * @tc.require: issueI7HDVG
2247 */
2248 HWTEST_F(RSMainThreadTest, AddTransactionDataPidInfo002, TestSize.Level1)
2249 {
2250 auto mainThread = RSMainThread::Instance();
2251 ASSERT_NE(mainThread, nullptr);
2252 auto isUniRender = mainThread->isUniRender_;
2253 mainThread->isUniRender_ = true;
2254 pid_t pid = 0;
2255 mainThread->AddTransactionDataPidInfo(pid);
2256 mainThread->isUniRender_ = isUniRender;
2257 }
2258
2259 /**
2260 * @tc.name: PerfAfterAnim001
2261 * @tc.desc: PerfAfterAnim Test, not UniRender, needRequestNextVsync
2262 * @tc.type: FUNC
2263 * @tc.require: issueI7HDVG
2264 */
2265 HWTEST_F(RSMainThreadTest, PerfAfterAnim001, TestSize.Level1)
2266 {
2267 auto mainThread = RSMainThread::Instance();
2268 ASSERT_NE(mainThread, nullptr);
2269 auto isUniRender = mainThread->isUniRender_;
2270 mainThread->isUniRender_ = false;
2271 bool needRequestNextVsync = true;
2272 mainThread->PerfAfterAnim(needRequestNextVsync);
2273 mainThread->isUniRender_ = isUniRender;
2274 }
2275
2276 /**
2277 * @tc.name: PerfAfterAnim002
2278 * @tc.desc: PerfAfterAnim Test, UniRender, needRequestNextVsync
2279 * @tc.type: FUNC
2280 * @tc.require: issueI7HDVG
2281 */
2282 HWTEST_F(RSMainThreadTest, PerfAfterAnim002, TestSize.Level1)
2283 {
2284 auto mainThread = RSMainThread::Instance();
2285 ASSERT_NE(mainThread, nullptr);
2286 auto isUniRender = mainThread->isUniRender_;
2287 mainThread->isUniRender_ = true;
2288 bool needRequestNextVsync = true;
2289 mainThread->PerfAfterAnim(needRequestNextVsync);
2290 mainThread->isUniRender_ = isUniRender;
2291 }
2292
2293 /**
2294 * @tc.name: PerfAfterAnim003
2295 * @tc.desc: PerfAfterAnim Test, UniRender, not needRequestNextVsync
2296 * @tc.type: FUNC
2297 * @tc.require: issueI7HDVG
2298 */
2299 HWTEST_F(RSMainThreadTest, PerfAfterAnim003, TestSize.Level1)
2300 {
2301 auto mainThread = RSMainThread::Instance();
2302 ASSERT_NE(mainThread, nullptr);
2303 auto isUniRender = mainThread->isUniRender_;
2304 mainThread->isUniRender_ = true;
2305 bool needRequestNextVsync = false;
2306 mainThread->PerfAfterAnim(needRequestNextVsync);
2307 mainThread->isUniRender_ = isUniRender;
2308 }
2309
2310 /**
2311 * @tc.name: ForceRefreshForUni001
2312 * @tc.desc: ForceRefreshForUni Test, UniRender
2313 * @tc.type: FUNC
2314 * @tc.require: issueI7HDVG
2315 */
2316 HWTEST_F(RSMainThreadTest, ForceRefreshForUni001, TestSize.Level1)
2317 {
2318 auto mainThread = RSMainThread::Instance();
2319 ASSERT_NE(mainThread, nullptr);
2320 auto isUniRender = mainThread->isUniRender_;
2321 mainThread->isUniRender_ = true;
2322 mainThread->ForceRefreshForUni();
2323 mainThread->isUniRender_ = isUniRender;
2324 }
2325
2326 /**
2327 * @tc.name: ForceRefreshForUni002
2328 * @tc.desc: ForceRefreshForUni Test, without UniRender
2329 * @tc.type: FUNC
2330 * @tc.require: issueI7HDVG
2331 */
2332 HWTEST_F(RSMainThreadTest, ForceRefreshForUni002, TestSize.Level1)
2333 {
2334 auto mainThread = RSMainThread::Instance();
2335 ASSERT_NE(mainThread, nullptr);
2336 auto isUniRender = mainThread->isUniRender_;
2337 mainThread->isUniRender_ = false;
2338 mainThread->ForceRefreshForUni();
2339 mainThread->isUniRender_ = isUniRender;
2340 }
2341
2342 /**
2343 * @tc.name: PerfForBlurIfNeeded
2344 * @tc.desc: PerfForBlurIfNeeded Test
2345 * @tc.type: FUNC
2346 * @tc.require: issueI7HDVG
2347 */
2348 HWTEST_F(RSMainThreadTest, PerfForBlurIfNeeded, TestSize.Level1)
2349 {
2350 auto mainThread = RSMainThread::Instance();
2351 ASSERT_NE(mainThread, nullptr);
2352 mainThread->runner_ = AppExecFwk::EventRunner::Create(false);
2353 mainThread->handler_ = std::make_shared<AppExecFwk::EventHandler>(mainThread->runner_);
2354 mainThread->PerfForBlurIfNeeded();
2355 mainThread->runner_ = nullptr;
2356 mainThread->handler_ = nullptr;
2357 }
2358
2359 /**
2360 * @tc.name: PerfMultiWindow001
2361 * @tc.desc: PerfMultiWindow Test, not unirender
2362 * @tc.type: FUNC
2363 * @tc.require: issueI7HDVG
2364 */
2365 HWTEST_F(RSMainThreadTest, PerfMultiWindow001, TestSize.Level1)
2366 {
2367 auto mainThread = RSMainThread::Instance();
2368 ASSERT_NE(mainThread, nullptr);
2369 auto isUniRender = mainThread->isUniRender_;
2370 mainThread->isUniRender_ = false;
2371 mainThread->PerfMultiWindow();
2372 mainThread->isUniRender_ = isUniRender;
2373 }
2374
2375 /**
2376 * @tc.name: PerfMultiWindow002
2377 * @tc.desc: PerfMultiWindow Test, unirender
2378 * @tc.type: FUNC
2379 * @tc.require: issueI7HDVG
2380 */
2381 HWTEST_F(RSMainThreadTest, PerfMultiWindow002, TestSize.Level1)
2382 {
2383 auto mainThread = RSMainThread::Instance();
2384 ASSERT_NE(mainThread, nullptr);
2385 auto isUniRender = mainThread->isUniRender_;
2386 mainThread->isUniRender_ = true;
2387 auto appWindowNum = mainThread->appWindowNum_;
2388 mainThread->appWindowNum_ = MULTI_WINDOW_PERF_START_NUM - 1;
2389 mainThread->PerfMultiWindow();
2390 mainThread->appWindowNum_ = MULTI_WINDOW_PERF_START_NUM;
2391 mainThread->PerfMultiWindow();
2392 mainThread->appWindowNum_ = MULTI_WINDOW_PERF_END_NUM + 1;
2393 mainThread->PerfMultiWindow();
2394 mainThread->isUniRender_ = isUniRender;
2395 mainThread->appWindowNum_ = appWindowNum;
2396 }
2397
2398 /**
2399 * @tc.name: RenderFrameStart
2400 * @tc.desc: RenderFrameStart Test
2401 * @tc.type: FUNC
2402 * @tc.require: issueI7HDVG
2403 */
2404 HWTEST_F(RSMainThreadTest, RenderFrameStart, TestSize.Level1)
2405 {
2406 auto mainThread = RSMainThread::Instance();
2407 ASSERT_NE(mainThread, nullptr);
2408 mainThread->RenderFrameStart(mainThread->timestamp_);
2409 }
2410
2411 /**
2412 * @tc.name: SetSystemAnimatedScenes001
2413 * @tc.desc: SetSystemAnimatedScenes Test, case set 1
2414 * @tc.type: FUNC
2415 * @tc.require: issueI7HDVG
2416 */
2417 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes001, TestSize.Level1)
2418 {
2419 auto mainThread = RSMainThread::Instance();
2420 ASSERT_NE(mainThread, nullptr);
2421 SystemAnimatedScenes scenesInit = mainThread->systemAnimatedScenes_;
2422 SystemAnimatedScenes scenes = SystemAnimatedScenes::ENTER_MISSION_CENTER;
2423 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2424 scenes = SystemAnimatedScenes::EXIT_MISSION_CENTER;
2425 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2426 scenes = SystemAnimatedScenes::ENTER_TFS_WINDOW;
2427 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2428 scenes = SystemAnimatedScenes::EXIT_TFU_WINDOW;
2429 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2430 scenes = SystemAnimatedScenes::ENTER_WINDOW_FULL_SCREEN;
2431 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2432 scenes = SystemAnimatedScenes::EXIT_WINDOW_FULL_SCREEN;
2433 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2434 scenes = SystemAnimatedScenes::ENTER_MAX_WINDOW;
2435 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2436 scenes = SystemAnimatedScenes::EXIT_MAX_WINDOW;
2437 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2438 mainThread->systemAnimatedScenes_ = scenesInit;
2439 }
2440
2441 /**
2442 * @tc.name: SetSystemAnimatedScenes002
2443 * @tc.desc: SetSystemAnimatedScenes Test, case set 2
2444 * @tc.type: FUNC
2445 * @tc.require: issueI7HDVG
2446 */
2447 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes002, TestSize.Level1)
2448 {
2449 auto mainThread = RSMainThread::Instance();
2450 ASSERT_NE(mainThread, nullptr);
2451 SystemAnimatedScenes scenesInit = mainThread->systemAnimatedScenes_;
2452 SystemAnimatedScenes scenes = SystemAnimatedScenes::ENTER_SPLIT_SCREEN;
2453 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2454 scenes = SystemAnimatedScenes::EXIT_SPLIT_SCREEN;
2455 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2456 scenes = SystemAnimatedScenes::ENTER_APP_CENTER;
2457 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2458 scenes = SystemAnimatedScenes::EXIT_APP_CENTER;
2459 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2460 scenes = SystemAnimatedScenes::APPEAR_MISSION_CENTER;
2461 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2462 scenes = SystemAnimatedScenes::ENTER_WIND_CLEAR;
2463 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2464 scenes = SystemAnimatedScenes::ENTER_WIND_RECOVER;
2465 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2466 scenes = SystemAnimatedScenes::OTHERS;
2467 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(scenes));
2468 mainThread->systemAnimatedScenes_ = scenesInit;
2469 }
2470
2471 /**
2472 * @tc.name: SetSystemAnimatedScenes003
2473 * @tc.desc: SetSystemAnimatedScenes Test, System Animated Scenes Disabled
2474 * @tc.type: FUNC
2475 * @tc.require: issueI7HDVG
2476 */
2477 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes003, TestSize.Level1)
2478 {
2479 auto mainThread = RSMainThread::Instance();
2480 ASSERT_NE(mainThread, nullptr);
2481 auto systemAnimatedScenesEnabled = mainThread->systemAnimatedScenesEnabled_;
2482 mainThread->systemAnimatedScenesEnabled_ = false;
2483 ASSERT_TRUE(mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::OTHERS));
2484 mainThread->systemAnimatedScenesEnabled_ = systemAnimatedScenesEnabled;
2485 }
2486
2487 /**
2488 * @tc.name: CheckNodeHasToBePreparedByPid001
2489 * @tc.desc: CheckNodeHasToBePreparedByPid Test, Classify By Root
2490 * @tc.type: FUNC
2491 * @tc.require: issueI7HDVG
2492 */
2493 HWTEST_F(RSMainThreadTest, CheckNodeHasToBePreparedByPid001, TestSize.Level1)
2494 {
2495 auto mainThread = RSMainThread::Instance();
2496 ASSERT_NE(mainThread, nullptr);
2497 NodeId id = 1;
2498 bool isClassifyByRoot = true;
2499 mainThread->CheckNodeHasToBePreparedByPid(id, isClassifyByRoot);
2500 }
2501
2502 /**
2503 * @tc.name: CheckNodeHasToBePreparedByPid002
2504 * @tc.desc: CheckNodeHasToBePreparedByPid Test, not Classify By Root
2505 * @tc.type: FUNC
2506 * @tc.require: issueI7HDVG
2507 */
2508 HWTEST_F(RSMainThreadTest, CheckNodeHasToBePreparedByPid002, TestSize.Level1)
2509 {
2510 auto mainThread = RSMainThread::Instance();
2511 ASSERT_NE(mainThread, nullptr);
2512 NodeId id = 1;
2513 bool isClassifyByRoot = false;
2514 mainThread->CheckNodeHasToBePreparedByPid(id, isClassifyByRoot);
2515 }
2516
2517 /**
2518 * @tc.name: SetVSyncRateByVisibleLevel001
2519 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when RSVisibleLevel is RS_SEMI_DEFAULT_VISIBLE
2520 * @tc.type: FUNC
2521 * @tc.require: issueI7HDVG
2522 */
2523 HWTEST_F(RSMainThreadTest, SetVSyncRateByVisibleLevel001, TestSize.Level1)
2524 {
2525 auto mainThread = RSMainThread::Instance();
2526 ASSERT_NE(mainThread, nullptr);
2527 if (mainThread->appVSyncDistributor_ == nullptr) {
2528 auto vsyncGenerator = CreateVSyncGenerator();
2529 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2530 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2531 }
2532 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2533 ASSERT_NE(vsyncDistributor, nullptr);
2534 vsyncDistributor->connectionsMap_.clear();
2535 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2536 uint32_t tmpPid = 0;
2537 if (vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid) == VSYNC_ERROR_OK) {
2538 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2539 std::map<NodeId, RSVisibleLevel> pidVisMap;
2540 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_SEMI_DEFAULT_VISIBLE;
2541 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2542 mainThread->lastVisMapForVsyncRate_.clear();
2543 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2544 ASSERT_NE(connection->highPriorityRate_, (int32_t)SIMI_VISIBLE_RATE);
2545 }
2546 }
2547
2548 /**
2549 * @tc.name: SetVSyncRateByVisibleLevel002
2550 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when RSVisibleLevel is RS_SYSTEM_ANIMATE_SCENE
2551 * @tc.type: FUNC
2552 * @tc.require: issueI7HDVG
2553 */
2554 HWTEST_F(RSMainThreadTest, SetVSyncRateByVisibleLevel002, TestSize.Level1)
2555 {
2556 auto mainThread = RSMainThread::Instance();
2557 ASSERT_NE(mainThread, nullptr);
2558 if (mainThread->appVSyncDistributor_ == nullptr) {
2559 auto vsyncGenerator = CreateVSyncGenerator();
2560 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2561 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2562 }
2563 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2564 ASSERT_NE(vsyncDistributor, nullptr);
2565 vsyncDistributor->connectionsMap_.clear();
2566 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2567 uint32_t tmpPid = 0;
2568 if (vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid) == VSYNC_ERROR_OK) {
2569 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2570 std::map<NodeId, RSVisibleLevel> pidVisMap;
2571 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_SYSTEM_ANIMATE_SCENE;
2572 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2573 mainThread->lastVisMapForVsyncRate_.clear();
2574 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2575 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2576 }
2577 }
2578
2579 /**
2580 * @tc.name: SetVSyncRateByVisibleLevel003
2581 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when RSVisibleLevel is RS_INVISIBLE
2582 * @tc.type: FUNC
2583 * @tc.require: issueI7HDVG
2584 */
2585 HWTEST_F(RSMainThreadTest, SetVSyncRateByVisibleLevel003, TestSize.Level1)
2586 {
2587 auto mainThread = RSMainThread::Instance();
2588 ASSERT_NE(mainThread, nullptr);
2589 if (mainThread->appVSyncDistributor_ == nullptr) {
2590 auto vsyncGenerator = CreateVSyncGenerator();
2591 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2592 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2593 }
2594 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2595 ASSERT_NE(vsyncDistributor, nullptr);
2596 vsyncDistributor->connectionsMap_.clear();
2597 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2598 uint32_t tmpPid = 0;
2599 if (vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid) == VSYNC_ERROR_OK) {
2600 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2601 std::map<NodeId, RSVisibleLevel> pidVisMap;
2602 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_INVISIBLE;
2603 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2604 mainThread->lastVisMapForVsyncRate_.clear();
2605 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2606 ASSERT_NE(connection->highPriorityRate_, (int32_t)INVISBLE_WINDOW_RATE);
2607 }
2608 }
2609
2610 /**
2611 * @tc.name: SetVSyncRateByVisibleLevel004
2612 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when RSVisibleLevel is RS_UNKNOW_VISIBLE_LEVEL
2613 * @tc.type: FUNC
2614 * @tc.require: issueI7HDVG
2615 */
2616 HWTEST_F(RSMainThreadTest, SetVSyncRateByVisibleLevel004, TestSize.Level1)
2617 {
2618 auto mainThread = RSMainThread::Instance();
2619 ASSERT_NE(mainThread, nullptr);
2620 if (mainThread->appVSyncDistributor_ == nullptr) {
2621 auto vsyncGenerator = CreateVSyncGenerator();
2622 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2623 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2624 }
2625 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2626 ASSERT_NE(vsyncDistributor, nullptr);
2627 vsyncDistributor->connectionsMap_.clear();
2628 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2629 uint32_t tmpPid = 0;
2630 if (vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid) == VSYNC_ERROR_OK) {
2631 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2632 std::map<NodeId, RSVisibleLevel> pidVisMap;
2633 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2634 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2635 mainThread->lastVisMapForVsyncRate_.clear();
2636 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2637 ASSERT_NE(connection->highPriorityRate_, (int32_t)DEFAULT_RATE);
2638 }
2639 }
2640
2641 /**
2642 * @tc.name: SetSystemAnimatedScenes004
2643 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when SystemAnimatedScenes is ENTER_MISSION_CENTER
2644 * @tc.type: FUNC
2645 * @tc.require: issueI7HDVG
2646 */
2647 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes004, TestSize.Level1)
2648 {
2649 auto mainThread = RSMainThread::Instance();
2650 ASSERT_NE(mainThread, nullptr);
2651 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_MISSION_CENTER);
2652 ASSERT_NE(mainThread->systemAnimatedScenesList_.empty(), true);
2653 if (mainThread->appVSyncDistributor_ == nullptr) {
2654 auto vsyncGenerator = CreateVSyncGenerator();
2655 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2656 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2657 }
2658 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2659 ASSERT_NE(vsyncDistributor, nullptr);
2660 vsyncDistributor->connectionsMap_.clear();
2661 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2662 uint32_t tmpPid = 0;
2663 ASSERT_EQ(vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid), VSYNC_ERROR_OK);
2664 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2665 std::map<NodeId, RSVisibleLevel> pidVisMap;
2666 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2667 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2668 mainThread->lastVisMapForVsyncRate_.clear();
2669 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2670 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2671 }
2672
2673 /**
2674 * @tc.name: SetSystemAnimatedScenes005
2675 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when SystemAnimatedScenes is ENTER_TFS_WINDOW
2676 * @tc.type: FUNC
2677 * @tc.require: issueI7HDVG
2678 */
2679 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes005, TestSize.Level1)
2680 {
2681 auto mainThread = RSMainThread::Instance();
2682 ASSERT_NE(mainThread, nullptr);
2683 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_TFS_WINDOW);
2684 ASSERT_NE(mainThread->systemAnimatedScenesList_.empty(), true);
2685 if (mainThread->appVSyncDistributor_ == nullptr) {
2686 auto vsyncGenerator = CreateVSyncGenerator();
2687 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2688 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2689 }
2690 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2691 ASSERT_NE(vsyncDistributor, nullptr);
2692 vsyncDistributor->connectionsMap_.clear();
2693 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2694 uint32_t tmpPid = 0;
2695 ASSERT_EQ(vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid), VSYNC_ERROR_OK);
2696 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2697 std::map<NodeId, RSVisibleLevel> pidVisMap;
2698 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2699 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2700 mainThread->lastVisMapForVsyncRate_.clear();
2701 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2702 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2703 }
2704
2705 /**
2706 * @tc.name: SetSystemAnimatedScenes006
2707 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when SystemAnimatedScenes is ENTER_WINDOW_FULL_SCREEN
2708 * @tc.type: FUNC
2709 * @tc.require: issueI7HDVG
2710 */
2711 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes006, TestSize.Level1)
2712 {
2713 auto mainThread = RSMainThread::Instance();
2714 ASSERT_NE(mainThread, nullptr);
2715 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_WINDOW_FULL_SCREEN);
2716 ASSERT_NE(mainThread->systemAnimatedScenesList_.empty(), true);
2717 if (mainThread->appVSyncDistributor_ == nullptr) {
2718 auto vsyncGenerator = CreateVSyncGenerator();
2719 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2720 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2721 }
2722 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2723 ASSERT_NE(vsyncDistributor, nullptr);
2724 vsyncDistributor->connectionsMap_.clear();
2725 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2726 uint32_t tmpPid = 0;
2727 ASSERT_EQ(vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid), VSYNC_ERROR_OK);
2728 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2729 std::map<NodeId, RSVisibleLevel> pidVisMap;
2730 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2731 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2732 mainThread->lastVisMapForVsyncRate_.clear();
2733 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2734 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2735 }
2736
2737 /**
2738 * @tc.name: SetSystemAnimatedScenes007
2739 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when SystemAnimatedScenes is ENTER_MAX_WINDOW
2740 * @tc.type: FUNC
2741 * @tc.require: issueI7HDVG
2742 */
2743 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes007, TestSize.Level1)
2744 {
2745 auto mainThread = RSMainThread::Instance();
2746 ASSERT_NE(mainThread, nullptr);
2747 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_MAX_WINDOW);
2748 ASSERT_NE(mainThread->systemAnimatedScenesList_.empty(), true);
2749 if (mainThread->appVSyncDistributor_ == nullptr) {
2750 auto vsyncGenerator = CreateVSyncGenerator();
2751 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2752 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2753 }
2754 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2755 ASSERT_NE(vsyncDistributor, nullptr);
2756 vsyncDistributor->connectionsMap_.clear();
2757 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2758 uint32_t tmpPid = 0;
2759 ASSERT_EQ(vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid), VSYNC_ERROR_OK);
2760 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2761 std::map<NodeId, RSVisibleLevel> pidVisMap;
2762 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2763 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2764 mainThread->lastVisMapForVsyncRate_.clear();
2765 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2766 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2767 }
2768
2769 /**
2770 * @tc.name: SetSystemAnimatedScenes008
2771 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when SystemAnimatedScenes is ENTER_SPLIT_SCREEN
2772 * @tc.type: FUNC
2773 * @tc.require: issueI7HDVG
2774 */
2775 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes008, TestSize.Level1)
2776 {
2777 auto mainThread = RSMainThread::Instance();
2778 ASSERT_NE(mainThread, nullptr);
2779 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_SPLIT_SCREEN);
2780 ASSERT_NE(mainThread->systemAnimatedScenesList_.empty(), true);
2781 if (mainThread->appVSyncDistributor_ == nullptr) {
2782 auto vsyncGenerator = CreateVSyncGenerator();
2783 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2784 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2785 }
2786 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2787 ASSERT_NE(vsyncDistributor, nullptr);
2788 vsyncDistributor->connectionsMap_.clear();
2789 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2790 uint32_t tmpPid = 0;
2791 ASSERT_EQ(vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid), VSYNC_ERROR_OK);
2792 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2793 std::map<NodeId, RSVisibleLevel> pidVisMap;
2794 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2795 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2796 mainThread->lastVisMapForVsyncRate_.clear();
2797 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2798 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2799 }
2800
2801 /**
2802 * @tc.name: SetSystemAnimatedScenes009
2803 * @tc.desc: SetVSyncRateByVisibleLevel Test, Check Vsyncrate when SystemAnimatedScenes is ENTER_APP_CENTER
2804 * @tc.type: FUNC
2805 * @tc.require: issueI7HDVG
2806 */
2807 HWTEST_F(RSMainThreadTest, SetSystemAnimatedScenes009, TestSize.Level1)
2808 {
2809 auto mainThread = RSMainThread::Instance();
2810 ASSERT_NE(mainThread, nullptr);
2811 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_APP_CENTER);
2812 ASSERT_NE(mainThread->systemAnimatedScenesList_.empty(), true);
2813 if (mainThread->appVSyncDistributor_ == nullptr) {
2814 auto vsyncGenerator = CreateVSyncGenerator();
2815 auto vsyncController = new VSyncController(vsyncGenerator, 0);
2816 mainThread->appVSyncDistributor_ = new VSyncDistributor(vsyncController, "WMVSyncConnection");
2817 }
2818 auto& vsyncDistributor = mainThread->appVSyncDistributor_;
2819 ASSERT_NE(vsyncDistributor, nullptr);
2820 vsyncDistributor->connectionsMap_.clear();
2821 sptr<VSyncConnection> connection = new VSyncConnection(vsyncDistributor, "WMVSyncConnection_0");
2822 uint32_t tmpPid = 0;
2823 ASSERT_EQ(vsyncDistributor->QosGetPidByName(connection->info_.name_, tmpPid), VSYNC_ERROR_OK);
2824 vsyncDistributor->connectionsMap_[tmpPid].push_back(connection);
2825 std::map<NodeId, RSVisibleLevel> pidVisMap;
2826 pidVisMap[static_cast<NodeId>(tmpPid)] = RSVisibleLevel::RS_UNKNOW_VISIBLE_LEVEL;
2827 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
2828 mainThread->lastVisMapForVsyncRate_.clear();
2829 mainThread->SetVSyncRateByVisibleLevel(pidVisMap, curAllSurfaces);
2830 ASSERT_NE(connection->highPriorityRate_, (int32_t)SYSTEM_ANIMATED_SCENES_RATE);
2831 }
2832
2833 /**
2834 * @tc.name: IsDrawingGroupChanged
2835 * @tc.desc: IsDrawingGroupChanged Test, not Classify By Root
2836 * @tc.type: FUNC
2837 * @tc.require: issueI7HDVG
2838 */
2839 HWTEST_F(RSMainThreadTest, IsDrawingGroupChanged, TestSize.Level1)
2840 {
2841 auto mainThread = RSMainThread::Instance();
2842 ASSERT_NE(mainThread, nullptr);
2843 NodeId id = 1;
2844 auto node = std::make_shared<RSRenderNode>(id);
2845 mainThread->IsDrawingGroupChanged(*node);
2846 }
2847
2848 /**
2849 * @tc.name: CheckAndUpdateInstanceContentStaticStatus003
2850 * @tc.desc: CheckAndUpdateInstanceContentStaticStatus Test, nullptr
2851 * @tc.type: FUNC
2852 * @tc.require: issueI7HDVG
2853 */
2854 HWTEST_F(RSMainThreadTest, CheckAndUpdateInstanceContentStaticStatus003, TestSize.Level1)
2855 {
2856 auto mainThread = RSMainThread::Instance();
2857 ASSERT_NE(mainThread, nullptr);
2858 mainThread->CheckAndUpdateInstanceContentStaticStatus(nullptr);
2859 }
2860
2861 /**
2862 * @tc.name: UpdateRogSizeIfNeeded
2863 * @tc.desc: UpdateRogSizeIfNeeded Test
2864 * @tc.type: FUNC
2865 * @tc.require: issueI7HDVG
2866 */
2867 HWTEST_F(RSMainThreadTest, UpdateRogSizeIfNeeded, TestSize.Level1)
2868 {
2869 auto mainThread = RSMainThread::Instance();
2870 ASSERT_NE(mainThread, nullptr);
2871 // prepare context
2872 auto contextInit = mainThread->context_;
2873 auto context = std::make_shared<RSContext>();
2874 auto rootNode = context->GetGlobalRootRenderNode();
2875 NodeId id = 1;
2876 RSDisplayNodeConfig config;
2877 auto childDisplayNode = std::make_shared<RSDisplayRenderNode>(id, config);
2878 rootNode->AddChild(childDisplayNode);
2879 mainThread->context_ = context;
2880 mainThread->UpdateRogSizeIfNeeded();
2881 mainThread->context_ = contextInit;
2882 }
2883
2884 /**
2885 * @tc.name: UpdateUIFirstSwitch001
2886 * @tc.desc: UpdateUIFirstSwitch Test, root node nullptr
2887 * @tc.type: FUNC
2888 * @tc.require: issueI7HDVG
2889 */
2890 HWTEST_F(RSMainThreadTest, UpdateUIFirstSwitch001, TestSize.Level1)
2891 {
2892 auto mainThread = RSMainThread::Instance();
2893 ASSERT_NE(mainThread, nullptr);
2894 auto rootNode = mainThread->context_->globalRootRenderNode_;
2895 mainThread->context_->globalRootRenderNode_ = nullptr;
2896 mainThread->UpdateUIFirstSwitch();
2897 mainThread->context_->globalRootRenderNode_ = rootNode;
2898 }
2899
2900 /**
2901 * @tc.name: UpdateUIFirstSwitch002
2902 * @tc.desc: UpdateUIFirstSwitch Test, with surfacenode child
2903 * @tc.type: FUNC
2904 * @tc.require: issueI7HDVG
2905 */
2906 HWTEST_F(RSMainThreadTest, UpdateUIFirstSwitch002, TestSize.Level1)
2907 {
2908 auto mainThread = RSMainThread::Instance();
2909 ASSERT_NE(mainThread, nullptr);
2910 auto rootNode = mainThread->context_->globalRootRenderNode_;
2911 // one child
2912 NodeId id = 1;
2913 auto node1 = std::make_shared<RSRenderNode>(id);
2914 id = 2;
2915 auto node2 = std::make_shared<RSSurfaceRenderNode>(id);
2916 node1->AddChild(node2);
2917 mainThread->context_->globalRootRenderNode_ = node1;
2918 mainThread->UpdateUIFirstSwitch();
2919 mainThread->context_->globalRootRenderNode_ = rootNode;
2920 }
2921
2922 /**
2923 * @tc.name: UpdateUIFirstSwitch003
2924 * @tc.desc: UpdateUIFirstSwitch Test, with displaynode child
2925 * @tc.type: FUNC
2926 * @tc.require: issueI7HDVG
2927 */
2928 HWTEST_F(RSMainThreadTest, UpdateUIFirstSwitch003, TestSize.Level1)
2929 {
2930 auto mainThread = RSMainThread::Instance();
2931 ASSERT_NE(mainThread, nullptr);
2932 auto rootNode = mainThread->context_->globalRootRenderNode_;
2933 // one child
2934 NodeId id = 1;
2935 auto node1 = std::make_shared<RSRenderNode>(id);
2936 id = 2;
2937 RSDisplayNodeConfig config;
2938 auto node2 = std::make_shared<RSDisplayRenderNode>(id, config);
2939 node1->AddChild(node2);
2940 mainThread->context_->globalRootRenderNode_ = node1;
2941 mainThread->UpdateUIFirstSwitch();
2942 mainThread->context_->globalRootRenderNode_ = rootNode;
2943 }
2944
2945 /**
2946 * @tc.name: ReleaseSurface
2947 * @tc.desc: ReleaseSurface Test
2948 * @tc.type: FUNC
2949 * @tc.require: issueI7HDVG
2950 */
2951 HWTEST_F(RSMainThreadTest, ReleaseSurface, TestSize.Level1)
2952 {
2953 auto mainThread = RSMainThread::Instance();
2954 ASSERT_NE(mainThread, nullptr);
2955 mainThread->tmpSurfaces_.push(nullptr);
2956 mainThread->ReleaseSurface();
2957 }
2958
2959 /**
2960 * @tc.name: SetCurtainScreenUsingStatus
2961 * @tc.desc: SetCurtainScreenUsingStatus Test
2962 * @tc.type: FUNC
2963 * @tc.require: issueI9ABGS
2964 */
2965 HWTEST_F(RSMainThreadTest, SetCurtainScreenUsingStatus, TestSize.Level2)
2966 {
2967 auto mainThread = RSMainThread::Instance();
2968 ASSERT_NE(mainThread, nullptr);
2969 mainThread->SetCurtainScreenUsingStatus(true);
2970 ASSERT_EQ(mainThread->IsCurtainScreenOn(), true);
2971
2972 // restore curtain screen status
2973 mainThread->SetCurtainScreenUsingStatus(false);
2974 }
2975
2976 /**
2977 * @tc.name: SetLuminanceChangingStatus
2978 * @tc.desc: SetLuminanceChangingStatus Test
2979 * @tc.type: FUNC
2980 * @tc.require: issueI9ABGS
2981 */
2982 HWTEST_F(RSMainThreadTest, SetLuminanceChangingStatus, TestSize.Level2)
2983 {
2984 auto mainThread = RSMainThread::Instance();
2985 ASSERT_NE(mainThread, nullptr);
2986 ASSERT_EQ(mainThread->isLuminanceChanged_.load(), false);
2987 mainThread->SetLuminanceChangingStatus(true);
2988 ASSERT_EQ(mainThread->isLuminanceChanged_.load(), true);
2989 }
2990
2991 /**
2992 * @tc.name: ExchangeLuminanceChangingStatus
2993 * @tc.desc: ExchangeLuminanceChangingStatus Test
2994 * @tc.type: FUNC
2995 * @tc.require: issueI9ABGS
2996 */
2997 HWTEST_F(RSMainThreadTest, ExchangeLuminanceChangingStatus, TestSize.Level2)
2998 {
2999 auto mainThread = RSMainThread::Instance();
3000 ASSERT_NE(mainThread, nullptr);
3001 mainThread->SetLuminanceChangingStatus(true);
3002 ASSERT_EQ(mainThread->ExchangeLuminanceChangingStatus(), true);
3003 ASSERT_EQ(mainThread->isLuminanceChanged_.load(), false);
3004 }
3005
3006 /**
3007 * @tc.name: CalcOcclusionImplementation001
3008 * @tc.desc: calculate occlusion when surfaces do not overlap
3009 * @tc.type: FUNC
3010 * @tc.require: issueI97LXT
3011 */
3012 HWTEST_F(RSMainThreadTest, CalcOcclusionImplementation001, TestSize.Level1)
3013 {
3014 auto mainThread = RSMainThread::Instance();
3015 ASSERT_NE(mainThread, nullptr);
3016 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
3017
3018 NodeId idBottom = 0;
3019 auto nodeBottom = std::make_shared<RSSurfaceRenderNode>(idBottom, mainThread->context_);
3020 nodeBottom->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idBottom);
3021 RectI rectBottom = RectI(0, 0, 100, 100);
3022 nodeBottom->oldDirtyInSurface_ = rectBottom;
3023 nodeBottom->SetDstRect(rectBottom);
3024 nodeBottom->opaqueRegion_ = Occlusion::Region(rectBottom);
3025
3026 NodeId idTop = 1;
3027 auto nodeTop = std::make_shared<RSSurfaceRenderNode>(idTop, mainThread->context_);
3028 nodeTop->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idTop);
3029 RectI rectTop = RectI(100, 100, 100, 100);
3030 nodeTop->oldDirtyInSurface_ = rectTop;
3031 nodeTop->SetDstRect(rectTop);
3032 nodeTop->opaqueRegion_ = Occlusion::Region(rectTop);
3033
3034 curAllSurfaces.emplace_back(nodeBottom);
3035 curAllSurfaces.emplace_back(nodeTop);
3036 VisibleData dstCurVisVec;
3037 std::map<NodeId, RSVisibleLevel> dstPidVisMap;
3038 mainThread->CalcOcclusionImplementation(nullptr, curAllSurfaces, dstCurVisVec, dstPidVisMap);
3039 ASSERT_EQ(nodeBottom->GetOcclusionVisible(), true);
3040 ASSERT_EQ(nodeTop->GetOcclusionVisible(), true);
3041 ASSERT_EQ(nodeBottom->GetVisibleRegion().Size(), 1);
3042 ASSERT_EQ(nodeTop->GetVisibleRegion().Size(), 1);
3043 }
3044
3045 /**
3046 * @tc.name: CalcOcclusionImplementation002
3047 * @tc.desc: calculate occlusion when surfaces partially overlap
3048 * @tc.type: FUNC
3049 * @tc.require: issueI97LXT
3050 */
3051 HWTEST_F(RSMainThreadTest, CalcOcclusionImplementation002, TestSize.Level1)
3052 {
3053 auto mainThread = RSMainThread::Instance();
3054 ASSERT_NE(mainThread, nullptr);
3055 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
3056
3057 NodeId idBottom = 0;
3058 auto nodeBottom = std::make_shared<RSSurfaceRenderNode>(idBottom, mainThread->context_);
3059 nodeBottom->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idBottom);
3060 RectI rectBottom = RectI(0, 0, 100, 100);
3061 nodeBottom->oldDirtyInSurface_ = rectBottom;
3062 nodeBottom->SetDstRect(rectBottom);
3063 nodeBottom->opaqueRegion_ = Occlusion::Region(rectBottom);
3064
3065 NodeId idTop = 1;
3066 auto nodeTop = std::make_shared<RSSurfaceRenderNode>(idTop, mainThread->context_);
3067 nodeTop->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idTop);
3068 RectI rectTop = RectI(50, 50, 100, 100);
3069 nodeTop->oldDirtyInSurface_ = rectTop;
3070 nodeTop->SetDstRect(rectTop);
3071 nodeTop->opaqueRegion_ = Occlusion::Region(rectTop);
3072
3073 curAllSurfaces.emplace_back(nodeBottom);
3074 curAllSurfaces.emplace_back(nodeTop);
3075 VisibleData dstCurVisVec;
3076 std::map<NodeId, RSVisibleLevel> dstPidVisMap;
3077 mainThread->CalcOcclusionImplementation(nullptr, curAllSurfaces, dstCurVisVec, dstPidVisMap);
3078 ASSERT_EQ(nodeBottom->GetOcclusionVisible(), true);
3079 ASSERT_EQ(nodeTop->GetOcclusionVisible(), true);
3080 ASSERT_EQ(nodeBottom->GetVisibleRegion().Size(), 2);
3081 ASSERT_EQ(nodeTop->GetVisibleRegion().Size(), 1);
3082 }
3083
3084 /**
3085 * @tc.name: CalcOcclusionImplementation003
3086 * @tc.desc: calculate occlusion when the bottom node is occluded completely
3087 * @tc.type: FUNC
3088 * @tc.require: issueI97LXT
3089 */
3090 HWTEST_F(RSMainThreadTest, CalcOcclusionImplementation003, TestSize.Level1)
3091 {
3092 auto mainThread = RSMainThread::Instance();
3093 ASSERT_NE(mainThread, nullptr);
3094 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
3095
3096 NodeId idBottom = 0;
3097 auto nodeBottom = std::make_shared<RSSurfaceRenderNode>(idBottom, mainThread->context_);
3098 nodeBottom->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idBottom);
3099 RectI rectBottom = RectI(0, 0, 100, 100);
3100 nodeBottom->oldDirtyInSurface_ = rectBottom;
3101 nodeBottom->SetDstRect(rectBottom);
3102 nodeBottom->opaqueRegion_ = Occlusion::Region(rectBottom);
3103
3104 NodeId idTop = 1;
3105 auto nodeTop = std::make_shared<RSSurfaceRenderNode>(idTop, mainThread->context_);
3106 nodeTop->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idTop);
3107 RectI rectTop = RectI(0, 0, 100, 100);
3108 nodeTop->oldDirtyInSurface_ = rectTop;
3109 nodeTop->SetDstRect(rectTop);
3110 nodeTop->opaqueRegion_ = Occlusion::Region(rectTop);
3111
3112 curAllSurfaces.emplace_back(nodeBottom);
3113 curAllSurfaces.emplace_back(nodeTop);
3114 VisibleData dstCurVisVec;
3115 std::map<NodeId, RSVisibleLevel> dstPidVisMap;
3116 mainThread->CalcOcclusionImplementation(nullptr, curAllSurfaces, dstCurVisVec, dstPidVisMap);
3117 ASSERT_EQ(nodeBottom->GetOcclusionVisible(), false);
3118 ASSERT_EQ(nodeTop->GetOcclusionVisible(), true);
3119 ASSERT_EQ(nodeBottom->GetVisibleRegion().Size(), 0);
3120 ASSERT_EQ(nodeTop->GetVisibleRegion().Size(), 1);
3121 }
3122
3123 /**
3124 * @tc.name: CalcOcclusionImplementation004
3125 * @tc.desc: calculate occlusion when the bottom node is occluded completely, and the top node is transparent
3126 * @tc.type: FUNC
3127 * @tc.require: issueI97LXT
3128 */
3129 HWTEST_F(RSMainThreadTest, CalcOcclusionImplementation004, TestSize.Level1)
3130 {
3131 auto mainThread = RSMainThread::Instance();
3132 ASSERT_NE(mainThread, nullptr);
3133 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
3134
3135 NodeId idBottom = 0;
3136 auto nodeBottom = std::make_shared<RSSurfaceRenderNode>(idBottom, mainThread->context_);
3137 nodeBottom->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idBottom);
3138 RectI rectBottom = RectI(0, 0, 100, 100);
3139 nodeBottom->oldDirtyInSurface_ = rectBottom;
3140 nodeBottom->SetDstRect(rectBottom);
3141 nodeBottom->opaqueRegion_ = Occlusion::Region(rectBottom);
3142
3143 NodeId idTop = 1;
3144 auto nodeTop = std::make_shared<RSSurfaceRenderNode>(idTop, mainThread->context_);
3145 nodeTop->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idTop);
3146 RectI rectTop = RectI(0, 0, 100, 100);
3147 nodeTop->oldDirtyInSurface_ = rectTop;
3148 nodeTop->SetDstRect(rectTop);
3149 // The top node is transparent
3150 nodeTop->SetGlobalAlpha(0.0f);
3151
3152 curAllSurfaces.emplace_back(nodeBottom);
3153 curAllSurfaces.emplace_back(nodeTop);
3154 VisibleData dstCurVisVec;
3155 std::map<NodeId, RSVisibleLevel> dstPidVisMap;
3156 mainThread->CalcOcclusionImplementation(nullptr, curAllSurfaces, dstCurVisVec, dstPidVisMap);
3157 ASSERT_EQ(nodeBottom->GetOcclusionVisible(), true);
3158 ASSERT_EQ(nodeTop->GetOcclusionVisible(), true);
3159 ASSERT_EQ(nodeBottom->GetVisibleRegion().Size(), 1);
3160 ASSERT_EQ(nodeTop->GetVisibleRegion().Size(), 1);
3161 }
3162
3163 /**
3164 * @tc.name: CalcOcclusionImplementation005
3165 * @tc.desc: calculate occlusion when the bottom node is occluded completely,
3166 * And the top node is transparent and filter cache valid
3167 * @tc.type: FUNC
3168 * @tc.require: issueI97LXT
3169 */
3170 HWTEST_F(RSMainThreadTest, CalcOcclusionImplementation005, TestSize.Level1)
3171 {
3172 auto mainThread = RSMainThread::Instance();
3173 ASSERT_NE(mainThread, nullptr);
3174 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
3175
3176 NodeId idBottom = 0;
3177 auto nodeBottom = std::make_shared<RSSurfaceRenderNode>(idBottom, mainThread->context_);
3178 nodeBottom->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idBottom);
3179 RectI rectBottom = RectI(0, 0, 100, 100);
3180 nodeBottom->oldDirtyInSurface_ = rectBottom;
3181 nodeBottom->SetDstRect(rectBottom);
3182 nodeBottom->opaqueRegion_ = Occlusion::Region(rectBottom);
3183
3184 NodeId idTop = 1;
3185 auto nodeTop = std::make_shared<RSSurfaceRenderNode>(idTop, mainThread->context_);
3186 nodeTop->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(idTop);
3187 RectI rectTop = RectI(0, 0, 100, 100);
3188 nodeTop->oldDirtyInSurface_ = rectTop;
3189 nodeTop->SetDstRect(rectTop);
3190 // The top node is transparent
3191 nodeTop->SetGlobalAlpha(0.0f);
3192 nodeTop->isFilterCacheValidForOcclusion_ = true;
3193
3194 curAllSurfaces.emplace_back(nodeBottom);
3195 curAllSurfaces.emplace_back(nodeTop);
3196 VisibleData dstCurVisVec;
3197 std::map<NodeId, RSVisibleLevel> dstPidVisMap;
3198 mainThread->CalcOcclusionImplementation(nullptr, curAllSurfaces, dstCurVisVec, dstPidVisMap);
3199 ASSERT_EQ(nodeBottom->GetOcclusionVisible(), false);
3200 ASSERT_EQ(nodeTop->GetOcclusionVisible(), true);
3201 ASSERT_EQ(nodeBottom->GetVisibleRegion().Size(), 0);
3202 ASSERT_EQ(nodeTop->GetVisibleRegion().Size(), 1);
3203 }
3204
3205 /**
3206 * @tc.name: UpdateDisplayNodeScreenId001
3207 * @tc.desc: UpdateDisplayNodeScreenId, when rootnode is nullptr.
3208 * @tc.type: FUNC
3209 * @tc.require: issueI97LXT
3210 */
3211 HWTEST_F(RSMainThreadTest, UpdateDisplayNodeScreenId001, TestSize.Level1)
3212 {
3213 auto mainThread = RSMainThread::Instance();
3214 ASSERT_NE(mainThread, nullptr);
3215 ASSERT_NE(mainThread->context_, nullptr);
3216 mainThread->context_->globalRootRenderNode_ = nullptr;
3217 mainThread->UpdateDisplayNodeScreenId();
3218 ASSERT_EQ(mainThread->displayNodeScreenId_, DEFAULT_DISPLAY_SCREEN_ID);
3219 }
3220
3221 /**
3222 * @tc.name: UpdateDisplayNodeScreenId002
3223 * @tc.desc: UpdateDisplayNodeScreenId, root node has no child display node.
3224 * @tc.type: FUNC
3225 * @tc.require: issueI97LXT
3226 */
3227 HWTEST_F(RSMainThreadTest, UpdateDisplayNodeScreenId002, TestSize.Level1)
3228 {
3229 auto mainThread = RSMainThread::Instance();
3230 ASSERT_NE(mainThread, nullptr);
3231 ASSERT_NE(mainThread->context_, nullptr);
3232 NodeId id = 1;
3233 mainThread->context_->globalRootRenderNode_ = std::make_shared<RSRenderNode>(id);
3234 mainThread->UpdateDisplayNodeScreenId();
3235 ASSERT_EQ(mainThread->displayNodeScreenId_, DEFAULT_DISPLAY_SCREEN_ID);
3236 }
3237
3238 /**
3239 * @tc.name: UpdateDisplayNodeScreenId003
3240 * @tc.desc: UpdateDisplayNodeScreenId, root node has one child display node.
3241 * @tc.type: FUNC
3242 * @tc.require: issueI97LXT
3243 */
3244 HWTEST_F(RSMainThreadTest, UpdateDisplayNodeScreenId003, TestSize.Level1)
3245 {
3246 auto mainThread = RSMainThread::Instance();
3247 ASSERT_NE(mainThread, nullptr);
3248 NodeId rootId = 0;
3249 ASSERT_NE(mainThread->context_, nullptr);
3250 mainThread->context_->globalRootRenderNode_ = std::make_shared<RSRenderNode>(rootId);
3251 RSDisplayNodeConfig config;
3252 NodeId displayId = 1;
3253 auto displayNode = std::make_shared<RSDisplayRenderNode>(displayId, config);
3254 uint64_t screenId = 1;
3255 displayNode->SetScreenId(screenId);
3256 mainThread->context_->globalRootRenderNode_->AddChild(displayNode);
3257 ASSERT_FALSE(mainThread->context_->globalRootRenderNode_->children_.empty());
3258 mainThread->UpdateDisplayNodeScreenId();
3259 }
3260
3261 /**
3262 * @tc.name: ProcessScreenHotPlugEvents
3263 * @tc.desc: Test ProcessScreenHotPlugEvents
3264 * @tc.type: FUNC
3265 * @tc.require: issueI97LXT
3266 */
3267 HWTEST_F(RSMainThreadTest, ProcessScreenHotPlugEvents, TestSize.Level1)
3268 {
3269 auto mainThread = RSMainThread::Instance();
3270 ASSERT_NE(mainThread, nullptr);
3271 mainThread->ProcessScreenHotPlugEvents();
3272 }
3273
3274 /**
3275 * @tc.name: CheckSurfaceVisChanged001
3276 * @tc.desc: Test CheckSurfaceVisChanged, systemAnimatedScenesList is empty
3277 * @tc.type: FUNC
3278 * @tc.require: issueI97LXT
3279 */
3280 HWTEST_F(RSMainThreadTest, CheckSurfaceVisChanged001, TestSize.Level1)
3281 {
3282 auto mainThread = RSMainThread::Instance();
3283 ASSERT_NE(mainThread, nullptr);
3284 std::map<NodeId, RSVisibleLevel> visMapForVsyncRate;
3285 std::vector<RSBaseRenderNode::SharedPtr> curAllSurfaces;
3286 mainThread->systemAnimatedScenesList_.clear();
3287 mainThread->CheckSurfaceVisChanged(visMapForVsyncRate, curAllSurfaces);
3288 }
3289
3290 /**
3291 * @tc.name: CheckSystemSceneStatus001
3292 * @tc.desc: Test CheckSystemSceneStatus, APPEAR_MISSION_CENTER
3293 * @tc.type: FUNC
3294 * @tc.require: issueI97LXT
3295 */
3296 HWTEST_F(RSMainThreadTest, CheckSystemSceneStatus001, TestSize.Level1)
3297 {
3298 auto mainThread = RSMainThread::Instance();
3299 ASSERT_NE(mainThread, nullptr);
3300 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::APPEAR_MISSION_CENTER);
3301 mainThread->CheckSystemSceneStatus();
3302 }
3303
3304 /**
3305 * @tc.name: CheckSystemSceneStatus002
3306 * @tc.desc: Test CheckSystemSceneStatus, ENTER_TFS_WINDOW
3307 * @tc.type: FUNC
3308 * @tc.require: issueI97LXT
3309 */
3310 HWTEST_F(RSMainThreadTest, CheckSystemSceneStatus002, TestSize.Level1)
3311 {
3312 auto mainThread = RSMainThread::Instance();
3313 ASSERT_NE(mainThread, nullptr);
3314 mainThread->SetSystemAnimatedScenes(SystemAnimatedScenes::ENTER_TFS_WINDOW);
3315 mainThread->CheckSystemSceneStatus();
3316 }
3317
3318 /**
3319 * @tc.name: DoDirectComposition
3320 * @tc.desc: Test DoDirectComposition
3321 * @tc.type: FUNC
3322 * @tc.require: issueI97LXT
3323 */
3324 HWTEST_F(RSMainThreadTest, DoDirectComposition, TestSize.Level1)
3325 {
3326 auto mainThread = RSMainThread::Instance();
3327 ASSERT_NE(mainThread, nullptr);
3328 NodeId rootId = 0;
3329 auto rootNode = std::make_shared<RSBaseRenderNode>(rootId);
3330 NodeId displayId = 1;
3331 RSDisplayNodeConfig config;
3332 auto displayNode = std::make_shared<RSDisplayRenderNode>(displayId, config);
3333 rootNode->AddChild(displayNode);
3334 mainThread->DoDirectComposition(rootNode, false);
3335 }
3336
3337 /**
3338 * @tc.name: UpdateNeedDrawFocusChange001
3339 * @tc.desc: test UpdateNeedDrawFocusChange while node don't has parent
3340 * @tc.type: FUNC
3341 * @tc.require: issueI9LOXQ
3342 */
3343 HWTEST_F(RSMainThreadTest, UpdateNeedDrawFocusChange001, TestSize.Level2)
3344 {
3345 auto mainThread = RSMainThread::Instance();
3346 ASSERT_NE(mainThread, nullptr);
3347
3348 NodeId id = 0;
3349 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3350 ASSERT_NE(node, nullptr);
3351
3352 ASSERT_NE(mainThread->context_, nullptr);
3353 mainThread->context_->nodeMap.renderNodeMap_[node->GetId()] = node;
3354 mainThread->UpdateNeedDrawFocusChange(id);
3355 ASSERT_TRUE(node->GetNeedDrawFocusChange());
3356 }
3357
3358 /**
3359 * @tc.name: UpdateNeedDrawFocusChange002
3360 * @tc.desc: test UpdateNeedDrawFocusChange while node's parent isn't leash window
3361 * @tc.type: FUNC
3362 * @tc.require: issueI9LOXQ
3363 */
3364 HWTEST_F(RSMainThreadTest, UpdateNeedDrawFocusChange002, TestSize.Level2)
3365 {
3366 auto mainThread = RSMainThread::Instance();
3367 ASSERT_NE(mainThread, nullptr);
3368
3369 NodeId id = 0;
3370 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3371 auto parentNode = std::make_shared<RSSurfaceRenderNode>(id + 1, mainThread->context_);
3372 ASSERT_NE(node, nullptr);
3373 ASSERT_NE(parentNode, nullptr);
3374 parentNode->AddChild(node);
3375 parentNode->SetSurfaceNodeType(RSSurfaceNodeType::APP_WINDOW_NODE);
3376
3377 ASSERT_NE(mainThread->context_, nullptr);
3378 mainThread->context_->nodeMap.renderNodeMap_[node->GetId()] = node;
3379 mainThread->context_->nodeMap.renderNodeMap_[parentNode->GetId()] = parentNode;
3380 mainThread->UpdateNeedDrawFocusChange(id);
3381 ASSERT_TRUE(node->GetNeedDrawFocusChange());
3382 }
3383
3384 /**
3385 * @tc.name: UpdateNeedDrawFocusChange003
3386 * @tc.desc: test UpdateNeedDrawFocusChange while node's parent is leash window
3387 * @tc.type: FUNC
3388 * @tc.require: issueI9LOXQ
3389 */
3390 HWTEST_F(RSMainThreadTest, UpdateNeedDrawFocusChange003, TestSize.Level2)
3391 {
3392 auto mainThread = RSMainThread::Instance();
3393 ASSERT_NE(mainThread, nullptr);
3394
3395 NodeId id = 0;
3396 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3397 auto parentNode = std::make_shared<RSSurfaceRenderNode>(id + 1, mainThread->context_);
3398 ASSERT_NE(node, nullptr);
3399 ASSERT_NE(parentNode, nullptr);
3400 parentNode->AddChild(node);
3401 parentNode->SetSurfaceNodeType(RSSurfaceNodeType::LEASH_WINDOW_NODE);
3402
3403 ASSERT_NE(mainThread->context_, nullptr);
3404 mainThread->context_->nodeMap.renderNodeMap_[node->GetId()] = node;
3405 mainThread->context_->nodeMap.renderNodeMap_[parentNode->GetId()] = parentNode;
3406 mainThread->UpdateNeedDrawFocusChange(id);
3407 ASSERT_FALSE(node->GetNeedDrawFocusChange());
3408 }
3409
3410 /**
3411 * @tc.name: UpdateFocusNodeId001
3412 * @tc.desc: test UpdateFocusNodeId while focusNodeId don't change
3413 * @tc.type: FUNC
3414 * @tc.require: issueI9LOXQ
3415 */
3416 HWTEST_F(RSMainThreadTest, UpdateFocusNodeId001, TestSize.Level2)
3417 {
3418 auto mainThread = RSMainThread::Instance();
3419 ASSERT_NE(mainThread, nullptr);
3420
3421 NodeId id = 0;
3422 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3423 ASSERT_NE(node, nullptr);
3424
3425 ASSERT_NE(mainThread->context_, nullptr);
3426 mainThread->context_->nodeMap.renderNodeMap_[node->GetId()] = node;
3427 mainThread->focusNodeId_ = id;
3428 mainThread->UpdateFocusNodeId(id);
3429 ASSERT_EQ(mainThread->GetFocusNodeId(), id);
3430 }
3431
3432 /**
3433 * @tc.name: UpdateFocusNodeId002
3434 * @tc.desc: test UpdateFocusNodeId while newfocusNodeId is invalid
3435 * @tc.type: FUNC
3436 * @tc.require: issueI9LOXQ
3437 */
3438 HWTEST_F(RSMainThreadTest, UpdateFocusNodeId002, TestSize.Level2)
3439 {
3440 auto mainThread = RSMainThread::Instance();
3441 ASSERT_NE(mainThread, nullptr);
3442
3443 NodeId id = 0;
3444 auto node = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3445 ASSERT_NE(node, nullptr);
3446
3447 ASSERT_NE(mainThread->context_, nullptr);
3448 mainThread->context_->nodeMap.renderNodeMap_[node->GetId()] = node;
3449 mainThread->focusNodeId_ = id;
3450 mainThread->UpdateFocusNodeId(INVALID_NODEID);
3451 ASSERT_EQ(mainThread->GetFocusNodeId(), id);
3452 }
3453
3454 /**
3455 * @tc.name: UpdateFocusNodeId003
3456 * @tc.desc: test UpdateFocusNodeId while focus node change
3457 * @tc.type: FUNC
3458 * @tc.require: issueI9LOXQ
3459 */
3460 HWTEST_F(RSMainThreadTest, UpdateFocusNodeId003, TestSize.Level2)
3461 {
3462 auto mainThread = RSMainThread::Instance();
3463 ASSERT_NE(mainThread, nullptr);
3464
3465 NodeId id = 0;
3466 auto oldFocusNode = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3467 auto newFocusNode = std::make_shared<RSSurfaceRenderNode>(id + 1, mainThread->context_);
3468 ASSERT_NE(oldFocusNode, nullptr);
3469 ASSERT_NE(newFocusNode, nullptr);
3470
3471 mainThread->context_->nodeMap.renderNodeMap_[oldFocusNode->GetId()] = oldFocusNode;
3472 mainThread->context_->nodeMap.renderNodeMap_[newFocusNode->GetId()] = newFocusNode;
3473 mainThread->focusNodeId_ = oldFocusNode->GetId();
3474 mainThread->UpdateFocusNodeId(newFocusNode->GetId());
3475 ASSERT_EQ(mainThread->GetFocusNodeId(), newFocusNode->GetId());
3476 }
3477
3478 /**
3479 * @tc.name: UiCaptureTasks
3480 * @tc.desc: test UiCaptureTasks processing
3481 * @tc.type: FUNC
3482 * @tc.require: issueIA6QID
3483 */
3484 HWTEST_F(RSMainThreadTest, UiCaptureTasks, TestSize.Level2)
3485 {
3486 auto mainThread = RSMainThread::Instance();
3487 ASSERT_NE(mainThread, nullptr);
3488
3489 auto node1 = RSTestUtil::CreateSurfaceNode();
3490 auto node2 = RSTestUtil::CreateSurfaceNode();
__anon22dae5050502() 3491 auto task = []() {};
3492
3493 mainThread->ProcessUiCaptureTasks();
3494 ASSERT_EQ(mainThread->pendingUiCaptureTasks_.empty(), true);
3495
3496 mainThread->context_->nodeMap.RegisterRenderNode(node1);
3497 mainThread->AddUiCaptureTask(node1->GetId(), task);
3498 mainThread->AddUiCaptureTask(node2->GetId(), task);
3499 ASSERT_EQ(mainThread->pendingUiCaptureTasks_.empty(), false);
3500 ASSERT_EQ(mainThread->uiCaptureTasks_.empty(), true);
3501
3502 mainThread->PrepareUiCaptureTasks(nullptr);
3503 ASSERT_EQ(mainThread->pendingUiCaptureTasks_.empty(), true);
3504 ASSERT_EQ(mainThread->uiCaptureTasks_.empty(), false);
3505
3506 mainThread->ProcessUiCaptureTasks();
3507 ASSERT_EQ(mainThread->pendingUiCaptureTasks_.empty(), true);
3508 ASSERT_EQ(mainThread->uiCaptureTasks_.empty(), true);
3509
3510 mainThread->context_->nodeMap.UnregisterRenderNode(node1->GetId());
3511 }
3512
3513 /**
3514 * @tc.name: CheckUIExtensionCallbackDataChanged001
3515 * @tc.desc: test CheckUIExtensionCallbackDataChanged, no need to callback (2 frames of empty callback data)
3516 * @tc.type: FUNC
3517 * @tc.require: issueIABHAX
3518 */
3519 HWTEST_F(RSMainThreadTest, UIExtensionNodesTraverseAndCallback001, TestSize.Level2)
3520 {
3521 auto mainThread = RSMainThread::Instance();
3522 ASSERT_NE(mainThread, nullptr);
3523 mainThread->lastFrameUIExtensionDataEmpty_ = true;
3524 mainThread->uiExtensionCallbackData_.clear();
3525 ASSERT_FALSE(mainThread->CheckUIExtensionCallbackDataChanged());
3526 }
3527
3528 /**
3529 * @tc.name: CheckUIExtensionCallbackDataChanged002
3530 * @tc.desc: test CheckUIExtensionCallbackDataChanged, first frame of empty callbackdata, need to callback
3531 * @tc.type: FUNC
3532 * @tc.require: issueIABHAX
3533 */
3534 HWTEST_F(RSMainThreadTest, CheckUIExtensionCallbackDataChanged002, TestSize.Level2)
3535 {
3536 auto mainThread = RSMainThread::Instance();
3537 ASSERT_NE(mainThread, nullptr);
3538 mainThread->lastFrameUIExtensionDataEmpty_ = false;
3539 mainThread->uiExtensionCallbackData_.clear();
3540 ASSERT_TRUE(mainThread->CheckUIExtensionCallbackDataChanged());
3541 }
3542
3543 /**
3544 * @tc.name: IsHardwareEnabledNodesNeedSync
3545 * @tc.desc: test IsHardwareEnabledNodesNeedSync
3546 * @tc.type: FUNC
3547 * @tc.require:
3548 */
3549 HWTEST_F(RSMainThreadTest, IsHardwareEnabledNodesNeedSync, TestSize.Level2)
3550 {
3551 NodeId id = 1;
3552 auto mainThread = RSMainThread::Instance();
3553 ASSERT_NE(mainThread, nullptr);
3554
3555 mainThread->hardwareEnabledNodes_.emplace_back(nullptr);
3556 ASSERT_EQ(mainThread->IsHardwareEnabledNodesNeedSync(), false);
3557
3558 mainThread->hardwareEnabledNodes_.clear();
3559 mainThread->doDirectComposition_ = false;
3560 auto node1 = std::make_shared<RSSurfaceRenderNode>(id, mainThread->context_);
3561 node1->stagingRenderParams_ = nullptr;
3562 mainThread->hardwareEnabledNodes_.emplace_back(node1);
3563 ASSERT_EQ(mainThread->IsHardwareEnabledNodesNeedSync(), false);
3564
3565 mainThread->hardwareEnabledNodes_.clear();
3566 mainThread->doDirectComposition_ = false;
3567 auto node2 = std::make_shared<RSSurfaceRenderNode>(id + 1, mainThread->context_);
3568 node2->stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(id + 2);
3569 node2->stagingRenderParams_->SetNeedSync(true);
3570 mainThread->hardwareEnabledNodes_.emplace_back(node2);
3571 ASSERT_EQ(mainThread->IsHardwareEnabledNodesNeedSync(), true);
3572
3573 mainThread->hardwareEnabledNodes_.clear();
3574 mainThread->doDirectComposition_ = true;
3575 auto node3 = std::make_shared<RSSurfaceRenderNode>(id + 3, mainThread->context_);
3576 node3->SetHardwareForcedDisabledState(false);
3577 RectI dstRect{0, 0, 400, 600};
3578 node3->SetDstRect(dstRect);
3579 mainThread->hardwareEnabledNodes_.emplace_back(node3);
3580 ASSERT_EQ(mainThread->IsHardwareEnabledNodesNeedSync(), true);
3581 }
3582
3583 /**
3584 * @tc.name: SendClientDumpNodeTreeCommands
3585 * @tc.desc: test SendClientDumpNodeTreeCommands
3586 * @tc.type: FUNC
3587 * @tc.require: issueIAKME2
3588 */
3589 HWTEST_F(RSMainThreadTest, SendClientDumpNodeTreeCommands, TestSize.Level2)
3590 {
3591 auto mainThread = RSMainThread::Instance();
3592 ASSERT_NE(mainThread, nullptr);
3593 ASSERT_NE(mainThread->context_, nullptr);
3594 mainThread->nodeTreeDumpTasks_.clear();
3595
3596 NodeId testId = 1;
3597 auto rootNode = mainThread->context_->globalRootRenderNode_;
3598 auto displayNode = std::make_shared<RSDisplayRenderNode>(testId++, RSDisplayNodeConfig {});
3599 rootNode->AddChild(displayNode);
3600 auto node1 = std::make_shared<RSRenderNode>(testId++);
3601 displayNode->AddChild(node1);
3602 rootNode->GenerateFullChildrenList();
3603 displayNode->GenerateFullChildrenList();
3604
3605 auto node2 = std::make_shared<RSSurfaceRenderNode>(testId++, mainThread->context_);
3606 node1->AddChild(node2);
3607 auto node3 = std::make_shared<RSRootRenderNode>(testId++, mainThread->context_);
3608 node2->AddChild(node3);
3609 node3->SetIsOnTheTree(true);
3610 mainThread->context_->GetMutableNodeMap().FilterNodeByPid(0);
3611 mainThread->context_->GetMutableNodeMap().RegisterRenderNode(node3);
3612
3613 uint32_t taskId = 0;
3614 sptr<ApplicationAgentImpl> agent = new ApplicationAgentImpl();
3615 mainThread->RegisterApplicationAgent(0, agent);
3616 mainThread->SendClientDumpNodeTreeCommands(taskId);
3617 ASSERT_TRUE(!mainThread->nodeTreeDumpTasks_.empty());
3618 ASSERT_TRUE(mainThread->nodeTreeDumpTasks_[taskId].count > 0);
3619
3620 mainThread->SendClientDumpNodeTreeCommands(taskId);
3621 rootNode->RemoveChild(displayNode);
3622 }
3623
3624 /**
3625 * @tc.name: CollectClientNodeTreeResult
3626 * @tc.desc: test CollectClientNodeTreeResult
3627 * @tc.type: FUNC
3628 * @tc.require: issueIAKME2
3629 */
3630 HWTEST_F(RSMainThreadTest, CollectClientNodeTreeResult, TestSize.Level2)
3631 {
3632 auto mainThread = RSMainThread::Instance();
3633 ASSERT_NE(mainThread, nullptr);
3634 mainThread->nodeTreeDumpTasks_.clear();
3635
3636 uint32_t taskId = 0;
3637 auto& task = mainThread->nodeTreeDumpTasks_[taskId];
3638 task.data[0] = "testData";
3639 task.count++;
3640
3641 std::string out;
3642 mainThread->CollectClientNodeTreeResult(taskId, out, 1);
3643 ASSERT_TRUE(!out.empty());
3644 ASSERT_TRUE(mainThread->nodeTreeDumpTasks_.empty());
3645 }
3646
3647 /**
3648 * @tc.name: OnDumpClientNodeTree
3649 * @tc.desc: test OnDumpClientNodeTree
3650 * @tc.type: FUNC
3651 * @tc.require: issueIAKME2
3652 */
3653 HWTEST_F(RSMainThreadTest, OnCommitDumpClientNodeTree, TestSize.Level2)
3654 {
3655 auto mainThread = RSMainThread::Instance();
3656 ASSERT_NE(mainThread, nullptr);
3657 mainThread->nodeTreeDumpTasks_.clear();
3658
3659 uint32_t taskId = 0;
3660 mainThread->OnCommitDumpClientNodeTree(0, 0, taskId, "testData");
3661 ASSERT_TRUE(mainThread->nodeTreeDumpTasks_.empty());
3662
3663 auto& task = mainThread->nodeTreeDumpTasks_[taskId];
3664 task.count++;
3665
3666 mainThread->OnCommitDumpClientNodeTree(0, 0, taskId, "testData");
3667 mainThread->OnCommitDumpClientNodeTree(0, 0, taskId, "testData");
3668 ASSERT_TRUE(!mainThread->nodeTreeDumpTasks_.empty());
3669 ASSERT_TRUE(!mainThread->nodeTreeDumpTasks_[taskId].data.empty());
3670 }
3671 } // namespace OHOS::Rosen
3672