1 #ifndef DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_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.
21 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
22 #include <dali/devel-api/common/circular-queue.h>
23 #include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
24 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
34 * Class to manage a rolling cache of Animated images, where the cache size
35 * is smaller than the total number of images.
37 * Frames are always ready, so the observer.FrameReady callback is never triggered;
38 * the FirstFrame and NextFrame APIs will always return a texture.
40 class RollingAnimatedImageCache : public ImageCache, public TextureUploadObserver
45 * @param[in] textureManager The texture manager
46 * @param[in] animatedImageLoader The loaded animated image
47 * @param[in] frameCount The number of frames in the animated image
48 * @param[in] observer FrameReady observer
49 * @param[in] cacheSize The size of the cache
50 * @param[in] batchSize The size of a batch to load
51 * @param[in] isSynchronousLoading The flag to define whether to load first frame synchronously
53 * This will start loading textures immediately, according to the
54 * batch and cache sizes.
56 RollingAnimatedImageCache( TextureManager& textureManager,
57 AnimatedImageLoading& animatedImageLoader,
59 ImageCache::FrameReadyObserver& observer,
62 bool isSynchronousLoading );
67 ~RollingAnimatedImageCache() override;
70 * Get the Nth frame. If it's not ready, this will trigger the
71 * sending of FrameReady() when the image becomes ready.
73 TextureSet Frame( uint32_t frameIndex ) override;
76 * Get the first frame. If it's not ready, this will trigger the
77 * sending of FrameReady() when the image becomes ready.
79 TextureSet FirstFrame() override;
82 * Get the interval of Nth frame.
84 uint32_t GetFrameInterval( uint32_t frameIndex ) override;
88 * @return true if the front frame is ready
90 bool IsFrontReady() const;
93 * Request to Load a frame
95 void RequestFrameLoading( uint32_t frameIndex );
98 * Load the next batch of images
103 * Find the matching image frame, and set it to ready
105 void SetImageFrameReady( TextureManager::TextureId textureId );
108 * Get the texture set of the front frame.
109 * @return the texture set
111 TextureSet GetFrontTextureSet() const;
114 * Get the texture id of the given index
116 TextureManager::TextureId GetCachedTextureId( int index ) const;
119 * Check if the front frame has become ready - if so, inform observer
120 * @param[in] wasReady Readiness before call.
122 void CheckFrontFrame( bool wasReady );
128 TextureSet textureSet,
130 const Vector4& atlasRect,
131 bool preMultiplied ) override;
135 Devel::PixelBuffer pixelBuffer,
136 const VisualUrl& url,
137 bool preMultiplied ) override;
141 * Secondary class to hold readiness and index into url
145 unsigned int mFrameNumber = 0u;
149 Dali::AnimatedImageLoading mAnimatedImageLoading;
150 uint32_t mFrameCount;
152 std::vector<UrlStore> mImageUrls;
153 std::vector<int32_t> mIntervals;
154 std::vector<uint32_t> mLoadWaitingQueue;
155 CircularQueue<ImageFrame> mQueue;
156 bool mIsSynchronousLoading;
160 } // namespace Internal
162 } // namespace Toolkit
166 #endif //DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H