1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
5 * Copyright (c) 2024 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
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 * @param[in] size The width and height of the rasterized buffer. The visual size will be used if these are 0.
77 * @return A smart-pointer to the newly allocated visual.
79 static AnimatedVectorImageVisualPtr New(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size = ImageDimensions());
81 public: // from Visual
83 * @copydoc Visual::Base::GetNaturalSize
85 void GetNaturalSize(Vector2& naturalSize) override;
88 * @copydoc Visual::Base::CreatePropertyMap
90 void DoCreatePropertyMap(Property::Map& map) const override;
93 * @copydoc Visual::Base::CreateInstancePropertyMap
95 void DoCreateInstancePropertyMap(Property::Map& map) const override;
98 * @copydoc Visual::Base::EnablePreMultipliedAlpha
100 void EnablePreMultipliedAlpha(bool preMultiplied) override;
104 * @brief Constructor.
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 * @param[in] size The width and height of the rasterized buffer. The visual size will be used if these are 0.
111 AnimatedVectorImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, ImageDimensions size);
114 * @brief A reference counted object may only be deleted by calling Unreference().
116 ~AnimatedVectorImageVisual() override;
119 * @copydoc Visual::Base::OnInitialize
121 void OnInitialize() override;
124 * @copydoc Visual::Base::DoSetProperties
126 void DoSetProperties(const Property::Map& propertyMap) override;
129 * @copydoc Visual::Base::DoSetOnScene
131 void DoSetOnScene(Actor& actor) override;
134 * @copydoc Visual::Base::DoSetOffScene
136 void DoSetOffScene(Actor& actor) override;
139 * @copydoc Visual::Base::OnSetTransform
141 void OnSetTransform() override;
144 * @copydoc Visual::Base::UpdateShader
146 void UpdateShader() override;
149 * @copydoc Visual::Base::GenerateShader
151 Shader GenerateShader() const override;
154 * @copydoc Visual::Base::OnDoAction
156 void OnDoAction(const Property::Index actionId, const Property::Value& attributes) override;
159 * @copydoc Visual::Base::OnDoActionExtension
161 void OnDoActionExtension(const Property::Index actionId, Dali::Any attributes) override;
165 * Helper method to set individual values by index key.
166 * @param[in] index The index key of the value
167 * @param[in] value The value
169 void DoSetProperty(Property::Index index, const Property::Value& value);
172 * @brief Called when the resource is ready.
173 * @param[in] status The resource status
175 void OnResourceReady(VectorAnimationTask::ResourceStatus status);
178 * @brief Event callback from rasterize thread. This is called after the animation is finished.
180 * @param[in] playStateId The play state id
182 void OnAnimationFinished(uint32_t playStateId);
185 * @brief Send animation data to the rasterize thread.
187 void SendAnimationData();
190 * @brief Set the vector image size.
192 void SetVectorImageSize();
195 * @brief Stop the animation.
197 void StopAnimation();
200 * @brief Trigger rasterization of the vector content.
202 void TriggerVectorRasterization();
205 * @brief Callback when the world scale factor changes.
207 void OnScaleNotification(PropertyNotification& source);
210 * @brief Callback when the size changes.
212 void OnSizeNotification(PropertyNotification& source);
215 * @brief Callback when the visibility of the actor is changed.
217 void OnControlInheritedVisibilityChanged(Actor actor, bool visible);
220 * @brief Callback when the visibility of the window is changed.
222 void OnWindowVisibilityChanged(Window window, bool visible);
225 * @brief Callback when the event is processed.
227 void OnProcessEvents();
230 AnimatedVectorImageVisual(const AnimatedVectorImageVisual& visual) = delete;
233 AnimatedVectorImageVisual& operator=(const AnimatedVectorImageVisual& visual) = delete;
236 WeakHandle<Window> mPlacementWindow;
238 VectorAnimationTask::AnimationData mAnimationData;
239 VectorAnimationTaskPtr mVectorAnimationTask;
240 ImageVisualShaderFactory& mImageVisualShaderFactory;
241 PropertyNotification mScaleNotification;
242 PropertyNotification mSizeNotification;
244 Vector2 mVisualScale;
245 Dali::ImageDimensions mDesiredSize{};
246 WeakHandle<Actor> mPlacementActor;
247 DevelImageVisual::PlayState::Type mPlayState;
248 CallbackBase* mEventCallback; // Not owned
250 uint32_t mLastSentPlayStateId;
252 bool mLoadFailed : 1;
253 bool mRendererAdded : 1;
254 bool mRedrawInScalingDown : 1;
255 bool mEnableFrameCache : 1;
256 bool mUseNativeImage : 1;
257 bool mNotifyAfterRasterization : 1;
260 } // namespace Internal
262 } // namespace Toolkit
266 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H