[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / vector-animation-renderer-plugin.h
1 #ifndef DALI_VECTOR_ANIMATION_RENDERER_PLUGIN_H
2 #define DALI_VECTOR_ANIMATION_RENDERER_PLUGIN_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/rendering/renderer.h>
23 #include <string>
24
25 // INTERNAL INCLUDES
26 #include <dali/devel-api/adaptor-framework/vector-animation-renderer.h>
27
28 namespace Dali
29 {
30 /**
31  * VectorAnimationRendererPlugin is an abstract interface, used by dali-adaptor to render a vector animation.
32  * A concrete implementation must be created for each platform and provided as a dynamic library which
33  * will be loaded at run time by the adaptor.
34  */
35 class VectorAnimationRendererPlugin
36 {
37 public:
38   using UploadCompletedSignalType = Dali::VectorAnimationRenderer::UploadCompletedSignalType;
39   using VectorProperty            = Dali::VectorAnimationRenderer::VectorProperty;
40
41   /**
42    * @brief Constructor
43    */
44   VectorAnimationRendererPlugin()
45   {
46   }
47
48   /**
49    * @brief Destructor
50    */
51   virtual ~VectorAnimationRendererPlugin()
52   {
53   }
54
55   /**
56    * @brief Finalizes the renderer. It will be called in the main thread.
57    */
58   virtual void Finalize() = 0;
59
60   /**
61    * @brief Loads the animation file.
62    *
63    * @param[in] url The url of the vector animation file
64    * @return True if loading success, false otherwise.
65    */
66   virtual bool Load(const std::string& url) = 0;
67
68   /**
69    * @brief Loads the animation file by buffer.
70    *
71    * @param[in] data The raw buffer of the vector animation file
72    * @return True if loading success, false otherwise.
73    */
74   virtual bool Load(const Dali::Vector<uint8_t>& data) = 0;
75
76   /**
77    * @brief Sets the renderer used to display the result image.
78    *
79    * @param[in] renderer The renderer used to display the result image
80    */
81   virtual void SetRenderer(Renderer renderer) = 0;
82
83   /**
84    * @brief Sets the target image size.
85    *
86    * @param[in] width The target image width
87    * @param[in] height The target image height
88    */
89   virtual void SetSize(uint32_t width, uint32_t height) = 0;
90
91   /**
92    * @brief Renders the content to the target buffer synchronously.
93    *
94    * @param[in] frameNumber The frame number to be rendered
95    * @return True if the rendering success, false otherwise.
96    */
97   virtual bool Render(uint32_t frameNumber) = 0;
98
99   /**
100    * @brief Notify the Renderer that rendering is stopped.
101    */
102   virtual void RenderStopped() = 0;
103
104   /**
105    * @brief Gets the total number of frames of the file.
106    *
107    * @return The total number of frames
108    */
109   virtual uint32_t GetTotalFrameNumber() const = 0;
110
111   /**
112    * @brief Gets the frame rate of the file.
113    *
114    * @return The frame rate of the file
115    */
116   virtual float GetFrameRate() const = 0;
117
118   /**
119    * @brief Gets the default size of the file.
120    *
121    * @param[out] width The default width of the file
122    * @param[out] height The default height of the file
123    */
124   virtual void GetDefaultSize(uint32_t& width, uint32_t& height) const = 0;
125
126   /**
127    * @brief Gets the layer information of all the child layers.
128    *
129    * @param[out] map The layer information
130    */
131   virtual void GetLayerInfo(Property::Map& map) const = 0;
132
133   /**
134    * @brief Gets the start frame and the end frame number of the composition marker.
135    *
136    * @param[in] marker The composition marker of the file
137    * @param[out] startFrame The start frame number of the specified marker
138    * @param[out] endFrame The end frame number of the specified marker
139    * @return True if the marker is found in the file, false otherwise.
140    *
141    * @note https://helpx.adobe.com/after-effects/using/layer-markers-composition-markers.html
142    * Markers exported from AfterEffect are used to describe a segment of an animation {comment/tag , startFrame, endFrame}
143    * Marker can be use to devide a resource in to separate animations by tagging the segment with comment string,
144    * start frame and duration of that segment.
145    */
146   virtual bool GetMarkerInfo(const std::string& marker, uint32_t& startFrame, uint32_t& endFrame) const = 0;
147
148   /**
149    * @brief Gets the all composition marker informations.
150    *
151    * @param[out] map The marker information
152    */
153   virtual void GetMarkerInfo(Property::Map& map) const = 0;
154
155   /**
156    * @brief Invalidates the rendered buffer.
157    * @note The upload completed signal will be emitted again.
158    */
159   virtual void InvalidateBuffer() = 0;
160
161   /**
162    * @brief Sets property value for the specified keyPath. This keyPath can resolve to multiple contents.
163    * In that case, the callback's value will apply to all of them.
164    *
165    * @param[in] keyPath The key path used to target a specific content or a set of contents that will be updated.
166    * @param[in] property The property to set.
167    * @param[in] callback The callback what gets called every time the animation is rendered.
168    * @param[in] id The Id to specify the callback. It should be unique and will be passed when the callback is called.
169    *
170    * @note A callback of the following type may be used:
171    * id  The id to specify the callback.
172    * property The property that represent what you are trying to change.
173    * frameNumber The current frame number.
174    * It returns a Property::Value to set according to the property type.
175    *
176    * @code
177    *   Property::Value MyFunction(int32_t id, VectorProperty property, uint32_t frameNumber);
178    * @endcode
179    *
180    * The keypath should conatin object names separated by (.) and can handle globe(**) or wildchar(*).
181    * Ownership of the callback is passed onto this class.
182    */
183   virtual void AddPropertyValueCallback(const std::string& keyPath, VectorProperty property, CallbackBase* callback, int32_t id) = 0;
184
185   virtual void KeepRasterizedBuffer() = 0;
186
187   /**
188    * @brief Connect to this signal to be notified when the texture upload is completed.
189    *
190    * @return The signal to connect to.
191    */
192   virtual UploadCompletedSignalType& UploadCompletedSignal() = 0;
193
194   /**
195    * @brief Function pointer called in adaptor to create a plugin instance.
196    */
197   using CreateVectorAnimationRendererFunction = VectorAnimationRendererPlugin* (*)();
198 };
199
200 } // namespace Dali
201
202 #endif // DALI_VECTOR_ANIMATION_RENDERER_PLUGIN_H