[Mesa-dev] [PATCH v5 7/9] egl: add dri2_surface_free_image() helper (v4)

Gwan-gyeong Mun elongbug at gmail.com
Fri Nov 3 12:41:19 UTC 2017


To share common free DRIimage code.

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

v2:
 - 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".

v4: Fixes from Gurchetan's review
  - add dri2_surface_free_image() helper for refactoring of almost identical
    functions. [1]

[1] https://lists.freedesktop.org/archives/mesa-dev/2017-October/173219.html

Signed-off-by: Mun Gwan-gyeong <elongbug at gmail.com>
---
 src/egl/drivers/dri2/egl_dri2.c             | 11 +++++++++++
 src/egl/drivers/dri2/egl_dri2.h             |  3 +++
 src/egl/drivers/dri2/platform_android.c     | 18 +++---------------
 src/egl/drivers/dri2/platform_surfaceless.c | 14 +-------------
 src/egl/drivers/dri2/platform_wayland.c     | 26 ++++++++++++--------------
 5 files changed, 30 insertions(+), 42 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index d381e52e86..13c86f87c2 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1142,6 +1142,17 @@ dri2_surface_update_age(_EGLSurface *surf)
       dri2_surf->back->age = 1;
 }
 
+void
+dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(surf->Resource.Display);
+
+   if (*img) {
+      dri2_dpy->image->destroyImage(*img);
+      *img = NULL;
+   }
+}
+
 /**
  * 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 58f8082509..9cc04930c8 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -460,6 +460,9 @@ dri2_surface_set_back_buffer(_EGLSurface *surf, void *buffer);
 void
 dri2_surface_update_age(_EGLSurface *surf);
 
+void
+dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img);
+
 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 45af871555..dc20bea319 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -228,10 +228,7 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_sur
 
    mtx_lock(&disp->Mutex);
 
-   if (dri2_surf->dri_image_back) {
-      dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-      dri2_surf->dri_image_back = NULL;
-   }
+   dri2_surface_free_image(&dri2_surf->base, &dri2_surf->dri_image_back);
 
    return EGL_TRUE;
 }
@@ -355,17 +352,8 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
       dri2_surf->window->common.decRef(&dri2_surf->window->common);
    }
 
-   if (dri2_surf->dri_image_back) {
-      _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__);
-      dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
-      dri2_surf->dri_image_back = NULL;
-   }
-
-   if (dri2_surf->dri_image_front) {
-      _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__);
-      dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
-      dri2_surf->dri_image_front = NULL;
-   }
+   dri2_surface_free_image(surf, &dri2_surf->dri_image_back);
+   dri2_surface_free_image(surf, &dri2_surf->dri_image_front);
 
    dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c
index 977b046016..959d587c88 100644
--- a/src/egl/drivers/dri2/platform_surfaceless.c
+++ b/src/egl/drivers/dri2/platform_surfaceless.c
@@ -50,18 +50,6 @@ surfaceless_alloc_image(struct dri2_egl_display *dri2_dpy,
             NULL);
 }
 
-static void
-surfaceless_free_images(struct dri2_egl_surface *dri2_surf)
-{
-   struct dri2_egl_display *dri2_dpy =
-      dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->front) {
-      dri2_dpy->image->destroyImage(dri2_surf->front);
-      dri2_surf->front = NULL;
-   }
-}
-
 static int
 surfaceless_image_get_buffers(__DRIdrawable *driDrawable,
                         unsigned int format,
@@ -161,7 +149,7 @@ surfaceless_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *sur
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
 
-   surfaceless_free_images(dri2_surf);
+   dri2_surface_free_image(&dri2_surf->base, &dri2_surf->front);
 
    dri2_dpy->core->destroyDrawable(dri2_surf->dri_drawable);
 
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 21037b4547..d864355eb4 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -268,10 +268,10 @@ dri2_wl_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
    for (int i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
       if (dri2_surf->color_buffers[i].native_buffer)
          wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
-      if (dri2_surf->color_buffers[i].dri_image)
-         dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
-      if (dri2_surf->color_buffers[i].linear_copy)
-         dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
+      dri2_surface_free_image(&dri2_surf->base,
+                              &dri2_surf->color_buffers[i].dri_image);
+      dri2_surface_free_image(&dri2_surf->base,
+                              &dri2_surf->color_buffers[i].linear_copy);
       if (dri2_surf->color_buffers[i].data)
          munmap(dri2_surf->color_buffers[i].data,
                 dri2_surf->color_buffers[i].data_size);
@@ -311,17 +311,15 @@ dri2_wl_release_buffers(struct dri2_egl_surface *dri2_surf)
       if (dri2_surf->color_buffers[i].native_buffer &&
           !dri2_surf->color_buffers[i].locked)
          wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
-      if (dri2_surf->color_buffers[i].dri_image)
-         dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
-      if (dri2_surf->color_buffers[i].linear_copy)
-         dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
+      dri2_surface_free_image(&dri2_surf->base,
+                              &dri2_surf->color_buffers[i].dri_image);
+      dri2_surface_free_image(&dri2_surf->base,
+                              &dri2_surf->color_buffers[i].linear_copy);
       if (dri2_surf->color_buffers[i].data)
          munmap(dri2_surf->color_buffers[i].data,
                 dri2_surf->color_buffers[i].data_size);
 
       dri2_surf->color_buffers[i].native_buffer = NULL;
-      dri2_surf->color_buffers[i].dri_image = NULL;
-      dri2_surf->color_buffers[i].linear_copy = NULL;
       dri2_surf->color_buffers[i].data = NULL;
       dri2_surf->color_buffers[i].locked = false;
    }
@@ -515,12 +513,12 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
       if (!dri2_surf->color_buffers[i].locked &&
           dri2_surf->color_buffers[i].native_buffer) {
          wl_buffer_destroy(dri2_surf->color_buffers[i].native_buffer);
-         dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].dri_image);
+         dri2_surface_free_image(&dri2_surf->base,
+                                 &dri2_surf->color_buffers[i].dri_image);
          if (dri2_dpy->is_different_gpu)
-            dri2_dpy->image->destroyImage(dri2_surf->color_buffers[i].linear_copy);
+            dri2_surface_free_image(&dri2_surf->base,
+                                    &dri2_surf->color_buffers[i].linear_copy);
          dri2_surf->color_buffers[i].native_buffer = NULL;
-         dri2_surf->color_buffers[i].dri_image = NULL;
-         dri2_surf->color_buffers[i].linear_copy = NULL;
       }
    }
 
-- 
2.15.0



More information about the mesa-dev mailing list