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