[Mesa-dev] [PATCH 2/3] egl/android; Use ANativeWindow::cancelBuffer in destroySurface

Tomasz Figa tfiga at chromium.org
Wed Apr 19 07:00:10 UTC 2017


When destroying a surface, we might have a buffer dequeued (and possibly used
for rendering) that was not posted on the screen by swapBuffers. We cannot
simply queue the buffer as usual, because it might (and actually it does)
confuse the consumer, who has not requested a swap. For this purpose,
ANativeWindow has a method called cancelBuffer, which we should use instead.

Signed-off-by: Tomasz Figa <tfiga at chromium.org>
---
 src/egl/drivers/dri2/platform_android.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 14f0dd0310..9a84a4c43d 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -258,7 +258,8 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
 }
 
 static EGLBoolean
-droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
+droid_window_enqueue_buffer(_EGLDisplay *disp,
+                            struct dri2_egl_surface *dri2_surf, bool cancel)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
 
@@ -281,8 +282,12 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_sur
     *    is responsible for closing it.
     */
    int fence_fd = -1;
-   dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
-                                  fence_fd);
+   if (cancel)
+      dri2_surf->window->cancelBuffer(dri2_surf->window, dri2_surf->buffer,
+                                      fence_fd);
+   else
+      dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
+                                     fence_fd);
 
    dri2_surf->buffer->common.decRef(&dri2_surf->buffer->common);
    dri2_surf->buffer = NULL;
@@ -298,13 +303,6 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_sur
    return EGL_TRUE;
 }
 
-static void
-droid_window_cancel_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
-{
-   /* no cancel buffer? */
-   droid_window_enqueue_buffer(disp, dri2_surf);
-}
-
 static _EGLSurface *
 droid_create_surface(_EGLDriver *drv, _EGLDisplay *disp, EGLint type,
 		    _EGLConfig *conf, void *native_window,
@@ -399,7 +397,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
 
    if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
       if (dri2_surf->buffer)
-         droid_window_cancel_buffer(disp, dri2_surf);
+         droid_window_enqueue_buffer(disp, dri2_surf, true);
 
       dri2_surf->window->common.decRef(&dri2_surf->window->common);
    }
@@ -632,7 +630,7 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
    dri2_flush_drawable_for_swapbuffers(disp, draw);
 
    if (dri2_surf->buffer)
-      droid_window_enqueue_buffer(disp, dri2_surf);
+      droid_window_enqueue_buffer(disp, dri2_surf, false);
 
    dri2_dpy->flush->invalidate(dri2_surf->dri_drawable);
 
-- 
2.12.2.816.g2cccc81164-goog



More information about the mesa-dev mailing list