| From d1b8ea27dd304b81dba02a9d1d74441fb2e6caea Mon Sep 17 00:00:00 2001 |
| From: David Stevens <stevensd@chromium.org> |
| Date: Thu, 26 Nov 2020 13:52:58 +0900 |
| Subject: [PATCH 11/11] egl/android: implement image cleanup callback |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| According to ANDROID_get_native_client_buffer, EGL implementations must |
| guarantee that the lifetime of an EGLClientBuffer returned by |
| eglGetNativeClientBufferANDROID is at least as long as that of the |
| EGLImage which is bound to. Do this by acquiring a reference to the |
| underlying AHardwareBuffer for all ANativeWindowBuffers which are bound |
| to an _EGLImage. |
| |
| Signed-off-by: David Stevens <stevensd@chromium.org> |
| Reviewed-by: Tapani Pรคlli <tapani.palli@intel.com> |
| Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7805> |
| Change-Id: I4097fbcba91b1d5f6d7e0e423a84a808c101c347 |
| --- |
| src/egl/drivers/dri2/platform_android.c | 72 ++++++++++++++++--------- |
| 1 file changed, 48 insertions(+), 24 deletions(-) |
| |
| diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c |
| index 0395b5246e4..1abe7d157c5 100644 |
| --- a/src/egl/drivers/dri2/platform_android.c |
| +++ b/src/egl/drivers/dri2/platform_android.c |
| @@ -207,6 +207,7 @@ get_native_buffer_name(struct ANativeWindowBuffer *buf) |
| static __DRIimage * |
| droid_create_image_from_prime_fds_yuv(_EGLDisplay *disp, |
| struct ANativeWindowBuffer *buf, |
| + void *priv, |
| int num_fds, int fds[3]) |
| { |
| struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| @@ -288,12 +289,13 @@ droid_create_image_from_prime_fds_yuv(_EGLDisplay *disp, |
| EGL_YUV_CHROMA_SITING_0_EXT, |
| EGL_YUV_CHROMA_SITING_0_EXT, |
| &error, |
| - NULL); |
| + priv); |
| } |
| |
| static __DRIimage * |
| droid_create_image_from_prime_fds(_EGLDisplay *disp, |
| - struct ANativeWindowBuffer *buf) |
| + struct ANativeWindowBuffer *buf, |
| + void *priv) |
| { |
| struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| int pitches[4] = { 0 }, offsets[4] = { 0 }; |
| @@ -308,7 +310,8 @@ droid_create_image_from_prime_fds(_EGLDisplay *disp, |
| if (is_yuv(buf->format)) { |
| __DRIimage *image; |
| |
| - image = droid_create_image_from_prime_fds_yuv(disp, buf, num_fds, fds); |
| + image = droid_create_image_from_prime_fds_yuv( |
| + disp, buf, priv, num_fds, fds); |
| /* |
| * HACK: https://issuetracker.google.com/32077885 |
| * There is no API available to properly query the IMPLEMENTATION_DEFINED |
| @@ -347,7 +350,7 @@ droid_create_image_from_prime_fds(_EGLDisplay *disp, |
| EGL_YUV_CHROMA_SITING_0_EXT, |
| EGL_YUV_CHROMA_SITING_0_EXT, |
| &error, |
| - NULL); |
| + priv); |
| } |
| |
| /* More recent CrOS gralloc has a perform op that fills out the struct below |
| @@ -373,7 +376,8 @@ struct cros_gralloc0_buffer_info { |
| |
| static __DRIimage * |
| droid_create_image_from_cros_info(_EGLDisplay *disp, |
| - struct ANativeWindowBuffer *buf) |
| + struct ANativeWindowBuffer *buf, |
| + void* priv) |
| { |
| struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| struct cros_gralloc0_buffer_info info; |
| @@ -396,7 +400,7 @@ droid_create_image_from_cros_info(_EGLDisplay *disp, |
| EGL_YUV_CHROMA_SITING_0_EXT, |
| EGL_YUV_CHROMA_SITING_0_EXT, |
| &error, |
| - NULL); |
| + priv); |
| } |
| |
| return NULL; |
| @@ -404,15 +408,16 @@ droid_create_image_from_cros_info(_EGLDisplay *disp, |
| |
| static __DRIimage * |
| droid_create_image_from_native_buffer(_EGLDisplay *disp, |
| - struct ANativeWindowBuffer *buf) |
| + struct ANativeWindowBuffer *buf, |
| + void *priv) |
| { |
| __DRIimage *dri_image; |
| |
| - dri_image = droid_create_image_from_cros_info(disp, buf); |
| + dri_image = droid_create_image_from_cros_info(disp, buf, priv); |
| if (dri_image) |
| return dri_image; |
| |
| - return droid_create_image_from_prime_fds(disp, buf); |
| + return droid_create_image_from_prime_fds(disp, buf, priv); |
| } |
| |
| static EGLBoolean |
| @@ -812,7 +817,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf) |
| } |
| |
| dri2_surf->dri_image_back = |
| - droid_create_image_from_native_buffer(disp, dri2_surf->buffer); |
| + droid_create_image_from_native_buffer(disp, dri2_surf->buffer, NULL); |
| if (!dri2_surf->dri_image_back) { |
| _eglLog(_EGL_WARNING, "failed to create DRI image from FD"); |
| return -1; |
| @@ -973,7 +978,8 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) |
| #ifdef HAVE_DRM_GRALLOC |
| static _EGLImage * |
| droid_create_image_from_name(_EGLDisplay *disp, |
| - struct ANativeWindowBuffer *buf) |
| + struct ANativeWindowBuffer *buf, |
| + void *priv) |
| { |
| struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); |
| __DRIimage *dri_image; |
| @@ -997,7 +1003,7 @@ droid_create_image_from_name(_EGLDisplay *disp, |
| format, |
| name, |
| buf->stride, |
| - dri2_img); |
| + priv); |
| } |
| #endif /* HAVE_DRM_GRALLOC */ |
| |
| @@ -1051,15 +1057,19 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp, |
| } |
| |
| __DRIimage *dri_image = |
| - droid_create_image_from_native_buffer(disp, buf); |
| + droid_create_image_from_native_buffer(disp, buf, buf); |
| |
| #ifdef HAVE_DRM_GRALLOC |
| if (dri_image == NULL) |
| - dri_image = droid_create_image_from_name(disp, buf); |
| + dri_image = droid_create_image_from_name(disp, buf, buf); |
| #endif |
| |
| - if (dri_image) |
| + if (dri_image) { |
| +#if ANDROID_API_LEVEL >= 26 |
| + AHardwareBuffer_acquire(ANativeWindowBuffer_getHardwareBuffer(buf)); |
| +#endif |
| return dri2_create_image_from_dri(disp, dri_image); |
| + } |
| |
| return NULL; |
| } |
| @@ -1173,6 +1183,17 @@ droid_get_capability(void *loaderPrivate, enum dri_loader_cap cap) |
| } |
| } |
| |
| +static void |
| +droid_destroy_loader_image_state(void *loaderPrivate) |
| +{ |
| +#if ANDROID_API_LEVEL >= 26 |
| + if (loaderPrivate) { |
| + AHardwareBuffer_release( |
| + ANativeWindowBuffer_getHardwareBuffer(loaderPrivate)); |
| + } |
| +#endif |
| +} |
| + |
| static EGLBoolean |
| droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp) |
| { |
| @@ -1277,12 +1298,13 @@ static const struct dri2_egl_display_vtbl droid_display_vtbl = { |
| |
| #ifdef HAVE_DRM_GRALLOC |
| static const __DRIdri2LoaderExtension droid_dri2_loader_extension = { |
| - .base = { __DRI_DRI2_LOADER, 4 }, |
| + .base = { __DRI_DRI2_LOADER, 5 }, |
| |
| - .getBuffers = NULL, |
| - .flushFrontBuffer = droid_flush_front_buffer, |
| - .getBuffersWithFormat = droid_get_buffers_with_format, |
| - .getCapability = droid_get_capability, |
| + .getBuffers = NULL, |
| + .flushFrontBuffer = droid_flush_front_buffer, |
| + .getBuffersWithFormat = droid_get_buffers_with_format, |
| + .getCapability = droid_get_capability, |
| + .destroyLoaderImageState = droid_destroy_loader_image_state, |
| }; |
| |
| static const __DRIextension *droid_dri2_loader_extensions[] = { |
| @@ -1297,11 +1319,13 @@ static const __DRIextension *droid_dri2_loader_extensions[] = { |
| #endif /* HAVE_DRM_GRALLOC */ |
| |
| static const __DRIimageLoaderExtension droid_image_loader_extension = { |
| - .base = { __DRI_IMAGE_LOADER, 2 }, |
| + .base = { __DRI_IMAGE_LOADER, 4 }, |
| |
| - .getBuffers = droid_image_get_buffers, |
| - .flushFrontBuffer = droid_flush_front_buffer, |
| - .getCapability = droid_get_capability, |
| + .getBuffers = droid_image_get_buffers, |
| + .flushFrontBuffer = droid_flush_front_buffer, |
| + .getCapability = droid_get_capability, |
| + .flushSwapBuffers = NULL, |
| + .destroyLoaderImageState = droid_destroy_loader_image_state, |
| }; |
| |
| static void |
| -- |
| 2.29.2.684.gfbc64c5ab5-goog |
| |