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 namespace OHOS {
19 namespace Rosen {
20 namespace {
21 RSNodeCommandHelper::DumpNodeTreeProcessor gDumpNodeTreeProcessor = nullptr;
22 RSNodeCommandHelper::CommitDumpNodeTreeProcessor gCommitDumpNodeTreeProcessor = nullptr;
23 }
24
AddModifier(RSContext & context,NodeId nodeId,const std::shared_ptr<RSRenderModifier> & modifier)25 void RSNodeCommandHelper::AddModifier(RSContext& context, NodeId nodeId,
26 const std::shared_ptr<RSRenderModifier>& modifier)
27 {
28 auto& nodeMap = context.GetNodeMap();
29 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
30 if (node) {
31 node->AddModifier(modifier);
32 }
33 }
34
RemoveModifier(RSContext & context,NodeId nodeId,PropertyId propertyId)35 void RSNodeCommandHelper::RemoveModifier(RSContext& context, NodeId nodeId, PropertyId propertyId)
36 {
37 auto& nodeMap = context.GetNodeMap();
38 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
39 if (node) {
40 node->RemoveModifier(propertyId);
41 }
42 }
43
RemoveAllModifiers(RSContext & context,NodeId nodeId)44 void RSNodeCommandHelper::RemoveAllModifiers(RSContext& context, NodeId nodeId)
45 {
46 auto& nodeMap = context.GetNodeMap();
47 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
48 if (node) {
49 node->RemoveAllModifiers();
50 }
51 }
52
SetFreeze(RSContext & context,NodeId nodeId,bool isFreeze)53 void RSNodeCommandHelper::SetFreeze(RSContext& context, NodeId nodeId, bool isFreeze)
54 {
55 auto& nodeMap = context.GetNodeMap();
56 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
57 if (node) {
58 node->SetStaticCached(isFreeze);
59 }
60 }
61
SetNodeName(RSContext & context,NodeId nodeId,std::string & nodeName)62 void RSNodeCommandHelper::SetNodeName(RSContext& context, NodeId nodeId, std::string& nodeName)
63 {
64 auto& nodeMap = context.GetNodeMap();
65 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
66 if (node) {
67 node->SetNodeName(nodeName);
68 }
69 }
70
MarkNodeGroup(RSContext & context,NodeId nodeId,bool isNodeGroup,bool isForced,bool includeProperty)71 void RSNodeCommandHelper::MarkNodeGroup(RSContext& context, NodeId nodeId, bool isNodeGroup, bool isForced,
72 bool includeProperty)
73 {
74 auto& nodeMap = context.GetNodeMap();
75 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
76 node->MarkNodeGroup(isForced ? RSRenderNode::GROUPED_BY_USER : RSRenderNode::GROUPED_BY_UI, isNodeGroup,
77 includeProperty);
78 }
79 }
80
MarkNodeSingleFrameComposer(RSContext & context,NodeId nodeId,bool isNodeSingleFrameComposer,pid_t pid)81 void RSNodeCommandHelper::MarkNodeSingleFrameComposer(RSContext& context,
82 NodeId nodeId, bool isNodeSingleFrameComposer, pid_t pid)
83 {
84 auto& nodeMap = context.GetNodeMap();
85 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
86 RSSingleFrameComposer::AddOrRemoveAppPidToMap(isNodeSingleFrameComposer, pid);
87 node->MarkNodeSingleFrameComposer(isNodeSingleFrameComposer, pid);
88 }
89 }
90
MarkSuggestOpincNode(RSContext & context,NodeId nodeId,bool isOpincNode,bool isNeedCalculate)91 void RSNodeCommandHelper::MarkSuggestOpincNode(RSContext& context, NodeId nodeId,
92 bool isOpincNode, bool isNeedCalculate)
93 {
94 auto& nodeMap = context.GetNodeMap();
95 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
96 node->MarkSuggestOpincNode(isOpincNode, isNeedCalculate);
97 }
98 }
99
MarkUifirstNode(RSContext & context,NodeId nodeId,bool isUifirstNode)100 void RSNodeCommandHelper::MarkUifirstNode(RSContext& context, NodeId nodeId, bool isUifirstNode)
101 {
102 auto& nodeMap = context.GetNodeMap();
103 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
104 node->MarkUifirstNode(isUifirstNode);
105 }
106 }
107
SetDrawRegion(RSContext & context,NodeId nodeId,std::shared_ptr<RectF> rect)108 void RSNodeCommandHelper::SetDrawRegion(RSContext& context, NodeId nodeId, std::shared_ptr<RectF> rect)
109 {
110 auto& nodeMap = context.GetNodeMap();
111 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
112 if (node) {
113 node->SetDrawRegion(rect);
114 }
115 }
116
SetOutOfParent(RSContext & context,NodeId nodeId,OutOfParentType outOfParent)117 void RSNodeCommandHelper::SetOutOfParent(RSContext& context, NodeId nodeId, OutOfParentType outOfParent)
118 {
119 auto& nodeMap = context.GetNodeMap();
120 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
121 if (node) {
122 node->SetOutOfParent(outOfParent);
123 }
124 }
125
RegisterGeometryTransitionPair(RSContext & context,NodeId inNodeId,NodeId outNodeId)126 void RSNodeCommandHelper::RegisterGeometryTransitionPair(RSContext& context, NodeId inNodeId, NodeId outNodeId)
127 {
128 auto& nodeMap = context.GetNodeMap();
129 auto inNode = nodeMap.GetRenderNode<RSRenderNode>(inNodeId);
130 auto outNode = nodeMap.GetRenderNode<RSRenderNode>(outNodeId);
131 if (inNode == nullptr || outNode == nullptr) {
132 return;
133 }
134 auto sharedTransitionParam = std::make_shared<SharedTransitionParam>(inNode, outNode);
135 inNode->SetSharedTransitionParam(sharedTransitionParam);
136 outNode->SetSharedTransitionParam(sharedTransitionParam);
137 }
138
UnregisterGeometryTransitionPair(RSContext & context,NodeId inNodeId,NodeId outNodeId)139 void RSNodeCommandHelper::UnregisterGeometryTransitionPair(RSContext& context, NodeId inNodeId, NodeId outNodeId)
140 {
141 auto& nodeMap = context.GetNodeMap();
142 auto inNode = nodeMap.GetRenderNode<RSRenderNode>(inNodeId);
143 auto outNode = nodeMap.GetRenderNode<RSRenderNode>(outNodeId);
144 // Sanity check, if any check failed, RSUniRenderVisitor will auto unregister the pair, we do nothing here.
145 if (inNode && outNode && inNode->GetSharedTransitionParam() == outNode->GetSharedTransitionParam()) {
146 inNode->SetSharedTransitionParam(nullptr);
147 outNode->SetSharedTransitionParam(nullptr);
148 }
149 }
150
DumpClientNodeTree(RSContext & context,NodeId nodeId,pid_t pid,uint32_t taskId)151 void RSNodeCommandHelper::DumpClientNodeTree(RSContext& context, NodeId nodeId, pid_t pid, uint32_t taskId)
152 {
153 if (gDumpNodeTreeProcessor) {
154 gDumpNodeTreeProcessor(nodeId, pid, taskId);
155 }
156 }
157
SetDumpNodeTreeProcessor(DumpNodeTreeProcessor processor)158 void RSNodeCommandHelper::SetDumpNodeTreeProcessor(DumpNodeTreeProcessor processor)
159 {
160 gDumpNodeTreeProcessor = processor;
161 }
162
CommitDumpClientNodeTree(RSContext & context,NodeId nodeId,pid_t pid,uint32_t taskId,const std::string & result)163 void RSNodeCommandHelper::CommitDumpClientNodeTree(RSContext& context, NodeId nodeId, pid_t pid, uint32_t taskId,
164 const std::string& result)
165 {
166 if (gCommitDumpNodeTreeProcessor) {
167 gCommitDumpNodeTreeProcessor(nodeId, pid, taskId, result);
168 }
169 }
170
SetCommitDumpNodeTreeProcessor(CommitDumpNodeTreeProcessor processor)171 void RSNodeCommandHelper::SetCommitDumpNodeTreeProcessor(CommitDumpNodeTreeProcessor processor)
172 {
173 gCommitDumpNodeTreeProcessor = processor;
174 }
175 } // namespace Rosen
176 } // namespace OHOS
177