1 /*
2 * Copyright (c) 2024 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 "params/rs_render_params.h"
17 #include "pipeline/rs_render_node.h"
18 #ifdef DDGR_ENABLE_FEATURE_OPINC_DFX
19 #include "string_utils.h"
20 #endif
21 #include "common/rs_optional_trace.h"
22
23 namespace OHOS {
24 namespace Rosen {
25
26 constexpr int64_t MIN_REUSECOUNT = 10;
27 constexpr int64_t MAX_REUSECOUNT = 60;
28 constexpr int32_t MAX_TRY_TIMES = 3;
29
30 // mark stable node
OpincSetInAppStateStart(bool & unchangeMarkInApp)31 void RSRenderNode::OpincSetInAppStateStart(bool& unchangeMarkInApp)
32 {
33 if (unchangeMarkInApp) {
34 return;
35 }
36 isUnchangeMarkInApp_ = true;
37 unchangeMarkInApp = true;
38 }
39
OpincSetInAppStateEnd(bool & unchangeMarkInApp)40 void RSRenderNode::OpincSetInAppStateEnd(bool& unchangeMarkInApp)
41 {
42 if (isUnchangeMarkInApp_) {
43 isUnchangeMarkInApp_ = false;
44 unchangeMarkInApp = false;
45 }
46 }
47
OpincQuickMarkStableNode(bool & unchangeMarkInApp,bool & unchangeMarkEnable,bool isAccessibilityChanged)48 void RSRenderNode::OpincQuickMarkStableNode(bool& unchangeMarkInApp, bool& unchangeMarkEnable,
49 bool isAccessibilityChanged)
50 {
51 if (!unchangeMarkInApp) {
52 return;
53 }
54 if (GetSuggestOpincNode() && !unchangeMarkEnable) {
55 isUnchangeMarkEnable_ = true;
56 unchangeMarkEnable = true;
57 }
58 if (!unchangeMarkEnable) {
59 return;
60 }
61 auto isSelfDirty = IsSubTreeDirty() || IsContentDirty() ||
62 nodeGroupType_ > RSRenderNode::NodeGroupType::NONE || (isOpincRootFlag_ && isAccessibilityChanged);
63 if (isSelfDirty) {
64 NodeCacheStateChange(NodeChangeType::SELF_DIRTY);
65 } else if (nodeCacheState_ != NodeCacheState::STATE_UNCHANGE) {
66 NodeCacheStateChange(NodeChangeType::KEEP_UNCHANGE);
67 }
68 }
69
OpincUpdateRootFlag(bool & unchangeMarkEnable)70 void RSRenderNode::OpincUpdateRootFlag(bool& unchangeMarkEnable)
71 {
72 if (unchangeMarkEnable) {
73 if (IsOpincUnchangeState()) {
74 isOpincRootFlag_ = true;
75 #ifdef RS_ENABLE_GPU
76 if (stagingRenderParams_) {
77 stagingRenderParams_->OpincUpdateRootFlag(true);
78 }
79 #endif
80 }
81 }
82 if (isUnchangeMarkEnable_) {
83 isUnchangeMarkEnable_ = false;
84 unchangeMarkEnable = false;
85 }
86 }
87
IsOpincUnchangeState()88 bool RSRenderNode::IsOpincUnchangeState()
89 {
90 return (nodeCacheState_ == NodeCacheState::STATE_UNCHANGE) && OpincGetNodeSupportFlag() && GetSuggestOpincNode();
91 }
92
QuickGetNodeDebugInfo()93 std::string RSRenderNode::QuickGetNodeDebugInfo()
94 {
95 std::string ret("");
96 #ifdef DDGR_ENABLE_FEATURE_OPINC_DFX
97 AppendFormat(ret, "%llx, IsSTD:%d s:%d uc:%d suggest:%d support:%d rootF:%d",
98 GetId(), IsSubTreeDirty(), nodeCacheState_, unchangeCount_, GetSuggestOpincNode(),
99 OpincGetNodeSupportFlag(), isOpincRootFlag_);
100 #endif
101 return ret;
102 }
103
104 // mark support node
OpincUpdateNodeSupportFlag(bool supportFlag)105 void RSRenderNode::OpincUpdateNodeSupportFlag(bool supportFlag)
106 {
107 isOpincNodeSupportFlag_ = isOpincNodeSupportFlag_ && supportFlag && (!IsMarkedRenderGroup());
108 }
109
IsMarkedRenderGroup()110 bool RSRenderNode::IsMarkedRenderGroup()
111 {
112 return (nodeGroupType_ > RSRenderNode::NodeGroupType::NONE) || isOpincRootFlag_;
113 }
114
OpincForcePrepareSubTree(bool autoCacheEnable)115 bool RSRenderNode::OpincForcePrepareSubTree(bool autoCacheEnable)
116 {
117 if (!autoCacheEnable) {
118 return false;
119 }
120 bool flag = (!(IsSubTreeDirty() || IsContentDirty())) && GetSuggestOpincNode() &&
121 OpincGetNodeSupportFlag() && !isOpincRootFlag_;
122 if (flag) {
123 SetParentSubTreeDirty();
124 }
125 return flag;
126 }
127
OpincGetRootFlag() const128 bool RSRenderNode::OpincGetRootFlag() const
129 {
130 return isOpincRootFlag_;
131 }
132
133 // arkui mark
MarkSuggestOpincNode(bool isOpincNode,bool isNeedCalculate)134 void RSRenderNode::MarkSuggestOpincNode(bool isOpincNode, bool isNeedCalculate)
135 {
136 RS_TRACE_NAME_FMT("mark opinc %llx, isopinc:%d. isCal:%d", GetId(), isOpincNode, isNeedCalculate);
137 isSuggestOpincNode_ = isOpincNode;
138 isNeedCalculate_ = isNeedCalculate;
139 SetDirty();
140 }
141
GetSuggestOpincNode() const142 bool RSRenderNode::GetSuggestOpincNode() const
143 {
144 return isSuggestOpincNode_;
145 }
146
NodeCacheStateChange(NodeChangeType type)147 void RSRenderNode::NodeCacheStateChange(NodeChangeType type)
148 {
149 #ifdef DDGR_ENABLE_FEATURE_OPINC_DFX
150 RS_TRACE_NAME_FMT("NodeCacheStateChange %llx, type:%d r%d unc:%d uncU:%d",
151 GetId(), type, nodeCacheState_, unchangeCount_, unchangeCountUpper_);
152 #endif
153 switch (type) {
154 case NodeChangeType::KEEP_UNCHANGE:
155 unchangeCount_++;
156 if (unchangeCount_ > unchangeCountUpper_) {
157 nodeCacheState_ = NodeCacheState::STATE_UNCHANGE;
158 }
159 #ifdef RS_ENABLE_GPU
160 if (stagingRenderParams_) {
161 stagingRenderParams_->OpincSetCacheChangeFlag(false, lastFrameSynced_);
162 }
163 #endif
164 break;
165 case NodeChangeType::SELF_DIRTY:
166 NodeCacheStateReset(NodeCacheState::STATE_CHANGE);
167 break;
168 }
169 }
170
SetCacheStateByRetrytime()171 void RSRenderNode::SetCacheStateByRetrytime()
172 {
173 tryCacheTimes_++;
174 if (tryCacheTimes_ < MAX_TRY_TIMES) {
175 unchangeCountUpper_ = unchangeCountUpper_ + MIN_REUSECOUNT;
176 return;
177 }
178 unchangeCountUpper_ = unchangeCountUpper_ + MAX_REUSECOUNT;
179 }
180
NodeCacheStateReset(NodeCacheState nodeCacheState)181 void RSRenderNode::NodeCacheStateReset(NodeCacheState nodeCacheState)
182 {
183 nodeCacheState_ = nodeCacheState;
184 unchangeCount_ = 0;
185 isUnchangeMarkInApp_ = false;
186 isUnchangeMarkEnable_ = false;
187 if (OpincGetRootFlag()) {
188 SetCacheStateByRetrytime();
189 }
190 #ifdef RS_ENABLE_GPU
191 if (stagingRenderParams_) {
192 stagingRenderParams_->OpincSetCacheChangeFlag(true, lastFrameSynced_);
193 stagingRenderParams_->OpincUpdateRootFlag(false);
194 }
195 #endif
196 isOpincRootFlag_ = false;
197 }
198 } // namespace Rosen
199 } // namespace OHOS
200