glamor_egl: Avoid flink names in glamor_egl_create_textured_pixmap().

Using flink is banned on render nodes, and they needlessly expose our
screen pixmap contents to any authenticated client.  This also
incidentally drops the dependency on EGL_MESA_drm_image.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Eric Anholt 2017-05-16 11:37:20 -07:00 committed by Adam Jackson
parent 5d6f17d913
commit 59de50d6ef

View File

@ -92,38 +92,6 @@ glamor_egl_make_current(struct glamor_context *glamor_ctx)
} }
} }
static EGLImageKHR
_glamor_egl_create_image(struct glamor_egl_screen_private *glamor_egl,
int width, int height, int stride, int name, int depth)
{
EGLImageKHR image;
EGLint attribs[] = {
EGL_WIDTH, 0,
EGL_HEIGHT, 0,
EGL_DRM_BUFFER_STRIDE_MESA, 0,
EGL_DRM_BUFFER_FORMAT_MESA,
EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA,
EGL_DRM_BUFFER_USE_SHARE_MESA | EGL_DRM_BUFFER_USE_SCANOUT_MESA,
EGL_NONE
};
attribs[1] = width;
attribs[3] = height;
attribs[5] = stride;
if (depth != 32 && depth != 24)
return EGL_NO_IMAGE_KHR;
image = eglCreateImageKHR(glamor_egl->display,
glamor_egl->context,
EGL_DRM_BUFFER_MESA,
(void *) (uintptr_t) name,
attribs);
if (image == EGL_NO_IMAGE_KHR)
return EGL_NO_IMAGE_KHR;
return image;
}
static int static int
glamor_get_flink_name(int fd, int handle, int *name) glamor_get_flink_name(int fd, int handle, int *name)
{ {
@ -212,43 +180,34 @@ glamor_egl_create_textured_pixmap(PixmapPtr pixmap, int handle, int stride)
{ {
ScreenPtr screen = pixmap->drawable.pScreen; ScreenPtr screen = pixmap->drawable.pScreen;
ScrnInfoPtr scrn = xf86ScreenToScrn(screen); ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
struct glamor_screen_private *glamor_priv = struct glamor_egl_screen_private *glamor_egl =
glamor_get_screen_private(screen); glamor_egl_get_screen_private(scrn);
struct glamor_egl_screen_private *glamor_egl; int ret, fd;
EGLImageKHR image;
GLuint texture;
int name;
Bool ret = FALSE;
glamor_egl = glamor_egl_get_screen_private(scrn); /* GBM doesn't have an import path from handles, so we make a
* dma-buf fd from it and then go through that.
glamor_make_current(glamor_priv); */
if (!glamor_get_flink_name(glamor_egl->fd, handle, &name)) { ret = drmPrimeHandleToFD(glamor_egl->fd, handle, O_CLOEXEC, &fd);
if (ret) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR, xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Couldn't flink pixmap handle\n"); "Failed to make prime FD for handle: %d\n", errno);
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY);
assert(0);
return FALSE; return FALSE;
} }
image = _glamor_egl_create_image(glamor_egl, if (!glamor_back_pixmap_from_fd(pixmap, fd,
pixmap->drawable.width, pixmap->drawable.width,
pixmap->drawable.height, pixmap->drawable.height,
((stride * 8 + stride,
7) / pixmap->drawable.bitsPerPixel), pixmap->drawable.depth,
name, pixmap->drawable.depth); pixmap->drawable.bitsPerPixel)) {
if (image == EGL_NO_IMAGE_KHR) { xf86DrvMsg(scrn->scrnIndex, X_ERROR,
glamor_set_pixmap_type(pixmap, GLAMOR_DRM_ONLY); "Failed to make import prime FD as pixmap: %d\n", errno);
goto done; close(fd);
return FALSE;
} }
glamor_create_texture_from_image(screen, image, &texture);
glamor_set_pixmap_type(pixmap, GLAMOR_TEXTURE_DRM);
glamor_set_pixmap_texture(pixmap, texture);
glamor_egl_set_pixmap_image(pixmap, image);
ret = TRUE;
done: close(fd);
return ret; return TRUE;
} }
Bool Bool
@ -739,7 +698,6 @@ glamor_egl_init(ScrnInfoPtr scrn, int fd)
goto error; \ goto error; \
} }
GLAMOR_CHECK_EGL_EXTENSION(MESA_drm_image);
GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_texture_2D_image); GLAMOR_CHECK_EGL_EXTENSION(KHR_gl_texture_2D_image);
#ifdef GLAMOR_GLES2 #ifdef GLAMOR_GLES2
GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context, KHR_surfaceless_gles2); GLAMOR_CHECK_EGL_EXTENSIONS(KHR_surfaceless_context, KHR_surfaceless_gles2);