• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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_surface_node_command.h"
17 
18 #include "common/rs_vector4.h"
19 #include "pipeline/rs_surface_render_node.h"
20 #include "pipeline/rs_display_render_node.h"
21 #include "pipeline/rs_render_node_gc.h"
22 #include "platform/common/rs_log.h"
23 #ifndef ROSEN_CROSS_PLATFORM
24 #include "surface_type.h"
25 #endif
26 
27 namespace OHOS {
28 namespace Rosen {
29 
Create(RSContext & context,NodeId id,RSSurfaceNodeType type,bool isTextureExportNode)30 void SurfaceNodeCommandHelper::Create(RSContext& context, NodeId id, RSSurfaceNodeType type, bool isTextureExportNode)
31 {
32     if (!context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
33         auto node = std::shared_ptr<RSSurfaceRenderNode>(new RSSurfaceRenderNode(id,
34             context.weak_from_this(), isTextureExportNode), RSRenderNodeGC::NodeDestructor);
35         node->SetSurfaceNodeType(type);
36         auto& nodeMap = context.GetMutableNodeMap();
37         nodeMap.RegisterRenderNode(node);
38     }
39 }
40 
CreateWithConfig(RSContext & context,NodeId nodeId,std::string name,uint8_t type,std::string bundleName,enum SurfaceWindowType windowType)41 void SurfaceNodeCommandHelper::CreateWithConfig(
42     RSContext& context, NodeId nodeId, std::string name, uint8_t type,
43     std::string bundleName, enum SurfaceWindowType windowType)
44 {
45     RSSurfaceRenderNodeConfig config = {
46         .id = nodeId, .name = name, .bundleName = bundleName,
47         .nodeType = static_cast<RSSurfaceNodeType>(type), .surfaceWindowType = windowType
48     };
49     auto node = std::shared_ptr<RSSurfaceRenderNode>(new RSSurfaceRenderNode(config,
50         context.weak_from_this()), RSRenderNodeGC::NodeDestructor);
51     context.GetMutableNodeMap().RegisterRenderNode(node);
52 }
53 
CreateWithConfigInRS(const RSSurfaceRenderNodeConfig & config,RSContext & context)54 std::shared_ptr<RSSurfaceRenderNode> SurfaceNodeCommandHelper::CreateWithConfigInRS(
55     const RSSurfaceRenderNodeConfig& config, RSContext& context)
56 {
57     auto node = std::shared_ptr<RSSurfaceRenderNode>(new RSSurfaceRenderNode(config,
58         context.weak_from_this()), RSRenderNodeGC::NodeDestructor);
59     return node;
60 }
61 
SetContextMatrix(RSContext & context,NodeId id,const std::optional<Drawing::Matrix> & matrix)62 void SurfaceNodeCommandHelper::SetContextMatrix(
63     RSContext& context, NodeId id, const std::optional<Drawing::Matrix>& matrix)
64 {
65     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
66         node->SetContextMatrix(matrix, false);
67     }
68 }
69 
SetContextAlpha(RSContext & context,NodeId id,float alpha)70 void SurfaceNodeCommandHelper::SetContextAlpha(RSContext& context, NodeId id, float alpha)
71 {
72     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
73         node->SetContextAlpha(alpha, false);
74     }
75 }
76 
SetContextClipRegion(RSContext & context,NodeId id,const std::optional<Drawing::Rect> & clipRect)77 void SurfaceNodeCommandHelper::SetContextClipRegion(
78     RSContext& context, NodeId id, const std::optional<Drawing::Rect>& clipRect)
79 {
80     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
81         node->SetContextClipRegion(clipRect, false);
82     }
83 }
84 
SetSecurityLayer(RSContext & context,NodeId id,bool isSecurityLayer)85 void SurfaceNodeCommandHelper::SetSecurityLayer(RSContext& context, NodeId id, bool isSecurityLayer)
86 {
87     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
88         node->SetSecurityLayer(isSecurityLayer);
89     }
90 }
91 
SetLeashPersistentId(RSContext & context,NodeId id,LeashPersistentId leashPersistentId)92 void SurfaceNodeCommandHelper::SetLeashPersistentId(RSContext& context, NodeId id, LeashPersistentId leashPersistentId)
93 {
94     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
95         node->SetLeashPersistentId(leashPersistentId);
96     }
97 }
98 
SetIsTextureExportNode(RSContext & context,NodeId id,bool isTextureExportNode)99 void SurfaceNodeCommandHelper::SetIsTextureExportNode(RSContext& context, NodeId id, bool isTextureExportNode)
100 {
101     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
102         node->SetIsTextureExportNode(isTextureExportNode);
103     }
104 }
105 
SetSkipLayer(RSContext & context,NodeId id,bool isSkipLayer)106 void SurfaceNodeCommandHelper::SetSkipLayer(RSContext& context, NodeId id, bool isSkipLayer)
107 {
108     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
109         node->SetSkipLayer(isSkipLayer);
110     }
111 }
112 
SetFingerprint(RSContext & context,NodeId id,bool hasFingerprint)113 void SurfaceNodeCommandHelper::SetFingerprint(RSContext& context, NodeId id, bool hasFingerprint)
114 {
115     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
116         node->SetFingerprint(hasFingerprint);
117     }
118 }
119 
SetColorSpace(RSContext & context,NodeId id,GraphicColorGamut colorSpace)120 void SurfaceNodeCommandHelper::SetColorSpace(RSContext& context, NodeId id, GraphicColorGamut colorSpace)
121 {
122     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
123         node->SetColorSpace(colorSpace);
124     }
125 }
126 
UpdateSurfaceDefaultSize(RSContext & context,NodeId id,float width,float height)127 void SurfaceNodeCommandHelper::UpdateSurfaceDefaultSize(RSContext& context, NodeId id, float width, float height)
128 {
129     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
130         node->UpdateSurfaceDefaultSize(width, height);
131     }
132 }
133 
ConnectToNodeInRenderService(RSContext & context,NodeId id)134 void SurfaceNodeCommandHelper::ConnectToNodeInRenderService(RSContext& context, NodeId id)
135 {
136     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
137         node->ConnectToNodeInRenderService();
138     }
139 }
140 
SetCallbackForRenderThreadRefresh(RSContext & context,NodeId id,bool isRefresh)141 void SurfaceNodeCommandHelper::SetCallbackForRenderThreadRefresh(
142     RSContext& context, NodeId id, bool isRefresh)
143 {
144     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
145         if (node->NeedSetCallbackForRenderThreadRefresh()) {
146             node->SetCallbackForRenderThreadRefresh(isRefresh);
147         }
148     }
149 }
150 
SetContextBounds(RSContext & context,NodeId id,Vector4f bounds)151 void SurfaceNodeCommandHelper::SetContextBounds(RSContext& context, NodeId id, Vector4f bounds)
152 {
153     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
154         node->GetMutableRenderProperties().SetBounds(bounds);
155     }
156 }
157 
SetAbilityBGAlpha(RSContext & context,NodeId id,uint8_t alpha)158 void SurfaceNodeCommandHelper::SetAbilityBGAlpha(RSContext& context, NodeId id, uint8_t alpha)
159 {
160     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
161         node->SetAbilityBGAlpha(alpha);
162     }
163 }
164 
SetIsNotifyUIBufferAvailable(RSContext & context,NodeId id,bool available)165 void SurfaceNodeCommandHelper::SetIsNotifyUIBufferAvailable(RSContext& context, NodeId id, bool available)
166 {
167     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
168         node->SetIsNotifyUIBufferAvailable(available);
169     }
170 }
171 
MarkUIHidden(RSContext & context,NodeId id,bool isHidden)172 void SurfaceNodeCommandHelper::MarkUIHidden(RSContext& context, NodeId id, bool isHidden)
173 {
174     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
175         node->MarkUIHidden(isHidden);
176     }
177 }
178 
SetSurfaceNodeType(RSContext & context,NodeId nodeId,uint8_t surfaceNodeType)179 void SurfaceNodeCommandHelper::SetSurfaceNodeType(RSContext& context, NodeId nodeId, uint8_t surfaceNodeType)
180 {
181     auto type = static_cast<RSSurfaceNodeType>(surfaceNodeType);
182     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
183         node->SetSurfaceNodeType(type);
184     }
185 }
186 
SetContainerWindow(RSContext & context,NodeId nodeId,bool hasContainerWindow,float density)187 void SurfaceNodeCommandHelper::SetContainerWindow(
188     RSContext& context, NodeId nodeId, bool hasContainerWindow, float density)
189 {
190     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
191         node->SetContainerWindow(hasContainerWindow, density);
192     }
193 }
194 
SetAnimationFinished(RSContext & context,NodeId nodeId)195 void SurfaceNodeCommandHelper::SetAnimationFinished(RSContext& context, NodeId nodeId)
196 {
197     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
198         node->SetStartAnimationFinished();
199     }
200 }
201 
AttachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)202 void SurfaceNodeCommandHelper::AttachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
203 {
204     const auto& nodeMap = context.GetNodeMap();
205     auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
206     if (surfaceRenderNode == nullptr) {
207         return;
208     }
209     nodeMap.TraverseDisplayNodes(
210         [&surfaceRenderNode, &screenId](const std::shared_ptr<RSDisplayRenderNode>& displayRenderNode) {
211             if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId ||
212                 displayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
213                 return;
214             }
215             displayRenderNode->AddChild(surfaceRenderNode);
216         });
217 }
218 
DetachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)219 void SurfaceNodeCommandHelper::DetachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
220 {
221     const auto& nodeMap = context.GetNodeMap();
222     auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
223     if (surfaceRenderNode == nullptr) {
224         return;
225     }
226     nodeMap.TraverseDisplayNodes(
227         [&surfaceRenderNode, &screenId](const std::shared_ptr<RSDisplayRenderNode>& displayRenderNode) {
228             if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId ||
229                 displayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
230                 return;
231             }
232             displayRenderNode->RemoveChild(surfaceRenderNode);
233         });
234 }
235 
SetBootAnimation(RSContext & context,NodeId nodeId,bool isBootAnimation)236 void SurfaceNodeCommandHelper::SetBootAnimation(RSContext& context, NodeId nodeId, bool isBootAnimation)
237 {
238     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
239         node->SetBootAnimation(isBootAnimation);
240     }
241 }
242 
243 #ifdef USE_SURFACE_TEXTURE
CreateSurfaceExt(RSContext & context,NodeId id,const std::shared_ptr<RSSurfaceTexture> & surfaceExt)244 void SurfaceNodeCommandHelper::CreateSurfaceExt(RSContext& context, NodeId id,
245     const std::shared_ptr<RSSurfaceTexture>& surfaceExt)
246 {
247     auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id);
248     if (node != nullptr) {
249         node->SetSurfaceTexture(surfaceExt);
250     }
251 }
252 #endif
253 
SetForceHardwareAndFixRotation(RSContext & context,NodeId nodeId,bool flag)254 void SurfaceNodeCommandHelper::SetForceHardwareAndFixRotation(RSContext& context, NodeId nodeId, bool flag)
255 {
256     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
257         node->SetForceHardwareAndFixRotation(flag);
258     }
259 }
260 
SetForeground(RSContext & context,NodeId nodeId,bool isForeground)261 void SurfaceNodeCommandHelper::SetForeground(RSContext& context, NodeId nodeId, bool isForeground)
262 {
263     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
264         node->SetForeground(isForeground);
265     }
266 }
267 
SetSurfaceId(RSContext & context,NodeId nodeId,SurfaceId surfaceId)268 void SurfaceNodeCommandHelper::SetSurfaceId(RSContext& context, NodeId nodeId, SurfaceId surfaceId)
269 {
270     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
271         node->SetSurfaceId(surfaceId);
272     }
273 }
274 
SetForceUIFirst(RSContext & context,NodeId nodeId,bool forceUIFirst)275 void SurfaceNodeCommandHelper::SetForceUIFirst(RSContext& context, NodeId nodeId, bool forceUIFirst)
276 {
277     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
278         node->SetForceUIFirst(forceUIFirst);
279     }
280 }
281 
SetAncoFlags(RSContext & context,NodeId nodeId,uint32_t flags)282 void SurfaceNodeCommandHelper::SetAncoFlags(RSContext& context, NodeId nodeId, uint32_t flags)
283 {
284     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
285         node->SetAncoFlags(flags);
286     }
287 }
288 
SetHDRPresent(RSContext & context,NodeId nodeId,bool ancoForceDoDirect)289 void SurfaceNodeCommandHelper::SetHDRPresent(RSContext& context, NodeId nodeId, bool ancoForceDoDirect)
290 {
291     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
292         node->SetHDRPresent(ancoForceDoDirect);
293     }
294 }
295 
SetSkipDraw(RSContext & context,NodeId nodeId,bool skip)296 void SurfaceNodeCommandHelper::SetSkipDraw(RSContext& context, NodeId nodeId, bool skip)
297 {
298     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
299         node->SetSkipDraw(skip);
300     }
301 }
302 
SetAbilityState(RSContext & context,NodeId nodeId,RSSurfaceNodeAbilityState abilityState)303 void SurfaceNodeCommandHelper::SetAbilityState(RSContext& context, NodeId nodeId,
304     RSSurfaceNodeAbilityState abilityState)
305 {
306     auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId);
307     if (!node) {
308         ROSEN_LOGE("SurfaceNodeCommandHelper::SetAbilityState node is null!");
309         return;
310     }
311     node->SetAbilityState(abilityState);
312 }
313 } // namespace Rosen
314 } // namespace OHOS
315