Merge "add Padding parameter at RendererParameters" into devel/master
[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) 2020 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/common/intrusive-ptr.h>
23 #include <dali/public-api/object/weak-handle.h>
24 #include <dali/public-api/object/property-notification.h>
25 #include <dali/public-api/adaptor-framework/window.h>
26 #include <dali/devel-api/actors/actor-devel.h>
27
28 // INTERNAL INCLUDES
29 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
30 #include <dali-toolkit/internal/visuals/visual-url.h>
31 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
32 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
33 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-manager.h>
34
35 namespace Dali
36 {
37
38 namespace Toolkit
39 {
40
41 namespace Internal
42 {
43
44 class ImageVisualShaderFactory;
45 class AnimatedVectorImageVisual;
46 using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
47
48 /**
49  * The visual which renders an animated vector image using VectorAnimationRenderer.
50  * VectorAnimationRenderer renders the animation image and this visuall controls the images.
51  *
52  * The following property is essential
53  *
54  * | %Property Name           | Type             |
55  * |--------------------------|------------------|
56  * | url                      | STRING           |
57  *
58  */
59 class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker, public VectorAnimationManager::LifecycleObserver
60 {
61 public:
62
63   /**
64    * @brief Create the AnimatedVectorImageVisual using the image URL.
65    *
66    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
67    * @param[in] shaderFactory The ImageVisualShaderFactory object
68    * @param[in] imageUrl The URL to an animated vector image to use
69    * @param[in] properties A Property::Map containing settings for this visual
70    * @return A smart-pointer to the newly allocated visual.
71    */
72   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
73
74   /**
75    * @brief Create the AnimatedVectorImageVisual using the image URL.
76    *
77    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
78    * @param[in] shaderFactory The ImageVisualShaderFactory object
79    * @param[in] imageUrl The URL to an animated vector image to use
80    * @return A smart-pointer to the newly allocated visual.
81    */
82   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
83
84 public:  // from Visual
85
86   /**
87    * @copydoc Visual::Base::GetNaturalSize
88    */
89   void GetNaturalSize( Vector2& naturalSize ) override;
90
91   /**
92    * @copydoc Visual::Base::CreatePropertyMap
93    */
94   void DoCreatePropertyMap( Property::Map& map ) const override;
95
96   /**
97    * @copydoc Visual::Base::CreateInstancePropertyMap
98    */
99   void DoCreateInstancePropertyMap( Property::Map& map ) const override;
100
101 protected: // From VectorAnimationManager::LifecycleObserver:
102   /**
103    * @copydoc VectorAnimationManager::LifecycleObserver::VectorAnimationManagerDestroyed()
104    */
105   void VectorAnimationManagerDestroyed() override;
106
107 protected:
108
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    */
116   AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
117
118   /**
119    * @brief A reference counted object may only be deleted by calling Unreference().
120    */
121   ~AnimatedVectorImageVisual() override;
122
123   /**
124    * @copydoc Visual::Base::DoSetProperties
125    */
126   void DoSetProperties( const Property::Map& propertyMap ) override;
127
128   /**
129    * @copydoc Visual::Base::DoSetOnScene
130    */
131   void DoSetOnScene( Actor& actor ) override;
132
133   /**
134    * @copydoc Visual::Base::DoSetOffScene
135    */
136   void DoSetOffScene( Actor& actor ) override;
137
138   /**
139    * @copydoc Visual::Base::OnSetTransform
140    */
141   void OnSetTransform() override;
142
143   /**
144    * @copydoc Visual::Base::OnDoAction
145    */
146   void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
147
148 private:
149
150   /**
151    * Helper method to set individual values by index key.
152    * @param[in] index The index key of the value
153    * @param[in] value The value
154    */
155   void DoSetProperty( Property::Index index, const Property::Value& value );
156
157   /**
158    * @brief Called when the texture upload is completed.
159    */
160   void OnUploadCompleted();
161
162   /**
163    * @brief Event callback from rasterize thread. This is called after the animation is finished.
164    */
165   void OnAnimationFinished();
166
167   /**
168    * @brief Send animation data to the rasterize thread.
169    */
170   void SendAnimationData();
171
172   /**
173    * @brief Set the vector image size.
174    */
175   void SetVectorImageSize();
176
177   /**
178    * @brief Stop the animation.
179    */
180   void StopAnimation();
181
182   /**
183    * @brief Trigger rasterization of the vector content.
184    */
185   void TriggerVectorRasterization();
186
187   /**
188    * @brief Callback when the world scale factor changes.
189    */
190   void OnScaleNotification( PropertyNotification& source );
191
192   /**
193    * @brief Callback when the size changes.
194    */
195   void OnSizeNotification( PropertyNotification& source );
196
197   /**
198    * @brief Callback when the visibility of the actor is changed.
199    */
200   void OnControlVisibilityChanged( Actor actor, bool visible, DevelActor::VisibilityChange::Type type );
201
202   /**
203    * @brief Callback when the visibility of the window is changed.
204    */
205   void OnWindowVisibilityChanged( Window window, bool visible );
206
207   /**
208    * @brief Callback when the event is processed.
209    */
210   void OnProcessEvents();
211
212   // Undefined
213   AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
214
215   // Undefined
216   AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
217
218 private:
219   VisualUrl                                    mUrl;
220   VectorAnimationTask::AnimationData           mAnimationData;
221   VectorAnimationTaskPtr                       mVectorAnimationTask;
222   ImageVisualShaderFactory&                    mImageVisualShaderFactory;
223   PropertyNotification                         mScaleNotification;
224   PropertyNotification                         mSizeNotification;
225   Vector2                                      mVisualSize;
226   Vector2                                      mVisualScale;
227   WeakHandle< Actor >                          mPlacementActor;
228   DevelImageVisual::PlayState::Type            mPlayState;
229   CallbackBase*                                mEventCallback;    // Not owned
230   bool                                         mRendererAdded;
231   bool                                         mCoreShutdown;
232   bool                                         mRedrawInScalingDown;
233 };
234
235 } // namespace Internal
236
237 } // namespace Toolkit
238
239 } // namespace Dali
240
241 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H