• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "pipeline/rs_surface_render_node.h"
17 
18 #include "command/rs_surface_node_command.h"
19 #include "common/rs_common_def.h"
20 #include "common/rs_common_hook.h"
21 #include "rs_trace.h"
22 #include "common/rs_optional_trace.h"
23 #include "common/rs_obj_abs_geometry.h"
24 #include "common/rs_rect.h"
25 #include "common/rs_vector2.h"
26 #include "common/rs_vector4.h"
27 #include "ipc_callbacks/rs_rt_refresh_callback.h"
28 #include "params/rs_surface_render_params.h"
29 #include "pipeline/rs_render_node.h"
30 #include "pipeline/rs_effect_render_node.h"
31 #include "pipeline/rs_root_render_node.h"
32 #include "pipeline/rs_surface_handler.h"
33 #include "platform/common/rs_log.h"
34 #include "platform/ohos/rs_jank_stats.h"
35 #include "property/rs_properties_painter.h"
36 #include "render/rs_drawing_filter.h"
37 #include "render/rs_skia_filter.h"
38 #include "transaction/rs_render_service_client.h"
39 #include "visitor/rs_node_visitor.h"
40 #ifndef ROSEN_CROSS_PLATFORM
41 #include "metadata_helper.h"
42 #include <v1_0/cm_color_space.h>
43 #endif
44 namespace OHOS {
45 namespace Rosen {
46 
47 // set the offset value to prevent the situation where the float number
48 // with the suffix 0.000x is still rounded up.
49 constexpr float RECT_CEIL_DEVIATION = 0.001;
50 
51 namespace {
CheckRootNodeReadyToDraw(const std::shared_ptr<RSBaseRenderNode> & child)52 bool CheckRootNodeReadyToDraw(const std::shared_ptr<RSBaseRenderNode>& child)
53 {
54     if (child->IsInstanceOf<RSRootRenderNode>()) {
55         auto rootNode = child->ReinterpretCastTo<RSRootRenderNode>();
56         // when rootnode is occluded, its applymodifiers will be skipped
57         // need to applymodifiers to update its properties here
58         rootNode->ApplyModifiers();
59         const auto& property = rootNode->GetRenderProperties();
60         if (property.GetFrameWidth() > 0 && property.GetFrameHeight() > 0 && rootNode->GetEnableRender()) {
61             return true;
62         }
63     }
64     return false;
65 }
66 
CheckScbReadyToDraw(const std::shared_ptr<RSBaseRenderNode> & child)67 bool CheckScbReadyToDraw(const std::shared_ptr<RSBaseRenderNode>& child)
68 {
69     if (child->IsInstanceOf<RSCanvasRenderNode>()) {
70         auto canvasRenderNode = child->ReinterpretCastTo<RSCanvasRenderNode>();
71         const auto& property = canvasRenderNode->GetRenderProperties();
72         if (property.GetFrameWidth() > 0 && property.GetFrameHeight() > 0) {
73             return true;
74         }
75     }
76     return false;
77 }
78 
IsFirstFrameReadyToDraw(RSSurfaceRenderNode & node)79 bool IsFirstFrameReadyToDraw(RSSurfaceRenderNode& node)
80 {
81     auto sortedChildren = node.GetSortedChildren();
82     if (node.IsScbScreen() || node.IsSCBNode()) {
83         for (const auto& child : *sortedChildren) {
84             if (CheckScbReadyToDraw(child)) {
85                 return true;
86             }
87         }
88     }
89     for (auto& child : *sortedChildren) {
90         if (CheckRootNodeReadyToDraw(child)) {
91             return true;
92         }
93         // when appWindow has abilityComponent node
94         if (child->IsInstanceOf<RSSurfaceRenderNode>()) {
95             for (const auto& surfaceNodeChild : *child->GetSortedChildren()) {
96                 if (CheckRootNodeReadyToDraw(surfaceNodeChild)) {
97                     return true;
98                 }
99             }
100         }
101     }
102     return false;
103 }
104 }
105 
RSSurfaceRenderNode(const RSSurfaceRenderNodeConfig & config,const std::weak_ptr<RSContext> & context)106 RSSurfaceRenderNode::RSSurfaceRenderNode(
107     const RSSurfaceRenderNodeConfig& config, const std::weak_ptr<RSContext>& context)
108     : RSRenderNode(config.id, context, config.isTextureExportNode), name_(config.name),
109       nodeType_(config.nodeType), surfaceWindowType_(config.surfaceWindowType),
110       dirtyManager_(std::make_shared<RSDirtyRegionManager>()),
111       cacheSurfaceDirtyManager_(std::make_shared<RSDirtyRegionManager>()),
112       surfaceHandler_(std::make_shared<RSSurfaceHandler>(config.id))
113 {
114 #ifndef ROSEN_ARKUI_X
115     MemoryInfo info = {sizeof(*this), ExtractPid(config.id), config.id, MEMORY_TYPE::MEM_RENDER_NODE};
116     MemoryTrack::Instance().AddNodeRecord(config.id, info);
117 #endif
118 }
119 
RSSurfaceRenderNode(NodeId id,const std::weak_ptr<RSContext> & context,bool isTextureExportNode)120 RSSurfaceRenderNode::RSSurfaceRenderNode(NodeId id, const std::weak_ptr<RSContext>& context, bool isTextureExportNode)
121     : RSSurfaceRenderNode(RSSurfaceRenderNodeConfig { .id = id, .name = "SurfaceNode",
122     .isTextureExportNode = isTextureExportNode}, context)
123 {}
124 
~RSSurfaceRenderNode()125 RSSurfaceRenderNode::~RSSurfaceRenderNode()
126 {
127 #ifdef USE_SURFACE_TEXTURE
128     SetSurfaceTexture(nullptr);
129 #endif
130 #ifndef ROSEN_ARKUI_X
131     MemoryTrack::Instance().RemoveNodeRecord(GetId());
132 #endif
133 }
134 
135 #ifndef ROSEN_CROSS_PLATFORM
SetConsumer(const sptr<IConsumerSurface> & consumer)136 void RSSurfaceRenderNode::SetConsumer(const sptr<IConsumerSurface>& consumer)
137 {
138     GetMutableRSSurfaceHandler()->SetConsumer(consumer);
139 }
140 #endif
141 
UpdateSrcRect(const Drawing::Canvas & canvas,const Drawing::RectI & dstRect,bool hasRotation)142 void RSSurfaceRenderNode::UpdateSrcRect(const Drawing::Canvas& canvas, const Drawing::RectI& dstRect,
143     bool hasRotation)
144 {
145     auto localClipRect = RSPaintFilterCanvas::GetLocalClipBounds(canvas, &dstRect).value_or(Drawing::Rect());
146     const RSProperties& properties = GetRenderProperties();
147     int left = std::clamp<int>(localClipRect.GetLeft(), 0, properties.GetBoundsWidth());
148     int top = std::clamp<int>(localClipRect.GetTop(), 0, properties.GetBoundsHeight());
149     int width = std::clamp<int>(std::ceil(localClipRect.GetWidth() - RECT_CEIL_DEVIATION), 0,
150         std::ceil(properties.GetBoundsWidth() - left));
151     int height = std::clamp<int>(std::ceil(localClipRect.GetHeight() - RECT_CEIL_DEVIATION), 0,
152         std::ceil(properties.GetBoundsHeight() - top));
153     RectI srcRect = {left, top, width, height};
154     SetSrcRect(srcRect);
155     // We allow 1px error value to avoid disable dss by mistake [this flag only used for YUV buffer format]
156     if (IsYUVBufferFormat()) {
157         isHardwareForcedDisabledBySrcRect_ = !GetAncoForceDoDirect() &&
158             (hasRotation ? (width + 1 < static_cast<int>(properties.GetBoundsWidth())) :
159             (height + 1 < static_cast<int>(properties.GetBoundsHeight())));
160 #ifndef ROSEN_CROSS_PLATFORM
161         RS_OPTIONAL_TRACE_NAME_FMT("UpdateSrcRect hwcDisableBySrc:%d localClip:[%.2f, %.2f, %.2f, %.2f]" \
162             " bounds:[%.2f, %.2f] hasRotation:%d name:%s id:%llu",
163             isHardwareForcedDisabledBySrcRect_,
164             localClipRect.GetLeft(), localClipRect.GetTop(), localClipRect.GetWidth(), localClipRect.GetHeight(),
165             properties.GetBoundsWidth(), properties.GetBoundsHeight(), hasRotation,
166             GetName().c_str(), GetId());
167 #endif
168     }
169 }
170 
UpdateHwcDisabledBySrcRect(bool hasRotation)171 void RSSurfaceRenderNode::UpdateHwcDisabledBySrcRect(bool hasRotation)
172 {
173 #ifndef ROSEN_CROSS_PLATFORM
174     const auto& buffer = surfaceHandler_->GetBuffer();
175     isHardwareForcedDisabledBySrcRect_ = false;
176     if (buffer == nullptr) {
177         return;
178     }
179 #endif
180 }
181 
IsYUVBufferFormat() const182 bool RSSurfaceRenderNode::IsYUVBufferFormat() const
183 {
184 #ifndef ROSEN_CROSS_PLATFORM
185     auto curBuffer = surfaceHandler_->GetBuffer();
186     if (!curBuffer) {
187         return false;
188     }
189     auto format = curBuffer->GetFormat();
190     if (format < GRAPHIC_PIXEL_FMT_YUV_422_I || format == GRAPHIC_PIXEL_FMT_RGBA_1010102 ||
191         format > GRAPHIC_PIXEL_FMT_YCRCB_P010) {
192         return false;
193     }
194     return true;
195 #else
196     return false;
197 #endif
198 }
199 
ShouldPrepareSubnodes()200 bool RSSurfaceRenderNode::ShouldPrepareSubnodes()
201 {
202     // if a appwindow or abilitycomponent has a empty dstrect, its subnodes' prepare stage can be skipped
203     // most common scenario: HiBoard (SwipeLeft screen on home screen)
204     if (GetDstRect().IsEmpty() && (IsAppWindow() || IsAbilityComponent())) {
205         return false;
206     }
207     return true;
208 }
209 
StoreMustRenewedInfo()210 void RSSurfaceRenderNode::StoreMustRenewedInfo()
211 {
212     mustRenewedInfo_ = RSRenderNode::HasMustRenewedInfo() || GetHasSecurityLayer() ||
213         GetHasSkipLayer() || GetHasProtectedLayer();
214 }
215 
DirtyRegionDump() const216 std::string RSSurfaceRenderNode::DirtyRegionDump() const
217 {
218     std::string dump = GetName() +
219         " SurfaceNodeType [" + std::to_string(static_cast<unsigned int>(GetSurfaceNodeType())) + "]" +
220         " Transparent [" + std::to_string(IsTransparent()) +"]" +
221         " DstRect: " + GetDstRect().ToString() +
222         " VisibleRegion: " + GetVisibleRegion().GetRegionInfo();
223     if (GetDirtyManager()) {
224         dump += " DirtyRegion: " + GetDirtyManager()->GetDirtyRegion().ToString();
225     }
226     return dump;
227 }
228 
PrepareRenderBeforeChildren(RSPaintFilterCanvas & canvas)229 void RSSurfaceRenderNode::PrepareRenderBeforeChildren(RSPaintFilterCanvas& canvas)
230 {
231     // Save the current state of the canvas before modifying it.
232     renderNodeSaveCount_ = canvas.SaveAllStatus();
233 
234     // Apply alpha to canvas
235     const RSProperties& properties = GetRenderProperties();
236     canvas.MultiplyAlpha(properties.GetAlpha());
237 
238     // Apply matrix to canvas
239     auto& currentGeoPtr = (properties.GetBoundsGeometry());
240     if (currentGeoPtr != nullptr) {
241         currentGeoPtr->UpdateByMatrixFromSelf();
242         auto matrix = currentGeoPtr->GetMatrix();
243         matrix.Set(Drawing::Matrix::TRANS_X, std::ceil(matrix.Get(Drawing::Matrix::TRANS_X)));
244         matrix.Set(Drawing::Matrix::TRANS_Y, std::ceil(matrix.Get(Drawing::Matrix::TRANS_Y)));
245         canvas.ConcatMatrix(matrix);
246     }
247 
248     // Clip by bounds
249     canvas.ClipRect(Drawing::Rect(0, 0, std::floor(properties.GetBoundsWidth()),
250         std::floor(properties.GetBoundsHeight())), Drawing::ClipOp::INTERSECT, false);
251 
252     // Extract srcDest and dstRect from Drawing::Canvas, localCLipBounds as SrcRect, deviceClipBounds as DstRect
253     auto deviceClipRect = canvas.GetDeviceClipBounds();
254     UpdateSrcRect(canvas, deviceClipRect);
255     RectI dstRect = { deviceClipRect.GetLeft() + offsetX_, deviceClipRect.GetTop() + offsetY_,
256         deviceClipRect.GetWidth(), deviceClipRect.GetHeight() };
257     SetDstRect(dstRect);
258 
259     // Save TotalMatrix and GlobalAlpha for compositor
260     SetTotalMatrix(canvas.GetTotalMatrix());
261     SetGlobalAlpha(canvas.GetAlpha());
262 }
263 
PrepareRenderAfterChildren(RSPaintFilterCanvas & canvas)264 void RSSurfaceRenderNode::PrepareRenderAfterChildren(RSPaintFilterCanvas& canvas)
265 {
266     canvas.RestoreStatus(renderNodeSaveCount_);
267 }
268 
CollectSurface(const std::shared_ptr<RSBaseRenderNode> & node,std::vector<RSBaseRenderNode::SharedPtr> & vec,bool isUniRender,bool onlyFirstLevel)269 void RSSurfaceRenderNode::CollectSurface(const std::shared_ptr<RSBaseRenderNode>& node,
270     std::vector<RSBaseRenderNode::SharedPtr>& vec, bool isUniRender, bool onlyFirstLevel)
271 {
272     if (IsScbScreen()) {
273         for (auto& child : *node->GetSortedChildren()) {
274             child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
275         }
276         return;
277     }
278     if (IsStartingWindow()) {
279         if (isUniRender) {
280             vec.emplace_back(shared_from_this());
281         }
282         return;
283     }
284     if (IsLeashWindow()) {
285         if (isUniRender) {
286             vec.emplace_back(shared_from_this());
287         }
288         if (onlyFirstLevel) {
289             return;
290         }
291         for (auto& child : *node->GetSortedChildren()) {
292             child->CollectSurface(child, vec, isUniRender, onlyFirstLevel);
293         }
294         return;
295     }
296 
297 #ifndef ROSEN_CROSS_PLATFORM
298     auto consumer = surfaceHandler_->GetConsumer();
299     if (consumer != nullptr && consumer->GetTunnelHandle() != nullptr) {
300         return;
301     }
302 #endif
303     auto num = find(vec.begin(), vec.end(), shared_from_this());
304     if (num != vec.end()) {
305         return;
306     }
307     if (isUniRender && ShouldPaint()) {
308         vec.emplace_back(shared_from_this());
309     } else {
310 #ifndef ROSEN_CROSS_PLATFORM
311         if (surfaceHandler_->GetBuffer() != nullptr && ShouldPaint()) {
312             vec.emplace_back(shared_from_this());
313         }
314 #endif
315     }
316 
317     if (isSubSurfaceEnabled_) {
318         if (onlyFirstLevel) {
319             return;
320         }
321         for (auto &nodes : node->GetSubSurfaceNodes()) {
322             for (auto &node : nodes.second) {
323                 auto surfaceNode = node.lock();
324                 if (surfaceNode != nullptr) {
325                     surfaceNode->CollectSurface(surfaceNode, vec, isUniRender, onlyFirstLevel);
326                 }
327             }
328         }
329     }
330 }
331 
CollectSurfaceForUIFirstSwitch(uint32_t & leashWindowCount,uint32_t minNodeNum)332 void RSSurfaceRenderNode::CollectSurfaceForUIFirstSwitch(uint32_t& leashWindowCount, uint32_t minNodeNum)
333 {
334     if (IsLeashWindow() || IsStartingWindow()) {
335         leashWindowCount++;
336     }
337     return;
338 }
339 
ClearChildrenCache()340 void RSSurfaceRenderNode::ClearChildrenCache()
341 {
342     for (auto& child : *GetChildren()) {
343         auto surfaceNode = child->ReinterpretCastTo<RSSurfaceRenderNode>();
344         if (surfaceNode == nullptr) {
345             continue;
346         }
347 #ifndef ROSEN_CROSS_PLATFORM
348         auto consumer = surfaceNode->GetRSSurfaceHandler()->GetConsumer();
349         if (consumer != nullptr) {
350             consumer->GoBackground();
351         }
352 #endif
353     }
354     // Temporary solution, GetChildren will generate fullChildrenList_, which will cause memory leak
355     OnTreeStateChanged();
356 }
357 
OnTreeStateChanged()358 void RSSurfaceRenderNode::OnTreeStateChanged()
359 {
360     NotifyTreeStateChange();
361     RSRenderNode::OnTreeStateChanged();
362 #if defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK)
363     if (!IsOnTheTree()) {
364         if (auto context = GetContext().lock()) {
365             RS_TRACE_NAME_FMT("need purgeUnlockedResources this SurfaceNode isn't on the tree Id:%" PRIu64 " Name:%s",
366                 GetId(), GetName().c_str());
367             if (IsLeashWindow()) {
368                 context->MarkNeedPurge(ClearMemoryMoment::COMMON_SURFACE_NODE_HIDE, RSContext::PurgeType::GENTLY);
369             }
370             if (surfaceWindowType_ == SurfaceWindowType::SYSTEM_SCB_WINDOW) {
371                 context->MarkNeedPurge(ClearMemoryMoment::SCENEBOARD_SURFACE_NODE_HIDE, RSContext::PurgeType::STRONGLY);
372             }
373         }
374     }
375 #endif
376     if (IsAbilityComponent()) {
377         if (auto instanceRootNode = GetInstanceRootNode()) {
378             if (auto surfaceNode = instanceRootNode->ReinterpretCastTo<RSSurfaceRenderNode>()) {
379                 surfaceNode->UpdateAbilityNodeIds(GetId(), IsOnTheTree());
380             }
381         }
382     } else if (IsHardwareEnabledType() && RSUniRenderJudgement::IsUniRender()) {
383         if (auto instanceRootNode = GetInstanceRootNode()) {
384             if (auto surfaceNode = instanceRootNode->ReinterpretCastTo<RSSurfaceRenderNode>()) {
385                 surfaceNode->UpdateChildHardwareEnabledNode(GetId(), IsOnTheTree());
386             }
387         }
388     }
389     OnSubSurfaceChanged();
390 
391     // sync skip & security info
392     SyncSecurityInfoToFirstLevelNode();
393     SyncSkipInfoToFirstLevelNode();
394     SyncProtectedInfoToFirstLevelNode();
395     SyncPrivacyContentInfoToFirstLevelNode();
396 }
397 
HasSubSurfaceNodes() const398 bool RSSurfaceRenderNode::HasSubSurfaceNodes() const
399 {
400     return childSubSurfaceNodes_.size() != 0;
401 }
402 
SetIsSubSurfaceNode(bool isSubSurfaceNode)403 void RSSurfaceRenderNode::SetIsSubSurfaceNode(bool isSubSurfaceNode)
404 {
405     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
406     if (surfaceParams) {
407         surfaceParams->SetIsSubSurfaceNode(isSubSurfaceNode);
408         isSubSurfaceNode_ = isSubSurfaceNode;
409         AddToPendingSyncList();
410     }
411 }
412 
IsSubSurfaceNode() const413 bool RSSurfaceRenderNode::IsSubSurfaceNode() const
414 {
415     return isSubSurfaceNode_;
416 }
417 
GetChildSubSurfaceNodes() const418 const std::map<NodeId, RSSurfaceRenderNode::WeakPtr>& RSSurfaceRenderNode::GetChildSubSurfaceNodes() const
419 {
420     return childSubSurfaceNodes_;
421 }
422 
OnSubSurfaceChanged()423 void RSSurfaceRenderNode::OnSubSurfaceChanged()
424 {
425     if (!IsMainWindowType() || !RSUniRenderJudgement::IsUniRender()) {
426         return;
427     }
428     auto parentNode = GetParent().lock();
429     if (!parentNode) {
430         return;
431     }
432     std::shared_ptr<RSSurfaceRenderNode> parentSurfaceNode = parentNode->ReinterpretCastTo<RSSurfaceRenderNode>();
433     if (!parentSurfaceNode || !parentSurfaceNode->IsMainWindowType()) {
434         if (auto instanceRootNode = parentNode->GetInstanceRootNode()) {
435             parentSurfaceNode = instanceRootNode->ReinterpretCastTo<RSSurfaceRenderNode>();
436         }
437     }
438     if (parentSurfaceNode && parentSurfaceNode->IsLeashOrMainWindow()) {
439         parentSurfaceNode->UpdateChildSubSurfaceNodes(ReinterpretCastTo<RSSurfaceRenderNode>(), IsOnTheTree());
440     }
441 }
442 
UpdateChildSubSurfaceNodes(RSSurfaceRenderNode::SharedPtr node,bool isOnTheTree)443 void RSSurfaceRenderNode::UpdateChildSubSurfaceNodes(RSSurfaceRenderNode::SharedPtr node, bool isOnTheTree)
444 {
445     if (isOnTheTree) {
446         childSubSurfaceNodes_[node->GetId()] = node;
447     } else {
448         childSubSurfaceNodes_.erase(node->GetId());
449     }
450     if (!IsLeashWindow()) {
451         node->SetIsSubSurfaceNode(isOnTheTree);
452     }
453 }
454 
GetAllSubSurfaceNodes(std::vector<std::pair<NodeId,RSSurfaceRenderNode::WeakPtr>> & allSubSurfaceNodes)455 void RSSurfaceRenderNode::GetAllSubSurfaceNodes(
456     std::vector<std::pair<NodeId, RSSurfaceRenderNode::WeakPtr>>& allSubSurfaceNodes)
457 {
458     for (auto& [id, node] : childSubSurfaceNodes_) {
459         auto subSubSurfaceNodePtr = node.lock();
460         if (!subSubSurfaceNodePtr) {
461             continue;
462         }
463         if (subSubSurfaceNodePtr->HasSubSurfaceNodes()) {
464             subSubSurfaceNodePtr->GetAllSubSurfaceNodes(allSubSurfaceNodes);
465         }
466         allSubSurfaceNodes.push_back({id, node});
467     }
468 }
469 
SubSurfaceNodesDump() const470 std::string RSSurfaceRenderNode::SubSurfaceNodesDump() const
471 {
472     std::string out;
473     out += ", subSurface";
474     for (auto [id, _] : childSubSurfaceNodes_) {
475         out += "[" + std::to_string(id) + "]";
476     }
477     return out;
478 }
479 
SetIsNodeToBeCaptured(bool isNodeToBeCaptured)480 void RSSurfaceRenderNode::SetIsNodeToBeCaptured(bool isNodeToBeCaptured)
481 {
482     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
483     if (surfaceParams) {
484         surfaceParams->SetIsNodeToBeCaptured(isNodeToBeCaptured);
485         isNodeToBeCaptured_ = isNodeToBeCaptured;
486         AddToPendingSyncList();
487     }
488 }
489 
IsNodeToBeCaptured() const490 bool RSSurfaceRenderNode::IsNodeToBeCaptured() const
491 {
492     return isNodeToBeCaptured_;
493 }
494 
OnResetParent()495 void RSSurfaceRenderNode::OnResetParent()
496 {
497     if (nodeType_ == RSSurfaceNodeType::LEASH_WINDOW_NODE) {
498         ClearChildrenCache();
499     } else {
500 #ifndef ROSEN_CROSS_PLATFORM
501         auto consumer = GetRSSurfaceHandler()->GetConsumer();
502         if (consumer != nullptr && !IsSelfDrawingType() && !IsAbilityComponent()) {
503             consumer->GoBackground();
504         }
505 #endif
506     }
507 }
508 
SetIsNotifyUIBufferAvailable(bool available)509 void RSSurfaceRenderNode::SetIsNotifyUIBufferAvailable(bool available)
510 {
511 #ifdef USE_SURFACE_TEXTURE
512     auto texture = GetSurfaceTexture();
513     if (texture) {
514         texture->MarkUiFrameAvailable(available);
515     }
516 #endif
517     isNotifyUIBufferAvailable_.store(available);
518 }
519 
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)520 void RSSurfaceRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
521 {
522     if (!visitor) {
523         return;
524     }
525     ApplyModifiers();
526     visitor->QuickPrepareSurfaceRenderNode(*this);
527 
528     if ((IsAppWindow() || IsScbScreen()) && !IsNotifyUIBufferAvailable() && IsFirstFrameReadyToDraw(*this)) {
529         NotifyUIBufferAvailable();
530     }
531 }
532 
IsSubTreeNeedPrepare(bool filterInGlobal,bool isOccluded)533 bool RSSurfaceRenderNode::IsSubTreeNeedPrepare(bool filterInGlobal, bool isOccluded)
534 {
535     // force preparation case for occlusion
536     if (IsLeashWindow()) {
537         SetSubTreeDirty(false);
538         UpdateChildrenOutOfRectFlag(false); // collect again
539         return true;
540     }
541 
542     // force preparation case for update gravity when appWindow geoDirty
543     auto parentPtr = this->GetParent().lock();
544     auto surfaceParentPtr = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(parentPtr);
545     if (surfaceParentPtr != nullptr &&
546         surfaceParentPtr->GetSurfaceNodeType() == RSSurfaceNodeType::LEASH_WINDOW_NODE) {
547         if (this->GetRenderProperties().IsCurGeoDirty()) {
548             return true;
549         }
550     }
551 
552     return RSRenderNode::IsSubTreeNeedPrepare(filterInGlobal, isOccluded);
553 }
554 
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)555 void RSSurfaceRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
556 {
557     if (!visitor) {
558         return;
559     }
560     ApplyModifiers();
561     visitor->PrepareSurfaceRenderNode(*this);
562 }
563 
Process(const std::shared_ptr<RSNodeVisitor> & visitor)564 void RSSurfaceRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
565 {
566     if (!visitor) {
567         return;
568     }
569     RSRenderNode::RenderTraceDebug();
570     visitor->ProcessSurfaceRenderNode(*this);
571 }
572 
ProcessRenderBeforeChildren(RSPaintFilterCanvas & canvas)573 void RSSurfaceRenderNode::ProcessRenderBeforeChildren(RSPaintFilterCanvas& canvas)
574 {
575     needDrawAnimateProperty_ = true;
576     ProcessAnimatePropertyBeforeChildren(canvas, true);
577     needDrawAnimateProperty_ = false;
578 }
579 
ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas & canvas,bool includeProperty)580 void RSSurfaceRenderNode::ProcessAnimatePropertyBeforeChildren(RSPaintFilterCanvas& canvas, bool includeProperty)
581 {
582     if (GetCacheType() != CacheType::ANIMATE_PROPERTY && !needDrawAnimateProperty_) {
583         return;
584     }
585 
586     const auto& property = GetRenderProperties();
587     const RectF absBounds = {0, 0, property.GetBoundsWidth(), property.GetBoundsHeight()};
588     RRect absClipRRect = RRect(absBounds, property.GetCornerRadius());
589     RSPropertiesPainter::DrawShadow(property, canvas, &absClipRRect);
590     RSPropertiesPainter::DrawOutline(property, canvas);
591 
592     if (!property.GetCornerRadius().IsZero()) {
593         canvas.ClipRoundRect(
594             RSPropertiesPainter::RRect2DrawingRRect(absClipRRect), Drawing::ClipOp::INTERSECT, true);
595     } else {
596         canvas.ClipRect(Drawing::Rect(0, 0, property.GetBoundsWidth(), property.GetBoundsHeight()),
597             Drawing::ClipOp::INTERSECT, false);
598     }
599 
600 #ifndef ROSEN_CROSS_PLATFORM
601     RSPropertiesPainter::DrawBackground(
602         property, canvas, true, IsSelfDrawingNode() && (surfaceHandler_->GetBuffer() != nullptr));
603 #else
604     RSPropertiesPainter::DrawBackground(property, canvas);
605 #endif
606     RSPropertiesPainter::DrawMask(property, canvas);
607     RSPropertiesPainter::DrawFilter(property, canvas, FilterType::BACKGROUND_FILTER);
608     SetTotalMatrix(canvas.GetTotalMatrix());
609 }
610 
ProcessRenderAfterChildren(RSPaintFilterCanvas & canvas)611 void RSSurfaceRenderNode::ProcessRenderAfterChildren(RSPaintFilterCanvas& canvas)
612 {
613     needDrawAnimateProperty_ = true;
614     ProcessAnimatePropertyAfterChildren(canvas);
615     needDrawAnimateProperty_ = false;
616 }
617 
ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas & canvas)618 void RSSurfaceRenderNode::ProcessAnimatePropertyAfterChildren(RSPaintFilterCanvas& canvas)
619 {
620     if (GetCacheType() != CacheType::ANIMATE_PROPERTY && !needDrawAnimateProperty_) {
621         return;
622     }
623     const auto& property = GetRenderProperties();
624     RSPropertiesPainter::DrawFilter(property, canvas, FilterType::FOREGROUND_FILTER);
625     canvas.Save();
626     if (GetSurfaceNodeType() == RSSurfaceNodeType::SELF_DRAWING_NODE) {
627         auto& geoPtr = (property.GetBoundsGeometry());
628         canvas.ConcatMatrix(geoPtr->GetMatrix());
629     }
630     RSPropertiesPainter::DrawOutline(property, canvas);
631     RSPropertiesPainter::DrawBorder(property, canvas);
632     canvas.Restore();
633 }
634 
SetContextBounds(const Vector4f bounds)635 void RSSurfaceRenderNode::SetContextBounds(const Vector4f bounds)
636 {
637     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetBounds>(GetId(), bounds);
638     SendCommandFromRT(command, GetId());
639 }
640 
GetDirtyManager() const641 const std::shared_ptr<RSDirtyRegionManager>& RSSurfaceRenderNode::GetDirtyManager() const
642 {
643     return dirtyManager_;
644 }
645 
GetCacheSurfaceDirtyManager() const646 std::shared_ptr<RSDirtyRegionManager> RSSurfaceRenderNode::GetCacheSurfaceDirtyManager() const
647 {
648     return cacheSurfaceDirtyManager_;
649 }
650 
SetSurfaceNodeType(RSSurfaceNodeType nodeType)651 void RSSurfaceRenderNode::SetSurfaceNodeType(RSSurfaceNodeType nodeType)
652 {
653     if (nodeType_ == RSSurfaceNodeType::ABILITY_COMPONENT_NODE ||
654         nodeType_ == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE ||
655         nodeType_ == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE) {
656         return;
657     }
658     if (nodeType == RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE ||
659         nodeType == RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE) {
660         RS_LOGE("RSSurfaceRenderNode::SetSurfaceNodeType prohibition of converting surfaceNodeType to uiExtension");
661         return;
662     }
663     nodeType_ = nodeType;
664 }
665 
MarkUIHidden(bool isHidden)666 void RSSurfaceRenderNode::MarkUIHidden(bool isHidden)
667 {
668     isUIHidden_ = isHidden;
669 }
670 
IsUIHidden() const671 bool RSSurfaceRenderNode::IsUIHidden() const
672 {
673     return isUIHidden_;
674 }
675 
IsLeashWindowSurfaceNodeVisible()676 bool RSSurfaceRenderNode::IsLeashWindowSurfaceNodeVisible()
677 {
678     if (!IsLeashWindow()) {
679         return false;
680     }
681     auto nestedSurfaces = GetLeashWindowNestedSurfaces();
682     return std::any_of(nestedSurfaces.begin(), nestedSurfaces.end(),
683         [](const auto& node) -> bool {
684             return node && !node->IsUIHidden();
685         });
686 }
687 
SetContextMatrix(const std::optional<Drawing::Matrix> & matrix,bool sendMsg)688 void RSSurfaceRenderNode::SetContextMatrix(const std::optional<Drawing::Matrix>& matrix, bool sendMsg)
689 {
690     if (contextMatrix_ == matrix) {
691         return;
692     }
693     contextMatrix_ = matrix;
694     SetContentDirty();
695     AddDirtyType(RSModifierType::SCALE);
696     AddDirtyType(RSModifierType::SKEW);
697     AddDirtyType(RSModifierType::PERSP);
698     AddDirtyType(RSModifierType::TRANSLATE);
699     if (!sendMsg) {
700         return;
701     }
702     // send a Command
703     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextMatrix>(GetId(), matrix);
704     SendCommandFromRT(command, GetId());
705 }
706 
SetContextAlpha(float alpha,bool sendMsg)707 void RSSurfaceRenderNode::SetContextAlpha(float alpha, bool sendMsg)
708 {
709     if (contextAlpha_ == alpha) {
710         return;
711     }
712     contextAlpha_ = alpha;
713     SetContentDirty();
714     AddDirtyType(RSModifierType::ALPHA);
715     if (!sendMsg) {
716         return;
717     }
718     // send a Command
719     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextAlpha>(GetId(), alpha);
720     SendCommandFromRT(command, GetId());
721 }
722 
SetContextClipRegion(const std::optional<Drawing::Rect> & clipRegion,bool sendMsg)723 void RSSurfaceRenderNode::SetContextClipRegion(const std::optional<Drawing::Rect>& clipRegion, bool sendMsg)
724 {
725     if (contextClipRect_ == clipRegion) {
726         return;
727     }
728     contextClipRect_ = clipRegion;
729     SetContentDirty();
730     AddDirtyType(RSModifierType::BOUNDS);
731     if (!sendMsg) {
732         return;
733     }
734     // send a Command
735     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetContextClipRegion>(GetId(), clipRegion);
736     SendCommandFromRT(command, GetId());
737 }
SetBootAnimation(bool isBootAnimation)738 void RSSurfaceRenderNode::SetBootAnimation(bool isBootAnimation)
739 {
740     ROSEN_LOGD("SetBootAnimation:: id:%{public}" PRIu64 ", isBootAnimation:%{public}d",
741         GetId(), isBootAnimation);
742     isBootAnimation_ = isBootAnimation;
743 }
744 
GetBootAnimation() const745 bool RSSurfaceRenderNode::GetBootAnimation() const
746 {
747     return isBootAnimation_;
748 }
749 
SetForceHardwareAndFixRotation(bool flag)750 void RSSurfaceRenderNode::SetForceHardwareAndFixRotation(bool flag)
751 {
752     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
753     if (surfaceParams == nullptr) {
754         return;
755     }
756     surfaceParams->SetFixRotationByUser(flag);
757     AddToPendingSyncList();
758 
759     isFixRotationByUser_ = flag;
760 }
761 
GetFixRotationByUser() const762 bool RSSurfaceRenderNode::GetFixRotationByUser() const
763 {
764     return isFixRotationByUser_;
765 }
766 
IsInFixedRotation() const767 bool RSSurfaceRenderNode::IsInFixedRotation() const
768 {
769     return isInFixedRotation_;
770 }
771 
SetInFixedRotation(bool isRotating)772 void RSSurfaceRenderNode::SetInFixedRotation(bool isRotating)
773 {
774     if (isFixRotationByUser_ && !isInFixedRotation_ && isRotating) {
775 #ifndef ROSEN_CROSS_PLATFORM
776         auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
777         if (surfaceParams) {
778             auto layer = surfaceParams->GetLayerInfo();
779             originalSrcRect_ = { layer.srcRect.x, layer.srcRect.y, layer.srcRect.w, layer.srcRect.h };
780             originalDstRect_ = { layer.dstRect.x, layer.dstRect.y, layer.dstRect.w, layer.dstRect.h };
781         }
782 #endif
783     }
784     isInFixedRotation_ = isFixRotationByUser_ && isRotating;
785 }
786 
SetHidePrivacyContent(bool needHidePrivacyContent)787 void RSSurfaceRenderNode::SetHidePrivacyContent(bool needHidePrivacyContent)
788 {
789     if (needHidePrivacyContent_ == needHidePrivacyContent) {
790         return;
791     }
792     needHidePrivacyContent_ = needHidePrivacyContent;
793     SetDirty();
794     if (needHidePrivacyContent) {
795         privacyContentLayerIds_.insert(GetId());
796     } else {
797         privacyContentLayerIds_.erase(GetId());
798     }
799     ROSEN_LOGI("RSSurfaceRenderNode::SetHidePrivacyContent, Node id: %{public}" PRIu64 ", privacyContent:%{public}d",
800         GetId(), needHidePrivacyContent);
801     SyncPrivacyContentInfoToFirstLevelNode();
802 }
803 
SetSecurityLayer(bool isSecurityLayer)804 void RSSurfaceRenderNode::SetSecurityLayer(bool isSecurityLayer)
805 {
806     if (isSecurityLayer_ == isSecurityLayer) {
807         return;
808     }
809     specialLayerChanged_ = true;
810     isSecurityLayer_ = isSecurityLayer;
811     SetDirty();
812     if (isSecurityLayer) {
813         securityLayerIds_.insert(GetId());
814     } else {
815         securityLayerIds_.erase(GetId());
816     }
817     SyncSecurityInfoToFirstLevelNode();
818 }
819 
SetLeashPersistentId(NodeId leashPersistentId)820 void RSSurfaceRenderNode::SetLeashPersistentId(NodeId leashPersistentId)
821 {
822     if (leashPersistentId_ == leashPersistentId) {
823         return;
824     }
825 
826     leashPersistentId_ = leashPersistentId;
827     SetDirty();
828 
829     ROSEN_LOGD("RSSurfaceRenderNode::SetLeashPersistentId, Node id: %{public}" PRIu64 ", leashPersistentId:%{public}"
830         "" PRIu64, GetId(), leashPersistentId);
831 }
832 
SetSkipLayer(bool isSkipLayer)833 void RSSurfaceRenderNode::SetSkipLayer(bool isSkipLayer)
834 {
835     if (isSkipLayer_ == isSkipLayer) {
836         return;
837     }
838     specialLayerChanged_ = true;
839     isSkipLayer_ = isSkipLayer;
840     SetDirty();
841     if (isSkipLayer) {
842         skipLayerIds_.insert(GetId());
843     } else {
844         skipLayerIds_.erase(GetId());
845     }
846     SyncSkipInfoToFirstLevelNode();
847 }
848 
GetLeashPersistentId() const849 LeashPersistentId RSSurfaceRenderNode::GetLeashPersistentId() const
850 {
851     return leashPersistentId_;
852 }
853 
SetProtectedLayer(bool isProtectedLayer)854 void RSSurfaceRenderNode::SetProtectedLayer(bool isProtectedLayer)
855 {
856     if (isProtectedLayer_ == isProtectedLayer) {
857         return;
858     }
859     specialLayerChanged_ = true;
860     isProtectedLayer_ = isProtectedLayer;
861     SetDirty();
862     if (isProtectedLayer) {
863         protectedLayerIds_.insert(GetId());
864     } else {
865         protectedLayerIds_.erase(GetId());
866     }
867     SyncProtectedInfoToFirstLevelNode();
868 }
869 
GetSecurityLayer() const870 bool RSSurfaceRenderNode::GetSecurityLayer() const
871 {
872     return isSecurityLayer_;
873 }
874 
875 
GetSkipLayer() const876 bool RSSurfaceRenderNode::GetSkipLayer() const
877 {
878     return isSkipLayer_;
879 }
880 
GetProtectedLayer() const881 bool RSSurfaceRenderNode::GetProtectedLayer() const
882 {
883     return isProtectedLayer_;
884 }
885 
GetHasSecurityLayer() const886 bool RSSurfaceRenderNode::GetHasSecurityLayer() const
887 {
888     return securityLayerIds_.size() != 0;
889 }
890 
GetHasSkipLayer() const891 bool RSSurfaceRenderNode::GetHasSkipLayer() const
892 {
893     return skipLayerIds_.size() != 0;
894 }
895 
GetHasProtectedLayer() const896 bool RSSurfaceRenderNode::GetHasProtectedLayer() const
897 {
898     return protectedLayerIds_.size() != 0;
899 }
900 
GetHasPrivacyContentLayer() const901 bool RSSurfaceRenderNode::GetHasPrivacyContentLayer() const
902 {
903     return privacyContentLayerIds_.size() != 0;
904 }
905 
SyncSecurityInfoToFirstLevelNode()906 void RSSurfaceRenderNode::SyncSecurityInfoToFirstLevelNode()
907 {
908     auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
909     // firstLevelNode is the nearest app window / leash node
910     if (firstLevelNode && GetFirstLevelNodeId() != GetId()) {
911         if (isSecurityLayer_ && IsOnTheTree()) {
912             firstLevelNode->securityLayerIds_.insert(GetId());
913         } else {
914             firstLevelNode->securityLayerIds_.erase(GetId());
915         }
916         firstLevelNode->specialLayerChanged_ = specialLayerChanged_;
917     }
918 }
919 
SyncSkipInfoToFirstLevelNode()920 void RSSurfaceRenderNode::SyncSkipInfoToFirstLevelNode()
921 {
922     auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
923     // firstLevelNode is the nearest app window / leash node
924     if (firstLevelNode && GetFirstLevelNodeId() != GetId()) {
925         if (isSkipLayer_ && IsOnTheTree()) {
926             firstLevelNode->skipLayerIds_.insert(GetId());
927         } else {
928             firstLevelNode->skipLayerIds_.erase(GetId());
929         }
930         firstLevelNode->specialLayerChanged_ = specialLayerChanged_;
931     }
932 }
933 
SyncProtectedInfoToFirstLevelNode()934 void RSSurfaceRenderNode::SyncProtectedInfoToFirstLevelNode()
935 {
936     if (isProtectedLayer_) {
937         auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
938         // firstLevelNode is the nearest app window / leash node
939         if (firstLevelNode && GetFirstLevelNodeId() != GetId()) {
940             firstLevelNode->SetDirty();
941             // should always sync protectedLayerIds_ to firstLevelNode
942             if (isProtectedLayer_ && IsOnTheTree()) {
943                 firstLevelNode->protectedLayerIds_.insert(GetId());
944             } else {
945                 firstLevelNode->protectedLayerIds_.erase(GetId());
946             }
947             firstLevelNode->specialLayerChanged_ = specialLayerChanged_;
948         }
949     }
950 }
951 
SyncPrivacyContentInfoToFirstLevelNode()952 void RSSurfaceRenderNode::SyncPrivacyContentInfoToFirstLevelNode()
953 {
954     auto firstLevelNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetFirstLevelNode());
955     // firstLevelNode is the nearest app window / leash node
956     if (firstLevelNode && GetFirstLevelNodeId() != GetId()) {
957         if (needHidePrivacyContent_ && IsOnTheTree()) {
958             firstLevelNode->privacyContentLayerIds_.insert(GetId());
959         } else {
960             firstLevelNode->privacyContentLayerIds_.erase(GetId());
961         }
962     }
963 }
964 
SetFingerprint(bool hasFingerprint)965 void RSSurfaceRenderNode::SetFingerprint(bool hasFingerprint)
966 {
967     hasFingerprint_ = hasFingerprint;
968 }
969 
GetFingerprint() const970 bool RSSurfaceRenderNode::GetFingerprint() const
971 {
972     return hasFingerprint_;
973 }
974 
SetForceUIFirst(bool forceUIFirst)975 void RSSurfaceRenderNode::SetForceUIFirst(bool forceUIFirst)
976 {
977     if (forceUIFirst) {
978         forceUIFirstChanged_ = true;
979     }
980     forceUIFirst_ = forceUIFirst;
981 }
GetForceUIFirst() const982 bool RSSurfaceRenderNode::GetForceUIFirst() const
983 {
984     return forceUIFirst_;
985 }
986 
SetHDRPresent(bool hasHdrPresent)987 void RSSurfaceRenderNode::SetHDRPresent(bool hasHdrPresent)
988 {
989     hasHdrPresent_ = hasHdrPresent;
990 }
991 
GetHDRPresent() const992 bool RSSurfaceRenderNode::GetHDRPresent() const
993 {
994     return hasHdrPresent_;
995 }
996 
SetForceUIFirstChanged(bool forceUIFirstChanged)997 void RSSurfaceRenderNode::SetForceUIFirstChanged(bool forceUIFirstChanged)
998 {
999     forceUIFirstChanged_ = forceUIFirstChanged;
1000 }
GetForceUIFirstChanged()1001 bool RSSurfaceRenderNode::GetForceUIFirstChanged()
1002 {
1003     return forceUIFirstChanged_;
1004 }
1005 
SetAncoForceDoDirect(bool direct)1006 void RSSurfaceRenderNode::SetAncoForceDoDirect(bool direct)
1007 {
1008     ancoForceDoDirect_.store(direct);
1009 }
1010 
GetAncoForceDoDirect() const1011 bool RSSurfaceRenderNode::GetAncoForceDoDirect() const
1012 {
1013     return (ancoForceDoDirect_.load() && (GetAncoFlags() & static_cast<uint32_t>(AncoFlags::IS_ANCO_NODE)));
1014 }
1015 
SetAncoFlags(uint32_t flags)1016 void RSSurfaceRenderNode::SetAncoFlags(uint32_t flags)
1017 {
1018     ancoFlags_.store(flags);
1019 }
1020 
GetAncoFlags() const1021 uint32_t RSSurfaceRenderNode::GetAncoFlags() const
1022 {
1023     return ancoFlags_.load();
1024 }
1025 
RegisterTreeStateChangeCallback(TreeStateChangeCallback callback)1026 void RSSurfaceRenderNode::RegisterTreeStateChangeCallback(TreeStateChangeCallback callback)
1027 {
1028     treeStateChangeCallback_ = callback;
1029 }
1030 
NotifyTreeStateChange()1031 void RSSurfaceRenderNode::NotifyTreeStateChange()
1032 {
1033     if (treeStateChangeCallback_) {
1034         treeStateChangeCallback_(*this);
1035     }
1036 }
1037 
SetLayerTop(bool isTop)1038 void RSSurfaceRenderNode::SetLayerTop(bool isTop)
1039 {
1040     isLayerTop_ = isTop;
1041     SetContentDirty();
1042     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1043     if (surfaceParams == nullptr) {
1044         return;
1045     }
1046     surfaceParams->SetLayerTop(isTop);
1047     AddToPendingSyncList();
1048 }
1049 
SetColorSpace(GraphicColorGamut colorSpace)1050 void RSSurfaceRenderNode::SetColorSpace(GraphicColorGamut colorSpace)
1051 {
1052     colorSpace_ = colorSpace;
1053 }
1054 
GetColorSpace() const1055 GraphicColorGamut RSSurfaceRenderNode::GetColorSpace() const
1056 {
1057     return colorSpace_;
1058 }
1059 
UpdateColorSpaceWithMetadata()1060 void RSSurfaceRenderNode::UpdateColorSpaceWithMetadata()
1061 {
1062 #ifndef ROSEN_CROSS_PLATFORM
1063     if (!GetRSSurfaceHandler() || !GetRSSurfaceHandler()->GetBuffer()) {
1064         RS_LOGD("RSSurfaceRenderNode::UpdateColorSpaceWithMetadata node(%{public}s) did not have buffer.",
1065             GetName().c_str());
1066         return;
1067     }
1068     const sptr<SurfaceBuffer>& buffer = GetRSSurfaceHandler()->GetBuffer();
1069     using namespace HDI::Display::Graphic::Common::V1_0;
1070     CM_ColorSpaceInfo colorSpaceInfo;
1071     if (MetadataHelper::GetColorSpaceInfo(buffer, colorSpaceInfo) != GSERROR_OK) {
1072         RS_LOGD("RSSurfaceRenderNode::UpdateColorSpaceWithMetadata get color space info failed.");
1073         return;
1074     }
1075     // currently, P3 is the only supported wide color gamut, this may be modified later.
1076     colorSpace_ = colorSpaceInfo.primaries != COLORPRIMARIES_SRGB ?
1077         GRAPHIC_COLOR_GAMUT_DISPLAY_P3 : GRAPHIC_COLOR_GAMUT_SRGB;
1078 #endif
1079 }
1080 
UpdateSurfaceDefaultSize(float width,float height)1081 void RSSurfaceRenderNode::UpdateSurfaceDefaultSize(float width, float height)
1082 {
1083 #ifndef ROSEN_CROSS_PLATFORM
1084     if (!surfaceHandler_) {
1085         return;
1086     }
1087     auto consumer = surfaceHandler_->GetConsumer();
1088     if (!consumer) {
1089         return;
1090     }
1091     consumer->SetDefaultWidthAndHeight(width, height);
1092 #else
1093 #ifdef USE_SURFACE_TEXTURE
1094     auto texture = GetSurfaceTexture();
1095     if (texture) {
1096         texture->UpdateSurfaceDefaultSize(width, height);
1097     }
1098 #endif
1099 #endif
1100 }
1101 
1102 #ifndef ROSEN_CROSS_PLATFORM
UpdateBufferInfo(const sptr<SurfaceBuffer> & buffer,const Rect & damageRect,const sptr<SyncFence> & acquireFence,const sptr<SurfaceBuffer> & preBuffer)1103 void RSSurfaceRenderNode::UpdateBufferInfo(const sptr<SurfaceBuffer>& buffer, const Rect& damageRect,
1104     const sptr<SyncFence>& acquireFence, const sptr<SurfaceBuffer>& preBuffer)
1105 {
1106     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1107     if (!surfaceParams->IsBufferSynced()) {
1108         auto curBuffer = surfaceParams->GetBuffer();
1109         auto consumer = GetRSSurfaceHandler()->GetConsumer();
1110         if (curBuffer && consumer) {
1111             auto fence = surfaceParams->GetAcquireFence();
1112             consumer->ReleaseBuffer(curBuffer, fence);
1113         }
1114     } else {
1115         surfaceParams->SetPreBuffer(preBuffer);
1116     }
1117 
1118     surfaceParams->SetBuffer(buffer, damageRect);
1119     surfaceParams->SetAcquireFence(acquireFence);
1120     surfaceParams->SetBufferSynced(false);
1121     AddToPendingSyncList();
1122 }
1123 
NeedClearBufferCache()1124 void RSSurfaceRenderNode::NeedClearBufferCache()
1125 {
1126     if (!surfaceHandler_) {
1127         return;
1128     }
1129 
1130     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1131     std::set<int32_t> bufferCacheSet;
1132     if (auto buffer = surfaceHandler_->GetBuffer()) {
1133         bufferCacheSet.insert(buffer->GetSeqNum());
1134     }
1135     if (auto preBuffer = surfaceHandler_->GetPreBuffer()) {
1136         bufferCacheSet.insert(preBuffer->GetSeqNum());
1137     }
1138     surfaceParams->SetBufferClearCacheSet(bufferCacheSet);
1139     AddToPendingSyncList();
1140 }
1141 #endif
1142 
1143 #ifndef ROSEN_CROSS_PLATFORM
GetBlendType()1144 GraphicBlendType RSSurfaceRenderNode::GetBlendType()
1145 {
1146     return blendType_;
1147 }
1148 
SetBlendType(GraphicBlendType blendType)1149 void RSSurfaceRenderNode::SetBlendType(GraphicBlendType blendType)
1150 {
1151     blendType_ = blendType;
1152 }
1153 #endif
1154 
RegisterBufferAvailableListener(sptr<RSIBufferAvailableCallback> callback,bool isFromRenderThread)1155 void RSSurfaceRenderNode::RegisterBufferAvailableListener(
1156     sptr<RSIBufferAvailableCallback> callback, bool isFromRenderThread)
1157 {
1158     if (isFromRenderThread) {
1159         std::lock_guard<std::mutex> lock(mutexRT_);
1160         callbackFromRT_ = callback;
1161     } else {
1162         {
1163             std::lock_guard<std::mutex> lock(mutexUI_);
1164             callbackFromUI_ = callback;
1165         }
1166         isNotifyUIBufferAvailable_ = false;
1167     }
1168 }
1169 
RegisterBufferClearListener(sptr<RSIBufferClearCallback> callback)1170 void RSSurfaceRenderNode::RegisterBufferClearListener(
1171     sptr<RSIBufferClearCallback> callback)
1172 {
1173     std::lock_guard<std::mutex> lock(mutexClear_);
1174     clearBufferCallback_ = callback;
1175 }
1176 
SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable)1177 void RSSurfaceRenderNode::SetNotifyRTBufferAvailable(bool isNotifyRTBufferAvailable)
1178 {
1179     isNotifyRTBufferAvailable_ = isNotifyRTBufferAvailable;
1180     if (GetIsTextureExportNode()) {
1181         SetContentDirty();
1182     }
1183     std::lock_guard<std::mutex> lock(mutexClear_);
1184     if (clearBufferCallback_) {
1185         clearBufferCallback_->OnBufferClear();
1186     }
1187 }
1188 
ConnectToNodeInRenderService()1189 void RSSurfaceRenderNode::ConnectToNodeInRenderService()
1190 {
1191     ROSEN_LOGI("RSSurfaceRenderNode::ConnectToNodeInRenderService nodeId = %{public}" PRIu64, GetId());
1192     auto renderServiceClient =
1193         std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
1194     if (renderServiceClient != nullptr) {
1195         renderServiceClient->RegisterBufferAvailableListener(
1196             GetId(), [weakThis = weak_from_this()]() {
1197                 auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(weakThis.lock());
1198                 if (node == nullptr) {
1199                     return;
1200                 }
1201                 node->NotifyRTBufferAvailable(node->GetIsTextureExportNode());
1202             }, true);
1203         renderServiceClient->RegisterBufferClearListener(
1204             GetId(), [weakThis = weak_from_this()]() {
1205                 auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(weakThis.lock());
1206                 if (node == nullptr) {
1207                     return;
1208                 }
1209                 node->SetNotifyRTBufferAvailable(false);
1210             });
1211     }
1212 }
1213 
NotifyRTBufferAvailable(bool isTextureExportNode)1214 void RSSurfaceRenderNode::NotifyRTBufferAvailable(bool isTextureExportNode)
1215 {
1216     // In RS, "isNotifyRTBufferAvailable_ = true" means buffer is ready and need to trigger ipc callback.
1217     // In RT, "isNotifyRTBufferAvailable_ = true" means RT know that RS have had available buffer
1218     // and ready to trigger "callbackForRenderThreadRefresh_" to "clip" on parent surface.
1219     if (!isTextureExportNode) {
1220         isNotifyRTBufferAvailablePre_ = isNotifyRTBufferAvailable_;
1221         if (isNotifyRTBufferAvailable_) {
1222             return;
1223         }
1224         isNotifyRTBufferAvailable_ = true;
1225     }
1226 
1227     if (isRefresh_) {
1228         ROSEN_LOGI("RSSurfaceRenderNode::NotifyRTBufferAvailable nodeId = %{public}" PRIu64 " RenderThread", GetId());
1229         RSRTRefreshCallback::Instance().ExecuteRefresh();
1230     }
1231     if (isTextureExportNode) {
1232         SetContentDirty();
1233     }
1234 
1235     {
1236         std::lock_guard<std::mutex> lock(mutexRT_);
1237         if (callbackFromRT_) {
1238             ROSEN_LOGI("RSSurfaceRenderNode::NotifyRTBufferAvailable nodeId = %{public}" PRIu64 " RenderService",
1239                 GetId());
1240             callbackFromRT_->OnBufferAvailable();
1241         }
1242         if (!isRefresh_ && !callbackFromRT_) {
1243             isNotifyRTBufferAvailable_ = false;
1244         }
1245     }
1246 }
1247 
NotifyUIBufferAvailable()1248 void RSSurfaceRenderNode::NotifyUIBufferAvailable()
1249 {
1250     RS_TRACE_NAME_FMT("RSSurfaceRenderNode::NotifyUIBufferAvailable id:%llu bufferAvailable:%d waitUifirst:%d",
1251         GetId(), IsNotifyUIBufferAvailable(), IsWaitUifirstFirstFrame());
1252     if (isNotifyUIBufferAvailable_ || isWaitUifirstFirstFrame_) {
1253         return;
1254     }
1255     isNotifyUIBufferAvailable_ = true;
1256     {
1257         std::lock_guard<std::mutex> lock(mutexUI_);
1258         if (callbackFromUI_) {
1259             RS_TRACE_NAME_FMT("NotifyUIBufferAvailable done. id:%llu", GetId());
1260             ROSEN_LOGI("RSSurfaceRenderNode::NotifyUIBufferAvailable nodeId = %{public}" PRIu64, GetId());
1261             callbackFromUI_->OnBufferAvailable();
1262 #ifdef OHOS_PLATFORM
1263             if (IsAppWindow()) {
1264                 RSJankStats::GetInstance().SetAppFirstFrame(ExtractPid(GetId()));
1265             }
1266 #endif
1267         }
1268     }
1269 }
1270 
IsNotifyRTBufferAvailable() const1271 bool RSSurfaceRenderNode::IsNotifyRTBufferAvailable() const
1272 {
1273 #if defined(ROSEN_ANDROID) || defined(ROSEN_IOS)
1274     return true;
1275 #else
1276     return isNotifyRTBufferAvailable_;
1277 #endif
1278 }
1279 
IsNotifyRTBufferAvailablePre() const1280 bool RSSurfaceRenderNode::IsNotifyRTBufferAvailablePre() const
1281 {
1282 #if defined(ROSEN_ANDROID) || defined(ROSEN_IOS)
1283     return true;
1284 #else
1285     return isNotifyRTBufferAvailablePre_;
1286 #endif
1287 }
1288 
IsNotifyUIBufferAvailable() const1289 bool RSSurfaceRenderNode::IsNotifyUIBufferAvailable() const
1290 {
1291     return isNotifyUIBufferAvailable_;
1292 }
1293 
SetCallbackForRenderThreadRefresh(bool isRefresh)1294 void RSSurfaceRenderNode::SetCallbackForRenderThreadRefresh(bool isRefresh)
1295 {
1296     isRefresh_ = isRefresh;
1297 }
1298 
NeedSetCallbackForRenderThreadRefresh()1299 bool RSSurfaceRenderNode::NeedSetCallbackForRenderThreadRefresh()
1300 {
1301     return !isRefresh_;
1302 }
1303 
IsStartAnimationFinished() const1304 bool RSSurfaceRenderNode::IsStartAnimationFinished() const
1305 {
1306     return startAnimationFinished_;
1307 }
1308 
SetStartAnimationFinished()1309 void RSSurfaceRenderNode::SetStartAnimationFinished()
1310 {
1311     RS_LOGD("RSSurfaceRenderNode::SetStartAnimationFinished");
1312     startAnimationFinished_ = true;
1313 }
1314 
UpdateDirtyIfFrameBufferConsumed()1315 bool RSSurfaceRenderNode::UpdateDirtyIfFrameBufferConsumed()
1316 {
1317     if (surfaceHandler_ && surfaceHandler_->IsCurrentFrameBufferConsumed()) {
1318         SetContentDirty();
1319         return true;
1320     }
1321     return false;
1322 }
1323 
IsSurfaceInStartingWindowStage() const1324 bool RSSurfaceRenderNode::IsSurfaceInStartingWindowStage() const
1325 {
1326     auto parentPtr = this->GetParent().lock();
1327     if (parentPtr != nullptr && parentPtr->IsInstanceOf<RSSurfaceRenderNode>()) {
1328         auto surfaceParentPtr = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(parentPtr);
1329         if (surfaceParentPtr->GetSurfaceNodeType() == RSSurfaceNodeType::LEASH_WINDOW_NODE &&
1330             !this->IsNotifyUIBufferAvailable()) {
1331             return true;
1332         }
1333     }
1334     return false;
1335 }
1336 
IsParentLeashWindowInScale() const1337 bool RSSurfaceRenderNode::IsParentLeashWindowInScale() const
1338 {
1339     auto parentPtr = this->GetParent().lock();
1340     if (parentPtr != nullptr && parentPtr->IsInstanceOf<RSSurfaceRenderNode>()) {
1341         auto surfaceParentPtr = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(parentPtr);
1342         if (surfaceParentPtr->IsLeashWindow() && surfaceParentPtr->IsScale()) {
1343             return true;
1344         }
1345     }
1346     return false;
1347 }
1348 
GetSurfaceOcclusionRect(bool isUniRender)1349 Occlusion::Rect RSSurfaceRenderNode::GetSurfaceOcclusionRect(bool isUniRender)
1350 {
1351     Occlusion::Rect occlusionRect;
1352     if (isUniRender) {
1353         occlusionRect = Occlusion::Rect {GetOldDirtyInSurface()};
1354     } else {
1355         occlusionRect = Occlusion::Rect {GetDstRect()};
1356     }
1357     return occlusionRect;
1358 }
1359 
QueryIfAllHwcChildrenForceDisabledByFilter()1360 bool RSSurfaceRenderNode::QueryIfAllHwcChildrenForceDisabledByFilter()
1361 {
1362     std::shared_ptr<RSSurfaceRenderNode> appWindow;
1363     for (auto& child : *GetSortedChildren()) {
1364         auto node = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child);
1365         if (node && node->IsAppWindow()) {
1366             appWindow = node;
1367             break;
1368         }
1369     }
1370     if (appWindow) {
1371         auto hardwareEnabledNodes = appWindow->GetChildHardwareEnabledNodes();
1372         for (auto& hardwareEnabledNode : hardwareEnabledNodes) {
1373             auto hardwareEnabledNodePtr = hardwareEnabledNode.lock();
1374             if (hardwareEnabledNodePtr && !hardwareEnabledNodePtr->IsHardwareForcedDisabledByFilter()) {
1375                 return false;
1376             }
1377         }
1378     }
1379     return true;
1380 }
1381 
AccumulateOcclusionRegion(Occlusion::Region & accumulatedRegion,Occlusion::Region & curRegion,bool & hasFilterCacheOcclusion,bool isUniRender,bool filterCacheOcclusionEnabled)1382 void RSSurfaceRenderNode::AccumulateOcclusionRegion(Occlusion::Region& accumulatedRegion,
1383     Occlusion::Region& curRegion,
1384     bool& hasFilterCacheOcclusion,
1385     bool isUniRender,
1386     bool filterCacheOcclusionEnabled)
1387 {
1388     // when surfacenode is in starting window stage, do not occlude other window surfaces
1389     // fix gray block when directly open app (i.e. setting) from notification center
1390     if (IsSurfaceInStartingWindowStage()) {
1391         return;
1392     }
1393     if (!isUniRender) {
1394         bool diff =
1395 #ifndef ROSEN_CROSS_PLATFORM
1396             (GetDstRect().width_ > surfaceHandler_->GetBuffer()->GetWidth() ||
1397                 GetDstRect().height_ > surfaceHandler_->GetBuffer()->GetHeight()) &&
1398 #endif
1399             GetRenderProperties().GetFrameGravity() != Gravity::RESIZE && ROSEN_EQ(GetGlobalAlpha(), 1.0f);
1400         if (!IsTransparent() && !diff) {
1401             accumulatedRegion.OrSelf(curRegion);
1402         }
1403     }
1404 
1405     if (GetName().find("hisearch") != std::string::npos) {
1406         return;
1407     }
1408     SetTreatedAsTransparent(false);
1409     // when a surfacenode is in animation (i.e. 3d animation), its dstrect cannot be trusted, we treated it as a full
1410     // transparent layer.
1411     if ((GetAnimateState() || IsParentLeashWindowInScale()) && !isOcclusionInSpecificScenes_) {
1412         SetTreatedAsTransparent(true);
1413         return;
1414     }
1415 
1416     // full surfacenode valid filter cache can be treated as opaque
1417     if (filterCacheOcclusionEnabled && IsTransparent() && GetFilterCacheValidForOcclusion()) {
1418         accumulatedRegion.OrSelf(curRegion);
1419         hasFilterCacheOcclusion = true;
1420     } else {
1421         accumulatedRegion.OrSelf(GetOpaqueRegion());
1422     }
1423     return;
1424 }
1425 
GetVisibleLevelForWMS(RSVisibleLevel visibleLevel)1426 WINDOW_LAYER_INFO_TYPE RSSurfaceRenderNode::GetVisibleLevelForWMS(RSVisibleLevel visibleLevel)
1427 {
1428     switch (visibleLevel) {
1429         case RSVisibleLevel::RS_INVISIBLE:
1430             return WINDOW_LAYER_INFO_TYPE::INVISIBLE;
1431         case RSVisibleLevel::RS_ALL_VISIBLE:
1432             return WINDOW_LAYER_INFO_TYPE::ALL_VISIBLE;
1433         case RSVisibleLevel::RS_SEMI_NONDEFAULT_VISIBLE:
1434         case RSVisibleLevel::RS_SEMI_DEFAULT_VISIBLE:
1435             return WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE;
1436         default:
1437             break;
1438     }
1439     return WINDOW_LAYER_INFO_TYPE::SEMI_VISIBLE;
1440 }
1441 
IsSCBNode() const1442 bool RSSurfaceRenderNode::IsSCBNode() const
1443 {
1444     return surfaceWindowType_ != SurfaceWindowType::SYSTEM_SCB_WINDOW;
1445 }
1446 
UpdateHwcNodeLayerInfo(GraphicTransformType transform)1447 void RSSurfaceRenderNode::UpdateHwcNodeLayerInfo(GraphicTransformType transform)
1448 {
1449 #ifndef ROSEN_CROSS_PLATFORM
1450     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1451     auto layer = surfaceParams->GetLayerInfo();
1452     layer.srcRect = {srcRect_.left_, srcRect_.top_, srcRect_.width_, srcRect_.height_};
1453     layer.dstRect = {dstRect_.left_, dstRect_.top_, dstRect_.width_, dstRect_.height_};
1454     const auto& properties = GetRenderProperties();
1455     layer.boundRect = {0, 0,
1456         static_cast<uint32_t>(properties.GetBoundsWidth()),
1457         static_cast<uint32_t>(properties.GetBoundsHeight())};
1458     layer.transformType = transform;
1459     layer.zOrder = surfaceHandler_->GetGlobalZOrder();
1460     layer.gravity = static_cast<int32_t>(properties.GetFrameGravity());
1461     layer.blendType = GetBlendType();
1462     layer.matrix = totalMatrix_;
1463     layer.alpha = GetGlobalAlpha();
1464     layer.arsrTag = GetArsrTag();
1465     isHardwareForcedDisabled_ = isProtectedLayer_ ? false : isHardwareForcedDisabled_;
1466 #ifndef ROSEN_CROSS_PLATFORM
1467     auto buffer = surfaceHandler_->GetBuffer();
1468     RS_LOGD("RSSurfaceRenderNode::UpdateHwcNodeLayerInfo: name:%{public}s id:%{public}" PRIu64 ", bufferFormat:%d,"
1469         " src:%{public}s, dst:%{public}s, bounds:[%{public}d, %{public}d] buffer:[%{public}d, %{public}d]"
1470         " transform:%{public}d, zOrder:%{public}d, cur:%{public}d, last:%{public}d",
1471         GetName().c_str(), GetId(), buffer ? buffer->GetFormat() : -1,
1472         srcRect_.ToString().c_str(),
1473         dstRect_.ToString().c_str(),
1474         layer.boundRect.w, layer.boundRect.h,
1475         buffer ? buffer->GetSurfaceBufferWidth() : 0, buffer ? buffer->GetSurfaceBufferHeight() : 0,
1476         transform, layer.zOrder, !IsHardwareForcedDisabled(), isLastFrameHwcEnabled_);
1477     RS_OPTIONAL_TRACE_NAME_FMT("hwc debug:UpdateHwcNodeLayerInfo: name:%s id:%lu, bufferFormat:%d,"
1478         " src:%s, dst:%s, bounds:[%d, %d], buffer:[%d, %d], transform:%d, zOrder:%d, cur:%d, last:%d",
1479         GetName().c_str(), GetId(), buffer ? buffer->GetFormat() : -1,
1480         srcRect_.ToString().c_str(),
1481         dstRect_.ToString().c_str(),
1482         layer.boundRect.w, layer.boundRect.h,
1483         buffer ? buffer->GetSurfaceBufferWidth() : 0, buffer ? buffer->GetSurfaceBufferHeight() : 0,
1484         transform, layer.zOrder, !IsHardwareForcedDisabled(), isLastFrameHwcEnabled_);
1485 #endif
1486     surfaceParams->SetLayerInfo(layer);
1487     surfaceParams->SetHardwareEnabled(!IsHardwareForcedDisabled());
1488     surfaceParams->SetLastFrameHardwareEnabled(isLastFrameHwcEnabled_);
1489     surfaceParams->SetInFixedRotation(isInFixedRotation_);
1490     // 1 means need source tuning
1491     if (RsCommonHook::Instance().GetVideoSurfaceFlag() && IsYUVBufferFormat()) {
1492         surfaceParams->SetLayerSourceTuning(1);
1493     }
1494     AddToPendingSyncList();
1495 #endif
1496 }
1497 
UpdateHardwareDisabledState(bool disabled)1498 void RSSurfaceRenderNode::UpdateHardwareDisabledState(bool disabled)
1499 {
1500     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1501     surfaceParams->SetLastFrameHardwareEnabled(!IsHardwareForcedDisabled());
1502     SetHardwareForcedDisabledState(disabled);
1503     surfaceParams->SetHardwareEnabled(!IsHardwareForcedDisabled());
1504     AddToPendingSyncList();
1505 }
1506 
SetVisibleRegionRecursive(const Occlusion::Region & region,VisibleData & visibleVec,std::map<NodeId,RSVisibleLevel> & visMapForVsyncRate,bool needSetVisibleRegion,RSVisibleLevel visibleLevel,bool isSystemAnimatedScenes)1507 void RSSurfaceRenderNode::SetVisibleRegionRecursive(const Occlusion::Region& region,
1508                                                     VisibleData& visibleVec,
1509                                                     std::map<NodeId, RSVisibleLevel>& visMapForVsyncRate,
1510                                                     bool needSetVisibleRegion,
1511                                                     RSVisibleLevel visibleLevel,
1512                                                     bool isSystemAnimatedScenes)
1513 {
1514     if (nodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE || IsAbilityComponent()) {
1515         SetOcclusionVisible(true);
1516         visibleVec.emplace_back(std::make_pair(GetId(), ALL_VISIBLE));
1517         return;
1518     }
1519 
1520     bool vis = !region.IsEmpty();
1521     if (vis) {
1522         visibleVec.emplace_back(std::make_pair(GetId(), GetVisibleLevelForWMS(visibleLevel)));
1523     }
1524 
1525     // collect visible changed pid
1526     if (qosPidCal_ && GetType() == RSRenderNodeType::SURFACE_NODE && !isSystemAnimatedScenes) {
1527         visMapForVsyncRate[GetId()] = !IsSCBNode() ? RSVisibleLevel::RS_ALL_VISIBLE : visibleLevel;
1528     }
1529 
1530     visibleRegionForCallBack_ = region;
1531     if (needSetVisibleRegion) {
1532         visibleRegion_ = region;
1533         SetOcclusionVisible(vis);
1534     }
1535     // when there is filter cache occlusion, also save occlusion status without filter cache
1536     SetOcclusionVisibleWithoutFilter(vis);
1537 
1538     for (auto& child : *GetChildren()) {
1539         if (auto surfaceChild = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child)) {
1540             surfaceChild->SetVisibleRegionRecursive(region, visibleVec, visMapForVsyncRate, needSetVisibleRegion,
1541                 visibleLevel, isSystemAnimatedScenes);
1542         }
1543     }
1544 }
1545 
ResetSurfaceOpaqueRegion(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow,const Vector4<int> & cornerRadius)1546 void RSSurfaceRenderNode::ResetSurfaceOpaqueRegion(const RectI& screeninfo, const RectI& absRect,
1547     const ScreenRotation screenRotation, const bool isFocusWindow, const Vector4<int>& cornerRadius)
1548 {
1549     Occlusion::Rect absRectR { absRect };
1550     Occlusion::Region oldOpaqueRegion { opaqueRegion_ };
1551 
1552     // The transparent region of surfaceNode should include shadow area
1553     Occlusion::Rect dirtyRect { GetOldDirty() };
1554     transparentRegion_ = Occlusion::Region{ dirtyRect };
1555 
1556     if (IsTransparent()) {
1557         opaqueRegion_ = Occlusion::Region();
1558     } else {
1559         if (IsAppWindow() && HasContainerWindow()) {
1560             opaqueRegion_ = ResetOpaqueRegion(absRect, screenRotation, isFocusWindow);
1561         } else {
1562             if (!cornerRadius.IsZero()) {
1563                 auto maxRadius = std::max({ cornerRadius.x_, cornerRadius.y_, cornerRadius.z_, cornerRadius.w_ });
1564                 Vector4<int> dstCornerRadius((cornerRadius.x_ > 0 ? maxRadius : 0),
1565                                              (cornerRadius.y_ > 0 ? maxRadius : 0),
1566                                              (cornerRadius.z_ > 0 ? maxRadius : 0),
1567                                              (cornerRadius.w_ > 0 ? maxRadius : 0));
1568                 opaqueRegion_ = SetCornerRadiusOpaqueRegion(absRect, dstCornerRadius);
1569             } else {
1570                 opaqueRegion_ = Occlusion::Region{absRectR};
1571             }
1572         }
1573         transparentRegion_.SubSelf(opaqueRegion_);
1574     }
1575     Occlusion::Rect screen{screeninfo};
1576     Occlusion::Region screenRegion{screen};
1577     transparentRegion_.AndSelf(screenRegion);
1578     opaqueRegion_.AndSelf(screenRegion);
1579     opaqueRegionChanged_ = !oldOpaqueRegion.Xor(opaqueRegion_).IsEmpty();
1580     ResetSurfaceContainerRegion(screeninfo, absRect, screenRotation);
1581 }
1582 
CalcFilterCacheValidForOcclusion()1583 void RSSurfaceRenderNode::CalcFilterCacheValidForOcclusion()
1584 {
1585     isFilterCacheStatusChanged_ = false;
1586     bool currentCacheValidForOcclusion = isFilterCacheFullyCovered_ && dirtyManager_->IsFilterCacheRectValid();
1587     if (isFilterCacheValidForOcclusion_ != currentCacheValidForOcclusion) {
1588         isFilterCacheValidForOcclusion_ = currentCacheValidForOcclusion;
1589         isFilterCacheStatusChanged_ = true;
1590     }
1591 }
1592 
UpdateFilterNodes(const std::shared_ptr<RSRenderNode> & nodePtr)1593 void RSSurfaceRenderNode::UpdateFilterNodes(const std::shared_ptr<RSRenderNode>& nodePtr)
1594 {
1595     if (nodePtr == nullptr) {
1596         return;
1597     }
1598     filterNodes_.emplace_back(nodePtr);
1599 }
1600 
CheckValidFilterCacheFullyCoverTarget(const RSRenderNode & filterNode,const RectI & targetRect)1601 void RSSurfaceRenderNode::CheckValidFilterCacheFullyCoverTarget(const RSRenderNode& filterNode, const RectI& targetRect)
1602 {
1603     if (filterNode.IsInstanceOf<RSEffectRenderNode>()) {
1604         return;
1605     }
1606     if (isFilterCacheFullyCovered_ || !filterNode.IsFilterCacheValid()) {
1607         return;
1608     }
1609     // AbsRect may not update here, so use filterCachedRegion to occlude
1610     isFilterCacheFullyCovered_ = targetRect.IsInsideOf(filterNode.GetFilterCachedRegion());
1611 }
1612 
UpdateOccludedByFilterCache(bool val)1613 void RSSurfaceRenderNode::UpdateOccludedByFilterCache(bool val)
1614 {
1615     isOccludedByFilterCache_ = val;
1616     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1617     surfaceParams->SetOccludedByFilterCache(isOccludedByFilterCache_);
1618 }
1619 
UpdateSurfaceCacheContentStaticFlag()1620 void RSSurfaceRenderNode::UpdateSurfaceCacheContentStaticFlag()
1621 {
1622     auto contentStatic = false;
1623     if (IsLeashWindow() || IsAbilityComponent()) {
1624         contentStatic = (!IsSubTreeDirty() || GetForceUpdateByUifirst()) && !HasRemovedChild();
1625     } else {
1626         contentStatic = surfaceCacheContentStatic_;
1627     }
1628     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1629     if (stagingSurfaceParams) {
1630         stagingSurfaceParams->SetSurfaceCacheContentStatic(contentStatic, lastFrameSynced_);
1631     }
1632     if (stagingRenderParams_->NeedSync()) {
1633         AddToPendingSyncList();
1634     }
1635     RS_OPTIONAL_TRACE_NAME_FMT("RSSurfaceRenderNode::UpdateSurfaceCacheContentStaticFlag: "
1636         "[%d] name:[%s] Id:[%" PRIu64 "] subDirty:[%d] forceUpdate:[%d]",
1637         contentStatic, GetName().c_str(), GetId(), IsSubTreeDirty(), GetForceUpdateByUifirst());
1638 }
1639 
IsOccludedByFilterCache() const1640 bool RSSurfaceRenderNode::IsOccludedByFilterCache() const
1641 {
1642     return isOccludedByFilterCache_;
1643 }
1644 
UpdateSurfaceSubTreeDirtyFlag()1645 void RSSurfaceRenderNode::UpdateSurfaceSubTreeDirtyFlag()
1646 {
1647     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
1648     if (stagingSurfaceParams) {
1649         stagingSurfaceParams->SetSurfaceSubTreeDirty(IsSubTreeDirty());
1650     }
1651     if (stagingRenderParams_->NeedSync()) {
1652         AddToPendingSyncList();
1653     }
1654 }
1655 
UpdateDrawingCacheNodes(const std::shared_ptr<RSRenderNode> & nodePtr)1656 void RSSurfaceRenderNode::UpdateDrawingCacheNodes(const std::shared_ptr<RSRenderNode>& nodePtr)
1657 {
1658     if (nodePtr == nullptr) {
1659         return;
1660     }
1661     drawingCacheNodes_.emplace(nodePtr->GetId(), nodePtr);
1662 }
1663 
ResetDrawingCacheStatusIfNodeStatic(std::unordered_map<NodeId,std::unordered_set<NodeId>> & allRects)1664 void RSSurfaceRenderNode::ResetDrawingCacheStatusIfNodeStatic(
1665     std::unordered_map<NodeId, std::unordered_set<NodeId>>& allRects)
1666 {
1667     // traversal drawing cache nodes including app window
1668     EraseIf(drawingCacheNodes_, [this, &allRects](const auto& pair) {
1669         auto node = pair.second.lock();
1670         if (node == nullptr || !node->IsOnTheTree()) {
1671             return true;
1672         }
1673         node->SetDrawingCacheChanged(false);
1674         node->GetFilterRectsInCache(allRects);
1675         return false;
1676     });
1677 }
1678 
UpdateFilterCacheStatusWithVisible(bool visible)1679 void RSSurfaceRenderNode::UpdateFilterCacheStatusWithVisible(bool visible)
1680 {
1681     if (visible == prevVisible_) {
1682         return;
1683     }
1684     prevVisible_ = visible;
1685 #if (defined(RS_ENABLE_GL) || defined(RS_ENABLE_VK))
1686     if (!RSUniRenderJudgement::IsUniRender() && !visible && !filterNodes_.empty()
1687         && !isOcclusionVisibleWithoutFilter_) {
1688         for (auto& node : filterNodes_) {
1689             node->GetMutableRenderProperties().ClearFilterCache();
1690         }
1691     }
1692 #endif
1693 }
1694 
UpdateFilterCacheStatusIfNodeStatic(const RectI & clipRect,bool isRotationChanged)1695 void RSSurfaceRenderNode::UpdateFilterCacheStatusIfNodeStatic(const RectI& clipRect, bool isRotationChanged)
1696 {
1697     // traversal filter nodes including app window
1698     for (auto node : filterNodes_) {
1699         if (node == nullptr || !node->IsOnTheTree() || !node->GetRenderProperties().NeedFilter()) {
1700             continue;
1701         }
1702         if (node->IsInstanceOf<RSEffectRenderNode>()) {
1703             if (auto effectNode = node->ReinterpretCastTo<RSEffectRenderNode>()) {
1704                 effectNode->SetRotationChanged(isRotationChanged);
1705             }
1706         }
1707         if (node->GetRenderProperties().GetBackgroundFilter()) {
1708             node->UpdateFilterCacheWithBelowDirty(*dirtyManager_);
1709         }
1710         if (node->GetRenderProperties().GetFilter()) {
1711             node->UpdateFilterCacheWithBelowDirty(*dirtyManager_);
1712         }
1713         node->UpdateFilterCacheWithSelfDirty();
1714     }
1715     SetFilterCacheFullyCovered(false);
1716     if (IsTransparent() && dirtyManager_->IfCacheableFilterRectFullyCover(GetOldDirtyInSurface())) {
1717         SetFilterCacheFullyCovered(true);
1718         RS_LOGD("UpdateFilterCacheStatusIfNodeStatic surfacenode %{public}" PRIu64 " [%{public}s] rectsize %{public}s",
1719             GetId(), GetName().c_str(), GetOldDirtyInSurface().ToString().c_str());
1720     }
1721     CalcFilterCacheValidForOcclusion();
1722 }
1723 
GetWindowCornerRadius()1724 Vector4f RSSurfaceRenderNode::GetWindowCornerRadius()
1725 {
1726     if (!GetRenderProperties().GetCornerRadius().IsZero()) {
1727         return GetRenderProperties().GetCornerRadius();
1728     }
1729     auto parent = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetParent().lock());
1730     if (parent != nullptr && parent->IsLeashWindow()) {
1731         return parent->GetRenderProperties().GetCornerRadius();
1732     }
1733     return Vector4f();
1734 }
1735 
ResetOpaqueRegion(const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow) const1736 Occlusion::Region RSSurfaceRenderNode::ResetOpaqueRegion(const RectI& absRect,
1737     const ScreenRotation screenRotation, const bool isFocusWindow) const
1738 {
1739     if (isFocusWindow) {
1740         return SetFocusedWindowOpaqueRegion(absRect, screenRotation);
1741     } else {
1742         return SetUnfocusedWindowOpaqueRegion(absRect, screenRotation);
1743     }
1744 }
1745 
Update(bool hasContainer,float density)1746 void RSSurfaceRenderNode::ContainerConfig::Update(bool hasContainer, float density)
1747 {
1748     this->hasContainerWindow_ = hasContainer;
1749     this->density = density;
1750 
1751     // px = vp * density
1752     float containerTitleHeight_ = CONTAINER_TITLE_HEIGHT * density;
1753     float containerContentPadding_ = CONTENT_PADDING * density;
1754     float containerBorderWidth_ = CONTAINER_BORDER_WIDTH * density;
1755     float containerOutRadius_ = CONTAINER_OUTER_RADIUS * density;
1756     float containerInnerRadius_ = CONTAINER_INNER_RADIUS * density;
1757 
1758     this->outR = RoundFloor(containerOutRadius_);
1759     this->inR = RoundFloor(containerInnerRadius_);
1760     this->bp = RoundFloor(containerBorderWidth_ + containerContentPadding_);
1761     this->bt = RoundFloor(containerBorderWidth_ + containerTitleHeight_);
1762 }
1763 
1764 /*
1765     If a surfacenode with containerwindow is not focus window, then its opaque
1766 region is absRect minus four roundCorner corresponding small rectangles.
1767 This corners removed region can be assembled with two crossed rectangles.
1768 Furthermore, when the surfacenode is not focus window, the inner content roundrect's
1769 boundingbox rect can be set opaque.
1770 */
SetUnfocusedWindowOpaqueRegion(const RectI & absRect,const ScreenRotation screenRotation) const1771 Occlusion::Region RSSurfaceRenderNode::SetUnfocusedWindowOpaqueRegion(const RectI& absRect,
1772     const ScreenRotation screenRotation) const
1773 {
1774     Occlusion::Rect opaqueRect1{ absRect.left_ + containerConfig_.outR,
1775         absRect.top_,
1776         absRect.GetRight() - containerConfig_.outR,
1777         absRect.GetBottom()};
1778     Occlusion::Rect opaqueRect2{ absRect.left_,
1779         absRect.top_ + containerConfig_.outR,
1780         absRect.GetRight(),
1781         absRect.GetBottom() - containerConfig_.outR};
1782     Occlusion::Region r1{opaqueRect1};
1783     Occlusion::Region r2{opaqueRect2};
1784     Occlusion::Region opaqueRegion = r1.Or(r2);
1785 
1786     switch (screenRotation) {
1787         case ScreenRotation::ROTATION_0: {
1788             Occlusion::Rect opaqueRect3{ absRect.left_ + containerConfig_.bp,
1789                 absRect.top_ + containerConfig_.bt,
1790                 absRect.GetRight() - containerConfig_.bp,
1791                 absRect.GetBottom() - containerConfig_.bp};
1792             Occlusion::Region r3{opaqueRect3};
1793             opaqueRegion.OrSelf(r3);
1794             break;
1795         }
1796         case ScreenRotation::ROTATION_90: {
1797             Occlusion::Rect opaqueRect3{ absRect.left_ + containerConfig_.bt,
1798                 absRect.top_ + containerConfig_.bp,
1799                 absRect.GetRight() - containerConfig_.bp,
1800                 absRect.GetBottom() - containerConfig_.bp};
1801             Occlusion::Region r3{opaqueRect3};
1802             opaqueRegion.OrSelf(r3);
1803             break;
1804         }
1805         case ScreenRotation::ROTATION_180: {
1806             Occlusion::Rect opaqueRect3{ absRect.left_ + containerConfig_.bp,
1807                 absRect.top_ + containerConfig_.bp,
1808                 absRect.GetRight() - containerConfig_.bp,
1809                 absRect.GetBottom() - containerConfig_.bt};
1810             Occlusion::Region r3{opaqueRect3};
1811             opaqueRegion.OrSelf(r3);
1812             break;
1813         }
1814         case ScreenRotation::ROTATION_270: {
1815             Occlusion::Rect opaqueRect3{ absRect.left_ + containerConfig_.bp,
1816                 absRect.top_ + containerConfig_.bp,
1817                 absRect.GetRight() - containerConfig_.bt,
1818                 absRect.GetBottom() - containerConfig_.bp};
1819             Occlusion::Region r3{opaqueRect3};
1820             opaqueRegion.OrSelf(r3);
1821             break;
1822         }
1823         default: {
1824             Occlusion::Rect opaqueRect3{ absRect.left_ + containerConfig_.bp,
1825                 absRect.top_ + containerConfig_.bt,
1826                 absRect.GetRight() - containerConfig_.bp,
1827                 absRect.GetBottom() - containerConfig_.bp};
1828             Occlusion::Region r3{opaqueRect3};
1829             opaqueRegion.OrSelf(r3);
1830             break;
1831         }
1832     }
1833     return opaqueRegion;
1834 }
1835 
1836 /*
1837     If a surfacenode with containerwindow is a focused window, then its containerWindow region
1838 should be set transparent, including: title, content padding area, border, and content corners.
1839 Note this region is not centrosymmetric, hence it should be differentiated under different
1840 screen rotation state as top/left/bottom/right has changed when screen rotated.
1841 */
SetFocusedWindowOpaqueRegion(const RectI & absRect,const ScreenRotation screenRotation) const1842 Occlusion::Region RSSurfaceRenderNode::SetFocusedWindowOpaqueRegion(const RectI& absRect,
1843     const ScreenRotation screenRotation) const
1844 {
1845     Occlusion::Region opaqueRegion;
1846     switch (screenRotation) {
1847         case ScreenRotation::ROTATION_0: {
1848             Occlusion::Rect opaqueRect1{
1849                 absRect.left_ + containerConfig_.bp,
1850                 absRect.top_ + containerConfig_.bt + containerConfig_.inR,
1851                 absRect.GetRight() - containerConfig_.bp,
1852                 absRect.GetBottom() - containerConfig_.bp - containerConfig_.inR};
1853             Occlusion::Rect opaqueRect2{
1854                 absRect.left_ + containerConfig_.bp + containerConfig_.inR,
1855                 absRect.top_ + containerConfig_.bt,
1856                 absRect.GetRight() - containerConfig_.bp - containerConfig_.inR,
1857                 absRect.GetBottom() - containerConfig_.bp};
1858             Occlusion::Region r1{opaqueRect1};
1859             Occlusion::Region r2{opaqueRect2};
1860             opaqueRegion = r1.Or(r2);
1861             break;
1862         }
1863         case ScreenRotation::ROTATION_90: {
1864             Occlusion::Rect opaqueRect1{
1865                 absRect.left_ + containerConfig_.bt + containerConfig_.inR,
1866                 absRect.top_ + containerConfig_.bp,
1867                 absRect.GetRight() - containerConfig_.bp - containerConfig_.inR,
1868                 absRect.GetBottom() - containerConfig_.bp};
1869             Occlusion::Rect opaqueRect2{
1870                 absRect.left_ + containerConfig_.bt,
1871                 absRect.top_ + containerConfig_.bp + containerConfig_.inR,
1872                 absRect.GetRight() - containerConfig_.bp,
1873                 absRect.GetBottom() - containerConfig_.bp - containerConfig_.inR};
1874             Occlusion::Region r1{opaqueRect1};
1875             Occlusion::Region r2{opaqueRect2};
1876             opaqueRegion = r1.Or(r2);
1877             break;
1878         }
1879         case ScreenRotation::ROTATION_180: {
1880             Occlusion::Rect opaqueRect1{
1881                 absRect.left_ + containerConfig_.bp,
1882                 absRect.top_ + containerConfig_.bp + containerConfig_.inR,
1883                 absRect.GetRight() - containerConfig_.bp,
1884                 absRect.GetBottom() - containerConfig_.bt - containerConfig_.inR};
1885             Occlusion::Rect opaqueRect2{
1886                 absRect.left_ + containerConfig_.bp + containerConfig_.inR,
1887                 absRect.top_ + containerConfig_.bp,
1888                 absRect.GetRight() - containerConfig_.bp - containerConfig_.inR,
1889                 absRect.GetBottom() - containerConfig_.bt};
1890             Occlusion::Region r1{opaqueRect1};
1891             Occlusion::Region r2{opaqueRect2};
1892             opaqueRegion = r1.Or(r2);
1893             break;
1894         }
1895         case ScreenRotation::ROTATION_270: {
1896             Occlusion::Rect opaqueRect1{
1897                 absRect.left_ + containerConfig_.bp + containerConfig_.inR,
1898                 absRect.top_ + containerConfig_.bp,
1899                 absRect.GetRight() - containerConfig_.bt - containerConfig_.inR,
1900                 absRect.GetBottom() - containerConfig_.bp};
1901             Occlusion::Rect opaqueRect2{
1902                 absRect.left_ + containerConfig_.bp,
1903                 absRect.top_ + containerConfig_.bp + containerConfig_.inR,
1904                 absRect.GetRight() - containerConfig_.bt,
1905                 absRect.GetBottom() - containerConfig_.bp - containerConfig_.inR};
1906             Occlusion::Region r1{opaqueRect1};
1907             Occlusion::Region r2{opaqueRect2};
1908             opaqueRegion = r1.Or(r2);
1909             break;
1910         }
1911         default: {
1912             Occlusion::Rect opaqueRect1{
1913                 absRect.left_ + containerConfig_.bp,
1914                 absRect.top_ + containerConfig_.bt + containerConfig_.inR,
1915                 absRect.GetRight() - containerConfig_.bp,
1916                 absRect.GetBottom() - containerConfig_.bp - containerConfig_.inR};
1917             Occlusion::Rect opaqueRect2{
1918                 absRect.left_ + containerConfig_.bp + containerConfig_.inR,
1919                 absRect.top_ + containerConfig_.bt,
1920                 absRect.GetRight() - containerConfig_.bp - containerConfig_.inR,
1921                 absRect.GetBottom() - containerConfig_.bp};
1922             Occlusion::Region r1{opaqueRect1};
1923             Occlusion::Region r2{opaqueRect2};
1924             opaqueRegion = r1.Or(r2);
1925             break;
1926         }
1927     }
1928     return opaqueRegion;
1929 }
1930 
SetCornerRadiusOpaqueRegion(const RectI & absRect,const Vector4<int> & cornerRadius) const1931 Occlusion::Region RSSurfaceRenderNode::SetCornerRadiusOpaqueRegion(
1932     const RectI& absRect, const Vector4<int>& cornerRadius) const
1933 {
1934     Occlusion::Rect opaqueRect0{ absRect.GetLeft(), absRect.GetTop(),
1935         absRect.GetRight(), absRect.GetBottom()};
1936     Occlusion::Rect opaqueRect1{ absRect.GetLeft(), absRect.GetTop(),
1937         absRect.GetLeft() + cornerRadius.x_, absRect.GetTop() + cornerRadius.x_};
1938     Occlusion::Rect opaqueRect2{ absRect.GetRight() - cornerRadius.y_, absRect.GetTop(),
1939         absRect.GetRight(), absRect.GetTop() + cornerRadius.y_};
1940     Occlusion::Rect opaqueRect3{ absRect.GetRight() - cornerRadius.z_, absRect.GetBottom() - cornerRadius.z_,
1941         absRect.GetRight(), absRect.GetBottom()};
1942     Occlusion::Rect opaqueRect4{ absRect.GetLeft(), absRect.GetBottom() - cornerRadius.w_,
1943         absRect.GetLeft() + cornerRadius.w_, absRect.GetBottom()};
1944 
1945     Occlusion::Region r0{opaqueRect0};
1946     Occlusion::Region r1{opaqueRect1};
1947     Occlusion::Region r2{opaqueRect2};
1948     Occlusion::Region r3{opaqueRect3};
1949     Occlusion::Region r4{opaqueRect4};
1950     Occlusion::Region opaqueRegion = r0.Sub(r1).Sub(r2).Sub(r3).Sub(r4);
1951     return opaqueRegion;
1952 }
1953 
ResetSurfaceContainerRegion(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation)1954 void RSSurfaceRenderNode::ResetSurfaceContainerRegion(const RectI& screeninfo, const RectI& absRect,
1955     const ScreenRotation screenRotation)
1956 {
1957     if (!HasContainerWindow()) {
1958         containerRegion_ = Occlusion::Region{};
1959         return;
1960     }
1961     Occlusion::Region absRegion{Occlusion::Rect{absRect}};
1962     Occlusion::Rect innerRect;
1963     switch (screenRotation) {
1964         case ScreenRotation::ROTATION_0: {
1965             innerRect = Occlusion::Rect{ absRect.left_ + containerConfig_.bp,
1966                 absRect.top_ + containerConfig_.bt,
1967                 absRect.GetRight() - containerConfig_.bp,
1968                 absRect.GetBottom() - containerConfig_.bp};
1969             break;
1970         }
1971         case ScreenRotation::ROTATION_90: {
1972             innerRect = Occlusion::Rect{ absRect.left_ + containerConfig_.bt,
1973                 absRect.top_ + containerConfig_.bp,
1974                 absRect.GetRight() - containerConfig_.bp,
1975                 absRect.GetBottom() - containerConfig_.bp};
1976             break;
1977         }
1978         case ScreenRotation::ROTATION_180: {
1979             innerRect = Occlusion::Rect{ absRect.left_ + containerConfig_.bp,
1980                 absRect.top_ + containerConfig_.bp,
1981                 absRect.GetRight() - containerConfig_.bp,
1982                 absRect.GetBottom() - containerConfig_.bt};
1983             break;
1984         }
1985         case ScreenRotation::ROTATION_270: {
1986             innerRect = Occlusion::Rect{ absRect.left_ + containerConfig_.bp,
1987                 absRect.top_ + containerConfig_.bp,
1988                 absRect.GetRight() - containerConfig_.bt,
1989                 absRect.GetBottom() - containerConfig_.bp};
1990             break;
1991         }
1992         default: {
1993             innerRect = Occlusion::Rect{ absRect.left_ + containerConfig_.bp,
1994                 absRect.top_ + containerConfig_.bt,
1995                 absRect.GetRight() - containerConfig_.bp,
1996                 absRect.GetBottom() - containerConfig_.bp};
1997             break;
1998         }
1999     }
2000     Occlusion::Region innerRectRegion{innerRect};
2001     containerRegion_ = absRegion.Sub(innerRectRegion);
2002 }
2003 
OnSync()2004 void RSSurfaceRenderNode::OnSync()
2005 {
2006     RS_OPTIONAL_TRACE_NAME_FMT("RSSurfaceRenderNode::OnSync name[%s] dirty[%s]",
2007         GetName().c_str(), dirtyManager_->GetCurrentFrameDirtyRegion().ToString().c_str());
2008     if (!renderDrawable_) {
2009         return;
2010     }
2011     auto syncDirtyManager = renderDrawable_->GetSyncDirtyManager();
2012     dirtyManager_->OnSync(syncDirtyManager);
2013     if (IsMainWindowType() || IsLeashWindow() || GetLastFrameUifirstFlag() != MultiThreadCacheType::NONE) {
2014         auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2015         if (surfaceParams == nullptr) {
2016             RS_LOGE("RSSurfaceRenderNode::OnSync surfaceParams is null");
2017             return;
2018         }
2019         surfaceParams->SetNeedSync(true);
2020     }
2021 #ifndef ROSEN_CROSS_PLATFORM
2022     renderDrawable_->RegisterDeleteBufferListenerOnSync(GetRSSurfaceHandler()->GetConsumer());
2023 #endif
2024     RSRenderNode::OnSync();
2025 }
2026 
CheckIfOcclusionReusable(std::queue<NodeId> & surfaceNodesIds) const2027 bool RSSurfaceRenderNode::CheckIfOcclusionReusable(std::queue<NodeId>& surfaceNodesIds) const
2028 {
2029     if (surfaceNodesIds.empty()) {
2030         return true;
2031     }
2032     auto lastFrameSurfaceNodeId = surfaceNodesIds.front();
2033     surfaceNodesIds.pop();
2034     if (lastFrameSurfaceNodeId != GetId()) {
2035         return true;
2036     }
2037     return false;
2038 }
2039 
CheckIfOcclusionChanged() const2040 bool RSSurfaceRenderNode::CheckIfOcclusionChanged() const
2041 {
2042     return GetZorderChanged() || GetDstRectChanged() || IsOpaqueRegionChanged();
2043 }
2044 
CheckParticipateInOcclusion()2045 bool RSSurfaceRenderNode::CheckParticipateInOcclusion()
2046 {
2047     // planning: Need consider others situation
2048     isParentScaling_ = false;
2049     auto nodeParent = GetParent().lock();
2050     if (nodeParent && nodeParent->IsScale()) {
2051         isParentScaling_ = true;
2052         if (GetDstRectChanged() && !isOcclusionInSpecificScenes_) {
2053             return false;
2054         }
2055     }
2056     if (IsTransparent() || GetAnimateState() || IsRotating() || IsSubSurfaceNode()) {
2057         return false;
2058     }
2059     return true;
2060 }
2061 
RotateCorner(int rotationDegree,Vector4<int> & cornerRadius) const2062 void RSSurfaceRenderNode::RotateCorner(int rotationDegree, Vector4<int>& cornerRadius) const
2063 {
2064     auto begin = cornerRadius.GetData();
2065     auto end = begin + Vector4<int>::V4SIZE;
2066     switch (rotationDegree) {
2067         case RS_ROTATION_90: {
2068             constexpr int moveTime = 1;
2069             std::rotate(begin, end - moveTime, end);
2070             break;
2071         }
2072         case RS_ROTATION_180: {
2073             constexpr int moveTime = 2;
2074             std::rotate(begin, end - moveTime, end);
2075             break;
2076         }
2077         case RS_ROTATION_270: {
2078             constexpr int moveTime = 3;
2079             std::rotate(begin, end - moveTime, end);
2080             break;
2081         }
2082         default:
2083             break;
2084     }
2085 }
2086 
CheckAndUpdateOpaqueRegion(const RectI & screeninfo,const ScreenRotation screenRotation,const bool isFocusWindow)2087 void RSSurfaceRenderNode::CheckAndUpdateOpaqueRegion(const RectI& screeninfo, const ScreenRotation screenRotation,
2088     const bool isFocusWindow)
2089 {
2090     auto absRect = GetDstRect().IntersectRect(GetOldDirtyInSurface());
2091     Vector4f tmpCornerRadius;
2092     Vector4f::Max(GetWindowCornerRadius(), GetGlobalCornerRadius(), tmpCornerRadius);
2093     Vector4<int> cornerRadius(static_cast<int>(std::round(tmpCornerRadius.x_)),
2094                                 static_cast<int>(std::round(tmpCornerRadius.y_)),
2095                                 static_cast<int>(std::round(tmpCornerRadius.z_)),
2096                                 static_cast<int>(std::round(tmpCornerRadius.w_)));
2097     auto boundsGeometry = GetRenderProperties().GetBoundsGeometry();
2098     if (boundsGeometry) {
2099         const auto& absMatrix = boundsGeometry->GetAbsMatrix();
2100         auto rotationDegree = static_cast<int>(-round(atan2(absMatrix.Get(Drawing::Matrix::SKEW_X),
2101             absMatrix.Get(Drawing::Matrix::SCALE_X)) * (RS_ROTATION_180 / PI)));
2102         if (rotationDegree < 0) {
2103             rotationDegree += RS_ROTATION_360;
2104         }
2105         RotateCorner(rotationDegree, cornerRadius);
2106     }
2107 
2108     bool ret = opaqueRegionBaseInfo_.screenRect_ == screeninfo &&
2109         opaqueRegionBaseInfo_.absRect_ == absRect &&
2110         opaqueRegionBaseInfo_.oldDirty_ == GetOldDirty() &&
2111         opaqueRegionBaseInfo_.screenRotation_ == screenRotation &&
2112         opaqueRegionBaseInfo_.isFocusWindow_ == isFocusWindow &&
2113         opaqueRegionBaseInfo_.cornerRadius_ == cornerRadius &&
2114         opaqueRegionBaseInfo_.isTransparent_ == IsTransparent() &&
2115         opaqueRegionBaseInfo_.hasContainerWindow_ == HasContainerWindow();
2116     if (!ret) {
2117         if (absRect.IsEmpty()) {
2118             RS_LOGW("%{public}s absRect is empty, dst rect: %{public}s, old dirty in surface: %{public}s",
2119                 GetName().c_str(), GetDstRect().ToString().c_str(), GetOldDirtyInSurface().ToString().c_str());
2120             RS_TRACE_NAME_FMT("%s absRect is empty, dst rect: %s, old dirty in surface: %s",
2121                 GetName().c_str(), GetDstRect().ToString().c_str(), GetOldDirtyInSurface().ToString().c_str());
2122         }
2123         ResetSurfaceOpaqueRegion(screeninfo, absRect, screenRotation, isFocusWindow, cornerRadius);
2124         SetOpaqueRegionBaseInfo(screeninfo, absRect, screenRotation, isFocusWindow, cornerRadius);
2125     }
2126 }
2127 
CheckOpaqueRegionBaseInfo(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow,const Vector4<int> & cornerRadius)2128 bool RSSurfaceRenderNode::CheckOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect,
2129     const ScreenRotation screenRotation, const bool isFocusWindow, const Vector4<int>& cornerRadius)
2130 {
2131     return opaqueRegionBaseInfo_.screenRect_ == screeninfo &&
2132         opaqueRegionBaseInfo_.absRect_ == absRect &&
2133         opaqueRegionBaseInfo_.screenRotation_ == screenRotation &&
2134         opaqueRegionBaseInfo_.isFocusWindow_ == isFocusWindow &&
2135         opaqueRegionBaseInfo_.cornerRadius_ == cornerRadius &&
2136         opaqueRegionBaseInfo_.isTransparent_ == IsTransparent() &&
2137         opaqueRegionBaseInfo_.hasContainerWindow_ == HasContainerWindow();
2138 }
2139 
SetOpaqueRegionBaseInfo(const RectI & screeninfo,const RectI & absRect,const ScreenRotation screenRotation,const bool isFocusWindow,const Vector4<int> & cornerRadius)2140 void RSSurfaceRenderNode::SetOpaqueRegionBaseInfo(const RectI& screeninfo, const RectI& absRect,
2141     const ScreenRotation screenRotation, const bool isFocusWindow, const Vector4<int>& cornerRadius)
2142 {
2143     opaqueRegionBaseInfo_.screenRect_ = screeninfo;
2144     opaqueRegionBaseInfo_.absRect_ = absRect;
2145     opaqueRegionBaseInfo_.oldDirty_ = GetOldDirty();
2146     opaqueRegionBaseInfo_.screenRotation_ = screenRotation;
2147     opaqueRegionBaseInfo_.isFocusWindow_ = isFocusWindow;
2148     opaqueRegionBaseInfo_.cornerRadius_ = cornerRadius;
2149     opaqueRegionBaseInfo_.isTransparent_ = IsTransparent();
2150     opaqueRegionBaseInfo_.hasContainerWindow_ = HasContainerWindow();
2151 }
2152 
2153 // [planning] Remove this after skia is upgraded, the clipRegion is supported
ResetChildrenFilterRects()2154 void RSSurfaceRenderNode::ResetChildrenFilterRects()
2155 {
2156     childrenFilterNodes_.clear();
2157     childrenFilterRects_.clear();
2158     childrenFilterRectsCacheValid_.clear();
2159 }
2160 
UpdateChildrenFilterRects(std::shared_ptr<RSRenderNode> filternode,const RectI & rect,bool cacheValid)2161 void RSSurfaceRenderNode::UpdateChildrenFilterRects(std::shared_ptr<RSRenderNode> filternode,
2162     const RectI& rect, bool cacheValid)
2163 {
2164     if (!rect.IsEmpty()) {
2165         childrenFilterNodes_.emplace_back(filternode);
2166         childrenFilterRects_.emplace_back(rect);
2167         childrenFilterRectsCacheValid_.emplace_back(cacheValid);
2168     }
2169 }
2170 
GetChildrenNeedFilterRects() const2171 const std::vector<RectI>& RSSurfaceRenderNode::GetChildrenNeedFilterRects() const
2172 {
2173     return childrenFilterRects_;
2174 }
2175 
GetChildrenNeedFilterRectsCacheValid() const2176 const std::vector<bool>& RSSurfaceRenderNode::GetChildrenNeedFilterRectsCacheValid() const
2177 {
2178     return childrenFilterRectsCacheValid_;
2179 }
2180 
GetChildrenFilterNodes() const2181 const std::vector<std::shared_ptr<RSRenderNode>>& RSSurfaceRenderNode::GetChildrenFilterNodes() const
2182 {
2183     return childrenFilterNodes_;
2184 }
2185 
GetChildrenNeedFilterRectsWithoutCacheValid()2186 std::vector<RectI> RSSurfaceRenderNode::GetChildrenNeedFilterRectsWithoutCacheValid()
2187 {
2188     std::vector<RectI> childrenFilterRectsWithoutCacheValid;
2189     auto maxSize = std::min(childrenFilterRects_.size(), childrenFilterRectsCacheValid_.size());
2190     for (size_t i = 0; i < maxSize; i++) {
2191         if (!childrenFilterRectsCacheValid_[i]) {
2192             childrenFilterRectsWithoutCacheValid.emplace_back(childrenFilterRects_[i]);
2193         }
2194     }
2195     return childrenFilterRectsWithoutCacheValid;
2196 }
2197 
2198 // manage abilities' nodeid info
UpdateAbilityNodeIds(NodeId id,bool isAdded)2199 void RSSurfaceRenderNode::UpdateAbilityNodeIds(NodeId id, bool isAdded)
2200 {
2201     if (isAdded) {
2202         abilityNodeIds_.emplace(id);
2203     } else {
2204         abilityNodeIds_.erase(id);
2205     }
2206 }
2207 
AddAbilityComponentNodeIds(const std::unordered_set<NodeId> & nodeIds)2208 void RSSurfaceRenderNode::AddAbilityComponentNodeIds(const std::unordered_set<NodeId>& nodeIds)
2209 {
2210     abilityNodeIds_.insert(nodeIds.begin(), nodeIds.end());
2211 }
2212 
ResetAbilityNodeIds()2213 void RSSurfaceRenderNode::ResetAbilityNodeIds()
2214 {
2215     abilityNodeIds_.clear();
2216 }
2217 
UpdateSurfaceCacheContentStatic()2218 void RSSurfaceRenderNode::UpdateSurfaceCacheContentStatic()
2219 {
2220     dirtyContentNodeNum_ = 0;
2221     dirtyGeoNodeNum_ = 0;
2222     dirtynodeNum_ = 0;
2223     surfaceCacheContentStatic_ = IsOnlyBasicGeoTransform();
2224 }
2225 
UpdateSurfaceCacheContentStatic(const std::unordered_map<NodeId,std::weak_ptr<RSRenderNode>> & activeNodeIds)2226 void RSSurfaceRenderNode::UpdateSurfaceCacheContentStatic(
2227     const std::unordered_map<NodeId, std::weak_ptr<RSRenderNode>>& activeNodeIds)
2228 {
2229     dirtyContentNodeNum_ = 0;
2230     dirtyGeoNodeNum_ = 0;
2231     dirtynodeNum_ = activeNodeIds.size();
2232     surfaceCacheContentStatic_ = IsOnlyBasicGeoTransform() || GetForceUpdateByUifirst();
2233     if (dirtynodeNum_ == 0) {
2234         RS_LOGD("Clear surface %{public}" PRIu64 " dirtynodes surfaceCacheContentStatic_:%{public}d",
2235             GetId(), surfaceCacheContentStatic_);
2236         return;
2237     }
2238     for (auto [id, subNode] : activeNodeIds) {
2239         auto node = subNode.lock();
2240         if (node == nullptr || (id == GetId() && surfaceCacheContentStatic_)) {
2241             continue;
2242         }
2243         // classify active nodes except instance surface itself
2244         if (node->IsContentDirty() && !node->IsNewOnTree() && !node->GetRenderProperties().IsGeoDirty()) {
2245             dirtyContentNodeNum_++;
2246         } else {
2247             dirtyGeoNodeNum_++;
2248         }
2249     }
2250     RS_OPTIONAL_TRACE_NAME_FMT("UpdateSurfaceCacheContentStatic [%s-%lu] contentStatic: %d, dirtyContentNode: %d, "
2251         "dirtyGeoNode: %d", GetName().c_str(), GetId(),
2252         surfaceCacheContentStatic_, dirtyContentNodeNum_, dirtyGeoNodeNum_);
2253     // if mainwindow node only basicGeoTransform and no subnode dirty, it is marked as CacheContentStatic_
2254     surfaceCacheContentStatic_ = surfaceCacheContentStatic_ && dirtyContentNodeNum_ == 0 && dirtyGeoNodeNum_ == 0;
2255 }
2256 
GetAbilityNodeIds() const2257 const std::unordered_set<NodeId>& RSSurfaceRenderNode::GetAbilityNodeIds() const
2258 {
2259     return abilityNodeIds_;
2260 }
2261 
ResetChildHardwareEnabledNodes()2262 void RSSurfaceRenderNode::ResetChildHardwareEnabledNodes()
2263 {
2264     childHardwareEnabledNodes_.clear();
2265 }
2266 
AddChildHardwareEnabledNode(std::weak_ptr<RSSurfaceRenderNode> childNode)2267 void RSSurfaceRenderNode::AddChildHardwareEnabledNode(std::weak_ptr<RSSurfaceRenderNode> childNode)
2268 {
2269     childHardwareEnabledNodes_.erase(std::remove_if(childHardwareEnabledNodes_.begin(),
2270         childHardwareEnabledNodes_.end(),
2271         [&childNode](const auto& iter) {
2272             auto node = iter.lock();
2273             auto childNodePtr = childNode.lock();
2274             return node && childNodePtr && node == childNodePtr;
2275         }), childHardwareEnabledNodes_.end());
2276     childHardwareEnabledNodes_.emplace_back(childNode);
2277 }
2278 
UpdateChildHardwareEnabledNode(NodeId id,bool isOnTree)2279 void RSSurfaceRenderNode::UpdateChildHardwareEnabledNode(NodeId id, bool isOnTree)
2280 {
2281     if (isOnTree) {
2282         needCollectHwcNode_ = true;
2283     } else {
2284         childHardwareEnabledNodes_.erase(std::remove_if(childHardwareEnabledNodes_.begin(),
2285             childHardwareEnabledNodes_.end(),
2286             [&id](std::weak_ptr<RSSurfaceRenderNode> item) {
2287                 std::shared_ptr<RSSurfaceRenderNode> hwcNodePtr = item.lock();
2288                 if (!hwcNodePtr) {
2289                     return false;
2290                 }
2291                 return hwcNodePtr->GetId() == id;
2292             }), childHardwareEnabledNodes_.end());
2293     }
2294 }
2295 
GetChildHardwareEnabledNodes() const2296 const std::vector<std::weak_ptr<RSSurfaceRenderNode>>& RSSurfaceRenderNode::GetChildHardwareEnabledNodes() const
2297 {
2298     return childHardwareEnabledNodes_;
2299 }
2300 
SetHwcChildrenDisabledStateByUifirst()2301 void RSSurfaceRenderNode::SetHwcChildrenDisabledStateByUifirst()
2302 {
2303     if (IsAppWindow()) {
2304         auto hwcNodes = GetChildHardwareEnabledNodes();
2305         if (hwcNodes.empty()) {
2306             return;
2307         }
2308         for (auto hwcNode : hwcNodes) {
2309             auto hwcNodePtr = hwcNode.lock();
2310             if (!hwcNodePtr || hwcNodePtr->IsHardwareForcedDisabled()) {
2311                 continue;
2312             }
2313             hwcNodePtr->SetHardwareForcedDisabledState(true);
2314         }
2315     } else if (IsLeashWindow()) {
2316         for (auto& child : *GetChildren()) {
2317             auto surfaceNode = child->ReinterpretCastTo<RSSurfaceRenderNode>();
2318             if (surfaceNode == nullptr) {
2319                 continue;
2320             }
2321             surfaceNode->SetHwcChildrenDisabledStateByUifirst();
2322         }
2323     }
2324 }
2325 
SetLocalZOrder(float localZOrder)2326 void RSSurfaceRenderNode::SetLocalZOrder(float localZOrder)
2327 {
2328     localZOrder_ = localZOrder;
2329 }
2330 
GetLocalZOrder() const2331 float RSSurfaceRenderNode::GetLocalZOrder() const
2332 {
2333     return localZOrder_;
2334 }
2335 
OnApplyModifiers()2336 void RSSurfaceRenderNode::OnApplyModifiers()
2337 {
2338     auto& properties = GetMutableRenderProperties();
2339     auto& geoPtr = (properties.GetBoundsGeometry());
2340 
2341     // Multiply context alpha into alpha
2342     properties.SetAlpha(properties.GetAlpha() * contextAlpha_);
2343 
2344     // Apply the context matrix into the bounds geometry
2345     geoPtr->SetContextMatrix(contextMatrix_);
2346     if (!ShouldPaint()) {
2347         UpdateFilterCacheStatusWithVisible(false);
2348     }
2349 }
2350 
SetTotalMatrix(const Drawing::Matrix & totalMatrix)2351 void RSSurfaceRenderNode::SetTotalMatrix(const Drawing::Matrix& totalMatrix)
2352 {
2353     totalMatrix_ = totalMatrix;
2354     stagingRenderParams_->SetTotalMatrix(totalMatrix);
2355 }
2356 
GetContextClipRegion() const2357 std::optional<Drawing::Rect> RSSurfaceRenderNode::GetContextClipRegion() const
2358 {
2359     return contextClipRect_;
2360 }
2361 
LeashWindowRelatedAppWindowOccluded(std::vector<std::shared_ptr<RSSurfaceRenderNode>> & appNodes)2362 bool RSSurfaceRenderNode::LeashWindowRelatedAppWindowOccluded(
2363     std::vector<std::shared_ptr<RSSurfaceRenderNode>>& appNodes)
2364 {
2365     if (!IsLeashWindow()) {
2366         return false;
2367     }
2368     for (auto& childNode : *GetChildren()) {
2369         const auto& childNodeSurface = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(childNode);
2370         if (childNodeSurface && childNodeSurface->GetVisibleRegion().IsEmpty()) {
2371             appNodes.emplace_back(childNodeSurface);
2372         } else {
2373             return false;
2374         }
2375     }
2376     return true;
2377 }
2378 
GetLeashWindowNestedSurfaces()2379 std::vector<std::shared_ptr<RSSurfaceRenderNode>> RSSurfaceRenderNode::GetLeashWindowNestedSurfaces()
2380 {
2381     std::vector<std::shared_ptr<RSSurfaceRenderNode>> res;
2382     if (!IsLeashWindow()) {
2383         return res;
2384     }
2385     for (auto& childNode : *GetSortedChildren()) {
2386         if (auto childNodeSurface = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(childNode)) {
2387                 res.emplace_back(childNodeSurface);
2388         }
2389     }
2390     return res;
2391 }
2392 
IsHistoryOccludedDirtyRegionNeedSubmit()2393 bool RSSurfaceRenderNode::IsHistoryOccludedDirtyRegionNeedSubmit()
2394 {
2395     return (hasUnSubmittedOccludedDirtyRegion_ &&
2396         !historyUnSubmittedOccludedDirtyRegion_.IsEmpty() &&
2397         !visibleRegion_.IsEmpty() &&
2398         visibleRegion_.IsIntersectWith(historyUnSubmittedOccludedDirtyRegion_));
2399 }
2400 
ClearHistoryUnSubmittedDirtyInfo()2401 void RSSurfaceRenderNode::ClearHistoryUnSubmittedDirtyInfo()
2402 {
2403     hasUnSubmittedOccludedDirtyRegion_ = false;
2404     historyUnSubmittedOccludedDirtyRegion_.Clear();
2405 }
2406 
UpdateHistoryUnsubmittedDirtyInfo()2407 void RSSurfaceRenderNode::UpdateHistoryUnsubmittedDirtyInfo()
2408 {
2409     hasUnSubmittedOccludedDirtyRegion_ = true;
2410     historyUnSubmittedOccludedDirtyRegion_ = dirtyManager_->GetCurrentFrameDirtyRegion().JoinRect(
2411         historyUnSubmittedOccludedDirtyRegion_);
2412 }
2413 
IsUIFirstSelfDrawCheck()2414 bool RSSurfaceRenderNode::IsUIFirstSelfDrawCheck()
2415 {
2416     if (IsAppWindow()) {
2417         auto hardwareEnabledNodes = GetChildHardwareEnabledNodes();
2418         for (auto& hardwareEnabledNode : hardwareEnabledNodes) {
2419             auto hardwareEnabledNodePtr = hardwareEnabledNode.lock();
2420             if (hardwareEnabledNodePtr && hardwareEnabledNodePtr->surfaceHandler_->IsCurrentFrameBufferConsumed()) {
2421                 return false;
2422             }
2423         }
2424     }
2425     if (IsMainWindowType()) {
2426         return true;
2427     } else if (IsLeashWindow()) {
2428         auto nestedSurfaceNodes = GetLeashWindowNestedSurfaces();
2429         // leashwindow subthread cache considered static if and only if all nested surfacenode static
2430         // (include appwindow and starting window)
2431         for (auto& nestedSurface: nestedSurfaceNodes) {
2432             if (nestedSurface && !nestedSurface->IsUIFirstSelfDrawCheck()) {
2433                 return false;
2434             }
2435         }
2436         return true;
2437     } else if (IsSelfDrawingType()) {
2438         return !surfaceHandler_->IsCurrentFrameBufferConsumed();
2439     } else {
2440         return false;
2441     }
2442 }
2443 
IsCurFrameStatic(DeviceType deviceType)2444 bool RSSurfaceRenderNode::IsCurFrameStatic(DeviceType deviceType)
2445 {
2446     bool isDirty = deviceType == DeviceType::PC ? !surfaceCacheContentStatic_ :
2447         !dirtyManager_->GetCurrentFrameDirtyRegion().IsEmpty();
2448     if (isDirty) {
2449         return false;
2450     }
2451     if (IsMainWindowType()) {
2452         return true;
2453     } else if (IsLeashWindow()) {
2454         auto nestedSurfaceNodes = GetLeashWindowNestedSurfaces();
2455         // leashwindow children changed or has other type node except surfacenode
2456         if (deviceType == DeviceType::PC && lastFrameChildrenCnt_ != GetChildren()->size()) {
2457             return false;
2458         }
2459         for (auto& nestedSurface: nestedSurfaceNodes) {
2460             if (nestedSurface && !nestedSurface->IsCurFrameStatic(deviceType)) {
2461                 return false;
2462             }
2463         }
2464         return true;
2465     } else {
2466         return false;
2467     }
2468 }
2469 
IsVisibleDirtyEmpty(DeviceType deviceType)2470 bool RSSurfaceRenderNode::IsVisibleDirtyEmpty(DeviceType deviceType)
2471 {
2472     bool isStaticUnderVisibleRegion = false;
2473     if (!dirtyManager_->GetCurrentFrameDirtyRegion().IsEmpty()) {
2474         if (deviceType != DeviceType::PC) {
2475             return false;
2476         }
2477         // Visible dirty region optimization takes effecct only in PC or TABLET scenarios
2478         Occlusion::Rect currentFrameDirty(dirtyManager_->GetCurrentFrameDirtyRegion());
2479         if (!visibleRegion_.IsEmpty() && visibleRegion_.IsIntersectWith(currentFrameDirty)) {
2480             ClearHistoryUnSubmittedDirtyInfo();
2481             return false;
2482         }
2483         isStaticUnderVisibleRegion = true;
2484     }
2485     if (IsMainWindowType()) {
2486         if (deviceType == DeviceType::PC) {
2487             if (IsHistoryOccludedDirtyRegionNeedSubmit()) {
2488                 ClearHistoryUnSubmittedDirtyInfo();
2489                 return false;
2490             }
2491             if (isStaticUnderVisibleRegion) {
2492                 UpdateHistoryUnsubmittedDirtyInfo();
2493             }
2494         }
2495         return true;
2496     } else if (IsLeashWindow()) {
2497         auto nestedSurfaceNodes = GetLeashWindowNestedSurfaces();
2498         if (nestedSurfaceNodes.empty()) {
2499             return false;
2500         }
2501         for (auto& nestedSurface: nestedSurfaceNodes) {
2502             if (nestedSurface && !nestedSurface->IsVisibleDirtyEmpty(deviceType)) {
2503                 return false;
2504             }
2505         }
2506         return true;
2507     } else {
2508         return false;
2509     }
2510 }
2511 
IsUIFirstCacheReusable(DeviceType deviceType)2512 bool RSSurfaceRenderNode::IsUIFirstCacheReusable(DeviceType deviceType)
2513 {
2514     return GetCacheSurfaceProcessedStatus() == CacheProcessStatus::DONE &&
2515         HasCachedTexture() && IsUIFirstSelfDrawCheck() && IsCurFrameStatic(deviceType);
2516 }
2517 
UpdateCacheSurfaceDirtyManager(int bufferAge)2518 void RSSurfaceRenderNode::UpdateCacheSurfaceDirtyManager(int bufferAge)
2519 {
2520     if (!cacheSurfaceDirtyManager_ || !dirtyManager_) {
2521         return;
2522     }
2523     cacheSurfaceDirtyManager_->Clear();
2524     cacheSurfaceDirtyManager_->MergeDirtyRect(dirtyManager_->GetLatestDirtyRegion());
2525     cacheSurfaceDirtyManager_->SetBufferAge(bufferAge);
2526     cacheSurfaceDirtyManager_->UpdateDirty(false);
2527     // for leashwindow type, nested app surfacenode's cacheSurfaceDirtyManager update is required
2528     auto nestedSurfaceNodes = GetLeashWindowNestedSurfaces();
2529     for (auto& nestedSurface : nestedSurfaceNodes) {
2530         if (nestedSurface) {
2531             nestedSurface->UpdateCacheSurfaceDirtyManager(bufferAge);
2532         }
2533     }
2534 }
2535 
SetIsOnTheTree(bool onTree,NodeId instanceRootNodeId,NodeId firstLevelNodeId,NodeId cacheNodeId,NodeId uifirstRootNodeId)2536 void RSSurfaceRenderNode::SetIsOnTheTree(bool onTree, NodeId instanceRootNodeId, NodeId firstLevelNodeId,
2537     NodeId cacheNodeId, NodeId uifirstRootNodeId)
2538 {
2539     RS_LOGI("RSSurfaceRenderNode:SetIsOnTheTree, node:[name: %{public}s, id: %{public}" PRIu64 "], "
2540         "on tree: %{public}d, nodeType: %{public}d", GetName().c_str(), GetId(), onTree, static_cast<int>(nodeType_));
2541     RS_TRACE_NAME_FMT("RSSurfaceRenderNode:SetIsOnTheTree, node:[name: %s, id: %" PRIu64 "], "
2542         "on tree: %d, nodeType: %d", GetName().c_str(), GetId(), onTree, static_cast<int>(nodeType_));
2543     instanceRootNodeId = IsLeashOrMainWindow() ? GetId() : instanceRootNodeId;
2544     if (IsLeashWindow()) {
2545         firstLevelNodeId = GetId();
2546     } else if (IsAppWindow()) {
2547         firstLevelNodeId = GetId();
2548         auto parentNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(GetParent().lock());
2549         if (parentNode && parentNode->GetFirstLevelNodeId() != INVALID_NODEID) {
2550             firstLevelNodeId = parentNode->GetFirstLevelNodeId ();
2551         }
2552     }
2553     if (IsSecureUIExtension()) {
2554         if (onTree) {
2555             secUIExtensionNodes_.insert(std::pair<NodeId, NodeId>(GetId(), instanceRootNodeId));
2556         } else {
2557             secUIExtensionNodes_.erase(GetId());
2558         }
2559         if (auto parent = GetParent().lock()) {
2560             parent->SetChildrenHasUIExtension(onTree);
2561         }
2562     }
2563     // if node is marked as cacheRoot, update subtree status when update surface
2564     // in case prepare stage upper cacheRoot cannot specify dirty subnode
2565     RSBaseRenderNode::SetIsOnTheTree(onTree, instanceRootNodeId, firstLevelNodeId, cacheNodeId);
2566 }
2567 
GetCacheSurfaceProcessedStatus() const2568 CacheProcessStatus RSSurfaceRenderNode::GetCacheSurfaceProcessedStatus() const
2569 {
2570     return cacheProcessStatus_.load();
2571 }
2572 
SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus)2573 void RSSurfaceRenderNode::SetCacheSurfaceProcessedStatus(CacheProcessStatus cacheProcessStatus)
2574 {
2575     cacheProcessStatus_.store(cacheProcessStatus);
2576 }
2577 
HasOnlyOneRootNode() const2578 bool RSSurfaceRenderNode::HasOnlyOneRootNode() const
2579 {
2580     if (GetChildrenCount() != 1) {
2581         return false;
2582     }
2583 
2584     const auto child = GetFirstChild();
2585     if (!child || child->GetType() != RSRenderNodeType::ROOT_NODE || child->GetChildrenCount() > 0) {
2586         return false;
2587     }
2588 
2589     return true;
2590 }
2591 
GetNodeIsSingleFrameComposer() const2592 bool RSSurfaceRenderNode::GetNodeIsSingleFrameComposer() const
2593 {
2594     bool flag = false;
2595     if (RSSystemProperties::GetSingleFrameComposerCanvasNodeEnabled()) {
2596         auto idx = GetName().find("hwstylusfeature");
2597         if (idx != std::string::npos) {
2598             flag = true;
2599         }
2600     }
2601     return isNodeSingleFrameComposer_ || flag;
2602 }
2603 
QuerySubAssignable(bool isRotation)2604 bool RSSurfaceRenderNode::QuerySubAssignable(bool isRotation)
2605 {
2606     if (!IsFirstLevelNode()) {
2607         return false;
2608     }
2609     hasTransparentSurface_ = false;
2610     if (IsLeashWindow()) {
2611         for (auto &child : *GetSortedChildren()) {
2612             auto childSurfaceNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(child);
2613             if (childSurfaceNode && childSurfaceNode->IsTransparent()) {
2614                 hasTransparentSurface_ = true;
2615                 break;
2616             }
2617         }
2618     } else {
2619         hasTransparentSurface_ = IsTransparent();
2620     }
2621     RS_TRACE_NAME_FMT("SubThreadAssignable node[%lld] hasTransparent: %d, childHasVisibleFilter: %d, hasFilter: %d, "
2622         "isRotation: %d", GetId(), hasTransparentSurface_, ChildHasVisibleFilter(), HasFilter(), isRotation);
2623     return !(hasTransparentSurface_ && ChildHasVisibleFilter()) && !HasFilter() && !isRotation;
2624 }
2625 
GetHasTransparentSurface() const2626 bool RSSurfaceRenderNode::GetHasTransparentSurface() const
2627 {
2628     return hasTransparentSurface_;
2629 }
2630 
GetHasSharedTransitionNode() const2631 bool RSSurfaceRenderNode::GetHasSharedTransitionNode() const
2632 {
2633     return hasSharedTransitionNode_;
2634 }
2635 
SetHasSharedTransitionNode(bool hasSharedTransitionNode)2636 void RSSurfaceRenderNode::SetHasSharedTransitionNode(bool hasSharedTransitionNode)
2637 {
2638     hasSharedTransitionNode_ = hasSharedTransitionNode;
2639 }
2640 
GetGravityTranslate(float imgWidth,float imgHeight)2641 Vector2f RSSurfaceRenderNode::GetGravityTranslate(float imgWidth, float imgHeight)
2642 {
2643     Gravity gravity = GetRenderProperties().GetFrameGravity();
2644     if (IsLeashWindow()) {
2645         for (auto child : *GetSortedChildren()) {
2646             auto childSurfaceNode = child ? child->ReinterpretCastTo<RSSurfaceRenderNode>() : nullptr;
2647             if (childSurfaceNode) {
2648                 gravity = childSurfaceNode->GetRenderProperties().GetFrameGravity();
2649                 break;
2650             }
2651         }
2652     }
2653 
2654     float boundsWidth = GetRenderProperties().GetBoundsWidth();
2655     float boundsHeight = GetRenderProperties().GetBoundsHeight();
2656     Drawing::Matrix gravityMatrix;
2657     RSPropertiesPainter::GetGravityMatrix(gravity, RectF {0.0f, 0.0f, boundsWidth, boundsHeight},
2658         imgWidth, imgHeight, gravityMatrix);
2659     return {gravityMatrix.Get(Drawing::Matrix::TRANS_X), gravityMatrix.Get(Drawing::Matrix::TRANS_Y)};
2660 }
2661 
UpdateUIFirstFrameGravity()2662 void RSSurfaceRenderNode::UpdateUIFirstFrameGravity()
2663 {
2664     Gravity gravity = GetRenderProperties().GetFrameGravity();
2665     if (IsLeashWindow()) {
2666         std::vector<Gravity> subGravity{};
2667         for (const auto& child : *GetSortedChildren()) {
2668             auto childSurfaceNode = child ? child->ReinterpretCastTo<RSSurfaceRenderNode>() : nullptr;
2669             if (childSurfaceNode) {
2670                 subGravity.push_back(childSurfaceNode->GetRenderProperties().GetFrameGravity());
2671             }
2672         }
2673         // planning: how to handle gravity while leashwindow has multiple subAppWindows is not clear yet
2674         if (subGravity.size() == 1) {
2675             gravity = subGravity.front();
2676         }
2677     }
2678     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2679     if (!stagingSurfaceParams) {
2680         RS_LOGE("RSSurfaceRenderNode::UpdateUIFirstFrameGravity staingSurfaceParams is null");
2681         return;
2682     }
2683     stagingSurfaceParams->SetUIFirstFrameGravity(gravity);
2684     AddToPendingSyncList();
2685 }
2686 
SetOcclusionVisible(bool visible)2687 void RSSurfaceRenderNode::SetOcclusionVisible(bool visible)
2688 {
2689     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2690     if (stagingSurfaceParams) {
2691         stagingSurfaceParams->SetOcclusionVisible(visible);
2692         AddToPendingSyncList();
2693     } else {
2694         RS_LOGE("RSSurfaceRenderNode::SetOcclusionVisible stagingSurfaceParams is null");
2695     }
2696 
2697     isOcclusionVisible_ = visible;
2698 }
2699 
UpdatePartialRenderParams()2700 void RSSurfaceRenderNode::UpdatePartialRenderParams()
2701 {
2702     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2703     if (surfaceParams == nullptr) {
2704         RS_LOGE("RSSurfaceRenderNode::UpdatePartialRenderParams surfaceParams is null");
2705         return;
2706     }
2707     if (IsMainWindowType()) {
2708         surfaceParams->SetVisibleRegionInVirtual(visibleRegionInVirtual_);
2709         surfaceParams->SetIsParentScaling(isParentScaling_);
2710     }
2711     surfaceParams->absDrawRect_ = GetAbsDrawRect();
2712     surfaceParams->SetOldDirtyInSurface(GetOldDirtyInSurface());
2713     surfaceParams->SetTransparentRegion(GetTransparentRegion());
2714     surfaceParams->SetOpaqueRegion(GetOpaqueRegion());
2715 }
2716 
UpdateExtendVisibleRegion(Occlusion::Region & region)2717 void RSSurfaceRenderNode::UpdateExtendVisibleRegion(Occlusion::Region& region)
2718 {
2719     extendVisibleRegion_.Reset();
2720     extendVisibleRegion_ = region.Or(visibleRegion_);
2721     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2722     if (surfaceParams == nullptr) {
2723         RS_LOGE("RSSurfaceRenderNode::UpdateExtendVisibleRegion surfaceParams is nullptr");
2724         return;
2725     }
2726     surfaceParams->SetVisibleRegion(extendVisibleRegion_);
2727 }
2728 
InitRenderParams()2729 void RSSurfaceRenderNode::InitRenderParams()
2730 {
2731     stagingRenderParams_ = std::make_unique<RSSurfaceRenderParams>(GetId());
2732     DrawableV2::RSRenderNodeDrawableAdapter::OnGenerate(shared_from_this());
2733     if (renderDrawable_ == nullptr) {
2734         RS_LOGE("RSSurfaceRenderNode::InitRenderParams failed");
2735         return;
2736     }
2737 }
2738 
UpdateRenderParams()2739 void RSSurfaceRenderNode::UpdateRenderParams()
2740 {
2741     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2742     if (surfaceParams == nullptr) {
2743         RS_LOGE("RSSurfaceRenderNode::UpdateRenderParams surfaceParams is null");
2744         return;
2745     }
2746     auto& properties = GetRenderProperties();
2747     surfaceParams->alpha_ = properties.GetAlpha();
2748     surfaceParams->isSpherizeValid_ = properties.IsSpherizeValid();
2749     surfaceParams->rsSurfaceNodeType_ = GetSurfaceNodeType();
2750     surfaceParams->backgroundColor_ = properties.GetBackgroundColor();
2751     surfaceParams->rrect_ = properties.GetRRect();
2752     surfaceParams->selfDrawingType_ = GetSelfDrawingNodeType();
2753     surfaceParams->needBilinearInterpolation_ = NeedBilinearInterpolation();
2754     surfaceParams->SetWindowInfo(IsMainWindowType(), IsLeashWindow(), IsAppWindow());
2755     surfaceParams->SetAncestorDisplayNode(ancestorDisplayNode_);
2756     surfaceParams->isSecurityLayer_ = isSecurityLayer_;
2757     surfaceParams->isSkipLayer_ = isSkipLayer_;
2758     surfaceParams->isProtectedLayer_ = isProtectedLayer_;
2759     surfaceParams->animateState_ = animateState_;
2760     surfaceParams->skipLayerIds_= skipLayerIds_;
2761     surfaceParams->securityLayerIds_= securityLayerIds_;
2762     surfaceParams->protectedLayerIds_= protectedLayerIds_;
2763     surfaceParams->privacyContentLayerIds_ = privacyContentLayerIds_;
2764     surfaceParams->name_= name_;
2765     surfaceParams->positionZ_ = properties.GetPositionZ();
2766     surfaceParams->SetVisibleRegion(visibleRegion_);
2767     surfaceParams->SetOldDirtyInSurface(GetOldDirtyInSurface());
2768     surfaceParams->dstRect_ = dstRect_;
2769     surfaceParams->overDrawBufferNodeCornerRadius_ = GetOverDrawBufferNodeCornerRadius();
2770     surfaceParams->isGpuOverDrawBufferOptimizeNode_ = isGpuOverDrawBufferOptimizeNode_;
2771     surfaceParams->SetSkipDraw(isSkipDraw_);
2772     surfaceParams->SetHidePrivacyContent(needHidePrivacyContent_);
2773     surfaceParams->visibleFilterChild_ = GetVisibleFilterChild();
2774     surfaceParams->isTransparent_ = IsTransparent();
2775     surfaceParams->leashPersistentId_ = leashPersistentId_;
2776     surfaceParams->SetNeedSync(true);
2777 
2778     RSRenderNode::UpdateRenderParams();
2779 }
2780 
SetNeedOffscreen(bool needOffscreen)2781 void RSSurfaceRenderNode::SetNeedOffscreen(bool needOffscreen)
2782 {
2783     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2784     if (stagingSurfaceParams) {
2785         stagingSurfaceParams->SetNeedOffscreen(needOffscreen);
2786         stagingSurfaceParams->SetFingerprint(GetFingerprint());
2787         AddToPendingSyncList();
2788     } else {
2789         RS_LOGE("RSSurfaceRenderNode::SetNeedOffscreen stagingSurfaceParams is null");
2790     }
2791 }
2792 
UpdateAncestorDisplayNodeInRenderParams()2793 void RSSurfaceRenderNode::UpdateAncestorDisplayNodeInRenderParams()
2794 {
2795     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2796     if (surfaceParams == nullptr) {
2797         RS_LOGE("RSSurfaceRenderNode::UpdateAncestorDisplayNodeInRenderParams surfaceParams is null");
2798         return;
2799     }
2800     surfaceParams->SetAncestorDisplayNode(ancestorDisplayNode_);
2801     surfaceParams->SetNeedSync(true);
2802 }
2803 
SetUifirstChildrenDirtyRectParam(RectI rect)2804 void RSSurfaceRenderNode::SetUifirstChildrenDirtyRectParam(RectI rect)
2805 {
2806     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2807     if (stagingSurfaceParams) {
2808         stagingSurfaceParams->SetUifirstChildrenDirtyRectParam(rect);
2809         AddToPendingSyncList();
2810     }
2811 }
2812 
SetLeashWindowVisibleRegionEmptyParam()2813 void RSSurfaceRenderNode::SetLeashWindowVisibleRegionEmptyParam()
2814 {
2815     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2816     if (!stagingSurfaceParams) {
2817         RS_LOGE("RSSurfaceRenderNode::SetLeashWindowVisibleRegionEmptyParam staingSurfaceParams is null");
2818         return;
2819     }
2820     stagingSurfaceParams->SetLeashWindowVisibleRegionEmptyParam(isLeashWindowVisibleRegionEmpty_);
2821 }
2822 
SetUifirstNodeEnableParam(MultiThreadCacheType b)2823 void RSSurfaceRenderNode::SetUifirstNodeEnableParam(MultiThreadCacheType b)
2824 {
2825     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2826     if (stagingSurfaceParams) {
2827         stagingSurfaceParams->SetUifirstNodeEnableParam(b);
2828         AddToPendingSyncList();
2829     }
2830 }
2831 
SetIsParentUifirstNodeEnableParam(bool b)2832 void RSSurfaceRenderNode::SetIsParentUifirstNodeEnableParam(bool b)
2833 {
2834     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2835     if (stagingSurfaceParams) {
2836         stagingSurfaceParams->SetIsParentUifirstNodeEnableParam(b);
2837         AddToPendingSyncList();
2838     }
2839 }
2840 
SetUifirstUseStarting(NodeId id)2841 void RSSurfaceRenderNode::SetUifirstUseStarting(NodeId id)
2842 {
2843     auto stagingSurfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2844     if (stagingSurfaceParams) {
2845         stagingSurfaceParams->SetUifirstUseStarting(id);
2846         AddToPendingSyncList();
2847     }
2848 }
2849 
SetCornerRadiusInfoForDRM(const std::vector<float> & drmCornerRadiusInfo)2850 void RSSurfaceRenderNode::SetCornerRadiusInfoForDRM(const std::vector<float>& drmCornerRadiusInfo)
2851 {
2852     if (drmCornerRadiusInfo_ != drmCornerRadiusInfo) {
2853         auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2854         if (surfaceParams) {
2855             surfaceParams->SetCornerRadiusInfoForDRM(drmCornerRadiusInfo);
2856             drmCornerRadiusInfo_ = drmCornerRadiusInfo;
2857         }
2858         AddToPendingSyncList();
2859     }
2860 }
2861 
SetSkipDraw(bool skip)2862 void RSSurfaceRenderNode::SetSkipDraw(bool skip)
2863 {
2864     isSkipDraw_ = skip;
2865     SetDirty();
2866 }
2867 
GetSkipDraw() const2868 bool RSSurfaceRenderNode::GetSkipDraw() const
2869 {
2870     return isSkipDraw_;
2871 }
2872 
GetSecUIExtensionNodes()2873 const std::unordered_map<NodeId, NodeId>& RSSurfaceRenderNode::GetSecUIExtensionNodes()
2874 {
2875     return secUIExtensionNodes_;
2876 }
2877 
SetSdrNit(int32_t sdrNit)2878 void RSSurfaceRenderNode::SetSdrNit(int32_t sdrNit)
2879 {
2880     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2881     if (surfaceParams) {
2882         surfaceParams->SetSdrNit(sdrNit);
2883     }
2884     AddToPendingSyncList();
2885 }
2886 
SetDisplayNit(int32_t displayNit)2887 void RSSurfaceRenderNode::SetDisplayNit(int32_t displayNit)
2888 {
2889     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2890     if (surfaceParams) {
2891         surfaceParams->SetDisplayNit(displayNit);
2892     }
2893     AddToPendingSyncList();
2894 }
2895 
SetBrightnessRatio(float brightnessRatio)2896 void RSSurfaceRenderNode::SetBrightnessRatio(float brightnessRatio)
2897 {
2898     auto surfaceParams = static_cast<RSSurfaceRenderParams*>(stagingRenderParams_.get());
2899     if (surfaceParams) {
2900         surfaceParams->SetBrightnessRatio(brightnessRatio);
2901     }
2902     AddToPendingSyncList();
2903 }
2904 
SetAbilityState(RSSurfaceNodeAbilityState abilityState)2905 void RSSurfaceRenderNode::SetAbilityState(RSSurfaceNodeAbilityState abilityState)
2906 {
2907     if (abilityState_ == abilityState) {
2908         ROSEN_LOGD("RSSurfaceRenderNode::SetAbilityState, surfaceNodeId:[%{public}" PRIu64 "], "
2909             "ability state same with before: %{public}s",
2910             GetId(), abilityState == RSSurfaceNodeAbilityState::FOREGROUND ? "foreground" : "background");
2911         return;
2912     }
2913 
2914     abilityState_ = abilityState;
2915     ROSEN_LOGI("RSSurfaceRenderNode::SetAbilityState, surfaceNodeId:[%{public}" PRIu64 "] ability state: %{public}s",
2916         GetId(), abilityState_ == RSSurfaceNodeAbilityState::FOREGROUND ? "foreground" : "background");
2917 }
2918 
GetAbilityState() const2919 RSSurfaceNodeAbilityState RSSurfaceRenderNode::GetAbilityState() const
2920 {
2921     return abilityState_;
2922 }
2923 } // namespace Rosen
2924 } // namespace OHOS
2925