From f8e07c4d7cc7f8ba5adfdd156905b643dccbee71 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Thu, 14 Jul 2016 16:25:05 -0500 Subject: [PATCH] ecore_drm2: Try to mmap gbm buffers We're currently doing screenshots in E under wayland by copying data out of the framebuffer, mmaping gbm buffers makes screenshots work again when rendering with GL. --- src/lib/ecore_drm2/ecore_drm2_fb.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib/ecore_drm2/ecore_drm2_fb.c b/src/lib/ecore_drm2/ecore_drm2_fb.c index 58ad911a72..07d4e51336 100644 --- a/src/lib/ecore_drm2/ecore_drm2_fb.c +++ b/src/lib/ecore_drm2/ecore_drm2_fb.c @@ -108,7 +108,9 @@ err: EAPI Ecore_Drm2_Fb * ecore_drm2_fb_gbm_create(int fd, int width, int height, int depth, int bpp, unsigned int format, unsigned int handle, unsigned int stride) { + struct drm_mode_map_dumb marg; Ecore_Drm2_Fb *fb; + int ret; EINA_SAFETY_ON_TRUE_RETURN_VAL((fd < 0), NULL); @@ -141,6 +143,15 @@ ecore_drm2_fb_gbm_create(int fd, int width, int height, int depth, int bpp, unsi } } + /* mmap it if we can so screenshots are easy */ + memset(&marg, 0, sizeof(struct drm_mode_map_dumb)); + marg.handle = fb->hdl; + ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &marg); + if (!ret) + { + fb->mmap = mmap(NULL, fb->size, PROT_WRITE, MAP_SHARED, fd, marg.offset); + if (fb->mmap == MAP_FAILED) fb->mmap = NULL; + } return fb; err: @@ -153,14 +164,14 @@ ecore_drm2_fb_destroy(Ecore_Drm2_Fb *fb) { EINA_SAFETY_ON_NULL_RETURN(fb); + if (fb->mmap) munmap(fb->mmap, fb->size); + if (fb->id) drmModeRmFB(fb->fd, fb->id); if (!fb->gbm) { struct drm_mode_destroy_dumb darg; - if (fb->mmap) munmap(fb->mmap, fb->size); - memset(&darg, 0, sizeof(struct drm_mode_destroy_dumb)); darg.handle = fb->hdl; drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);