Merge "Fix gradient shader + Remove comment about BorderlineColor" 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) 2021 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    * @return A smart-pointer to the newly allocated visual.
77    */
78   static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
79
80 public: // from Visual
81   /**
82    * @copydoc Visual::Base::GetNaturalSize
83    */
84   void GetNaturalSize(Vector2& naturalSize) override;
85
86   /**
87    * @copydoc Visual::Base::CreatePropertyMap
88    */
89   void DoCreatePropertyMap(Property::Map& map) const override;
90
91   /**
92    * @copydoc Visual::Base::CreateInstancePropertyMap
93    */
94   void DoCreateInstancePropertyMap(Property::Map& map) const override;
95
96 protected: // From VectorAnimationManager::LifecycleObserver:
97   /**
98    * @copydoc VectorAnimationManager::LifecycleObserver::VectorAnimationManagerDestroyed()
99    */
100   void VectorAnimationManagerDestroyed() override;
101
102 protected:
103   /**
104    * @brief Constructor.
105    *
106    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
107    * @param[in] shaderFactory The ImageVisualShaderFactory object
108    * @param[in] imageUrl The URL to an animated vector image to use
109    */
110   AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
111
112   /**
113    * @brief A reference counted object may only be deleted by calling Unreference().
114    */
115   ~AnimatedVectorImageVisual() override;
116
117   /**
118    * @copydoc Visual::Base::OnInitialize
119    */
120   void OnInitialize() override;
121
122   /**
123    * @copydoc Visual::Base::DoSetProperties
124    */
125   void DoSetProperties(const Property::Map& propertyMap) override;
126
127   /**
128    * @copydoc Visual::Base::DoSetOnScene
129    */
130   void DoSetOnScene(Actor& actor) override;
131
132   /**
133    * @copydoc Visual::Base::DoSetOffScene
134    */
135   void DoSetOffScene(Actor& actor) override;
136
137   /**
138    * @copydoc Visual::Base::OnSetTransform
139    */
140   void OnSetTransform() override;
141
142   /**
143    * @copydoc Visual::Base::UpdateShader
144    */
145   void UpdateShader() override;
146
147   /**
148    * @copydoc Visual::Base::GenerateShader
149    */
150   Shader GenerateShader() const override;
151
152   /**
153    * @copydoc Visual::Base::OnDoAction
154    */
155   void OnDoAction(const Property::Index actionId, const Property::Value& attributes) override;
156
157 private:
158   /**
159    * Helper method to set individual values by index key.
160    * @param[in] index The index key of the value
161    * @param[in] value The value
162    */
163   void DoSetProperty(Property::Index index, const Property::Value& value);
164
165   /**
166    * @brief Called when the texture upload is completed.
167    */
168   void OnUploadCompleted();
169
170   /**
171    * @brief Event callback from rasterize thread. This is called after the animation is finished.
172    */
173   void OnAnimationFinished();
174
175   /**
176    * @brief Send animation data to the rasterize thread.
177    */
178   void SendAnimationData();
179
180   /**
181    * @brief Set the vector image size.
182    */
183   void SetVectorImageSize();
184
185   /**
186    * @brief Stop the animation.
187    */
188   void StopAnimation();
189
190   /**
191    * @brief Trigger rasterization of the vector content.
192    */
193   void TriggerVectorRasterization();
194
195   /**
196    * @brief Callback when the world scale factor changes.
197    */
198   void OnScaleNotification(PropertyNotification& source);
199
200   /**
201    * @brief Callback when the size changes.
202    */
203   void OnSizeNotification(PropertyNotification& source);
204
205   /**
206    * @brief Callback when the visibility of the actor is changed.
207    */
208   void OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type);
209
210   /**
211    * @brief Callback when the visibility of the window is changed.
212    */
213   void OnWindowVisibilityChanged(Window window, bool visible);
214
215   /**
216    * @brief Callback when the event is processed.
217    */
218   void OnProcessEvents();
219
220   // Undefined
221   AnimatedVectorImageVisual(const AnimatedVectorImageVisual& visual) = delete;
222
223   // Undefined
224   AnimatedVectorImageVisual& operator=(const AnimatedVectorImageVisual& visual) = delete;
225
226 private:
227   VisualUrl                          mUrl;
228   VectorAnimationTask::AnimationData mAnimationData;
229   VectorAnimationTaskPtr             mVectorAnimationTask;
230   ImageVisualShaderFactory&          mImageVisualShaderFactory;
231   PropertyNotification               mScaleNotification;
232   PropertyNotification               mSizeNotification;
233   Vector2                            mVisualSize;
234   Vector2                            mVisualScale;
235   WeakHandle<Actor>                  mPlacementActor;
236   DevelImageVisual::PlayState::Type  mPlayState;
237   CallbackBase*                      mEventCallback; // Not owned
238   bool                               mLoadFailed;
239   bool                               mRendererAdded;
240   bool                               mCoreShutdown;
241   bool                               mRedrawInScalingDown;
242 };
243
244 } // namespace Internal
245
246 } // namespace Toolkit
247
248 } // namespace Dali
249
250 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H