Support WebP format
[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) 2020 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
31 class FixedImageCache : public ImageCache, public TextureUploadObserver
32 {
33 public:
34   /**
35    * Constructor.
36    * @param[in] textureManager The texture manager
37    * @param[in] urlList List of urls to cache
38    * @param[in] observer FrameReady observer
39    * @param[in] batchSize The size of a batch to load
40    *
41    * This will start loading textures immediately, according to the
42    * batch and cache sizes. The cache is as large as the number of urls.
43    */
44   FixedImageCache( TextureManager&                 textureManager,
45                    UrlList&                        urlList,
46                    ImageCache::FrameReadyObserver& observer,
47                    unsigned int                    batchSize );
48
49   virtual ~FixedImageCache();
50
51   /**
52    * Get the Nth frame. If it's not ready, this will trigger the
53    * sending of FrameReady() when the image becomes ready.
54    */
55   TextureSet Frame( uint32_t frameIndex ) override;
56
57   /**
58    * Get the first frame. If it's not ready, this will trigger the
59    * sending of FrameReady() when the image becomes ready.
60    */
61   TextureSet FirstFrame() override;
62
63   /**
64    * Get the interval of Nth frame.
65    */
66   uint32_t GetFrameInterval( uint32_t frameIndex ) override;
67
68 private:
69   /**
70    * @return true if the front frame is ready
71    */
72   bool IsFrontReady() const;
73
74   /**
75    * Load the next batch of images
76    */
77   void LoadBatch();
78
79   /**
80    * Find the matching image frame, and set it to ready
81    */
82   void SetImageFrameReady( TextureManager::TextureId textureId );
83
84   /**
85    * Get the texture set of the front frame.
86    * @return the texture set
87    */
88   TextureSet GetFrontTextureSet() const;
89
90   /**
91    * Check if the front frame has become ready - if so, inform observer
92    * @param[in] wasReady Readiness before call.
93    */
94   void CheckFrontFrame( bool wasReady );
95
96 protected:
97   void UploadComplete(
98     bool           loadSuccess,
99     int32_t        textureId,
100     TextureSet     textureSet,
101     bool           useAtlasing,
102     const Vector4& atlasRect,
103     bool           premultiplied ) override;
104
105   void LoadComplete(
106     bool loadSuccess,
107     Devel::PixelBuffer pixelBuffer,
108     const VisualUrl& url,
109     bool preMultiplied ) override;
110
111 private:
112   std::vector<UrlStore>& mImageUrls;
113   std::vector<bool> mReadyFlags;
114   unsigned int      mFront;
115 };
116
117 } //namespace Internal
118 } //namespace Toolkit
119 } //namespace Dali
120
121 #endif // DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H