1 #ifndef DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
5 * Copyright (c) 2021 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-toolkit/internal/visuals/animated-image/image-cache.h>
22 #include <dali-toolkit/internal/visuals/texture-manager-impl.h>
23 #include <dali/devel-api/adaptor-framework/animated-image-loading.h>
24 #include <dali/devel-api/common/circular-queue.h>
33 * Class to manage a rolling cache of Animated images, where the cache size
34 * is smaller than the total number of images.
36 * Frames are always ready, so the observer.FrameReady callback is never triggered;
37 * the FirstFrame and NextFrame APIs will always return a texture.
39 class RollingAnimatedImageCache : public ImageCache, public TextureUploadObserver
44 * @param[in] textureManager The texture manager
45 * @param[in] animatedImageLoader The loaded animated image
46 * @param[in] frameCount The number of frames in the animated image
47 * @param[in] observer FrameReady observer
48 * @param[in] cacheSize The size of the cache
49 * @param[in] batchSize The size of a batch to load
50 * @param[in] isSynchronousLoading The flag to define whether to load first frame synchronously
52 * This will start loading textures immediately, according to the
53 * batch and cache sizes.
55 RollingAnimatedImageCache(TextureManager& textureManager,
56 AnimatedImageLoading& animatedImageLoader,
58 ImageCache::FrameReadyObserver& observer,
61 bool isSynchronousLoading);
66 ~RollingAnimatedImageCache() override;
69 * Get the Nth frame. If it's not ready, this will trigger the
70 * sending of FrameReady() when the image becomes ready.
72 TextureSet Frame(uint32_t frameIndex) override;
75 * Get the first frame. If it's not ready, this will trigger the
76 * sending of FrameReady() when the image becomes ready.
78 TextureSet FirstFrame() override;
81 * Get the next frame. If it's not ready, this will trigger the
82 * sending of FrameReady() when the image becomes ready.
84 TextureSet NextFrame() override;
87 * Get the interval of Nth frame.
89 uint32_t GetFrameInterval(uint32_t frameIndex) const override;
92 * Get the current rendered frame index.
93 * If there isn't any loaded frame, returns -1.
95 int32_t GetCurrentFrameIndex() const override;
98 * Get total frame count of the animated image file.
100 int32_t GetTotalFrameCount() const override;
104 * @return true if the front frame is ready
106 bool IsFrontReady() const;
109 * Request to Load a frame
111 void RequestFrameLoading(uint32_t frameIndex);
114 * Load the next batch of images
119 * Find the matching image frame, and set it to ready
121 void SetImageFrameReady(TextureManager::TextureId textureId);
124 * Get the texture set of the front frame.
125 * @return the texture set
127 TextureSet GetFrontTextureSet() const;
130 * Get the texture id of the given index
132 TextureManager::TextureId GetCachedTextureId(int index) const;
135 * Check if the front frame has become ready - if so, inform observer
136 * @param[in] wasReady Readiness before call.
138 void CheckFrontFrame(bool wasReady);
144 TextureSet textureSet,
146 const Vector4& atlasRect,
147 bool preMultiplied) override;
151 Devel::PixelBuffer pixelBuffer,
152 const VisualUrl& url,
153 bool preMultiplied) override;
157 * Secondary class to hold readiness and index into url
161 unsigned int mFrameNumber = 0u;
165 Dali::AnimatedImageLoading mAnimatedImageLoading;
166 uint32_t mFrameCount;
169 std::vector<UrlStore> mImageUrls;
170 std::vector<int32_t> mIntervals;
171 std::vector<uint32_t> mLoadWaitingQueue;
172 CircularQueue<ImageFrame> mQueue;
173 bool mIsSynchronousLoading;
177 } // namespace Internal
179 } // namespace Toolkit
183 #endif //DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H