CPU Alpha Masking for Animated Image Visual
[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) 2022 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] urlList        List of urls to cache
37    * @param[in] maskingData    Masking data to be applied.
38    * @param[in] observer       FrameReady observer
39    * @param[in] batchSize      The size of a batch to load
40    * @param[in] interval       Time interval between each frame
41    *
42    * This will start loading textures immediately, according to the
43    * batch and cache sizes. The cache is as large as the number of urls.
44    */
45   FixedImageCache(TextureManager&                     textureManager,
46                   UrlList&                            urlList,
47                   TextureManager::MaskingDataPointer& maskingData,
48                   ImageCache::FrameReadyObserver&     observer,
49                   uint32_t                            batchSize,
50                   uint32_t                            interval);
51
52   ~FixedImageCache() override;
53
54   /**
55    * @copydoc Internal::ImageCache::Frame()
56    */
57   TextureSet Frame(uint32_t frameIndex) override;
58
59   /**
60    * @copydoc Internal::ImageCache::FirstFrame()
61    */
62   TextureSet FirstFrame() override;
63
64   /**
65    * @copydoc Internal::ImageCache::GetFrameInterval()
66    */
67   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
68
69   /**
70    * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
71    */
72   int32_t GetCurrentFrameIndex() const override;
73
74   /**
75    * @copydoc Internal::ImageCache::GetTotalFrameCount()
76    */
77   int32_t GetTotalFrameCount() const override;
78
79   /**
80    * @copydoc Internal::ImageCache::ClearCache()
81    */
82   void ClearCache() override;
83
84 private:
85   /**
86    * @brief Check whether the front frame is ready or not.
87    *
88    * @return true if the front frame is ready
89    */
90   bool IsFrontReady() const;
91
92   /**
93    * @brief Load the next batch of images
94    */
95   void LoadBatch();
96
97   /**
98    * @brief Get the texture set of the front frame.
99    *
100    * @return the texture set of the front of Cache.
101    */
102   TextureSet GetFrontTextureSet() const;
103
104   /**
105    * @brief Check if the front frame has become ready - if so, inform observer
106    *
107    * @param[in] wasReady Readiness before call.
108    */
109   void CheckFrontFrame(bool wasReady);
110
111 protected:
112   /**
113    * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
114    */
115   void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
116
117 private:
118   std::vector<UrlStore>&                 mImageUrls;
119   std::vector<bool>                      mReadyFlags;
120   std::vector<TextureManager::LoadState> mLoadStates;
121   uint32_t                               mFront;
122 };
123
124 } //namespace Internal
125 } //namespace Toolkit
126 } //namespace Dali
127
128 #endif // DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H