<p dir="ltr">+Chad</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Nov 10, 2016 3:53 AM, "Liu Zhiquan" <<a href="mailto:zhiquan.liu@intel.com">zhiquan.liu@intel.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mesa android path didn't support pbuffer, so add pbuffer support to<br>
fix most deqp and cts pbuffer test cases fail;<br>
add support of front buffer and single buffer config.<br>
<br>
Test status: android CTS EGL pbuffer test can run without native crash.<br>
test:[DEQP,EGL]all deqp pbuffer case passed.<br>
<br>
Signed-off-by: Liu Zhiquan <<a href="mailto:zhiquan.liu@intel.com">zhiquan.liu@intel.com</a>><br>
---<br>
 src/egl/drivers/dri2/egl_dri2.<wbr>h         |   3 +-<br>
 src/egl/drivers/dri2/platform_<wbr>android.c | 169 +++++++++++++++++++++++-------<wbr>--<br>
 2 files changed, 124 insertions(+), 48 deletions(-)<br>
<br>
diff --git a/src/egl/drivers/dri2/egl_<wbr>dri2.h b/src/egl/drivers/dri2/egl_<wbr>dri2.h<br>
index 3add32e..f3d09dc 100644<br>
--- a/src/egl/drivers/dri2/egl_<wbr>dri2.h<br>
+++ b/src/egl/drivers/dri2/egl_<wbr>dri2.h<br>
@@ -290,7 +290,8 @@ struct dri2_egl_surface<br>
 #ifdef HAVE_ANDROID_PLATFORM<br>
    struct ANativeWindow *window;<br>
    struct ANativeWindowBuffer *buffer;<br>
-   __DRIimage *dri_image;<br>
+   __DRIimage *dri_image_back;<br>
+   __DRIimage *dri_image_front;<br>
<br>
    /* EGL-owned buffers */<br>
    __DRIbuffer           *local_buffers[__DRI_BUFFER_<wbr>COUNT];<br>
diff --git a/src/egl/drivers/dri2/<wbr>platform_android.c b/src/egl/drivers/dri2/<wbr>platform_android.c<br>
index ec52a02..79fe81a 100644<br>
--- a/src/egl/drivers/dri2/<wbr>platform_android.c<br>
+++ b/src/egl/drivers/dri2/<wbr>platform_android.c<br>
@@ -204,9 +204,9 @@ droid_window_enqueue_buffer(_<wbr>EGLDisplay *disp, struct dri2_egl_surface *dri2_sur<br>
<br>
    mtx_lock(&disp->Mutex);<br>
<br>
-   if (dri2_surf->dri_image) {<br>
-      dri2_dpy->image->destroyImage(<wbr>dri2_surf->dri_image);<br>
-      dri2_surf->dri_image = NULL;<br>
+   if (dri2_surf->dri_image_back) {<br>
+      dri2_dpy->image->destroyImage(<wbr>dri2_surf->dri_image_back);<br>
+      dri2_surf->dri_image_back = NULL;<br>
    }<br>
<br>
    return EGL_TRUE;<br>
@@ -295,7 +295,7 @@ droid_create_surface(_<wbr>EGLDriver *drv, _EGLDisplay *disp, EGLint type,<br>
       window->query(window, NATIVE_WINDOW_HEIGHT, &dri2_surf->base.Height);<br>
    }<br>
<br>
-   config = dri2_get_dri_config(dri2_conf, EGL_WINDOW_BIT,<br>
+   config = dri2_get_dri_config(dri2_conf, type,<br>
                                 dri2_surf->base.GLColorspace);<br>
    if (!config)<br>
       goto cleanup_surface;<br>
@@ -353,6 +353,18 @@ droid_destroy_surface(_<wbr>EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)<br>
       dri2_surf->window->common.<wbr>decRef(&dri2_surf->window-><wbr>common);<br>
    }<br>
<br>
+   if (dri2_surf->dri_image_back) {<br>
+       _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__);<br>
+      dri2_dpy->image->destroyImage(<wbr>dri2_surf->dri_image_back);<br>
+      dri2_surf->dri_image_back = NULL;<br>
+   }<br>
+<br>
+   if (dri2_surf->dri_image_front) {<br>
+       _eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__);<br>
+      dri2_dpy->image->destroyImage(<wbr>dri2_surf->dri_image_front);<br>
+      dri2_surf->dri_image_front = NULL;<br>
+   }<br>
+<br>
    (*dri2_dpy->core-><wbr>destroyDrawable)(dri2_surf-><wbr>dri_drawable);<br>
<br>
    free(dri2_surf);<br>
