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 {
AddModifier(RSContext & context,NodeId nodeId,const std::shared_ptr<RSRenderModifier> & modifier)20 void RSNodeCommandHelper::AddModifier(RSContext& context, NodeId nodeId,
21 const std::shared_ptr<RSRenderModifier>& modifier)
22 {
23 auto& nodeMap = context.GetNodeMap();
24 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
25 if (node) {
26 node->AddModifier(modifier);
27 }
28 }
29
RemoveModifier(RSContext & context,NodeId nodeId,PropertyId propertyId)30 void RSNodeCommandHelper::RemoveModifier(RSContext& context, NodeId nodeId, PropertyId propertyId)
31 {
32 auto& nodeMap = context.GetNodeMap();
33 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
34 if (node) {
35 node->RemoveModifier(propertyId);
36 }
37 }
38
SetFreeze(RSContext & context,NodeId nodeId,bool isFreeze)39 void RSNodeCommandHelper::SetFreeze(RSContext& context, NodeId nodeId, bool isFreeze)
40 {
41 auto& nodeMap = context.GetNodeMap();
42 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
43 if (node) {
44 node->SetStaticCached(isFreeze);
45 }
46 }
47
MarkNodeGroup(RSContext & context,NodeId nodeId,bool isNodeGroup)48 void RSNodeCommandHelper::MarkNodeGroup(RSContext& context, NodeId nodeId, bool isNodeGroup)
49 {
50 auto& nodeMap = context.GetNodeMap();
51 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
52 node->MarkNodeGroup(RSRenderNode::GROUPED_BY_USER, isNodeGroup);
53 }
54 }
55
MarkDrivenRender(RSContext & context,NodeId nodeId,bool flag)56 void RSNodeCommandHelper::MarkDrivenRender(RSContext& context, NodeId nodeId, bool flag)
57 {
58 auto node = context.GetNodeMap().GetRenderNode<RSRenderNode>(nodeId);
59 if (node) {
60 node->SetIsMarkDriven(flag);
61 auto& nodeMap = context.GetMutableNodeMap();
62 if (flag) {
63 nodeMap.AddDrivenRenderNode(node);
64 } else {
65 nodeMap.RemoveDrivenRenderNode(nodeId);
66 }
67 }
68 }
69
MarkDrivenRenderItemIndex(RSContext & context,NodeId nodeId,int32_t index)70 void RSNodeCommandHelper::MarkDrivenRenderItemIndex(RSContext& context, NodeId nodeId, int32_t index)
71 {
72 auto node = context.GetNodeMap().GetRenderNode<RSRenderNode>(nodeId);
73 if (node) {
74 node->SetItemIndex(index);
75 }
76 }
77
MarkDrivenRenderFramePaintState(RSContext & context,NodeId nodeId,bool flag)78 void RSNodeCommandHelper::MarkDrivenRenderFramePaintState(RSContext& context, NodeId nodeId, bool flag)
79 {
80 auto node = context.GetNodeMap().GetRenderNode<RSRenderNode>(nodeId);
81 if (node) {
82 node->SetPaintState(flag);
83 }
84 }
85
MarkContentChanged(RSContext & context,NodeId nodeId,bool isChanged)86 void RSNodeCommandHelper::MarkContentChanged(RSContext& context, NodeId nodeId, bool isChanged)
87 {
88 auto node = context.GetNodeMap().GetRenderNode<RSRenderNode>(nodeId);
89 if (node) {
90 node->SetIsContentChanged(isChanged);
91 }
92 }
93
SetDrawRegion(RSContext & context,NodeId nodeId,std::shared_ptr<RectF> rect)94 void RSNodeCommandHelper::SetDrawRegion(RSContext& context, NodeId nodeId, std::shared_ptr<RectF> rect)
95 {
96 auto& nodeMap = context.GetNodeMap();
97 auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId);
98 if (node) {
99 node->SetDrawRegion(rect);
100 }
101 }
102
RegisterGeometryTransitionPair(RSContext & context,NodeId inNodeId,NodeId outNodeId)103 void RSNodeCommandHelper::RegisterGeometryTransitionPair(RSContext& context, NodeId inNodeId, NodeId outNodeId)
104 {
105 auto& nodeMap = context.GetNodeMap();
106 auto inNode = nodeMap.GetRenderNode<RSRenderNode>(inNodeId);
107 auto outNode = nodeMap.GetRenderNode<RSRenderNode>(outNodeId);
108 if (inNode && outNode) {
109 // used inNode id as transition key
110 RSRenderNode::SharedTransitionParam inNodeParam { inNode->GetId(), outNode };
111 inNode->SetSharedTransitionParam(std::move(inNodeParam));
112
113 RSRenderNode::SharedTransitionParam outNodeParam { inNode->GetId(), inNode };
114 outNode->SetSharedTransitionParam(std::move(outNodeParam));
115 }
116 }
117
UnregisterGeometryTransitionPair(RSContext & context,NodeId inNodeId,NodeId outNodeId)118 void RSNodeCommandHelper::UnregisterGeometryTransitionPair(RSContext& context, NodeId inNodeId, NodeId outNodeId)
119 {
120 auto& nodeMap = context.GetNodeMap();
121 auto inNode = nodeMap.GetRenderNode<RSRenderNode>(inNodeId);
122 auto outNode = nodeMap.GetRenderNode<RSRenderNode>(outNodeId);
123 // Sanity check, if any check failed, RSUniRenderVisitor will auto unregister the pair, we do nothing here.
124 if (inNode && outNode &&
125 inNode->GetSharedTransitionParam().has_value() &&
126 inNode->GetSharedTransitionParam()->first == inNode->GetId() &&
127 outNode->GetSharedTransitionParam().has_value() &&
128 outNode->GetSharedTransitionParam()->first == inNode->GetId()) {
129 inNode->SetSharedTransitionParam(std::nullopt);
130 outNode->SetSharedTransitionParam(std::nullopt);
131 }
132 }
133
SetUIFrameRateRange(RSContext & context,NodeId nodeId,FrameRateRange range)134 void RSNodeCommandHelper::SetUIFrameRateRange(RSContext& context, NodeId nodeId, FrameRateRange range)
135 {
136 auto& nodeMap = context.GetNodeMap();
137 if (auto node = nodeMap.GetRenderNode<RSRenderNode>(nodeId)) {
138 node->SetUIFrameRateRange(range);
139 }
140 }
141 } // namespace Rosen
142 } // namespace OHOS
143