[dali_1.2.58] 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) 2017 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
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 first frame. If it's not ready, this will trigger the
53    * sending of FrameReady() when the image becomes ready.
54    */
55   virtual TextureSet FirstFrame();
56
57   /**
58    * Get the next frame. If it's not ready, this will trigger the
59    * sending of FrameReady() when the image becomes ready.
60    * This will trigger the loading of the next batch.
61    */
62   virtual TextureSet NextFrame();
63
64 private:
65   /**
66    * @return true if the front frame is ready
67    */
68   bool IsFrontReady() const;
69
70   /**
71    * Load the next batch of images
72    */
73   void LoadBatch();
74
75   /**
76    * Find the matching image frame, and set it to ready
77    */
78   void SetImageFrameReady( TextureManager::TextureId textureId );
79
80   /**
81    * Get the texture set of the front frame.
82    * @return the texture set
83    */
84   TextureSet GetFrontTextureSet() const;
85
86   /**
87    * Check if the front frame has become ready - if so, inform observer
88    * @param[in] wasReady Readiness before call.
89    */
90   void CheckFrontFrame( bool wasReady );
91
92 protected:
93   virtual void UploadComplete(
94     bool           loadSuccess,
95     int32_t        textureId,
96     TextureSet     textureSet,
97     bool           useAtlasing,
98     const Vector4& atlasRect );
99
100 protected:
101   std::vector<bool> mReadyFlags;
102   unsigned int      mFront;
103 };
104
105 } //namespace Internal
106 } //namespace Toolkit
107 } //namespace Dali
108
109 #endif // DALI_TOOLKIT_INTERNAL_FIXED_IMAGE_CACHE_H