From 736193d355148c911daaa7b8e6f34b898d64b106 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Wed, 5 May 2021 18:42:21 +0800 Subject: [PATCH] use update lock (semaphore) for sharedfb schema under MiniGUI-Processes --- src/include/sharedres.h | 10 ++++++++++ src/newgal/drm/drmvideo.c | 40 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/include/sharedres.h b/src/include/sharedres.h index 94902bb9..806fff86 100644 --- a/src/include/sharedres.h +++ b/src/include/sharedres.h @@ -59,6 +59,10 @@ #include #include +#ifdef _MGSCHEMA_SHAREDFB +#include +#endif + #include "constants.h" enum { @@ -108,6 +112,9 @@ typedef struct tagG_RES { char video_exdriver [LEN_EXDRIVER_NAME + 1]; Uint32 video_drm_format; Uint32 video_dbl_buff:1; +#ifdef _MGSCHEMA_SHAREDFB + sem_t video_update_lock; /* the semaphore used for sync update */ +#endif #endif int nr_layers; @@ -184,6 +191,9 @@ typedef G_RES* PG_RES; #define SHAREDRES_VIDEO_EXDRIVER (((PG_RES)mgSharedRes)->video_exdriver) #define SHAREDRES_VIDEO_DRM_FORMAT (((PG_RES)mgSharedRes)->video_drm_format) #define SHAREDRES_VIDEO_DBL_BUFF (((PG_RES)mgSharedRes)->video_dbl_buff) +#ifdef _MGSCHEMA_SHAREDFB +#define SHAREDRES_VIDEO_UPDATE_LOCK (&((PG_RES)mgSharedRes)->video_update_lock) +#endif #endif #define SHAREDRES_TIMER_COUNTER (((PG_RES)mgSharedRes)->timer_counter) diff --git a/src/newgal/drm/drmvideo.c b/src/newgal/drm/drmvideo.c index 1fdff924..769a47a5 100644 --- a/src/newgal/drm/drmvideo.c +++ b/src/newgal/drm/drmvideo.c @@ -1248,6 +1248,15 @@ static GAL_VideoDevice *DRM_CreateDevice(int devindex) strcasecmp (tmp, "yes") == 0) { device->hidden->dbl_buff = 1; } + +#ifdef _MGSCHEMA_SHAREDFB + if (device->hidden->dbl_buff) { + if (sem_init (SHAREDRES_VIDEO_UPDATE_LOCK, 1, 0)) { + _WRN_PRINTF ("Failed to create update lock\n"); + device->hidden->dbl_buff = 0; + } + } +#endif } #ifdef _MGRM_PROCESSES else { @@ -1257,7 +1266,7 @@ static GAL_VideoDevice *DRM_CreateDevice(int devindex) /* override double buffering */ #if IS_COMPOSITING_SCHEMA - /* force to use double buffering to compositing schema */ + /* force to use double buffering for compositing schema */ if (mgIsServer) { device->hidden->dbl_buff = 1; #if 0 /* test code */ @@ -1650,6 +1659,14 @@ static void DRM_VideoQuit(_THIS) this->screen->pixels = NULL; } +#if defined (_MGRM_PROCESSES) && defined (_MGSCHEMA_SHAREDFB) + if (mgIsServer && this->hidden->dbl_buff) { + if (sem_destroy (SHAREDRES_VIDEO_UPDATE_LOCK)) { + _ERR_PRINTF ("Failed to destroy the update lock\n"); + } + } +#endif + #if 0 /* test code */ #ifdef _MBSCHEMA_COMPOSITING if (this->hidden->update_th) { @@ -3202,6 +3219,10 @@ static void DRM_UpdateRects (_THIS, int numrects, GAL_Rect *rects) RECT bound; #if IS_SHAREDFB_SCHEMA_PROCS + if (this->hidden->dbl_buff) { + sem_wait (SHAREDRES_VIDEO_UPDATE_LOCK); + } + GAL_ShadowSurfaceHeader* hdr; if (this->hidden->shadow_screen->flags & GAL_HWSURFACE) { hdr = (GAL_ShadowSurfaceHeader*) @@ -3233,6 +3254,12 @@ static void DRM_UpdateRects (_THIS, int numrects, GAL_Rect *rects) bound = GetScreenRect(); if (!IntersectRect (dirty_rc, dirty_rc, &bound)) SetRectEmpty (dirty_rc); + +#if IS_SHAREDFB_SCHEMA_PROCS + if (this->hidden->dbl_buff) { + sem_post (SHAREDRES_VIDEO_UPDATE_LOCK); + } +#endif } static BOOL DRM_SyncUpdate (_THIS) @@ -3242,6 +3269,10 @@ static BOOL DRM_SyncUpdate (_THIS) RECT bound; #if IS_SHAREDFB_SCHEMA_PROCS + if (this->hidden->dbl_buff) { + sem_wait (SHAREDRES_VIDEO_UPDATE_LOCK); + } + GAL_ShadowSurfaceHeader* hdr; if (this->hidden->shadow_screen->flags & GAL_HWSURFACE) { hdr = (GAL_ShadowSurfaceHeader*) @@ -3344,7 +3375,14 @@ static BOOL DRM_SyncUpdate (_THIS) } SetRectEmpty (dirty_rc); + ret: +#if IS_SHAREDFB_SCHEMA_PROCS + if (this->hidden->dbl_buff) { + sem_post (SHAREDRES_VIDEO_UPDATE_LOCK); + } +#endif + return retval; }