summaryrefslogtreecommitdiffstats
path: root/src/egl/drivers/dri2/platform_android.c
diff options
context:
space:
mode:
authorTomasz Figa <tfiga@chromium.org>2016-08-02 20:07:52 +0900
committerChad Versace <chad@kiwitree.net>2016-08-08 11:40:37 -0700
commite77b4933907106238c7872cb74d0ba0b5246aee6 (patch)
tree6810215bc15000ac320a5de7f52601fd2d029b62 /src/egl/drivers/dri2/platform_android.c
parent217af75a4092545fb9f5afe4a12e0b74cb1b48e4 (diff)
downloadexternal_mesa3d-e77b4933907106238c7872cb74d0ba0b5246aee6.zip
external_mesa3d-e77b4933907106238c7872cb74d0ba0b5246aee6.tar.gz
external_mesa3d-e77b4933907106238c7872cb74d0ba0b5246aee6.tar.bz2
egl/android: Refactor image creation to separate flink and prime paths (v2)
This patch splits current dri2_create_image_android_native_buffer() into main entry point and two additional functions, one for creating an image from flink name and one for handling prime FDs using the generic DMA-buf path. This makes the code cleaner and also prepares for disabling flink path more easily in the future. v2: Split into separate patch. Add error messages. Signed-off-by: Tomasz Figa <tfiga@chromium.org> Tested-by: Rob Herring <rob@kernel.org> Reviewed-by: Chad Versace <chad@kiwitree.net> Change-Id: Ifdfb5927399d56992fe707160423c29278f49172
Diffstat (limited to 'src/egl/drivers/dri2/platform_android.c')
-rw-r--r--src/egl/drivers/dri2/platform_android.c99
1 files changed, 57 insertions, 42 deletions
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index d78c06d..94e765d 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -478,53 +478,36 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
}
static _EGLImage *
-dri2_create_image_android_native_buffer(_EGLDisplay *disp,
- _EGLContext *ctx,
- struct ANativeWindowBuffer *buf)
+droid_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx,
+ struct ANativeWindowBuffer *buf, int fd)
{
- struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- struct dri2_egl_image *dri2_img;
- int name, fd;
- int format;
-
- if (ctx != NULL) {
- /* From the EGL_ANDROID_image_native_buffer spec:
- *
- * * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not
- * EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated.
- */
- _eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for "
- "EGL_NATIVE_BUFFER_ANDROID, the context must be "
- "EGL_NO_CONTEXT");
- return NULL;
- }
+ const int fourcc = get_fourcc(get_format(buf->format));
+ const int pitch = buf->stride * get_format_bpp(buf->format);
+
+ const EGLint attr_list[14] = {
+ EGL_WIDTH, buf->width,
+ EGL_HEIGHT, buf->height,
+ EGL_LINUX_DRM_FOURCC_EXT, fourcc,
+ EGL_DMA_BUF_PLANE0_FD_EXT, fd,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT, pitch,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
+ EGL_NONE, 0
+ };
- if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC ||
- buf->common.version != sizeof(*buf)) {
- _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+ if (fourcc == -1 || pitch == 0)
return NULL;
- }
- fd = get_native_buffer_fd(buf);
- if (fd >= 0) {
- const int fourcc = get_fourcc(get_format(buf->format));
- const int pitch = buf->stride * get_format_bpp(buf->format);
-
- const EGLint attr_list[14] = {
- EGL_WIDTH, buf->width,
- EGL_HEIGHT, buf->height,
- EGL_LINUX_DRM_FOURCC_EXT, fourcc,
- EGL_DMA_BUF_PLANE0_FD_EXT, fd,
- EGL_DMA_BUF_PLANE0_PITCH_EXT, pitch,
- EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
- EGL_NONE, 0
- };
-
- if (fourcc == -1 || pitch == 0)
- return NULL;
+ return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list);
+}
- return dri2_create_image_dma_buf(disp, ctx, NULL, attr_list);
- }
+static _EGLImage *
+droid_create_image_from_name(_EGLDisplay *disp, _EGLContext *ctx,
+ struct ANativeWindowBuffer *buf)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_image *dri2_img;
+ int name;
+ int format;
name = get_native_buffer_name(buf);
if (!name) {
@@ -565,6 +548,38 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp,
}
static _EGLImage *
+dri2_create_image_android_native_buffer(_EGLDisplay *disp,
+ _EGLContext *ctx,
+ struct ANativeWindowBuffer *buf)
+{
+ int fd;
+
+ if (ctx != NULL) {
+ /* From the EGL_ANDROID_image_native_buffer spec:
+ *
+ * * If <target> is EGL_NATIVE_BUFFER_ANDROID and <ctx> is not
+ * EGL_NO_CONTEXT, the error EGL_BAD_CONTEXT is generated.
+ */
+ _eglError(EGL_BAD_CONTEXT, "eglCreateEGLImageKHR: for "
+ "EGL_NATIVE_BUFFER_ANDROID, the context must be "
+ "EGL_NO_CONTEXT");
+ return NULL;
+ }
+
+ if (!buf || buf->common.magic != ANDROID_NATIVE_BUFFER_MAGIC ||
+ buf->common.version != sizeof(*buf)) {
+ _eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
+ return NULL;
+ }
+
+ fd = get_native_buffer_fd(buf);
+ if (fd >= 0)
+ return droid_create_image_from_prime_fd(disp, ctx, buf, fd);
+
+ return droid_create_image_from_name(disp, ctx, buf);
+}
+
+static _EGLImage *
droid_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
_EGLContext *ctx, EGLenum target,
EGLClientBuffer buffer, const EGLint *attr_list)