1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_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/texture-manager/texture-upload-observer.h>
30 class ImageCache : public TextureManager::LifecycleObserver
34 * Observer class to inform when the next image is ready
36 class FrameReadyObserver
40 * @brief Informs observer when the next texture set is ready to display
41 * @param[in] textureSet The ready texture set
42 * @param[in] interval interval(ms) for the frame
44 virtual void FrameReady(TextureSet textureSet, uint32_t interval) = 0;
49 TextureManager::TextureId mTextureId = TextureManager::INVALID_TEXTURE_ID;
56 typedef std::vector<UrlStore> UrlList;
61 * @param[in] textureManager The texture manager
62 * @param[in] urlList List of urls to cache
63 * @param[in] observer FrameReady observer
64 * @param[in] batchSize The size of a batch to load
65 * @param[in] interval Time interval(ms) between each frame
67 * This will start loading textures immediately, according to the
68 * batch and cache sizes. The cache is as large as the number of urls.
70 ImageCache(TextureManager& textureManager,
71 ImageCache::FrameReadyObserver& observer,
75 virtual ~ImageCache();
78 * @brief Get the first frame. If it's not ready, this will trigger the
79 * sending of FrameReady() when the image becomes ready.
81 * @return TextureSet of the first frame.
83 virtual TextureSet FirstFrame() = 0;
86 * @brief Get the Nth frame. If it's not ready, this will trigger the
87 * sending of FrameReady() when the image becomes ready.
89 * @param[in] frameIndex required frame index to be returned.
90 * @return TextureSet of the frame index.
92 virtual TextureSet Frame(uint32_t frameIndex) = 0;
95 * @brief Get the interval(ms) of Nth frame.
97 * @param[in] frameIndex frame index to get frame interval.
98 * @return Time interval in millisecond between frames of frameIndex and frameIndex + 1.
100 virtual uint32_t GetFrameInterval(uint32_t frameIndex) const = 0;
103 * @brief Get the current rendered frame index.
104 * If there isn't any loaded frame, returns -1.
106 * @return Frame index of currently showing frame.
108 virtual int32_t GetCurrentFrameIndex() const = 0;
111 * @brief Get total frame count of the animated image file.
113 * @return Total frame count of the animated image file.
115 virtual int32_t GetTotalFrameCount() const = 0;
118 * @brief Clears animated image cache and remove loaded textures.
120 virtual void ClearCache() = 0;
123 * @brief Set default interval(ms) between each frame.
125 * @param[in] interval time interval in millisecond to be used as default interval.
127 virtual void SetInterval(uint32_t interval);
131 * @brief Called before the texture manager is destroyed.
133 void TextureManagerDestroyed() final;
136 TextureManager& mTextureManager;
137 FrameReadyObserver& mObserver;
140 TextureManager::LoadState mLoadState;
141 bool mRequestingLoad : 1;
142 bool mTextureManagerAlive : 1;
145 } //namespace Internal
146 } //namespace Toolkit
149 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_CACHE_H