1 #ifndef DALI_VECTOR_ANIMATION_RENDERER_H
2 #define DALI_VECTOR_ANIMATION_RENDERER_H
5 * Copyright (c) 2022 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>
26 #include <dali/public-api/dali-adaptor-common.h>
31 * @addtogroup dali_adaptor_framework
35 namespace Internal DALI_INTERNAL
39 class VectorAnimationRenderer;
41 } // namespace DALI_INTERNAL
44 * @brief Used for rendering a vector animation file
46 class DALI_ADAPTOR_API VectorAnimationRenderer : public BaseHandle
49 enum class VectorProperty
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
63 /// @brief UploadCompleted signal type.
64 using UploadCompletedSignalType = Signal<void()>;
67 * @brief Creates an initialized handle to a new VectorAnimationRenderer.
69 * @return A handle to a newly allocated VectorAnimationRenderer
71 static VectorAnimationRenderer New();
74 * @brief Creates an empty handle.
75 * Use VectorAnimationRenderer::New() to create an initialized object.
77 VectorAnimationRenderer();
82 ~VectorAnimationRenderer();
85 * @brief This copy constructor is required for (smart) pointer semantics.
87 * @param[in] handle A reference to the copied handle
89 VectorAnimationRenderer(const VectorAnimationRenderer& handle);
92 * @brief This assignment operator is required for (smart) pointer semantics.
94 * @param[in] rhs A reference to the copied handle
95 * @return A reference to this
97 VectorAnimationRenderer& operator=(const VectorAnimationRenderer& rhs);
100 * @brief Finalizes the renderer.
105 * @brief Loads the animation file.
107 * @param[in] url The url of the vector animation file
108 * @return True if loading success, false otherwise.
110 bool Load(const std::string& url);
113 * @brief Sets the renderer used to display the result image.
115 * @param[in] renderer The renderer used to display the result image
117 void SetRenderer(Renderer renderer);
120 * @brief Sets the target image size.
122 * @param[in] width The target image width
123 * @param[in] height The target image height
125 void SetSize(uint32_t width, uint32_t height);
128 * @brief Renders the content to the target buffer synchronously.
130 * @param[in] frameNumber The frame number to be rendered
131 * @return True if the rendering success, false otherwise.
133 bool Render(uint32_t frameNumber);
136 * @brief Notify the Renderer that rendering is stopped.
138 void RenderStopped();
141 * @brief Gets the total number of frames of the file
143 * @return The total number of frames
145 uint32_t GetTotalFrameNumber() const;
148 * @brief Gets the frame rate of the file.
150 * @return The frame rate of the file
152 float GetFrameRate() const;
155 * @brief Gets the default size of the file.
157 * @param[out] width The default width of the file
158 * @param[out] height The default height of the file
160 void GetDefaultSize(uint32_t& width, uint32_t& height) const;
163 * @brief Gets the layer information of all the child layers.
165 * @param[out] map The layer information
167 void GetLayerInfo(Property::Map& map) const;
170 * @brief Gets the start frame and the end frame number of the composition marker.
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.
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.
182 bool GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const;
185 * @brief Invalidates the rendered buffer.
186 * @note The upload completed signal will be emitted again.
188 void InvalidateBuffer();
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.
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.
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.
206 * Property::Value MyFunction(int32_t id, VectorProperty property, uint32_t frameNumber);
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.
212 void AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id);
216 * @brief Connect to this signal to be notified when the texture upload is completed.
218 * @return The signal to connect to.
220 UploadCompletedSignalType& UploadCompletedSignal();
222 public: // Not intended for application developers
225 * @brief The constructor.
226 * @note Not intended for application developers.
228 * @param[in] pointer A pointer to a newly allocated VectorAnimationRenderer
230 explicit DALI_INTERNAL VectorAnimationRenderer(Internal::Adaptor::VectorAnimationRenderer* internal);
239 #endif // DALI_VECTOR_ANIMATION_RENDERER_H