From 8df8700bedef4d56dc1745b6d59fcba74aca38ec Mon Sep 17 00:00:00 2001 From: rabbitsaviola Date: Fri, 28 Aug 2020 21:31:30 +0800 Subject: [PATCH] Add async gpu wait interface (#1736) Add async gpu wait interface Closes #1708 --- CHANGELOG.md | 1 + src/lv_core/lv_refr.c | 2 ++ src/lv_draw/lv_draw_blend.c | 5 ++++- src/lv_hal/lv_hal_disp.h | 4 ++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e4b2e0f5..e4e70460a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Add `lv_font_free()` function - Frees the memory allocated by the `lv_font_load()` function - Add style caching to reduce acces time of properties with default value - Add `clean_dcache_cb` and `lv_disp_clean_dcache` to enable users to use their own cache management function +- Add `gpu_wait_cb` to wait until the GPU is working. It allows to run CPU a wait only when the rendered data is needed. ### Bugfixes - Fix color bleeding on border drawing diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index 0765fba27..3ed5182db 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -741,6 +741,8 @@ static void lv_refr_vdb_flush(void) /*Flush the rendered content to the display*/ lv_disp_t * disp = _lv_refr_get_disp_refreshing(); + if (disp->driver.gpu_wait_cb) disp->driver.gpu_wait_cb(&disp->driver); + if(disp->driver.flush_cb) disp->driver.flush_cb(&disp->driver, &vdb->area, vdb->buf_act); if(vdb->buf1 && vdb->buf2) { diff --git a/src/lv_draw/lv_draw_blend.c b/src/lv_draw/lv_draw_blend.c index a7d9e0d1d..f4de48e7e 100644 --- a/src/lv_draw/lv_draw_blend.c +++ b/src/lv_draw/lv_draw_blend.c @@ -138,7 +138,8 @@ LV_ATTRIBUTE_FAST_MEM void _lv_blend_fill(const lv_area_t * clip_area, const lv_ const lv_area_t * disp_area = &vdb->area; lv_color_t * disp_buf = vdb->buf_act; - + if (disp->driver.gpu_wait_cb) disp->driver.gpu_wait_cb(&disp->driver); + /* Get clipped fill area which is the real draw area. * It is always the same or inside `fill_area` */ lv_area_t draw_area; @@ -212,6 +213,8 @@ LV_ATTRIBUTE_FAST_MEM void _lv_blend_map(const lv_area_t * clip_area, const lv_a const lv_area_t * disp_area = &vdb->area; lv_color_t * disp_buf = vdb->buf_act; + if (disp->driver.gpu_wait_cb) disp->driver.gpu_wait_cb(&disp->driver); + /* Now `draw_area` has absolute coordinates. * Make it relative to `disp_area` to simplify draw to `disp_buf`*/ draw_area.x1 -= disp_area->x1; diff --git a/src/lv_hal/lv_hal_disp.h b/src/lv_hal/lv_hal_disp.h index 04ea3efdf..7a1eef6b0 100644 --- a/src/lv_hal/lv_hal_disp.h +++ b/src/lv_hal/lv_hal_disp.h @@ -114,7 +114,11 @@ typedef struct _disp_drv_t { /** OPTIONAL: Called when lvgl needs any CPU cache that affects rendering to be cleaned */ void (*clean_dcache_cb)(struct _disp_drv_t * disp_drv); + /** OPTIONAL: called to wait while the gpu is working */ + void (*gpu_wait_cb)(struct _disp_drv_t * disp_drv); + #if LV_USE_GPU + /** OPTIONAL: Blend two memories using opacity (GPU only)*/ void (*gpu_blend_cb)(struct _disp_drv_t * disp_drv, lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa);