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 #endif 34 #include "transaction/rs_transaction_proxy.h" 35 #include "ui/rs_node.h" 36 37 #ifndef USE_ROSEN_DRAWING 38 class SkCanvas; 39 #endif 40 41 namespace OHOS { 42 namespace Rosen { 43 44 using BufferAvailableCallback = std::function<void()>; 45 struct RSSurfaceNodeConfig { 46 std::string SurfaceNodeName = "SurfaceNode"; 47 void* additionalData = nullptr; 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 SetFingerprint(bool hasFingerprint); 81 bool GetFingerprint() const; 82 void SetAbilityBGAlpha(uint8_t alpha); 83 void SetIsNotifyUIBufferAvailable(bool available); 84 void MarkUIHidden(bool isHidden); 85 86 bool SetBufferAvailableCallback(BufferAvailableCallback callback); 87 void SetAnimationFinished(); 88 89 bool Marshalling(Parcel& parcel) const; 90 static SharedPtr Unmarshalling(Parcel& parcel); 91 // Create RSProxyNode by unmarshalling RSSurfaceNode, return existing node if it exists in RSNodeMap. 92 static RSNode::SharedPtr UnmarshallingAsProxyNode(Parcel& parcel); 93 94 FollowType GetFollowType() const override; 95 96 void AttachToDisplay(uint64_t screenId); 97 void DetachToDisplay(uint64_t screenId); 98 void SetHardwareEnabled(bool isEnabled); 99 100 #ifndef ROSEN_CROSS_PLATFORM 101 sptr<OHOS::Surface> GetSurface() const; 102 103 void SetColorSpace(GraphicColorGamut colorSpace); GetColorSpace()104 GraphicColorGamut GetColorSpace() 105 { 106 return colorSpace_; 107 } 108 #endif GetName()109 std::string GetName() const 110 { 111 return name_; 112 } 113 GetBundleName()114 const std::string GetBundleName() const 115 { 116 return bundleName_; 117 } 118 119 void ResetContextAlpha() const; 120 121 void SetContainerWindow(bool hasContainerWindow, float density); 122 void SetWindowId(uint32_t windowId); 123 124 void SetFreeze(bool isFreeze) override; 125 126 protected: 127 bool NeedForcedSendToRemote() const override; 128 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode); 129 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id); 130 RSSurfaceNode(const RSSurfaceNode&) = delete; 131 RSSurfaceNode(const RSSurfaceNode&&) = delete; 132 RSSurfaceNode& operator=(const RSSurfaceNode&) = delete; 133 RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete; 134 135 private: 136 bool CreateNode(const RSSurfaceRenderNodeConfig& config); 137 bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 138 void OnBoundsSizeChanged() const override; 139 std::pair<std::string, std::string> SplitSurfaceNodeName(std::string surfaceNodeName); 140 #ifdef NEW_RENDER_CONTEXT 141 std::shared_ptr<RSRenderSurface> surface_; 142 #else 143 std::shared_ptr<RSSurface> surface_; 144 #endif 145 std::string name_; 146 std::string bundleName_; 147 std::mutex mutex_; 148 BufferAvailableCallback callback_; 149 #ifndef ROSEN_CROSS_PLATFORM 150 GraphicColorGamut colorSpace_ = GraphicColorGamut::GRAPHIC_COLOR_GAMUT_SRGB; 151 #endif 152 bool isSecurityLayer_ = false; 153 bool hasFingerprint_ = false; 154 bool isChildOperationDisallowed_ { false }; 155 156 uint32_t windowId_ = 0; 157 #ifndef ROSEN_CROSS_PLATFORM 158 sptr<SurfaceDelegate> surfaceDelegate_; 159 sptr<SurfaceDelegate::ISurfaceCallback> surfaceCallback_; 160 #endif 161 162 friend class RSUIDirector; 163 friend class RSAnimation; 164 friend class RSPathAnimation; 165 friend class RSPropertyAnimation; 166 friend class RSSurfaceExtractor; 167 friend class RSSurfaceCallback; 168 }; 169 } // namespace Rosen 170 } // namespace OHOS 171 172 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H 173