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 "surface.h" 24 #include "surface_delegate.h" 25 #include "surface_type.h" 26 #endif 27 28 #include "platform/drawing/rs_surface.h" 29 #include "transaction/rs_transaction_proxy.h" 30 #include "ui/rs_node.h" 31 32 class SkCanvas; 33 34 namespace OHOS { 35 namespace Rosen { 36 37 using BufferAvailableCallback = std::function<void()>; 38 struct RSSurfaceNodeConfig { 39 std::string SurfaceNodeName = "SurfaceNode"; 40 UseSurfaceToRenderFunc onRender = nullptr; 41 }; 42 43 class RSC_EXPORT RSSurfaceNode : public RSNode { 44 public: 45 using WeakPtr = std::weak_ptr<RSSurfaceNode>; 46 using SharedPtr = std::shared_ptr<RSSurfaceNode>; 47 static inline constexpr RSUINodeType Type = RSUINodeType::SURFACE_NODE; GetType()48 RSUINodeType GetType() const override 49 { 50 return Type; 51 } 52 53 ~RSSurfaceNode() override; 54 55 static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, bool isWindow = true); 56 57 // This interface is only available for WMS 58 static SharedPtr Create(const RSSurfaceNodeConfig& surfaceNodeConfig, RSSurfaceNodeType type, bool isWindow = true); 59 60 // This API is only for abilityView create RSRenderSurfaceNode in RenderThread. 61 // Do not call this API unless you are sure what you do. 62 // After calling it, this surfaceNode is disallowed to add/remove child. 63 void CreateNodeInRenderThread(); 64 65 void AddChild(std::shared_ptr<RSBaseNode> child, int index) override; 66 void RemoveChild(std::shared_ptr<RSBaseNode> child) override; 67 void ClearChildren() override; 68 69 void SetSecurityLayer(bool isSecurityLayer); 70 bool GetSecurityLayer() const; 71 void SetAbilityBGAlpha(uint8_t alpha); 72 void SetIsNotifyUIBufferAvailable(bool available); 73 74 bool SetBufferAvailableCallback(BufferAvailableCallback callback); 75 void SetAnimationFinished(); 76 77 bool Marshalling(Parcel& parcel) const; 78 static SharedPtr Unmarshalling(Parcel& parcel); 79 // Create RSProxyNode by unmarshalling RSSurfaceNode, return existing node if it exists in RSNodeMap. 80 static RSNode::SharedPtr UnmarshallingAsProxyNode(Parcel& parcel); 81 82 FollowType GetFollowType() const override; 83 84 #ifndef ROSEN_CROSS_PLATFORM 85 sptr<OHOS::Surface> GetSurface() const; 86 87 void SetColorSpace(ColorGamut colorSpace); GetColorSpace()88 ColorGamut GetColorSpace() 89 { 90 return colorSpace_; 91 } 92 #endif GetName()93 std::string GetName() const 94 { 95 return name_; 96 } 97 98 void ResetContextAlpha() const; 99 100 void SetAppFreeze(bool isAppFreeze); 101 void SetContainerWindow(bool hasContainerWindow, float density); 102 void SetWindowId(uint32_t windowId); 103 104 protected: 105 bool NeedForcedSendToRemote() const override; 106 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode); 107 RSSurfaceNode(const RSSurfaceNodeConfig& config, bool isRenderServiceNode, NodeId id); 108 RSSurfaceNode(const RSSurfaceNode&) = delete; 109 RSSurfaceNode(const RSSurfaceNode&&) = delete; 110 RSSurfaceNode& operator=(const RSSurfaceNode&) = delete; 111 RSSurfaceNode& operator=(const RSSurfaceNode&&) = delete; 112 113 private: 114 bool CreateNode(const RSSurfaceRenderNodeConfig& config); 115 bool CreateNodeAndSurface(const RSSurfaceRenderNodeConfig& config); 116 void OnBoundsSizeChanged() const override; 117 std::shared_ptr<RSSurface> surface_; 118 std::string name_; 119 std::mutex mutex_; 120 BufferAvailableCallback callback_; 121 #ifndef ROSEN_CROSS_PLATFORM 122 ColorGamut colorSpace_ = ColorGamut::COLOR_GAMUT_SRGB; 123 #endif 124 bool isSecurityLayer_ = false; 125 bool isChildOperationDisallowed_ { false }; 126 127 uint32_t windowId_; 128 #ifndef ROSEN_CROSS_PLATFORM 129 sptr<SurfaceDelegate> surfaceDelegate_; 130 sptr<SurfaceDelegate::ISurfaceCallback> surfaceCallback_; 131 #endif 132 133 friend class RSUIDirector; 134 friend class RSAnimation; 135 friend class RSPathAnimation; 136 friend class RSPropertyAnimation; 137 friend class RSSurfaceExtractor; 138 friend class RSSurfaceCallback; 139 }; 140 } // namespace Rosen 141 } // namespace OHOS 142 143 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_SURFACE_NODE_H 144