• 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 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H
16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H
17 
18 #include <parcel.h>
19 #include <refbase.h>
20 #include <string>
21 
22 #ifdef ROSEN_OHOS
23 #include "iconsumer_surface.h"
24 #include "surface.h"
25 #include "surface_delegate.h"
26 #include "surface_type.h"
27 #endif
28 
29 #ifndef ROSEN_CROSS_PLATFORM
30 #include "surface_delegate.h"
31 #endif
32 
33 #include "platform/drawing/rs_surface.h"
34 #include "platform/common/rs_surface_ext.h"
35 #include "transaction/rs_transaction_proxy.h"
36 #include "ui/rs_node.h"
37 
38 
39 namespace OHOS {
40 namespace Rosen {
41 struct RSSurfaceNodeConfig {
42     std::string SurfaceNodeName = "SurfaceNode";
43     void* additionalData = nullptr;
44     bool isTextureExportNode = false;
45     SurfaceId surfaceId = 0;
46     bool isSync = true;
47     enum SurfaceWindowType surfaceWindowType = SurfaceWindowType::DEFAULT_WINDOW;
48     std::shared_ptr<RSUIContext> rsUIContext = nullptr;
49 };
50 
51 class RSC_EXPORT RSSurfaceNode : public RSNode {
52 public:
53     static constexpr float POINTER_WINDOW_POSITION_Z = 9999;
54 
55     using WeakPtr = std::weak_ptr<RSSurfaceNode>;
56     using SharedPtr = std::shared_ptr<RSSurfaceNode>;
57     static inline constexpr RSUINodeType Type = RSUINodeType::SURFACE_NODE;
GetType()58     RSUINodeType GetType() const override
59     {
60         return Type;
61     }
62 
63     ~RSSurfaceNode() override;
64 
65     static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow = true,
66         std::shared_ptr<RSUIContext> rsUIContext = nullptr);
67 
68     // This interface is only available for WMS
69     static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, RSSurfaceNodeType type, bool isWindow = true,
70         bool unobscured = false, std::shared_ptr<RSUIContext> rsUIContext = nullptr);
71 
72     // This API is only for abilityView create RSRenderSurfaceNode in RenderThread.
73     // Do not call this API unless you are sure what you do.
74     // After calling it, this surfaceNode is disallowed to add/remove child.
75     void CreateNodeInRenderThread();
76 
77     void AddChild(std::shared_ptr<RSBaseNode> child, int index) override;
78     void RemoveChild(std::shared_ptr<RSBaseNode> child) override;
79     void ClearChildren() override;
80 
81     void SetSecurityLayer(bool isSecurityLayer);
82     bool GetSecurityLayer() const;
83     void SetLeashPersistentId(LeashPersistentId leashPersistentId);
84     LeashPersistentId GetLeashPersistentId() const;
85     void SetSkipLayer(bool isSkipLayer);
86     bool GetSkipLayer() const;
87     void SetSnapshotSkipLayer(bool isSnapshotSkipLayer);
88     bool GetSnapshotSkipLayer() const;
89     void SetFingerprint(bool hasFingerprint);
90     bool GetFingerprint() const;
91     void SetAbilityBGAlpha(uint8_t alpha);
92     void SetIsNotifyUIBufferAvailable(bool available);
93     void MarkUIHidden(bool isHidden);
94 
95     using BufferAvailableCallback = std::function<void()>;
96     bool SetBufferAvailableCallback(BufferAvailableCallback callback);
97     bool IsBufferAvailable() const;
98     void SetBoundsChangedCallback(BoundsChangedCallback callback) override;
99     void SetAnimationFinished();
100 
101     bool Marshalling(Parcel& parcel) const;
102     static SharedPtr Unmarshalling(Parcel& parcel);
103     // Create RSProxyNode by unmarshalling RSSurfaceNode, return existing node if it exists in RSNodeMap.
104     static RSNode::SharedPtr UnmarshallingAsProxyNode(Parcel& parcel);
105 
106     FollowType GetFollowType() const override;
107 
108     void AttachToDisplay(uint64_t screenId);
109     void DetachToDisplay(uint64_t screenId);
110     void SetHardwareEnabled(bool isEnabled, SelfDrawingNodeType selfDrawingType = SelfDrawingNodeType::DEFAULT,
111         bool dynamicHardwareEnable = true);
112     void SetForceHardwareAndFixRotation(bool flag);
113     void SetBootAnimation(bool isBootAnimation);
114     bool GetBootAnimation() const;
115     void SetTextureExport(bool isTextureExportNode) override;
116     void SetGlobalPositionEnabled(bool isEnabled);
117     bool GetGlobalPositionEnabled() const;
118 
119 #ifndef ROSEN_CROSS_PLATFORM
120     sptr<OHOS::Surface> GetSurface() const;
121 #endif
122     void SetColorSpace(GraphicColorGamut colorSpace);
GetColorSpace()123     GraphicColorGamut GetColorSpace()
124     {
125         return colorSpace_;
126     }
127 
GetName()128     inline std::string GetName() const
129     {
130         return name_;
131     }
132 
133     void ResetContextAlpha() const;
134 
135     void SetContainerWindow(bool hasContainerWindow, RRect rrect);
136     void SetWindowId(uint32_t windowId);
137 
138     void SetFreeze(bool isFreeze) override;
139     // codes for arkui-x
140 #ifdef USE_SURFACE_TEXTURE
141     void SetSurfaceTexture(const RSSurfaceExtConfig& config);
142     void MarkUiFrameAvailable(bool available);
143     void SetSurfaceTextureAttachCallBack(const RSSurfaceTextureAttachCallBack& attachCallback);
144     void SetSurfaceTextureUpdateCallBack(const RSSurfaceTextureUpdateCallBack& updateCallback);
145     void SetSurfaceTextureInitTypeCallBack(const RSSurfaceTextureInitTypeCallBack& initTypeCallback);
146 #endif
147     void SetForeground(bool isForeground);
148     // [Attention] The function only used for unlocking screen for PC currently
149     void SetClonedNodeId(NodeId nodeId);
150     // Force enable UIFirst when set TRUE
151     void SetForceUIFirst(bool forceUIFirst);
152     void SetAncoFlags(uint32_t flags);
153     void SetHDRPresent(bool hdrPresent, NodeId id);
154     void SetSkipDraw(bool skip);
155     bool GetSkipDraw() const;
156     void SetAbilityState(RSSurfaceNodeAbilityState abilityState);
157     RSSurfaceNodeAbilityState GetAbilityState() const;
158 
159     void SetWatermarkEnabled(const std::string& name, bool isEnabled);
160 
161     RSInterfaceErrorCode SetHidePrivacyContent(bool needHidePrivacyContent);
162     // Specifying hardware enable is only a 'hint' to RS that
163     // the self-drawing node use hardware composer in some condition,
164     // such as transparent background.
165     void SetHardwareEnableHint(bool enable);
166     void SetApiCompatibleVersion(uint32_t version);
167 
168     void SetSourceVirtualDisplayId(ScreenId screenId);
169     void AttachToWindowContainer(ScreenId screenId);
170     void DetachFromWindowContainer(ScreenId screenId);
171 protected:
172     bool NeedForcedSendToRemote() const override;
173     RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode,
174         std::shared_ptr<RSUIContext> rsUIContext = nullptr);
175     RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id,
176         std::shared_ptr<RSUIContext> rsUIContext = nullptr);
177     RSSurfaceNode(const RSSurfaceNode&) = delete;
178     RSSurfaceNode(const RSSurfaceNode&&) = delete;
179     RSSurfaceNode& operator=(const RSSurfaceNode&) = delete;
180     RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete;
181 
182 private:
183 #ifdef USE_SURFACE_TEXTURE
184     void CreateSurfaceExt(const RSSurfaceExtConfig& config);
185 #endif
186     bool CreateNode(const RSSurfaceRenderNodeConfig& config);
187     bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, SurfaceId surfaceId = 0,
188         bool unobscured = false);
189     void OnBoundsSizeChanged() const override;
190     // this function is only used in texture export
191     void SetSurfaceIdToRenderNode();
192     void CreateRenderNodeForTextureExportSwitch() override;
193     void SetIsTextureExportNode(bool isTextureExportNode);
194     std::pair<std::string, std::string> SplitSurfaceNodeName(std::string surfaceNodeName);
195     void RegisterNodeMap() override;
196     std::shared_ptr<RSSurface> surface_;
197     std::string name_;
198     std::string bundleName_;
199     mutable std::mutex mutex_;
200     BufferAvailableCallback callback_;
201     bool bufferAvailable_ = false;
202     BoundsChangedCallback boundsChangedCallback_;
203     GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
204     bool isSecurityLayer_ = false;
205     bool isSkipLayer_ = false;
206     bool isSnapshotSkipLayer_ = false;
207     bool hasFingerprint_ = false;
208     bool isChildOperationDisallowed_ { false };
209     bool isBootAnimation_ = false;
210     bool isSkipDraw_ = false;
211     RSSurfaceNodeAbilityState abilityState_ = RSSurfaceNodeAbilityState::FOREGROUND;
212     bool isGlobalPositionEnabled_ = false;
213     LeashPersistentId leashPersistentId_ = INVALID_LEASH_PERSISTENTID;
214 
215     uint32_t windowId_ = 0;
216 #ifndef ROSEN_CROSS_PLATFORM
217     sptr<SurfaceDelegate> surfaceDelegate_;
218     sptr<SurfaceDelegate::ISurfaceCallback> surfaceCallback_;
219 #endif
220 
221     friend class RSUIDirector;
222     friend class RSAnimation;
223     friend class RSPathAnimation;
224     friend class RSPropertyAnimation;
225     friend class RSSurfaceExtractor;
226     friend class RSSurfaceCallback;
227 };
228 } // namespace Rosen
229 } // namespace OHOS
230 
231 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H
232