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 69 // This API is only for abilityView create RSRenderSurfaceNode in RenderThread. 70 // Do not call this API unless you are sure what you do. 71 // After calling it, this surfaceNode is disallowed to add/remove child. 72 void CreateNodeInRenderThread(); 73 74 void AddChild(std::shared_ptr<RSBaseNode> child, int index) override; 75 void RemoveChild(std::shared_ptr<RSBaseNode> child) override; 76 void ClearChildren() override; 77 78 void SetSecurityLayer(bool isSecurityLayer); 79 bool GetSecurityLayer() const; 80 void SetLeashPersistentId(LeashPersistentId leashPersistentId); 81 LeashPersistentId GetLeashPersistentId() 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 bool dynamicHardwareEnable = true); 108 void SetForceHardwareAndFixRotation(bool flag); 109 void SetBootAnimation(bool isBootAnimation); 110 bool GetBootAnimation() const; 111 void SetTextureExport(bool isTextureExportNode) override; 112 113 #ifndef ROSEN_CROSS_PLATFORM 114 sptr<OHOS::Surface> GetSurface() const; 115 #endif 116 void SetColorSpace(GraphicColorGamut colorSpace); GetColorSpace()117 GraphicColorGamut GetColorSpace() 118 { 119 return colorSpace_; 120 } 121 GetName()122 inline std::string GetName() const 123 { 124 return name_; 125 } 126 GetBundleName()127 const std::string GetBundleName() const 128 { 129 return bundleName_; 130 } 131 132 void ResetContextAlpha() const; 133 134 void SetContainerWindow(bool hasContainerWindow, float density); 135 void SetWindowId(uint32_t windowId); 136 137 void SetFreeze(bool isFreeze) override; 138 #ifdef USE_SURFACE_TEXTURE 139 void SetSurfaceTexture(const RSSurfaceExtConfig& config); 140 void MarkUiFrameAvailable(bool available); 141 void SetSurfaceTextureAttachCallBack(const RSSurfaceTextureAttachCallBack& attachCallback); 142 void SetSurfaceTextureUpdateCallBack(const RSSurfaceTextureUpdateCallBack& updateCallback); 143 #endif 144 void SetForeground(bool isForeground); 145 // Force enable UIFirst when set TRUE 146 void SetForceUIFirst(bool forceUIFirst); 147 void SetAncoFlags(uint32_t flags); 148 static void SetHDRPresent(bool hdrPresent, NodeId id); 149 void SetSkipDraw(bool skip); 150 bool GetSkipDraw() const; 151 RSInterfaceErrorCode SetHidePrivacyContent(bool needHidePrivacyContent); 152 void SetAbilityState(RSSurfaceNodeAbilityState abilityState); 153 RSSurfaceNodeAbilityState GetAbilityState() const; 154 protected: 155 bool NeedForcedSendToRemote() const override; 156 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode); 157 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id); 158 RSSurfaceNode(const RSSurfaceNode&) = delete; 159 RSSurfaceNode(const RSSurfaceNode&&) = delete; 160 RSSurfaceNode& operator=(const RSSurfaceNode&) = delete; 161 RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete; 162 163 private: 164 #ifdef USE_SURFACE_TEXTURE 165 void CreateSurfaceExt(const RSSurfaceExtConfig& config); 166 #endif 167 bool CreateNode(const RSSurfaceRenderNodeConfig& config); 168 bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config, SurfaceId surfaceId = 0); 169 void OnBoundsSizeChanged() const override; 170 // this function is only used in texture export 171 void SetSurfaceIdToRenderNode(); 172 void CreateRenderNodeForTextureExportSwitch() override; 173 void SetIsTextureExportNode(bool isTextureExportNode); 174 std::pair<std::string, std::string> SplitSurfaceNodeName(std::string surfaceNodeName); 175 #ifdef NEW_RENDER_CONTEXT 176 std::shared_ptr<RSRenderSurface> surface_; 177 #else 178 std::shared_ptr<RSSurface> surface_; 179 #endif 180 std::string name_; 181 std::string bundleName_; 182 mutable std::mutex mutex_; 183 BufferAvailableCallback callback_; 184 bool bufferAvailable_ = false; 185 BoundsChangedCallback boundsChangedCallback_; 186 GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 187 bool isSecurityLayer_ = false; 188 bool isSkipLayer_ = false; 189 bool hasFingerprint_ = false; 190 bool isChildOperationDisallowed_ { false }; 191 bool isBootAnimation_ = false; 192 bool isSkipDraw_ = false; 193 RSSurfaceNodeAbilityState abilityState_ = RSSurfaceNodeAbilityState::FOREGROUND; 194 LeashPersistentId leashPersistentId_ = INVALID_LEASH_PERSISTENTID; 195 196 uint32_t windowId_ = 0; 197 #ifndef ROSEN_CROSS_PLATFORM 198 sptr<SurfaceDelegate> surfaceDelegate_; 199 sptr<SurfaceDelegate::ISurfaceCallback> surfaceCallback_; 200 #endif 201 202 friend class RSUIDirector; 203 friend class RSAnimation; 204 friend class RSPathAnimation; 205 friend class RSPropertyAnimation; 206 friend class RSSurfaceExtractor; 207 friend class RSSurfaceCallback; 208 }; 209 } // namespace Rosen 210 } // namespace OHOS 211 212 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H 213