st/egl: add native_present_control
authorChia-I Wu <olv@lunarg.com>
Fri, 2 Sep 2011 13:26:24 +0000 (21:26 +0800)
committerChia-I Wu <olv@lunarg.com>
Thu, 8 Sep 2011 03:16:11 +0000 (11:16 +0800)
Replace the parameters of native_surface::present by a struct,
native_present_control.  Using a struct allows us to add more control
options without having to update each backend every time.

src/gallium/state_trackers/egl/android/native_android.cpp
src/gallium/state_trackers/egl/common/egl_g3d_api.c
src/gallium/state_trackers/egl/common/egl_g3d_st.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/common/native_helper.c
src/gallium/state_trackers/egl/drm/modeset.c
src/gallium/state_trackers/egl/fbdev/native_fbdev.c
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/wayland/native_wayland.c
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_ximage.c

index 338427d6925bbf14d2fa3b88ec10c90ea9fb3128..5f4638a679ab855e875f0fb973c46300613114bd 100644 (file)
@@ -386,24 +386,22 @@ copy_resources(struct native_display *ndpy,
 
 static boolean
 android_surface_present(struct native_surface *nsurf,
-                        enum native_attachment natt,
-                        boolean preserve,
-                        uint swap_interval)
+                        const native_present_control *ctrl)
 {
    struct android_surface *asurf = android_surface(nsurf);
    struct android_display *adpy = asurf->adpy;
    boolean ret;
 
-   if (swap_interval || natt != NATIVE_ATTACHMENT_BACK_LEFT)
+   if (ctrl->swap_interval || ctrl->natt != NATIVE_ATTACHMENT_BACK_LEFT)
       return FALSE;
 
    /* we always render to color_res first when it exists */
    if (asurf->color_res) {
       copy_resources(&adpy->base, asurf->color_res, asurf->buf_res);
-      if (!preserve)
+      if (!ctrl->preserve)
          pipe_resource_reference(&asurf->color_res, NULL);
    }
-   else if (preserve) {
+   else if (ctrl->preserve) {
       struct pipe_resource templ;
 
       memset(&templ, 0, sizeof(templ));
index f897054a540fbdba9d98b9e6c09037396734e7d1..27bc8be4e48d32016fe40723befc252a82e4f7b7 100644 (file)
@@ -551,6 +551,7 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
    _EGLContext *ctx = _eglGetCurrentContext();
    struct egl_g3d_context *gctx = NULL;
+   struct native_present_control ctrl;
 
    /* no-op for pixmap or pbuffer surface */
    if (gsurf->base.Type == EGL_PIXMAP_BIT ||
@@ -569,10 +570,12 @@ egl_g3d_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
       gctx->stctxi->flush(gctx->stctxi, ST_FLUSH_FRONT, NULL);
    }
 
-   return gsurf->native->present(gsurf->native,
-         NATIVE_ATTACHMENT_BACK_LEFT,
-         gsurf->base.SwapBehavior == EGL_BUFFER_PRESERVED,
-         gsurf->base.SwapInterval);
+   memset(&ctrl, 0, sizeof(ctrl));
+   ctrl.natt = NATIVE_ATTACHMENT_BACK_LEFT;
+   ctrl.preserve = (gsurf->base.SwapBehavior == EGL_BUFFER_PRESERVED);
+   ctrl.swap_interval = gsurf->base.SwapInterval;
+
+   return gsurf->native->present(gsurf->native, &ctrl);
 }
 
 static EGLBoolean
index b839f848d7b30defe101889fdc7a4c6e37c97ec6..50ed669ba303a65e690b3b1d07c7a108a33e9fa8 100644 (file)
@@ -192,9 +192,12 @@ egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi,
 {
    _EGLSurface *surf = (_EGLSurface *) stfbi->st_manager_private;
    struct egl_g3d_surface *gsurf = egl_g3d_surface(surf);
+   struct native_present_control ctrl;
 
-   return gsurf->native->present(gsurf->native,
-         NATIVE_ATTACHMENT_FRONT_LEFT, FALSE, 0);
+   memset(&ctrl, 0, sizeof(ctrl));
+   ctrl.natt = NATIVE_ATTACHMENT_FRONT_LEFT;
+
+   return gsurf->native->present(gsurf->native, &ctrl);
 }
 
 static boolean 
index 58593a489cd948c4cb77e96ab24059a204ab99be..0c86b752c925ab2190a5afabc75d5c9ee6e9cd50 100644 (file)
@@ -73,6 +73,20 @@ enum native_param_type {
    NATIVE_PARAM_MAX_SWAP_INTERVAL
 };
 
+/**
+ * Control how a surface presentation should happen.
+ */
+struct native_present_control {
+   /**< the attachment to present */
+   enum native_attachment natt;
+
+   /**< the contents of the presented attachment should be preserved */
+   boolean preserve;
+
+   /**< wait until the given vsyncs has passed since the last presentation */
+   uint swap_interval;
+};
+
 struct native_surface {
    /**
     * Available for caller's use.
@@ -85,9 +99,7 @@ struct native_surface {
     * Present the given buffer to the native engine.
     */
    boolean (*present)(struct native_surface *nsurf,
-                      enum native_attachment natt,
-                      boolean preserve,
-                      uint swap_interval);
+                      const struct native_present_control *ctrl);
 
    /**
     * Validate the buffers of the surface.  textures, if not NULL, points to an
index cca1e1c62954ec2da7b40f095b3ca7cb88edc36f..ebe5144b36799819fab79c5b712f05c37c38ee76 100644 (file)
@@ -393,12 +393,16 @@ native_display_copy_to_pixmap(struct native_display *ndpy,
    dst = tmp[natt];
 
    if (dst && dst->format == src->format) {
+      struct native_present_control ctrl;
       struct pipe_box src_box;
 
       u_box_origin_2d(src->width0, src->height0, &src_box);
       pipe->resource_copy_region(pipe, dst, 0, 0, 0, 0, src, 0, &src_box);
       pipe->flush(pipe, NULL);
-      nsurf->present(nsurf, natt, FALSE, 0);
+
+      memset(&ctrl, 0, sizeof(ctrl));
+      ctrl.natt = natt;
+      nsurf->present(nsurf, &ctrl);
    }
 
    if (dst)
index 73968d1343bb3994610382c0c7839da065e6fd9d..b33323b9d60f9c5a7b637fa996764ff0e6f1b22c 100644 (file)
@@ -194,21 +194,19 @@ drm_surface_swap_buffers(struct native_surface *nsurf)
 
 static boolean
 drm_surface_present(struct native_surface *nsurf,
-                    enum native_attachment natt,
-                    boolean preserve,
-                    uint swap_interval)
+                    const struct native_present_control *ctrl)
 {
    boolean ret;
 
-   if (swap_interval)
+   if (ctrl->swap_interval)
       return FALSE;
 
-   switch (natt) {
+   switch (ctrl->natt) {
    case NATIVE_ATTACHMENT_FRONT_LEFT:
       ret = drm_surface_flush_frontbuffer(nsurf);
       break;
    case NATIVE_ATTACHMENT_BACK_LEFT:
-      if (preserve)
+      if (ctrl->preserve)
         ret = drm_surface_copy_swap(nsurf);
       else
         ret = drm_surface_swap_buffers(nsurf);
index 6772d379f7355921be3127baf276cc2b04c7a0f9..e126888df902e060720a065dc2e8f3a7a632c4ce 100644 (file)
@@ -183,17 +183,15 @@ fbdev_surface_update_drawable(struct native_surface *nsurf,
 
 static boolean
 fbdev_surface_present(struct native_surface *nsurf,
-                      enum native_attachment natt,
-                      boolean preserve,
-                      uint swap_interval)
+                      const struct native_present_control *ctrl)
 {
    struct fbdev_surface *fbsurf = fbdev_surface(nsurf);
    struct fbdev_display *fbdpy = fbsurf->fbdpy;
    boolean ret = FALSE;
 
-   if (swap_interval)
+   if (ctrl->swap_interval)
       return FALSE;
-   if (natt != NATIVE_ATTACHMENT_BACK_LEFT)
+   if (ctrl->natt != NATIVE_ATTACHMENT_BACK_LEFT)
       return FALSE;
 
    if (!fbdpy->assume_fixed_vinfo) {
@@ -206,7 +204,7 @@ fbdev_surface_present(struct native_surface *nsurf,
       /* present the surface */
       if (fbdev_surface_update_drawable(&fbsurf->base, &vinfo)) {
          ret = resource_surface_present(fbsurf->rsurf,
-               natt, (void *) &fbsurf->drawable);
+               ctrl->natt, (void *) &fbsurf->drawable);
       }
 
       fbsurf->width = vinfo.xres;
@@ -223,7 +221,7 @@ fbdev_surface_present(struct native_surface *nsurf,
    else {
       /* the drawable never changes */
       ret = resource_surface_present(fbsurf->rsurf,
-            natt, (void *) &fbsurf->drawable);
+            ctrl->natt, (void *) &fbsurf->drawable);
    }
 
    return ret;
index 6bf0d4e46687841de290fc937e4927444b65cc0e..d3fec719a21fadf91a815a32f1d18a041911c2e4 100644 (file)
@@ -161,16 +161,14 @@ gdi_surface_swap_buffers(struct native_surface *nsurf)
 
 static boolean
 gdi_surface_present(struct native_surface *nsurf,
-                    enum native_attachment natt,
-                    boolean preserve,
-                    uint swap_interval)
+                    const native_present_control *ctrl)
 {
    boolean ret;
 
-   if (preserve || swap_interval)
+   if (ctrl->preserve || ctrl->swap_interval)
       return FALSE;
 
-   switch (natt) {
+   switch (ctrl->natt) {
    case NATIVE_ATTACHMENT_FRONT_LEFT:
       ret = gdi_surface_flush_frontbuffer(nsurf);
       break;
index ded4cc481d1a65e9ff5ff54481c6369eaf3c237c..29c9b46d612eed386da49ebf429008ab7d9b9fc2 100644 (file)
@@ -294,18 +294,16 @@ wayland_surface_swap_buffers(struct native_surface *nsurf)
 
 static boolean
 wayland_surface_present(struct native_surface *nsurf,
-                        enum native_attachment natt,
-                        boolean preserve,
-                        uint swap_interval)
+                        const struct native_present_control *ctrl)
 {
    struct wayland_surface *surface = wayland_surface(nsurf);
    uint width, height;
    boolean ret;
 
-   if (preserve || swap_interval)
+   if (ctrl->preserve || ctrl->swap_interval)
       return FALSE;
 
-   switch (natt) {
+   switch (ctrl->natt) {
    case NATIVE_ATTACHMENT_FRONT_LEFT:
       ret = TRUE;
       break;
index 4b8be7bc7593f621019666c0b9935bd0381df9b5..47547446ffd41cd694b7a758180c7635e9b2553d 100644 (file)
@@ -342,16 +342,14 @@ dri2_surface_swap_buffers(struct native_surface *nsurf)
 
 static boolean
 dri2_surface_present(struct native_surface *nsurf,
-                     enum native_attachment natt,
-                     boolean preserve,
-                     uint swap_interval)
+                     const struct native_present_control *ctrl)
 {
    boolean ret;
 
-   if (swap_interval)
+   if (ctrl->swap_interval)
       return FALSE;
 
-   switch (natt) {
+   switch (ctrl->natt) {
    case NATIVE_ATTACHMENT_FRONT_LEFT:
       ret = dri2_surface_flush_frontbuffer(nsurf);
       break;
index e7794f0d3d78133d1d8ae88d371fa018bcfb2103..c0108fc552504a657d52200e8c1ab5609bfd0bbb 100644 (file)
@@ -170,16 +170,14 @@ ximage_surface_swap_buffers(struct native_surface *nsurf)
 
 static boolean
 ximage_surface_present(struct native_surface *nsurf,
-                       enum native_attachment natt,
-                       boolean preserve,
-                       uint swap_interval)
+                       const struct native_present_control *ctrl)
 {
    boolean ret;
 
-   if (preserve || swap_interval)
+   if (ctrl->preserve || ctrl->swap_interval)
       return FALSE;
 
-   switch (natt) {
+   switch (ctrl->natt) {
    case NATIVE_ATTACHMENT_FRONT_LEFT:
       ret = ximage_surface_flush_frontbuffer(nsurf);
       break;