• 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 "command/rs_command_verify_helper.h"
19 #include "common/rs_vector4.h"
20 #include "pipeline/rs_surface_render_node.h"
21 #include "pipeline/rs_screen_render_node.h"
22 #include "pipeline/rs_logical_display_render_node.h"
23 #include "pipeline/rs_render_node_gc.h"
24 #include "platform/common/rs_log.h"
25 #ifndef ROSEN_CROSS_PLATFORM
26 #include "surface_type.h"
27 #endif
28 
29 namespace OHOS {
30 namespace Rosen {
31 
Create(RSContext & context,NodeId id,RSSurfaceNodeType type,bool isTextureExportNode)32 void SurfaceNodeCommandHelper::Create(RSContext& context, NodeId id, RSSurfaceNodeType type, bool isTextureExportNode)
33 {
34     if (!context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
35         if (!RsCommandVerifyHelper::GetInstance().IsSurfaceNodeCreateCommandVaild(ExtractPid(id))) {
36             ROSEN_LOGI("SurfaceNodeCommandHelper::Create command is not vaild because there "
37             "have been too many surfaceNodes, nodeId:%{public}" PRIu64 "", id);
38             return;
39         }
40         auto node = std::shared_ptr<RSSurfaceRenderNode>(new RSSurfaceRenderNode(id,
41             context.weak_from_this(), isTextureExportNode), RSRenderNodeGC::NodeDestructor);
42         node->SetSurfaceNodeType(type);
43         auto& nodeMap = context.GetMutableNodeMap();
44         nodeMap.RegisterRenderNode(node);
45     }
46 }
47 
CreateWithConfig(RSContext & context,NodeId nodeId,std::string name,uint8_t type,enum SurfaceWindowType windowType)48 void SurfaceNodeCommandHelper::CreateWithConfig(
49     RSContext& context, NodeId nodeId, std::string name, uint8_t type, enum SurfaceWindowType windowType)
50 {
51     RSSurfaceRenderNodeConfig config = {
52         .id = nodeId, .name = name,
53         .nodeType = static_cast<RSSurfaceNodeType>(type), .surfaceWindowType = windowType
54     };
55     if (!RsCommandVerifyHelper::GetInstance().IsSurfaceNodeCreateCommandVaild(ExtractPid(nodeId))) {
56         ROSEN_LOGI("SurfaceNodeCommandHelper::CreateWithConfig command is not vaild because there "
57             "have been too many surfaceNodes, nodeId:%{public}" PRIu64 "", nodeId);
58         return;
59     }
60     auto node = std::shared_ptr<RSSurfaceRenderNode>(new RSSurfaceRenderNode(config,
61         context.weak_from_this()), RSRenderNodeGC::NodeDestructor);
62     context.GetMutableNodeMap().RegisterRenderNode(node);
63 }
64 
CreateWithConfigInRS(const RSSurfaceRenderNodeConfig & config,RSContext & context,bool unobscured)65 std::shared_ptr<RSSurfaceRenderNode> SurfaceNodeCommandHelper::CreateWithConfigInRS(
66     const RSSurfaceRenderNodeConfig& config, RSContext& context, bool unobscured)
67 {
68     if (!RsCommandVerifyHelper::GetInstance().IsSurfaceNodeCreateCommandVaild(ExtractPid(config.id))) {
69         ROSEN_LOGI("SurfaceNodeCommandHelper::CreateWithConfigInRS command is not vaild because there have "
70             "been too many surfaceNodes, nodeId:%{public}" PRIu64 "", config.id);
71         return nullptr;
72     }
73     auto node = std::shared_ptr<RSSurfaceRenderNode>(new RSSurfaceRenderNode(config,
74         context.weak_from_this()), RSRenderNodeGC::NodeDestructor);
75     node->SetUIExtensionUnobscured(unobscured);
76     return node;
77 }
78 
SetContextMatrix(RSContext & context,NodeId id,const std::optional<Drawing::Matrix> & matrix)79 void SurfaceNodeCommandHelper::SetContextMatrix(
80     RSContext& context, NodeId id, const std::optional<Drawing::Matrix>& matrix)
81 {
82     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
83         node->SetContextMatrix(matrix, false);
84     }
85 }
86 
SetContextAlpha(RSContext & context,NodeId id,float alpha)87 void SurfaceNodeCommandHelper::SetContextAlpha(RSContext& context, NodeId id, float alpha)
88 {
89     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
90         node->SetContextAlpha(alpha, false);
91     }
92 }
93 
SetContextClipRegion(RSContext & context,NodeId id,const std::optional<Drawing::Rect> & clipRect)94 void SurfaceNodeCommandHelper::SetContextClipRegion(
95     RSContext& context, NodeId id, const std::optional<Drawing::Rect>& clipRect)
96 {
97     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
98         node->SetContextClipRegion(clipRect, false);
99     }
100 }
101 
SetSecurityLayer(RSContext & context,NodeId id,bool isSecurityLayer)102 void SurfaceNodeCommandHelper::SetSecurityLayer(RSContext& context, NodeId id, bool isSecurityLayer)
103 {
104     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
105         node->SetSecurityLayer(isSecurityLayer);
106     }
107 }
108 
SetLeashPersistentId(RSContext & context,NodeId id,LeashPersistentId leashPersistentId)109 void SurfaceNodeCommandHelper::SetLeashPersistentId(RSContext& context, NodeId id, LeashPersistentId leashPersistentId)
110 {
111     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
112         node->SetLeashPersistentId(leashPersistentId);
113     }
114 }
115 
SetIsTextureExportNode(RSContext & context,NodeId id,bool isTextureExportNode)116 void SurfaceNodeCommandHelper::SetIsTextureExportNode(RSContext& context, NodeId id, bool isTextureExportNode)
117 {
118     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
119         node->SetIsTextureExportNode(isTextureExportNode);
120     }
121 }
122 
SetSkipLayer(RSContext & context,NodeId id,bool isSkipLayer)123 void SurfaceNodeCommandHelper::SetSkipLayer(RSContext& context, NodeId id, bool isSkipLayer)
124 {
125     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
126         node->SetSkipLayer(isSkipLayer);
127     }
128 }
129 
SetSnapshotSkipLayer(RSContext & context,NodeId id,bool isSnapshotSkipLayer)130 void SurfaceNodeCommandHelper::SetSnapshotSkipLayer(RSContext& context, NodeId id, bool isSnapshotSkipLayer)
131 {
132     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
133         node->SetSnapshotSkipLayer(isSnapshotSkipLayer);
134     }
135 }
136 
SetFingerprint(RSContext & context,NodeId id,bool hasFingerprint)137 void SurfaceNodeCommandHelper::SetFingerprint(RSContext& context, NodeId id, bool hasFingerprint)
138 {
139     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
140         node->SetFingerprint(hasFingerprint);
141     }
142 }
143 
SetColorSpace(RSContext & context,NodeId id,GraphicColorGamut colorSpace)144 void SurfaceNodeCommandHelper::SetColorSpace(RSContext& context, NodeId id, GraphicColorGamut colorSpace)
145 {
146     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
147         node->SetColorSpace(colorSpace);
148     }
149 }
150 
UpdateSurfaceDefaultSize(RSContext & context,NodeId id,float width,float height)151 void SurfaceNodeCommandHelper::UpdateSurfaceDefaultSize(RSContext& context, NodeId id, float width, float height)
152 {
153     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
154         node->UpdateSurfaceDefaultSize(width, height);
155     }
156 }
157 
ConnectToNodeInRenderService(RSContext & context,NodeId id)158 void SurfaceNodeCommandHelper::ConnectToNodeInRenderService(RSContext& context, NodeId id)
159 {
160     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
161         node->ConnectToNodeInRenderService();
162     }
163 }
164 
SetCallbackForRenderThreadRefresh(RSContext & context,NodeId id,bool isRefresh)165 void SurfaceNodeCommandHelper::SetCallbackForRenderThreadRefresh(
166     RSContext& context, NodeId id, bool isRefresh)
167 {
168     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
169         if (node->NeedSetCallbackForRenderThreadRefresh()) {
170             node->SetCallbackForRenderThreadRefresh(isRefresh);
171         }
172     }
173 }
174 
SetContextBounds(RSContext & context,NodeId id,Vector4f bounds)175 void SurfaceNodeCommandHelper::SetContextBounds(RSContext& context, NodeId id, Vector4f bounds)
176 {
177     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
178         node->GetMutableRenderProperties().SetBounds(bounds);
179     }
180 }
181 
SetAbilityBGAlpha(RSContext & context,NodeId id,uint8_t alpha)182 void SurfaceNodeCommandHelper::SetAbilityBGAlpha(RSContext& context, NodeId id, uint8_t alpha)
183 {
184     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
185         node->SetAbilityBGAlpha(alpha);
186     }
187 }
188 
SetIsNotifyUIBufferAvailable(RSContext & context,NodeId id,bool available)189 void SurfaceNodeCommandHelper::SetIsNotifyUIBufferAvailable(RSContext& context, NodeId id, bool available)
190 {
191     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
192         node->SetIsNotifyUIBufferAvailable(available);
193     }
194 }
195 
MarkUIHidden(RSContext & context,NodeId id,bool isHidden)196 void SurfaceNodeCommandHelper::MarkUIHidden(RSContext& context, NodeId id, bool isHidden)
197 {
198     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
199         node->MarkUIHidden(isHidden);
200     }
201 }
202 
SetSurfaceNodeType(RSContext & context,NodeId nodeId,uint8_t surfaceNodeType)203 void SurfaceNodeCommandHelper::SetSurfaceNodeType(RSContext& context, NodeId nodeId, uint8_t surfaceNodeType)
204 {
205     auto type = static_cast<RSSurfaceNodeType>(surfaceNodeType);
206     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
207         node->SetSurfaceNodeType(type);
208     }
209 }
210 
SetContainerWindow(RSContext & context,NodeId nodeId,bool hasContainerWindow,RRect rrect)211 void SurfaceNodeCommandHelper::SetContainerWindow(
212     RSContext& context, NodeId nodeId, bool hasContainerWindow, RRect rrect)
213 {
214     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
215         node->SetContainerWindow(hasContainerWindow, rrect);
216     }
217 }
218 
SetAnimationFinished(RSContext & context,NodeId nodeId)219 void SurfaceNodeCommandHelper::SetAnimationFinished(RSContext& context, NodeId nodeId)
220 {
221     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
222         node->SetStartAnimationFinished();
223     }
224 }
225 
AttachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)226 void SurfaceNodeCommandHelper::AttachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
227 {
228     const auto& nodeMap = context.GetNodeMap();
229     auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
230     if (surfaceRenderNode == nullptr) {
231         return;
232     }
233     nodeMap.TraverseLogicalDisplayNodes(
234         [&surfaceRenderNode, &screenId](const std::shared_ptr<RSLogicalDisplayRenderNode>& logicalDisplayRenderNode) {
235             if (logicalDisplayRenderNode == nullptr || logicalDisplayRenderNode->GetScreenId() != screenId ||
236                 logicalDisplayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation() ||
237                 !logicalDisplayRenderNode->IsOnTheTree()) {
238                 return;
239             }
240             logicalDisplayRenderNode->AddChild(surfaceRenderNode);
241         });
242 }
243 
DetachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)244 void SurfaceNodeCommandHelper::DetachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
245 {
246     const auto& nodeMap = context.GetNodeMap();
247     auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
248     if (surfaceRenderNode == nullptr) {
249         return;
250     }
251     nodeMap.TraverseLogicalDisplayNodes(
252         [&surfaceRenderNode, &screenId](const std::shared_ptr<RSLogicalDisplayRenderNode>& logicalDisplayRenderNode) {
253             if (logicalDisplayRenderNode == nullptr || logicalDisplayRenderNode->GetScreenId() != screenId ||
254                 logicalDisplayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
255                 return;
256             }
257             logicalDisplayRenderNode->RemoveChild(surfaceRenderNode);
258         });
259 }
260 
SetBootAnimation(RSContext & context,NodeId nodeId,bool isBootAnimation)261 void SurfaceNodeCommandHelper::SetBootAnimation(RSContext& context, NodeId nodeId, bool isBootAnimation)
262 {
263     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
264         node->SetBootAnimation(isBootAnimation);
265     }
266 }
267 
SetGlobalPositionEnabled(RSContext & context,NodeId nodeId,bool isEnabled)268 void SurfaceNodeCommandHelper::SetGlobalPositionEnabled(RSContext& context, NodeId nodeId, bool isEnabled)
269 {
270     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
271         node->SetGlobalPositionEnabled(isEnabled);
272     }
273 }
274 
275 #ifdef USE_SURFACE_TEXTURE
CreateSurfaceExt(RSContext & context,NodeId id,const std::shared_ptr<RSSurfaceTexture> & surfaceExt)276 void SurfaceNodeCommandHelper::CreateSurfaceExt(RSContext& context, NodeId id,
277     const std::shared_ptr<RSSurfaceTexture>& surfaceExt)
278 {
279     auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id);
280     if (node != nullptr) {
281         node->SetSurfaceTexture(surfaceExt);
282     }
283 }
284 #endif
285 
SetForceHardwareAndFixRotation(RSContext & context,NodeId nodeId,bool flag)286 void SurfaceNodeCommandHelper::SetForceHardwareAndFixRotation(RSContext& context, NodeId nodeId, bool flag)
287 {
288     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
289         node->SetForceHardwareAndFixRotation(flag);
290     }
291 }
292 
SetForeground(RSContext & context,NodeId nodeId,bool isForeground)293 void SurfaceNodeCommandHelper::SetForeground(RSContext& context, NodeId nodeId, bool isForeground)
294 {
295     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
296         node->SetForeground(isForeground);
297     }
298 }
299 
SetSurfaceId(RSContext & context,NodeId nodeId,SurfaceId surfaceId)300 void SurfaceNodeCommandHelper::SetSurfaceId(RSContext& context, NodeId nodeId, SurfaceId surfaceId)
301 {
302     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
303         node->SetSurfaceId(surfaceId);
304     }
305 }
306 
SetClonedNodeInfo(RSContext & context,NodeId nodeId,NodeId cloneNodeId,bool needOffscreen)307 void SurfaceNodeCommandHelper::SetClonedNodeInfo(
308     RSContext& context, NodeId nodeId, NodeId cloneNodeId, bool needOffscreen)
309 {
310     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
311         node->SetClonedNodeInfo(cloneNodeId, needOffscreen);
312     }
313 }
314 
SetForceUIFirst(RSContext & context,NodeId nodeId,bool forceUIFirst)315 void SurfaceNodeCommandHelper::SetForceUIFirst(RSContext& context, NodeId nodeId, bool forceUIFirst)
316 {
317     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
318         node->SetForceUIFirst(forceUIFirst);
319     }
320 }
321 
SetAncoFlags(RSContext & context,NodeId nodeId,uint32_t flags)322 void SurfaceNodeCommandHelper::SetAncoFlags(RSContext& context, NodeId nodeId, uint32_t flags)
323 {
324     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
325         node->SetAncoFlags(flags);
326     }
327 }
328 
SetHDRPresent(RSContext & context,NodeId nodeId,bool hdrPresent)329 void SurfaceNodeCommandHelper::SetHDRPresent(RSContext& context, NodeId nodeId, bool hdrPresent)
330 {
331     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
332         node->SetHDRPresent(hdrPresent);
333     }
334 }
335 
SetSkipDraw(RSContext & context,NodeId nodeId,bool skip)336 void SurfaceNodeCommandHelper::SetSkipDraw(RSContext& context, NodeId nodeId, bool skip)
337 {
338     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
339         node->SetSkipDraw(skip);
340     }
341 }
342 
SetWatermarkEnabled(RSContext & context,NodeId nodeId,const std::string & name,bool isEnabled)343 void SurfaceNodeCommandHelper::SetWatermarkEnabled(RSContext& context, NodeId nodeId,
344     const std::string& name, bool isEnabled)
345 {
346     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
347         node->SetWatermarkEnabled(name, isEnabled);
348     }
349 }
350 
SetAbilityState(RSContext & context,NodeId nodeId,RSSurfaceNodeAbilityState abilityState)351 void SurfaceNodeCommandHelper::SetAbilityState(RSContext& context, NodeId nodeId,
352     RSSurfaceNodeAbilityState abilityState)
353 {
354     auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId);
355     if (!node) {
356         ROSEN_LOGE("SurfaceNodeCommandHelper::SetAbilityState node is null!");
357         return;
358     }
359     node->SetAbilityState(abilityState);
360 }
361 
SetApiCompatibleVersion(RSContext & context,NodeId nodeId,uint32_t apiCompatibleVersion)362 void SurfaceNodeCommandHelper::SetApiCompatibleVersion(RSContext& context, NodeId nodeId, uint32_t apiCompatibleVersion)
363 {
364     auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId);
365     if (!node) {
366         RS_LOGE("SurfaceNodeCommandHelper::SetApiCompatibleVersion node is null!");
367         return;
368     }
369     node->SetApiCompatibleVersion(apiCompatibleVersion);
370 }
371 
SetHardwareEnableHint(RSContext & context,NodeId nodeId,bool enable)372 void SurfaceNodeCommandHelper::SetHardwareEnableHint(RSContext& context, NodeId nodeId, bool enable)
373 {
374     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
375         node->SetHardwareEnableHint(enable);
376     }
377 }
378 
SetSourceVirtualDisplayId(RSContext & context,NodeId nodeId,ScreenId screenId)379 void SurfaceNodeCommandHelper::SetSourceVirtualDisplayId(RSContext& context, NodeId nodeId, ScreenId screenId)
380 {
381     if (auto surfaceRenderNode = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
382         const auto& nodeMap = context.GetNodeMap();
383         nodeMap.TraverseScreenNodes(
384             [surfaceRenderNode, screenId](const std::shared_ptr<RSScreenRenderNode>& screenRenderNode) {
385                 if (screenRenderNode != nullptr && screenRenderNode->GetScreenId() == screenId) {
386                     surfaceRenderNode->SetSourceDisplayRenderNodeId(screenRenderNode->GetId());
387                 }
388             }
389         );
390     }
391 }
392 
AttachToWindowContainer(RSContext & context,NodeId nodeId,ScreenId screenId)393 void SurfaceNodeCommandHelper::AttachToWindowContainer(RSContext& context, NodeId nodeId, ScreenId screenId)
394 {
395     const auto& nodeMap = context.GetNodeMap();
396     auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
397     if (surfaceRenderNode == nullptr) {
398         RS_LOGE("SurfaceNodeCommandHelper::AttachToWindowContainer Invalid surfaceRenderNode");
399         return;
400     }
401     nodeMap.TraverseLogicalDisplayNodes(
402         [surfaceRenderNode, screenId](const std::shared_ptr<RSLogicalDisplayRenderNode>& displayRenderNode) {
403             if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId ||
404                 displayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
405                 return;
406             }
407             auto windowContainer = displayRenderNode->GetWindowContainer();
408             if (windowContainer == nullptr || !windowContainer->IsOnTheTree()) {
409                 displayRenderNode->AddChild(surfaceRenderNode);
410                 RS_LOGD("SurfaceNodeCommandHelper::AttachToWindowContainer %{public}" PRIu64 " attach to %{public}"
411                     PRIu64, surfaceRenderNode->GetId(), displayRenderNode->GetId());
412             } else {
413                 windowContainer->AddChild(surfaceRenderNode);
414                 RS_LOGD("SurfaceNodeCommandHelper::AttachToWindowContainer %{public}" PRIu64 " attach to %{public}"
415                     PRIu64, surfaceRenderNode->GetId(), windowContainer->GetId());
416             }
417         }
418     );
419 }
420 
DetachFromWindowContainer(RSContext & context,NodeId nodeId,ScreenId screenId)421 void SurfaceNodeCommandHelper::DetachFromWindowContainer(RSContext& context, NodeId nodeId, ScreenId screenId)
422 {
423     const auto& nodeMap = context.GetNodeMap();
424     auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
425     if (surfaceRenderNode == nullptr) {
426         RS_LOGE("SurfaceNodeCommandHelper::DetachFromWindowContainer Invalid surfaceRenderNode");
427         return;
428     }
429     nodeMap.TraverseLogicalDisplayNodes(
430         [surfaceRenderNode, screenId](const std::shared_ptr<RSLogicalDisplayRenderNode>& displayRenderNode) {
431             if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId ||
432                 displayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
433                 return;
434             }
435             auto windowContainer = displayRenderNode->GetWindowContainer();
436             if (windowContainer == nullptr || !windowContainer->IsOnTheTree()) {
437                 displayRenderNode->RemoveChild(surfaceRenderNode);
438                 RS_LOGD("SurfaceNodeCommandHelper::DetachFromWindowContainer %{public}" PRIu64 " detach from %{public}"
439                     PRIu64, surfaceRenderNode->GetId(), displayRenderNode->GetId());
440             } else {
441                 windowContainer->RemoveChild(surfaceRenderNode);
442                 RS_LOGD("SurfaceNodeCommandHelper::DetachFromWindowContainer %{public}" PRIu64 " detach from %{public}"
443                     PRIu64, surfaceRenderNode->GetId(), windowContainer->GetId());
444             }
445         }
446     );
447 }
448 
SetRegionToBeMagnified(RSContext & context,NodeId id,const Vector4<int> & regionToBeMagnified)449 void SurfaceNodeCommandHelper::SetRegionToBeMagnified(
450     RSContext& context, NodeId id, const Vector4<int>& regionToBeMagnified)
451 {
452     if (auto surfaceRenderNode = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
453         surfaceRenderNode->SetRegionToBeMagnified(regionToBeMagnified);
454     }
455 }
456 
SetFrameGravityNewVersionEnabled(RSContext & context,NodeId nodeId,bool isEnabled)457 void SurfaceNodeCommandHelper::SetFrameGravityNewVersionEnabled(RSContext& context, NodeId nodeId, bool isEnabled)
458 {
459     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
460         node->SetFrameGravityNewVersionEnabled(isEnabled);
461     }
462 }
463 
SetAncoSrcCrop(RSContext & context,NodeId nodeId,const Rect & srcCrop)464 void SurfaceNodeCommandHelper::SetAncoSrcCrop(RSContext& context, NodeId nodeId, const Rect& srcCrop)
465 {
466     if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
467         node->SetAncoSrcCrop(srcCrop);
468     }
469 }
470 } // namespace Rosen
471 } // namespace OHOS
472