From c445b5a80d2397736fe790647dae32d065bd500c Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Fri, 14 Jun 2019 15:50:37 +0800 Subject: [PATCH] Suspend and Resume methods --- src/newgal/drm/drmvideo.c | 69 +++++++++++++++++++++++++++++++++++++-- src/newgal/drm/drmvideo.h | 2 +- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/newgal/drm/drmvideo.c b/src/newgal/drm/drmvideo.c index f73e805a..306f7878 100644 --- a/src/newgal/drm/drmvideo.c +++ b/src/newgal/drm/drmvideo.c @@ -69,6 +69,8 @@ static GAL_Surface *DRM_SetVideoMode_Dumb(_THIS, GAL_Surface *current, int width, int height, int bpp, Uint32 flags); static int DRM_AllocHWSurface_Dumb(_THIS, GAL_Surface *surface); static void DRM_FreeHWSurface_Dumb(_THIS, GAL_Surface *surface); +static int DRM_Suspend_Dumb(_THIS); +static int DRM_Resume_Dumb(_THIS); /* DRM engine operators accelerated */ static GAL_Surface *DRM_SetVideoMode_Accl(_THIS, GAL_Surface *current, @@ -154,14 +156,18 @@ static void drm_cleanup(DrmVideoData* vdata) if (vdata->saved_crtc) { /* restore saved CRTC configuration */ - drmModeSetCrtc(vdata->dev_fd, + int ret = drmModeSetCrtc(vdata->dev_fd, vdata->saved_crtc->crtc_id, vdata->saved_crtc->buffer_id, vdata->saved_crtc->x, vdata->saved_crtc->y, - &vdata->conn, - 1, + &vdata->saved_info->conn, 1, &vdata->saved_crtc->mode); + if (ret) { + _ERR_PRINTF ("NEWGAL>DRM: failed to restore CRTC for connector %u (%d): %m\n", + vdata->saved_info->conn, errno); + } + drmModeFreeCrtc(vdata->saved_crtc); } @@ -350,6 +356,8 @@ static GAL_VideoDevice *DRM_CreateDevice(int devindex) device->SetHWColorKey = NULL; device->SetHWAlpha = NULL; device->FreeHWSurface = DRM_FreeHWSurface_Dumb; + device->Suspend = DRM_Suspend_Dumb; + device->Resume = DRM_Resume_Dumb; } device->free = DRM_DeleteDevice; @@ -735,6 +743,8 @@ static GAL_Surface *DRM_SetVideoMode_Dumb(_THIS, GAL_Surface *current, return NULL; } + this->hidden->saved_info = info; + /* Set up the new mode framebuffer */ /* Allocate the new pixel format for the screen */ if (!GAL_ReallocFormat (current, bpp, 0, 0, 0, 0)) { @@ -764,6 +774,59 @@ static void DRM_FreeHWSurface_Dumb(_THIS, GAL_Surface *surface) surface->pixels = NULL; } +static int DRM_Resume_Dumb(_THIS) +{ + DrmVideoData* vdata = this->hidden; + int ret = -1; + + _DBG_PRINTF ("NEWGAL>DRM: %s called\n", __FUNCTION__); + + if (vdata->saved_info) { + vdata->saved_crtc = drmModeGetCrtc(vdata->dev_fd, + vdata->saved_info->crtc); + ret = drmModeSetCrtc(vdata->dev_fd, + vdata->saved_info->crtc, + vdata->buff, 0, 0, + &vdata->saved_info->conn, 1, + &vdata->saved_info->mode); + } + + if (ret) { + _ERR_PRINTF ("NEWGAL>DRM: Failed to resume dumb frame buffer: %d.\n", + ret); + } + + return ret; +} + +static int DRM_Suspend_Dumb(_THIS) +{ + DrmVideoData* vdata = this->hidden; + int ret = -1; + + _DBG_PRINTF ("NEWGAL>DRM: %s called\n", __FUNCTION__); + + if (vdata->saved_crtc) { + /* restore saved CRTC configuration */ + ret = drmModeSetCrtc(vdata->dev_fd, + vdata->saved_crtc->crtc_id, + vdata->saved_crtc->buffer_id, + vdata->saved_crtc->x, + vdata->saved_crtc->y, + &vdata->saved_info->conn, 1, + &vdata->saved_crtc->mode); + + drmModeFreeCrtc(vdata->saved_crtc); + vdata->saved_crtc = NULL; + } + + if (ret) { + _ERR_PRINTF ("NEWGAL>DRM: Failed to suspend dumb frame buffer: %m.\n"); + } + + return ret; +} + /* DRM engine methods for accelerated buffers */ static GAL_Surface *DRM_SetVideoMode_Accl(_THIS, GAL_Surface *current, int width, int height, int bpp, Uint32 flags) diff --git a/src/newgal/drm/drmvideo.h b/src/newgal/drm/drmvideo.h index 33af1a81..33caf665 100644 --- a/src/newgal/drm/drmvideo.h +++ b/src/newgal/drm/drmvideo.h @@ -63,10 +63,10 @@ typedef struct GAL_PrivateVideoData { uint32_t pitch; uint32_t size; - uint32_t conn; uint32_t buff; uint32_t handle; + DrmModeInfo* saved_info; drmModeCrtc* saved_crtc; uint8_t* fb; } DrmVideoData;