Prevent texture removal after TextureManager destroyed
[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) 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/texture-upload-observer.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 ImageCache : public TextureManager::LifecycleObserver
32 {
33 public:
34   /**
35    * Observer class to inform when the next image is ready
36    */
37   class FrameReadyObserver
38   {
39   public:
40     /**
41      * Informs observer when the next texture set is ready to display
42      * @param[in] textureSet The ready texture set
43      */
44     virtual void FrameReady( TextureSet textureSet ) = 0;
45   };
46
47   struct UrlStore
48   {
49     TextureManager::TextureId mTextureId;
50     std::string mUrl;
51   };
52
53   /**
54    * List of URLs
55    */
56   typedef std::vector<UrlStore> UrlList;
57
58 public:
59   /**
60    * Constructor.
61    * @param[in] textureManager The texture manager
62    * @param[in] urlList List of urls to cache
63    * @param[in] observer FrameReady observer
64    * @param[in] batchSize The size of a batch to load
65    *
66    * This will start loading textures immediately, according to the
67    * batch and cache sizes. The cache is as large as the number of urls.
68    */
69   ImageCache( TextureManager&                 textureManager,
70               ImageCache::FrameReadyObserver& observer,
71               unsigned int                    batchSize );
72
73   virtual ~ImageCache();
74
75   /**
76    * Get the first frame. If it's not ready, this will trigger the
77    * sending of FrameReady() when the image becomes ready.
78    */
79   virtual TextureSet FirstFrame() = 0;
80
81   /**
82    * Get the next frame. If it's not ready, this will trigger the
83    * sending of FrameReady() when the image becomes ready.
84    * This will trigger the loading of the next batch.
85    */
86   virtual TextureSet NextFrame() = 0;
87
88 private:
89   /**
90    * Called before the texture manager is destroyed.
91    */
92   virtual void TextureManagerDestroyed() override final;
93
94 protected:
95   TextureManager&        mTextureManager;
96   FrameReadyObserver&    mObserver;
97   unsigned int           mBatchSize;
98   unsigned int           mUrlIndex;
99   bool                   mWaitingForReadyFrame:1;
100   bool                   mRequestingLoad:1;
101   bool                   mTextureManagerAlive:1;
102 };
103
104 } //namespace Internal
105 } //namespace Toolkit
106 } //namespace Dali
107
108 #endif // DALI_TOOLKIT_INTERNAL_IMAGE_CACHE_H