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] 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
121 * @param[in] frameIndex index of frame to be loaded.
122 * @param[in] synchronousLoading true if the frame should be loaded synchronously
124 * @return the texture set currently loaded.
126 TextureSet RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading);
129 * @brief Load the next batch of images
131 * @param[in] frameIndex starting frame index of batch to be loaded.
133 void LoadBatch(uint32_t frameIndex);
136 * @brief Find the matching image frame, and set it to ready
138 * @param[in] textureId texture id to be marked as ready.
140 void SetImageFrameReady(TextureManager::TextureId textureId);
143 * @brief Get the texture set of the front frame.
145 * @return the texture set of the front of Cache.
147 TextureSet GetFrontTextureSet() const;
150 * @brief Get the texture id of the given index
152 * @param[in] index index of the queue.
154 TextureManager::TextureId GetCachedTextureId(int index) const;
157 * @brief Make the loaded frame ready and notify it to the texture upload observer
159 * @param[in] loadSuccess whether the loading is succeded or not.
160 * @param[in] textureSet textureSet for this frame.
161 * @param[in] interval interval between this frame and next frame.
163 void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval);
166 * @brief Pop front entity of Cache.
168 void PopFrontCache();
172 * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
174 void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
178 * Secondary class to hold readiness and index into url
182 uint32_t mFrameNumber = 0u;
185 std::vector<TextureManager::TextureId> mTextureIds;
188 Dali::AnimatedImageLoading mAnimatedImageLoading;
189 uint32_t mFrameCount;
190 uint32_t mFrameIndex;
192 std::vector<int32_t> mIntervals;
193 std::vector<uint32_t> mLoadWaitingQueue;
194 CircularQueue<ImageFrame> mQueue;
195 Dali::WrapMode::Type mWrapModeU : 3;
196 Dali::WrapMode::Type mWrapModeV : 3;
197 bool mIsSynchronousLoading;
198 bool mPreMultiplyOnLoad;
201 } // namespace Internal
203 } // namespace Toolkit
207 #endif //DALI_TOOLKIT_INTERNAL_ROLLING_ANIMATED_IMAGE_CACHE_H