1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "feature/opinc/rs_opinc_manager.h"
17
18 #include "string_utils.h"
19
20 namespace OHOS {
21 namespace Rosen {
22
Instance()23 RSOpincManager& RSOpincManager::Instance()
24 {
25 static RSOpincManager instance;
26 return instance;
27 }
28
OpincGetNodeSupportFlag(RSRenderNode & node)29 bool RSOpincManager::OpincGetNodeSupportFlag(RSRenderNode& node)
30 {
31 auto nodeType = node.GetType();
32 auto supportFlag = false;
33 if (nodeType == RSRenderNodeType::CANVAS_NODE) {
34 supportFlag = OpincGetCanvasNodeSupportFlag(node);
35 } else if (nodeType == RSRenderNodeType::CANVAS_DRAWING_NODE) {
36 supportFlag = !node.GetOpincCache().IsSuggestOpincNode() && OpincGetCanvasNodeSupportFlag(node);
37 }
38
39 node.GetOpincCache().SetCurNodeTreeSupportFlag(supportFlag);
40 return supportFlag;
41 }
42
OpincGetCanvasNodeSupportFlag(RSRenderNode & node)43 bool RSOpincManager::OpincGetCanvasNodeSupportFlag(RSRenderNode& node)
44 {
45 const auto& property = node.GetRenderProperties();
46 if (node.GetSharedTransitionParam() ||
47 property.IsSpherizeValid() ||
48 property.IsAttractionValid() ||
49 property.NeedFilter() ||
50 property.GetUseEffect() ||
51 property.GetColorBlend().has_value() ||
52 node.ChildHasVisibleFilter() ||
53 node.ChildHasVisibleEffect()) {
54 return false;
55 }
56 return node.GetOpincCache().GetSubTreeSupportFlag();
57 }
58
IsOpincSubTreeDirty(RSRenderNode & node,bool opincEnable)59 bool RSOpincManager::IsOpincSubTreeDirty(RSRenderNode& node, bool opincEnable)
60 {
61 auto subTreeDirty = node.GetOpincCache().OpincForcePrepareSubTree(opincEnable,
62 node.IsSubTreeDirty() || node.IsContentDirty(), OpincGetNodeSupportFlag(node));
63 if (subTreeDirty) {
64 node.SetParentSubTreeDirty();
65 }
66 return subTreeDirty;
67 }
68
GetUnsupportReason(RSRenderNode & node)69 OpincUnsupportType RSOpincManager::GetUnsupportReason(RSRenderNode& node)
70 {
71 if (!node.GetOpincCache().GetSubTreeSupportFlag()) {
72 return OpincUnsupportType::CHILD_NOT_SUPPORT;
73 }
74 if (node.GetSharedTransitionParam()) {
75 return OpincUnsupportType::SHARED_TRANSITION;
76 }
77 const auto& property = node.GetRenderProperties();
78 if (property.IsSpherizeValid()) {
79 return OpincUnsupportType::SPHERIZE;
80 }
81 if (property.IsAttractionValid()) {
82 return OpincUnsupportType::ATTRACTION;
83 }
84 if (property.NeedFilter()) {
85 return OpincUnsupportType::HAS_FILTER;
86 }
87 if (property.GetUseEffect()) {
88 return OpincUnsupportType::USE_EFFECT;
89 }
90 if (property.GetColorBlend().has_value()) {
91 return OpincUnsupportType::COLOR_BLEND;
92 }
93 if (node.ChildHasVisibleFilter()) {
94 return OpincUnsupportType::CHILD_HAS_FILTER;
95 }
96 if (node.ChildHasVisibleEffect()) {
97 return OpincUnsupportType::CHILD_HAS_EFFECT;
98 }
99 return OpincUnsupportType::NONE;
100 }
101
QuickGetNodeDebugInfo(RSRenderNode & node)102 std::string RSOpincManager::QuickGetNodeDebugInfo(RSRenderNode& node)
103 {
104 std::string ret("");
105 auto& opincCache = node.GetOpincCache();
106 AppendFormat(ret, "%" PRIu64 ", subD:%d conD:%d s:%d uc:%d suggest:%d support:%d rootF:%d not_sup_reason:%d",
107 node.GetId(), node.IsSubTreeDirty(), node.IsContentDirty(), opincCache.GetNodeCacheState(),
108 opincCache.GetUnchangeCount(), opincCache.IsSuggestOpincNode(), opincCache.GetCurNodeTreeSupportFlag(),
109 opincCache.OpincGetRootFlag(), GetUnsupportReason(node));
110 return ret;
111 }
112 }
113 }