「App:Library:LVGL:docs:Porting:Add custom GPU」の版間の差分
9行目: | 9行目: | ||
The core structure of drawing is <code>lv_draw_ctx_t</code>. It contains a pointer to a buffer where drawing should happen and a couple of callbacks to draw rectangles, texts, and other primitives. | The core structure of drawing is <code>lv_draw_ctx_t</code>. It contains a pointer to a buffer where drawing should happen and a couple of callbacks to draw rectangles, texts, and other primitives. | ||
+ | === Fields === | ||
+ | <code>lv_draw_ctx_t</code> has the following fields: | ||
+ | * <code>void * buf</code> Pointer to a buffer to draw into | ||
+ | * <code>lv_area_t * buf_area</code> The position and size of <code>buf</code> (absolute coordinates) | ||
+ | * <code>const lv_area_t * clip_area</code> The current clip area with absolute coordinates, always the same or smaller than <code>buf_area</code>. All drawings should be clipped to this area. | ||
+ | * <code>void (*draw_rect)()</code> Draw a rectangle with shadow, gradient, border, etc. | ||
+ | * <code>void (*draw_arc)()</code> Draw an arc | ||
+ | * <code>void (*draw_img_decoded)()</code> Draw an (A)RGB image that is already decoded by LVGL. | ||
+ | * <code>lv_res_t (*draw_img)()</code> Draw an image before decoding it (it bypasses LVGL's internal image decoders) | ||
+ | * <code>void (*draw_letter)()</code> Draw a letter | ||
+ | * <code>void (*draw_line)()</code> Draw a line | ||
+ | * <code>void (*draw_polygon)()</code> Draw a polygon | ||
+ | * <code>void (*draw_bg)()</code> Replace the buffer with a rect without decoration like radius or borders. | ||
+ | * <code>void (*wait_for_finish)()</code> Wait until all background operation are finished. (E.g. GPU operations) | ||
+ | * <code>void * user_data</code> Custom user data for arbitrary purpose | ||
+ | (For the sake of simplicity the parameters of the callbacks are not shown here.) | ||
+ | |||
+ | All <code>draw_*</code> callbacks receive a pointer to the current <code>draw_ctx</code> as their first parameter. Among the other parameters there is a descriptor that tells what to draw, e.g. for <code>draw_rect</code> it's called lv_draw_rect_dsc_t, for <code>lv_draw_line</code> it's called lv_draw_line_dsc_t, etc. | ||
+ | |||
+ | To correctly render according to a <code>draw_dsc</code> you need to be familiar with the Boxing model of LVGL and the meanings of the fields. The name and meaning of the fields are identical to name and meaning of the Style properties. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | === Initialization === | ||
+ | The <code>lv_disp_drv_t</code> has 4 fields related to the draw context: | ||
+ | |||
+ | * <code>lv_draw_ctx_t * draw_ctx</code> Pointer to the <code>draw_ctx</code> of this display | ||
+ | * <code>void (*draw_ctx_init)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)</code> Callback to initialize a <code>draw_ctx</code> | ||
+ | * <code>void (*draw_ctx_deinit)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)</code> Callback to de-initialize a <code>draw_ctx</code> | ||
+ | * <code>size_t draw_ctx_size</code> Size of the draw context structure. E.g. <code>sizeof(lv_draw_sw_ctx_t)</code> | ||
+ | |||
+ | When you ignore these fields, LVGL will set default values for callbacks and size in <code>lv_disp_drv_init()</code> based on the configuration in <code>lv_conf.h</code>. <code>lv_disp_drv_register()</code> will allocate a <code>draw_ctx</code> based on <code>draw_ctx_size</code> and call <code>draw_ctx_init()</code> on it. | ||
+ | |||
+ | However, you can overwrite the callbacks and the size values before calling <code>lv_disp_drv_register()</code>. It makes it possible to use your own <code>draw_ctx</code> with your own callbacks. | ||
2022年6月21日 (火) 13:16時点における版
https://docs.lvgl.io/8.2/porting/gpu.html
Add custom GPU
LVGL has a flexible and extendable draw pipeline.
You can hook it to do some rendering with a GPU or even completely replace the built-in software renderer.
Draw context
The core structure of drawing is lv_draw_ctx_t
. It contains a pointer to a buffer where drawing should happen and a couple of callbacks to draw rectangles, texts, and other primitives.
Fields
lv_draw_ctx_t
has the following fields:
void * buf
Pointer to a buffer to draw intolv_area_t * buf_area
The position and size ofbuf
(absolute coordinates)const lv_area_t * clip_area
The current clip area with absolute coordinates, always the same or smaller thanbuf_area
. All drawings should be clipped to this area.void (*draw_rect)()
Draw a rectangle with shadow, gradient, border, etc.void (*draw_arc)()
Draw an arcvoid (*draw_img_decoded)()
Draw an (A)RGB image that is already decoded by LVGL.lv_res_t (*draw_img)()
Draw an image before decoding it (it bypasses LVGL's internal image decoders)void (*draw_letter)()
Draw a lettervoid (*draw_line)()
Draw a linevoid (*draw_polygon)()
Draw a polygonvoid (*draw_bg)()
Replace the buffer with a rect without decoration like radius or borders.void (*wait_for_finish)()
Wait until all background operation are finished. (E.g. GPU operations)void * user_data
Custom user data for arbitrary purpose
(For the sake of simplicity the parameters of the callbacks are not shown here.)
All draw_*
callbacks receive a pointer to the current draw_ctx
as their first parameter. Among the other parameters there is a descriptor that tells what to draw, e.g. for draw_rect
it's called lv_draw_rect_dsc_t, for lv_draw_line
it's called lv_draw_line_dsc_t, etc.
To correctly render according to a draw_dsc
you need to be familiar with the Boxing model of LVGL and the meanings of the fields. The name and meaning of the fields are identical to name and meaning of the Style properties.
Initialization
The lv_disp_drv_t
has 4 fields related to the draw context:
lv_draw_ctx_t * draw_ctx
Pointer to thedraw_ctx
of this displayvoid (*draw_ctx_init)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
Callback to initialize adraw_ctx
void (*draw_ctx_deinit)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
Callback to de-initialize adraw_ctx
size_t draw_ctx_size
Size of the draw context structure. E.g.sizeof(lv_draw_sw_ctx_t)
When you ignore these fields, LVGL will set default values for callbacks and size in lv_disp_drv_init()
based on the configuration in lv_conf.h
. lv_disp_drv_register()
will allocate a draw_ctx
based on draw_ctx_size
and call draw_ctx_init()
on it.
However, you can overwrite the callbacks and the size values before calling lv_disp_drv_register()
. It makes it possible to use your own draw_ctx
with your own callbacks.