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
21 namespace OHOS {
22 namespace Rosen {
23
Create(RSContext & context,NodeId id)24 void SurfaceNodeCommandHelper::Create(RSContext& context, NodeId id)
25 {
26 auto node = std::make_shared<RSSurfaceRenderNode>(id, context.weak_from_this());
27 auto& nodeMap = context.GetMutableNodeMap();
28 nodeMap.RegisterRenderNode(node);
29 }
30
SetContextMatrix(RSContext & context,NodeId id,SkMatrix matrix)31 void SurfaceNodeCommandHelper::SetContextMatrix(RSContext& context, NodeId id, SkMatrix matrix)
32 {
33 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
34 node->SetContextMatrix(matrix, false);
35 }
36 }
37
SetContextAlpha(RSContext & context,NodeId id,float alpha)38 void SurfaceNodeCommandHelper::SetContextAlpha(RSContext& context, NodeId id, float alpha)
39 {
40 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
41 node->SetContextAlpha(alpha, false);
42 }
43 }
44
SetContextClipRegion(RSContext & context,NodeId id,SkRect clipRect)45 void SurfaceNodeCommandHelper::SetContextClipRegion(RSContext& context, NodeId id, SkRect clipRect)
46 {
47 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
48 node->SetContextClipRegion(clipRect, false);
49 }
50 }
51
SetSecurityLayer(RSContext & context,NodeId id,bool isSecurityLayer)52 void SurfaceNodeCommandHelper::SetSecurityLayer(RSContext& context, NodeId id, bool isSecurityLayer)
53 {
54 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
55 node->SetSecurityLayer(isSecurityLayer);
56 }
57 }
58
59 #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__gnu_linux__)
SetColorSpace(RSContext & context,NodeId id,ColorGamut colorSpace)60 void SurfaceNodeCommandHelper::SetColorSpace(RSContext& context, NodeId id, ColorGamut colorSpace)
61 {
62 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
63 node->SetColorSpace(colorSpace);
64 }
65 }
66 #endif
67
UpdateSurfaceDefaultSize(RSContext & context,NodeId id,float width,float height)68 void SurfaceNodeCommandHelper::UpdateSurfaceDefaultSize(RSContext& context, NodeId id, float width, float height)
69 {
70 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
71 node->UpdateSurfaceDefaultSize(width, height);
72 }
73 }
74
ConnectToNodeInRenderService(RSContext & context,NodeId id)75 void SurfaceNodeCommandHelper::ConnectToNodeInRenderService(RSContext& context, NodeId id)
76 {
77 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
78 node->ConnectToNodeInRenderService();
79 }
80 }
81
SetCallbackForRenderThreadRefresh(RSContext & context,NodeId id,std::function<void (void)> callback)82 void SurfaceNodeCommandHelper::SetCallbackForRenderThreadRefresh(RSContext& context, NodeId id, std::function<void(void)> callback)
83 {
84 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
85 if (node->NeedSetCallbackForRenderThreadRefresh()) {
86 node->SetCallbackForRenderThreadRefresh(callback);
87 }
88 }
89 }
90
SetContextBounds(RSContext & context,NodeId id,Vector4f bounds)91 void SurfaceNodeCommandHelper::SetContextBounds(RSContext& context, NodeId id, Vector4f bounds)
92 {
93 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
94 node->GetMutableRenderProperties().SetBounds(bounds);
95 }
96 }
97
SetAbilityBGAlpha(RSContext & context,NodeId id,uint8_t alpha)98 void SurfaceNodeCommandHelper::SetAbilityBGAlpha(RSContext& context, NodeId id, uint8_t alpha)
99 {
100 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
101 node->SetAbilityBGAlpha(alpha);
102 }
103 }
104
UpdateParentWithoutTransition(RSContext & context,NodeId nodeId,NodeId parentId)105 void SurfaceNodeCommandHelper::UpdateParentWithoutTransition(RSContext& context, NodeId nodeId, NodeId parentId)
106 {
107 auto& nodeMap = context.GetNodeMap();
108 auto node = nodeMap.GetRenderNode(nodeId);
109 auto parent = nodeMap.GetRenderNode(parentId);
110 if (node && parent) {
111 node->RemoveFromTree(true);
112 parent->AddChild(node);
113 }
114 }
115
SetIsNotifyUIBufferAvailable(RSContext & context,NodeId id,bool available)116 void SurfaceNodeCommandHelper::SetIsNotifyUIBufferAvailable(RSContext& context, NodeId id, bool available)
117 {
118 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(id)) {
119 node->SetIsNotifyUIBufferAvailable(available);
120 }
121 }
122
SetAppFreeze(RSContext & context,NodeId nodeId,bool isAppFreeze)123 void SurfaceNodeCommandHelper::SetAppFreeze(RSContext& context, NodeId nodeId, bool isAppFreeze)
124 {
125 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
126 node->SetAppFreeze(isAppFreeze);
127 }
128 }
129
SetSurfaceNodeType(RSContext & context,NodeId nodeId,RSSurfaceNodeType type)130 void SurfaceNodeCommandHelper::SetSurfaceNodeType(RSContext& context, NodeId nodeId, RSSurfaceNodeType type)
131 {
132 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
133 node->SetSurfaceNodeType(type);
134 }
135 }
136
SetContainerWindow(RSContext & context,NodeId nodeId,bool hasContainerWindow,float density)137 void SurfaceNodeCommandHelper::SetContainerWindow(RSContext& context, NodeId nodeId,
138 bool hasContainerWindow, float density)
139 {
140 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
141 node->SetContainerWindow(hasContainerWindow, density);
142 }
143 }
144
SetAnimationFinished(RSContext & context,NodeId nodeId)145 void SurfaceNodeCommandHelper::SetAnimationFinished(RSContext& context, NodeId nodeId)
146 {
147 if (auto node = context.GetNodeMap().GetRenderNode<RSSurfaceRenderNode>(nodeId)) {
148 node->SetStartAnimationFinished();
149 }
150 }
151 } // namespace Rosen
152 } // namespace OHOS
153