1 /*
2 * Copyright (c) 2021-2022 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 "command/rs_node_command.h"
17
18 #include "modifier_ng/rs_render_modifier_ng.h"
19 #include "pipeline/rs_surface_render_node.h"
20 #include "platform/common/rs_log.h"
21
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25 RSNodeCommandHelper::DumpNodeTreeProcessor gDumpNodeTreeProcessor = nullptr;
26 RSNodeCommandHelper::CommitDumpNodeTreeProcessor gCommitDumpNodeTreeProcessor = nullptr;
27 }
28
SetFreeze(RSContext & context,NodeId nodeId,bool isFreeze)29 void RSNodeCommandHelper::SetFreeze(RSContext& context, NodeId nodeId, bool isFreeze)
30 {
31 auto& nodeMap = context.GetNodeMap();
32 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
33 if (node) {
34 node->SetStaticCached(isFreeze);
35 }
36 }
37
SetNodeName(RSContext & context,NodeId nodeId,std::string & nodeName)38 void RSNodeCommandHelper::SetNodeName(RSContext& context, NodeId nodeId, std::string& nodeName)
39 {
40 auto& nodeMap = context.GetNodeMap();
41 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
42 if (node) {
43 node->SetNodeName(nodeName);
44 }
45 }
46
MarkNodeGroup(RSContext & context,NodeId nodeId,bool isNodeGroup,bool isForced,bool includeProperty)47 void RSNodeCommandHelper::MarkNodeGroup(RSContext& context, NodeId nodeId, bool isNodeGroup, bool isForced,
48 bool includeProperty)
49 {
50 auto& nodeMap = context.GetNodeMap();
51 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
52 node->MarkNodeGroup(isForced ? RSRenderNode::GROUPED_BY_USER : RSRenderNode::GROUPED_BY_UI, isNodeGroup,
53 includeProperty);
54 }
55 }
56
MarkRepaintBoundary(RSContext & context,NodeId nodeId,bool isRepaintBoundary)57 void RSNodeCommandHelper::MarkRepaintBoundary(RSContext& context, NodeId nodeId, bool isRepaintBoundary)
58 {
59 auto& nodeMap = context.GetNodeMap();
60 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
61 node->MarkRepaintBoundary(isRepaintBoundary);
62 }
63 }
64
MarkNodeSingleFrameComposer(RSContext & context,NodeId nodeId,bool isNodeSingleFrameComposer,pid_t pid)65 void RSNodeCommandHelper::MarkNodeSingleFrameComposer(RSContext& context,
66 NodeId nodeId, bool isNodeSingleFrameComposer, pid_t pid)
67 {
68 auto& nodeMap = context.GetNodeMap();
69 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
70 RSSingleFrameComposer::AddOrRemoveAppPidToMap(isNodeSingleFrameComposer, pid);
71 node->MarkNodeSingleFrameComposer(isNodeSingleFrameComposer, pid);
72 }
73 }
74
MarkSuggestOpincNode(RSContext & context,NodeId nodeId,bool isOpincNode,bool isNeedCalculate)75 void RSNodeCommandHelper::MarkSuggestOpincNode(RSContext& context, NodeId nodeId,
76 bool isOpincNode, bool isNeedCalculate)
77 {
78 auto& nodeMap = context.GetNodeMap();
79 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
80 node->MarkSuggestOpincNode(isOpincNode, isNeedCalculate);
81 }
82 }
83
MarkUifirstNode(RSContext & context,NodeId nodeId,bool isUifirstNode)84 void RSNodeCommandHelper::MarkUifirstNode(RSContext& context, NodeId nodeId, bool isUifirstNode)
85 {
86 auto& nodeMap = context.GetNodeMap();
87 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
88 node->MarkUifirstNode(isUifirstNode);
89 }
90 }
91
ForceUifirstNode(RSContext & context,NodeId nodeId,bool isForceFlag,bool isUifirstEnable)92 void RSNodeCommandHelper::ForceUifirstNode(RSContext& context, NodeId nodeId, bool isForceFlag,
93 bool isUifirstEnable)
94 {
95 auto& nodeMap = context.GetNodeMap();
96 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
97 node->MarkUifirstNode(isForceFlag, isUifirstEnable);
98 }
99 }
100
SetUIFirstSwitch(RSContext & context,NodeId nodeId,RSUIFirstSwitch uiFirstSwitch)101 void RSNodeCommandHelper::SetUIFirstSwitch(RSContext& context, NodeId nodeId, RSUIFirstSwitch uiFirstSwitch)
102 {
103 auto& nodeMap = context.GetNodeMap();
104 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
105 node->SetUIFirstSwitch(uiFirstSwitch);
106 }
107 }
108
SetDrawRegion(RSContext & context,NodeId nodeId,std::shared_ptr<RectF> rect)109 void RSNodeCommandHelper::SetDrawRegion(RSContext& context, NodeId nodeId, std::shared_ptr<RectF> rect)
110 {
111 auto& nodeMap = context.GetNodeMap();
112 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
113 if (node) {
114 node->SetDrawRegion(rect);
115 }
116 }
117
SetOutOfParent(RSContext & context,NodeId nodeId,OutOfParentType outOfParent)118 void RSNodeCommandHelper::SetOutOfParent(RSContext& context, NodeId nodeId, OutOfParentType outOfParent)
119 {
120 auto& nodeMap = context.GetNodeMap();
121 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
122 if (node) {
123 node->SetOutOfParent(outOfParent);
124 }
125 }
126
SetTakeSurfaceForUIFlag(RSContext & context,NodeId nodeId)127 void RSNodeCommandHelper::SetTakeSurfaceForUIFlag(RSContext& context, NodeId nodeId)
128 {
129 context.GetUiCaptureHelper().InsertUiCaptureCmdsExecutedFlag(nodeId, true);
130 }
131
SetNeedUseCmdlistDrawRegion(RSContext & context,NodeId nodeId,bool needUseCmdlistDrawRegion)132 void RSNodeCommandHelper::SetNeedUseCmdlistDrawRegion(RSContext& context, NodeId nodeId, bool needUseCmdlistDrawRegion)
133 {
134 auto& nodeMap = context.GetNodeMap();
135 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
136 if (node != nullptr) {
137 node->SetNeedUseCmdlistDrawRegion(needUseCmdlistDrawRegion);
138 }
139 }
140
RegisterGeometryTransitionPair(RSContext & context,NodeId inNodeId,NodeId outNodeId,const bool isInSameWindow)141 void RSNodeCommandHelper::RegisterGeometryTransitionPair(RSContext& context, NodeId inNodeId, NodeId outNodeId,
142 const bool isInSameWindow)
143 {
144 auto& nodeMap = context.GetNodeMap();
145 auto inNode = nodeMap.GetRenderNode<RSRenderNode>(inNodeId);
146 auto outNode = nodeMap.GetRenderNode<RSRenderNode>(outNodeId);
147 if (inNode == nullptr || outNode == nullptr) {
148 return;
149 }
150 auto sharedTransitionParam = std::make_shared<SharedTransitionParam>(inNode, outNode, isInSameWindow);
151 inNode->SetSharedTransitionParam(sharedTransitionParam);
152 outNode->SetSharedTransitionParam(sharedTransitionParam);
153 }
154
UnregisterGeometryTransitionPair(RSContext & context,NodeId inNodeId,NodeId outNodeId)155 void RSNodeCommandHelper::UnregisterGeometryTransitionPair(RSContext& context, NodeId inNodeId, NodeId outNodeId)
156 {
157 auto& nodeMap = context.GetNodeMap();
158 auto inNode = nodeMap.GetRenderNode<RSRenderNode>(inNodeId);
159 auto outNode = nodeMap.GetRenderNode<RSRenderNode>(outNodeId);
160 // Sanity check, if any check failed, RSUniRenderVisitor will auto unregister the pair, we do nothing here.
161 if (inNode && outNode && inNode->GetSharedTransitionParam() == outNode->GetSharedTransitionParam()) {
162 inNode->SetSharedTransitionParam(nullptr);
163 outNode->SetSharedTransitionParam(nullptr);
164 }
165 }
166
DumpClientNodeTree(RSContext & context,NodeId nodeId,pid_t pid,uint64_t token,uint32_t taskId)167 void RSNodeCommandHelper::DumpClientNodeTree(
168 RSContext& context, NodeId nodeId, pid_t pid, uint64_t token, uint32_t taskId)
169 {
170 if (gDumpNodeTreeProcessor) {
171 gDumpNodeTreeProcessor(nodeId, pid, token, taskId);
172 }
173 }
174
SetDumpNodeTreeProcessor(DumpNodeTreeProcessor processor)175 void RSNodeCommandHelper::SetDumpNodeTreeProcessor(DumpNodeTreeProcessor processor)
176 {
177 gDumpNodeTreeProcessor = processor;
178 }
179
CommitDumpClientNodeTree(RSContext & context,NodeId nodeId,pid_t pid,uint32_t taskId,const std::string & result)180 void RSNodeCommandHelper::CommitDumpClientNodeTree(RSContext& context, NodeId nodeId, pid_t pid, uint32_t taskId,
181 const std::string& result)
182 {
183 if (gCommitDumpNodeTreeProcessor) {
184 gCommitDumpNodeTreeProcessor(nodeId, pid, taskId, result);
185 }
186 }
187
SetCommitDumpNodeTreeProcessor(CommitDumpNodeTreeProcessor processor)188 void RSNodeCommandHelper::SetCommitDumpNodeTreeProcessor(CommitDumpNodeTreeProcessor processor)
189 {
190 gCommitDumpNodeTreeProcessor = processor;
191 }
192
SetUIToken(RSContext & context,NodeId nodeId,uint64_t token)193 void RSNodeCommandHelper::SetUIToken(RSContext& context, NodeId nodeId, uint64_t token)
194 {
195 auto& nodeMap = context.GetNodeMap();
196 auto node = nodeMap.GetRenderNode(nodeId);
197 if (node) {
198 node->SetUIContextToken(token);
199 }
200 }
201
SetDrawNodeType(RSContext & context,NodeId nodeId,DrawNodeType nodeType)202 void RSNodeCommandHelper::SetDrawNodeType(RSContext& context, NodeId nodeId, DrawNodeType nodeType)
203 {
204 auto& nodeMap = context.GetNodeMap();
205 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
206 if (node) {
207 node->SetDrawNodeType(nodeType);
208 }
209 }
210
UpdateOcclusionCullingStatus(RSContext & context,NodeId nodeId,bool enable,NodeId keyOcclusionNodeId)211 void RSNodeCommandHelper::UpdateOcclusionCullingStatus(RSContext& context, NodeId nodeId,
212 bool enable, NodeId keyOcclusionNodeId)
213 {
214 auto& nodeMap = context.GetNodeMap();
215 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
216 auto instanceNode = RSBaseRenderNode::ReinterpretCast<RSSurfaceRenderNode>(node->GetInstanceRootNode());
217 if (instanceNode == nullptr) {
218 return;
219 }
220 if (auto occlusionParams = instanceNode->GetOcclusionParams()) {
221 occlusionParams->UpdateOcclusionCullingStatus(enable, keyOcclusionNodeId);
222 }
223 }
224 }
225
AddModifierNG(RSContext & context,NodeId nodeId,const std::shared_ptr<ModifierNG::RSRenderModifier> & modifier)226 void RSNodeCommandHelper::AddModifierNG(RSContext& context, NodeId nodeId,
227 const std::shared_ptr<ModifierNG::RSRenderModifier>& modifier)
228 {
229 auto& nodeMap = context.GetNodeMap();
230 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
231 if (node) {
232 node->AddModifier(modifier);
233 }
234 }
235
RemoveModifierNG(RSContext & context,NodeId nodeId,ModifierNG::RSModifierType type,ModifierId id)236 void RSNodeCommandHelper::RemoveModifierNG(
237 RSContext& context, NodeId nodeId, ModifierNG::RSModifierType type, ModifierId id)
238 {
239 auto& nodeMap = context.GetNodeMap();
240 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
241 if (node) {
242 node->RemoveModifier(type, id);
243 }
244 }
245
ModifierNGAttachProperty(RSContext & context,NodeId nodeId,ModifierId modifierId,ModifierNG::RSModifierType modifierType,ModifierNG::RSPropertyType propertyType,std::shared_ptr<RSRenderPropertyBase> prop)246 void RSNodeCommandHelper::ModifierNGAttachProperty(RSContext& context, NodeId nodeId, ModifierId modifierId,
247 ModifierNG::RSModifierType modifierType, ModifierNG::RSPropertyType propertyType,
248 std::shared_ptr<RSRenderPropertyBase> prop)
249 {
250 auto& nodeMap = context.GetNodeMap();
251 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
252 if (!node) {
253 return;
254 }
255 auto modifier = node->GetModifierNG(modifierType, modifierId);
256 if (!modifier) {
257 return;
258 }
259 modifier->AttachProperty(propertyType, prop);
260 }
261
UpdateModifierNGDrawCmdList(RSContext & context,NodeId nodeId,Drawing::DrawCmdListPtr value,PropertyId propertyId)262 void RSNodeCommandHelper::UpdateModifierNGDrawCmdList(
263 RSContext& context, NodeId nodeId, Drawing::DrawCmdListPtr value, PropertyId propertyId)
264 {
265 auto& nodeMap = context.GetNodeMap();
266 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
267 if (!node) {
268 return;
269 }
270 auto baseProperty = node->GetProperty(propertyId);
271 if (!baseProperty) {
272 return;
273 }
274 auto property = std::static_pointer_cast<RSRenderProperty<Drawing::DrawCmdListPtr>>(baseProperty);
275 property->Set(value);
276 if (value) {
277 value->UpdateNodeIdToPicture(nodeId);
278 }
279 }
280
ModifierNGDetachProperty(RSContext & context,NodeId nodeId,ModifierId modifierId,ModifierNG::RSModifierType modifierType,ModifierNG::RSPropertyType propertyType)281 void RSNodeCommandHelper::ModifierNGDetachProperty(RSContext& context, NodeId nodeId, ModifierId modifierId,
282 ModifierNG::RSModifierType modifierType, ModifierNG::RSPropertyType propertyType)
283 {
284 auto& nodeMap = context.GetNodeMap();
285 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
286 if (!node) {
287 return;
288 }
289 auto modifier = node->GetModifierNG(modifierType, modifierId);
290 if (!modifier) {
291 return;
292 }
293 modifier->DetachProperty(propertyType);
294 }
295
RemoveAllModifiersNG(RSContext & context,NodeId nodeId)296 void RSNodeCommandHelper::RemoveAllModifiersNG(RSContext& context, NodeId nodeId)
297 {
298 auto& nodeMap = context.GetNodeMap();
299 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
300 if (node) {
301 node->RemoveAllModifiersNG();
302 }
303 }
304 } // namespace Rosen
305 } // namespace OHOS
306