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 16 /** 17 * @addtogroup RenderNodeDisplay 18 * @{ 19 * 20 * @brief Display render nodes. 21 */ 22 23 /** 24 * @file rs_canvas_node.h 25 * 26 * @brief Defines the properties and methods for RSCanvasNode class. 27 */ 28 29 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H 30 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H 31 32 #include "ui/rs_node.h" 33 34 35 namespace OHOS { 36 namespace Rosen { 37 class RSNodeMap; 38 39 /** 40 * @class RSCanvasNode 41 * 42 * @brief Represents a canvas node in the rendering service. 43 */ 44 class RSC_EXPORT RSCanvasNode : public RSNode { 45 public: 46 using WeakPtr = std::weak_ptr<RSCanvasNode>; 47 using SharedPtr = std::shared_ptr<RSCanvasNode>; 48 static inline constexpr RSUINodeType Type = RSUINodeType::CANVAS_NODE; 49 50 /** 51 * @brief Get the type of the RSNode. 52 * 53 * @return The type of the RSNode. 54 */ GetType()55 RSUINodeType GetType() const override 56 { 57 return Type; 58 } 59 60 /** 61 * @brief Destructor for RSCanvasNode. 62 */ 63 ~RSCanvasNode() override; 64 65 /** 66 * @brief Creates a shared pointer to an RSCanvasNode. 67 * 68 * @param isRenderServiceNode Indicates whether the node is a render service node. Defaults to false. 69 * @param isTextureExportNode Indicates whether the node is a texture export node. Defaults to false. 70 * @param rsUIContext A shared pointer to an RSUIContext object. Defaults to nullptr. 71 * @return A shared pointer to the created RSCanvasNode. 72 */ 73 static SharedPtr Create(bool isRenderServiceNode = false, bool isTextureExportNode = false, 74 std::shared_ptr<RSUIContext> rsUIContext = nullptr); 75 76 /** 77 * @brief Begins recording drawing commands on the canvas. 78 * 79 * @param width The width of the recording canvas. 80 * @param height The height of the recording canvas. 81 * @return A pointer to an ExtendRecordingCanvas object for recording drawing commands. 82 */ 83 ExtendRecordingCanvas* BeginRecording(int width, int height); 84 85 /** 86 * @brief Checks if the canvas is currently recording. 87 * 88 * @return true if the canvas is recording; false otherwise. 89 */ 90 bool IsRecording() const; 91 92 /** 93 * @brief Completes the drawing record and add the drawing command. 94 */ 95 void FinishRecording(); 96 97 /** 98 * @brief Gets the width of the paint used in the canvas node. 99 * 100 * @return The width of the paint. 101 */ 102 float GetPaintWidth() const; 103 104 /** 105 * @brief Gets the height of the paint used in the canvas node. 106 * 107 * @return The height of the paint. 108 */ 109 float GetPaintHeight() const; 110 111 /** 112 * @brief Draws on the canvas node using the specified modifier type and drawing function. 113 * 114 * @param type The type of modifier to be applied during the drawing operation. 115 * @param func The drawing function that defines the drawing logic to be executed on the node. 116 */ 117 void DrawOnNode(RSModifierType type, DrawFunc func) override; 118 119 /** 120 * @brief Controls freeze state of canvas node rendering content 121 * 122 * Freezes current frame data when enabled, preventing content refresh until unfrozen. 123 * Used for scenarios requiring static snapshots or temporary rendering suspension. 124 * 125 * @param isFreeze Freeze control flag: 126 * - true: Freeze current content 127 * - false: Resume normal rendering pipeline 128 */ 129 void SetFreeze(bool isFreeze) override; 130 131 /** 132 * @brief Sets the HDR display properties. 133 * 134 * @param hdrPresent True means HDR display; false otherwise. 135 */ 136 void SetHDRPresent(bool hdrPresent); 137 138 /** 139 * @brief Sets the canvas node's color gamut. 140 * 141 * @param colorGamut The enum of ColorSpaceName. 142 */ 143 void SetColorGamut(uint32_t colorGamut); 144 145 /** 146 * @brief Sets the callback function to be called when the bounds of the canvas node change. 147 * 148 * @param callback The function to be called when the bounds change. 149 */ 150 void SetBoundsChangedCallback(BoundsChangedCallback callback) override; 151 152 /** 153 * @brief Set linked node id in PC window resize scenario. 154 * @param rootNodeId source RSRootNode id. 155 */ 156 void SetLinkedRootNodeId(NodeId rootNodeId); 157 158 /** 159 * @brief Get linked node id. 160 * @return RootNode id. 161 */ 162 NodeId GetLinkedRootNodeId(); 163 164 /** 165 * @brief Serializes the RSCanvasNode into a parcel. 166 * 167 * @param parcel The Parcel object where the RSCanvasNode data will be written. 168 * @return true if the serialization is successful; false otherwise. 169 */ 170 bool Marshalling(Parcel& parcel) const; 171 172 /** 173 * @brief Deserializes the RSCanvasNode from a Parcel. 174 * 175 * @param parcel The Parcel object containing the serialized RSCanvasNode data. 176 * @return A shared pointer to the deserialized RSCanvasNode instance. 177 */ 178 static SharedPtr Unmarshalling(Parcel& parcel); 179 180 /** 181 * @brief Sets the hybrid render canvas state. 182 * 183 * @param hybridRenderCanvas True to enable hybrid render canvas; false to disable it. 184 */ SetHybridRenderCanvas(bool hybridRenderCanvas)185 void SetHybridRenderCanvas(bool hybridRenderCanvas) override 186 { 187 hybridRenderCanvas_ = hybridRenderCanvas; 188 } 189 190 /** 191 * @brief Gets a bitmap. 192 * 193 * @param bitmap The bitmap object to store the retrieved drawing content. 194 * @param drawCmdList Optional parameter specifying a list of drawing commands to apply. Defaults to nullptr. 195 * @return true if the bitmap is successfully retrieved; false otherwise. 196 */ 197 bool GetBitmap(Drawing::Bitmap& bitmap, std::shared_ptr<Drawing::DrawCmdList> drawCmdList = nullptr); 198 199 /** 200 * @brief Gets a pixel map. 201 * 202 * @param pixelMap A shared pointer to a Media::PixelMap object where the pixel map data will be stored. 203 * @param drawCmdList An optional shared pointer containing drawing commands to be applied. Defaults to nullptr. 204 * @param rect An optional pointer specifying the region of interest. 205 * @return true if the pixel map was successfully retrieved; false otherwise. 206 */ 207 bool GetPixelmap(std::shared_ptr<Media::PixelMap> pixelMap, 208 std::shared_ptr<Drawing::DrawCmdList> drawCmdList = nullptr, const Drawing::Rect* rect = nullptr); 209 210 /** 211 * @brief Resets the surface with the specified width and height. 212 * 213 * @param width The new width of the surface. 214 * @param height The new height of the surface. 215 * @return true if the surface was successfully reset; false otherwise. 216 */ 217 bool ResetSurface(int width, int height); 218 219 protected: 220 RSCanvasNode( 221 bool isRenderServiceNode, bool isTextureExportNode = false, std::shared_ptr<RSUIContext> rsUIContext = nullptr); 222 RSCanvasNode(bool isRenderServiceNode, NodeId id, bool isTextureExportNode = false, 223 std::shared_ptr<RSUIContext> rsUIContext = nullptr); 224 RSCanvasNode(const RSCanvasNode&) = delete; 225 RSCanvasNode(const RSCanvasNode&&) = delete; 226 RSCanvasNode& operator=(const RSCanvasNode&) = delete; 227 RSCanvasNode& operator=(const RSCanvasNode&&) = delete; 228 BoundsChangedCallback boundsChangedCallback_; 229 230 private: 231 ExtendRecordingCanvas* recordingCanvas_ = nullptr; 232 bool recordingUpdated_ = false; 233 mutable std::mutex mutex_; 234 235 friend class RSUIDirector; 236 friend class RSAnimation; 237 friend class RSPathAnimation; 238 friend class RSPropertyAnimation; 239 friend class RSNodeMap; 240 friend class RSNodeMapV2; 241 void OnBoundsSizeChanged() const override; 242 void CreateRenderNodeForTextureExportSwitch() override; 243 void RegisterNodeMap() override; 244 245 // [Attention] Only used in PC window resize scene now 246 NodeId linkedRootNodeId_ = INVALID_NODEID; 247 }; 248 } // namespace Rosen 249 } // namespace OHOS 250 251 /** @} */ 252 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_NODE_H 253