• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "pipeline/rs_screen_render_node.h"
17 
18 #include "common/rs_obj_abs_geometry.h"
19 #include "common/rs_optional_trace.h"
20 #include "common/rs_special_layer_manager.h"
21 #include "params/rs_screen_render_params.h"
22 #include "pipeline/rs_render_node.h"
23 #include "pipeline/rs_surface_render_node.h"
24 #include "platform/common/rs_log.h"
25 #include "screen_manager/screen_types.h"
26 #include "visitor/rs_node_visitor.h"
27 #include "transaction/rs_render_service_client.h"
28 namespace OHOS {
29 namespace Rosen {
30 constexpr int64_t MAX_JITTER_NS = 2000000; // 2ms
31 
32 namespace {
SelectBigGamut(GraphicColorGamut oldGamut,GraphicColorGamut newGamut)33 GraphicColorGamut SelectBigGamut(GraphicColorGamut oldGamut, GraphicColorGamut newGamut)
34 {
35     if (oldGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
36         return oldGamut;
37     }
38     if (oldGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
39         if (newGamut == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
40             return newGamut;
41         } else {
42             return oldGamut;
43         }
44     }
45     return newGamut;
46 }
47 }
48 
RSScreenRenderNode(NodeId id,ScreenId screenId,const std::weak_ptr<RSContext> & context)49 RSScreenRenderNode::RSScreenRenderNode(
50     NodeId id, ScreenId screenId, const std::weak_ptr<RSContext>& context)
51     : RSRenderNode(id, context), screenId_(screenId), dirtyManager_(std::make_shared<RSDirtyRegionManager>(true))
52 {
53     RS_LOGI("RSScreen RSScreenRenderNode ctor id:%{public}" PRIu64 ", config[screenid:%{public}" PRIu64,
54         id, screenId_);
55     MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
56     MemoryTrack::Instance().AddNodeRecord(id, info);
57     MemorySnapshot::Instance().AddCpuMemory(ExtractPid(id), sizeof(*this));
58 }
59 
~RSScreenRenderNode()60 RSScreenRenderNode::~RSScreenRenderNode()
61 {
62     RS_LOGI("RSScreen RSScreenRenderNode dtor id:%{public}" PRIu64 ", screenId:%{public}" PRIu64, GetId(), screenId_);
63     MemoryTrack::Instance().RemoveNodeRecord(GetId());
64     MemorySnapshot::Instance().RemoveCpuMemory(ExtractPid(GetId()), sizeof(*this));
65 }
66 
CollectSurface(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<RSBaseRenderNode::SharedPtr> & vec,bool isUniRender,bool onlyFirstLevel)67 void RSScreenRenderNode::CollectSurface(
68     const std::shared_ptr<RSBaseRenderNode>& node, std::vector<RSBaseRenderNode::SharedPtr>& vec, bool isUniRender,
69     bool onlyFirstLevel)
70 {
71     for (auto& child : *node->GetSortedChildren()) {
72         child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
73     }
74 }
75 
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)76 void RSScreenRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
77 {
78     if (!visitor) {
79         return;
80     }
81     ApplyModifiers();
82     visitor->QuickPrepareScreenRenderNode(*this);
83 }
84 
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)85 void RSScreenRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
86 {
87     if (!visitor) {
88         return;
89     }
90     ApplyModifiers();
91     visitor->PrepareScreenRenderNode(*this);
92 }
93 
Process(const std::shared_ptr<RSNodeVisitor> & visitor)94 void RSScreenRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
95 {
96     if (!visitor) {
97         return;
98     }
99     RSRenderNode::RenderTraceDebug();
100     visitor->ProcessScreenRenderNode(*this);
101 }
102 
SetIsOnTheTree(bool flag,NodeId instanceRootNodeId,NodeId firstLevelNodeId,NodeId cacheNodeId,NodeId uifirstRootNodeId,NodeId screenNodeId,NodeId logicalDisplayNodeId)103 void RSScreenRenderNode::SetIsOnTheTree(bool flag, NodeId instanceRootNodeId, NodeId firstLevelNodeId,
104     NodeId cacheNodeId, NodeId uifirstRootNodeId, NodeId screenNodeId, NodeId logicalDisplayNodeId)
105 {
106     // if node is marked as cacheRoot, update subtree status when update surface
107     // in case prepare stage upper cacheRoot cannot specify dirty subnode
108     RSRenderNode::SetIsOnTheTree(flag, GetId(), firstLevelNodeId, cacheNodeId, uifirstRootNodeId, GetId(),
109         logicalDisplayNodeId);
110 }
111 
SetForceSoftComposite(bool flag)112 void RSScreenRenderNode::SetForceSoftComposite(bool flag)
113 {
114     forceSoftComposite_ = flag;
115 }
116 
SetMirrorSource(SharedPtr node)117 void RSScreenRenderNode::SetMirrorSource(SharedPtr node)
118 {
119     if (!isMirroredScreen_ || node == nullptr || node == mirrorSource_.lock()) {
120         return;
121     }
122 
123     if (auto mirrorSource = mirrorSource_.lock()) {
124         mirrorSource->SetHasMirrorScreen(false);
125     }
126     node->SetHasMirrorScreen(true);
127     mirrorSource_ = node;
128 }
129 
ResetMirrorSource()130 void RSScreenRenderNode::ResetMirrorSource()
131 {
132     if (auto mirrorSource = mirrorSource_.lock()) {
133         mirrorSource->SetHasMirrorScreen(false);
134     }
135     mirrorSource_.reset();
136 }
137 
SetIsMirrorScreen(bool isMirror)138 void RSScreenRenderNode::SetIsMirrorScreen(bool isMirror)
139 {
140     if (isMirroredScreen_ != isMirror) {
141         hasMirroredScreenChanged_ = true;
142     }
143     isMirroredScreen_ = isMirror;
144 }
145 
InitRenderParams()146 void RSScreenRenderNode::InitRenderParams()
147 {
148 #ifdef RS_ENABLE_GPU
149     stagingRenderParams_ = std::make_unique<RSScreenRenderParams>(GetId());
150     DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(shared_from_this());
151     if (renderDrawable_ == nullptr) {
152         RS_LOGE("RSScreenRenderNode::InitRenderParams failed");
153         return;
154     }
155 #endif
156 }
157 
158 ReleaseDmaBufferTask RSScreenRenderNode::releaseScreenDmaBufferTask_;
SetReleaseTask(ReleaseDmaBufferTask callback)159 void RSScreenRenderNode::SetReleaseTask(ReleaseDmaBufferTask callback)
160 {
161     if (!releaseScreenDmaBufferTask_ && callback) {
162         releaseScreenDmaBufferTask_ = callback;
163     } else {
164         RS_LOGE("RreleaseScreenDmaBufferTask_ register failed!");
165     }
166 }
167 
OnSync()168 void RSScreenRenderNode::OnSync()
169 {
170 #ifdef RS_ENABLE_GPU
171     RS_OPTIONAL_TRACE_NAME_FMT("RSScreenRenderNode::OnSync global dirty[%s]",
172         dirtyManager_->GetCurrentFrameDirtyRegion().ToString().c_str());
173     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
174     if (screenParams == nullptr) {
175         RS_LOGE("RSScreenRenderNode::OnSync screenParams is null");
176         return;
177     }
178     if (!renderDrawable_) {
179         return;
180     }
181     auto syncDirtyManager = renderDrawable_->GetSyncDirtyManager();
182     dirtyManager_->OnSync(syncDirtyManager);
183     screenParams->SetZoomed(curZoomState_);
184     screenParams->SetNeedSync(true);
185     RSRenderNode::OnSync();
186 #endif
187 }
188 
HandleCurMainAndLeashSurfaceNodes()189 void RSScreenRenderNode::HandleCurMainAndLeashSurfaceNodes()
190 {
191     surfaceCountForMultiLayersPerf_ = 0;
192     for (const auto& surface : curMainAndLeashSurfaceNodes_) {
193         auto surfaceNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(surface);
194         if (!surfaceNode || surfaceNode->IsLeashWindow() || !surfaceNode->IsOnTheTree()) {
195             continue;
196         }
197         surfaceCountForMultiLayersPerf_++;
198     }
199     curMainAndLeashSurfaceNodes_.clear();
200 }
201 
UpdateRenderParams()202 void RSScreenRenderNode::UpdateRenderParams()
203 {
204 #ifdef RS_ENABLE_GPU
205     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
206     if (screenParams == nullptr) {
207         RS_LOGE("RSScreenRenderNode::UpdateRenderParams ScreenParams is null");
208         return;
209     }
210     auto mirroredNode = GetMirrorSource().lock();
211     if (mirroredNode) {
212         screenParams->mirrorSourceDrawable_ = mirroredNode->GetRenderDrawable();
213     } else {
214         screenParams->mirrorSourceDrawable_.reset();
215     }
216     screenParams->childDisplayCount_ = GetChildrenCount();
217     screenParams->screenInfo_ = screenInfo_;
218     screenParams->logicalDisplayNodeDrawables_ = std::move(logicalDisplayNodeDrawables_);
219     screenParams->roundCornerSurfaceDrawables_.clear();
220     if (rcdSurfaceNodeTop_ && rcdSurfaceNodeTop_->GetRenderDrawable() != nullptr) {
221         screenParams->roundCornerSurfaceDrawables_.push_back(rcdSurfaceNodeTop_->GetRenderDrawable());
222     }
223     if (rcdSurfaceNodeBottom_ && rcdSurfaceNodeBottom_->GetRenderDrawable() != nullptr) {
224         screenParams->roundCornerSurfaceDrawables_.push_back(rcdSurfaceNodeBottom_->GetRenderDrawable());
225     }
226     RSRenderNode::UpdateRenderParams();
227 #endif
228 }
229 
UpdateScreenRenderParams()230 void RSScreenRenderNode::UpdateScreenRenderParams()
231 {
232     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
233     if (screenParams == nullptr) {
234         RS_LOGE("RSScreenRenderNode::UpdateScreenRenderParams screenParams is null");
235         return;
236     }
237     screenParams->compositeType_ = GetCompositeType();
238     screenParams->hasChildCrossNode_ = HasChildCrossNode();
239     screenParams->isMirrorScreen_ = IsMirrorScreen();
240     screenParams->isFirstVisitCrossNodeDisplay_ = IsFirstVisitCrossNodeDisplay();
241 }
242 
UpdatePartialRenderParams()243 void RSScreenRenderNode::UpdatePartialRenderParams()
244 {
245     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
246     if (screenParams == nullptr) {
247         RS_LOGE("RSScreenRenderNode::UpdatePartialRenderParams screenParams is null");
248         return;
249     }
250     screenParams->SetAllMainAndLeashSurfaces(curMainAndLeashSurfaceNodes_);
251 }
252 
SkipFrame(uint32_t refreshRate,uint32_t skipFrameInterval)253 bool RSScreenRenderNode::SkipFrame(uint32_t refreshRate, uint32_t skipFrameInterval)
254 {
255     if (refreshRate == 0 || skipFrameInterval <= 1) {
256         return false;
257     }
258     int64_t currentTime = std::chrono::duration_cast<std::chrono::nanoseconds>(
259         std::chrono::steady_clock::now().time_since_epoch()).count();
260     // when refreshRate % skipFrameInterval != 0 means the skipFrameInterval is the virtual screen refresh rate
261     if (refreshRate % skipFrameInterval != 0) {
262         int64_t minFrameInterval = 1000000000LL / skipFrameInterval;
263         if (minFrameInterval == 0) {
264             return false;
265         }
266         // lastRefreshTime_ is next frame expected refresh time for virtual Display
267         if (lastRefreshTime_ <= 0) {
268             lastRefreshTime_ = currentTime + minFrameInterval;
269             return false;
270         }
271         if (currentTime < (lastRefreshTime_ - MAX_JITTER_NS)) {
272             return true;
273         }
274         int64_t intervalNums = (currentTime - lastRefreshTime_ + MAX_JITTER_NS) / minFrameInterval;
275         lastRefreshTime_ += (intervalNums + 1) * minFrameInterval;
276         return false;
277     }
278     // the skipFrameInterval is equal to 60 divide the virtual screen refresh rate
279     int64_t refreshInterval = currentTime - lastRefreshTime_;
280     // 1000000000ns == 1s, 110/100 allows 10% over.
281     bool needSkip = refreshInterval < (1000000000LL / refreshRate) * (skipFrameInterval - 1) * 110 / 100;
282     if (!needSkip) {
283         lastRefreshTime_ = currentTime;
284     }
285     return needSkip;
286 }
287 
SetDisplayGlobalZOrder(float zOrder)288 void RSScreenRenderNode::SetDisplayGlobalZOrder(float zOrder)
289 {
290     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
291     if (screenParams == nullptr) {
292         RS_LOGE("RSScreenRenderNode::SetDisplayGlobalZOrder screenParams is null");
293         return;
294     }
295     screenParams->SetGlobalZOrder(zOrder);
296 }
297 
UpdateDisplayDirtyManager(int32_t bufferage,bool useAlignedDirtyRegion)298 void RSScreenRenderNode::UpdateDisplayDirtyManager(int32_t bufferage, bool useAlignedDirtyRegion)
299 {
300     dirtyManager_->SetBufferAge(bufferage);
301     dirtyManager_->UpdateDirty(useAlignedDirtyRegion);
302 }
303 
ClearCurrentSurfacePos()304 void RSScreenRenderNode::ClearCurrentSurfacePos()
305 {
306     lastFrameSurfacePos_ = std::move(currentFrameSurfacePos_);
307     lastFrameSurfacesByDescZOrder_ = std::move(currentFrameSurfacesByDescZOrder_);
308 }
309 
SetMainAndLeashSurfaceDirty(bool isDirty)310 void RSScreenRenderNode::SetMainAndLeashSurfaceDirty(bool isDirty)
311 {
312     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
313     if (screenParams == nullptr) {
314         RS_LOGE("%{public}s screenParams is nullptr", __func__);
315         return;
316     }
317     screenParams->SetMainAndLeashSurfaceDirty(isDirty);
318     if (stagingRenderParams_->NeedSync()) {
319         AddToPendingSyncList();
320     }
321 }
322 
SetNeedForceUpdateHwcNodes(bool needForceUpdate,bool hasVisibleHwcNodes)323 void RSScreenRenderNode::SetNeedForceUpdateHwcNodes(bool needForceUpdate, bool hasVisibleHwcNodes)
324 {
325     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
326     if (screenParams == nullptr) {
327         return;
328     }
329     HwcDisplayRecorder().SetNeedForceUpdateHwcNodes(needForceUpdate);
330     HwcDisplayRecorder().SetHasVisibleHwcNodes(hasVisibleHwcNodes);
331     screenParams->SetNeedForceUpdateHwcNodes(needForceUpdate);
332     if (stagingRenderParams_->NeedSync()) {
333         AddToPendingSyncList();
334     }
335 }
336 
SetFingerprint(bool hasFingerprint)337 void RSScreenRenderNode::SetFingerprint(bool hasFingerprint)
338 {
339 #ifdef RS_ENABLE_GPU
340     if (hasFingerprint_ == hasFingerprint) {
341         return;
342     }
343     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
344     if (screenParams == nullptr) {
345         RS_LOGE("%{public}s screenParams is nullptr", __func__);
346         return;
347     }
348     screenParams->SetFingerprint(hasFingerprint);
349     if (stagingRenderParams_->NeedSync()) {
350         AddToPendingSyncList();
351     }
352     hasFingerprint_ = hasFingerprint;
353 #endif
354 }
355 
SetFixVirtualBuffer10Bit(bool isFixVirtualBuffer10Bit)356 void RSScreenRenderNode::SetFixVirtualBuffer10Bit(bool isFixVirtualBuffer10Bit)
357 {
358     if (isFixVirtualBuffer10Bit_ == isFixVirtualBuffer10Bit) {
359         return;
360     }
361     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
362     if (screenParams == nullptr) {
363         RS_LOGE("%{public}s screenParams is nullptr", __func__);
364         return;
365     }
366     screenParams->SetFixVirtualBuffer10Bit(isFixVirtualBuffer10Bit);
367     if (stagingRenderParams_->NeedSync()) {
368         AddToPendingSyncList();
369     }
370     isFixVirtualBuffer10Bit_ = isFixVirtualBuffer10Bit;
371 }
372 
GetFixVirtualBuffer10Bit() const373 bool RSScreenRenderNode::GetFixVirtualBuffer10Bit() const
374 {
375     return isFixVirtualBuffer10Bit_;
376 }
377 
SetExistHWCNode(bool existHWCNode)378 void RSScreenRenderNode::SetExistHWCNode(bool existHWCNode)
379 {
380     if (existHWCNode_ == existHWCNode) {
381         return;
382     }
383     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
384     if (screenParams == nullptr) {
385         RS_LOGE("%{public}s screenParams is nullptr", __func__);
386         return;
387     }
388     screenParams->SetExistHWCNode(existHWCNode);
389     if (stagingRenderParams_->NeedSync()) {
390         AddToPendingSyncList();
391     }
392     existHWCNode_ = existHWCNode;
393 }
394 
GetExistHWCNode() const395 bool RSScreenRenderNode::GetExistHWCNode() const
396 {
397     return existHWCNode_;
398 }
399 
SetHDRPresent(bool hdrPresent)400 void RSScreenRenderNode::SetHDRPresent(bool hdrPresent)
401 {
402 #ifdef RS_ENABLE_GPU
403     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
404     if (screenParams == nullptr) {
405         RS_LOGE("%{public}s screenParams is nullptr", __func__);
406         return;
407     }
408     screenParams->SetHDRStatusChanged(screenParams->GetHDRPresent() != hdrPresent);
409     screenParams->SetHDRPresent(hdrPresent);
410     if (stagingRenderParams_->NeedSync()) {
411         AddToPendingSyncList();
412     }
413 #endif
414 }
415 
SetBrightnessRatio(float brightnessRatio)416 void RSScreenRenderNode::SetBrightnessRatio(float brightnessRatio)
417 {
418 #ifdef RS_ENABLE_GPU
419     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
420     if (screenParams == nullptr) {
421         RS_LOGE("%{public}s screenParams is nullptr", __func__);
422         return;
423     }
424     screenParams->SetBrightnessRatio(brightnessRatio);
425     if (stagingRenderParams_->NeedSync()) {
426         AddToPendingSyncList();
427     }
428 #endif
429 }
430 
SetColorSpace(const GraphicColorGamut & colorSpace)431 void RSScreenRenderNode::SetColorSpace(const GraphicColorGamut& colorSpace)
432 {
433 #ifdef RS_ENABLE_GPU
434     if (colorSpace_ == colorSpace) {
435         return;
436     }
437     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
438     if (screenParams == nullptr) {
439         RS_LOGE("%{public}s screenParams is nullptr", __func__);
440         return;
441     }
442     screenParams->SetNewColorSpace(colorSpace);
443     if (stagingRenderParams_->NeedSync()) {
444         AddToPendingSyncList();
445     }
446     colorSpace_ = colorSpace;
447 #endif
448 }
449 
UpdateColorSpace(const GraphicColorGamut & colorSpace)450 void RSScreenRenderNode::UpdateColorSpace(const GraphicColorGamut& colorSpace)
451 {
452     GraphicColorGamut newColorSpace = SelectBigGamut(colorSpace_, colorSpace);
453     if (colorSpace_ == newColorSpace) {
454         return;
455     }
456     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
457     if (screenParams == nullptr) {
458         RS_LOGE("%{public}s displayParams is nullptr", __func__);
459         return;
460     }
461     screenParams->SetNewColorSpace(newColorSpace);
462     if (stagingRenderParams_->NeedSync()) {
463         AddToPendingSyncList();
464     }
465     colorSpace_ = newColorSpace;
466 }
467 
SelectBestGamut(const std::vector<ScreenColorGamut> & mode)468 void RSScreenRenderNode::SelectBestGamut(const std::vector<ScreenColorGamut>& mode)
469 {
470     if (mode.empty()) {
471         SetColorSpace(GRAPHIC_COLOR_GAMUT_SRGB);
472         return;
473     }
474     bool isSupportBt2020 = false;
475     bool isSupportP3 = false;
476     for (const auto& gamut : mode) {
477         auto temp = static_cast<GraphicColorGamut>(gamut);
478         if (colorSpace_ == temp) {
479             return;
480         }
481         if (temp == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
482             isSupportBt2020 = true;
483             continue;
484         }
485         if (temp == GRAPHIC_COLOR_GAMUT_DISPLAY_P3) {
486             isSupportP3 = true;
487             continue;
488         }
489     }
490     GraphicColorGamut finalGamut;
491     if (colorSpace_ == GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020) {
492         finalGamut = isSupportP3 ? GRAPHIC_COLOR_GAMUT_DISPLAY_P3 :
493             GRAPHIC_COLOR_GAMUT_SRGB;
494     } else {
495         finalGamut = isSupportBt2020 ? GRAPHIC_COLOR_GAMUT_DISPLAY_BT2020 :
496             GRAPHIC_COLOR_GAMUT_SRGB;
497     }
498     SetColorSpace(finalGamut);
499 }
500 
SetForceCloseHdr(bool isForceCloseHdr)501 void RSScreenRenderNode::SetForceCloseHdr(bool isForceCloseHdr)
502 {
503     isForceCloseHdr_ = isForceCloseHdr;
504 }
505 
GetForceCloseHdr() const506 bool RSScreenRenderNode::GetForceCloseHdr() const
507 {
508     return ROSEN_EQ(GetRenderProperties().GetHDRBrightnessFactor(), 0.0f);
509 }
510 
GetSortedChildren() const511 RSRenderNode::ChildrenListSharedPtr RSScreenRenderNode::GetSortedChildren() const
512 {
513     return RSRenderNode::GetSortedChildren();
514 }
515 
GetDisappearedSurfaceRegionBelowCurrent(NodeId currentSurface) const516 Occlusion::Region RSScreenRenderNode::GetDisappearedSurfaceRegionBelowCurrent(NodeId currentSurface) const
517 {
518     Occlusion::Region result;
519     auto it = std::find_if(lastFrameSurfacesByDescZOrder_.begin(), lastFrameSurfacesByDescZOrder_.end(),
520         [currentSurface](const std::pair<NodeId, RectI>& surface) { return surface.first == currentSurface; });
521     if (it == lastFrameSurfacesByDescZOrder_.end()) {
522         return result;
523     }
524 
525     for (++it; it != lastFrameSurfacesByDescZOrder_.end(); ++it) {
526         if (currentFrameSurfacePos_.count(it->first) != 0) {
527             break;
528         }
529         Occlusion::Region disappearedSurface{ Occlusion::Rect{ it->second } };
530         result.OrSelf(disappearedSurface);
531     }
532     return result;
533 }
534 
SetTargetSurfaceRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)535 void RSScreenRenderNode::SetTargetSurfaceRenderNodeDrawable(DrawableV2::RSRenderNodeDrawableAdapter::WeakPtr drawable)
536 {
537     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
538     if (screenParams == nullptr) {
539         RS_LOGE("RSScreenRenderNode::SetTargetSurfaceRenderNodeDrawable screenParams is null");
540         return;
541     }
542     screenParams->SetTargetSurfaceRenderNodeDrawable(drawable);
543     if (stagingRenderParams_->NeedSync()) {
544         AddToPendingSyncList();
545     }
546 }
547 
SetHasMirrorScreen(bool hasMirrorScreen)548 void RSScreenRenderNode::SetHasMirrorScreen(bool hasMirrorScreen)
549 {
550     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
551     if (screenParams == nullptr) {
552         RS_LOGE("RSScreenRenderNode::SetHasMirrorScreen screenParams is null");
553         return;
554     }
555     screenParams->SetHasMirrorScreen(hasMirrorScreen);
556     if (stagingRenderParams_->NeedSync()) {
557         AddToPendingSyncList();
558     }
559 }
560 
SetForceFreeze(bool forceFreeze)561 void RSScreenRenderNode::SetForceFreeze(bool forceFreeze)
562 {
563     auto screenParams = static_cast<RSScreenRenderParams*>(stagingRenderParams_.get());
564     if (screenParams == nullptr) {
565         RS_LOGE("RSScreenRenderNode::SetForceFreeze screenParams is null");
566         return;
567     }
568     forceFreeze_ = forceFreeze;
569     screenParams->SetForceFreeze(forceFreeze);
570     if (stagingRenderParams_->NeedSync()) {
571         AddToPendingSyncList();
572     }
573 }
574 
GetForceFreeze() const575 bool RSScreenRenderNode::GetForceFreeze() const
576 {
577     return forceFreeze_ && RSSystemProperties::GetSupportScreenFreezeEnabled();
578 }
579 } // namespace Rosen
580 } // namespace OHOS
581