Module: Mesa
Branch: dri2-swapbuffers
Commit: e8f275fbae9c57c2ff4cd9ae9f0e773bed9c8b95
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e8f275fbae9c57c2ff4cd9ae9f0e773bed9c8b95

Author: Jesse Barnes <[email protected]>
Date:   Fri May  1 14:37:33 2009 -0700

intel: add support for DRI2 swapbuffers

Add support for the new swapbuffers interface by factoring out the
renderbuffer update code and reporting buffer exchange in the visual.

---

 src/mesa/drivers/dri/intel/intel_context.c    |  177 ++++++++++++++----------
 src/mesa/drivers/dri/intel/intel_extensions.h |    3 +
 src/mesa/drivers/dri/intel/intel_screen.c     |   20 ++-
 src/mesa/drivers/dri/intel/intel_screen.h     |    3 +
 4 files changed, 121 insertions(+), 82 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_context.c 
b/src/mesa/drivers/dri/intel/intel_context.c
index a6d8729..e6057ec 100644
--- a/src/mesa/drivers/dri/intel/intel_context.c
+++ b/src/mesa/drivers/dri/intel/intel_context.c
@@ -191,85 +191,20 @@ intel_bits_per_pixel(const struct intel_renderbuffer *rb)
    }
 }
 
-void
-intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
+/*
+ * DRI may give us with a new set of buffers after a flip or swap, so
+ * update the attachments here.
+ */
+static void intel_set_buffers(__DRIcontext *driContext, __DRIdrawable 
*drawable,
+                             __DRIbuffer *buffers, int count)
 {
    struct intel_framebuffer *intel_fb = drawable->driverPrivate;
    struct intel_renderbuffer *rb;
    struct intel_region *region, *depth_region;
-   struct intel_context *intel = context->driverPrivate;
-   __DRIbuffer *buffers = NULL;
-   __DRIscreen *screen;
-   int i, count;
-   unsigned int attachments[10];
-   uint32_t name;
+   struct intel_context *intel = driContext->driverPrivate;
    const char *region_name;
-
-   if (INTEL_DEBUG & DEBUG_DRI)
-      fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
-
-   screen = intel->intelScreen->driScrnPriv;
-
-   if (screen->dri2.loader
-       && (screen->dri2.loader->base.version > 2)
-       && (screen->dri2.loader->getBuffersWithFormat != NULL)) {
-      struct intel_renderbuffer *depth_rb;
-      struct intel_renderbuffer *stencil_rb;
-
-      i = 0;
-      if ((intel->is_front_buffer_rendering || !intel_fb->color_rb[1])
-          && intel_fb->color_rb[0]) {
-        attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
-        attachments[i++] = intel_bits_per_pixel(intel_fb->color_rb[0]);
-      }
-
-      if (intel_fb->color_rb[1]) {
-        attachments[i++] = __DRI_BUFFER_BACK_LEFT;
-        attachments[i++] = intel_bits_per_pixel(intel_fb->color_rb[1]);
-      }
-
-      depth_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
-      stencil_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
-
-      if ((depth_rb != NULL) && (stencil_rb != NULL)) {
-        attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL;
-        attachments[i++] = intel_bits_per_pixel(depth_rb);
-      } else if (depth_rb != NULL) {
-        attachments[i++] = __DRI_BUFFER_DEPTH;
-        attachments[i++] = intel_bits_per_pixel(depth_rb);
-      } else if (stencil_rb != NULL) {
-        attachments[i++] = __DRI_BUFFER_STENCIL;
-        attachments[i++] = intel_bits_per_pixel(stencil_rb);
-      }
-
-      buffers =
-        (*screen->dri2.loader->getBuffersWithFormat)(drawable,
-                                                     &drawable->w,
-                                                     &drawable->h,
-                                                     attachments, i / 2,
-                                                     &count,
-                                                     drawable->loaderPrivate);
-   } else if (screen->dri2.loader) {
-      i = 0;
-      if (intel_fb->color_rb[0])
-        attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
-      if (intel_fb->color_rb[1])
-        attachments[i++] = __DRI_BUFFER_BACK_LEFT;
-      if (intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH))
-        attachments[i++] = __DRI_BUFFER_DEPTH;
-      if (intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL))
-        attachments[i++] = __DRI_BUFFER_STENCIL;
-
-      buffers = (*screen->dri2.loader->getBuffers)(drawable,
-                                                  &drawable->w,
-                                                  &drawable->h,
-                                                  attachments, i,
-                                                  &count,
-                                                  drawable->loaderPrivate);
-   }
-
-   if (buffers == NULL)
-      return;
+   uint32_t name;
+   int i;
 
    drawable->x = 0;
    drawable->y = 0;
