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