1 #ifndef DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H
5 * Copyright (c) 2024 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] size The width and height to fit the loaded image to.
46 * @param[in] fittingMode The FittingMode of the resource to load
47 * @param[in] samplingMode The SamplingMode of the resource to load
48 * @param[in] animatedImageLoading The loaded animated image
49 * @param[in] maskingData Masking data to be applied.
50 * @param[in] observer FrameReady observer
51 * @param[in] cacheSize The size of the cache
52 * @param[in] batchSize The size of a batch to load
53 * @param[in] wrapModeU Horizontal Wrap mode
54 * @param[in] wrapModeV Vertical Wrap mode
55 * @param[in] isSynchronousLoading The flag to define whether to load first frame synchronously
56 * @param[in] preMultiplyOnLoad The flag if image's color should be multiplied by it's alpha
58 * This will start loading textures immediately, according to the
59 * batch and cache sizes.
61 RollingAnimatedImageCache(TextureManager& textureManager,
63 Dali::FittingMode::Type fittingMode,
64 Dali::SamplingMode::Type samplingMode,
65 AnimatedImageLoading& animatedImageLoading,
66 TextureManager::MaskingDataPointer& maskingData,
67 ImageCache::FrameReadyObserver& observer,
70 const Dali::WrapMode::Type& wrapModeU,
71 const Dali::WrapMode::Type& wrapModeV,
72 bool isSynchronousLoading,
73 bool preMultiplyOnLoad);
78 ~RollingAnimatedImageCache() override;
81 * @copydoc Internal::ImageCache::Frame()
83 TextureSet Frame(uint32_t frameIndex) override;
86 * @copydoc Internal::ImageCache::FirstFrame()
88 TextureSet FirstFrame() override;
91 * @copydoc Internal::ImageCache::GetFrameInterval()
93 uint32_t GetFrameInterval(uint32_t frameIndex) const override;
96 * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
98 int32_t GetCurrentFrameIndex() const override;
101 * @copydoc Internal::ImageCache::GetTotalFrameCount()
103 int32_t GetTotalFrameCount() const override;
106 * @copydoc Internal::ImageCache::ClearCache()
108 void ClearCache() override;
112 * @brief Check whether the front frame is ready or not.
114 * @return true if the front frame is ready
116 bool IsFrontReady() const;
119 * @brief Request to Load a frame asynchronously
121 * @param[in] frameIndex index of frame to be loaded.
123 * @return the texture set currently loaded.
125 TextureSet RequestFrameLoading(uint32_t frameIndex);
128 * @brief Request to Load a frame
130 * @param[in] frameIndex Index of frame to be loaded.
131 * @param[in] synchronousLoading True if the frame should be loaded synchronously
132 * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
133 * image has no alpha channel
135 * @return the texture set currently loaded.
137 TextureSet RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading, TextureManager::MultiplyOnLoad& preMultiplyOnLoading);
140 * @brief Load the next batch of images
142 * @param[in] frameIndex starting frame index of batch to be loaded.
144 void LoadBatch(uint32_t frameIndex);
147 * @brief Find the matching image frame, and set it to ready
149 * @param[in] textureId texture id to be marked as ready.
151 void SetImageFrameReady(TextureManager::TextureId textureId);
154 * @brief Get the texture set of the front frame.
156 * @return the texture set of the front of Cache.
158 TextureSet GetFrontTextureSet() const;
161 * @brief Get the texture id of the given index
163 * @param[in] index index of the queue.
165 TextureManager::TextureId GetCachedTextureId(int index) const;
168 * @brief Make the loaded frame ready and notify it to the texture upload observer
170 * @param[in] loadSuccess whether the loading is succeded or not.
171 * @param[in] textureSet textureSet for this frame.
172 * @param[in] frameCount Total frame count for this image.
173 * @param[in] interval interval between this frame and next frame.
174 * @param[in] preMultiplied whether the texture is premultied alpha or not.
176 void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t frameCount, uint32_t interval, bool preMultiplied);
179 * @brief Pop front entity of Cache.
181 void PopFrontCache();
185 * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
187 void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
191 * Secondary class to hold readiness and index into url
195 uint32_t mFrameNumber = 0u;
198 std::vector<TextureManager::TextureId> mTextureIds;
201 Dali::AnimatedImageLoading mAnimatedImageLoading;
202 uint32_t mFrameCount;
203 uint32_t mFrameIndex;
205 std::vector<int32_t> mIntervals;
206 std::vector<uint32_t> mLoadWaitingQueue;
207 CircularQueue<ImageFrame> mQueue;
208 Dali::WrapMode::Type mWrapModeU : 3;
209 Dali::WrapMode::Type mWrapModeV : 3;
210 bool mIsSynchronousLoading;
213 } // namespace Internal
215 } // namespace Toolkit
219 #endif //DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H