1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
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>
41 class ImageVisualShaderFactory;
42 class AnimatedVectorImageVisual;
43 using AnimatedVectorImageVisualPtr = IntrusivePtr<AnimatedVectorImageVisual>;
46 * The visual which renders an animated vector image using VectorAnimationRenderer.
47 * VectorAnimationRenderer renders the animation image and this visuall controls the images.
49 * The following property is essential
51 * | %Property Name | Type |
52 * |--------------------------|------------------|
56 class AnimatedVectorImageVisual : public Visual::Base, public ConnectionTracker, public VectorAnimationManager::LifecycleObserver
60 * @brief Create the AnimatedVectorImageVisual using the image URL.
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.
68 static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties);
71 * @brief Create the AnimatedVectorImageVisual using the image URL.
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.
78 static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
80 public: // from Visual
82 * @copydoc Visual::Base::GetNaturalSize
84 void GetNaturalSize(Vector2& naturalSize) override;
87 * @copydoc Visual::Base::CreatePropertyMap
89 void DoCreatePropertyMap(Property::Map& map) const override;
92 * @copydoc Visual::Base::CreateInstancePropertyMap
94 void DoCreateInstancePropertyMap(Property::Map& map) const override;
97 * @copydoc Visual::Base::EnablePreMultipliedAlpha
99 void EnablePreMultipliedAlpha(bool preMultiplied) override;
101 protected: // From VectorAnimationManager::LifecycleObserver:
103 * @copydoc VectorAnimationManager::LifecycleObserver::VectorAnimationManagerDestroyed()
105 void VectorAnimationManagerDestroyed() override;
109 * @brief Constructor.
111 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
112 * @param[in] shaderFactory The ImageVisualShaderFactory object
113 * @param[in] imageUrl The URL to an animated vector image to use
115 AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl);
118 * @brief A reference counted object may only be deleted by calling Unreference().
120 ~AnimatedVectorImageVisual() override;
123 * @copydoc Visual::Base::OnInitialize
125 void OnInitialize() override;
128 * @copydoc Visual::Base::DoSetProperties
130 void DoSetProperties(const Property::Map& propertyMap) override;
133 * @copydoc Visual::Base::DoSetOnScene
135 void DoSetOnScene(Actor& actor) override;
138 * @copydoc Visual::Base::DoSetOffScene
140 void DoSetOffScene(Actor& actor) override;
143 * @copydoc Visual::Base::OnSetTransform
145 void OnSetTransform() override;
148 * @copydoc Visual::Base::UpdateShader
150 void UpdateShader() override;
153 * @copydoc Visual::Base::GenerateShader
155 Shader GenerateShader() const override;
158 * @copydoc Visual::Base::OnDoAction
160 void OnDoAction(const Property::Index actionId, const Property::Value& attributes) override;
164 * Helper method to set individual values by index key.
165 * @param[in] index The index key of the value
166 * @param[in] value The value
168 void DoSetProperty(Property::Index index, const Property::Value& value);
171 * @brief Called when the resource is ready.
172 * @param[in] success True if the texture load was successful. If false, then the resource failed to load.
174 void OnResourceReady(bool success);
177 * @brief Event callback from rasterize thread. This is called after the animation is finished.
179 void OnAnimationFinished();
182 * @brief Send animation data to the rasterize thread.
184 void SendAnimationData();
187 * @brief Set the vector image size.
189 void SetVectorImageSize();
192 * @brief Stop the animation.
194 void StopAnimation();
197 * @brief Trigger rasterization of the vector content.
199 void TriggerVectorRasterization();
202 * @brief Callback when the world scale factor changes.
204 void OnScaleNotification(PropertyNotification& source);
207 * @brief Callback when the size changes.
209 void OnSizeNotification(PropertyNotification& source);
212 * @brief Callback when the visibility of the actor is changed.
214 void OnControlVisibilityChanged(Actor actor, bool visible, DevelActor::VisibilityChange::Type type);
217 * @brief Callback when the visibility of the window is changed.
219 void OnWindowVisibilityChanged(Window window, bool visible);
222 * @brief Callback when the event is processed.
224 void OnProcessEvents();
227 AnimatedVectorImageVisual(const AnimatedVectorImageVisual& visual) = delete;
230 AnimatedVectorImageVisual& operator=(const AnimatedVectorImageVisual& visual) = delete;
234 VectorAnimationTask::AnimationData mAnimationData;
235 VectorAnimationTaskPtr mVectorAnimationTask;
236 ImageVisualShaderFactory& mImageVisualShaderFactory;
237 PropertyNotification mScaleNotification;
238 PropertyNotification mSizeNotification;
240 Vector2 mVisualScale;
241 WeakHandle<Actor> mPlacementActor;
242 DevelImageVisual::PlayState::Type mPlayState;
243 CallbackBase* mEventCallback; // Not owned
247 bool mRedrawInScalingDown;
250 } // namespace Internal
252 } // namespace Toolkit
256 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H