From bfe28b8d938c4082e9334e4ccaf423fcd1625154 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Thu, 20 Dec 2012 14:16:50 -0800 Subject: egl/android: Fix build for Jelly Bean (v2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Jelly Bean, the interface to ANativeWindow changed. The change included adding a new parameter the queueBuffer and dequeueBuffer methods, removing the lockBuffer method, and requiring libsync. v2: - s/fence_fd == -1/fence_fd != -1/ - Fix leak. Close the fence_fd. Reviewed-by: Tapani Pälli Signed-off-by: Chad Versace --- src/egl/drivers/dri2/platform_android.c | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/egl/drivers') diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 15bf0548b5c..7ede48de69c 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -31,6 +31,10 @@ #include #include +#if ANDROID_VERSION >= 0x402 +#include +#endif + /* for droid_get_pci_id */ #include #include @@ -79,11 +83,48 @@ get_native_buffer_name(struct ANativeWindowBuffer *buf) static EGLBoolean droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf) { +#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 >= 0) { + /* From the SYNC_IOC_WAIT documentation in : + * + * Waits indefinitely if timeout < 0. + */ + int timeout = -1; + sync_wait(fence_fd, timeout); + close(fence_fd); + } + + dri2_surf->buffer->common.incRef(&dri2_surf->buffer->common); +#else if (dri2_surf->window->dequeueBuffer(dri2_surf->window, &dri2_surf->buffer)) return EGL_FALSE; dri2_surf->buffer->common.incRef(&dri2_surf->buffer->common); dri2_surf->window->lockBuffer(dri2_surf->window, dri2_surf->buffer); +#endif return EGL_TRUE; } @@ -91,7 +132,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; -- cgit v1.2.3