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 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 }; 49 50 class RSC_EXPORT RSSurfaceNode : public RSNode { 51 public: 52 static constexpr float POINTER_WINDOW_POSITION_Z = 9999; 53 54 using WeakPtr = std::weak_ptr<RSSurfaceNode>; 55 using SharedPtr = std::shared_ptr<RSSurfaceNode>; 56 static inline constexpr RSUINodeType Type = RSUINodeType::SURFACE_NODE; GetType()57 RSUINodeType GetType() const override 58 { 59 return Type; 60 } 61 62 ~RSSurfaceNode() override; 63 64 static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow = true); 65 66 // This interface is only available for WMS 67 static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, RSSurfaceNodeType type, bool isWindow = true, 68 bool unobscured = false); 69 70 // This API is only for abilityView create RSRenderSurfaceNode in RenderThread. 71 // Do not call this API unless you are sure what you do. 72 // After calling it, this surfaceNode is disallowed to add/remove child. 73 void CreateNodeInRenderThread(); 74 75 void AddChild(std::shared_ptr<RSBaseNode> child, int index) override; 76 void RemoveChild(std::shared_ptr<RSBaseNode> child) override; 77 void ClearChildren() override; 78 79 void SetSecurityLayer(bool isSecurityLayer); 80 bool GetSecurityLayer() const; 81 void SetLeashPersistentId(LeashPersistentId leashPersistentId); 82 LeashPersistentId GetLeashPersistentId() const; 83 void SetSkipLayer(bool isSkipLayer); 84 bool GetSkipLayer() const; 85 void SetSnapshotSkipLayer(bool isSnapshotSkipLayer); 86 bool GetSnapshotSkipLayer() const; 87 void SetFingerprint(bool hasFingerprint); 88 bool GetFingerprint() const; 89 void SetAbilityBGAlpha(uint8_t alpha); 90 void SetIsNotifyUIBufferAvailable(bool available); 91 void MarkUIHidden(bool isHidden); 92 93 using BufferAvailableCallback = std::function<void()>; 94 bool SetBufferAvailableCallback(BufferAvailableCallback callback); 95 bool IsBufferAvailable() const; 96 using BoundsChangedCallback = std::function<void(const Rosen::Vector4f&)>; 97 void SetBoundsChangedCallback(BoundsChangedCallback callback) override; 98 void SetAnimationFinished(); 99 100 bool Marshalling(Parcel& parcel) const; 101 static SharedPtr Unmarshalling(Parcel& parcel); 102 // Create RSProxyNode by unmarshalling RSSurfaceNode, return existing node if it exists in RSNodeMap. 103 static RSNode::SharedPtr UnmarshallingAsProxyNode(Parcel& parcel); 104 105 FollowType GetFollowType() const override; 106 107 void AttachToDisplay(uint64_t screenId); 108 void DetachToDisplay(uint64_t screenId); 109 void SetHardwareEnabled(bool isEnabled, SelfDrawingNodeType selfDrawingType = SelfDrawingNodeType::DEFAULT, 110 bool dynamicHardwareEnable = true); 111 void SetForceHardwareAndFixRotation(bool flag); 112 void SetBootAnimation(bool isBootAnimation); 113 bool GetBootAnimation() const; 114 void SetTextureExport(bool isTextureExportNode) override; 115 116 #ifndef ROSEN_CROSS_PLATFORM 117 sptr<OHOS::Surface> GetSurface() const; 118 #endif 119 void SetColorSpace(GraphicColorGamut colorSpace); GetColorSpace()120 GraphicColorGamut GetColorSpace() 121 { 122 return colorSpace_; 123 } 124 GetName()125 inline std::string GetName() const 126 { 127 return name_; 128 } 129 GetBundleName()130 const std::string GetBundleName() const 131 { 132 return bundleName_; 133 } 134 135 void ResetContextAlpha() const; 136 137 void SetContainerWindow(bool hasContainerWindow, float density); 138 void SetWindowId(uint32_t windowId); 139 140 void SetFreeze(bool isFreeze) override; 141 // codes for arkui-x 142 #ifdef USE_SURFACE_TEXTURE 143 void SetSurfaceTexture(const RSSurfaceExtConfig& config); 144 void MarkUiFrameAvailable(bool available); 145 void SetSurfaceTextureAttachCallBack(const RSSurfaceTextureAttachCallBack& attachCallback); 146 void SetSurfaceTextureUpdateCallBack(const RSSurfaceTextureUpdateCallBack& updateCallback); 147 void SetSurfaceTextureInitTypeCallBack(const RSSurfaceTextureInitTypeCallBack& initTypeCallback); 148 #endif 149 void SetForeground(bool isForeground); 150 // Force enable UIFirst when set TRUE 151 void SetForceUIFirst(bool forceUIFirst); 152 void SetAncoFlags(uint32_t flags); 153 static void SetHDRPresent(bool hdrPresent, NodeId id); 154 void SetSkipDraw(bool skip); 155 bool GetSkipDraw() const; 156 RSInterfaceErrorCode SetHidePrivacyContent(bool needHidePrivacyContent); 157 void SetAbilityState(RSSurfaceNodeAbilityState abilityState); 158 RSSurfaceNodeAbilityState GetAbilityState() const; 159 160 void AttachToWindowContainer(ScreenId screenId); 161 void DetachFromWindowContainer(ScreenId screenId); 162 protected: 163 bool NeedForcedSendToRemote() const override; 164 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode); 165 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id); 166 RSSurfaceNode(const RSSurfaceNode&) = delete; 167 RSSurfaceNode(const RSSurfaceNode&&) = delete; 168 RSSurfaceNode& operator=(const RSSurfaceNode&) = delete; 169 RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete; 170 171 private: 172 #ifdef USE_SURFACE_TEXTURE 173 void CreateSurfaceExt(const RSSurfaceExtConfig& config); 174 #endif 175 bool CreateNode(const RSSurfaceRenderNodeConfig& config); 176 bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, SurfaceId surfaceId = 0, 177 bool unobscured = false); 178 void OnBoundsSizeChanged() const override; 179 // this function is only used in texture export 180 void SetSurfaceIdToRenderNode(); 181 void CreateRenderNodeForTextureExportSwitch() override; 182 void SetIsTextureExportNode(bool isTextureExportNode); 183 std::pair<std::string, std::string> SplitSurfaceNodeName(std::string surfaceNodeName); 184 #ifdef NEW_RENDER_CONTEXT 185 std::shared_ptr<RSRenderSurface> surface_; 186 #else 187 std::shared_ptr<RSSurface> surface_; 188 #endif 189 std::string name_; 190 std::string bundleName_; 191 mutable std::mutex mutex_; 192 BufferAvailableCallback callback_; 193 bool bufferAvailable_ = false; 194 BoundsChangedCallback boundsChangedCallback_; 195 GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 196 bool isSecurityLayer_ = false; 197 bool isSkipLayer_ = false; 198 bool isSnapshotSkipLayer_ = false; 199 bool hasFingerprint_ = false; 200 bool isChildOperationDisallowed_ { false }; 201 bool isBootAnimation_ = false; 202 bool isSkipDraw_ = false; 203 RSSurfaceNodeAbilityState abilityState_ = RSSurfaceNodeAbilityState::FOREGROUND; 204 LeashPersistentId leashPersistentId_ = INVALID_LEASH_PERSISTENTID; 205 206 uint32_t windowId_ = 0; 207 #ifndef ROSEN_CROSS_PLATFORM 208 sptr<SurfaceDelegate> surfaceDelegate_; 209 sptr<SurfaceDelegate::ISurfaceCallback> surfaceCallback_; 210 #endif 211 212 std::mutex apiInitMutex_; 213 214 friend class RSUIDirector; 215 friend class RSAnimation; 216 friend class RSPathAnimation; 217 friend class RSPropertyAnimation; 218 friend class RSSurfaceExtractor; 219 friend class RSSurfaceCallback; 220 }; 221 } // namespace Rosen 222 } // namespace OHOS 223 224 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H 225