• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_drawing_node.h
25  *
26  * @brief Defines the properties and methods for RSCanvasDrawingNode class.
27  */
28 
29 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_DRAWING_NODE_H
30 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_DRAWING_NODE_H
31 
32 #include "pixel_map.h"
33 
34 #include "ui/rs_canvas_node.h"
35 
36 class SkCanvas;
37 
38 namespace OHOS {
39 namespace Rosen {
40 class RSNodeMap;
41 
42 /**
43  * @class RSCanvasDrawingNode
44  *
45  * @brief Represents a drawing node in the rendering service.
46  *
47  * This class is responsible for handling drawing operations on a canvas.
48  */
49 class RSC_EXPORT RSCanvasDrawingNode : public RSCanvasNode {
50 public:
51     using WeakPtr = std::weak_ptr<RSCanvasDrawingNode>;
52     using SharedPtr = std::shared_ptr<RSCanvasDrawingNode>;
53     static inline constexpr RSUINodeType Type = RSUINodeType::CANVAS_DRAWING_NODE;
54 
55     /**
56      * @brief Gets the type of the RSNode.
57      *
58      * @return The type of the RSNode.
59      */
GetType()60     RSUINodeType GetType() const override
61     {
62         return Type;
63     }
64 
65     /**
66      * @brief Destructor for RSCanvasDrawingNode.
67      */
68     ~RSCanvasDrawingNode() override;
69 
70     /**
71      * @brief Create a new RSCanvasDrawingNode instance.
72      *
73      * @param isRenderServiceNode Indicates if the node is a render service node.
74      * @param isTextureExportNode Indicates if the node is a texture export node.
75      * @param rsUIContext The RSUIContext to be used.
76      * @return A shared pointer to the created RSCanvasDrawingNode instance.
77      */
78     static SharedPtr Create(bool isRenderServiceNode = false, bool isTextureExportNode = false,
79         std::shared_ptr<RSUIContext> rsUIContext = nullptr);
80 
81     /**
82      * @brief Gets a bitmap representation of the drawing content.
83      *
84      * @param bitmap The bitmap object to store the retrieved drawing content.
85      * @param drawCmdList Optional parameter specifying a list of drawing commands to apply. Defaults to nullptr.
86      * @param rect Optional parameter specifying the rectangular region to retrieve.
87      * @return true if the bitmap is successfully retrieved; false otherwise.
88      */
89     bool GetBitmap(Drawing::Bitmap& bitmap,
90         std::shared_ptr<Drawing::DrawCmdList> drawCmdList = nullptr, const Drawing::Rect* rect = nullptr);
91 
92     /**
93      * @brief Gets a pixel map representation of the drawing node.
94      *
95      * @param pixelmap A shared pointer to a Media::PixelMap object where the pixel map data will be stored.
96      * @param drawCmdList An optional shared pointer containing drawing commands to be applied. Defaults to nullptr.
97      * @param rect An optional pointer specifying the region of interest.
98      * @return true if the pixel map was successfully retrieved; false otherwise.
99      */
100     bool GetPixelmap(std::shared_ptr<Media::PixelMap> pixelmap,
101         std::shared_ptr<Drawing::DrawCmdList> drawCmdList = nullptr, const Drawing::Rect* rect = nullptr);
102 
103     /**
104      * @brief Resets the surface with the specified width and height.
105      *
106      * @param width The new width of the surface.
107      * @param height The new height of the surface.
108      * @return true if the surface was successfully reset; false otherwise.
109      */
110     bool ResetSurface(int width, int height);
111 
112 protected:
113     RSCanvasDrawingNode(
114         bool isRenderServiceNode, bool isTextureExportNode = false, std::shared_ptr<RSUIContext> rsUIContext = nullptr);
115     RSCanvasDrawingNode(const RSCanvasDrawingNode&) = delete;
116     RSCanvasDrawingNode(const RSCanvasDrawingNode&&) = delete;
117     RSCanvasDrawingNode& operator=(const RSCanvasDrawingNode&) = delete;
118     RSCanvasDrawingNode& operator=(const RSCanvasDrawingNode&&) = delete;
119 
120     /**
121      * @brief Creates a render node for exporting texture with a switch mechanism.
122      */
123     void CreateRenderNodeForTextureExportSwitch() override;
124 private:
125     /**
126      * @brief Registers the node in the node map.
127      */
128     void RegisterNodeMap() override;
129 };
130 } // namespace Rosen
131 } // namespace OHOS
132 
133 /** @} */
134 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_CANVAS_DRAWING_NODE_H