@@ -384,49 +396,114 @@ update_buffers(struct dri2_egl_surface *dri2_surf)<br>
 }<br>
<br>
 static int<br>
-get_back_bo(struct dri2_egl_surface *dri2_surf)<br>
+droid_get_front_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)<br>
 {<br>
    struct dri2_egl_display *dri2_dpy =<br>
       dri2_egl_display(dri2_surf-><wbr>base.Resource.Display);<br>
-   int fourcc, pitch;<br>
-   int offset = 0, fd;<br>
<br>
-   if (dri2_surf->dri_image)<br>
-          return 0;<br>
+   if (dri2_surf->dri_image_front) {<br>
+      _eglLog(_EGL_WARNING, "%s:%d dri2_image_front allocated !\n", __func__, __LINE__);<br>
+      return 0;<br>
+   }<br>
<br>
-   if (!dri2_surf->buffer)<br>
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {<br>
+       /* According current EGL spec,<br>
+        * front buffer rendering for window surface is not supported now */<br>
+       _eglLog(_EGL_WARNING, "%s:%d front buffer rendering for window surface is not supported!\n",<br>
+               __func__, __LINE__);<br>
+       return -1;<br>
+<br>
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {<br>
+       dri2_surf->dri_image_front =<br>
+          dri2_dpy->image->createImage(<wbr>dri2_dpy->dri_screen,<br>
+                                              dri2_surf->base.Width,<br>
+                                              dri2_surf->base.Height,<br>
+                                              format,<br>
+                                              0,<br>
+                                              dri2_surf);<br>
+<br>
+<br>
+   } else {<br>
+      _eglLog(_EGL_WARNING, "%s:%d pixmap is not supported now !\n", __func__, __LINE__);<br>
       return -1;<br>
+   }<br>
<br>
-   fd = get_native_buffer_fd(dri2_<wbr>surf->buffer);<br>
-   if (fd < 0) {<br>
-      _eglLog(_EGL_WARNING, "Could not get native buffer FD");<br>
+   if (!dri2_surf->dri_image_front) {<br>
+      _eglLog(_EGL_WARNING, "%s:%d dri2_image_front allocation failed !\n", __func__, __LINE__);<br>
       return -1;<br>
    }<br>
<br>
-   fourcc = get_fourcc(dri2_surf->buffer-><wbr>format);<br>
+   return 0;<br>
+}<br>
<br>
-   pitch = dri2_surf->buffer->stride *<br>
-      get_format_bpp(dri2_surf-><wbr>buffer->format);<br>
+static int<br>
+droid_get_back_bo(struct dri2_egl_surface *dri2_surf, unsigned int format)<br>
+{<br>
+   struct dri2_egl_display *dri2_dpy =<br>
+      dri2_egl_display(dri2_surf-><wbr>base.Resource.Display);<br>
+   int fourcc, pitch;<br>
+   int offset = 0, fd;<br>
<br>
-   if (fourcc == -1 || pitch == 0) {<br>
-      _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",<br>
-              fourcc, pitch);<br>
-      return -1;<br>
+   if (dri2_surf->dri_image_back) {<br>
+      _eglLog(_EGL_WARNING, "%s:%d dri_image_back allocated !\n", __func__, __LINE__);<br>
+      return 0;<br>
    }<br>
<br>
-   dri2_surf->dri_image =<br>
-      dri2_dpy->image-><wbr>createImageFromFds(dri2_dpy-><wbr>dri_screen,<br>
-                                          dri2_surf->base.Width,<br>
-                                          dri2_surf->base.Height,<br>
-                                          fourcc,<br>
-                                          &fd,<br>
-                                          1,<br>
-                                          &pitch,<br>
-                                          &offset,<br>
-                                          dri2_surf);<br>
-   if (!dri2_surf->dri_image)<br>
+   if (dri2_surf->base.Type == EGL_WINDOW_BIT) {<br>
+<br>
+      if (!dri2_surf->buffer) {<br>
+         _eglLog(_EGL_WARNING, "Could not get native buffer");<br>
+         return -1;<br>
+      }<br>
+<br>
+      fd = get_native_buffer_fd(dri2_<wbr>surf->buffer);<br>
+      if (fd < 0) {<br>
+         _eglLog(_EGL_WARNING, "Could not get native buffer FD");<br>
+         return -1;<br>
+      }<br>
+<br>
+      fourcc = get_fourcc(dri2_surf->buffer-><wbr>format);<br>
+<br>
+      pitch = dri2_surf->buffer->stride *<br>
+         get_format_bpp(dri2_surf-><wbr>buffer->format);<br>
+<br>
+      if (fourcc == -1 || pitch == 0) {<br>
+         _eglLog(_EGL_WARNING, "Invalid buffer fourcc(%x) or pitch(%d)",<br>
+                 fourcc, pitch);<br>
+         return -1;<br>
+      }<br>
+<br>
+      dri2_surf->dri_image_back =<br>
+         dri2_dpy->image-><wbr>createImageFromFds(dri2_dpy-><wbr>dri_screen,<br>
+                                             dri2_surf->base.Width,<br>
+                                             dri2_surf->base.Height,<br>
+                                             fourcc,<br>
+                                             &fd,<br>
+                                             1,<br>
+                                             &pitch,<br>
+                                             &offset,<br>
+                                             dri2_surf);<br>
+   } else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {<br>
+      /* Current implementation pass FRONT mask for pbuffer, as it is single buffer config.<br>
+       * But according to EGL spec,  pbuffer is back buffer, add below code for logic<br>
+       * completeness.<br>
+       */<br>
+      dri2_surf->dri_image_back =<br>
+         dri2_dpy->image->createImage(<wbr>dri2_dpy->dri_screen,<br>
+                                             dri2_surf->base.Width,<br>
+                                             dri2_surf->base.Height,<br>
+                                             format,<br>
+                                             0,<br>
+                                             dri2_surf);<br>
+   } else {<br>
+      _eglLog(_EGL_WARNING, "%s:%d pixmap is not supported now !\n", __func__, __LINE__);<br>
       return -1;<br>
+   }<br>
<br>
+   if (!dri2_surf->dri_image_back) {<br>
+      _eglLog(_EGL_WARNING, "%s:%d dri2_image allocation failed !\n", __func__, __LINE__);<br>
+      return -1;<br>
+   }<br>
    return 0;<br>
 }<br>
<br>
@@ -441,23 +518,29 @@ droid_image_get_buffers(__<wbr>DRIdrawable *driDrawable,<br>
    struct dri2_egl_surface *dri2_surf = loaderPrivate;<br>
<br>
    images->image_mask = 0;<br>
+   images->front = NULL;<br>
+   images->back = NULL;<br>
<br>
-   if (update_buffers(dri2_surf) < 0)<br>
+     if (update_buffers(dri2_surf) < 0)<br>
       return 0;<br>
<br>
    if (buffer_mask & __DRI_IMAGE_BUFFER_FRONT) {<br>
-      /*<br>
-       * We don't support front buffers and GLES doesn't require them for<br>
-       * window surfaces, but some DRI drivers will request them anyway.<br>
-       * We just ignore such request as other platforms backends do.<br>
-       */<br>
+      if (droid_get_front_bo(dri2_surf, format) < 0) {<br>
+         _eglError(EGL_BAD_PARAMETER, "droid_get_front_bo");<br>
+         return 0;<br>
+      }<br>
+<br>
+      images->front = dri2_surf->dri_image_front;<br>
+      images->image_mask |= __DRI_IMAGE_BUFFER_FRONT;<br>
    }<br>
<br>
    if (buffer_mask & __DRI_IMAGE_BUFFER_BACK) {<br>
-      if (get_back_bo(dri2_surf) < 0)<br>
+      if (droid_get_back_bo(dri2_surf, format) < 0) {<br>
+         _eglError(EGL_BAD_PARAMETER, "droid_get_back_bo");<br>
          return 0;<br>
+      }<br>
<br>
-      images->back = dri2_surf->dri_image;<br>
+      images->back = dri2_surf->dri_image_back;<br>
       images->image_mask |= __DRI_IMAGE_BUFFER_BACK;<br>
    }<br>
<br>
@@ -775,14 +858,6 @@ droid_add_configs_for_visuals(<wbr>_EGLDriver *drv, _EGLDisplay *dpy)<br>
    for (i = 0; dri2_dpy->driver_configs[i]; i++) {<br>
       const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;<br>
       struct dri2_egl_config *dri2_conf;<br>
-      unsigned int double_buffered = 0;<br>
-<br>
-      dri2_dpy->core-><wbr>getConfigAttrib(dri2_dpy-><wbr>driver_configs[i],<br>
-         __DRI_ATTRIB_DOUBLE_BUFFER, &double_buffered);<br>
-<br>
-      /* support only double buffered configs */<br>
-      if (!double_buffered)<br>
-         continue;<br>
<br>
       for (j = 0; j < ARRAY_SIZE(visuals); j++) {<br>
          config_attrs[1] = visuals[j].format;<br>
--<br>
1.9.1<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div>