• 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 #ifdef NEW_RENDER_CONTEXT
30 #include "rs_render_surface.h"
31 #else
32 #include "platform/drawing/rs_surface.h"
33 #include "platform/common/rs_surface_ext.h"
34 #endif
35 #include "transaction/rs_transaction_proxy.h"
36 #include "ui/rs_node.h"
37 
38 #ifndef USE_ROSEN_DRAWING
39 class SkCanvas;
40 #endif
41 
42 namespace OHOS {
43 namespace Rosen {
44 struct RSSurfaceNodeConfig {
45     std::string SurfaceNodeName = "SurfaceNode";
46     void* additionalData = nullptr;
47     bool isTextureExportNode = false;
48     SurfaceId surfaceId = 0;
49     bool isSync = true;
50 };
51 
52 class RSC_EXPORT RSSurfaceNode : public RSNode {
53 public:
54     static constexpr float POINTER_WINDOW_POSITION_Z = 9999;
55 
56     using WeakPtr = std::weak_ptr<RSSurfaceNode>;
57     using SharedPtr = std::shared_ptr<RSSurfaceNode>;
58     static inline constexpr RSUINodeType Type = RSUINodeType::SURFACE_NODE;
GetType()59     RSUINodeType GetType() const override
60     {
61         return Type;
62     }
63 
64     ~RSSurfaceNode() override;
65 
66     static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow = true);
67 
68     // This interface is only available for WMS
69     static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, RSSurfaceNodeType type, bool isWindow = true);
70 
71     // This API is only for abilityView create RSRenderSurfaceNode in RenderThread.
72     // Do not call this API unless you are sure what you do.
73     // After calling it, this surfaceNode is disallowed to add/remove child.
74     void CreateNodeInRenderThread();
75 
76     void AddChild(std::shared_ptr<RSBaseNode> child, int index) override;
77     void RemoveChild(std::shared_ptr<RSBaseNode> child) override;
78     void ClearChildren() override;
79 
80     void SetSecurityLayer(bool isSecurityLayer);
81     bool GetSecurityLayer() const;
82     void SetSkipLayer(bool isSkipLayer);
83     bool GetSkipLayer() const;
84     void SetFingerprint(bool hasFingerprint);
85     bool GetFingerprint() const;
86     void SetAbilityBGAlpha(uint8_t alpha);
87     void SetIsNotifyUIBufferAvailable(bool available);
88     void MarkUIHidden(bool isHidden);
89 
90     using BufferAvailableCallback = std::function<void()>;
91     bool SetBufferAvailableCallback(BufferAvailableCallback callback);
92     bool IsBufferAvailable() const;
93     using BoundsChangedCallback = std::function<void(const Rosen::Vector4f&)>;
94     void SetBoundsChangedCallback(BoundsChangedCallback callback) override;
95     void SetAnimationFinished();
96 
97     bool Marshalling(Parcel& parcel) const;
98     static SharedPtr Unmarshalling(Parcel& parcel);
99     // Create RSProxyNode by unmarshalling RSSurfaceNode, return existing node if it exists in RSNodeMap.
100     static RSNode::SharedPtr UnmarshallingAsProxyNode(Parcel& parcel);
101 
102     FollowType GetFollowType() const override;
103 
104     void AttachToDisplay(uint64_t screenId);
105     void DetachToDisplay(uint64_t screenId);
106     void SetHardwareEnabled(bool isEnabled, SelfDrawingNodeType selfDrawingType = SelfDrawingNodeType::DEFAULT);
107     void SetBootAnimation(bool isBootAnimation);
108     bool GetBootAnimation() const;
109     void SetTextureExport(bool isTextureExportNode);
110 
111 #ifndef ROSEN_CROSS_PLATFORM
112     sptr<OHOS::Surface> GetSurface() const;
113 #endif
114     void SetColorSpace(GraphicColorGamut colorSpace);
GetColorSpace()115     GraphicColorGamut GetColorSpace()
116     {
117         return colorSpace_;
118     }
119 
GetName()120     std::string GetName() const
121     {
122         return name_;
123     }
124 
GetBundleName()125     const std::string GetBundleName() const
126     {
127         return bundleName_;
128     }
129 
130     void ResetContextAlpha() const;
131 
132     void SetContainerWindow(bool hasContainerWindow, float density);
133     void SetWindowId(uint32_t windowId);
134 
135     void SetFreeze(bool isFreeze) override;
136 #ifdef USE_SURFACE_TEXTURE
137     void SetSurfaceTexture(const RSSurfaceExtConfig& config);
138     void MarkUiFrameAvailable(bool available);
139     void SetSurfaceTextureAttachCallBack(const RSSurfaceTextureAttachCallBack& attachCallback);
140     void SetSurfaceTextureUpdateCallBack(const RSSurfaceTextureUpdateCallBack& updateCallback);
141 #endif
142     void SetForeground(bool isForeground);
143     // Force enable UIFirst when set TRUE
144     void SetForceUIFirst(bool forceUIFirst);
145 
146 protected:
147     bool NeedForcedSendToRemote() const override;
148     RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode);
149     RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id);
150     RSSurfaceNode(const RSSurfaceNode&) = delete;
151     RSSurfaceNode(const RSSurfaceNode&&) = delete;
152     RSSurfaceNode& operator=(const RSSurfaceNode&) = delete;
153     RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete;
154 
155 private:
156 #ifdef USE_SURFACE_TEXTURE
157     void CreateSurfaceExt(const RSSurfaceExtConfig& config);
158 #endif
159     bool CreateNode(const RSSurfaceRenderNodeConfig& config);
160     bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, SurfaceId surfaceId = 0);
161     void OnBoundsSizeChanged() const override;
162     // this function is only used in texture export
163     void SetSurfaceIdToRenderNode();
164     void CreateTextExportRenderNodeInRT();
165     void SetIsTextureExportNode(bool isTextureExportNode);
166     std::pair<std::string, std::string> SplitSurfaceNodeName(std::string surfaceNodeName);
167 #ifdef NEW_RENDER_CONTEXT
168     std::shared_ptr<RSRenderSurface> surface_;
169 #else
170     std::shared_ptr<RSSurface> surface_;
171 #endif
172     std::string name_;
173     std::string bundleName_;
174     mutable std::mutex mutex_;
175     BufferAvailableCallback callback_;
176     bool bufferAvailable_ = false;
177     BoundsChangedCallback boundsChangedCallback_;
178     GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB;
179     bool isSecurityLayer_ = false;
180     bool isSkipLayer_ = false;
181     bool hasFingerprint_ = false;
182     bool isChildOperationDisallowed_ { false };
183     bool isBootAnimation_ = false;
184 
185     uint32_t windowId_ = 0;
186 #ifndef ROSEN_CROSS_PLATFORM
187     sptr<SurfaceDelegate> surfaceDelegate_;
188     sptr<SurfaceDelegate::ISurfaceCallback> surfaceCallback_;
189 #endif
190 
191     friend class RSUIDirector;
192     friend class RSAnimation;
193     friend class RSPathAnimation;
194     friend class RSPropertyAnimation;
195     friend class RSSurfaceExtractor;
196     friend class RSSurfaceCallback;
197 };
198 } // namespace Rosen
199 } // namespace OHOS
200 
201 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H
202