Updated all header files to new format
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / animated-image / image-cache.h
1 #ifndef DALI_TOOLKIT_INTERNAL_IMAGE_CACHE_H
2 #define DALI_TOOLKIT_INTERNAL_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/texture-manager-impl.h>
22 #include <dali-toolkit/internal/visuals/texture-upload-observer.h>
23
24 namespace Dali
25 {
26 namespace Toolkit
27 {
28 namespace Internal
29 {
30 class ImageCache : public TextureManager::LifecycleObserver
31 {
32 public:
33   /**
34    * Observer class to inform when the next image is ready
35    */
36   class FrameReadyObserver
37   {
38   public:
39     /**
40      * Informs observer when the next texture set is ready to display
41      * @param[in] textureSet The ready texture set
42      */
43     virtual void FrameReady(TextureSet textureSet) = 0;
44   };
45
46   struct UrlStore
47   {
48     TextureManager::TextureId mTextureId = TextureManager::INVALID_TEXTURE_ID;
49     std::string               mUrl;
50   };
51
52   /**
53    * List of URLs
54    */
55   typedef std::vector<UrlStore> UrlList;
56
57 public:
58   /**
59    * Constructor.
60    * @param[in] textureManager The texture manager
61    * @param[in] urlList List of urls to cache
62    * @param[in] observer FrameReady observer
63    * @param[in] batchSize The size of a batch to load
64    *
65    * This will start loading textures immediately, according to the
66    * batch and cache sizes. The cache is as large as the number of urls.
67    */
68   ImageCache(TextureManager&                 textureManager,
69              ImageCache::FrameReadyObserver& observer,
70              unsigned int                    batchSize);
71
72   virtual ~ImageCache();
73
74   /**
75    * Get the first frame. If it's not ready, this will trigger the
76    * sending of FrameReady() when the image becomes ready.
77    */
78   virtual TextureSet FirstFrame() = 0;
79
80   /**
81    * Get the next frame. If it's not ready, this will trigger the
82    * sending of FrameReady() when the image becomes ready.
83    */
84   virtual TextureSet NextFrame() = 0;
85
86   /**
87    * Get the Nth frame. If it's not ready, this will trigger the
88    * sending of FrameReady() when the image becomes ready.
89    */
90   virtual TextureSet Frame(uint32_t frameIndex) = 0;
91
92   /**
93    * Get the interval of Nth frame.
94    */
95   virtual uint32_t GetFrameInterval(uint32_t frameIndex) const = 0;
96
97   /**
98    * Get the current rendered frame index.
99    * If there isn't any loaded frame, returns -1.
100    */
101   virtual int32_t GetCurrentFrameIndex() const = 0;
102
103   /**
104    * Get total frame count of the animated image file.
105    */
106   virtual int32_t GetTotalFrameCount() const = 0;
107
108 private:
109   /**
110    * Called before the texture manager is destroyed.
111    */
112   void TextureManagerDestroyed() final;
113
114 protected:
115   TextureManager&     mTextureManager;
116   FrameReadyObserver& mObserver;
117   unsigned int        mBatchSize;
118   unsigned int        mUrlIndex;
119   bool                mWaitingForReadyFrame : 1;
120   bool                mRequestingLoad : 1;
121   bool                mTextureManagerAlive : 1;
122 };
123
124 } //namespace Internal
125 } //namespace Toolkit
126 } //namespace Dali
127
128 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_CACHE_H