1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H
5 * Copyright (c) 2019 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/devel-api/actors/actor-devel.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
30 #include <dali-toolkit/devel-api/visuals/animated-vector-image-visual-actions-devel.h>
31 #include <dali-toolkit/internal/visuals/animated-vector-image/vector-animation-task.h>
42 class ImageVisualShaderFactory;
43 class AnimatedVectorImageVisual;
44 using AnimatedVectorImageVisualPtr = IntrusivePtr< AnimatedVectorImageVisual >;
47 * The visual which renders an animated vector image using VectorAnimationRenderer.
48 * VectorAnimationRenderer renders the animation image and this visuall controls the images.
50 * The following property is essential
52 * | %Property Name | Type |
53 * |--------------------------|------------------|
57 class AnimatedVectorImageVisual: public Visual::Base, public ConnectionTracker
62 * @brief Create the AnimatedVectorImageVisual using the image URL.
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.
70 static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl, const Property::Map& properties );
73 * @brief Create the AnimatedVectorImageVisual using the image URL.
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.
80 static AnimatedVectorImageVisualPtr New( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
82 public: // from Visual
85 * @copydoc Visual::Base::GetNaturalSize
87 void GetNaturalSize( Vector2& naturalSize ) override;
90 * @copydoc Visual::Base::CreatePropertyMap
92 void DoCreatePropertyMap( Property::Map& map ) const override;
95 * @copydoc Visual::Base::CreateInstancePropertyMap
97 void DoCreateInstancePropertyMap( Property::Map& map ) const override;
102 * @brief Constructor.
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
108 AnimatedVectorImageVisual( VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory, const VisualUrl& imageUrl );
111 * @brief A reference counted object may only be deleted by calling Unreference().
113 virtual ~AnimatedVectorImageVisual();
116 * @copydoc Visual::Base::DoSetProperties
118 void DoSetProperties( const Property::Map& propertyMap ) override;
121 * @copydoc Visual::Base::DoSetOnStage
123 void DoSetOnStage( Actor& actor ) override;
126 * @copydoc Visual::Base::DoSetOffStage
128 void DoSetOffStage( Actor& actor ) override;
131 * @copydoc Visual::Base::OnSetTransform
133 void OnSetTransform() override;
136 * @copydoc Visual::Base::OnDoAction
138 void OnDoAction( const Property::Index actionId, const Property::Value& attributes ) override;
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
147 void DoSetProperty( Property::Index index, const Property::Value& value );
150 * @brief Called when the texture upload is completed.
152 void OnUploadCompleted();
155 * @brief Event callback from rasterize thread. This is called after the animation is finished.
157 void OnAnimationFinished();
160 * @brief Send animation data to the rasterize thread.
162 void SendAnimationData();
165 * @brief Set the vector image size.
167 void SetVectorImageSize();
170 * @brief Callback when the world scale factor changes.
172 void OnScaleNotification( PropertyNotification& source );
175 * @brief Callback when the size changes.
177 void OnSizeNotification( PropertyNotification& source );
180 * @brief Callback when the visibility of the actor is changed.
182 void OnVisibilityChanged( Actor actor, bool visible, DevelActor::VisibilityChange::Type type );
185 AnimatedVectorImageVisual( const AnimatedVectorImageVisual& visual ) = delete;
188 AnimatedVectorImageVisual& operator=( const AnimatedVectorImageVisual& visual ) = delete;
192 VectorAnimationTaskPtr mVectorAnimationTask;
193 ImageVisualShaderFactory& mImageVisualShaderFactory;
194 PropertyNotification mScaleNotification;
195 PropertyNotification mSizeNotification;
197 Vector2 mVisualScale;
198 WeakHandle< Actor > mPlacementActor;
200 uint32_t mStartFrame;
202 uint32_t mResendFlag;
203 DevelAnimatedVectorImageVisual::Action::Type mActionStatus;
204 DevelImageVisual::StopBehavior::Type mStopBehavior;
205 DevelImageVisual::LoopingMode::Type mLoopingMode;
209 } // namespace Internal
211 } // namespace Toolkit
215 #endif // DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H