Skip to content

Commit

Permalink
minuitwrp: drm: wait for last page flip to complete
Browse files Browse the repository at this point in the history
if we try and flip pages too quickly, the kernel returns -EBUSY.
Use drmHandleEvent to wait for any previous flip to complete
before attempting a new one.

Change-Id: If3def889c0c89d7cfb8b7f13c4dae6d4b12760f9
  • Loading branch information
fourkbomb authored and Dees-Troy committed May 25, 2018
1 parent 16d831b commit 34ad728
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion minuitwrp/graphics_drm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct drm_surface {

static drm_surface *drm_surfaces[2];
static int current_buffer;
static bool flip_pending = false;
static GRSurface *draw_buf = NULL;

static drmModeCrtc *main_monitor_crtc;
Expand Down Expand Up @@ -480,18 +481,36 @@ static GRSurface* drm_init(minui_backend* backend __unused) {
return draw_buf;
}

static void drm_page_flip_event(int fd, unsigned int frame, unsigned int sec,
unsigned int usec, void *data) {
flip_pending = false;
}

static GRSurface* drm_flip(minui_backend* backend __unused) {
int ret;
drmEventContext ev;

memset(&ev, 0, sizeof(ev));

memcpy(drm_surfaces[current_buffer]->base.data,
draw_buf->data, draw_buf->height * draw_buf->row_bytes);

ev.version = 2;
ev.page_flip_handler = drm_page_flip_event;

/* wait for previous page flip, if any, to complete */
while (flip_pending) {
drmHandleEvent(drm_fd, &ev);
}

ret = drmModePageFlip(drm_fd, main_monitor_crtc->crtc_id,
drm_surfaces[current_buffer]->fb_id, 0, NULL);
drm_surfaces[current_buffer]->fb_id, DRM_MODE_PAGE_FLIP_EVENT, NULL);
if (ret < 0) {
printf("drmModePageFlip failed ret=%d\n", ret);
return NULL;
}

flip_pending = true;
current_buffer = 1 - current_buffer;
return draw_buf;
}
Expand Down

0 comments on commit 34ad728

Please sign in to comment.