case _EGL_PLATFORM_WAYLAND:
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;
#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"
{
struct dri2_egl_display *dri2_dpy;
struct gbm_device *gbm;
+ int fd = -1;
int i;
dri2_dpy = malloc(sizeof *dri2_dpy);
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;
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;
if (drmdpy->device_name)
FREE(drmdpy->device_name);
- if (drmdpy->fd >= 0)
- close(drmdpy->fd);
+ if (drmdpy->own_gbm) {
+ gbm_device_destroy(&drmdpy->gbmdrm->base.base);
+ if (drmdpy->fd >= 0)
+ close(drmdpy->fd);
+ }
FREE(drmdpy);
}
}
static struct native_display *
-drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
+drm_create_display(struct gbm_gallium_drm_device *gbmdrm, int own_gbm,
const struct native_event_handler *event_handler)
{
struct drm_display *drmdpy;
if (!drmdpy)
return NULL;
+ drmdpy->gbmdrm = gbmdrm;
+ drmdpy->own_gbm = own_gbm;
drmdpy->fd = gbmdrm->base.base.fd;
drmdpy->device_name = drm_get_device_name(drmdpy->fd);
{
struct gbm_gallium_drm_device *gbm;
int fd;
+ int own_gbm = 0;
gbm = dpy;
if (gbm == NULL) {
fd = open("/dev/dri/card0", O_RDWR);
+ /* FIXME: Use an internal constructor to create a gbm
+ * device with gallium backend directly, without setenv */
+ setenv("GBM_BACKEND", "gbm_gallium_drm.so", 1);
gbm = gbm_gallium_drm_device(gbm_create_device(fd));
+ own_gbm = 1;
}
if (gbm == NULL)
return NULL;
if (strcmp(gbm_device_get_backend_name(&gbm->base.base), "drm") != 0 ||
- gbm->base.type != GBM_DRM_DRIVER_TYPE_GALLIUM)
+ gbm->base.type != GBM_DRM_DRIVER_TYPE_GALLIUM) {
+ if (own_gbm)
+ gbm_device_destroy(&gbm->base.base);
return NULL;
+ }
- return drm_create_display(gbm, drm_event_handler);
+ return drm_create_display(gbm, own_gbm, drm_event_handler);
}
static const struct native_platform drm_platform = {