+
+ if (stq->pq)
+ pipe->end_query(pipe, stq->pq);
+}
+
+
+static boolean
+get_query_result(struct pipe_context *pipe,
+ struct st_query_object *stq,
+ boolean wait)
+{
+ if (!stq->pq) {
+ /* Only needed in case we failed to allocate the gallium query earlier.
+ * Return TRUE so we don't spin on this forever.
+ */
+ return TRUE;
+ }
+
+ if (!pipe->get_query_result(pipe,
+ stq->pq,
+ wait,
+ (void *)&stq->base.Result)) {
+ return FALSE;
+ }
+
+ if (stq->base.Target == GL_TIME_ELAPSED &&
+ stq->type == PIPE_QUERY_TIMESTAMP) {
+ /* Calculate the elapsed time from the two timestamp queries */
+ GLuint64EXT Result0 = 0;
+ assert(stq->pq_begin);
+ pipe->get_query_result(pipe, stq->pq_begin, TRUE, (void *)&Result0);
+ stq->base.Result -= Result0;
+ } else {
+ assert(!stq->pq_begin);
+ }
+
+ return TRUE;
+}
+
+
+static void
+st_WaitQuery(struct gl_context *ctx, struct gl_query_object *q)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_query_object *stq = st_query_object(q);
+
+ /* this function should only be called if we don't have a ready result */
+ assert(!stq->base.Ready);
+
+ while (!stq->base.Ready &&
+ !get_query_result(pipe, stq, TRUE))
+ {
+ /* nothing */
+ }
+
+ q->Ready = GL_TRUE;
+}
+
+
+static void
+st_CheckQuery(struct gl_context *ctx, struct gl_query_object *q)
+{
+ struct pipe_context *pipe = st_context(ctx)->pipe;
+ struct st_query_object *stq = st_query_object(q);
+ assert(!q->Ready); /* we should not get called if Ready is TRUE */
+ q->Ready = get_query_result(pipe, stq, FALSE);
+}
+
+
+static uint64_t
+st_GetTimestamp(struct gl_context *ctx)
+{
+ struct pipe_screen *screen = st_context(ctx)->pipe->screen;
+
+ return screen->get_timestamp(screen);