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 #ifndef ROSEN_CROSS_PLATFORM
22 #include "surface_type.h"
23 #endif
24
25 namespace OHOS {
26 namespace Rosen {
27
Create(RSContext & context,NodeId id)28 void SurfaceNodeCommandHelper::Create(RSContext& context, NodeId id)
29 {
30 auto node = std::make_shared<RSSurfaceRenderNode>(id, context.weak_from_this());
31 auto& nodeMap = context.GetMutableNodeMap();
32 nodeMap.RegisterRenderNode(node);
33 }
34
35 #ifndef USE_ROSEN_DRAWING
SetContextMatrix(RSContext & context,NodeId id,const std::optional<SkMatrix> & matrix)36 void SurfaceNodeCommandHelper::SetContextMatrix(RSContext& context, NodeId id, const std::optional<SkMatrix>& matrix)
37 #else
38 void SurfaceNodeCommandHelper::SetContextMatrix(
39 RSContext& context, NodeId id, const std::optional<Drawing::Matrix>& matrix)
40 #endif
41 {
42 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
43 node->SetContextMatrix(matrix, false);
44 }
45 }
46
SetContextAlpha(RSContext & context,NodeId id,float alpha)47 void SurfaceNodeCommandHelper::SetContextAlpha(RSContext& context, NodeId id, float alpha)
48 {
49 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
50 node->SetContextAlpha(alpha, false);
51 }
52 }
53
54 #ifndef USE_ROSEN_DRAWING
SetContextClipRegion(RSContext & context,NodeId id,const std::optional<SkRect> & clipRect)55 void SurfaceNodeCommandHelper::SetContextClipRegion(
56 RSContext& context, NodeId id, const std::optional<SkRect>& clipRect)
57 #else
58 void SurfaceNodeCommandHelper::SetContextClipRegion(
59 RSContext& context, NodeId id, const std::optional<Drawing::Rect>& clipRect)
60 #endif
61 {
62 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
63 node->SetContextClipRegion(clipRect, false);
64 }
65 }
66
SetSecurityLayer(RSContext & context,NodeId id,bool isSecurityLayer)67 void SurfaceNodeCommandHelper::SetSecurityLayer(RSContext& context, NodeId id, bool isSecurityLayer)
68 {
69 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
70 node->SetSecurityLayer(isSecurityLayer);
71 }
72 }
73
SetFingerprint(RSContext & context,NodeId id,bool hasFingerprint)74 void SurfaceNodeCommandHelper::SetFingerprint(RSContext& context, NodeId id, bool hasFingerprint)
75 {
76 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
77 node->SetFingerprint(hasFingerprint);
78 }
79 }
80
81 #ifndef ROSEN_CROSS_PLATFORM
SetColorSpace(RSContext & context,NodeId id,GraphicColorGamut colorSpace)82 void SurfaceNodeCommandHelper::SetColorSpace(RSContext& context, NodeId id, GraphicColorGamut colorSpace)
83 {
84 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
85 node->SetColorSpace(colorSpace);
86 }
87 }
88 #endif
89
UpdateSurfaceDefaultSize(RSContext & context,NodeId id,float width,float height)90 void SurfaceNodeCommandHelper::UpdateSurfaceDefaultSize(RSContext& context, NodeId id, float width, float height)
91 {
92 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
93 node->UpdateSurfaceDefaultSize(width, height);
94 }
95 }
96
ConnectToNodeInRenderService(RSContext & context,NodeId id)97 void SurfaceNodeCommandHelper::ConnectToNodeInRenderService(RSContext& context, NodeId id)
98 {
99 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
100 node->ConnectToNodeInRenderService();
101 }
102 }
103
SetCallbackForRenderThreadRefresh(RSContext & context,NodeId id,bool isRefresh)104 void SurfaceNodeCommandHelper::SetCallbackForRenderThreadRefresh(
105 RSContext& context, NodeId id, bool isRefresh)
106 {
107 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
108 if (node->NeedSetCallbackForRenderThreadRefresh()) {
109 node->SetCallbackForRenderThreadRefresh(isRefresh);
110 }
111 }
112 }
113
SetContextBounds(RSContext & context,NodeId id,Vector4f bounds)114 void SurfaceNodeCommandHelper::SetContextBounds(RSContext& context, NodeId id, Vector4f bounds)
115 {
116 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
117 node->GetMutableRenderProperties().SetBounds(bounds);
118 }
119 }
120
SetAbilityBGAlpha(RSContext & context,NodeId id,uint8_t alpha)121 void SurfaceNodeCommandHelper::SetAbilityBGAlpha(RSContext& context, NodeId id, uint8_t alpha)
122 {
123 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
124 node->SetAbilityBGAlpha(alpha);
125 }
126 }
127
SetIsNotifyUIBufferAvailable(RSContext & context,NodeId id,bool available)128 void SurfaceNodeCommandHelper::SetIsNotifyUIBufferAvailable(RSContext& context, NodeId id, bool available)
129 {
130 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
131 node->SetIsNotifyUIBufferAvailable(available);
132 }
133 }
134
MarkUIHidden(RSContext & context,NodeId id,bool isHidden)135 void SurfaceNodeCommandHelper::MarkUIHidden(RSContext& context, NodeId id, bool isHidden)
136 {
137 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
138 node->MarkUIHidden(isHidden);
139 }
140 }
141
SetSurfaceNodeType(RSContext & context,NodeId nodeId,uint8_t surfaceNodeType)142 void SurfaceNodeCommandHelper::SetSurfaceNodeType(RSContext& context, NodeId nodeId, uint8_t surfaceNodeType)
143 {
144 auto type = static_cast<RSSurfaceNodeType>(surfaceNodeType);
145 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
146 node->SetSurfaceNodeType(type);
147 }
148 }
149
SetContainerWindow(RSContext & context,NodeId nodeId,bool hasContainerWindow,float density)150 void SurfaceNodeCommandHelper::SetContainerWindow(
151 RSContext& context, NodeId nodeId, bool hasContainerWindow, float density)
152 {
153 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
154 node->SetContainerWindow(hasContainerWindow, density);
155 }
156 }
157
SetAnimationFinished(RSContext & context,NodeId nodeId)158 void SurfaceNodeCommandHelper::SetAnimationFinished(RSContext& context, NodeId nodeId)
159 {
160 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
161 node->SetStartAnimationFinished();
162 }
163 }
164
AttachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)165 void SurfaceNodeCommandHelper::AttachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
166 {
167 const auto& nodeMap = context.GetNodeMap();
168 auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
169 nodeMap.TraverseDisplayNodes(
170 [&surfaceRenderNode, &screenId](const std::shared_ptr<RSDisplayRenderNode>& displayRenderNode) {
171 if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId) {
172 return;
173 }
174 displayRenderNode->AddChild(surfaceRenderNode);
175 });
176 }
177
DetachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)178 void SurfaceNodeCommandHelper::DetachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
179 {
180 const auto& nodeMap = context.GetNodeMap();
181 auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
182 nodeMap.TraverseDisplayNodes(
183 [&surfaceRenderNode, &screenId](const std::shared_ptr<RSDisplayRenderNode>& displayRenderNode) {
184 if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId) {
185 return;
186 }
187 displayRenderNode->RemoveChild(surfaceRenderNode);
188 });
189 }
190 } // namespace Rosen
191 } // namespace OHOS
192