1 /* 2 * Copyright (c) 2022-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 16 /** 17 * @addtogroup RenderNodeDisplay 18 * @{ 19 * 20 * @brief Display render nodes. 21 */ 22 23 /** 24 * @file rs_proxy_node.h 25 * 26 * @brief Defines the properties and methods for RSProxyNode class. 27 */ 28 29 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_PROXY_NODE_H 30 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_PROXY_NODE_H 31 32 #include <parcel.h> 33 #include <string> 34 35 #include "ui/rs_node.h" 36 37 namespace OHOS { 38 namespace Rosen { 39 40 /** 41 * @class RSProxyNode 42 * 43 * @brief Represents a proxy node in the rendering service. 44 */ 45 class RSC_EXPORT RSProxyNode : public RSNode { 46 public: 47 using WeakPtr = std::weak_ptr<RSProxyNode>; 48 using SharedPtr = std::shared_ptr<RSProxyNode>; 49 static inline constexpr RSUINodeType Type = RSUINodeType::PROXY_NODE; 50 51 /** 52 * @brief Get the type of the RSNode. 53 * 54 * @return The type of the RSNode. 55 */ GetType()56 RSUINodeType GetType() const override 57 { 58 return Type; 59 } 60 61 /** 62 * @brief Creates a shared pointer to a ProxyNode instance. 63 * 64 * @param targetNodeId The ID of the target node to be associated with the ProxyNode. 65 * @param name The name of the ProxyNode. Defaults to "ProxyNode" if not specified. 66 * @param rsUIContext A shared pointer to the RSUIContext. Defaults to nullptr if not specified. 67 * @return A shared pointer to the newly created ProxyNode instance. 68 */ 69 static SharedPtr Create( 70 NodeId targetNodeId, std::string name = "ProxyNode", std::shared_ptr<RSUIContext> rsUIContext = nullptr); 71 72 /** 73 * @brief Destructor for RSProxyNode. 74 */ 75 ~RSProxyNode() override; 76 77 /** 78 * @brief Resets the context variable cache for the proxy node. 79 */ 80 void ResetContextVariableCache() const; 81 82 /** 83 * @brief Get the name of the node. 84 * 85 * @return A string representing the name of the node. 86 */ GetName()87 const std::string& GetName() const 88 { 89 return name_; 90 } 91 92 /** 93 * @brief Adds a child node to the current node at the specified index. 94 * 95 * @param child The shared pointer to the child node to be added. 96 * @param index The position at which the child node should be inserted. 97 * If the index is -1 (default), the child is added to the end. 98 */ 99 void AddChild(std::shared_ptr<RSBaseNode> child, int index) override; 100 101 /** 102 * @brief Removes a child node from the current node. 103 * 104 * @param child A shared pointer to the child node to be removed. 105 */ 106 void RemoveChild(std::shared_ptr<RSBaseNode> child) override; 107 108 /** 109 * @brief Removes all child nodes associated with this node. 110 */ 111 void ClearChildren() override; 112 113 /** 114 * @brief Sets the bounds of the node. 115 * 116 * @param bounds A Vector4f representing the new bounds (X, Y, width, height). 117 */ SetBounds(const Vector4f & bounds)118 void SetBounds(const Vector4f& bounds) override {} 119 120 /** 121 * @brief Sets the bounds of the node. 122 * 123 * @param positionX The X coordinate of the new bounds. 124 * @param positionY The Y coordinate of the new bounds. 125 * @param width The width of the new bounds. 126 * @param height The height of the new bounds. 127 */ SetBounds(float positionX,float positionY,float width,float height)128 void SetBounds(float positionX, float positionY, float width, float height) override {} 129 130 /** 131 * @brief Sets the width of the node's bounds. 132 * 133 * @param width The new width to set for the node's bounds. 134 */ SetBoundsWidth(float width)135 void SetBoundsWidth(float width) override {} 136 137 /** 138 * @brief Sets the height of the node's bounds. 139 * 140 * @param height The new height to set for the node's bounds. 141 */ SetBoundsHeight(float height)142 void SetBoundsHeight(float height) override {} 143 144 /** 145 * @brief Sets the frame of the node. 146 * 147 * @param frame A Vector4f representing the new frame, containing values for x, y, width, and height. 148 */ SetFrame(const Vector4f & frame)149 void SetFrame(const Vector4f& frame) override {} 150 151 /** 152 * @brief Sets the frame of the node. 153 * 154 * @param positionX The X coordinate of the frame. 155 * @param positionY The Y coordinate of the frame. 156 * @param width The width of the frame. 157 * @param height The height of the frame. 158 */ SetFrame(float positionX,float positionY,float width,float height)159 void SetFrame(float positionX, float positionY, float width, float height) override {} 160 161 /** 162 * @brief Sets the X coordinate of the node's frame. 163 * 164 * @param positionX The X coordinate of the frame. 165 */ SetFramePositionX(float positionX)166 void SetFramePositionX(float positionX) override {} 167 168 /** 169 * @brief Sets the Y coordinate of the node's frame. 170 * 171 * @param positionY The Y coordinate of the frame. 172 */ SetFramePositionY(float positionY)173 void SetFramePositionY(float positionY) override {} 174 175 protected: 176 explicit RSProxyNode(NodeId targetNodeId, std::string name, std::shared_ptr<RSUIContext> rsUIContext = nullptr); 177 178 /** 179 * @brief Retrieves the NodeId associated with the hierarchy command for this proxy node. 180 * 181 * when add/remove/update child, construct command using proxy node id, not target node id 182 * 183 * @return The NodeId of the hierarchy command node. 184 */ GetHierarchyCommandNodeId()185 NodeId GetHierarchyCommandNodeId() const override 186 { 187 return proxyNodeId_; 188 } 189 190 private: 191 /** 192 * @brief Creates a proxy render node for rendering operations. 193 */ 194 void CreateProxyRenderNode(); 195 196 /** 197 * @brief Registers the node in the node map. 198 */ 199 void RegisterNodeMap() override; 200 NodeId proxyNodeId_; 201 std::string name_; 202 }; 203 } // namespace Rosen 204 } // namespace OHOS 205 206 /** @} */ 207 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_PROXY_NODE_H 208