1 /**
2  * @file lv_draw_sdl_texture_cache.h
3  *
4  */
5 
6 #ifndef LV_DRAW_SDL_TEXTURE_CACHE_H
7 #define LV_DRAW_SDL_TEXTURE_CACHE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 
17 #include "../../lv_conf_internal.h"
18 
19 #if LV_USE_GPU_SDL
20 
21 #include LV_GPU_SDL_INCLUDE_PATH
22 #include "lv_draw_sdl.h"
23 #include "lv_draw_sdl_priv.h"
24 #include "../../draw/lv_img_decoder.h"
25 #include "../../misc/lv_area.h"
26 
27 /*********************
28  *      DEFINES
29  *********************/
30 
31 #define LV_DRAW_SDL_DEC_DSC_TEXTURE_HEAD "@LVSDLTex"
32 
33 /**********************
34  *      TYPEDEFS
35  **********************/
36 
37 typedef struct {
38     char head[8];
39     SDL_Texture * texture;
40     SDL_Rect rect;
41     bool texture_managed;
42     bool texture_referenced;
43 } lv_draw_sdl_dec_dsc_userdata_t;
44 
45 typedef enum {
46     LV_GPU_CACHE_KEY_MAGIC_ARC = 0x01,
47     LV_GPU_CACHE_KEY_MAGIC_IMG = 0x11,
48     LV_GPU_CACHE_KEY_MAGIC_IMG_ROUNDED_CORNERS = 0x12,
49     LV_GPU_CACHE_KEY_MAGIC_LINE = 0x21,
50     LV_GPU_CACHE_KEY_MAGIC_RECT_BG = 0x31,
51     LV_GPU_CACHE_KEY_MAGIC_RECT_SHADOW = 0x32,
52     LV_GPU_CACHE_KEY_MAGIC_RECT_BORDER = 0x33,
53     LV_GPU_CACHE_KEY_MAGIC_RECT_GRAD = 0x34,
54     LV_GPU_CACHE_KEY_MAGIC_FONT_GLYPH = 0x41,
55     LV_GPU_CACHE_KEY_MAGIC_MASK = 0x51,
56 } lv_sdl_cache_key_magic_t;
57 
58 typedef enum {
59     LV_DRAW_SDL_CACHE_FLAG_NONE = 0,
60     LV_DRAW_SDL_CACHE_FLAG_MANAGED = 1,
61 } lv_draw_sdl_cache_flag_t;
62 
63 typedef struct {
64     lv_sdl_cache_key_magic_t magic;
65     lv_img_src_t type;
66     int32_t frame_id;
67 } lv_draw_sdl_cache_key_head_img_t;
68 
69 /**********************
70  * GLOBAL PROTOTYPES
71  **********************/
72 
73 void lv_draw_sdl_texture_cache_init(lv_draw_sdl_ctx_t * ctx);
74 
75 void lv_draw_sdl_texture_cache_deinit(lv_draw_sdl_ctx_t * ctx);
76 
77 /**
78  * Find cached texture by key. The texture can be destroyed during usage.
79  */
80 SDL_Texture * lv_draw_sdl_texture_cache_get(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, bool * found);
81 
82 SDL_Texture * lv_draw_sdl_texture_cache_get_with_userdata(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
83                                                           bool * found, void ** userdata);
84 
85 /**
86  * @return Whether the texture has been put in the cache
87  */
88 bool lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture);
89 
90 /**
91  * @return Whether the texture has been put in the cache
92  */
93 bool lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
94                                             SDL_Texture * texture, void * userdata, void userdata_free(void *),
95                                             lv_draw_sdl_cache_flag_t flags);
96 
97 lv_draw_sdl_cache_key_head_img_t * lv_draw_sdl_texture_img_key_create(const void * src, int32_t frame_id,
98                                                                       size_t * size);
99 
100 /**********************
101  *      MACROS
102  **********************/
103 #endif /*LV_USE_GPU_SDL*/
104 
105 #ifdef __cplusplus
106 } /*extern "C"*/
107 #endif
108 
109 #endif /*LV_DRAW_SDL_TEXTURE_CACHE_H*/
110