• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "ui/rs_surface_node.h"
18 
19 #include <algorithm>
20 #include <string>
21 
22 #include "command/rs_base_node_command.h"
23 #include "command/rs_node_command.h"
24 #include "command/rs_surface_node_command.h"
25 #include "ipc_callbacks/rs_rt_refresh_callback.h"
26 #include "pipeline/rs_node_map.h"
27 #include "pipeline/rs_render_thread.h"
28 #include "platform/common/rs_log.h"
29 #ifndef ROSEN_CROSS_PLATFORM
30 #include "platform/drawing/rs_surface_converter.h"
31 #endif
32 #ifdef RS_ENABLE_GPU
33 #include "render_context/render_context.h"
34 #endif
35 #include "transaction/rs_render_service_client.h"
36 #include "transaction/rs_transaction_proxy.h"
37 #include "feature/composite_layer/rs_composite_layer_utils.h"
38 #include "ui/rs_proxy_node.h"
39 #include "rs_trace.h"
40 #include "common/rs_optional_trace.h"
41 #include "rs_ui_context.h"
42 #include "transaction/rs_interfaces.h"
43 
44 #ifndef ROSEN_CROSS_PLATFORM
45 #include "surface_utils.h"
46 #endif
47 
48 #ifdef USE_VIDEO_PROCESSING_ENGINE
49 #include "display_engine/rs_vpe_manager.h"
50 #endif
51 
52 namespace OHOS {
53 namespace Rosen {
54 #ifdef ROSEN_OHOS
55 namespace {
56 constexpr uint32_t WATERMARK_NAME_LENGTH_LIMIT = 128;
57 }
58 #endif
Create(const RSSurfaceNodeConfig & surfaceNodeConfig,bool isWindow,std::shared_ptr<RSUIContext> rsUIContext)59 RSSurfaceNode::SharedPtr RSSurfaceNode::Create(
60     const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow, std::shared_ptr<RSUIContext> rsUIContext)
61 {
62     if (!isWindow) {
63         return Create(surfaceNodeConfig, RSSurfaceNodeType::SELF_DRAWING_NODE, isWindow, false, rsUIContext);
64     }
65     return Create(surfaceNodeConfig, RSSurfaceNodeType::DEFAULT, isWindow);
66 }
67 
Create(const RSSurfaceNodeConfig & surfaceNodeConfig,RSSurfaceNodeType type,bool isWindow,bool unobscured,std::shared_ptr<RSUIContext> rsUIContext)68 RSSurfaceNode::SharedPtr RSSurfaceNode::Create(const RSSurfaceNodeConfig& surfaceNodeConfig,
69     RSSurfaceNodeType type, bool isWindow, bool unobscured, std::shared_ptr<RSUIContext> rsUIContext)
70 {
71     SharedPtr node(new RSSurfaceNode(surfaceNodeConfig, isWindow, rsUIContext));
72     if (rsUIContext != nullptr) {
73         rsUIContext->GetMutableNodeMap().RegisterNode(node);
74     } else {
75         RSNodeMap::MutableInstance().RegisterNode(node);
76     }
77 
78     // create node in RS
79     RSSurfaceRenderNodeConfig config = {
80         .id = node->GetId(),
81         .name = node->name_,
82         .additionalData = surfaceNodeConfig.additionalData,
83         .isTextureExportNode = surfaceNodeConfig.isTextureExportNode,
84         .isSync = surfaceNodeConfig.isSync,
85         .surfaceWindowType = surfaceNodeConfig.surfaceWindowType,
86     };
87     config.nodeType = type;
88     node->surfaceNodeType_ = config.nodeType;
89 
90     RS_TRACE_NAME_FMT("RSSurfaceNode::Create name: %s type: %hhu, id: %lu, token:%lu", node->name_.c_str(),
91         config.nodeType, node->GetId(), rsUIContext ? rsUIContext->GetToken() : -1);
92     RS_LOGD("RSSurfaceNode::Create name:%{public}s type: %{public}hhu "
93         "isWindow %{public}d %{public}d ", config.name.c_str(),
94         config.nodeType, isWindow, node->IsRenderServiceNode());
95 
96     if (type == RSSurfaceNodeType::LEASH_WINDOW_NODE && node->IsUniRenderEnabled()) {
97         std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeCreateWithConfig>(
98             config.id, config.name, static_cast<uint8_t>(config.nodeType), config.surfaceWindowType);
99         node->AddCommand(command, isWindow);
100     } else {
101 #ifndef SCREENLESS_DEVICE
102         if (!node->CreateNodeAndSurface(config, surfaceNodeConfig.surfaceId, unobscured)) {
103             ROSEN_LOGE("RSSurfaceNode::Create, create node and surface failed");
104             return nullptr;
105         }
106 #endif
107     }
108 
109     node->SetClipToFrame(true);
110     // create node in RT (only when in divided render and isRenderServiceNode_ == false)
111     // create node in RT if is TextureExport node
112     if (!node->IsRenderServiceNode()) {
113         std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeCreate>(node->GetId(),
114             config.nodeType, surfaceNodeConfig.isTextureExportNode);
115         if (surfaceNodeConfig.isTextureExportNode) {
116             node->AddCommand(command, false);
117             node->SetSurfaceIdToRenderNode();
118         } else {
119             node->AddCommand(command, isWindow);
120         }
121         command = std::make_unique<RSSurfaceNodeConnectToNodeInRenderService>(node->GetId());
122         node->AddCommand(command, isWindow);
123 
124         RSRTRefreshCallback::Instance().SetRefresh([] { RSRenderThread::Instance().RequestNextVSync(); });
125         command = std::make_unique<RSSurfaceNodeSetCallbackForRenderThreadRefresh>(node->GetId(), true);
126         node->AddCommand(command, isWindow);
127         node->SetFrameGravity(Gravity::RESIZE);
128         // codes for arkui-x
129 #if defined(USE_SURFACE_TEXTURE) && defined(ROSEN_ANDROID) && !defined(SCREENLESS_DEVICE)
130         if (type == RSSurfaceNodeType::SURFACE_TEXTURE_NODE) {
131             RSSurfaceExtConfig config = {
132                 .type = RSSurfaceExtType::SURFACE_TEXTURE,
133                 .additionalData = nullptr,
134             };
135             node->CreateSurfaceExt(config);
136         }
137 #endif
138         // codes for arkui-x
139 #if defined(USE_SURFACE_TEXTURE) && defined(ROSEN_IOS) && !defined(SCREENLESS_DEVICE)
140         if ((type == RSSurfaceNodeType::SURFACE_TEXTURE_NODE) &&
141             (surfaceNodeConfig.SurfaceNodeName == "PlatformViewSurface")) {
142             RSSurfaceExtConfig config = {
143                 .type = RSSurfaceExtType::SURFACE_PLATFORM_TEXTURE,
144                 .additionalData = nullptr,
145             };
146             node->CreateSurfaceExt(config);
147         }
148 #endif
149     }
150 
151     if (node->GetName().find("battery_panel") != std::string::npos ||
152         node->GetName().find("sound_panel") != std::string::npos ||
153         node->GetName().find("RosenWeb") != std::string::npos) {
154         node->SetFrameGravity(Gravity::TOP_LEFT);
155     } else if (!isWindow) {
156         node->SetFrameGravity(Gravity::RESIZE);
157     }
158     ROSEN_LOGD("RsDebug RSSurfaceNode::Create id:%{public}" PRIu64, node->GetId());
159     node->SetUIContextToken();
160     return node;
161 }
162 
CreateNodeInRenderThread()163 void RSSurfaceNode::CreateNodeInRenderThread()
164 {
165     if (!IsRenderServiceNode()) {
166         ROSEN_LOGI(
167             "RsDebug RSSurfaceNode::CreateNodeInRenderThread id:%{public}" PRIu64 " already has RT Node", GetId());
168         return;
169     }
170 
171     isChildOperationDisallowed_ = true;
172     isRenderServiceNode_ = false;
173     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetSurfaceNodeType>(
174         GetId(), static_cast<uint8_t>(RSSurfaceNodeType::ABILITY_COMPONENT_NODE));
175     AddCommand(command, true);
176 
177     // create node in RT (only when in divided render and isRenderServiceNode_ == false)
178     if (!IsRenderServiceNode()) {
179         command = std::make_unique<RSSurfaceNodeCreate>(GetId(), RSSurfaceNodeType::ABILITY_COMPONENT_NODE, false);
180         AddCommand(command, false);
181 
182         command = std::make_unique<RSSurfaceNodeConnectToNodeInRenderService>(GetId());
183         AddCommand(command, false);
184 
185         RSRTRefreshCallback::Instance().SetRefresh([] { RSRenderThread::Instance().RequestNextVSync(); });
186         command = std::make_unique<RSSurfaceNodeSetCallbackForRenderThreadRefresh>(GetId(), true);
187         AddCommand(command, false);
188     }
189 }
190 
AddChild(std::shared_ptr<RSBaseNode> child,int index)191 void RSSurfaceNode::AddChild(std::shared_ptr<RSBaseNode> child, int index)
192 {
193     if (isChildOperationDisallowed_) {
194         ROSEN_LOGE("RSSurfaceNode::AddChild for non RenderServiceNodeType surfaceNode is not allowed");
195         return;
196     }
197     RSBaseNode::AddChild(child, index);
198 }
199 
RemoveChild(std::shared_ptr<RSBaseNode> child)200 void RSSurfaceNode::RemoveChild(std::shared_ptr<RSBaseNode> child)
201 {
202     if (isChildOperationDisallowed_) {
203         ROSEN_LOGE("RSSurfaceNode::RemoveChild for non RenderServiceNodeType surfaceNode is not allowed");
204         return;
205     }
206     RSBaseNode::RemoveChild(child);
207 }
208 
ClearChildren()209 void RSSurfaceNode::ClearChildren()
210 {
211     if (isChildOperationDisallowed_) {
212         ROSEN_LOGE("RSSurfaceNode::ClearChildren for non RenderServiceNodeType surfaceNode is not allowed");
213         return;
214     }
215     RSBaseNode::ClearChildren();
216 }
217 
GetFollowType() const218 FollowType RSSurfaceNode::GetFollowType() const
219 {
220     if (IsRenderServiceNode()) {
221         return FollowType::NONE;
222     } else {
223         return FollowType::FOLLOW_TO_PARENT;
224     }
225 }
226 
MarkUIHidden(bool isHidden)227 void RSSurfaceNode::MarkUIHidden(bool isHidden)
228 {
229     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeMarkUIHidden>(GetId(), isHidden);
230     auto transaction = GetRSTransaction();
231     if (transaction != nullptr) {
232         transaction->AddCommand(command, IsRenderServiceNode());
233         if (!isTextureExportNode_) {
234             transaction->FlushImplicitTransaction();
235         }
236     } else {
237         auto transactionProxy = RSTransactionProxy::GetInstance();
238         if (transactionProxy != nullptr) {
239             transactionProxy->AddCommand(command, IsRenderServiceNode());
240             if (!isTextureExportNode_) {
241                 transactionProxy->FlushImplicitTransaction();
242             }
243         }
244     }
245 }
246 
OnBoundsSizeChanged() const247 void RSSurfaceNode::OnBoundsSizeChanged() const
248 {
249     auto bounds = GetStagingProperties().GetBounds();
250     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeUpdateSurfaceDefaultSize>(
251         GetId(), bounds.z_, bounds.w_);
252     AddCommand(command, true);
253 #ifdef ROSEN_CROSS_PLATFORM
254     if (!IsRenderServiceNode()) {
255         std::unique_ptr<RSCommand> commandRt = std::make_unique<RSSurfaceNodeUpdateSurfaceDefaultSize>(
256             GetId(), bounds.z_, bounds.w_);
257         AddCommand(commandRt, false);
258     }
259 #endif
260     std::lock_guard<std::mutex> lock(mutex_);
261     if (boundsChangedCallback_) {
262         boundsChangedCallback_(bounds);
263         RS_TRACE_NAME_FMT("node:[name: %s, id: %" PRIu64 ", bounds:%f %f %f %f] already callback",
264             GetName().c_str(), GetId(), bounds.x_, bounds.y_, bounds.z_, bounds.w_);
265     }
266 }
267 
SetLeashPersistentId(LeashPersistentId leashPersistentId)268 void RSSurfaceNode::SetLeashPersistentId(LeashPersistentId leashPersistentId)
269 {
270     leashPersistentId_ = leashPersistentId;
271     std::unique_ptr<RSCommand> command =
272         std::make_unique<RSurfaceNodeSetLeashPersistentId>(GetId(), leashPersistentId);
273     AddCommand(command, true);
274     ROSEN_LOGD("RSSurfaceNode::SetLeashPersistentId, \
275         surfaceNodeId:[%{public}" PRIu64 "] leashPersistentId:[%{public}" PRIu64 "]", GetId(), leashPersistentId);
276 }
277 
GetLeashPersistentId() const278 LeashPersistentId RSSurfaceNode::GetLeashPersistentId() const
279 {
280     return leashPersistentId_;
281 }
282 
SetSecurityLayer(bool isSecurityLayer)283 void RSSurfaceNode::SetSecurityLayer(bool isSecurityLayer)
284 {
285     isSecurityLayer_ = isSecurityLayer;
286     std::unique_ptr<RSCommand> command =
287         std::make_unique<RSSurfaceNodeSetSecurityLayer>(GetId(), isSecurityLayer);
288     AddCommand(command, true);
289     ROSEN_LOGI("RSSurfaceNode::SetSecurityLayer, surfaceNodeId:[%{public}" PRIu64 "] isSecurityLayer:%{public}s",
290         GetId(), isSecurityLayer ? "true" : "false");
291 }
292 
GetSecurityLayer() const293 bool RSSurfaceNode::GetSecurityLayer() const
294 {
295     return isSecurityLayer_;
296 }
297 
SetSkipLayer(bool isSkipLayer)298 void RSSurfaceNode::SetSkipLayer(bool isSkipLayer)
299 {
300     isSkipLayer_ = isSkipLayer;
301     std::unique_ptr<RSCommand> command =
302         std::make_unique<RSSurfaceNodeSetSkipLayer>(GetId(), isSkipLayer);
303     AddCommand(command, true);
304     ROSEN_LOGD("RSSurfaceNode::SetSkipLayer, surfaceNodeId:[%" PRIu64 "] isSkipLayer:%s", GetId(),
305         isSkipLayer ? "true" : "false");
306 }
307 
GetSkipLayer() const308 bool RSSurfaceNode::GetSkipLayer() const
309 {
310     return isSkipLayer_;
311 }
312 
SetSnapshotSkipLayer(bool isSnapshotSkipLayer)313 void RSSurfaceNode::SetSnapshotSkipLayer(bool isSnapshotSkipLayer)
314 {
315     isSnapshotSkipLayer_ = isSnapshotSkipLayer;
316     std::unique_ptr<RSCommand> command =
317         std::make_unique<RSSurfaceNodeSetSnapshotSkipLayer>(GetId(), isSnapshotSkipLayer);
318     AddCommand(command, true);
319     ROSEN_LOGD("RSSurfaceNode::SetSnapshotSkipLayer, surfaceNodeId:[%" PRIu64 "] isSnapshotSkipLayer:%s", GetId(),
320         isSnapshotSkipLayer ? "true" : "false");
321 }
322 
GetSnapshotSkipLayer() const323 bool RSSurfaceNode::GetSnapshotSkipLayer() const
324 {
325     return isSnapshotSkipLayer_;
326 }
327 
SetFingerprint(bool hasFingerprint)328 void RSSurfaceNode::SetFingerprint(bool hasFingerprint)
329 {
330     hasFingerprint_ = hasFingerprint;
331     std::unique_ptr<RSCommand> command =
332         std::make_unique<RSSurfaceNodeSetFingerprint>(GetId(), hasFingerprint);
333     AddCommand(command, true);
334     ROSEN_LOGD("RSSurfaceNode::SetFingerprint, surfaceNodeId:[%{public}" PRIu64 "] hasFingerprint:%{public}s", GetId(),
335         hasFingerprint ? "true" : "false");
336 }
337 
GetFingerprint() const338 bool RSSurfaceNode::GetFingerprint() const
339 {
340     return hasFingerprint_;
341 }
342 
SetColorSpace(GraphicColorGamut colorSpace)343 void RSSurfaceNode::SetColorSpace(GraphicColorGamut colorSpace)
344 {
345     colorSpace_ = colorSpace;
346     std::unique_ptr<RSCommand> command =
347         std::make_unique<RSSurfaceNodeSetColorSpace>(GetId(), colorSpace);
348     AddCommand(command, true);
349 }
350 
CreateRenderNodeForTextureExportSwitch()351 void RSSurfaceNode::CreateRenderNodeForTextureExportSwitch()
352 {
353     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeCreate>(GetId(),
354         RSSurfaceNodeType::SELF_DRAWING_NODE, isTextureExportNode_);
355     AddCommand(command, IsRenderServiceNode());
356     if (!IsRenderServiceNode()) {
357         hasCreateRenderNodeInRT_ = true;
358         command = std::make_unique<RSSurfaceNodeConnectToNodeInRenderService>(GetId());
359         AddCommand(command, false);
360 
361         RSRTRefreshCallback::Instance().SetRefresh([] { RSRenderThread::Instance().RequestNextVSync(); });
362         command = std::make_unique<RSSurfaceNodeSetCallbackForRenderThreadRefresh>(GetId(), true);
363         AddCommand(command, false);
364     } else {
365         hasCreateRenderNodeInRS_ = true;
366     }
367 }
368 
SetIsTextureExportNode(bool isTextureExportNode)369 void RSSurfaceNode::SetIsTextureExportNode(bool isTextureExportNode)
370 {
371     std::unique_ptr<RSCommand> command =
372         std::make_unique<RSSurfaceNodeSetIsTextureExportNode>(GetId(), isTextureExportNode);
373     AddCommand(command, false);
374     // need to reset isTextureExport sign in renderService
375     command = std::make_unique<RSSurfaceNodeSetIsTextureExportNode>(GetId(), isTextureExportNode);
376     AddCommand(command, true);
377 }
378 
SetTextureExport(bool isTextureExportNode)379 void RSSurfaceNode::SetTextureExport(bool isTextureExportNode)
380 {
381     if (isTextureExportNode == isTextureExportNode_) {
382         return;
383     }
384     isTextureExportNode_ = isTextureExportNode;
385     if (!IsUniRenderEnabled()) {
386         return;
387     }
388     if (!isTextureExportNode_) {
389         SetIsTextureExportNode(isTextureExportNode);
390         DoFlushModifier();
391         return;
392     }
393     CreateRenderNodeForTextureExportSwitch();
394     SetIsTextureExportNode(isTextureExportNode);
395     SetSurfaceIdToRenderNode();
396     DoFlushModifier();
397 }
398 
SetAbilityBGAlpha(uint8_t alpha)399 void RSSurfaceNode::SetAbilityBGAlpha(uint8_t alpha)
400 {
401     std::unique_ptr<RSCommand> command =
402         std::make_unique<RSSurfaceNodeSetAbilityBGAlpha>(GetId(), alpha);
403     AddCommand(command, true);
404 }
405 
SetIsNotifyUIBufferAvailable(bool available)406 void RSSurfaceNode::SetIsNotifyUIBufferAvailable(bool available)
407 {
408     std::unique_ptr<RSCommand> command =
409         std::make_unique<RSSurfaceNodeSetIsNotifyUIBufferAvailable>(GetId(), available);
410     AddCommand(command, true);
411 }
412 
SetBufferAvailableCallback(BufferAvailableCallback callback)413 bool RSSurfaceNode::SetBufferAvailableCallback(BufferAvailableCallback callback)
414 {
415     {
416         std::lock_guard<std::mutex> lock(mutex_);
417         callback_ = callback;
418     }
419     auto renderServiceClient =
420         std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
421     if (renderServiceClient == nullptr) {
422         return false;
423     }
424     return renderServiceClient->RegisterBufferAvailableListener(GetId(), [weakThis = weak_from_this()]() {
425         auto rsSurfaceNode = RSBaseNode::ReinterpretCast<RSSurfaceNode>(weakThis.lock());
426         if (rsSurfaceNode == nullptr) {
427             ROSEN_LOGE("RSSurfaceNode::SetBufferAvailableCallback this == null");
428             return;
429         }
430         BufferAvailableCallback actualCallback;
431         {
432             std::lock_guard<std::mutex> lock(rsSurfaceNode->mutex_);
433             actualCallback = rsSurfaceNode->callback_;
434         }
435         rsSurfaceNode->bufferAvailable_ = true;
436         if (actualCallback) {
437             actualCallback();
438         }
439     });
440 }
441 
IsBufferAvailable() const442 bool RSSurfaceNode::IsBufferAvailable() const
443 {
444     return bufferAvailable_;
445 }
446 
SetBoundsChangedCallback(BoundsChangedCallback callback)447 void RSSurfaceNode::SetBoundsChangedCallback(BoundsChangedCallback callback)
448 {
449     std::lock_guard<std::mutex> lock(mutex_);
450     boundsChangedCallback_ = callback;
451 }
452 
SetAnimationFinished()453 void RSSurfaceNode::SetAnimationFinished()
454 {
455     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetAnimationFinished>(GetId());
456     auto transaction = GetRSTransaction();
457     if (transaction != nullptr) {
458         transaction->AddCommand(command, true);
459         transaction->FlushImplicitTransaction();
460     } else {
461         auto transactionProxy = RSTransactionProxy::GetInstance();
462         if (transactionProxy != nullptr) {
463             transactionProxy->AddCommand(command, true);
464             transactionProxy->FlushImplicitTransaction();
465         }
466     }
467 }
468 
Marshalling(Parcel & parcel) const469 bool RSSurfaceNode::Marshalling(Parcel& parcel) const
470 {
471     bool flag = parcel.WriteUint64(GetId()) && parcel.WriteString(name_) && parcel.WriteBool(IsRenderServiceNode());
472     if (!flag) {
473         ROSEN_LOGE("RSSurfaceNode::Marshalling failed");
474     }
475     return flag;
476 }
477 
Unmarshalling(Parcel & parcel)478 std::shared_ptr<RSSurfaceNode> RSSurfaceNode::Unmarshalling(Parcel& parcel)
479 {
480     uint64_t id = UINT64_MAX;
481     std::string name;
482     bool isRenderServiceNode = false;
483     if (!(parcel.ReadUint64(id) && parcel.ReadString(name) && parcel.ReadBool(isRenderServiceNode))) {
484         ROSEN_LOGE("RSSurfaceNode::Unmarshalling, read param failed");
485         return nullptr;
486     }
487     RSSurfaceNodeConfig config = { name };
488     RS_LOGI("RSSurfaceNode::Unmarshalling, Node: %{public}" PRIu64 ", Name: %{public}s", id, name.c_str());
489 
490     if (auto prevNode = RSNodeMap::Instance().GetNode(id)) { // Planning
491         RS_LOGD("RSSurfaceNode::Unmarshalling, the node id is already in the map");
492         // if the node id is already in the map, we should not create a new node
493         return prevNode->ReinterpretCastTo<RSSurfaceNode>();
494     }
495 
496     SharedPtr surfaceNode(new RSSurfaceNode(config, isRenderServiceNode, id));
497     RSNodeMap::MutableInstance().RegisterNode(surfaceNode);
498 
499     // for nodes constructed by unmarshalling, we should not destroy the corresponding render node on destruction
500     surfaceNode->skipDestroyCommandInDestructor_ = true;
501 
502     return surfaceNode;
503 }
504 
SetSurfaceIdToRenderNode()505 void RSSurfaceNode::SetSurfaceIdToRenderNode()
506 {
507 #ifndef ROSEN_CROSS_PLATFORM
508     auto surface = GetSurface();
509     if (surface) {
510         std::unique_ptr<RSCommand> command = std::make_unique<RSurfaceNodeSetSurfaceId>(GetId(),
511             surface->GetUniqueId());
512         AddCommand(command, false);
513     }
514 #endif
515 }
516 
UnmarshallingAsProxyNode(Parcel & parcel)517 RSNode::SharedPtr RSSurfaceNode::UnmarshallingAsProxyNode(Parcel& parcel)
518 {
519     uint64_t id = UINT64_MAX;
520     std::string name;
521     bool isRenderServiceNode = false;
522     if (!(parcel.ReadUint64(id) && parcel.ReadString(name) && parcel.ReadBool(isRenderServiceNode))) {
523         ROSEN_LOGE("RSSurfaceNode::Unmarshalling, read param failed");
524         return nullptr;
525     }
526 
527     // Create RSProxyNode by unmarshalling RSSurfaceNode, return existing node if it exists in RSNodeMap.
528     return RSProxyNode::Create(id, name);
529 }
530 
CreateNode(const RSSurfaceRenderNodeConfig & config)531 bool RSSurfaceNode::CreateNode(const RSSurfaceRenderNodeConfig& config)
532 {
533     return std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient())->
534         CreateNode(config);
535 }
536 
CreateNodeAndSurface(const RSSurfaceRenderNodeConfig & config,SurfaceId surfaceId,bool unobscured)537 bool RSSurfaceNode::CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, SurfaceId surfaceId, bool unobscured)
538 {
539     if (surfaceId == 0) {
540         surface_ = std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient())->
541         CreateNodeAndSurface(config, unobscured);
542     } else {
543 #ifndef ROSEN_CROSS_PLATFORM
544         sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(surfaceId);
545         if (surface == nullptr) {
546             ROSEN_LOGE("RSSurfaceNode::CreateNodeAndSurface nodeId is %{public}" PRIu64
547                        " cannot find surface by surfaceId %{public}" PRIu64 "",
548                 GetId(), surfaceId);
549             return false;
550         }
551         surface_ = std::static_pointer_cast<RSRenderServiceClient>(
552             RSIRenderClient::CreateRenderServiceClient())->CreateRSSurface(surface);
553         if (surface_ == nullptr) {
554             ROSEN_LOGE(
555                 "RSSurfaceNode::CreateNodeAndSurface nodeId is %{public}" PRIu64 " creat RSSurface fail", GetId());
556             return false;
557         }
558 #endif
559     }
560     return (surface_ != nullptr);
561 }
562 
563 #ifndef ROSEN_CROSS_PLATFORM
GetSurface() const564 sptr<OHOS::Surface> RSSurfaceNode::GetSurface() const
565 {
566     if (surface_ == nullptr) {
567         ROSEN_LOGE("RSSurfaceNode::GetSurface, surface_ is nullptr");
568         return nullptr;
569     }
570     auto ohosSurface = RSSurfaceConverter::ConvertToOhosSurface(surface_);
571     return ohosSurface;
572 }
573 #endif
574 
NeedForcedSendToRemote() const575 bool RSSurfaceNode::NeedForcedSendToRemote() const
576 {
577     if (IsRenderServiceNode()) {
578         // Property message should be sent to RenderService.
579         return false;
580     } else {
581         // Only when in divided render and isRenderServiceNode_ == false
582         // property message should be sent to RenderService & RenderThread.
583         return true;
584     }
585 }
586 
ResetContextAlpha() const587 void RSSurfaceNode::ResetContextAlpha() const
588 {
589     // temporarily fix: manually set contextAlpha in RT and RS to 0.0f, to avoid residual alpha/context matrix from
590     // previous animation. this value will be overwritten in RenderThreadVisitor::ProcessSurfaceRenderNode.
591     std::unique_ptr<RSCommand> commandRS = std::make_unique<RSSurfaceNodeSetContextAlpha>(GetId(), 0.0f);
592     AddCommand(commandRS, true);
593 }
594 
SetContainerWindow(bool hasContainerWindow,RRect rrect)595 void RSSurfaceNode::SetContainerWindow(bool hasContainerWindow, RRect rrect)
596 {
597     std::unique_ptr<RSCommand> command =
598         std::make_unique<RSSurfaceNodeSetContainerWindow>(GetId(), hasContainerWindow, rrect);
599     AddCommand(command, true);
600 }
601 
SetWindowId(uint32_t windowId)602 void RSSurfaceNode::SetWindowId(uint32_t windowId)
603 {
604     windowId_ = windowId;
605 }
606 
SetFreeze(bool isFreeze)607 void RSSurfaceNode::SetFreeze(bool isFreeze)
608 {
609     if (!IsUniRenderEnabled()) {
610         ROSEN_LOGE("SetFreeze is not supported in separate render");
611         return;
612     }
613     RS_OPTIONAL_TRACE_NAME_FMT("RSSurfaceNode::SetFreeze id:%llu", GetId());
614     std::unique_ptr<RSCommand> command = std::make_unique<RSSetFreeze>(GetId(), isFreeze);
615     AddCommand(command, true);
616 }
617 
SplitSurfaceNodeName(std::string surfaceNodeName)618 std::pair<std::string, std::string> RSSurfaceNode::SplitSurfaceNodeName(std::string surfaceNodeName)
619 {
620     if (auto position = surfaceNodeName.find("#");  position != std::string::npos) {
621         return std::make_pair(surfaceNodeName.substr(0, position), surfaceNodeName.substr(position + 1));
622     }
623     return std::make_pair("", surfaceNodeName);
624 }
625 
RSSurfaceNode(const RSSurfaceNodeConfig & config,bool isRenderServiceNode,std::shared_ptr<RSUIContext> rsUIContext)626 RSSurfaceNode::RSSurfaceNode(
627     const RSSurfaceNodeConfig& config, bool isRenderServiceNode, std::shared_ptr<RSUIContext> rsUIContext)
628     : RSNode(isRenderServiceNode, config.isTextureExportNode, rsUIContext, true), name_(config.SurfaceNodeName)
629 {}
630 
RSSurfaceNode(const RSSurfaceNodeConfig & config,bool isRenderServiceNode,NodeId id,std::shared_ptr<RSUIContext> rsUIContext)631 RSSurfaceNode::RSSurfaceNode(
632     const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id, std::shared_ptr<RSUIContext> rsUIContext)
633     : RSNode(isRenderServiceNode, id, config.isTextureExportNode, rsUIContext, true), name_(config.SurfaceNodeName)
634 {}
635 
~RSSurfaceNode()636 RSSurfaceNode::~RSSurfaceNode()
637 {
638     RS_LOGI("RSSurfaceNode::~RSSurfaceNode, Node: %{public}" PRIu64 ", Name: %{public}s", GetId(), GetName().c_str());
639     // both divided and unirender need to unregister listener when surfaceNode destroy
640     auto renderServiceClient =
641         std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
642     if (renderServiceClient != nullptr) {
643         renderServiceClient->UnregisterBufferAvailableListener(GetId());
644 #ifdef USE_VIDEO_PROCESSING_ENGINE
645         RSVpeManager::GetInstance().ReleaseVpeVideo(GetId());
646 #endif
647     }
648 
649     // For abilityComponent and remote window, we should destroy the corresponding render node in RenderThread
650     // The destructor of render node in RenderService should controlled by application
651     // Command sent only in divided render
652     if (skipDestroyCommandInDestructor_ && !IsUniRenderEnabled()) {
653         std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(GetId());
654         AddCommand(command, false, FollowType::FOLLOW_TO_PARENT, GetId());
655         return;
656     }
657 
658     // For self-drawing surfaceNode, we should destroy the corresponding render node in RenderService
659     // Command sent only in divided render
660     if (!IsRenderServiceNode()) {
661         std::unique_ptr<RSCommand> command = std::make_unique<RSBaseNodeDestroy>(GetId());
662         AddCommand(command, false, FollowType::FOLLOW_TO_PARENT, GetId());
663         return;
664     }
665 }
666 
AttachToDisplay(uint64_t screenId)667 void RSSurfaceNode::AttachToDisplay(uint64_t screenId)
668 {
669     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeAttachToDisplay>(GetId(), screenId);
670     if (AddCommand(command, IsRenderServiceNode())) {
671         RS_LOGI("RSSurfaceNode:attach to display, node:[name: %{public}s, id: %{public}" PRIu64 "], "
672             "screen id: %{public}" PRIu64, GetName().c_str(), GetId(), screenId);
673         RS_TRACE_NAME_FMT("RSSurfaceNode:attach to display, node:[name: %s, id: %" PRIu64 "], "
674             "screen id: %" PRIu64, GetName().c_str(), GetId(), screenId);
675     }
676 }
677 
DetachToDisplay(uint64_t screenId)678 void RSSurfaceNode::DetachToDisplay(uint64_t screenId)
679 {
680     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeDetachToDisplay>(GetId(), screenId);
681     if (AddCommand(command, IsRenderServiceNode())) {
682         RS_LOGI("RSSurfaceNode:detach from display, node:[name: %{public}s, id: %{public}" PRIu64 "], "
683                 "screen id: %{public}" PRIu64,
684             GetName().c_str(), GetId(), screenId);
685         RS_TRACE_NAME_FMT("RSSurfaceNode:detach from display, node:[name: %s, id: %" PRIu64 "], "
686                           "screen id: %" PRIu64,
687             GetName().c_str(), GetId(), screenId);
688     }
689 }
690 
SetHardwareEnabled(bool isEnabled,SelfDrawingNodeType selfDrawingType,bool dynamicHardwareEnable)691 void RSSurfaceNode::SetHardwareEnabled(bool isEnabled, SelfDrawingNodeType selfDrawingType, bool dynamicHardwareEnable)
692 {
693     auto renderServiceClient =
694         std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
695     if (renderServiceClient != nullptr) {
696         renderServiceClient->SetHardwareEnabled(GetId(), isEnabled, selfDrawingType, dynamicHardwareEnable);
697     }
698 }
699 
SetForceHardwareAndFixRotation(bool flag)700 void RSSurfaceNode::SetForceHardwareAndFixRotation(bool flag)
701 {
702     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetHardwareAndFixRotation>(GetId(), flag);
703     AddCommand(command, true);
704 }
705 
SetBootAnimation(bool isBootAnimation)706 void RSSurfaceNode::SetBootAnimation(bool isBootAnimation)
707 {
708     isBootAnimation_ = isBootAnimation;
709     std::unique_ptr<RSCommand> command =
710         std::make_unique<RSSurfaceNodeSetBootAnimation>(GetId(), isBootAnimation);
711     AddCommand(command, true);
712     ROSEN_LOGD("RSSurfaceNode::SetBootAnimation, surfaceNodeId:[%" PRIu64 "] isBootAnimation:%s",
713         GetId(), isBootAnimation ? "true" : "false");
714 }
715 
GetBootAnimation() const716 bool RSSurfaceNode::GetBootAnimation() const
717 {
718     return isBootAnimation_;
719 }
720 
SetGlobalPositionEnabled(bool isEnabled)721 void RSSurfaceNode::SetGlobalPositionEnabled(bool isEnabled)
722 {
723     if (isGlobalPositionEnabled_ == isEnabled) {
724         return;
725     }
726 
727     isGlobalPositionEnabled_ = isEnabled;
728     std::unique_ptr<RSCommand> command =
729         std::make_unique<RSSurfaceNodeSetGlobalPositionEnabled>(GetId(), isEnabled);
730     AddCommand(command, true);
731     ROSEN_LOGI("RSSurfaceNode::SetGlobalPositionEnabled, surfaceNodeId:[%{public}" PRIu64 "] isEnabled:%{public}s",
732         GetId(), isEnabled ? "true" : "false");
733 }
734 
GetGlobalPositionEnabled() const735 bool RSSurfaceNode::GetGlobalPositionEnabled() const
736 {
737     return isGlobalPositionEnabled_;
738 }
739 
740 #ifdef USE_SURFACE_TEXTURE
CreateSurfaceExt(const RSSurfaceExtConfig & config)741 void RSSurfaceNode::CreateSurfaceExt(const RSSurfaceExtConfig& config)
742 {
743     auto texture = surface_->GetSurfaceExt(config);
744     if (texture == nullptr) {
745         texture = surface_->CreateSurfaceExt(config);
746     }
747     if (texture == nullptr) {
748         ROSEN_LOGE("RSSurfaceNode::CreateSurfaceExt failed %{public}" PRIu64 " type %{public}u",
749         GetId(), config.type);
750         return;
751     }
752 #ifdef ROSEN_IOS
753     if (texture->GetSurfaceExtConfig().additionalData == nullptr) {
754         texture->UpdateSurfaceExtConfig(config);
755     }
756 #endif
757     ROSEN_LOGD("RSSurfaceNode::CreateSurfaceExt %{public}" PRIu64 " type %{public}u", GetId(), config.type);
758     std::unique_ptr<RSCommand> command =
759         std::make_unique<RSSurfaceNodeCreateSurfaceExt>(GetId(), texture);
760     AddCommand(command, false);
761 }
762 
SetSurfaceTexture(const RSSurfaceExtConfig & config)763 void RSSurfaceNode::SetSurfaceTexture(const RSSurfaceExtConfig& config)
764 {
765     CreateSurfaceExt(config);
766 }
767 
MarkUiFrameAvailable(bool available)768 void RSSurfaceNode::MarkUiFrameAvailable(bool available)
769 {
770     std::unique_ptr<RSCommand> command =
771         std::make_unique<RSSurfaceNodeSetIsNotifyUIBufferAvailable>(GetId(), available);
772     auto transaction = GetRSTransaction();
773     if (transaction != nullptr) {
774         transaction->AddCommand(command, false);
775         transaction->FlushImplicitTransaction();
776     } else {
777         auto transactionProxy = RSTransactionProxy::GetInstance();
778         if (transactionProxy != nullptr) {
779             transactionProxy->AddCommand(command, false);
780             transactionProxy->FlushImplicitTransaction();
781         }
782     }
783 }
784 
SetSurfaceTextureAttachCallBack(const RSSurfaceTextureAttachCallBack & attachCallback)785 void RSSurfaceNode::SetSurfaceTextureAttachCallBack(const RSSurfaceTextureAttachCallBack& attachCallback)
786 {
787 #if defined(ROSEN_IOS)
788     RSSurfaceTextureConfig config = {
789         .type = RSSurfaceExtType::SURFACE_PLATFORM_TEXTURE,
790     };
791     auto texture = surface_->GetSurfaceExt(config);
792     if (texture) {
793         texture->SetAttachCallback(attachCallback);
794     }
795 #else
796     RSSurfaceTextureConfig config = {
797         .type = RSSurfaceExtType::SURFACE_TEXTURE,
798     };
799     auto texture = surface_->GetSurfaceExt(config);
800     if (texture) {
801         texture->SetAttachCallback(attachCallback);
802     }
803 #endif // ROSEN_IOS
804 }
805 
SetSurfaceTextureUpdateCallBack(const RSSurfaceTextureUpdateCallBack & updateCallback)806 void RSSurfaceNode::SetSurfaceTextureUpdateCallBack(const RSSurfaceTextureUpdateCallBack& updateCallback)
807 {
808 #if defined(ROSEN_IOS)
809     RSSurfaceTextureConfig config = {
810         .type = RSSurfaceExtType::SURFACE_PLATFORM_TEXTURE,
811     };
812     auto texture = surface_->GetSurfaceExt(config);
813     if (texture) {
814         texture->SetUpdateCallback(updateCallback);
815     }
816 #else
817     RSSurfaceTextureConfig config = {
818         .type = RSSurfaceExtType::SURFACE_TEXTURE,
819         .additionalData = nullptr
820     };
821     auto texture = surface_->GetSurfaceExt(config);
822     if (texture) {
823         texture->SetUpdateCallback(updateCallback);
824     }
825 #endif // ROSEN_IOS
826 }
827 
SetSurfaceTextureInitTypeCallBack(const RSSurfaceTextureInitTypeCallBack & initTypeCallback)828 void RSSurfaceNode::SetSurfaceTextureInitTypeCallBack(const RSSurfaceTextureInitTypeCallBack& initTypeCallback)
829 {
830 #if defined(ROSEN_IOS)
831     RSSurfaceTextureConfig config = {
832         .type = RSSurfaceExtType::SURFACE_PLATFORM_TEXTURE,
833     };
834     auto texture = surface_->GetSurfaceExt(config);
835     if (texture) {
836         texture->SetInitTypeCallback(initTypeCallback);
837     }
838 #endif // ROSEN_IOS
839 }
840 #endif
841 
SetForeground(bool isForeground)842 void RSSurfaceNode::SetForeground(bool isForeground)
843 {
844     ROSEN_LOGD("RSSurfaceNode::SetForeground, surfaceNodeId:[%" PRIu64 "] isForeground:%s",
845         GetId(), isForeground ? "true" : "false");
846     std::unique_ptr<RSCommand> commandRS =
847         std::make_unique<RSSurfaceNodeSetForeground>(GetId(), isForeground);
848     std::unique_ptr<RSCommand> commandRT =
849         std::make_unique<RSSurfaceNodeSetForeground>(GetId(), isForeground);
850     AddCommand(commandRS, true);
851     AddCommand(commandRT, false);
852 }
853 
SetClonedNodeInfo(NodeId nodeId,bool needOffscreen)854 void RSSurfaceNode::SetClonedNodeInfo(NodeId nodeId, bool needOffscreen)
855 {
856     std::unique_ptr<RSCommand> command =
857         std::make_unique<RSSurfaceNodeSetClonedNodeId>(GetId(), nodeId, needOffscreen);
858     AddCommand(command, true);
859 }
860 
SetForceUIFirst(bool forceUIFirst)861 void RSSurfaceNode::SetForceUIFirst(bool forceUIFirst)
862 {
863     std::unique_ptr<RSCommand> command =
864         std::make_unique<RSSurfaceNodeSetForceUIFirst>(GetId(), forceUIFirst);
865     AddCommand(command, true);
866 }
867 
SetAncoFlags(uint32_t flags)868 void RSSurfaceNode::SetAncoFlags(uint32_t flags)
869 {
870     std::unique_ptr<RSCommand> command =
871         std::make_unique<RSSurfaceNodeSetAncoFlags>(GetId(), flags);
872     AddCommand(command, true);
873 }
SetHDRPresent(bool hdrPresent,NodeId id)874 void RSSurfaceNode::SetHDRPresent(bool hdrPresent, NodeId id)
875 {
876     std::unique_ptr<RSCommand> command =
877         std::make_unique<RSSurfaceNodeSetHDRPresent>(id, hdrPresent);
878     ROSEN_LOGD("SetHDRPresent  RSSurfaceNode");
879     AddCommand(command, true);
880 }
881 
SetSkipDraw(bool skip)882 void RSSurfaceNode::SetSkipDraw(bool skip)
883 {
884     isSkipDraw_ = skip;
885     std::unique_ptr<RSCommand> command =
886         std::make_unique<RSSurfaceNodeSetSkipDraw>(GetId(), skip);
887     AddCommand(command, true);
888     ROSEN_LOGD("RSSurfaceNode::SetSkipDraw, surfaceNodeId:[%" PRIu64 "] skipdraw:%s", GetId(),
889         skip ? "true" : "false");
890 }
891 
GetSkipDraw() const892 bool RSSurfaceNode::GetSkipDraw() const
893 {
894     return isSkipDraw_;
895 }
896 
RegisterNodeMap()897 void RSSurfaceNode::RegisterNodeMap()
898 {
899     auto rsContext = GetRSUIContext();
900     if (rsContext == nullptr) {
901         return;
902     }
903     auto& nodeMap = rsContext->GetMutableNodeMap();
904     nodeMap.RegisterNode(shared_from_this());
905 }
906 
SetWatermarkEnabled(const std::string & name,bool isEnabled)907 void RSSurfaceNode::SetWatermarkEnabled(const std::string& name, bool isEnabled)
908 {
909 #ifdef ROSEN_OHOS
910     if (name.empty() || name.length() > WATERMARK_NAME_LENGTH_LIMIT) {
911         ROSEN_LOGE("SetWatermarkEnabled name[%{public}s] is error.", name.c_str());
912         return;
913     }
914     std::unique_ptr<RSCommand> command =
915         std::make_unique<RSSurfaceNodeSetWatermarkEnabled>(GetId(), name, isEnabled);
916     ROSEN_LOGI("SetWatermarkEnabled[%{public}s, %{public}" PRIu64 " watermark:%{public}s]",
917         GetName().c_str(), GetId(), name.c_str());
918     AddCommand(command, true);
919 #endif
920 }
921 
SetAbilityState(RSSurfaceNodeAbilityState abilityState)922 void RSSurfaceNode::SetAbilityState(RSSurfaceNodeAbilityState abilityState)
923 {
924     if (abilityState_ == abilityState) {
925         ROSEN_LOGD("RSSurfaceNode::SetAbilityState, surfaceNodeId:[%{public}" PRIu64 "], "
926             "ability state same with before: %{public}s",
927             GetId(), abilityState == RSSurfaceNodeAbilityState::FOREGROUND ? "foreground" : "background");
928     }
929     std::unique_ptr<RSCommand> command =
930         std::make_unique<RSSurfaceNodeSetAbilityState>(GetId(), abilityState);
931     AddCommand(command, true);
932     abilityState_ = abilityState;
933     ROSEN_LOGI("RSSurfaceNode::SetAbilityState, surfaceNodeId:[%{public}" PRIu64 "], ability state: %{public}s",
934         GetId(), abilityState_ == RSSurfaceNodeAbilityState::FOREGROUND ? "foreground" : "background");
935 }
936 
GetAbilityState() const937 RSSurfaceNodeAbilityState RSSurfaceNode::GetAbilityState() const
938 {
939     return abilityState_;
940 }
941 
SetHidePrivacyContent(bool needHidePrivacyContent)942 RSInterfaceErrorCode RSSurfaceNode::SetHidePrivacyContent(bool needHidePrivacyContent)
943 {
944     auto renderServiceClient =
945         std::static_pointer_cast<RSRenderServiceClient>(RSIRenderClient::CreateRenderServiceClient());
946     if (renderServiceClient != nullptr) {
947         return static_cast<RSInterfaceErrorCode>(
948             renderServiceClient->SetHidePrivacyContent(GetId(), needHidePrivacyContent));
949     }
950     return RSInterfaceErrorCode::UNKNOWN_ERROR;
951 }
952 
SetHardwareEnableHint(bool enable)953 void RSSurfaceNode::SetHardwareEnableHint(bool enable)
954 {
955     std::unique_ptr<RSCommand> command =
956         std::make_unique<RSSurfaceNodeSetHardwareEnableHint>(GetId(), enable);
957     AddCommand(command, true);
958 }
959 
SetApiCompatibleVersion(uint32_t version)960 void RSSurfaceNode::SetApiCompatibleVersion(uint32_t version)
961 {
962     std::unique_ptr<RSCommand> command = std::make_unique<RSSurfaceNodeSetApiCompatibleVersion>(GetId(), version);
963     AddCommand(command, true);
964     RS_LOGD("RSSurfaceNode::SetApiCompatibleVersion: Node: %{public}" PRIu64 ", version: %{public}u", GetId(), version);
965 }
966 
SetSourceVirtualDisplayId(ScreenId screenId)967 void RSSurfaceNode::SetSourceVirtualDisplayId(ScreenId screenId)
968 {
969     std::unique_ptr<RSCommand> command =
970         std::make_unique<RSSurfaceNodeSetSourceVirtualDisplayId>(GetId(), screenId);
971     AddCommand(command, true);
972 }
973 
AttachToWindowContainer(ScreenId screenId)974 void RSSurfaceNode::AttachToWindowContainer(ScreenId screenId)
975 {
976     std::unique_ptr<RSCommand> command =
977         std::make_unique<RSSurfaceNodeAttachToWindowContainer>(GetId(), screenId);
978     AddCommand(command, true);
979     RS_LOGD("RSSurfaceNode::AttachToWindowContainer: Node: %{public}" PRIu64 ", screenId: %{public}" PRIu64,
980         GetId(), screenId);
981 }
982 
DetachFromWindowContainer(ScreenId screenId)983 void RSSurfaceNode::DetachFromWindowContainer(ScreenId screenId)
984 {
985     std::unique_ptr<RSCommand> command =
986         std::make_unique<RSSurfaceNodeDetachFromWindowContainer>(GetId(), screenId);
987     AddCommand(command, true);
988     RS_LOGD("RSSurfaceNode::DetachFromWindowContainer: Node: %{public}" PRIu64 ", screenId: %{public}" PRIu64,
989         GetId(), screenId);
990 }
991 
SetRegionToBeMagnified(const Vector4<int> & regionToBeMagnified)992 void RSSurfaceNode::SetRegionToBeMagnified(const Vector4<int>& regionToBeMagnified)
993 {
994     std::unique_ptr<RSCommand> command =
995         std::make_unique<RSSurfaceNodeSetRegionToBeMagnified>(GetId(), regionToBeMagnified);
996     AddCommand(command, true);
997 }
998 
IsSelfDrawingNode() const999 bool RSSurfaceNode::IsSelfDrawingNode() const
1000 {
1001     if (surfaceNodeType_ == RSSurfaceNodeType::SELF_DRAWING_NODE) {
1002         return true;
1003     } else {
1004         return false;
1005     }
1006 }
1007 
SetCompositeLayer(TopLayerZOrder zOrder)1008 bool RSSurfaceNode::SetCompositeLayer(TopLayerZOrder zOrder)
1009 {
1010     if (!RSSystemProperties::GetCompositeLayerEnabled()) {
1011         return false;
1012     }
1013     RS_TRACE_NAME_FMT("RSSurfaceNode::SetCompositeLayer %llu zOrder: %u", GetId(), zOrder);
1014     uint32_t topLayerZOrder = static_cast<uint32_t>(zOrder);
1015     if (IsSelfDrawingNode()) {
1016         RS_LOGI("RSSurfaceNode::SetCompositeLayer selfDrawingNode %{public}" PRIu64 " setLayerTop directly", GetId());
1017         RSInterfaces::GetInstance().SetLayerTopForHWC(GetId(), true, topLayerZOrder);
1018         return true;
1019     }
1020     compositeLayerUtils_ = std::make_shared<RSCompositeLayerUtils>(shared_from_this(), topLayerZOrder);
1021     if (zOrder == TopLayerZOrder::CHARGE_3D_MOTION) {
1022         if (GetChildren().size() == 1) {
1023             bool ret = compositeLayerUtils_->DealWithSelfDrawCompositeNode(GetChildren()[0].lock(), topLayerZOrder);
1024             compositeLayerUtils_ = nullptr;
1025             return ret;
1026         }
1027         return false;
1028     }
1029     return compositeLayerUtils_->CreateCompositeLayer();
1030 }
1031 
GetCompositeLayerUtils() const1032 std::shared_ptr<RSCompositeLayerUtils> RSSurfaceNode::GetCompositeLayerUtils() const
1033 {
1034     return compositeLayerUtils_;
1035 }
1036 
SetFrameGravityNewVersionEnabled(bool isEnabled)1037 void RSSurfaceNode::SetFrameGravityNewVersionEnabled(bool isEnabled)
1038 {
1039     if (isFrameGravityNewVersionEnabled_ == isEnabled) {
1040         return;
1041     }
1042 
1043     isFrameGravityNewVersionEnabled_ = isEnabled;
1044     std::unique_ptr<RSCommand> command =
1045         std::make_unique<RSSurfaceNodeSetFrameGravityNewVersionEnabled>(GetId(), isEnabled);
1046     AddCommand(command, true);
1047 }
1048 
GetFrameGravityNewVersionEnabled() const1049 bool RSSurfaceNode::GetFrameGravityNewVersionEnabled() const
1050 {
1051     return isFrameGravityNewVersionEnabled_;
1052 }
1053 } // namespace Rosen
1054 } // namespace OHOS
1055