(Vector) Add NOTIFY_AFTER_RASTERIZATION property for low fps file + Use UpdateOnce...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-vector-image / animated-vector-image-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
3
4 /*
5  * Copyright (c) 2024 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/devel-api/actors/actor-devel.h>
23 #include <dali/public-api/adaptor-framework/window.h>
24 #include <dali/public-api/common/intrusive-ptr.h>
25 #include <dali/public-api/object/property-notification.h>
26 #include <dali/public-api/object/weak-handle.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
30 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
31 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
32 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
33 #include <dali-toolkit/internal/visuals/visual-url.h>
34
35 namespace Dali
36 {
37 namespace Toolkit
38 {
39 namespace Internal
40 {
41 class ImageVisualShaderFactory;
42 class AnimatedVectorImageVisual;
43 using AnimatedVectorImageVisualPtr = IntrusivePtr<AnimatedVectorImageVisual>;
44
45 /**
46  * The visual which renders an animated vector image using VectorAnimationRenderer.
47  * VectorAnimationRenderer renders the animation image and this visuall controls the images.
48  *
49  * The following property is essential
50  *
51  * | %Property Name           | Type             |
52  * |--------------------------|------------------|
53  * | url                      | STRING           |
54  *
55  */
56 class AnimatedVectorImageVisual : public Visual::Base, public ConnectionTracker, public VectorAnimationManager::LifecycleObserver
57 {
58 public:
59   /**
60    * @brief Create the AnimatedVectorImageVisual using the image URL.
61    *
62    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
63    * @param[in] shaderFactory The ImageVisualShaderFactory object
64    * @param[in] imageUrl The URL to an animated vector image to use
65    * @param[in] properties A Property::Map containing settings for this visual
66    * @return A smart-pointer to the newly allocated visual.
67    */
68   static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties);
69
70   /**
71    * @brief Create the AnimatedVectorImageVisual using the image URL.
72    *
73    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
74    * @param[in] shaderFactory The ImageVisualShaderFactory object
75    * @param[in] imageUrl The URL to an animated vector image to use
76    * @param[in] size The width and height of the rasterized buffer. The visual size will be used if these are 0.
77    * @return A smart-pointer to the newly allocated visual.
78    */
79   static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size = ImageDimensions());
80
81 public: // from Visual
82   /**
83    * @copydoc Visual::Base::GetNaturalSize
84    */
85   void GetNaturalSize(Vector2& naturalSize) override;
86
87   /**
88    * @copydoc Visual::Base::CreatePropertyMap
89    */
90   void DoCreatePropertyMap(Property::Map& map) const override;
91
92   /**
93    * @copydoc Visual::Base::CreateInstancePropertyMap
94    */
95   void DoCreateInstancePropertyMap(Property::Map& map) const override;
96
97   /**
98    * @copydoc Visual::Base::EnablePreMultipliedAlpha
99    */
100   void EnablePreMultipliedAlpha(bool preMultiplied) override;
101
102 protected: // From VectorAnimationManager::LifecycleObserver:
103   /**
104    * @copydoc VectorAnimationManager::LifecycleObserver::VectorAnimationManagerDestroyed()
105    */
106   void VectorAnimationManagerDestroyed() override;
107
108 protected:
109   /**
110    * @brief Constructor.
111    *
112    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
113    * @param[in] shaderFactory The ImageVisualShaderFactory object
114    * @param[in] imageUrl The URL to an animated vector image to use
115    * @param[in] size The width and height of the rasterized buffer. The visual size will be used if these are 0.
116    */
117   AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size);
118
119   /**
120    * @brief A reference counted object may only be deleted by calling Unreference().
121    */
122   ~AnimatedVectorImageVisual() override;
123
124   /**
125    * @copydoc Visual::Base::OnInitialize
126    */
127   void OnInitialize() override;
128
129   /**
130    * @copydoc Visual::Base::DoSetProperties
131    */
132   void DoSetProperties(const Property::Map& propertyMap) override;
133
134   /**
135    * @copydoc Visual::Base::DoSetOnScene
136    */
137   void DoSetOnScene(Actor& actor) override;
138
139   /**
140    * @copydoc Visual::Base::DoSetOffScene
141    */
142   void DoSetOffScene(Actor& actor) override;
143
144   /**
145    * @copydoc Visual::Base::OnSetTransform
146    */
147   void OnSetTransform() override;
148
149   /**
150    * @copydoc Visual::Base::UpdateShader
151    */
152   void UpdateShader() override;
153
154   /**
155    * @copydoc Visual::Base::GenerateShader
156    */
157   Shader GenerateShader() const override;
158
159   /**
160    * @copydoc Visual::Base::OnDoAction
161    */
162   void OnDoAction(const Property::Index actionId, const Property::Value& attributes) override;
163
164   /**
165    * @copydoc Visual::Base::OnDoActionExtension
166    */
167   void OnDoActionExtension(const Property::Index actionId, Dali::Any attributes) override;
168
169 private:
170   /**
171    * Helper method to set individual values by index key.
172    * @param[in] index The index key of the value
173    * @param[in] value The value
174    */
175   void DoSetProperty(Property::Index index, const Property::Value& value);
176
177   /**
178    * @brief Called when the resource is ready.
179    * @param[in] status The resource status
180    */
181   void OnResourceReady(VectorAnimationTask::ResourceStatus status);
182
183   /**
184    * @brief Event callback from rasterize thread. This is called after the animation is finished.
185    *
186    * @param[in] playStateId The play state id
187    */
188   void OnAnimationFinished(uint32_t playStateId);
189
190   /**
191    * @brief Event callback from rasterize thread. This is called when we want to ensure rendering next frame.
192    *
193    * @param[in] argument Not using arguments
194    */
195   void OnForceRendering(uint32_t argument);
196
197   /**
198    * @brief Send animation data to the rasterize thread.
199    */
200   void SendAnimationData();
201
202   /**
203    * @brief Set the vector image size.
204    */
205   void SetVectorImageSize();
206
207   /**
208    * @brief Stop the animation.
209    */
210   void StopAnimation();
211
212   /**
213    * @brief Trigger rasterization of the vector content.
214    */
215   void TriggerVectorRasterization();
216
217   /**
218    * @brief Callback when the world scale factor changes.
219    */
220   void OnScaleNotification(PropertyNotification& source);
221
222   /**
223    * @brief Callback when the size changes.
224    */
225   void OnSizeNotification(PropertyNotification& source);
226
227   /**
228    * @brief Callback when the visibility of the actor is changed.
229    */
230   void OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type);
231
232   /**
233    * @brief Callback when the visibility of the window is changed.
234    */
235   void OnWindowVisibilityChanged(Window window, bool visible);
236
237   /**
238    * @brief Callback when the event is processed.
239    */
240   void OnProcessEvents();
241
242   // Undefined
243   AnimatedVectorImageVisual(const AnimatedVectorImageVisual& visual) = delete;
244
245   // Undefined
246   AnimatedVectorImageVisual& operator=(const AnimatedVectorImageVisual& visual) = delete;
247
248 private:
249   VisualUrl                          mImageUrl;
250   VectorAnimationTask::AnimationData mAnimationData;
251   VectorAnimationTaskPtr             mVectorAnimationTask;
252   ImageVisualShaderFactory&          mImageVisualShaderFactory;
253   PropertyNotification               mScaleNotification;
254   PropertyNotification               mSizeNotification;
255   Vector2                            mVisualSize;
256   Vector2                            mVisualScale;
257   Dali::ImageDimensions              mDesiredSize{};
258   WeakHandle<Actor>                  mPlacementActor;
259   DevelImageVisual::PlayState::Type  mPlayState;
260   CallbackBase*                      mEventCallback; // Not owned
261
262   uint32_t mLastSentPlayStateId;
263
264   bool mLoadFailed : 1;
265   bool mRendererAdded : 1;
266   bool mCoreShutdown : 1;
267   bool mRedrawInScalingDown : 1;
268   bool mEnableFrameCache : 1;
269   bool mUseNativeImage : 1;
270   bool mNotifyAfterRasterization : 1;
271 };
272
273 } // namespace Internal
274
275 } // namespace Toolkit
276
277 } // namespace Dali
278
279 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H