1 /**
2  * @file lv_draw.h
3  *
4  */
5 
6 #ifndef LV_DRAW_H
7 #define LV_DRAW_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 
18 #include "../misc/lv_style.h"
19 #include "../misc/lv_txt.h"
20 #include "lv_img_decoder.h"
21 #include "lv_img_cache.h"
22 
23 #include "lv_draw_rect.h"
24 #include "lv_draw_label.h"
25 #include "lv_draw_img.h"
26 #include "lv_draw_line.h"
27 #include "lv_draw_triangle.h"
28 #include "lv_draw_arc.h"
29 #include "lv_draw_mask.h"
30 #include "lv_draw_transform.h"
31 #include "lv_draw_layer.h"
32 
33 /*********************
34  *      DEFINES
35  *********************/
36 
37 /**********************
38  *      TYPEDEFS
39  **********************/
40 
41 typedef struct {
42     void * user_data;
43 } lv_draw_mask_t;
44 
45 typedef struct _lv_draw_layer_ctx_t {
46     lv_area_t area_full;
47     lv_area_t area_act;
48     lv_coord_t max_row_with_alpha;
49     lv_coord_t max_row_with_no_alpha;
50     void * buf;
51     struct {
52         const lv_area_t * clip_area;
53         lv_area_t * buf_area;
54         void * buf;
55         bool screen_transp;
56     } original;
57 } lv_draw_layer_ctx_t;
58 
59 typedef struct _lv_draw_ctx_t  {
60     /**
61      *  Pointer to a buffer to draw into
62      */
63     void * buf;
64 
65     /**
66      * The position and size of `buf` (absolute coordinates)
67      */
68     lv_area_t * buf_area;
69 
70     /**
71      * The current clip area with absolute coordinates, always the same or smaller than `buf_area`
72      */
73     const lv_area_t * clip_area;
74 
75     void (*init_buf)(struct _lv_draw_ctx_t * draw_ctx);
76 
77     void (*draw_rect)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dsc, const lv_area_t * coords);
78 
79     void (*draw_arc)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * dsc, const lv_point_t * center,
80                      uint16_t radius,  uint16_t start_angle, uint16_t end_angle);
81 
82     void (*draw_img_decoded)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * dsc,
83                              const lv_area_t * coords, const uint8_t * map_p, lv_img_cf_t color_format);
84 
85     lv_res_t (*draw_img)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t * draw_dsc,
86                          const lv_area_t * coords, const void * src);
87 
88     void (*draw_letter)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc,  const lv_point_t * pos_p,
89                         uint32_t letter);
90 
91     void (*draw_line)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
92                       const lv_point_t * point2);
93 
94     void (*draw_polygon)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc,
95                          const lv_point_t * points, uint16_t point_cnt);
96 
97     /**
98      * Get an area of a transformed image (zoomed and/or rotated)
99      * @param draw_ctx      pointer to a draw context
100      * @param dest_area     get this area of the result image. It assumes that the original image is placed to the 0;0 position.
101      * @param src_buf       the source image
102      * @param src_w         width of the source image in [px]
103      * @param src_h         height of the source image in [px]
104      * @param src_stride    the stride in [px].
105      * @param draw_dsc      an `lv_draw_img_dsc_t` descriptor containing the transformation parameters
106      * @param cf            the color format of `src_buf`
107      * @param cbuf          place the colors of the pixels on `dest_area` here in RGB format
108      * @param abuf          place the opacity of the pixels on `dest_area` here
109      */
110     void (*draw_transform)(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf,
111                            lv_coord_t src_w, lv_coord_t src_h, lv_coord_t src_stride,
112                            const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf);
113 
114     /**
115      * Replace the buffer with a rect without decoration like radius or borders
116      */
117     void (*draw_bg)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_area_t * coords);
118 
119     /**
120      * Wait until all background operations are finished. (E.g. GPU operations)
121      */
122     void (*wait_for_finish)(struct _lv_draw_ctx_t * draw_ctx);
123 
124     /**
125      * Copy an area from buffer to an other
126      * @param draw_ctx      pointer to a draw context
127      * @param dest_buf      copy the buffer into this buffer
128      * @param dest_stride   the width of the dest_buf in pixels
129      * @param dest_area     the destination area
130      * @param src_buf       copy from this buffer
131      * @param src_stride    the width of src_buf in pixels
132      * @param src_area      the source area.
133      *
134      * @note dest_area and src_area must have the same width and height
135      *       but can have different x and y position.
136      * @note dest_area and src_area must be clipped to the real dimensions of the buffers
137      */
138     void (*buffer_copy)(struct _lv_draw_ctx_t * draw_ctx, void * dest_buf, lv_coord_t dest_stride,
139                         const lv_area_t * dest_area,
140                         void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area);
141 
142     /**
143      * Initialize a new layer context.
144      * The original buffer and area data are already saved from `draw_ctx` to `layer_ctx`
145      * @param draw_ctx      pointer to the current draw context
146      * @param layer_area    the coordinates of the layer
147      * @param flags         OR-ed flags from @lv_draw_layer_flags_t
148      * @return              pointer to the layer context, or NULL on error
149      */
150     struct _lv_draw_layer_ctx_t * (*layer_init)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx,
151                                                 lv_draw_layer_flags_t flags);
152 
153     /**
154      * Adjust the layer_ctx and/or draw_ctx based on the `layer_ctx->area_act`.
155      * It's called only if flags has `LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE`
156      * @param draw_ctx      pointer to the current draw context
157      * @param layer_ctx     pointer to a layer context
158      * @param flags         OR-ed flags from @lv_draw_layer_flags_t
159      */
160     void (*layer_adjust)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx,
161                          lv_draw_layer_flags_t flags);
162 
163     /**
164      * Blend a rendered layer to `layer_ctx->area_act`
165      * @param draw_ctx      pointer to the current draw context
166      * @param layer_ctx     pointer to a layer context
167      * @param draw_dsc      pointer to an image draw descriptor
168      */
169     void (*layer_blend)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx,
170                         const lv_draw_img_dsc_t * draw_dsc);
171 
172     /**
173      * Destroy a layer context. The original buffer and area data of the `draw_ctx` will be restored
174      * and the `layer_ctx` itself will be freed automatically.
175      * @param draw_ctx      pointer to the current draw context
176      * @param layer_ctx     pointer to a layer context
177      */
178     void (*layer_destroy)(struct _lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx);
179 
180     /**
181      * Size of a layer context in bytes.
182      */
183     size_t layer_instance_size;
184 
185 #if LV_USE_USER_DATA
186     void * user_data;
187 #endif
188 
189 } lv_draw_ctx_t;
190 
191 /**********************
192  * GLOBAL PROTOTYPES
193  **********************/
194 
195 void lv_draw_init(void);
196 
197 void lv_draw_wait_for_finish(lv_draw_ctx_t * draw_ctx);
198 
199 /**********************
200  *  GLOBAL VARIABLES
201  **********************/
202 
203 /**********************
204  *      MACROS
205  **********************/
206 
207 /**********************
208  *   POST INCLUDES
209  *********************/
210 
211 #ifdef __cplusplus
212 } /*extern "C"*/
213 #endif
214 
215 #endif /*LV_DRAW_H*/
216