1 /**
2  * @file lv_draw_sdl.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 
10 
11 #include "../../lv_conf_internal.h"
12 
13 #if LV_USE_GPU_SDL
14 
15 #include "lv_draw_sdl.h"
16 #include "lv_draw_sdl_utils.h"
17 #include "lv_draw_sdl_texture_cache.h"
18 #include "lv_draw_sdl_layer.h"
19 
20 /*********************
21  *      DEFINES
22  *********************/
23 void lv_draw_sdl_draw_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
24 
25 lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc,
26                               const lv_area_t * coords, const void * src);
27 
28 void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc,  const lv_point_t * pos_p,
29                              uint32_t letter);
30 
31 void lv_draw_sdl_draw_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
32                            const lv_point_t * point2);
33 
34 void lv_draw_sdl_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center,
35                           uint16_t radius, uint16_t start_angle, uint16_t end_angle);
36 
37 void lv_draw_sdl_polygon(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_point_t * points,
38                          uint16_t point_cnt);
39 
40 void lv_draw_sdl_draw_bg(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
41 
42 /**********************
43  *      TYPEDEFS
44  **********************/
45 
46 /**********************
47  *  STATIC PROTOTYPES
48  **********************/
49 
50 /**********************
51  *  STATIC VARIABLES
52  **********************/
53 
54 /**********************
55  *      MACROS
56  **********************/
57 
58 /**********************
59  *   GLOBAL FUNCTIONS
60  **********************/
61 
lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv,lv_draw_ctx_t * draw_ctx)62 void lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
63 {
64     _lv_draw_sdl_utils_init();
65     lv_memset_00(draw_ctx, sizeof(lv_draw_sdl_ctx_t));
66     draw_ctx->draw_rect = lv_draw_sdl_draw_rect;
67     draw_ctx->draw_img = lv_draw_sdl_img_core;
68     draw_ctx->draw_letter = lv_draw_sdl_draw_letter;
69     draw_ctx->draw_line = lv_draw_sdl_draw_line;
70     draw_ctx->draw_arc = lv_draw_sdl_draw_arc;
71     draw_ctx->draw_polygon = lv_draw_sdl_polygon;
72     draw_ctx->draw_bg = lv_draw_sdl_draw_bg;
73     draw_ctx->layer_init = lv_draw_sdl_layer_init;
74     draw_ctx->layer_blend = lv_draw_sdl_layer_blend;
75     draw_ctx->layer_destroy = lv_draw_sdl_layer_destroy;
76     draw_ctx->layer_instance_size = sizeof(lv_draw_sdl_layer_ctx_t);
77     lv_draw_sdl_ctx_t * draw_ctx_sdl = (lv_draw_sdl_ctx_t *) draw_ctx;
78     draw_ctx_sdl->renderer = ((lv_draw_sdl_drv_param_t *) disp_drv->user_data)->renderer;
79     draw_ctx_sdl->internals = lv_mem_alloc(sizeof(lv_draw_sdl_context_internals_t));
80     lv_memset_00(draw_ctx_sdl->internals, sizeof(lv_draw_sdl_context_internals_t));
81     lv_draw_sdl_texture_cache_init(draw_ctx_sdl);
82 }
83 
lv_draw_sdl_deinit_ctx(lv_disp_drv_t * disp_drv,lv_draw_ctx_t * draw_ctx)84 void lv_draw_sdl_deinit_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
85 {
86     lv_draw_sdl_ctx_t * draw_ctx_sdl = (lv_draw_sdl_ctx_t *) draw_ctx;
87     lv_draw_sdl_texture_cache_deinit(draw_ctx_sdl);
88     lv_mem_free(draw_ctx_sdl->internals);
89     _lv_draw_sdl_utils_deinit();
90 }
91 
lv_draw_sdl_create_screen_texture(SDL_Renderer * renderer,lv_coord_t hor,lv_coord_t ver)92 SDL_Texture * lv_draw_sdl_create_screen_texture(SDL_Renderer * renderer, lv_coord_t hor, lv_coord_t ver)
93 {
94     SDL_Texture * texture = SDL_CreateTexture(renderer, LV_DRAW_SDL_TEXTURE_FORMAT, SDL_TEXTUREACCESS_TARGET, hor, ver);
95     SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
96     return texture;
97 }
98 
99 /**********************
100  *   STATIC FUNCTIONS
101  **********************/
102 
103 #endif /*LV_USE_GPU_SDL*/
104