Mesa (master): egl_dri2: refactor droid_get_buffers_with_format

Chia-I Wu olv at kemper.freedesktop.org
Tue Aug 30 21:09:23 PDT 2011


Module: Mesa
Branch: master
Commit: 384f228a2573ce592854f58c45564f75419fe987
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=384f228a2573ce592854f58c45564f75419fe987

Author: Chia-I Wu <olv at lunarg.com>
Date:   Fri Aug 26 23:49:04 2011 +0800

egl_dri2: refactor droid_get_buffers_with_format

Move the loop to parse attachments to its own function.

Reviewed-by: Chad Versace <chad at chad-versace.us>

---

 src/egl/drivers/dri2/platform_android.c |   66 ++++++++++++++++++-------------
 1 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 284dc3a..2bbd210 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -369,36 +369,18 @@ droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
 {
 }
 
-static __DRIbuffer *
-droid_get_buffers_with_format(__DRIdrawable * driDrawable,
-			     int *width, int *height,
-			     unsigned int *attachments, int count,
-			     int *out_count, void *loaderPrivate)
+static int
+droid_get_buffers_parse_attachments(struct dri2_egl_surface *dri2_surf,
+                                    unsigned int *attachments, int count)
 {
-   struct dri2_egl_surface *dri2_surf = loaderPrivate;
-   struct dri2_egl_display *dri2_dpy =
-      dri2_egl_display(dri2_surf->base.Resource.Display);
-   int i;
+   int num_buffers = 0, i;
 
-   if (!dri2_surf->buffer) {
-      if (!droid_window_dequeue_buffer(dri2_surf))
-         return NULL;
-   }
-
-   /* free outdated buffers and update the surface size */
-   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
-       dri2_surf->base.Height != dri2_surf->buffer->height) {
-      droid_free_local_buffers(dri2_surf);
-      dri2_surf->base.Width = dri2_surf->buffer->width;
-      dri2_surf->base.Height = dri2_surf->buffer->height;
-   }
-
-   dri2_surf->buffer_count = 0;
+   /* fill dri2_surf->buffers */
    for (i = 0; i < count * 2; i += 2) {
       __DRIbuffer *buf, *local;
 
-      assert(dri2_surf->buffer_count < ARRAY_SIZE(dri2_surf->buffers));
-      buf = &dri2_surf->buffers[dri2_surf->buffer_count];
+      assert(num_buffers < ARRAY_SIZE(dri2_surf->buffers));
+      buf = &dri2_surf->buffers[num_buffers];
 
       switch (attachments[i]) {
       case __DRI_BUFFER_BACK_LEFT:
@@ -409,7 +391,7 @@ droid_get_buffers_with_format(__DRIdrawable * driDrawable,
          buf->flags = 0;
 
          if (buf->name)
-            dri2_surf->buffer_count++;
+            num_buffers++;
          break;
       case __DRI_BUFFER_DEPTH:
       case __DRI_BUFFER_STENCIL:
@@ -421,7 +403,7 @@ droid_get_buffers_with_format(__DRIdrawable * driDrawable,
 
          if (local) {
             *buf = *local;
-            dri2_surf->buffer_count++;
+            num_buffers++;
          }
          break;
       case __DRI_BUFFER_FRONT_LEFT:
@@ -435,6 +417,36 @@ droid_get_buffers_with_format(__DRIdrawable * driDrawable,
       }
    }
 
+   return num_buffers;
+}
+
+static __DRIbuffer *
+droid_get_buffers_with_format(__DRIdrawable * driDrawable,
+			     int *width, int *height,
+			     unsigned int *attachments, int count,
+			     int *out_count, void *loaderPrivate)
+{
+   struct dri2_egl_surface *dri2_surf = loaderPrivate;
+   struct dri2_egl_display *dri2_dpy =
+      dri2_egl_display(dri2_surf->base.Resource.Display);
+   int i;
+
+   if (!dri2_surf->buffer) {
+      if (!droid_window_dequeue_buffer(dri2_surf))
+         return NULL;
+   }
+
+   /* free outdated buffers and update the surface size */
+   if (dri2_surf->base.Width != dri2_surf->buffer->width ||
+       dri2_surf->base.Height != dri2_surf->buffer->height) {
+      droid_free_local_buffers(dri2_surf);
+      dri2_surf->base.Width = dri2_surf->buffer->width;
+      dri2_surf->base.Height = dri2_surf->buffer->height;
+   }
+
+   dri2_surf->buffer_count =
+      droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
+
    if (width)
       *width = dri2_surf->base.Width;
    if (height)



More information about the mesa-commit mailing list