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