st/egl: Add native_surface::present callback.
authorChia-I Wu <olv@lunarg.com>
Wed, 3 Nov 2010 07:22:36 +0000 (15:22 +0800)
committerChia-I Wu <olv@lunarg.com>
Wed, 3 Nov 2010 08:04:59 +0000 (16:04 +0800)
The callback presents the given attachment to the native engine.  It
allows the swap behavior and interval to be controlled.  It will replace
native_surface::flush_frontbuffer and native_surface::swap_buffers
shortly.

src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/drm/modeset.c
src/gallium/state_trackers/egl/drm/native_drm.c
src/gallium/state_trackers/egl/fbdev/native_fbdev.c
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_ximage.c

index 3c3f57e2670e3124f30f3f1ca8d6a063c022cdb4..446c6b45a926b287dd737b26e5fabfcc50865026 100644 (file)
@@ -54,7 +54,17 @@ enum native_param_type {
     * Return TRUE if window/pixmap surfaces use the buffers of the native
     * types.
     */
-   NATIVE_PARAM_USE_NATIVE_BUFFER
+   NATIVE_PARAM_USE_NATIVE_BUFFER,
+
+   /**
+    * Return TRUE if native_surface::present can preserve the buffer.
+    */
+   NATIVE_PARAM_PRESERVE_BUFFER,
+
+   /**
+    * Return the maximum supported swap interval.
+    */
+   NATIVE_PARAM_MAX_SWAP_INTERVAL
 };
 
 struct native_surface {
@@ -78,6 +88,14 @@ struct native_surface {
     */
    boolean (*flush_frontbuffer)(struct native_surface *nsurf);
 
+   /**
+    * Present the given buffer to the native engine.
+    */
+   boolean (*present)(struct native_surface *nsurf,
+                      enum native_attachment natt,
+                      boolean preserve,
+                      uint swap_interval);
+
    /**
     * Validate the buffers of the surface.  textures, if not NULL, points to an
     * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
index 5ed22f7b9d45864dec0e52d2d4dd6bce59c70fb8..453730ffa5ce93d327f9e15acb3e16f1fdd0d653 100644 (file)
@@ -167,6 +167,32 @@ drm_surface_swap_buffers(struct native_surface *nsurf)
    return TRUE;
 }
 
+static boolean
+drm_surface_present(struct native_surface *nsurf,
+                    enum native_attachment natt,
+                    boolean preserve,
+                    uint swap_interval)
+{
+   boolean ret;
+
+   if (preserve || swap_interval)
+      return FALSE;
+
+   switch (natt) {
+   case NATIVE_ATTACHMENT_FRONT_LEFT:
+      ret = drm_surface_flush_frontbuffer(nsurf);
+      break;
+   case NATIVE_ATTACHMENT_BACK_LEFT:
+      ret = drm_surface_swap_buffers(nsurf);
+      break;
+   default:
+      ret = FALSE;
+      break;
+   }
+
+   return ret;
+}
+
 static void
 drm_surface_wait(struct native_surface *nsurf)
 {
@@ -227,6 +253,7 @@ drm_display_create_surface(struct native_display *ndpy,
    drmsurf->base.destroy = drm_surface_destroy;
    drmsurf->base.swap_buffers = drm_surface_swap_buffers;
    drmsurf->base.flush_frontbuffer = drm_surface_flush_frontbuffer;
+   drmsurf->base.present = drm_surface_present;
    drmsurf->base.validate = drm_surface_validate;
    drmsurf->base.wait = drm_surface_wait;
 
index f6dc55843703dda26a8057b9d8f589357135ecea..21555dcd0ed262f0bdbe94a9cfd964ef2027311d 100644 (file)
@@ -103,6 +103,9 @@ drm_display_get_param(struct native_display *ndpy,
    int val;
 
    switch (param) {
+   case NATIVE_PARAM_USE_NATIVE_BUFFER:
+   case NATIVE_PARAM_PRESERVE_BUFFER:
+   case NATIVE_PARAM_MAX_SWAP_INTERVAL:
    default:
       val = 0;
       break;
index e459402076db66d790a5202aaf08b98588f9ba0a..728dba3ff49f9ca8b864aca559dca5befbf509b2 100644 (file)
@@ -137,6 +137,32 @@ fbdev_surface_swap_buffers(struct native_surface *nsurf)
    return ret;
 }
 
+static boolean
+fbdev_surface_present(struct native_surface *nsurf,
+                      enum native_attachment natt,
+                      boolean preserve,
+                      uint swap_interval)
+{
+   boolean ret;
+
+   if (preserve || swap_interval)
+      return FALSE;
+
+   switch (natt) {
+   case NATIVE_ATTACHMENT_FRONT_LEFT:
+      ret = fbdev_surface_flush_frontbuffer(nsurf);
+      break;
+   case NATIVE_ATTACHMENT_BACK_LEFT:
+      ret = fbdev_surface_swap_buffers(nsurf);
+      break;
+   default:
+      ret = FALSE;
+      break;
+   }
+
+   return ret;
+}
+
 static void
 fbdev_surface_wait(struct native_surface *nsurf)
 {
@@ -183,6 +209,7 @@ fbdev_display_create_scanout_surface(struct native_display *ndpy,
    fbsurf->base.destroy = fbdev_surface_destroy;
    fbsurf->base.swap_buffers = fbdev_surface_swap_buffers;
    fbsurf->base.flush_frontbuffer = fbdev_surface_flush_frontbuffer;
+   fbsurf->base.present = fbdev_surface_present;
    fbsurf->base.validate = fbdev_surface_validate;
    fbsurf->base.wait = fbdev_surface_wait;
 
@@ -279,6 +306,9 @@ fbdev_display_get_param(struct native_display *ndpy,
    int val;
 
    switch (param) {
+   case NATIVE_PARAM_USE_NATIVE_BUFFER:
+   case NATIVE_PARAM_PRESERVE_BUFFER:
+   case NATIVE_PARAM_MAX_SWAP_INTERVAL:
    default:
       val = 0;
       break;
index 91701e5b7df2675ea2d2d70607b9e276acf8a3f8..e010c1c4e69c7cea8b00e0d8d43ce8345432f84d 100644 (file)
@@ -159,6 +159,32 @@ gdi_surface_swap_buffers(struct native_surface *nsurf)
    return ret;
 }
 
+static boolean
+gdi_surface_present(struct native_surface *nsurf,
+                    enum native_attachment natt,
+                    boolean preserve,
+                    uint swap_interval)
+{
+   boolean ret;
+
+   if (preserve || swap_interval)
+      return FALSE;
+
+   switch (natt) {
+   case NATIVE_ATTACHMENT_FRONT_LEFT:
+      ret = gdi_surface_flush_frontbuffer(nsurf);
+      break;
+   case NATIVE_ATTACHMENT_BACK_LEFT:
+      ret = gdi_surface_swap_buffers(nsurf);
+      break;
+   default:
+      ret = FALSE;
+      break;
+   }
+
+   return ret;
+}
+
 static boolean
 gdi_surface_validate(struct native_surface *nsurf, uint attachment_mask,
                         unsigned int *seq_num, struct pipe_resource **textures,
@@ -233,6 +259,7 @@ gdi_display_create_window_surface(struct native_display *ndpy,
    gsurf->base.destroy = gdi_surface_destroy;
    gsurf->base.swap_buffers = gdi_surface_swap_buffers;
    gsurf->base.flush_frontbuffer = gdi_surface_flush_frontbuffer;
+   xsurf->base.present = gdi_surface_present;
    gsurf->base.validate = gdi_surface_validate;
    gsurf->base.wait = gdi_surface_wait;
 
@@ -321,6 +348,8 @@ gdi_display_get_param(struct native_display *ndpy,
       /* private buffers are allocated */
       val = FALSE;
       break;
+   case NATIVE_PARAM_PRESERVE_BUFFER:
+   case NATIVE_PARAM_MAX_SWAP_INTERVAL:
    default:
       val = 0;
       break;
index 1169e273c34bbdbff967b22e364e732526803086..a8df58a076d87b234a22c7cfa580e1b36d6c5ae2 100644 (file)
@@ -337,6 +337,32 @@ dri2_surface_swap_buffers(struct native_surface *nsurf)
    return TRUE;
 }
 
+static boolean
+dri2_surface_present(struct native_surface *nsurf,
+                     enum native_attachment natt,
+                     boolean preserve,
+                     uint swap_interval)
+{
+   boolean ret;
+
+   if (swap_interval)
+      return FALSE;
+
+   switch (natt) {
+   case NATIVE_ATTACHMENT_FRONT_LEFT:
+      ret = dri2_surface_flush_frontbuffer(nsurf);
+      break;
+   case NATIVE_ATTACHMENT_BACK_LEFT:
+      ret = dri2_surface_swap_buffers(nsurf);
+      break;
+   default:
+      ret = FALSE;
+      break;
+   }
+
+   return ret;
+}
+
 static boolean
 dri2_surface_validate(struct native_surface *nsurf, uint attachment_mask,
                       unsigned int *seq_num, struct pipe_resource **textures,
@@ -432,6 +458,7 @@ dri2_display_create_surface(struct native_display *ndpy,
    dri2surf->base.destroy = dri2_surface_destroy;
    dri2surf->base.swap_buffers = dri2_surface_swap_buffers;
    dri2surf->base.flush_frontbuffer = dri2_surface_flush_frontbuffer;
+   dri2surf->base.present = dri2_surface_present;
    dri2surf->base.validate = dri2_surface_validate;
    dri2surf->base.wait = dri2_surface_wait;
 
@@ -630,9 +657,14 @@ dri2_display_get_param(struct native_display *ndpy,
 
    switch (param) {
    case NATIVE_PARAM_USE_NATIVE_BUFFER:
-      /* DRI2GetBuffers use the native buffers */
+      /* DRI2GetBuffers uses the native buffers */
+      val = TRUE;
+      break;
+   case NATIVE_PARAM_PRESERVE_BUFFER:
+      /* DRI2CopyRegion is used */
       val = TRUE;
       break;
+   case NATIVE_PARAM_MAX_SWAP_INTERVAL:
    default:
       val = 0;
       break;
index 4b32f6e36e0490a4d7f4d00186b3b9576c8d3b0b..8e1ea4f45cd44ea5f8798117a313a472dc436414 100644 (file)
@@ -174,6 +174,32 @@ ximage_surface_swap_buffers(struct native_surface *nsurf)
    return ret;
 }
 
+static boolean
+ximage_surface_present(struct native_surface *nsurf,
+                       enum native_attachment natt,
+                       boolean preserve,
+                       uint swap_interval)
+{
+   boolean ret;
+
+   if (preserve || swap_interval)
+      return FALSE;
+
+   switch (natt) {
+   case NATIVE_ATTACHMENT_FRONT_LEFT:
+      ret = ximage_surface_flush_frontbuffer(nsurf);
+      break;
+   case NATIVE_ATTACHMENT_BACK_LEFT:
+      ret = ximage_surface_swap_buffers(nsurf);
+      break;
+   default:
+      ret = FALSE;
+      break;
+   }
+
+   return ret;
+}
+
 static boolean
 ximage_surface_validate(struct native_surface *nsurf, uint attachment_mask,
                         unsigned int *seq_num, struct pipe_resource **textures,
@@ -259,6 +285,7 @@ ximage_display_create_surface(struct native_display *ndpy,
    xsurf->base.destroy = ximage_surface_destroy;
    xsurf->base.swap_buffers = ximage_surface_swap_buffers;
    xsurf->base.flush_frontbuffer = ximage_surface_flush_frontbuffer;
+   xsurf->base.present = ximage_surface_present;
    xsurf->base.validate = ximage_surface_validate;
    xsurf->base.wait = ximage_surface_wait;
 
@@ -416,6 +443,8 @@ ximage_display_get_param(struct native_display *ndpy,
       /* private buffers are allocated */
       val = FALSE;
       break;
+   case NATIVE_PARAM_PRESERVE_BUFFER:
+   case NATIVE_PARAM_MAX_SWAP_INTERVAL:
    default:
       val = 0;
       break;