From 0e38976c6af075f8db9b3db669ca52fd5143a08e Mon Sep 17 00:00:00 2001 From: Gabriel Wang Date: Sat, 28 Dec 2024 05:45:55 +0000 Subject: [PATCH] update the low level sync-up scheme of the pfb helper service --- ARM.Arm-2D.pdsc | 2 +- Helper/Include/arm_2d_helper_pfb.h | 12 +++++-- Helper/Source/arm_2d_helper_pfb.c | 36 ++++++++++--------- Library/Include/arm_2d_types.h | 1 - .../platform/Virtual_TFT_Port.c | 17 ++++----- .../platform/Virtual_TFT_Port.h | 2 +- .../platform/arm_2d_disp_adapter_0.h | 4 +-- 7 files changed, 42 insertions(+), 32 deletions(-) diff --git a/ARM.Arm-2D.pdsc b/ARM.Arm-2D.pdsc index a3318182..da3fc68d 100644 --- a/ARM.Arm-2D.pdsc +++ b/ARM.Arm-2D.pdsc @@ -321,7 +321,7 @@ - + Helper services for LCD adaptor(s), e.g. Generic Partial Framebuffer, Scene Player etc. diff --git a/Helper/Include/arm_2d_helper_pfb.h b/Helper/Include/arm_2d_helper_pfb.h index edb0cca3..06fa6347 100644 --- a/Helper/Include/arm_2d_helper_pfb.h +++ b/Helper/Include/arm_2d_helper_pfb.h @@ -21,8 +21,8 @@ * Title: #include "arm_2d_helper_pfb.h" * Description: Public header file for the PFB helper service * - * $Date: 26. Dec 2024 - * $Revision: V.1.12.4 + * $Date: 28. Dec 2024 + * $Revision: V.1.13.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ @@ -678,7 +678,13 @@ typedef struct arm_2d_helper_pfb_dependency_t { //! event handler for drawing GUI arm_2d_helper_draw_evt_t evtOnDrawing; - //! low level rendering handler wants to sync-up (return arm_fsm_rt_wait_for_obj) + /*! event handler for waiting LCD finish rendering previous frame + * \note when then handler return false, the refresh task will yield and return + * arm_fsm_rt_wait_async. + * when the handler return true, it means the display device finished + * rendering the previous frame and the refresh task will continue the + * following steps. + */ arm_2d_evt_t evtOnLowLevelSyncUp; //! event handler for each frame complete diff --git a/Helper/Source/arm_2d_helper_pfb.c b/Helper/Source/arm_2d_helper_pfb.c index c01026cd..2e65c3b6 100644 --- a/Helper/Source/arm_2d_helper_pfb.c +++ b/Helper/Source/arm_2d_helper_pfb.c @@ -21,8 +21,8 @@ * Title: #include "arm_2d_helper_pfb.c" * Description: the pfb helper service source code * - * $Date: 26. Dec 2024 - * $Revision: V.1.12.4 + * $Date: 28. Dec 2024 + * $Revision: V.1.13.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ @@ -152,8 +152,7 @@ void __arm_2d_helper_pfb_free(arm_2d_helper_pfb_t *ptThis, arm_2d_pfb_t *ptPFB) } /* set event */ - if ( (NULL == this.tCFG.Dependency.evtOnLowLevelSyncUp.fnHandler) - && ((uintptr_t)NULL != this.Adapter.pFPBPoolAvailable)) { + if ((uintptr_t)NULL != this.Adapter.pFPBPoolAvailable) { arm_2d_port_set_semaphore(this.Adapter.pFPBPoolAvailable); } @@ -275,10 +274,8 @@ arm_2d_err_t arm_2d_helper_pfb_init(arm_2d_helper_pfb_t *ptThis, } } while(0); - if (NULL == this.tCFG.Dependency.evtOnLowLevelSyncUp.fnHandler) { - /* use default semaphore */ - this.Adapter.pFPBPoolAvailable = arm_2d_port_new_semaphore(); - } + /* use semaphore */ + this.Adapter.pFPBPoolAvailable = arm_2d_port_new_semaphore(); /* initialize internal dirty region pool*/ do { @@ -2680,9 +2677,20 @@ ARM_PT_BEGIN(this.Adapter.chPT) assert(NULL == this.Adapter.OptimizedDirtyRegions.ptWorkingList); assert(NULL == this.Adapter.OptimizedDirtyRegions.ptCandidateList); } + +ARM_PT_ENTRY(); + /* wait until LCD finish rendering the previous frame */ + if (NULL != this.tCFG.Dependency.evtOnLowLevelSyncUp.fnHandler){ + // wait until lcd is ready + if (!(*this.tCFG.Dependency.evtOnLowLevelSyncUp.fnHandler)( + this.tCFG.Dependency.evtOnLowLevelSyncUp.pTarget)) { + ARM_PT_GOTO_PREV_ENTRY(arm_fsm_rt_async); + } + } __arm_2d_helper_perf_counter_start(&this.Statistics.lTimestamp, - ARM_2D_PERFC_DRIVER); + ARM_2D_PERFC_DRIVER); + do { /* begin of the drawing iteration, * try to request the tile of frame buffer @@ -2731,12 +2739,8 @@ ARM_PT_BEGIN(this.Adapter.chPT) "PFB TASK", "No PFB is available, waiting..." ); - if (NULL != this.tCFG.Dependency.evtOnLowLevelSyncUp.fnHandler){ - // wait until lcd is ready - (*this.tCFG.Dependency.evtOnLowLevelSyncUp.fnHandler)( - this.tCFG.Dependency.evtOnLowLevelSyncUp.pTarget - ); - } else if ((uintptr_t)NULL != this.Adapter.pFPBPoolAvailable) { + + if ((uintptr_t)NULL != this.Adapter.pFPBPoolAvailable) { arm_2d_port_wait_for_semaphore( this.Adapter.pFPBPoolAvailable); } @@ -2801,7 +2805,7 @@ ARM_PT_BEGIN(this.Adapter.chPT) this.Adapter.bIsNewFrame); // just in case some one forgot to do this... - arm_2d_op_wait_async(NULL); + ARM_2D_OP_WAIT_ASYNC(); this.Statistics.nTotalCycle += __arm_2d_helper_perf_counter_stop( &this.Statistics.lTimestamp, diff --git a/Library/Include/arm_2d_types.h b/Library/Include/arm_2d_types.h index 427efc6f..ca58d8f4 100644 --- a/Library/Include/arm_2d_types.h +++ b/Library/Include/arm_2d_types.h @@ -907,7 +907,6 @@ typedef struct arm_2d_evt_t { void *pTarget; //!< user attached target } arm_2d_evt_t; - #define ARM_2D_OP_INFO_PARAM_HAS_SOURCE _BV(0) //!< opcode has source tile info #define ARM_2D_OP_INFO_PARAM_HAS_TARGET _BV(1) //!< opcode has target tile info #define ARM_2D_OP_INFO_PARAM_HAS_SOURCE_MASK _BV(2) //!< opcode has source mask info diff --git a/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.c b/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.c index c125c2e2..f50bb345 100644 --- a/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.c +++ b/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.c @@ -314,18 +314,19 @@ int32_t Disp0_DrawBitmap(int16_t x,int16_t y,int16_t width,int16_t height,const return 0; } -void VT_sdl_flush(int32_t nMS) +bool VT_sdl_flush(int32_t nMS) { nMS = MAX(1, nMS); -#if __DISP0_CFG_ENABLE_3FB_HELPER_SERVICE__ - SDL_Delay(nMS); -#else - while(!sdl_refr_cpl) { + + if (sdl_refr_cpl) { + sdl_refr_cpl = false; + sdl_refr_qry = true; + return true; + } else { SDL_Delay(nMS); } -#endif - sdl_refr_cpl = false; - sdl_refr_qry = true; + + return false; } #if defined(_POSIX_VERSION) || defined(CLOCK_MONOTONIC) || defined(__APPLE__) diff --git a/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.h b/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.h index 5f47ee7c..f190fa35 100644 --- a/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.h +++ b/examples/[template][pc][vscode]/platform/Virtual_TFT_Port.h @@ -44,7 +44,7 @@ typedef uint32_t color_typedef; extern void VT_init(void); extern bool VT_is_request_quit(void); extern void VT_deinit(void); -extern void VT_sdl_flush(int32_t nMS); +extern bool VT_sdl_flush(int32_t nMS); extern void VT_sdl_refresh_task(void); extern void VT_enter_global_mutex(void); extern void VT_leave_global_mutex(void); diff --git a/examples/[template][pc][vscode]/platform/arm_2d_disp_adapter_0.h b/examples/[template][pc][vscode]/platform/arm_2d_disp_adapter_0.h index 3b87ba71..43394bd7 100644 --- a/examples/[template][pc][vscode]/platform/arm_2d_disp_adapter_0.h +++ b/examples/[template][pc][vscode]/platform/arm_2d_disp_adapter_0.h @@ -225,13 +225,13 @@ extern "C" { // Enable the helper service for 3FB (LCD Direct Mode) // You can select this option when your LCD controller supports direct mode #ifndef __DISP0_CFG_ENABLE_3FB_HELPER_SERVICE__ -# define __DISP0_CFG_ENABLE_3FB_HELPER_SERVICE__ 0 +# define __DISP0_CFG_ENABLE_3FB_HELPER_SERVICE__ 1 #endif // Disable the default scene // Remove the default scene for this display adapter. We highly recommend you to disable the default scene when creating real applications. #ifndef __DISP0_CFG_DISABLE_DEFAULT_SCENE__ -# define __DISP0_CFG_DISABLE_DEFAULT_SCENE__ 0 +# define __DISP0_CFG_DISABLE_DEFAULT_SCENE__ 1 #endif // Maximum number of Virtual Resources used per API