1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
5 * Copyright (c) 2020 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/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 #include <dali/public-api/adaptor-framework/window.h>
26 #include <dali/devel-api/actors/actor-devel.h>
27 #include <dali/integration-api/processor-interface.h>
30 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
31 #include <dali-toolkit/internal/visuals/visual-url.h>
32 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
33 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
44 class ImageVisualShaderFactory;
45 class AnimatedVectorImageVisual;
46 using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
49 * The visual which renders an animated vector image using VectorAnimationRenderer.
50 * VectorAnimationRenderer renders the animation image and this visuall controls the images.
52 * The following property is essential
54 * | %Property Name | Type |
55 * |--------------------------|------------------|
59 class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker, public Integration::Processor
64 * @brief Create the AnimatedVectorImageVisual using the image URL.
66 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
67 * @param[in] shaderFactory The ImageVisualShaderFactory object
68 * @param[in] imageUrl The URL to an animated vector image to use
69 * @param[in] properties A Property::Map containing settings for this visual
70 * @return A smart-pointer to the newly allocated visual.
72 static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
75 * @brief Create the AnimatedVectorImageVisual using the image URL.
77 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
78 * @param[in] shaderFactory The ImageVisualShaderFactory object
79 * @param[in] imageUrl The URL to an animated vector image to use
80 * @return A smart-pointer to the newly allocated visual.
82 static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
84 public: // from Visual
87 * @copydoc Visual::Base::GetNaturalSize
89 void GetNaturalSize( Vector2& naturalSize ) override;
92 * @copydoc Visual::Base::CreatePropertyMap
94 void DoCreatePropertyMap( Property::Map& map ) const override;
97 * @copydoc Visual::Base::CreateInstancePropertyMap
99 void DoCreateInstancePropertyMap( Property::Map& map ) const 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
110 AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
113 * @brief A reference counted object may only be deleted by calling Unreference().
115 virtual ~AnimatedVectorImageVisual();
118 * @copydoc Visual::Base::DoSetProperties
120 void DoSetProperties( const Property::Map& propertyMap ) override;
123 * @copydoc Visual::Base::DoSetOnScene
125 void DoSetOnScene( Actor& actor ) override;
128 * @copydoc Visual::Base::DoSetOffScene
130 void DoSetOffScene( Actor& actor ) override;
133 * @copydoc Visual::Base::OnSetTransform
135 void OnSetTransform() override;
138 * @copydoc Visual::Base::OnDoAction
140 void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
142 protected: // Implementation of Processor
145 * @copydoc Dali::Integration::Processor::Process()
147 void Process() override;
152 * Helper method to set individual values by index key.
153 * @param[in] index The index key of the value
154 * @param[in] value The value
156 void DoSetProperty( Property::Index index, const Property::Value& value );
159 * @brief Called when the texture upload is completed.
161 void OnUploadCompleted();
164 * @brief Event callback from rasterize thread. This is called after the animation is finished.
166 void OnAnimationFinished();
169 * @brief Send animation data to the rasterize thread.
171 void SendAnimationData();
174 * @brief Set the vector image size.
176 void SetVectorImageSize();
179 * @brief Stop the animation.
181 void StopAnimation();
184 * @brief Trigger rasterization of the vector content.
186 void TriggerVectorRasterization();
189 * @brief Callback when the world scale factor changes.
191 void OnScaleNotification( PropertyNotification& source );
194 * @brief Callback when the size changes.
196 void OnSizeNotification( PropertyNotification& source );
199 * @brief Callback when the visibility of the actor is changed.
201 void OnControlVisibilityChanged( Actor actor, bool visible, DevelActor::VisibilityChange::Type type );
204 * @brief Callback when the visibility of the window is changed.
206 void OnWindowVisibilityChanged( Window window, bool visible );
209 AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
212 AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
216 VectorAnimationTask::AnimationData mAnimationData;
217 VectorAnimationTaskPtr mVectorAnimationTask;
218 ImageVisualShaderFactory& mImageVisualShaderFactory;
219 PropertyNotification mScaleNotification;
220 PropertyNotification mSizeNotification;
222 Vector2 mVisualScale;
223 WeakHandle< Actor > mPlacementActor;
224 DevelImageVisual::PlayState::Type mPlayState;
226 bool mRasterizationTriggered;
229 } // namespace Internal
231 } // namespace Toolkit
235 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H