1 #ifndef DALI_VECTOR_ANIMATION_RENDERER_H
2 #define DALI_VECTOR_ANIMATION_RENDERER_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-handle.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/public-api/common/dali-vector.h>
27 #include <dali/public-api/dali-adaptor-common.h>
32 * @addtogroup dali_adaptor_framework
36 namespace Internal DALI_INTERNAL
40 class VectorAnimationRenderer;
42 } // namespace DALI_INTERNAL
45 * @brief Used for rendering a vector animation file
47 class DALI_ADAPTOR_API VectorAnimationRenderer : public BaseHandle
50 enum class VectorProperty
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
64 /// @brief UploadCompleted signal type.
65 using UploadCompletedSignalType = Signal<void()>;
68 * @brief Creates an initialized handle to a new VectorAnimationRenderer.
70 * @return A handle to a newly allocated VectorAnimationRenderer
72 static VectorAnimationRenderer New();
75 * @brief Creates an empty handle.
76 * Use VectorAnimationRenderer::New() to create an initialized object.
78 VectorAnimationRenderer();
83 ~VectorAnimationRenderer();
86 * @brief This copy constructor is required for (smart) pointer semantics.
88 * @param[in] handle A reference to the copied handle
90 VectorAnimationRenderer(const VectorAnimationRenderer& handle);
93 * @brief This assignment operator is required for (smart) pointer semantics.
95 * @param[in] rhs A reference to the copied handle
96 * @return A reference to this
98 VectorAnimationRenderer& operator=(const VectorAnimationRenderer& rhs);
101 * @brief Finalizes the renderer.
106 * @brief Loads the animation file.
108 * @param[in] url The url of the vector animation file
109 * @return True if loading success, false otherwise.
111 bool Load(const std::string& url);
114 * @brief Loads the animation file by buffer.
116 * @param[in] data The raw buffer of the vector animation file
117 * @return True if loading success, false otherwise.
119 bool Load(const Dali::Vector<uint8_t>& data);
122 * @brief Sets the renderer used to display the result image.
124 * @param[in] renderer The renderer used to display the result image
126 void SetRenderer(Renderer renderer);
129 * @brief Sets the target image size.
131 * @param[in] width The target image width
132 * @param[in] height The target image height
134 void SetSize(uint32_t width, uint32_t height);
137 * @brief Renders the content to the target buffer synchronously.
139 * @param[in] frameNumber The frame number to be rendered
140 * @return True if the rendering success, false otherwise.
142 bool Render(uint32_t frameNumber);
145 * @brief Notify the Renderer that rendering is stopped.
147 void RenderStopped();
150 * @brief Gets the total number of frames of the file
152 * @return The total number of frames
154 uint32_t GetTotalFrameNumber() const;
157 * @brief Gets the frame rate of the file.
159 * @return The frame rate of the file
161 float GetFrameRate() const;
164 * @brief Gets the default size of the file.
166 * @param[out] width The default width of the file
167 * @param[out] height The default height of the file
169 void GetDefaultSize(uint32_t& width, uint32_t& height) const;
172 * @brief Gets the layer information of all the child layers.
174 * @param[out] map The layer information
176 void GetLayerInfo(Property::Map& map) const;
179 * @brief Gets the start frame and the end frame number of the composition marker.
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.
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.
191 bool GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const;
194 * @brief Invalidates the rendered buffer.
195 * @note The upload completed signal will be emitted again.
197 void InvalidateBuffer();
200 * @brief Sets property value for the specified keyPath. This keyPath can resolve to multiple contents.
201 * In that case, the callback's value will apply to all of them.
203 * @param[in] keyPath The key path used to target a specific content or a set of contents that will be updated.
204 * @param[in] property The property to set.
205 * @param[in] callback The callback that gets called every time the animation is rendered.
206 * @param[in] id The Id to specify the callback. It should be unique and will be passed when the callback is called.
208 * @note A callback of the following type may be used:
209 * id The id to specify the callback.
210 * property The property that represent what you are trying to change.
211 * frameNumber The current frame number.
212 * It returns a Property::Value to set according to the property type.
215 * Property::Value MyFunction(int32_t id, VectorProperty property, uint32_t frameNumber);
218 * The keypath should contain object names separated by (.) and can handle globe(**) or wildchar(*).
219 * Ownership of the callback is passed onto this class.
221 void AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id);
225 * @brief Connect to this signal to be notified when the texture upload is completed.
227 * @return The signal to connect to.
229 UploadCompletedSignalType& UploadCompletedSignal();
231 public: // Not intended for application developers
234 * @brief The constructor.
235 * @note Not intended for application developers.
237 * @param[in] pointer A pointer to a newly allocated VectorAnimationRenderer
239 explicit DALI_INTERNAL VectorAnimationRenderer(Internal::Adaptor::VectorAnimationRenderer* internal);
248 #endif // DALI_VECTOR_ANIMATION_RENDERER_H