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 92 void (*draw_line)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1, 93 const lv_point_t * point2); 94 95 96 void (*draw_polygon)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, 97 const lv_point_t * points, uint16_t point_cnt); 98 99 100 /** 101 * Get an area of a transformed image (zoomed and/or rotated) 102 * @param draw_ctx pointer to a draw context 103 * @param dest_area get this area of the result image. It assumes that the original image is placed to the 0;0 position. 104 * @param src_buf the source image 105 * @param src_w width of the source image in [px] 106 * @param src_h height of the source image in [px] 107 * @param src_stride the stride in [px]. 108 * @param draw_dsc an `lv_draw_img_dsc_t` descriptor containing the transformation parameters 109 * @param cf the color format of `src_buf` 110 * @param cbuf place the colors of the pixels on `dest_area` here in RGB format 111 * @param abuf place the opacity of the pixels on `dest_area` here 112 */ 113 void (*draw_transform)(struct _lv_draw_ctx_t * draw_ctx, const lv_area_t * dest_area, const void * src_buf, 114 lv_coord_t src_w, lv_coord_t src_h, lv_coord_t src_stride, 115 const lv_draw_img_dsc_t * draw_dsc, lv_img_cf_t cf, lv_color_t * cbuf, lv_opa_t * abuf); 116 117 /** 118 * Replace the buffer with a rect without decoration like radius or borders 119 */ 120 void (*draw_bg)(struct _lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * draw_dsc, const lv_area_t * coords); 121 122 /** 123 * Wait until all background operations are finished. (E.g. GPU operations) 124 */ 125 void (*wait_for_finish)(struct _lv_draw_ctx_t * draw_ctx); 126 127 /** 128 * Copy an area from buffer to an other 129 * @param draw_ctx pointer to a draw context 130 * @param dest_buf copy the buffer into this buffer 131 * @param dest_stride the width of the dest_buf in pixels 132 * @param dest_area the destination area 133 * @param src_buf copy from this buffer 134 * @param src_stride the width of src_buf in pixels 135 * @param src_area the source area. 136 * 137 * @note dest_area and src_area must have the same width and height 138 * but can have different x and y position. 139 * @note dest_area and src_area must be clipped to the real dimensions of the buffers 140 */ 141 void (*buffer_copy)(struct _lv_draw_ctx_t * draw_ctx, void * dest_buf, lv_coord_t dest_stride, 142 const lv_area_t * dest_area, 143 void * src_buf, lv_coord_t src_stride, const lv_area_t * src_area); 144 145 /** 146 * Initialize a new layer context. 147 * The original buffer and area data are already saved from `draw_ctx` to `layer_ctx` 148 * @param draw_ctx pointer to the current draw context 149 * @param layer_area the coordinates of the layer 150 * @param flags OR-ed flags from @lv_draw_layer_flags_t 151 * @return pointer to the layer context, or NULL on error 152 */ 153 struct _lv_draw_layer_ctx_t * (*layer_init)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, 154 lv_draw_layer_flags_t flags); 155 156 /** 157 * Adjust the layer_ctx and/or draw_ctx based on the `layer_ctx->area_act`. 158 * It's called only if flags has `LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE` 159 * @param draw_ctx pointer to the current draw context 160 * @param layer_ctx pointer to a layer context 161 * @param flags OR-ed flags from @lv_draw_layer_flags_t 162 */ 163 void (*layer_adjust)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, 164 lv_draw_layer_flags_t flags); 165 166 /** 167 * Blend a rendered layer to `layer_ctx->area_act` 168 * @param draw_ctx pointer to the current draw context 169 * @param layer_ctx pointer to a layer context 170 * @param draw_dsc pointer to an image draw descriptor 171 */ 172 void (*layer_blend)(struct _lv_draw_ctx_t * draw_ctx, struct _lv_draw_layer_ctx_t * layer_ctx, 173 const lv_draw_img_dsc_t * draw_dsc); 174 175 /** 176 * Destroy a layer context. The original buffer and area data of the `draw_ctx` will be restored 177 * and the `layer_ctx` itself will be freed automatically. 178 * @param draw_ctx pointer to the current draw context 179 * @param layer_ctx pointer to a layer context 180 */ 181 void (*layer_destroy)(struct _lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx); 182 183 /** 184 * Size of a layer context in bytes. 185 */ 186 size_t layer_instance_size; 187 188 #if LV_USE_USER_DATA 189 void * user_data; 190 #endif 191 192 } lv_draw_ctx_t; 193 194 /********************** 195 * GLOBAL PROTOTYPES 196 **********************/ 197 198 void lv_draw_init(void); 199 200 201 void lv_draw_wait_for_finish(lv_draw_ctx_t * draw_ctx); 202 203 /********************** 204 * GLOBAL VARIABLES 205 **********************/ 206 207 /********************** 208 * MACROS 209 **********************/ 210 211 /********************** 212 * POST INCLUDES 213 *********************/ 214 215 #ifdef __cplusplus 216 } /*extern "C"*/ 217 #endif 218 219 #endif /*LV_DRAW_H*/ 220