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 "platform/common/rs_log.h"
22 #ifndef ROSEN_CROSS_PLATFORM
23 #include "surface_type.h"
24 #endif
25
26 namespace OHOS {
27 namespace Rosen {
28
Create(RSContext & context,NodeId id,RSSurfaceNodeType type,bool isTextureExportNode)29 void SurfaceNodeCommandHelper::Create(RSContext& context, NodeId id, RSSurfaceNodeType type, bool isTextureExportNode)
30 {
31 if (!context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
32 auto node = std::make_shared<RSSurfaceRenderNode>(id, context.weak_from_this(), isTextureExportNode);
33 node->SetSurfaceNodeType(type);
34 auto& nodeMap = context.GetMutableNodeMap();
35 nodeMap.RegisterRenderNode(node);
36 }
37 }
38
CreateWithConfig(RSContext & context,NodeId nodeId,std::string name,uint8_t type,std::string bundleName)39 void SurfaceNodeCommandHelper::CreateWithConfig(
40 RSContext& context, NodeId nodeId, std::string name, uint8_t type, std::string bundleName)
41 {
42 RSSurfaceRenderNodeConfig config = {
43 .id = nodeId, .name = name, .bundleName = bundleName, .nodeType = static_cast<RSSurfaceNodeType>(type)
44 };
45 auto node = std::make_shared<RSSurfaceRenderNode>(config, context.weak_from_this());
46 context.GetMutableNodeMap().RegisterRenderNode(node);
47 }
48
49 #ifndef USE_ROSEN_DRAWING
SetContextMatrix(RSContext & context,NodeId id,const std::optional<SkMatrix> & matrix)50 void SurfaceNodeCommandHelper::SetContextMatrix(RSContext& context, NodeId id, const std::optional<SkMatrix>& matrix)
51 #else
52 void SurfaceNodeCommandHelper::SetContextMatrix(
53 RSContext& context, NodeId id, const std::optional<Drawing::Matrix>& matrix)
54 #endif
55 {
56 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
57 node->SetContextMatrix(matrix, false);
58 }
59 }
60
SetContextAlpha(RSContext & context,NodeId id,float alpha)61 void SurfaceNodeCommandHelper::SetContextAlpha(RSContext& context, NodeId id, float alpha)
62 {
63 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
64 node->SetContextAlpha(alpha, false);
65 }
66 }
67
68 #ifndef USE_ROSEN_DRAWING
SetContextClipRegion(RSContext & context,NodeId id,const std::optional<SkRect> & clipRect)69 void SurfaceNodeCommandHelper::SetContextClipRegion(
70 RSContext& context, NodeId id, const std::optional<SkRect>& clipRect)
71 #else
72 void SurfaceNodeCommandHelper::SetContextClipRegion(
73 RSContext& context, NodeId id, const std::optional<Drawing::Rect>& clipRect)
74 #endif
75 {
76 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
77 node->SetContextClipRegion(clipRect, false);
78 }
79 }
80
SetSecurityLayer(RSContext & context,NodeId id,bool isSecurityLayer)81 void SurfaceNodeCommandHelper::SetSecurityLayer(RSContext& context, NodeId id, bool isSecurityLayer)
82 {
83 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
84 node->SetSecurityLayer(isSecurityLayer);
85 }
86 }
87
SetIsTextureExportNode(RSContext & context,NodeId id,bool isTextureExportNode)88 void SurfaceNodeCommandHelper::SetIsTextureExportNode(RSContext& context, NodeId id, bool isTextureExportNode)
89 {
90 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
91 node->SetIsTextureExportNode(isTextureExportNode);
92 }
93 }
94
SetSkipLayer(RSContext & context,NodeId id,bool isSkipLayer)95 void SurfaceNodeCommandHelper::SetSkipLayer(RSContext& context, NodeId id, bool isSkipLayer)
96 {
97 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
98 node->SetSkipLayer(isSkipLayer);
99 }
100 }
101
SetFingerprint(RSContext & context,NodeId id,bool hasFingerprint)102 void SurfaceNodeCommandHelper::SetFingerprint(RSContext& context, NodeId id, bool hasFingerprint)
103 {
104 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
105 node->SetFingerprint(hasFingerprint);
106 }
107 }
108
SetColorSpace(RSContext & context,NodeId id,GraphicColorGamut colorSpace)109 void SurfaceNodeCommandHelper::SetColorSpace(RSContext& context, NodeId id, GraphicColorGamut colorSpace)
110 {
111 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
112 node->SetColorSpace(colorSpace);
113 }
114 }
115
UpdateSurfaceDefaultSize(RSContext & context,NodeId id,float width,float height)116 void SurfaceNodeCommandHelper::UpdateSurfaceDefaultSize(RSContext& context, NodeId id, float width, float height)
117 {
118 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
119 node->UpdateSurfaceDefaultSize(width, height);
120 }
121 }
122
ConnectToNodeInRenderService(RSContext & context,NodeId id)123 void SurfaceNodeCommandHelper::ConnectToNodeInRenderService(RSContext& context, NodeId id)
124 {
125 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
126 node->ConnectToNodeInRenderService();
127 }
128 }
129
SetCallbackForRenderThreadRefresh(RSContext & context,NodeId id,bool isRefresh)130 void SurfaceNodeCommandHelper::SetCallbackForRenderThreadRefresh(
131 RSContext& context, NodeId id, bool isRefresh)
132 {
133 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
134 if (node->NeedSetCallbackForRenderThreadRefresh()) {
135 node->SetCallbackForRenderThreadRefresh(isRefresh);
136 }
137 }
138 }
139
SetContextBounds(RSContext & context,NodeId id,Vector4f bounds)140 void SurfaceNodeCommandHelper::SetContextBounds(RSContext& context, NodeId id, Vector4f bounds)
141 {
142 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
143 node->GetMutableRenderProperties().SetBounds(bounds);
144 }
145 }
146
SetAbilityBGAlpha(RSContext & context,NodeId id,uint8_t alpha)147 void SurfaceNodeCommandHelper::SetAbilityBGAlpha(RSContext& context, NodeId id, uint8_t alpha)
148 {
149 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
150 node->SetAbilityBGAlpha(alpha);
151 }
152 }
153
SetIsNotifyUIBufferAvailable(RSContext & context,NodeId id,bool available)154 void SurfaceNodeCommandHelper::SetIsNotifyUIBufferAvailable(RSContext& context, NodeId id, bool available)
155 {
156 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
157 node->SetIsNotifyUIBufferAvailable(available);
158 }
159 }
160
MarkUIHidden(RSContext & context,NodeId id,bool isHidden)161 void SurfaceNodeCommandHelper::MarkUIHidden(RSContext& context, NodeId id, bool isHidden)
162 {
163 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
164 node->MarkUIHidden(isHidden);
165 }
166 }
167
SetSurfaceNodeType(RSContext & context,NodeId nodeId,uint8_t surfaceNodeType)168 void SurfaceNodeCommandHelper::SetSurfaceNodeType(RSContext& context, NodeId nodeId, uint8_t surfaceNodeType)
169 {
170 auto type = static_cast<RSSurfaceNodeType>(surfaceNodeType);
171 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
172 node->SetSurfaceNodeType(type);
173 }
174 }
175
SetContainerWindow(RSContext & context,NodeId nodeId,bool hasContainerWindow,float density)176 void SurfaceNodeCommandHelper::SetContainerWindow(
177 RSContext& context, NodeId nodeId, bool hasContainerWindow, float density)
178 {
179 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
180 node->SetContainerWindow(hasContainerWindow, density);
181 }
182 }
183
SetAnimationFinished(RSContext & context,NodeId nodeId)184 void SurfaceNodeCommandHelper::SetAnimationFinished(RSContext& context, NodeId nodeId)
185 {
186 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
187 node->SetStartAnimationFinished();
188 }
189 }
190
AttachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)191 void SurfaceNodeCommandHelper::AttachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
192 {
193 const auto& nodeMap = context.GetNodeMap();
194 auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
195 if (surfaceRenderNode == nullptr) {
196 return;
197 }
198 nodeMap.TraverseDisplayNodes(
199 [&surfaceRenderNode, &screenId](const std::shared_ptr<RSDisplayRenderNode>& displayRenderNode) {
200 if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId ||
201 displayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
202 return;
203 }
204 displayRenderNode->AddChild(surfaceRenderNode);
205 });
206 }
207
DetachToDisplay(RSContext & context,NodeId nodeId,uint64_t screenId)208 void SurfaceNodeCommandHelper::DetachToDisplay(RSContext& context, NodeId nodeId, uint64_t screenId)
209 {
210 const auto& nodeMap = context.GetNodeMap();
211 auto surfaceRenderNode = nodeMap.GetRenderNode<RSSurfaceRenderNode>(nodeId);
212 if (surfaceRenderNode == nullptr) {
213 return;
214 }
215 nodeMap.TraverseDisplayNodes(
216 [&surfaceRenderNode, &screenId](const std::shared_ptr<RSDisplayRenderNode>& displayRenderNode) {
217 if (displayRenderNode == nullptr || displayRenderNode->GetScreenId() != screenId ||
218 displayRenderNode->GetBootAnimation() != surfaceRenderNode->GetBootAnimation()) {
219 return;
220 }
221 displayRenderNode->RemoveChild(surfaceRenderNode);
222 });
223 }
224
SetBootAnimation(RSContext & context,NodeId nodeId,bool isBootAnimation)225 void SurfaceNodeCommandHelper::SetBootAnimation(RSContext& context, NodeId nodeId, bool isBootAnimation)
226 {
227 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
228 node->SetBootAnimation(isBootAnimation);
229 }
230 }
231
232 #ifdef USE_SURFACE_TEXTURE
CreateSurfaceExt(RSContext & context,NodeId id,const std::shared_ptr<RSSurfaceTexture> & surfaceExt)233 void SurfaceNodeCommandHelper::CreateSurfaceExt(RSContext& context, NodeId id,
234 const std::shared_ptr<RSSurfaceTexture>& surfaceExt)
235 {
236 auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id);
237 if (node != nullptr) {
238 node->SetSurfaceTexture(surfaceExt);
239 }
240 }
241 #endif
242
SetForeground(RSContext & context,NodeId nodeId,bool isForeground)243 void SurfaceNodeCommandHelper::SetForeground(RSContext& context, NodeId nodeId, bool isForeground)
244 {
245 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
246 node->SetForeground(isForeground);
247 }
248 }
249
SetSurfaceId(RSContext & context,NodeId nodeId,SurfaceId surfaceId)250 void SurfaceNodeCommandHelper::SetSurfaceId(RSContext& context, NodeId nodeId, SurfaceId surfaceId)
251 {
252 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
253 node->SetSurfaceId(surfaceId);
254 }
255 }
256
SetForceUIFirst(RSContext & context,NodeId nodeId,bool forceUIFirst)257 void SurfaceNodeCommandHelper::SetForceUIFirst(RSContext& context, NodeId nodeId, bool forceUIFirst)
258 {
259 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
260 node->SetForceUIFirst(forceUIFirst);
261 }
262 }
263 } // namespace Rosen
264 } // namespace OHOS
265