(AnimatedVectorImageVisual) Add some features
[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 <memory>
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-rasterize-thread.h>
31
32 namespace Dali
33 {
34
35 namespace Toolkit
36 {
37
38 namespace Internal
39 {
40
41 class ImageVisualShaderFactory;
42 class VectorRasterizeThread;
43 class AnimatedVectorImageVisual;
44 using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
45
46 /**
47  * The visual which renders an animated vector image using VectorAnimationRenderer.
48  * VectorAnimationRenderer renders the animation image and this visuall controls the images.
49  *
50  * The following property is essential
51  *
52  * | %Property Name           | Type             |
53  * |--------------------------|------------------|
54  * | url                      | STRING           |
55  *
56  */
57 class AnimatedVectorImageVisual: public Visual::Base
58 {
59 public:
60
61   /**
62    * @brief Create the AnimatedVectorImageVisual using the image URL.
63    *
64    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
65    * @param[in] shaderFactory The ImageVisualShaderFactory object
66    * @param[in] imageUrl The URL to an animated vector image to use
67    * @param[in] properties A Property::Map containing settings for this visual
68    * @return A smart-pointer to the newly allocated visual.
69    */
70   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
71
72   /**
73    * @brief Create the AnimatedVectorImageVisual using the image URL.
74    *
75    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
76    * @param[in] shaderFactory The ImageVisualShaderFactory object
77    * @param[in] imageUrl The URL to an animated vector image to use
78    * @return A smart-pointer to the newly allocated visual.
79    */
80   static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
81
82 public:  // from Visual
83
84   /**
85    * @copydoc Visual::Base::GetNaturalSize
86    */
87   void GetNaturalSize( Vector2& naturalSize ) override;
88
89   /**
90    * @copydoc Visual::Base::CreatePropertyMap
91    */
92   void DoCreatePropertyMap( Property::Map& map ) const override;
93
94   /**
95    * @copydoc Visual::Base::CreateInstancePropertyMap
96    */
97   void DoCreateInstancePropertyMap( Property::Map& map ) const override;
98
99 protected:
100
101   /**
102    * @brief Constructor.
103    *
104    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
105    * @param[in] shaderFactory The ImageVisualShaderFactory object
106    * @param[in] imageUrl The URL to an animated vector image to use
107    */
108   AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
109
110   /**
111    * @brief A reference counted object may only be deleted by calling Unreference().
112    */
113   virtual ~AnimatedVectorImageVisual();
114
115   /**
116    * @copydoc Visual::Base::DoSetProperties
117    */
118   void DoSetProperties( const Property::Map& propertyMap ) override;
119
120   /**
121    * @copydoc Visual::Base::DoSetOnStage
122    */
123   void DoSetOnStage( Actor& actor ) override;
124
125   /**
126    * @copydoc Visual::Base::DoSetOffStage
127    */
128   void DoSetOffStage( Actor& actor ) override;
129
130   /**
131    * @copydoc Visual::Base::OnSetTransform
132    */
133   void OnSetTransform() override;
134
135   /**
136    * @copydoc Visual::Base::OnDoAction
137    */
138   void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
139
140 private:
141
142   /**
143    * Helper method to set individual values by index key.
144    * @param[in] index The index key of the value
145    * @param[in] value The value
146    */
147   void DoSetProperty( Property::Index index, const Property::Value& value );
148
149   /**
150    * @brief Event callback from rasterize thread. This is called after the first frame is ready.
151    */
152   void OnResourceReady();
153
154   /**
155    * @brief Event callback from rasterize thread. This is called after the animation is finished.
156    */
157   void OnAnimationFinished();
158
159   /**
160    * @brief Send animation data to the rasterize thread.
161    */
162   void SendAnimationData();
163
164   // Undefined
165   AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
166
167   // Undefined
168   AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
169
170 private:
171   ImageVisualShaderFactory&                    mImageVisualShaderFactory;
172   VisualUrl                                    mUrl;
173   VectorRasterizeThread                        mVectorRasterizeThread;
174   Vector2                                      mVisualSize;
175   Vector2                                      mPlayRange;
176   WeakHandle< Actor >                          mPlacementActor;
177   int32_t                                      mLoopCount;
178   uint32_t                                     mResendFlag;
179   DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
180 };
181
182 } // namespace Internal
183
184 } // namespace Toolkit
185
186 } // namespace Dali
187
188 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H