[Mesa-dev] [PATCH v4 8/9] egl: add dri2_surface_get_front_image() helper (v4)

Gwan-gyeong Mun elongbug at gmail.com
Thu Nov 2 22:10:53 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".

v4:
  - Move dri_image_front to outside of android ifdef block for not to use of
    ifdef magic on dri2_surface_get_front_image().

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         |  6 +++++-
 src/egl/drivers/dri2/platform_android.c | 35 +--------------------------------
 3 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 13c86f87c2..c1a9392f68 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1153,6 +1153,39 @@ dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img)
    }
 }
 
+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 9cc04930c8..96c4a213df 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -303,11 +303,12 @@ struct dri2_egl_surface
       int                 age;
    } color_buffers[COLOR_BUFFERS_SIZE], *back, *current;
 
+   __DRIimage *dri_image_front;
+
 #ifdef HAVE_ANDROID_PLATFORM
    struct ANativeWindow *window;
    struct ANativeWindowBuffer *buffer;
    __DRIimage *dri_image_back;
-   __DRIimage *dri_image_front;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
@@ -463,6 +464,9 @@ dri2_surface_update_age(_EGLSurface *surf);
 void
 dri2_surface_free_image(_EGLSurface *surf, __DRIimage **img);
 
+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 74b034b18f..707195f03d 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.15.0



More information about the mesa-dev mailing list