[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / vector-animation-renderer.h
1 #ifndef DALI_VECTOR_ANIMATION_RENDERER_H
2 #define DALI_VECTOR_ANIMATION_RENDERER_H
3
4 /*
5  * Copyright (c) 2023 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/common/dali-vector.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/rendering/renderer.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/dali-adaptor-common.h>
28
29 namespace Dali
30 {
31 /**
32  * @addtogroup dali_adaptor_framework
33  * @{
34  */
35
36 namespace Internal DALI_INTERNAL
37 {
38 namespace Adaptor
39 {
40 class VectorAnimationRenderer;
41 }
42 } // namespace DALI_INTERNAL
43
44 /**
45  * @brief Used for rendering a vector animation file
46  */
47 class DALI_ADAPTOR_API VectorAnimationRenderer : public BaseHandle
48 {
49 public:
50   enum class VectorProperty
51   {
52     FILL_COLOR,         ///< Fill color of the object, Type Property::VECTOR3
53     FILL_OPACITY,       ///< Fill opacity of the object, Type Property::FLOAT
54     STROKE_COLOR,       ///< Stroke color of the object, Type Property::VECTOR3
55     STROKE_OPACITY,     ///< Stroke opacity of the object, Type Property::FLOAT
56     STROKE_WIDTH,       ///< Stroke width of the object, Type Property::FLOAT
57     TRANSFORM_ANCHOR,   ///< Transform anchor of the Layer and Group object, Type Property::VECTOR2
58     TRANSFORM_POSITION, ///< Transform position of the Layer and Group object, Type Property::VECTOR2
59     TRANSFORM_SCALE,    ///< Transform scale of the Layer and Group object, Type Property::VECTOR2 [0..100]
60     TRANSFORM_ROTATION, ///< Transform rotation of the Layer and Group object, Type Property::FLOAT [0..360] in degrees
61     TRANSFORM_OPACITY   ///< Transform opacity of the Layer and Group object, Type Property::FLOAT
62   };
63
64   /// @brief UploadCompleted signal type.
65   using UploadCompletedSignalType = Signal<void()>;
66
67   /**
68    * @brief Creates an initialized handle to a new VectorAnimationRenderer.
69    *
70    * @return A handle to a newly allocated VectorAnimationRenderer
71    */
72   static VectorAnimationRenderer New();
73
74   /**
75    * @brief Creates an empty handle.
76    * Use VectorAnimationRenderer::New() to create an initialized object.
77    */
78   VectorAnimationRenderer();
79
80   /**
81    * @brief Destructor.
82    */
83   ~VectorAnimationRenderer();
84
85   /**
86    * @brief This copy constructor is required for (smart) pointer semantics.
87    *
88    * @param[in] handle A reference to the copied handle
89    */
90   VectorAnimationRenderer(const VectorAnimationRenderer& handle);
91
92   /**
93    * @brief This assignment operator is required for (smart) pointer semantics.
94    *
95    * @param[in] rhs A reference to the copied handle
96    * @return A reference to this
97    */
98   VectorAnimationRenderer& operator=(const VectorAnimationRenderer& rhs);
99
100   /**
101    * @brief Finalizes the renderer.
102    */
103   void Finalize();
104
105   /**
106    * @brief Loads the animation file.
107    *
108    * @param[in] url The url of the vector animation file
109    * @return True if loading success, false otherwise.
110    */
111   bool Load(const std::string& url);
112
113   /**
114    * @brief Loads the animation file by buffer.
115    *
116    * @param[in] data The raw buffer of the vector animation file
117    * @return True if loading success, false otherwise.
118    */
119   bool Load(const Dali::Vector<uint8_t>& data);
120
121   /**
122    * @brief Sets the renderer used to display the result image.
123    *
124    * @param[in] renderer The renderer used to display the result image
125    */
126   void SetRenderer(Renderer renderer);
127
128   /**
129    * @brief Sets the target image size.
130    *
131    * @param[in] width The target image width
132    * @param[in] height The target image height
133    */
134   void SetSize(uint32_t width, uint32_t height);
135
136   /**
137    * @brief Renders the content to the target buffer synchronously.
138    *
139    * @param[in] frameNumber The frame number to be rendered
140    * @return True if the rendering success, false otherwise.
141    */
142   bool Render(uint32_t frameNumber);
143
144   /**
145    * @brief Notify the Renderer that rendering is stopped.
146    */
147   void RenderStopped();
148
149   /**
150    * @brief Gets the total number of frames of the file
151    *
152    * @return The total number of frames
153    */
154   uint32_t GetTotalFrameNumber() const;
155
156   /**
157    * @brief Gets the frame rate of the file.
158    *
159    * @return The frame rate of the file
160    */
161   float GetFrameRate() const;
162
163   /**
164    * @brief Gets the default size of the file.
165    *
166    * @param[out] width The default width of the file
167    * @param[out] height The default height of the file
168    */
169   void GetDefaultSize(uint32_t& width, uint32_t& height) const;
170
171   /**
172    * @brief Gets the layer information of all the child layers.
173    *
174    * @param[out] map The layer information
175    */
176   void GetLayerInfo(Property::Map& map) const;
177
178   /**
179    * @brief Gets the start frame and the end frame number of the composition marker.
180    *
181    * @param[in] marker The composition marker of the file
182    * @param[out] startFrame The start frame number of the specified marker
183    * @param[out] endFrame The end frame number of the specified marker
184    * @return True if the marker is found in the file, false otherwise.
185    *
186    * @note https://helpx.adobe.com/after-effects/using/layer-markers-composition-markers.html
187    * Markers exported from AfterEffect are used to describe a segment of an animation {comment/tag , startFrame, endFrame}
188    * Marker can be use to devide a resource in to separate animations by tagging the segment with comment string,
189    * start frame and duration of that segment.
190    */
191   bool GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const;
192
193   /**
194    * @brief Gets the all composition marker informations.
195    *
196    * @param[out] map The marker information
197    */
198   void GetMarkerInfo(Property::Map& map) const;
199
200   /**
201    * @brief Invalidates the rendered buffer.
202    * @note The upload completed signal will be emitted again.
203    */
204   void InvalidateBuffer();
205
206   /**
207    * @brief Sets property value for the specified keyPath. This keyPath can resolve to multiple contents.
208    * In that case, the callback's value will apply to all of them.
209    *
210    * @param[in] keyPath The key path used to target a specific content or a set of contents that will be updated.
211    * @param[in] property The property to set.
212    * @param[in] callback The callback that gets called every time the animation is rendered.
213    * @param[in] id The Id to specify the callback. It should be unique and will be passed when the callback is called.
214    *
215    * @note A callback of the following type may be used:
216    * id  The id to specify the callback.
217    * property The property that represent what you are trying to change.
218    * frameNumber The current frame number.
219    * It returns a Property::Value to set according to the property type.
220    *
221    * @code
222    *   Property::Value MyFunction(int32_t id, VectorProperty property, uint32_t frameNumber);
223    * @endcode
224    *
225    * The keypath should contain object names separated by (.) and can handle globe(**) or wildchar(*).
226    * Ownership of the callback is passed onto this class.
227    */
228   void AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id);
229
230   /**
231    * @brief Keep the rasterized buffer to use the frame cache.
232    *
233    * By default, only as much as needed is kept in the rasterized buffer and not kept after use.
234    * tis API is efficient in terms of memory, but has the disadvantage of having to load the necessary buffer each time.
235    * therefore, if there are cases in which you want to improve the performance even if the app sacrifices a lot of memory, this API is useful.
236    */
237   void KeepRasterizedBuffer();
238
239 public: // Signals
240   /**
241    * @brief Connect to this signal to be notified when the texture upload is completed.
242    *
243    * @return The signal to connect to.
244    */
245   UploadCompletedSignalType& UploadCompletedSignal();
246
247 public: // Not intended for application developers
248   /// @cond internal
249   /**
250    * @brief The constructor.
251    * @note  Not intended for application developers.
252    *
253    * @param[in] pointer A pointer to a newly allocated VectorAnimationRenderer
254    */
255   explicit DALI_INTERNAL VectorAnimationRenderer(Internal::Adaptor::VectorAnimationRenderer* internal);
256   /// @endcond
257 };
258
259 /**
260  * @}
261  */
262 } // namespace Dali
263
264 #endif // DALI_VECTOR_ANIMATION_RENDERER_H