1 #ifndef DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H
5 * Copyright (c) 2016 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/dali-vector.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24 #include <dali/public-api/math/vector4.h>
25 #include <dali/public-api/adaptor-framework/timer.h>
28 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
30 #include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
41 class AnimatedImageVisual;
42 typedef IntrusivePtr< AnimatedImageVisual > AnimatedImageVisualPtr;
45 * The visual which renders an animated image
47 * One of the following properties is mandatory
49 * | %Property Name | Type |
50 * |------------------- |-------------------|
52 * | urls | ARRAY of STRING |
54 * The remaining properties are optional
55 * | pixelArea | VECTOR4 |
56 * | wrapModeU | INTEGER OR STRING |
57 * | wrapModeV | INTEGER OR STRING |
58 * | cacheSize | INTEGER |
59 * | batchSize | INTEGER |
60 * | frameDelay | INTEGER |
62 * pixelArea is a rectangular area.
63 * In its Vector4 value, the first two elements indicate the top-left position of the area,
64 * and the last two elements are the area width and height respectively.
65 * If not specified, the default value is [0.0, 0.0, 1.0, 1.0], i.e. the entire area of the image.
67 * wrapModeU and wrapModeV separately decide how the texture should be sampled when the u and v coordinate exceeds the range of 0.0 to 1.0.
68 * Its value should be one of the following wrap mode:
74 * cacheSize is used with multiple images - it determines how many images are kept pre-loaded
75 * batchSize is used with multiple images - it determines how many images to load on each frame
76 * frameDelay is used with multiple images - it is the number of milliseconds between each frame
79 class AnimatedImageVisual : public Visual::Base,
80 public ConnectionTracker,
81 public ImageCache::FrameReadyObserver
87 * @brief Create the animated image Visual using the image URL.
89 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
90 * @param[in] imageUrl The URL to gif resource to use
91 * @param[in] properties A Property::Map containing settings for this visual
92 * @return A smart-pointer to the newly allocated visual.
94 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl, const Property::Map& properties );
97 * @brief Create the animated image Visual using image URLs.
99 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
100 * @param[in] imageUrls A Property::Array containing the URLs to the image resources
101 * @param[in] properties A Property::Map containing settings for this visual
102 * @return A smart-pointer to the newly allocated visual.
104 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const Property::Array& imageUrls, const Property::Map& properties );
107 * @brief Create the animated image visual using the image URL.
109 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
110 * @param[in] imageUrl The URL to animated image resource to use
112 static AnimatedImageVisualPtr New( VisualFactoryCache& factoryCache, const VisualUrl& imageUrl );
114 public: // from Visual
117 * @copydoc Visual::Base::GetNaturalSize
119 virtual void GetNaturalSize( Vector2& naturalSize );
122 * @copydoc Visual::Base::CreatePropertyMap
124 virtual void DoCreatePropertyMap( Property::Map& map ) const;
127 * @copydoc Visual::Base::CreateInstancePropertyMap
129 virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
134 * @brief Constructor.
136 * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
138 AnimatedImageVisual( VisualFactoryCache& factoryCache );
141 * @brief A reference counted object may only be deleted by calling Unreference().
143 virtual ~AnimatedImageVisual();
146 * @copydoc Visual::Base::DoSetProperties
148 virtual void DoSetProperties( const Property::Map& propertyMap );
151 * Helper method to set individual values by index key.
152 * @param[in] index The index key of the value
153 * @param[in] value The value
155 void DoSetProperty( Property::Index index, const Property::Value& value );
158 * @copydoc Visual::Base::DoSetOnStage
160 virtual void DoSetOnStage( Actor& actor );
163 * @copydoc Visual::Base::DoSetOffStage
165 virtual void DoSetOffStage( Actor& actor );
168 * @copydoc Visual::Base::OnSetTransform
170 virtual void OnSetTransform();
174 * Creates the renderer for the animated image
176 void CreateRenderer();
179 * Starts the Load of the first batch of URLs
181 void LoadFirstBatch();
184 * Adds the texture set to the renderer, and the renderer to the
185 * placement actor, and starts the frame timer
187 void StartFirstFrame( TextureSet& textureSet );
190 * Prepares the texture set for displaying
192 TextureSet PrepareTextureSet();
195 * Load the gif image and pack the frames into atlas.
196 * @return The atlas texture.
198 TextureSet PrepareAnimatedGifImage();
201 * Set the image size from the texture set
203 void SetImageSize( TextureSet& textureSet );
206 * Called when the next frame is ready.
208 void FrameReady( TextureSet textureSet );
211 * Display the next frame. It is called when the mFrameDelayTimer ticks.
212 * Returns true to ensure the timer continues running.
214 bool DisplayNextFrame();
218 AnimatedImageVisual( const AnimatedImageVisual& animatedImageVisual );
221 AnimatedImageVisual& operator=( const AnimatedImageVisual& animatedImageVisual );
225 Timer mFrameDelayTimer;
226 WeakHandle<Actor> mPlacementActor;
228 // Variables for GIF player
229 Dali::Vector<Vector4> mTextureRectContainer;
230 Dali::Vector<uint32_t> mFrameDelayContainer;
233 uint32_t mCurrentFrameIndex; // Frame index into textureRects
235 // Variables for Multi-Image player
236 ImageCache::UrlList* mImageUrls;
237 ImageCache* mImageCache;
240 uint16_t mFrameDelay;
244 ImageDimensions mImageSize;
246 Dali::WrapMode::Type mWrapModeU:3;
247 Dali::WrapMode::Type mWrapModeV:3;
248 bool mStartFirstFrame:1;
251 } // namespace Internal
253 } // namespace Toolkit
256 #endif /* DALI_TOOLKIT_INTERNAL_ANIMATED_IMAGE_VISUAL_H */