diff --git a/Kconfig b/Kconfig index 33d07af44c..2cc7a1121f 100644 --- a/Kconfig +++ b/Kconfig @@ -207,6 +207,23 @@ menu "LVGL configuration" help If FreeType or ThorVG is enabled, it is recommended to set it to 32KB or more. + config LV_DRAW_THREAD_PRIO + int "Thread priority for the drawing thread" + range 0 4 + default 3 + depends on LV_USE_OS > 0 + help + Thread priority controls the relative importance of the drawing threads. + Values correspond to lv_thread_prio_t enum in lv_os.h: + 0: LV_THREAD_PRIO_LOWEST + 1: LV_THREAD_PRIO_LOW + 2: LV_THREAD_PRIO_MID (default) + 3: LV_THREAD_PRIO_HIGH + 4: LV_THREAD_PRIO_HIGHEST + + Higher priority can improve rendering performance but might cause + starvation of lower priority tasks. + config LV_USE_DRAW_SW bool "Enable software rendering" default y diff --git a/docs/src/details/main-modules/draw/draw_pipeline.rst b/docs/src/details/main-modules/draw/draw_pipeline.rst index cf8cc18716..435c4154f9 100644 --- a/docs/src/details/main-modules/draw/draw_pipeline.rst +++ b/docs/src/details/main-modules/draw/draw_pipeline.rst @@ -113,6 +113,19 @@ For an example of how draw-unit cration and initialization is done, see :cpp:func:`lv_draw_sw_init` in lv_draw_sw.c_ or the other draw units whose ``init`` functions are optionally called in :cpp:func:`lv_init`. +Thread Priority +--------------- + +All draw units operate with a configurable thread priority which can be set using the +:c:macro:`LV_DRAW_THREAD_PRIO` configuration option in ``lv_conf.h``. This allows you +to fine-tune the priority level across all drawing units, which is especially useful for +systems with limited priority levels. + +By default, draw units use :c:macro:`LV_THREAD_PRIO_HIGH` as their thread priority. +This consistent approach ensures that all drawing units (software rendering, hardware +accelerators like STM32 DMA2D, NXP VGLite, etc.) use the same priority level unless +explicitly configured otherwise. + .. _lv_draw_sw.c: https://github.com/lvgl/lvgl/blob/master/src/draw/sw/lv_draw_sw.c @@ -196,4 +209,4 @@ API lv_draw_task_t LV_DRAW_TRANSFORM_USE_MATRIX lv_draw_unit_t - LV_USE_DRAW_OPENGLES + LV_USE_DRAW_OPENGLES \ No newline at end of file diff --git a/lv_conf_template.h b/lv_conf_template.h index 220dd739fe..b16c099ffa 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -156,6 +156,15 @@ */ #define LV_DRAW_THREAD_STACK_SIZE (8 * 1024) /**< [bytes]*/ +/** Thread priority of the drawing task. + * Higher values mean higher priority. + * Can use values from lv_thread_prio_t enum in lv_os.h: LV_THREAD_PRIO_LOWEST, + * LV_THREAD_PRIO_LOW, LV_THREAD_PRIO_MID, LV_THREAD_PRIO_HIGH, LV_THREAD_PRIO_HIGHEST + * Make sure the priority value aligns with the OS-specific priority levels. + * On systems with limited priority levels (e.g., FreeRTOS), a higher value can improve + * rendering performance but might cause other tasks to starve. */ +#define LV_DRAW_THREAD_PRIO LV_THREAD_PRIO_HIGH + #define LV_USE_DRAW_SW 1 #if LV_USE_DRAW_SW == 1 /* diff --git a/src/draw/dma2d/lv_draw_dma2d.c b/src/draw/dma2d/lv_draw_dma2d.c index 1cf966117d..465de8c113 100644 --- a/src/draw/dma2d/lv_draw_dma2d.c +++ b/src/draw/dma2d/lv_draw_dma2d.c @@ -69,7 +69,7 @@ void lv_draw_dma2d_init(void) #if LV_DRAW_DMA2D_ASYNC g_unit = draw_dma2d_unit; - lv_result_t res = lv_thread_init(&draw_dma2d_unit->thread, "dma2d", LV_THREAD_PRIO_HIGH, thread_cb, 2 * 1024, + lv_result_t res = lv_thread_init(&draw_dma2d_unit->thread, "dma2d", LV_DRAW_THREAD_PRIO, thread_cb, 2 * 1024, draw_dma2d_unit); LV_ASSERT(res == LV_RESULT_OK); #endif diff --git a/src/draw/nema_gfx/lv_draw_nema_gfx.c b/src/draw/nema_gfx/lv_draw_nema_gfx.c index 3a1f77a195..53221e3b58 100644 --- a/src/draw/nema_gfx/lv_draw_nema_gfx.c +++ b/src/draw/nema_gfx/lv_draw_nema_gfx.c @@ -119,7 +119,7 @@ void lv_draw_nema_gfx_init(void) #if LV_USE_OS - lv_thread_init(&draw_nema_gfx_unit->thread, "nemagfx", LV_THREAD_PRIO_HIGH, nema_gfx_render_thread_cb, 2 * 1024, + lv_thread_init(&draw_nema_gfx_unit->thread, "nemagfx", LV_DRAW_THREAD_PRIO, nema_gfx_render_thread_cb, 2 * 1024, draw_nema_gfx_unit); #endif } diff --git a/src/draw/nxp/g2d/lv_draw_g2d.c b/src/draw/nxp/g2d/lv_draw_g2d.c index 73afe27474..3d3de38e1c 100644 --- a/src/draw/nxp/g2d/lv_draw_g2d.c +++ b/src/draw/nxp/g2d/lv_draw_g2d.c @@ -78,7 +78,7 @@ void lv_draw_g2d_init(void) LV_LOG_ERROR("g2d_open fail.\n"); } #if LV_USE_G2D_DRAW_THREAD - lv_thread_init(&draw_g2d_unit->thread, "g2ddraw", LV_THREAD_PRIO_HIGH, _g2d_render_thread_cb, 2 * 1024, draw_g2d_unit); + lv_thread_init(&draw_g2d_unit->thread, "g2ddraw", LV_DRAW_THREAD_PRIO, _g2d_render_thread_cb, 2 * 1024, draw_g2d_unit); #endif } diff --git a/src/draw/nxp/pxp/lv_draw_pxp.c b/src/draw/nxp/pxp/lv_draw_pxp.c index 6332ba7f69..21f1bbcf1d 100644 --- a/src/draw/nxp/pxp/lv_draw_pxp.c +++ b/src/draw/nxp/pxp/lv_draw_pxp.c @@ -95,7 +95,7 @@ void lv_draw_pxp_init(void) draw_pxp_unit->base_unit.name = "NXP_PXP"; #if LV_USE_PXP_DRAW_THREAD - lv_thread_init(&draw_pxp_unit->thread, "pxpdraw", LV_THREAD_PRIO_HIGH, _pxp_render_thread_cb, 2 * 1024, draw_pxp_unit); + lv_thread_init(&draw_pxp_unit->thread, "pxpdraw", LV_DRAW_THREAD_PRIO, _pxp_render_thread_cb, 2 * 1024, draw_pxp_unit); #endif #endif /*LV_USE_DRAW_PXP*/ } diff --git a/src/draw/nxp/vglite/lv_draw_vglite.c b/src/draw/nxp/vglite/lv_draw_vglite.c index 51b0e77ffc..173b33e7e8 100644 --- a/src/draw/nxp/vglite/lv_draw_vglite.c +++ b/src/draw/nxp/vglite/lv_draw_vglite.c @@ -118,7 +118,7 @@ void lv_draw_vglite_init(void) draw_vglite_unit->base_unit.name = "NXP_VGLITE"; #if LV_USE_VGLITE_DRAW_THREAD - lv_thread_init(&draw_vglite_unit->thread, "vglitedraw", LV_THREAD_PRIO_HIGHEST, _vglite_render_thread_cb, 4 * 1024, + lv_thread_init(&draw_vglite_unit->thread, "vglitedraw", LV_DRAW_THREAD_PRIO, _vglite_render_thread_cb, 4 * 1024, draw_vglite_unit); #endif } diff --git a/src/draw/renesas/dave2d/lv_draw_dave2d.c b/src/draw/renesas/dave2d/lv_draw_dave2d.c index f4a6430c69..35d610ed10 100644 --- a/src/draw/renesas/dave2d/lv_draw_dave2d.c +++ b/src/draw/renesas/dave2d/lv_draw_dave2d.c @@ -99,7 +99,7 @@ void lv_draw_dave2d_init(void) lv_ll_init(&_ll_Dave2D_Tasks, 4); #if LV_USE_OS - lv_thread_init(&draw_dave2d_unit->thread, "dave2d", LV_THREAD_PRIO_HIGH, _dave2d_render_thread_cb, 8 * 1024, + lv_thread_init(&draw_dave2d_unit->thread, "dave2d", LV_DRAW_THREAD_PRIO, _dave2d_render_thread_cb, 8 * 1024, draw_dave2d_unit); #endif diff --git a/src/draw/sw/lv_draw_sw.c b/src/draw/sw/lv_draw_sw.c index b1a8dc2b0c..24e465774b 100644 --- a/src/draw/sw/lv_draw_sw.c +++ b/src/draw/sw/lv_draw_sw.c @@ -91,7 +91,7 @@ void lv_draw_sw_init(void) lv_draw_sw_thread_dsc_t * thread_dsc = &draw_sw_unit->thread_dscs[i]; thread_dsc->idx = i; thread_dsc->draw_unit = (void *) draw_sw_unit; - lv_thread_init(&thread_dsc->thread, "swdraw", LV_THREAD_PRIO_HIGH, render_thread_cb, + lv_thread_init(&thread_dsc->thread, "swdraw", LV_DRAW_THREAD_PRIO, render_thread_cb, LV_DRAW_THREAD_STACK_SIZE, thread_dsc); } #endif diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index dee631ae32..bb454e3be8 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -377,6 +377,21 @@ #endif #endif +/** Thread priority of the drawing task. + * Higher values mean higher priority. + * Can use values from lv_thread_prio_t enum in lv_os.h: LV_THREAD_PRIO_LOWEST, + * LV_THREAD_PRIO_LOW, LV_THREAD_PRIO_MID, LV_THREAD_PRIO_HIGH, LV_THREAD_PRIO_HIGHEST + * Make sure the priority value aligns with the OS-specific priority levels. + * On systems with limited priority levels (e.g., FreeRTOS), a higher value can improve + * rendering performance but might cause other tasks to starve. */ +#ifndef LV_DRAW_THREAD_PRIO + #ifdef CONFIG_LV_DRAW_THREAD_PRIO + #define LV_DRAW_THREAD_PRIO CONFIG_LV_DRAW_THREAD_PRIO + #else + #define LV_DRAW_THREAD_PRIO LV_THREAD_PRIO_HIGH + #endif +#endif + #ifndef LV_USE_DRAW_SW #ifdef LV_KCONFIG_PRESENT #ifdef CONFIG_LV_USE_DRAW_SW