sp_query.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 /* Author:
00029  *    Keith Whitwell <keith@tungstengraphics.com>
00030  */
00031 
00032 #include "draw/draw_context.h"
00033 #include "pipe/p_defines.h"
00034 #include "pipe/p_inlines.h"
00035 #include "util/u_memory.h"
00036 #include "sp_context.h"
00037 #include "sp_query.h"
00038 
00039 struct softpipe_query {
00040    uint64 start;
00041    uint64 end;
00042 };
00043 
00044 
00045 static struct softpipe_query *softpipe_query( struct pipe_query *p )
00046 {
00047    return (struct softpipe_query *)p;
00048 }
00049 
00050 static struct pipe_query *
00051 softpipe_create_query(struct pipe_context *pipe, 
00052                       unsigned type)
00053 {
00054    assert(type == PIPE_QUERY_OCCLUSION_COUNTER);
00055    return (struct pipe_query *)CALLOC_STRUCT( softpipe_query );
00056 }
00057 
00058 
00059 static void
00060 softpipe_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
00061 {
00062    FREE(q);
00063 }
00064 
00065 
00066 static void
00067 softpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
00068 {
00069    struct softpipe_context *softpipe = softpipe_context( pipe );
00070    struct softpipe_query *sq = softpipe_query(q);
00071    
00072    sq->start = softpipe->occlusion_count;
00073 }
00074 
00075 
00076 static void
00077 softpipe_end_query(struct pipe_context *pipe, struct pipe_query *q)
00078 {
00079    struct softpipe_context *softpipe = softpipe_context( pipe );
00080    struct softpipe_query *sq = softpipe_query(q);
00081 
00082    sq->end = softpipe->occlusion_count;
00083 }
00084 
00085 
00086 static boolean
00087 softpipe_get_query_result(struct pipe_context *pipe, 
00088                           struct pipe_query *q,
00089                           boolean wait,
00090                           uint64 *result )
00091 {
00092    struct softpipe_query *sq = softpipe_query(q);
00093    *result = sq->end - sq->start;
00094    return TRUE;
00095 }
00096 
00097 
00098 void softpipe_init_query_funcs(struct softpipe_context *softpipe )
00099 {
00100    softpipe->pipe.create_query = softpipe_create_query;
00101    softpipe->pipe.destroy_query = softpipe_destroy_query;
00102    softpipe->pipe.begin_query = softpipe_begin_query;
00103    softpipe->pipe.end_query = softpipe_end_query;
00104    softpipe->pipe.get_query_result = softpipe_get_query_result;
00105 }
00106 
00107 

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4