diff options
Diffstat (limited to 'src/egl/drivers')
-rw-r--r-- | src/egl/drivers/dri2/egl_dri2.c | 7 | ||||
-rw-r--r-- | src/egl/drivers/dri2/egl_dri2.h | 1 | ||||
-rw-r--r-- | src/egl/drivers/dri2/platform_drm.c | 25 |
3 files changed, 31 insertions, 2 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 0aca929e6aa..9a37ea4bbfc 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -592,6 +592,13 @@ dri2_terminate(_EGLDriver *drv, _EGLDisplay *disp) wl_display_destroy(dri2_dpy->wl_dpy); break; #endif +#ifdef HAVE_DRM_PLATFORM + case _EGL_PLATFORM_DRM: + if (dri2_dpy->own_gbm_device) { + gbm_device_destroy(&dri2_dpy->gbm_dri->base.base); + } + break; +#endif default: break; } diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 3854200bc69..a7297188af2 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -86,6 +86,7 @@ struct dri2_egl_display #ifdef HAVE_DRM_PLATFORM struct gbm_dri_device *gbm_dri; + int own_gbm_device; #endif char *device_name; diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c index 579baf9f9d2..04b10e279ec 100644 --- a/src/egl/drivers/dri2/platform_drm.c +++ b/src/egl/drivers/dri2/platform_drm.c @@ -30,6 +30,10 @@ #include <string.h> #include <xf86drm.h> #include <dlfcn.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> #include "egl_dri2.h" @@ -90,6 +94,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) { struct dri2_egl_display *dri2_dpy; struct gbm_device *gbm; + int fd = -1; int i; dri2_dpy = malloc(sizeof *dri2_dpy); @@ -100,7 +105,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) disp->DriverData = (void *) dri2_dpy; - gbm = (struct gbm_device *) disp->PlatformDisplay; + gbm = disp->PlatformDisplay; + if (gbm == NULL) { + fd = open("/dev/dri/card0", O_RDWR); + dri2_dpy->own_gbm_device = 1; + gbm = gbm_create_device(fd); + if (gbm == NULL) + return EGL_FALSE; + } + if (strcmp(gbm_device_get_backend_name(gbm), "drm") != 0) { free(dri2_dpy); return EGL_FALSE; @@ -112,7 +125,15 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp) return EGL_FALSE; } - dri2_dpy->fd = gbm_device_get_fd(gbm); + if (fd < 0) { + fd = dup(gbm_device_get_fd(gbm)); + if (fd < 0) { + free(dri2_dpy); + return EGL_FALSE; + } + } + + dri2_dpy->fd = fd; dri2_dpy->device_name = dri2_get_device_name_for_fd(dri2_dpy->fd); dri2_dpy->driver_name = dri2_dpy->gbm_dri->base.driver_name; |