@@ -382,6 +317,90 @@ intel_update_renderbuffers(__DRIcontext *context, 
__DRIdrawable *drawable)
    driUpdateFramebufferSize(&intel->ctx, drawable);
 }
 
+void intelSetBuffers(__DRIdrawable *drawable, __DRIbuffer *buffers, int count)
+{
+   return intel_set_buffers(drawable->driContextPriv, drawable, buffers, 
count);
+}
+
+void
+intel_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
+{
+   struct intel_framebuffer *intel_fb = drawable->driverPrivate;
+   struct intel_context *intel = context->driverPrivate;
+   __DRIbuffer *buffers = NULL;
+   __DRIscreen *screen;
+   int i, count;
+   unsigned int attachments[10];
+
+   if (INTEL_DEBUG & DEBUG_DRI)
+      fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
+
+   screen = intel->intelScreen->driScrnPriv;
+
+   if (screen->dri2.loader
+       && (screen->dri2.loader->base.version > 2)
+       && (screen->dri2.loader->getBuffersWithFormat != NULL)) {
+      struct intel_renderbuffer *depth_rb;
+      struct intel_renderbuffer *stencil_rb;
+
+      i = 0;
+      if ((intel->is_front_buffer_rendering || !intel_fb->color_rb[1])
+          && intel_fb->color_rb[0]) {
+        attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
+        attachments[i++] = intel_bits_per_pixel(intel_fb->color_rb[0]);
+      }
+
+      if (intel_fb->color_rb[1]) {
+        attachments[i++] = __DRI_BUFFER_BACK_LEFT;
+        attachments[i++] = intel_bits_per_pixel(intel_fb->color_rb[1]);
+      }
+
+      depth_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH);
+      stencil_rb = intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL);
+
+      if ((depth_rb != NULL) && (stencil_rb != NULL)) {
+        attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL;
+        attachments[i++] = intel_bits_per_pixel(depth_rb);
+      } else if (depth_rb != NULL) {
+        attachments[i++] = __DRI_BUFFER_DEPTH;
+        attachments[i++] = intel_bits_per_pixel(depth_rb);
+      } else if (stencil_rb != NULL) {
+        attachments[i++] = __DRI_BUFFER_STENCIL;
+        attachments[i++] = intel_bits_per_pixel(stencil_rb);
+      }
+
+      buffers =
+        (*screen->dri2.loader->getBuffersWithFormat)(drawable,
+                                                     &drawable->w,
+                                                     &drawable->h,
+                                                     attachments, i / 2,
+                                                     &count,
+                                                     drawable->loaderPrivate);
+   } else if (screen->dri2.loader) {
+      i = 0;
+      if (intel_fb->color_rb[0])
+        attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
+      if (intel_fb->color_rb[1])
+        attachments[i++] = __DRI_BUFFER_BACK_LEFT;
+      if (intel_get_renderbuffer(&intel_fb->Base, BUFFER_DEPTH))
+        attachments[i++] = __DRI_BUFFER_DEPTH;
+      if (intel_get_renderbuffer(&intel_fb->Base, BUFFER_STENCIL))
+        attachments[i++] = __DRI_BUFFER_STENCIL;
+
+      buffers = (*screen->dri2.loader->getBuffers)(drawable,
+                                                  &drawable->w,
+                                                  &drawable->h,
+                                                  attachments, i,
+                                                  &count,
+                                                  drawable->loaderPrivate);
+   }
+
+   if (buffers == NULL)
+      return;
+
+   intel_set_buffers(context, drawable, buffers, count);
+}
+
 void
 intel_viewport(GLcontext *ctx, GLint x, GLint y, GLsizei w, GLsizei h)
 {
@@ -512,6 +531,16 @@ intel_glFlush(GLcontext *ctx)
    intel_flush(ctx, GL_TRUE);
 }
 
