[Mesa-dev] [PATCH v4 3/9] egl: add dri2_surface_set_back_buffer() helper (v3)

Gwan-gyeong Mun elongbug at gmail.com
Thu Nov 2 22:10:48 UTC 2017


To share common record buffers and update back buffer code.
This records all the buffers created by each platform's native window and
update back buffer for updating buffer's age in swap_buffers.

In preparation to adding of new platform which uses this helper.

v2:
 - Remove unneeded ifdef magic
 - Fixes from Eric's review:
   a) Split out series of refactor for helpers to a separate series.
   b) Add the new helper function and use them to replace the old code in the
      same patch.

v3:
  - Fixes from Emil and Gurchetan's review:
    Follow the naming convention which prevents too verbose name of functions.
    a) use a dri2_surface_$action_$object naming convention
    b) change a first argument type "struct dri2_egl_surface" to "_EGLSurface".
  - Fixes from Emil's review:
    a) fix typo
    b) drop the addition of initialization of buffer age.

Signed-off-by: Mun Gwan-gyeong <elongbug at gmail.com>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c         | 31 +++++++++++++++++++++++++++++++
 src/egl/drivers/dri2/egl_dri2.h         |  3 +++
 src/egl/drivers/dri2/platform_android.c | 24 +-----------------------
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 238e299aed..2063d1ca56 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1092,6 +1092,37 @@ dri2_surface_fixup(_EGLSurface *surf, int width, int height)
    }
 }
 
+void
+dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer)
+{
+   /* Record all the buffers created by each platform's native window and
+    * update back buffer for updating buffer's age in swap_buffers.
+    */
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   EGLBoolean updated = EGL_FALSE;
+
+   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+      if (!dri2_surf->color_buffers[i].native_buffer) {
+         dri2_surf->color_buffers[i].native_buffer = buffer;
+      }
+      if (dri2_surf->color_buffers[i].native_buffer == buffer) {
+         dri2_surf->back = &dri2_surf->color_buffers[i];
+         updated = EGL_TRUE;
+         break;
+      }
+   }
+
+   if (!updated) {
+      /* In case of all the buffers were recreated, reset the color_buffers */
+      for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
+         dri2_surf->color_buffers[i].native_buffer = NULL;
+         dri2_surf->color_buffers[i].age = 0;
+      }
+      dri2_surf->color_buffers[0].native_buffer = buffer;
+      dri2_surf->back = &dri2_surf->color_buffers[0];
+   }
+}
+
 /**
  * Called via eglTerminate(), drv->API.Terminate().
  *
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 6a218b49aa..4c01959324 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -454,6 +454,9 @@ dri2_egl_surface_free_local_buffers(struct dri2_egl_surface *dri2_surf);
 void
 dri2_surface_fixup(_EGLSurface *surf, int width, int height);
 
+void
+dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer);
+
 EGLBoolean
 dri2_init_surface(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
         _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean enable_out_fence);
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index c254173690..559672ff21 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -191,29 +191,7 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
    /* Record all the buffers created by ANativeWindow and update back buffer
     * for updating buffer's age in swap_buffers.
     */
-   EGLBoolean updated = EGL_FALSE;
-   for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-      if (!dri2_surf->color_buffers[i].native_buffer) {
-         dri2_surf->color_buffers[i].native_buffer = dri2_surf->buffer;
-      }
-      if (dri2_surf->color_buffers[i].native_buffer == dri2_surf->buffer) {
-         dri2_surf->back = &dri2_surf->color_buffers[i];
-         updated = EGL_TRUE;
-         break;
-      }
-   }
-
-   if (!updated) {
-      /* In case of all the buffers were recreated by ANativeWindow, reset
-       * the color_buffers
-       */
-      for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
-         dri2_surf->color_buffers[i].native_buffer = NULL;
-         dri2_surf->color_buffers[i].age = 0;
-      }
-      dri2_surf->color_buffers[0].native_buffer = dri2_surf->buffer;
-      dri2_surf->back = &dri2_surf->color_buffers[0];
-   }
+   dri2_surface_set_back_buffer(&dri2_surf->base, dri2_surf->buffer);
 
    return EGL_TRUE;
 }
-- 
2.15.0



More information about the mesa-dev mailing list