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