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