big patch from Samsung SAIT (Advanced research group) for async multi-frame
[framework/uifw/evas.git] / src / lib / cache / evas_cache.h
1 #ifndef _EVAS_CACHE_H
2 #define _EVAS_CACHE_H
3
4
5 typedef struct _Evas_Cache_Image                Evas_Cache_Image;
6 typedef struct _Evas_Cache_Image_Func           Evas_Cache_Image_Func;
7 typedef struct _Evas_Cache_Engine_Image         Evas_Cache_Engine_Image;
8 typedef struct _Evas_Cache_Engine_Image_Func    Evas_Cache_Engine_Image_Func;
9
10
11 struct _Evas_Cache_Image_Func
12 {
13    Image_Entry *(*alloc)(void);
14    void         (*dealloc)(Image_Entry *im);
15
16    /* The cache provide some helpers for surface manipulation. */
17    int          (*surface_alloc)(Image_Entry *im, int w, int h);
18    void         (*surface_delete)(Image_Entry *im);
19    DATA32      *(*surface_pixels)(Image_Entry *im);
20
21    /* The cache is doing the allocation and deallocation, you must just do the rest. */
22    int          (*constructor)(Image_Entry *im); /**< return is EVAS_LOAD_ERROR_* or EVAS_LOAD_ERROR_NONE! */
23    void         (*destructor)(Image_Entry *im);
24
25    void         (*dirty_region)(Image_Entry *im, int x, int y, int w, int h);
26    /* Only called when references > 0. Need to provide a fresh copie of im. */
27    /* The destination surface does have a surface, but no allocated pixel data. */
28    int          (*dirty)(Image_Entry *dst, const Image_Entry *src);
29    /* Only called when references == 1. We will call drop on `im'. */
30    /* The destination surface does not have any surface. */
31    int          (*size_set)(Image_Entry *dst, const Image_Entry *src, int w, int h);
32
33    /* The destination surface does not have any surface. */
34    int          (*copied_data)(Image_Entry *dst, int w, int h, DATA32 *image_data, int alpha, int cspace);
35    /* The destination surface does not have any surface. */
36    int          (*data)(Image_Entry *dst, int w, int h, DATA32 *image_data, int alpha, int cspace);
37    int          (*color_space)(Image_Entry *dst, int cspace);
38
39    /* This function need to update im->w and im->h. */
40    int          (*load)(Image_Entry *im); /**< return is EVAS_LOAD_ERROR_* or EVAS_LOAD_ERROR_NONE! */
41    int          (*mem_size_get)(Image_Entry *im);
42    void         (*debug)(const char *context, Image_Entry *im);
43 };
44
45 struct _Evas_Cache_Image
46 {
47    Evas_Cache_Image_Func         func;
48
49    Eina_List                    *preload;
50    Eina_List                    *pending;
51
52    Eina_Inlist                  *dirty;
53
54    Eina_Inlist                  *lru;
55    Eina_Inlist                  *lru_nodata;
56    Eina_Hash                    *inactiv;
57    Eina_Hash                    *activ;
58    void                         *data;
59
60    int                           usage;
61    int                           limit;
62    int                           references;
63 #ifdef EVAS_FRAME_QUEUING
64    LK(lock);
65 #endif
66 };
67
68 struct _Evas_Cache_Engine_Image_Func
69 {
70    /* Must return a char* allocated with eina_stringshare_add. */
71    char*                (*key)(Image_Entry *im, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
72
73    Engine_Image_Entry*  (*alloc)(void);
74    void                 (*dealloc)(Engine_Image_Entry *eim);
75
76    int                  (*constructor)(Engine_Image_Entry *eim, void* data);
77    void                 (*destructor)(Engine_Image_Entry *eim);
78
79    void                 (*dirty_region)(Engine_Image_Entry *eim, int x, int y, int w, int h);
80    /* Only called when references > 0. Need to provide a fresh copie of im. */
81    int                  (*dirty)(Engine_Image_Entry *dst, const Engine_Image_Entry *src);
82    /* Only called when references == 1. We will call drop on `im'. */
83    int                  (*size_set)(Engine_Image_Entry *dst, const Engine_Image_Entry *src);
84
85    int                  (*update_data)(Engine_Image_Entry* dst, void* data);
86
87    void                 (*load)(Engine_Image_Entry *eim, const Image_Entry* im);
88    int                  (*mem_size_get)(Engine_Image_Entry *eim);
89    void                 (*debug)(const char* context, Engine_Image_Entry *eim);
90 };
91
92 struct _Evas_Cache_Engine_Image
93 {
94    Evas_Cache_Engine_Image_Func func;
95
96    Eina_Inlist*                 dirty;
97
98    Eina_Hash*                   activ;
99    Eina_Hash*                   inactiv;
100    Eina_Inlist*                 lru;
101
102    Evas_Cache_Image*            parent;
103    Evas_Cache_Engine_Image*     brother;
104
105    int                          usage;
106    int                          limit;
107
108    int                          references;
109 };
110
111
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115
116
117 EAPI Evas_Cache_Image*        evas_cache_image_init(const Evas_Cache_Image_Func *cb);
118 EAPI void                     evas_cache_image_shutdown(Evas_Cache_Image *cache);
119 EAPI Image_Entry*             evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
120 EAPI void                     evas_cache_image_drop(Image_Entry *im);
121 EAPI void                     evas_cache_image_data_not_needed(Image_Entry *im);
122 EAPI int                      evas_cache_image_flush(Evas_Cache_Image *cache);
123 EAPI void                     evas_cache_private_set(Evas_Cache_Image *cache, const void *data);
124 EAPI void*                    evas_cache_private_get(Evas_Cache_Image *cache);
125 EAPI void*                    evas_cache_private_from_image_entry_get(Image_Entry *im);
126
127 EAPI int                      evas_cache_image_usage_get(Evas_Cache_Image *cache);
128 EAPI int                      evas_cache_image_get(Evas_Cache_Image *cache);
129 EAPI void                     evas_cache_image_set(Evas_Cache_Image *cache, int size);
130
131 EAPI Image_Entry*             evas_cache_image_alone(Image_Entry *im);
132 EAPI Image_Entry*             evas_cache_image_dirty(Image_Entry *im, int x, int y, int w, int h);
133 EAPI void                     evas_cache_image_load_data(Image_Entry *im);
134 EAPI void                     evas_cache_image_unload_data(Image_Entry *im);
135 EAPI Eina_Bool                evas_cache_image_is_loaded(Image_Entry *im);
136 EAPI void                     evas_cache_image_unload_all(Evas_Cache_Image *cache);
137 EAPI void                     evas_cache_image_surface_alloc(Image_Entry *im, int w, int h);
138 EAPI DATA32*                  evas_cache_image_pixels(Image_Entry *im);
139 EAPI Image_Entry*             evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace);
140 EAPI Image_Entry*             evas_cache_image_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace);
141 EAPI void                     evas_cache_image_colorspace(Image_Entry *im, int cspace);
142 EAPI Image_Entry*             evas_cache_image_empty(Evas_Cache_Image *cache);
143 EAPI Image_Entry*             evas_cache_image_size_set(Image_Entry *im, int w, int h);
144
145 EAPI Evas_Cache_Engine_Image* evas_cache_engine_image_init(const Evas_Cache_Engine_Image_Func *cb, Evas_Cache_Image *parent);
146 EAPI void                     evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache);
147
148 EAPI int                      evas_cache_engine_image_usage_get(Evas_Cache_Engine_Image *cache);
149 EAPI int                      evas_cache_engine_image_get(Evas_Cache_Engine_Image *cache);
150 EAPI void                     evas_cache_engine_image_set(Evas_Cache_Engine_Image *cache, int limit);
151
152 EAPI Engine_Image_Entry*      evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, void *engine_data, int *error);
153 EAPI void                     evas_cache_engine_parent_not_needed(Engine_Image_Entry *eim);
154 EAPI Engine_Image_Entry*      evas_cache_engine_image_engine(Evas_Cache_Engine_Image *cache, void *engine_data);
155 EAPI void                     evas_cache_engine_image_drop(Engine_Image_Entry *eim);
156 EAPI Engine_Image_Entry*      evas_cache_engine_image_alone(Engine_Image_Entry *eim, void *data);
157 EAPI Engine_Image_Entry*      evas_cache_engine_image_dirty(Engine_Image_Entry *eim, int x, int y, int w, int h);
158 EAPI Engine_Image_Entry*      evas_cache_engine_image_copied_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data);
159 EAPI Engine_Image_Entry*      evas_cache_engine_image_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data);
160 EAPI void                     evas_cache_engine_image_colorspace(Engine_Image_Entry *eim, int cspace, void *engine_data);
161 EAPI Engine_Image_Entry*      evas_cache_engine_image_size_set(Engine_Image_Entry *eim, int w, int h);
162
163 EAPI void                     evas_cache_engine_image_load_data(Engine_Image_Entry *eim);
164
165 EAPI void                     evas_cache_image_preload_data(Image_Entry *im, const void *target);
166 EAPI void                     evas_cache_image_preload_cancel(Image_Entry *im, const void *target);
167
168 EAPI void                     evas_cache_image_wakeup(void);
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174
175 #endif /* _EVAS_CACHE_H */