Merge "CanvasRenderer: Change GetSize() method to const" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / canvas-renderer.h
1 #ifndef DALI_CANVAS_RENDERER_H
2 #define DALI_CANVAS_RENDERER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
26 #include <dali/public-api/dali-adaptor-common.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_adaptor_framework
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 namespace Adaptor
38 {
39 class CanvasRenderer;
40 }
41 } // namespace DALI_INTERNAL
42
43 /**
44  * @brief Used for rendering a vector primitives
45  */
46 class DALI_ADAPTOR_API CanvasRenderer : public BaseHandle
47 {
48 public:
49   /**
50    * @brief Creates an initialized handle to a new CanvasRenderer.
51    * @param[in] viewBox The viewBox of canvas.
52    * @return A handle to a newly allocated CanvasRenderer
53    */
54   static CanvasRenderer New(const Vector2& viewBox);
55
56 public:
57   /**
58    * @brief Creates an empty handle.
59    * Use CanvasRenderer::New() to create an initialized object.
60    */
61   CanvasRenderer();
62
63   /**
64    * @brief Destructor.
65    */
66   ~CanvasRenderer();
67
68 public:
69   /**
70    * @brief This copy constructor is required for (smart) pointer semantics.
71    *
72    * @param[in] handle A reference to the copied handle
73    */
74   CanvasRenderer(const CanvasRenderer& handle) = default;
75
76   /**
77    * @brief This assignment operator is required for (smart) pointer semantics.
78    *
79    * @param[in] rhs A reference to the copied handle
80    * @return A reference to this
81    */
82   CanvasRenderer& operator=(const CanvasRenderer& rhs) = default;
83
84 public:
85   class Drawable;
86   class Shape;
87   class DrawableGroup;
88
89   class Gradient;
90   class LinearGradient;
91   class RadialGradient;
92
93 public:
94   /**
95    * @brief Prepare for drawing drawables added to CanvasRenderer on inner canvas.
96    * @return Returns True when it's successful. False otherwise.
97    */
98   bool Commit();
99
100   /**
101    * @brief Add drawable object to the Canvas. This method is similar to registration.
102    * The added drawable object(shape) is drawn on the inner canvas using @ref Commit().
103    * @param[in] drawable The drawable object.
104    * @return Returns True when it's successful. False otherwise.
105    */
106   bool AddDrawable(Drawable& drawable);
107
108   /**
109    * @brief Remove drawable object to the CanvasView.
110    * This method is similar to deregistration. Freeing memory is not concerned for drawables being removed.
111    * @param[in] drawable the drawable object.
112    * @return Returns True when it's successful. False otherwise.
113    */
114   bool RemoveDrawable(Drawable& drawable);
115
116   /**
117    * @brief Remove all drawable objects added to the CanvasRenderer.
118    * @return Returns True when it's successful. False otherwise.
119    */
120   bool RemoveAllDrawables();
121
122   /**
123    * @brief Returns the PixelBuffer, which is the Render buffer of Canvas.
124    *
125    * @return Returns the pixel buffer.
126    */
127   Devel::PixelBuffer GetPixelBuffer();
128
129   /**
130    * @brief Draw drawables added to CanvasRenderer to inner buffer.
131    * @return Returns True when it's successful. False otherwise.
132    */
133   bool Rasterize();
134
135   /**
136    * @brief Returns whether the drawables added to the Canvas are changed.
137    * @return Returns True when drawables added to the Canvas are changed, False otherwise.
138    */
139   bool IsCanvasChanged() const;
140
141   /**
142    * @brief This is the size of the buffer in the Canvas.
143    * @param[in] size The size of canvas buffer.
144    * @return Returns True when it's successful. False otherwise.
145    */
146   bool SetSize(Vector2 size);
147
148   /**
149    * @brief This is the size of the Buffer in the Canvas.
150    * @return Returns The size of canvas buffer.
151    */
152   Vector2 GetSize() const;
153
154   /**
155    * @brief This is the viewbox of the Canvas.
156    * @param[in] viewBox The size of viewbox.
157    * @return Returns True when it's successful. False otherwise.
158    */
159   bool SetViewBox(const Vector2& viewBox);
160
161   /**
162    * @brief This is the viewbox of the Canvas.
163    * @return Returns The size of viewbox.
164    */
165   const Vector2& GetViewBox();
166
167 public: // Not intended for application developers
168   /// @cond internal
169   /**
170    * @brief The constructor.
171    * @note  Not intended for application developers.
172    *
173    * @param[in] pointer A pointer to a newly allocated CanvasRenderer
174    */
175   explicit DALI_INTERNAL CanvasRenderer(Internal::Adaptor::CanvasRenderer* internal);
176   /// @endcond
177 };
178
179 /**
180  * @}
181  */
182 } // namespace Dali
183
184 #endif // DALI_CANVAS_RENDERER_H