(Vector) Refactor vector to use thread pool
[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) 2019 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
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
28 #include <dali-toolkit/internal/visuals/visual-url.h>
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-task.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
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
57 {
58 public:
59
60   /**
61    * @brief Create the AnimatedVectorImageVisual using the image URL.
62    *
63    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
64    * @param[in] shaderFactory The ImageVisualShaderFactory object
65    * @param[in] imageUrl The URL to an animated vector image to use
66    * @param[in] properties A Property::Map containing settings for this visual
67    * @return A smart-pointer to the newly allocated visual.
68    */
69   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
70
71   /**
72    * @brief Create the AnimatedVectorImageVisual using the image URL.
73    *
74    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
75    * @param[in] shaderFactory The ImageVisualShaderFactory object
76    * @param[in] imageUrl The URL to an animated vector image to use
77    * @return A smart-pointer to the newly allocated visual.
78    */
79   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
80
81 public:  // from Visual
82
83   /**
84    * @copydoc Visual::Base::GetNaturalSize
85    */
86   void GetNaturalSize( Vector2& naturalSize ) override;
87
88   /**
89    * @copydoc Visual::Base::CreatePropertyMap
90    */
91   void DoCreatePropertyMap( Property::Map& map ) const override;
92
93   /**
94    * @copydoc Visual::Base::CreateInstancePropertyMap
95    */
96   void DoCreateInstancePropertyMap( Property::Map& map ) const override;
97
98 protected:
99
100   /**
101    * @brief Constructor.
102    *
103    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
104    * @param[in] shaderFactory The ImageVisualShaderFactory object
105    * @param[in] imageUrl The URL to an animated vector image to use
106    */
107   AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
108
109   /**
110    * @brief A reference counted object may only be deleted by calling Unreference().
111    */
112   virtual ~AnimatedVectorImageVisual();
113
114   /**
115    * @copydoc Visual::Base::DoSetProperties
116    */
117   void DoSetProperties( const Property::Map& propertyMap ) override;
118
119   /**
120    * @copydoc Visual::Base::DoSetOnStage
121    */
122   void DoSetOnStage( Actor& actor ) override;
123
124   /**
125    * @copydoc Visual::Base::DoSetOffStage
126    */
127   void DoSetOffStage( Actor& actor ) override;
128
129   /**
130    * @copydoc Visual::Base::OnSetTransform
131    */
132   void OnSetTransform() override;
133
134   /**
135    * @copydoc Visual::Base::OnDoAction
136    */
137   void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
138
139 private:
140
141   /**
142    * Helper method to set individual values by index key.
143    * @param[in] index The index key of the value
144    * @param[in] value The value
145    */
146   void DoSetProperty( Property::Index index, const Property::Value& value );
147
148   /**
149    * @brief Called when the texture upload is completed.
150    */
151   void OnUploadCompleted();
152
153   /**
154    * @brief Event callback from rasterize thread. This is called after the animation is finished.
155    */
156   void OnAnimationFinished();
157
158   /**
159    * @brief Send animation data to the rasterize thread.
160    */
161   void SendAnimationData();
162
163   /**
164    * @brief Set the vector image size.
165    */
166   void SetVectorImageSize();
167
168   /**
169    * @brief Callback when the world scale factor changes.
170    */
171   void OnScaleNotification( PropertyNotification& source );
172
173   /**
174    * @brief Callback when the size changes.
175    */
176   void OnSizeNotification( PropertyNotification& source );
177
178   // Undefined
179   AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
180
181   // Undefined
182   AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
183
184 private:
185   VisualUrl                                    mUrl;
186   VectorAnimationTaskPtr                       mVectorAnimationTask;
187   ImageVisualShaderFactory&                    mImageVisualShaderFactory;
188   PropertyNotification                         mScaleNotification;
189   PropertyNotification                         mSizeNotification;
190   Vector2                                      mVisualSize;
191   Vector2                                      mVisualScale;
192   WeakHandle< Actor >                          mPlacementActor;
193   int32_t                                      mLoopCount;
194   uint32_t                                     mStartFrame;
195   uint32_t                                     mEndFrame;
196   uint32_t                                     mResendFlag;
197   DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
198   DevelImageVisual::StopBehavior::Type         mStopBehavior;
199   DevelImageVisual::LoopingMode::Type          mLoopingMode;
200   bool                                         mRendererAdded;
201 };
202
203 } // namespace Internal
204
205 } // namespace Toolkit
206
207 } // namespace Dali
208
209 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H