Merge "Initialize surface before PreRender" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / common / drawable-impl.h
1 #ifndef DALI_INTERNAL_DRAWABLE_IMPL_H
2 #define DALI_INTERNAL_DRAWABLE_IMPL_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-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/canvas-renderer-drawable.h>
26 #include <dali/devel-api/adaptor-framework/canvas-renderer.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Adaptor
33 {
34 /**
35  * Dali internal Drawable.
36  */
37 class Drawable : public Dali::BaseObject
38 {
39 public:
40   /**
41    * @brief Enumeration for type of drawable.
42    */
43   enum class Types
44   {
45     NONE = 0,      ///< Means that type is not defined.
46     SHAPE,         ///< Meaning of Shape class that inherits Drawable.
47     DRAWABLE_GROUP ///< Meaning of DrawableGorup class that inherits Drawable.
48   };
49
50   /**
51    * @brief Enumeration indicating type used in the composition of two objects - the target and the source.
52    */
53   enum class CompositionType
54   {
55     NONE = 0,          ///< Means that type is not defined.
56     CLIP_PATH,         ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered.
57     ALPHA_MASK,        ///< The pixels of the source and the target are alpha blended. As a result, only the part of the source, which intersects with the target is visible.
58     ALPHA_MASK_INVERSE ///< The pixels of the source and the complement to the target's pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible.
59   };
60
61 public:
62   /**
63    * @brief Constructor
64    */
65   Drawable();
66
67   /**
68    * @brief Destructor.
69    */
70   virtual ~Drawable() override;
71
72   /**
73    * @brief Create factory item(implementation) object.
74    */
75   void Create();
76
77   /**
78    * @copydoc Dali::CanvasRenderer::Drawable::SetOpacity()
79    */
80   virtual bool SetOpacity(float opacity);
81
82   /**
83    * @copydoc Dali::CanvasRenderer::Drawable::GetOpacity()
84    */
85   virtual float GetOpacity() const;
86
87   /**
88    * @copydoc Dali::CanvasRenderer::Drawable::Rotate()
89    */
90   virtual bool Rotate(Degree degree);
91
92   /**
93    * @copydoc Dali::CanvasRenderer::Drawable::Scale()
94    */
95   virtual bool Scale(float factor);
96
97   /**
98    * @copydoc Dali::CanvasRenderer::Drawable::Translate()
99    */
100   virtual bool Translate(Vector2 translate);
101
102   /**
103    * @copydoc Dali::CanvasRenderer::Drawable::Transform()
104    */
105   virtual bool Transform(const Dali::Matrix3& matrix);
106
107   /**
108    * @copydoc Dali::CanvasRenderer::Drawable::GetBoundingBox
109    */
110   virtual Rect<float> GetBoundingBox() const;
111
112   /**
113    * @copydoc Dali::CanvasRenderer::Drawable::SetClipPath()
114    */
115   virtual bool SetClipPath(Dali::CanvasRenderer::Drawable& clip);
116
117   /**
118    * @copydoc Dali::CanvasRenderer::Drawable::SetMask()
119    */
120   virtual bool SetMask(Dali::CanvasRenderer::Drawable& mask, Dali::CanvasRenderer::Drawable::MaskType type);
121
122   /**
123    * @brief Returns a composition drawble object.
124    * @return Returns a composition drawble object.
125    */
126   virtual Dali::CanvasRenderer::Drawable GetCompositionDrawable() const;
127
128   /**
129    * @brief Returns a composition type
130    * @return Returns a composition type
131    */
132   virtual CompositionType GetCompositionType() const;
133
134   /**
135    * @brief Set whether this drawable object was added to other object(CanvasRenderer or DrawableGroup) or not.
136    * @param[in] added Ture if added, false otherwise.
137    */
138   virtual void SetAdded(bool added);
139
140   /**
141    * @brief Returns whether this drawable object was added to another object(CanvasRenderer or DrawableGroup).
142    * @return Returns Ture if added, false otherwise.
143    */
144   virtual bool IsAdded() const;
145
146   /**
147    * @brief Returns a drawable object pointer.
148    * @return Returns a drawable object pointer.
149    */
150   virtual void* GetObject() const;
151
152   /**
153    * @brief Set a drawable object
154    * @param[in] object drawable object
155    */
156   virtual void SetObject(const void* object);
157
158   /**
159    * @brief Set a changed state.
160    * @param[in] changed The state of changed.
161    */
162   virtual void SetChanged(bool changed);
163
164   /**
165    * @brief Get a changed state.
166    * @return Returns state of changed.
167    */
168   virtual bool GetChanged() const;
169
170   /**
171    * @brief Set drawable's type.
172    * @param[in] type Type of drawable.
173    */
174   virtual void SetType(Types type);
175
176   /**
177    * @brief Get drawable's type.
178    * @return Returns type of drawable.
179    */
180   virtual Types GetType() const;
181
182   /**
183    * @brief Returns a drawable's implements object pointer.
184    * @return Returns a drawable's implements object pointer.
185    */
186   Dali::Internal::Adaptor::Drawable* GetImplementation();
187
188   Drawable(const Drawable&) = delete;
189   Drawable& operator=(Drawable&) = delete;
190   Drawable(Drawable&&)           = delete;
191   Drawable& operator=(Drawable&&) = delete;
192
193 private:
194   Dali::Internal::Adaptor::Drawable* mImpl = nullptr;
195 };
196
197 } // namespace Adaptor
198
199 } // namespace Internal
200
201 inline static Internal::Adaptor::Drawable& GetImplementation(Dali::CanvasRenderer::Drawable& drawable)
202 {
203   DALI_ASSERT_ALWAYS(drawable && "Drawable handle is empty.");
204
205   BaseObject& handle = drawable.GetBaseObject();
206
207   return static_cast<Internal::Adaptor::Drawable&>(handle);
208 }
209
210 inline static const Internal::Adaptor::Drawable& GetImplementation(const Dali::CanvasRenderer::Drawable& drawable)
211 {
212   DALI_ASSERT_ALWAYS(drawable && "Drawable handle is empty.");
213
214   const BaseObject& handle = drawable.GetBaseObject();
215
216   return static_cast<const Internal::Adaptor::Drawable&>(handle);
217 }
218
219 } // namespace Dali
220
221 #endif // DALI_INTERNAL_DRAWABLE_IMPL_H