Permalink
Browse files

egl: android: experimental dma-buf fd support

* create_image() using createImageFromFds() when built with DMABUF flag.
* flink names still required by getBuffersWithFormat() to fill
  __DRIbuffer->name

Signed-off-by: Varad Gautam <varadgautam@gmail.com>
  • Loading branch information...
varadgautam committed Jul 13, 2015
1 parent b298311 commit 0eb02ed82de38046239a581f0e714b86de06d551
Showing with 59 additions and 2 deletions.
  1. +2 −1 src/egl/drivers/dri2/Android.mk
  2. +57 −1 src/egl/drivers/dri2/platform_android.c
@@ -33,7 +33,8 @@ LOCAL_SRC_FILES := \
LOCAL_CFLAGS := \
-DHAVE_SHARED_GLAPI \
-DHAVE_ANDROID_PLATFORM
-DHAVE_ANDROID_PLATFORM \
-DDMABUF
ifeq ($(MESA_LOLLIPOP_BUILD),true)
LOCAL_CFLAGS_arm := -DDEFAULT_DRIVER_DIR=\"/system/lib/dri\"
@@ -64,6 +64,37 @@ get_format_bpp(int native)
return bpp;
}
/* createImageFromFds requires fourcc format */
static int get_fourcc(int format)
{
switch(format) {
case __DRI_IMAGE_FORMAT_RGB565:
format = __DRI_IMAGE_FOURCC_RGB565;
break;
case __DRI_IMAGE_FORMAT_ARGB8888:
format = __DRI_IMAGE_FOURCC_ARGB8888;
break;
case __DRI_IMAGE_FORMAT_XRGB8888:
format = __DRI_IMAGE_FOURCC_XRGB8888;
break;
case __DRI_IMAGE_FORMAT_ABGR8888:
format = __DRI_IMAGE_FOURCC_ABGR8888;
break;
case __DRI_IMAGE_FORMAT_XBGR8888:
format = __DRI_IMAGE_FOURCC_XBGR8888;
break;
default:
return -1;
}
return format;
}
static int
get_native_buffer_fd(struct ANativeWindowBuffer *buf)
{
return gralloc_drm_get_prime_fd(buf->handle);
}
static int
get_native_buffer_name(struct ANativeWindowBuffer *buf)
{
@@ -327,7 +358,9 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_image *dri2_img;
int name;
int name, fd;
int offset = 0;
int stride;
EGLint format;
if (ctx != NULL) {
@@ -348,11 +381,19 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
return NULL;
}
#ifdef DMABUF // createImageFromFds()
fd = get_native_buffer_fd(buf);
if (fd < 0) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return NULL;
}
#else // createImageFromName()
name = get_native_buffer_name(buf);
if (!name) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return NULL;
}
#endif
/* see the table in droid_add_configs_for_visuals */
switch (buf->format) {
@@ -387,6 +428,20 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
return NULL;
}
#ifdef DMABUF
/* createImageFromFds requires stride in bytes instead of pixels */
stride = buf->stride * get_format_bpp(buf->format);
dri2_img->dri_image =
dri2_dpy->image->createImageFromFds(dri2_dpy->dri_screen,
buf->width,
buf->height,
get_fourcc(format),
&fd,
1,
&stride,
&offset,
dri2_img);
#else
dri2_img->dri_image =
dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
buf->width,
@@ -395,6 +450,7 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
name,
buf->stride,
dri2_img);
#endif
if (!dri2_img->dri_image) {
free(dri2_img);
_eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");

0 comments on commit 0eb02ed

Please sign in to comment.