(DRM/EGL) Cleanups

This commit is contained in:
twinaphex 2015-11-19 17:02:02 +01:00
parent 64bfea11f6
commit 512585f673

View File

@ -147,13 +147,14 @@ static void gfx_ctx_drm_egl_check_window(void *data, bool *quit,
*quit = g_egl_quit; *quit = g_egl_quit;
} }
static unsigned first_page_flip;
static unsigned last_page_flip;
static bool waiting_for_flip; static bool waiting_for_flip;
static void page_flip_handler(int fd, unsigned frame, static void page_flip_handler(int fd, unsigned frame,
unsigned sec, unsigned usec, void *data) unsigned sec, unsigned usec, void *data)
{ {
static unsigned first_page_flip;
static unsigned last_page_flip;
(void)fd; (void)fd;
(void)sec; (void)sec;
(void)usec; (void)usec;
@ -179,9 +180,11 @@ static bool wait_flip(gfx_ctx_drm_egl_data_t *drm, bool block)
struct pollfd fds = {0}; struct pollfd fds = {0};
drmEventContext evctx = {0}; drmEventContext evctx = {0};
fds.fd = drm->g_drm_fd; if (!waiting_for_flip)
fds.events = POLLIN; return false;
fds.fd = drm->g_drm_fd;
fds.events = POLLIN;
evctx.version = DRM_EVENT_CONTEXT_VERSION; evctx.version = DRM_EVENT_CONTEXT_VERSION;
evctx.page_flip_handler = page_flip_handler; evctx.page_flip_handler = page_flip_handler;
@ -217,7 +220,7 @@ static bool wait_flip(gfx_ctx_drm_egl_data_t *drm, bool block)
return false; return false;
} }
static void queue_flip(gfx_ctx_drm_egl_data_t *drm) static bool queue_flip(gfx_ctx_drm_egl_data_t *drm)
{ {
struct drm_fb *fb = NULL; struct drm_fb *fb = NULL;
@ -226,13 +229,11 @@ static void queue_flip(gfx_ctx_drm_egl_data_t *drm)
fb = (struct drm_fb*)drm_fb_get_from_bo(drm, drm->g_next_bo); fb = (struct drm_fb*)drm_fb_get_from_bo(drm, drm->g_next_bo);
if (drmModePageFlip(drm->g_drm_fd, drm->g_crtc_id, fb->fb_id, if (drmModePageFlip(drm->g_drm_fd, drm->g_crtc_id, fb->fb_id,
DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip) < 0) DRM_MODE_PAGE_FLIP_EVENT, &waiting_for_flip) == 0)
{ return true;
RARCH_ERR("[KMS/EGL]: Failed to queue page flip.\n");
return; /* Failed to queue page flip. */
} return false;
waiting_for_flip = true;
} }
static void gfx_ctx_drm_egl_swap_buffers(void *data) static void gfx_ctx_drm_egl_swap_buffers(void *data)
@ -244,17 +245,14 @@ static void gfx_ctx_drm_egl_swap_buffers(void *data)
egl_swap_buffers(data); egl_swap_buffers(data);
/* I guess we have to wait for flip to have taken /* I guess we have to wait for flip to have taken
* place before another flip can be queued up. */ * place before another flip can be queued up.
if (waiting_for_flip) *
{ * If true, we are still waiting for a flip
/* We are still waiting for a flip * (nonblocking mode, so just drop the frame). */
* (nonblocking mode, just drop the frame). if (wait_flip(drm, g_interval))
*/ return;
if (wait_flip(drm, g_interval))
return;
}
queue_flip(drm); waiting_for_flip = queue_flip(drm);
if (gbm_surface_has_free_buffers(drm->g_gbm_surface)) if (gbm_surface_has_free_buffers(drm->g_gbm_surface))
return; return;
@ -339,9 +337,7 @@ static void gfx_ctx_drm_egl_destroy_resources(gfx_ctx_drm_egl_data_t *drm)
return; return;
/* Make sure we acknowledge all page-flips. */ /* Make sure we acknowledge all page-flips. */
wait_flip(drm, true);
if (waiting_for_flip)
wait_flip(drm, true);
egl_destroy(NULL); egl_destroy(NULL);