The interface to ANativeWindow changed in Jelly Bean. The change included adding fence file descriptor parameter to the queueBuffer and dequeueBuffer methods and removing the lockBuffer method.
CC: Tapani Pälli <tapani.pa...@intel.com> Signed-off-by: Chad Versace <chad.vers...@linux.intel.com> --- src/egl/drivers/dri2/Android.mk | 5 +++ src/egl/drivers/dri2/platform_android.c | 60 +++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/egl/drivers/dri2/Android.mk b/src/egl/drivers/dri2/Android.mk index 090a0e1..eb4ab93 100644 --- a/src/egl/drivers/dri2/Android.mk +++ b/src/egl/drivers/dri2/Android.mk @@ -43,6 +43,11 @@ LOCAL_C_INCLUDES := \ $(DRM_TOP) \ $(DRM_TOP)/include/drm +ifeq ($(shell echo "$(MESA_ANDROID_VERSION) >= 4.2" | bc),1) + LOCAL_SHARED_LIBRARIES := \ + sync +endif + LOCAL_MODULE := libmesa_egl_dri2 include $(MESA_COMMON_MK) diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 15bf054..a600d2b 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -31,6 +31,10 @@ #include <errno.h> #include <dlfcn.h> +#if ANDROID_VERSION >= 0x402 +#include <sync/sync.h> +#endif + /* for droid_get_pci_id */ #include <xf86drm.h> #include <i915_drm.h> @@ -79,11 +83,44 @@ get_native_buffer_name(struct ANativeWindowBuffer *buf) static EGLBoolean droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf) { - if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer)) +#if ANDROID_VERSION >= 0x0402 + int fence_fd; + + if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer, + &fence_fd)) + return EGL_FALSE; + + /* If access to the buffer is controlled by a sync fence, then block on the + * fence. + * + * It may be more performant to postpone blocking until there is an + * immediate need to write to the buffer. But doing so would require adding + * hooks to the DRI2 loader. + * + * From the ANativeWindow::dequeueBuffer documentation: + * + * The libsync fence file descriptor returned in the int pointed to by + * the fenceFd argument will refer to the fence that must signal + * before the dequeued buffer may be written to. A value of -1 + * indicates that the caller may access the buffer immediately without + * waiting on a fence. If a valid file descriptor is returned (i.e. + * any value except -1) then the caller is responsible for closing the + * file descriptor. + */ + if (fence_fd == -1) { + /* From the SYNC_IOC_WAIT documentation in <linux/sync.h>: + * + * Waits indefinitely if timeout < 0. + */ + int timeout = -1; + sync_wait(fence_fd, timeout); + } +#else + if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer) return EGL_FALSE; +#endif dri2_surf->buffer->common.incRef(&dri2_surf->buffer->common); - dri2_surf->window->lockBuffer(dri2_surf->window, dri2_surf->buffer); return EGL_TRUE; } @@ -91,8 +128,25 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf) static EGLBoolean droid_window_enqueue_buffer(struct dri2_egl_surface *dri2_surf) { +#if ANDROID_VERSION >= 0x0402 + /* Queue the buffer without a sync fence. This informs the ANativeWindow + * that it may access the buffer immediately. + * + * From ANativeWindow::dequeueBuffer: + * + * The fenceFd argument specifies a libsync fence file descriptor for + * a fence that must signal before the buffer can be accessed. If + * the buffer can be accessed immediately then a value of -1 should + * be used. The caller must not use the file descriptor after it + * is passed to queueBuffer, and the ANativeWindow implementation + * is responsible for closing it. + */ + int fence_fd = -1; + dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer, + fence_fd); +#else dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer); - +#endif dri2_surf->buffer->common.decRef(&dri2_surf->buffer->common); dri2_surf->buffer = NULL; -- 1.7.11.7 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev