From 6fb92e67b3f3dee38d8d440c8ab9f8cc5dcef9bc Mon Sep 17 00:00:00 2001 From: Li Peng Date: Fri, 20 Jan 2012 16:23:17 +0800 Subject: [PATCH] glamor: check driver support GEM or not glamor calls DRM_IOCTL_GEM_FLINK to get a name for a buffer object. It only works for driver that support GEM, such as intel i915 driver. But for pvr driver who doesn't has GEM, we can't do it this way. According to Chris's comments, we check the has_gem as the following method: Here we just try to flink handle 0. If that fails with ENODEV or ENOTTY instead of ENOENT (or EINVAL on older kernels), set has_gem=0. Signed-off-by: Li Peng Reviewed-by: Zhigang Gong --- glamor/glamor_egl.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c index c273e8a13..71121bce7 100644 --- a/glamor/glamor_egl.c +++ b/glamor/glamor_egl.c @@ -89,6 +89,7 @@ struct glamor_egl_screen_private { #ifdef GLAMOR_HAS_GBM struct gbm_device *gbm; #endif + int has_gem; PFNEGLCREATEIMAGEKHRPROC egl_create_image_khr; PFNEGLDESTROYIMAGEKHRPROC egl_destroy_image_khr; @@ -188,6 +189,19 @@ glamor_egl_create_textured_screen(ScreenPtr screen, int handle, int stride) return TRUE; } +Bool +glamor_egl_check_has_gem(int fd) +{ + struct drm_gem_flink flink; + flink.handle = 0; + int err; + + ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink); + if (errno == ENOENT || err == EINVAL) + return TRUE; + return FALSE; +} + Bool glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) { @@ -200,12 +214,16 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride) glamor_egl = glamor_egl_get_screen_private(scrn); - if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) { - xf86DrvMsg(scrn->scrnIndex, X_ERROR, - "Couldn't flink pixmap handle\n"); - glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY); - exit(1); - } + if (glamor_egl->has_gem) { + if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) { + xf86DrvMsg(scrn->scrnIndex, X_ERROR, + "Couldn't flink pixmap handle\n"); + glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY); + exit(1); + } + } else + name = handle; + image = _glamor_egl_create_image(glamor_egl, pixmap->drawable.width, pixmap->drawable.height, @@ -312,6 +330,8 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd) glamor_egl->display = eglGetDisplay((EGLNativeDisplayType)fd); #endif + glamor_egl->has_gem = glamor_egl_check_has_gem(fd); + #ifndef GLAMOR_GLES2 eglBindAPI(EGL_OPENGL_API); #else