+void intelFlushDrawable(__DRIdrawable *drawable)
+{
+    __DRIdrawablePrivate * dPriv = drawable->driverPrivate;
+    struct intel_context *intel =
+       (struct intel_context *) dPriv->driContextPriv->driverPrivate;
+    GLcontext *ctx = &intel->ctx;
+
+    intel_flush(ctx, GL_TRUE);
+}
+
 void
 intelFinish(GLcontext * ctx)
 {
diff --git a/src/mesa/drivers/dri/intel/intel_extensions.h 
b/src/mesa/drivers/dri/intel/intel_extensions.h
index 97147ec..9283ee9 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.h
+++ b/src/mesa/drivers/dri/intel/intel_extensions.h
@@ -32,5 +32,8 @@
 extern void
 intelInitExtensions(GLcontext *ctx, GLboolean enable_imaging);
 
+extern void
+intelFlushDrawable(__DRIdrawable *drawable);
+
 
 #endif
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c 
b/src/mesa/drivers/dri/intel/intel_screen.c
index 65e6294..9982cff 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -214,6 +214,11 @@ static const __DRItexBufferExtension 
intelTexBufferExtension = {
    intelSetTexBuffer2,
 };
 
+static const __DRI2flushExtension intelFlushExtension = {
+    { __DRI2_FLUSH, __DRI2_FLUSH_VERSION },
+    intelFlushDrawable,
+};
+
 static const __DRIextension *intelScreenExtensions[] = {
     &driReadDrawableExtension,
     &driCopySubBufferExtension.base,
@@ -478,11 +483,9 @@ intelFillInModes(__DRIscreenPrivate *psp,
    unsigned back_buffer_factor;
    int i;
 
-   /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
-    * support pageflipping at all.
-    */
    static const GLenum back_buffer_modes[] = {
-      GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
+       GLX_NONE, GLX_SWAP_UNDEFINED_OML,
+       GLX_SWAP_EXCHANGE_OML, GLX_SWAP_COPY_OML
    };
 
    uint8_t depth_bits_array[3];
@@ -703,11 +706,10 @@ __DRIconfig **intelInitScreen2(__DRIscreenPrivate *psp)
    intelScreenPrivate *intelScreen;
    GLenum fb_format[3];
    GLenum fb_type[3];
-   /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
-    * support pageflipping at all.
-    */
+
    static const GLenum back_buffer_modes[] = {
-      GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
+       GLX_NONE, GLX_SWAP_UNDEFINED_OML,
+       GLX_SWAP_EXCHANGE_OML, GLX_SWAP_COPY_OML
    };
    uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
    int color;
@@ -834,4 +836,6 @@ const struct __DriverAPIRec driDriverAPI = {
    .CopySubBuffer       = intelCopySubBuffer,
 
    .InitScreen2                 = intelInitScreen2,
+
+   .SetBuffers          = intelSetBuffers,
 };
diff --git a/src/mesa/drivers/dri/intel/intel_screen.h 
b/src/mesa/drivers/dri/intel/intel_screen.h
index a9b9e10..6bdb05e 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.h
+++ b/src/mesa/drivers/dri/intel/intel_screen.h
@@ -104,4 +104,7 @@ intelMakeCurrent(__DRIcontextPrivate * driContextPriv,
 
 extern struct intel_context *intelScreenContext(intelScreenPrivate 
*intelScreen);
 
+extern void intelSetBuffers(__DRIdrawable *drawable, __DRIbuffer *buffers,
+                           int count);
+
 #endif

_______________________________________________
mesa-commit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to