Refactoring ImageVisualShaderFactory::GetShader
[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) 2021 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/visuals/animated-image/image-cache.h>
22 #include <dali-toolkit/internal/visuals/texture-manager-impl.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] observer FrameReady observer
38    * @param[in] batchSize The size of a batch to load
39    *
40    * This will start loading textures immediately, according to the
41    * batch and cache sizes. The cache is as large as the number of urls.
42    */
43   FixedImageCache(TextureManager&                 textureManager,
44                   UrlList&                        urlList,
45                   ImageCache::FrameReadyObserver& observer,
46                   unsigned int                    batchSize);
47
48   ~FixedImageCache() override;
49
50   /**
51    * Get the Nth frame. If it's not ready, this will trigger the
52    * sending of FrameReady() when the image becomes ready.
53    */
54   TextureSet Frame(uint32_t frameIndex) override;
55
56   /**
57    * Get the first frame. If it's not ready, this will trigger the
58    * sending of FrameReady() when the image becomes ready.
59    */
60   TextureSet FirstFrame() override;
61
62   /**
63    * Get the next frame. If it's not ready, this will trigger the
64    * sending of FrameReady() when the image becomes ready.
65    */
66   TextureSet NextFrame() override;
67
68   /**
69    * Get the interval of Nth frame.
70    */
71   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
72
73   /**
74    * Get the current rendered frame index.
75    * If there isn't any loaded frame, returns -1.
76    */
77   int32_t GetCurrentFrameIndex() const override;
78
79   /**
80    * Get total frame count of the animated image file.
81    */
82   int32_t GetTotalFrameCount() const override;
83
84 private:
85   /**
86    * @return true if the front frame is ready
87    */
88   bool IsFrontReady() const;
89
90   /**
91    * Load the next batch of images
92    */
93   void LoadBatch();
94
95   /**
96    * Find the matching image frame, and set it to ready
97    */
98   void SetImageFrameReady(TextureManager::TextureId textureId);
99
100   /**
101    * Get the texture set of the front frame.
102    * @return the texture set
103    */
104   TextureSet GetFrontTextureSet() const;
105
106   /**
107    * Check if the front frame has become ready - if so, inform observer
108    * @param[in] wasReady Readiness before call.
109    */
110   void CheckFrontFrame(bool wasReady);
111
112 protected:
113   void UploadComplete(
114     bool           loadSuccess,
115     int32_t        textureId,
116     TextureSet     textureSet,
117     bool           useAtlasing,
118     const Vector4& atlasRect,
119     bool           premultiplied) override;
120
121   void LoadComplete(
122     bool               loadSuccess,
123     Devel::PixelBuffer pixelBuffer,
124     const VisualUrl&   url,
125     bool               preMultiplied) override;
126
127 private:
128   std::vector<UrlStore>& mImageUrls;
129   std::vector<bool>      mReadyFlags;
130   unsigned int           mFront;
131 };
132
133 } //namespace Internal
134 } //namespace Toolkit
135 } //namespace Dali
136
137 #endif // DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H