gallium/dri2: Refactor image property queries
[mesa.git] / src / gallium / state_trackers / dri / dri_drawable.c
index 53dbfd707ef384d03cf2d2540dc6f7e3943cbdb9..f27396195ec7345e93fd2d6b798aed044787c8c6 100644 (file)
@@ -43,7 +43,7 @@ static uint32_t drifb_ID = 0;
 static void
 swap_fences_unref(struct dri_drawable *draw);
 
-static boolean
+static bool
 dri_st_framebuffer_validate(struct st_context_iface *stctx,
                             struct st_framebuffer_iface *stfbi,
                             const enum st_attachment_type *statts,
@@ -55,7 +55,7 @@ dri_st_framebuffer_validate(struct st_context_iface *stctx,
       (struct dri_drawable *) stfbi->st_manager_private;
    struct dri_screen *screen = dri_screen(drawable->sPriv);
    unsigned statt_mask, new_mask;
-   boolean new_stamp;
+   bool new_stamp;
    int i;
    unsigned int lastStamp;
    struct pipe_resource **textures =
@@ -96,16 +96,16 @@ dri_st_framebuffer_validate(struct st_context_iface *stctx,
    } while (lastStamp != drawable->dPriv->lastStamp);
 
    if (!out)
-      return TRUE;
+      return true;
 
    /* Set the window-system buffers for the state tracker. */
    for (i = 0; i < count; i++)
       pipe_resource_reference(&out[i], textures[statts[i]]);
 
-   return TRUE;
+   return true;
 }
 
-static boolean
+static bool
 dri_st_framebuffer_flush_front(struct st_context_iface *stctx,
                                struct st_framebuffer_iface *stfbi,
                                enum st_attachment_type statt)
@@ -117,13 +117,13 @@ dri_st_framebuffer_flush_front(struct st_context_iface *stctx,
    /* XXX remove this and just set the correct one on the framebuffer */
    drawable->flush_frontbuffer(ctx, drawable, statt);
 
-   return TRUE;
+   return true;
 }
 
 /**
  * The state tracker framebuffer interface flush_swapbuffers callback
  */
-static boolean
+static bool
 dri_st_framebuffer_flush_swapbuffers(struct st_context_iface *stctx,
                                      struct st_framebuffer_iface *stfbi)
 {
@@ -134,16 +134,16 @@ dri_st_framebuffer_flush_swapbuffers(struct st_context_iface *stctx,
    if (drawable->flush_swapbuffers)
       drawable->flush_swapbuffers(ctx, drawable);
 
-   return TRUE;
+   return true;
 }
 
 /**
  * This is called when we need to set up GL rendering to a new X window.
  */
-boolean
+bool
 dri_create_buffer(__DRIscreen * sPriv,
                  __DRIdrawable * dPriv,
-                 const struct gl_config * visual, boolean isPixmap)
+                 const struct gl_config * visual, bool isPixmap)
 {
    struct dri_screen *screen = sPriv->driverPrivate;
    struct dri_drawable *drawable = NULL;
@@ -176,10 +176,10 @@ dri_create_buffer(__DRIscreen * sPriv,
    drawable->base.ID = p_atomic_inc_return(&drifb_ID);
    drawable->base.state_manager = &screen->base;
 
-   return GL_TRUE;
+   return true;
 fail:
    FREE(drawable);
-   return GL_FALSE;
+   return false;
 }
 
 void
@@ -260,6 +260,12 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
       if (format == __DRI_TEXTURE_FORMAT_RGB)  {
          /* only need to cover the formats recognized by dri_fill_st_visual */
          switch (internal_format) {
+         case PIPE_FORMAT_B10G10R10A2_UNORM:
+            internal_format = PIPE_FORMAT_B10G10R10X2_UNORM;
+            break;
+         case PIPE_FORMAT_R10G10B10A2_UNORM:
+            internal_format = PIPE_FORMAT_R10G10B10X2_UNORM;
+            break;
          case PIPE_FORMAT_BGRA8888_UNORM:
             internal_format = PIPE_FORMAT_BGRX8888_UNORM;
             break;
@@ -275,7 +281,7 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
 
       ctx->st->teximage(ctx->st,
             (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT,
-            0, internal_format, pt, FALSE);
+            0, internal_format, pt, false);
    }
 }
 
@@ -474,7 +480,7 @@ dri_flush(__DRIcontext *cPriv,
    struct dri_drawable *drawable = dri_drawable(dPriv);
    struct st_context_iface *st;
    unsigned flush_flags;
-   boolean swap_msaa_buffers = FALSE;
+   bool swap_msaa_buffers = false;
 
    if (!ctx) {
       assert(0);
@@ -490,7 +496,7 @@ dri_flush(__DRIcontext *cPriv,
       if (drawable->flushing)
          return;
 
-      drawable->flushing = TRUE;
+      drawable->flushing = true;
    }
    else {
       flags &= ~__DRI2_FLUSH_DRAWABLE;
@@ -510,7 +516,7 @@ dri_flush(__DRIcontext *cPriv,
 
          if (drawable->msaa_textures[ST_ATTACHMENT_FRONT_LEFT] &&
              drawable->msaa_textures[ST_ATTACHMENT_BACK_LEFT]) {
-            swap_msaa_buffers = TRUE;
+            swap_msaa_buffers = true;
          }
 
          /* FRONT_LEFT is resolved in drawable->flush_frontbuffer. */
@@ -518,12 +524,6 @@ dri_flush(__DRIcontext *cPriv,
 
       dri_postprocessing(ctx, drawable, ST_ATTACHMENT_BACK_LEFT);
 
-      if (ctx->hud) {
-         hud_run(ctx->hud, drawable->textures[ST_ATTACHMENT_BACK_LEFT]);
-      }
-
-      pipe->flush_resource(pipe, drawable->textures[ST_ATTACHMENT_BACK_LEFT]);
-
       if (pipe->invalidate_resource &&
           (flags & __DRI2_FLUSH_INVALIDATE_ANCILLARY)) {
          if (drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL])
@@ -531,6 +531,13 @@ dri_flush(__DRIcontext *cPriv,
          if (drawable->msaa_textures[ST_ATTACHMENT_DEPTH_STENCIL])
             pipe->invalidate_resource(pipe, drawable->msaa_textures[ST_ATTACHMENT_DEPTH_STENCIL]);
       }
+
+      if (ctx->hud) {
+         hud_run(ctx->hud, ctx->st->cso_context,
+                 drawable->textures[ST_ATTACHMENT_BACK_LEFT]);
+      }
+
+      pipe->flush_resource(pipe, drawable->textures[ST_ATTACHMENT_BACK_LEFT]);
    }
 
    flush_flags = 0;
@@ -540,7 +547,7 @@ dri_flush(__DRIcontext *cPriv,
       flush_flags |= ST_FLUSH_END_OF_FRAME;
 
    /* Flush the context and throttle if needed. */
-   if (dri_screen(ctx->sPriv)->throttling_enabled &&
+   if (dri_screen(ctx->sPriv)->default_throttle_frames &&
        drawable &&
        (reason == __DRI2_THROTTLE_SWAPBUFFER ||
         reason == __DRI2_THROTTLE_FLUSHFRONT)) {
@@ -555,19 +562,19 @@ dri_flush(__DRIcontext *cPriv,
        * flush method returns a fence even if there are no commands to flush.
        */
       struct pipe_screen *screen = drawable->screen->base.screen;
-      struct pipe_fence_handle *fence;
+      struct pipe_fence_handle *oldest_fence, *new_fence = NULL;
 
-      fence = swap_fences_pop_front(drawable);
-      if (fence) {
-         (void) screen->fence_finish(screen, NULL, fence, PIPE_TIMEOUT_INFINITE);
-         screen->fence_reference(screen, &fence, NULL);
-      }
+      st->flush(st, flush_flags, &new_fence);
 
-      st->flush(st, flush_flags, &fence);
+      oldest_fence = swap_fences_pop_front(drawable);
+      if (oldest_fence) {
+         screen->fence_finish(screen, NULL, oldest_fence, PIPE_TIMEOUT_INFINITE);
+         screen->fence_reference(screen, &oldest_fence, NULL);
+      }
 
-      if (fence) {
-         swap_fences_push_back(drawable, fence);
-         screen->fence_reference(screen, &fence, NULL);
+      if (new_fence) {
+         swap_fences_push_back(drawable, new_fence);
+         screen->fence_reference(screen, &new_fence, NULL);
       }
    }
    else if (flags & (__DRI2_FLUSH_DRAWABLE | __DRI2_FLUSH_CONTEXT)) {
@@ -575,7 +582,7 @@ dri_flush(__DRIcontext *cPriv,
    }
 
    if (drawable) {
-      drawable->flushing = FALSE;
+      drawable->flushing = false;
    }
 
    /* Swap the MSAA front and back buffers, so that reading