From 5cdd2580466d245e9d521fdf3f04e4937430a653 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 14 Jul 2023 14:06:28 +0800 Subject: [PATCH] use WaitVBlank --- src/newgal/drm/drmvideo.c | 17 +++++++++++++++++ src/newgal/fbcon/fbvideo.c | 35 ++++++++++++++++++----------------- src/newgal/shadow/shadow.c | 7 ++++++- src/newgal/sysvideo.h | 3 +++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/newgal/drm/drmvideo.c b/src/newgal/drm/drmvideo.c index 30fc2e2d..8223e836 100644 --- a/src/newgal/drm/drmvideo.c +++ b/src/newgal/drm/drmvideo.c @@ -120,6 +120,7 @@ static int DRM_FillHWRect_Accl(_THIS, GAL_Surface *dst, GAL_Rect *rect, Uint32 color); static void DRM_UpdateRects(_THIS, int numrects, GAL_Rect *rects); +static BOOL DRM_WaitVBlank(_THIS); static BOOL DRM_SyncUpdate(_THIS); static BOOL DRM_SyncUpdateAsync(_THIS); @@ -2574,6 +2575,7 @@ static void* task_do_update(void *data) } else { vbl_ok = TRUE; + this->WaitVBlank = DRM_WaitVBlank; } } #endif @@ -3713,6 +3715,21 @@ static void DRM_UpdateRects (_THIS, int numrects, GAL_Rect *rects) #endif } +static BOOL DRM_WaitVBlank(_THIS) +{ + drmVBlank vbl; + vbl.request.type = DRM_VBLANK_RELATIVE | DRM_VBLANK_NEXTONMISS; + if (this->hidden->cap_vblank_high_crtc) + vbl.request.type |= + (this->hidden->crtc_idx << DRM_VBLANK_HIGH_CRTC_SHIFT); + vbl.request.sequence = 1; + vbl.request.signal = 0; + if (drmWaitVBlank(this->hidden->dev_fd, &vbl)) + return FALSE; + + return TRUE; +} + static BOOL DRM_SyncUpdate(_THIS) { BOOL retval = FALSE; diff --git a/src/newgal/fbcon/fbvideo.c b/src/newgal/fbcon/fbvideo.c index e834f7c9..a9dfee40 100644 --- a/src/newgal/fbcon/fbvideo.c +++ b/src/newgal/fbcon/fbvideo.c @@ -99,8 +99,6 @@ static void FB_RequestHWSurface (_THIS, const REQ_HWSURFACE* request, REP_HWSURFACE* reply); static int FB_AllocHWSurface(_THIS, GAL_Surface *surface); static void FB_FreeHWSurface(_THIS, GAL_Surface *surface); -static void FB_WaitVBL(_THIS); -static void FB_WaitIdle(_THIS); #include "../shadow-screen.h" #include "debug.h" @@ -191,6 +189,19 @@ static BOOL FB_SyncUpdatePanning (_THIS) return TRUE; } +static BOOL FB_WaitVBlank(_THIS) +{ + if (wait_vbl) { + wait_vbl(this); + } + else if (ioctl(console_fd, FBIO_WAITFORVSYNC, 0)) { + _WRN_PRINTF("Failed VSync.\n"); + return FALSE; + } + + return TRUE; +} + static BOOL FB_SyncUpdate (_THIS) { if (IsRectEmpty (&this->hidden->dirty_rc)) @@ -269,8 +280,6 @@ static GAL_VideoDevice *FB_CreateDevice(int devindex) memset(this->hidden, 0, (sizeof *this->hidden)); this->hidden->magic = MAGIC_SHADOW_SCREEN_HEADER; this->hidden->version = 0; - wait_vbl = FB_WaitVBL; - wait_idle = FB_WaitIdle; /* Set the function pointers */ this->VideoInit = FB_VideoInit; @@ -894,6 +903,11 @@ static GAL_Surface *FB_SetVideoMode(_THIS, GAL_Surface *current, } } + if (FB_WaitVBlank(this)) + this->WaitVBlank = FB_WaitVBlank; + else + _WRN_PRINTF("The FBCon device does not support VSync.\n"); + /* We're done */ return (current); } @@ -1176,19 +1190,6 @@ static void FB_FreeHWSurface(_THIS, GAL_Surface *surface) surface->hwdata = NULL; } -static void FB_WaitVBL(_THIS) -{ -#ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */ - ioctl(console_fd, FBIOWAITRETRACE, 0); -#endif - return; -} - -static void FB_WaitIdle(_THIS) -{ - return; -} - void FB_SavePaletteTo(_THIS, int palette_len, __u16 *area) { struct fb_cmap cmap; diff --git a/src/newgal/shadow/shadow.c b/src/newgal/shadow/shadow.c index ebba7a44..260784ff 100644 --- a/src/newgal/shadow/shadow.c +++ b/src/newgal/shadow/shadow.c @@ -630,7 +630,12 @@ static void *task_do_update(void *data) sem_post(&this->hidden->sync_sem); do { - usleep(this->hidden->update_interval * 1000); + if (this->WaitVBlank) { + this->WaitVBlank(this); + } + else { + usleep(this->hidden->update_interval * 1000); + } #if USE_UPDATE_SEM if (sem_wait(&this->hidden->update_sem)) diff --git a/src/newgal/sysvideo.h b/src/newgal/sysvideo.h index 2f4f0019..ef5ccd1c 100644 --- a/src/newgal/sysvideo.h +++ b/src/newgal/sysvideo.h @@ -128,6 +128,9 @@ struct GAL_VideoDevice { */ void (*UpdateRects)(_THIS, int numrects, GAL_Rect *rects); + /* Wait vertical blank */ + BOOL (*WaitVBlank)(_THIS); + /* Synchronize the dirty content */ BOOL (*SyncUpdate)(_THIS);