[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / fixed-image-cache.h
1 #ifndef DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H
3
4 /*
5  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 // EXTERNAL INCLUDES
21 #include <dali-toolkit/internal/texture-manager/texture-manager-impl.h>
22 #include <dali-toolkit/internal/visuals/animated-image/image-cache.h>
23
24 namespace Dali
25 {
26 namespace Toolkit
27 {
28 namespace Internal
29 {
30 class FixedImageCache : public ImageCache, public TextureUploadObserver
31 {
32 public:
33   /**
34    * Constructor.
35    * @param[in] textureManager    The texture manager
36    * @param[in] size              The width and height to fit the loaded image to.
37    * @param[in] fittingMode       The FittingMode of the resource to load
38    * @param[in] samplingMode      The SamplingMode of the resource to load
39    * @param[in] urlList           List of urls to cache
40    * @param[in] maskingData       Masking data to be applied.
41    * @param[in] observer          FrameReady observer
42    * @param[in] batchSize         The size of a batch to load
43    * @param[in] interval          Time interval between each frame
44    * @param[in] preMultiplyOnLoad The flag if image's color should be multiplied by it's alpha
45    *
46    * This will start loading textures immediately, according to the
47    * batch and cache sizes. The cache is as large as the number of urls.
48    */
49   FixedImageCache(TextureManager&                     textureManager,
50                   ImageDimensions                     size,
51                   Dali::FittingMode::Type             fittingMode,
52                   Dali::SamplingMode::Type            samplingMode,
53                   UrlList&                            urlList,
54                   TextureManager::MaskingDataPointer& maskingData,
55                   ImageCache::FrameReadyObserver&     observer,
56                   uint32_t                            batchSize,
57                   uint32_t                            interval,
58                   bool                                preMultiplyOnLoad);
59
60   ~FixedImageCache() override;
61
62   /**
63    * @copydoc Internal::ImageCache::Frame()
64    */
65   TextureSet Frame(uint32_t frameIndex) override;
66
67   /**
68    * @copydoc Internal::ImageCache::FirstFrame()
69    */
70   TextureSet FirstFrame() override;
71
72   /**
73    * @copydoc Internal::ImageCache::GetFrameInterval()
74    */
75   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
76
77   /**
78    * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
79    */
80   int32_t GetCurrentFrameIndex() const override;
81
82   /**
83    * @copydoc Internal::ImageCache::GetTotalFrameCount()
84    */
85   int32_t GetTotalFrameCount() const override;
86
87   /**
88    * @copydoc Internal::ImageCache::ClearCache()
89    */
90   void ClearCache() override;
91
92 private:
93   /**
94    * @brief Check whether the frame is ready or not.
95    * @param[in] frameIndex The frame index to check the frame is ready or not.
96    *
97    * @return true if the frame is ready
98    */
99   bool IsFrameReady(uint32_t frameIndex) const;
100
101   /**
102    * @brief Load the next batch of images
103    */
104   void LoadBatch();
105
106   /**
107    * @brief Get the texture set at the input frame index
108    * @param[in] frameIndex The frame index to retrieve texture set.
109    *
110    * @return the texture set of the front of Cache.
111    */
112   TextureSet GetTextureSet(uint32_t frameIndex) const;
113
114   /**
115    * @brief Check if the front frame has become ready - if so, inform observer
116    *
117    * @param[in] wasReady Readiness before call.
118    * @param[in] frameIndex The frame index for this frame
119    * @param[in] preMultiplied whether the texture is premultied alpha or not.
120    */
121   void MakeReady(bool wasReady, uint32_t frameIndex, bool preMultiplied);
122
123 protected:
124   /**
125    * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
126    */
127   void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
128
129 private:
130   std::vector<UrlStore>&                 mImageUrls;
131   std::vector<bool>                      mReadyFlags;
132   std::vector<TextureManager::LoadState> mLoadStates;
133   uint32_t                               mCurrentFrameIndex;
134 };
135
136 } //namespace Internal
137 } //namespace Toolkit
138 } //namespace Dali
139
140 #endif // DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H