1 #ifndef DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
5 * Copyright (c) 2022 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/texture-manager/texture-manager-impl.h>
22 #include <dali-toolkit/internal/visuals/animated-image/image-cache.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] animatedImageLoading The loaded animated image
46 * @param[in] maskingData Masking data to be applied.
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& animatedImageLoading,
57 TextureManager::MaskingDataPointer& maskingData,
58 ImageCache::FrameReadyObserver& observer,
61 bool isSynchronousLoading,
62 bool preMultiplyOnLoad);
67 ~RollingAnimatedImageCache() override;
70 * @copydoc Internal::ImageCache::Frame()
72 TextureSet Frame(uint32_t frameIndex) override;
75 * @copydoc Internal::ImageCache::FirstFrame()
77 TextureSet FirstFrame() override;
80 * @copydoc Internal::ImageCache::GetFrameInterval()
82 uint32_t GetFrameInterval(uint32_t frameIndex) const override;
85 * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
87 int32_t GetCurrentFrameIndex() const override;
90 * @copydoc Internal::ImageCache::GetTotalFrameCount()
92 int32_t GetTotalFrameCount() const override;
95 * @copydoc Internal::ImageCache::ClearCache()
97 void ClearCache() override;
101 * @brief Check whether the front frame is ready or not.
103 * @return true if the front frame is ready
105 bool IsFrontReady() const;
108 * @brief Request to Load a frame
110 * @param[in] frameIndex index of frame to be loaded.
111 * @param[in] synchronousLoading true if the frame should be loaded synchronously
113 * @return the texture set currently loaded.
115 TextureSet RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading);
118 * @brief Load the next batch of images
120 * @param[in] frameIndex starting frame index of batch to be loaded.
122 void LoadBatch(uint32_t frameIndex);
125 * @brief Find the matching image frame, and set it to ready
127 * @param[in] textureId texture id to be marked as ready.
129 void SetImageFrameReady(TextureManager::TextureId textureId);
132 * @brief Get the texture set of the front frame.
134 * @return the texture set of the front of Cache.
136 TextureSet GetFrontTextureSet() const;
139 * @brief Get the texture id of the given index
141 * @param[in] index index of the queue.
143 TextureManager::TextureId GetCachedTextureId(int index) const;
146 * @brief Make the loaded frame ready and notify it to the texture upload observer
148 * @param[in] loadSuccess whether the loading is succeded or not.
149 * @param[in] textureSet textureSet for this frame.
150 * @param[in] interval interval between this frame and next frame.
152 void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval);
155 * @brief Pop front entity of Cache.
157 void PopFrontCache();
161 * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
163 void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
167 * Secondary class to hold readiness and index into url
171 uint32_t mFrameNumber = 0u;
174 std::vector<TextureManager::TextureId> mTextureIds;
177 Dali::AnimatedImageLoading mAnimatedImageLoading;
178 uint32_t mFrameCount;
179 uint32_t mFrameIndex;
181 std::vector<int32_t> mIntervals;
182 std::vector<uint32_t> mLoadWaitingQueue;
183 CircularQueue<ImageFrame> mQueue;
184 bool mIsSynchronousLoading;
185 bool mPreMultiplyOnLoad;
188 } // namespace Internal
190 } // namespace Toolkit
194 #endif //DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H