[Mesa-dev] [PATCH v3 09/10] egl: add dri2_surface_get_front_image() helper (v3)

Gwan-gyeong Mun elongbug at gmail.com
Tue Oct 24 21:45:03 UTC 2017


To share common get and create dri_image_front code.

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

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         | 33 +++++++++++++++++++++++++++++++
 src/egl/drivers/dri2/egl_dri2.h         |  3 +++
 src/egl/drivers/dri2/platform_android.c | 35 +--------------------------------
 3 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index ed0fff199d..e4ecd4ec09 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1166,6 +1166,39 @@ dri2_surface_destroy_front_image(_EGLSurface *surf)
    }
 }
 
+int
+dri2_surface_get_front_image(_EGLSurface *surf, unsigned int format)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(surf->Resource.Display);
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+
+   if (dri2_surf->dri_image_front)
+      return 0;
+
+   if (surf->Type == EGL_WINDOW_BIT) {
+      /* According current EGL spec, front buffer rendering
+       * for window surface is not supported now.
+       * and mesa doesn't have the implementation of this case.
+       * Add warning message, but not treat it as error.
+       */
+      _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface");
+   } else if (surf->Type == EGL_PBUFFER_BIT) {
+      dri2_surf->dri_image_front =
+         dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+                                      surf->Width,
+                                      surf->Height,
+                                      format,
+                                      0,
+                                      dri2_surf);
+      if (!dri2_surf->dri_image_front) {
+         _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
+         return -1;
+      }
+   }
+
+   return 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 6415fb22e6..26d0ee986e 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -467,6 +467,9 @@ dri2_surface_destroy_back_image(_EGLSurface *surf);
 void
 dri2_surface_destroy_front_image(_EGLSurface *surf);
 
+int
+dri2_surface_get_front_image(_EGLSurface *surf, unsigned int format);
+
 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 0b84f7221d..3bb85ab4cd 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -386,39 +386,6 @@ update_buffers(struct dri2_egl_surface *dri2_surf)
    return 0;
 }
 
-static int
-get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)
-{
-   struct dri2_egl_display *dri2_dpy =
-      dri2_egl_display(dri2_surf->base.Resource.Display);
-
-   if (dri2_surf->dri_image_front)
-      return 0;
-
-   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
-      /* According current EGL spec, front buffer rendering
-       * for window surface is not supported now.
-       * and mesa doesn't have the implementation of this case.
-       * Add warning message, but not treat it as error.
-       */
-      _eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface");
-   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
-      dri2_surf->dri_image_front =
-          dri2_dpy->image->createImage(dri2_dpy->dri_screen,
-                                              dri2_surf->base.Width,
-                                              dri2_surf->base.Height,
-                                              format,
-                                              0,
-                                              dri2_surf);
-      if (!dri2_surf->dri_image_front) {
-         _eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
-         return -1;
-      }
-   }
-
-   return 0;
-}
-
 static int
 get_back_bo(struct dri2_egl_surface *dri2_surf)
 {
@@ -510,7 +477,7 @@ droid_image_get_buffers(__DRIdrawable *driDrawable,
       return 0;
 
    if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {
-      if (get_front_bo(dri2_surf, format) < 0)
+      if (dri2_surface_get_front_image(&dri2_surf->base, format) < 0)
          return 0;
 
       if (dri2_surf->dri_image_front) {
-- 
2.14.2



More information about the mesa-dev mailing list