1 /**
2 * @file lv_draw_layer.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_draw.h"
10 #include "lv_draw_arc.h"
11 #include "../core/lv_refr.h"
12
13 /*********************
14 * DEFINES
15 *********************/
16
17 /**********************
18 * TYPEDEFS
19 **********************/
20
21 /**********************
22 * STATIC PROTOTYPES
23 **********************/
24
25 /**********************
26 * STATIC VARIABLES
27 **********************/
28
29 /**********************
30 * MACROS
31 **********************/
32
33 /**********************
34 * GLOBAL FUNCTIONS
35 **********************/
36
lv_draw_layer_create(lv_draw_ctx_t * draw_ctx,const lv_area_t * layer_area,lv_draw_layer_flags_t flags)37 lv_draw_layer_ctx_t * lv_draw_layer_create(lv_draw_ctx_t * draw_ctx, const lv_area_t * layer_area,
38 lv_draw_layer_flags_t flags)
39 {
40 if(draw_ctx->layer_init == NULL) return NULL;
41
42 lv_draw_layer_ctx_t * layer_ctx = lv_mem_alloc(draw_ctx->layer_instance_size);
43 LV_ASSERT_MALLOC(layer_ctx);
44 if(layer_ctx == NULL) {
45 LV_LOG_WARN("Couldn't allocate a new layer context");
46 return NULL;
47 }
48
49 lv_memset_00(layer_ctx, draw_ctx->layer_instance_size);
50
51 lv_disp_t * disp_refr = _lv_refr_get_disp_refreshing();
52 layer_ctx->original.buf = draw_ctx->buf;
53 layer_ctx->original.buf_area = draw_ctx->buf_area;
54 layer_ctx->original.clip_area = draw_ctx->clip_area;
55 layer_ctx->original.screen_transp = disp_refr->driver->screen_transp;
56 layer_ctx->area_full = *layer_area;
57
58 lv_draw_layer_ctx_t * init_layer_ctx = draw_ctx->layer_init(draw_ctx, layer_ctx, flags);
59 if(NULL == init_layer_ctx) {
60 lv_mem_free(layer_ctx);
61 }
62 return init_layer_ctx;
63 }
64
lv_draw_layer_adjust(struct _lv_draw_ctx_t * draw_ctx,struct _lv_draw_layer_ctx_t * layer_ctx,lv_draw_layer_flags_t flags)65 void lv_draw_layer_adjust(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx,
66 lv_draw_layer_flags_t flags)
67 {
68 if(draw_ctx->layer_adjust) draw_ctx->layer_adjust(draw_ctx, layer_ctx, flags);
69 }
70
lv_draw_layer_blend(struct _lv_draw_ctx_t * draw_ctx,struct _lv_draw_layer_ctx_t * layer_ctx,lv_draw_img_dsc_t * draw_dsc)71 void lv_draw_layer_blend(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx,
72 lv_draw_img_dsc_t * draw_dsc)
73 {
74 if(draw_ctx->layer_blend) draw_ctx->layer_blend(draw_ctx, layer_ctx, draw_dsc);
75 }
76
lv_draw_layer_destroy(lv_draw_ctx_t * draw_ctx,lv_draw_layer_ctx_t * layer_ctx)77 void lv_draw_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx)
78 {
79
80 lv_draw_wait_for_finish(draw_ctx);
81 draw_ctx->buf = layer_ctx->original.buf;
82 draw_ctx->buf_area = layer_ctx->original.buf_area;
83 draw_ctx->clip_area = layer_ctx->original.clip_area;
84 lv_disp_t * disp_refr = _lv_refr_get_disp_refreshing();
85 disp_refr->driver->screen_transp = layer_ctx->original.screen_transp;
86
87 if(draw_ctx->layer_destroy) draw_ctx->layer_destroy(draw_ctx, layer_ctx);
88 lv_mem_free(layer_ctx);
89 }
90
91 /**********************
92 * STATIC FUNCTIONS
93 **********************/
94