pb_buffer.h

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 
00043 #ifndef PB_BUFFER_H_
00044 #define PB_BUFFER_H_
00045 
00046 
00047 #include "pipe/p_compiler.h"
00048 #include "pipe/p_debug.h"
00049 #include "pipe/p_state.h"
00050 #include "pipe/p_inlines.h"
00051 
00052 
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056 
00057 
00058 struct pb_vtbl;
00059 
00065 struct pb_desc
00066 {
00067    unsigned alignment;
00068    unsigned usage;
00069 };
00070 
00071 
00075 struct pb_buffer 
00076 {
00077    struct pipe_buffer base;
00078 
00085    const struct pb_vtbl *vtbl;
00086 };
00087 
00088 
00094 struct pb_vtbl
00095 {
00096    void (*destroy)( struct pb_buffer *buf );
00097 
00102    void *(*map)( struct pb_buffer *buf, 
00103                  unsigned flags );
00104    
00105    void (*unmap)( struct pb_buffer *buf );
00106 
00118    void (*get_base_buffer)( struct pb_buffer *buf,
00119                             struct pb_buffer **base_buf,
00120                             unsigned *offset );
00121 };
00122 
00123 
00124 static INLINE struct pipe_buffer *
00125 pb_pipe_buffer( struct pb_buffer *pbuf )
00126 {
00127    assert(pbuf);
00128    return &pbuf->base;
00129 }
00130 
00131 
00132 static INLINE struct pb_buffer *
00133 pb_buffer( struct pipe_buffer *buf )
00134 {
00135    assert(buf);
00136    /* Could add a magic cookie check on debug builds.
00137     */
00138    return (struct pb_buffer *)buf;
00139 }
00140 
00141 
00142 /* Accessor functions for pb->vtbl:
00143  */
00144 static INLINE void *
00145 pb_map(struct pb_buffer *buf, 
00146        unsigned flags)
00147 {
00148    assert(buf);
00149    if(!buf)
00150       return NULL;
00151    return buf->vtbl->map(buf, flags);
00152 }
00153 
00154 
00155 static INLINE void 
00156 pb_unmap(struct pb_buffer *buf)
00157 {
00158    assert(buf);
00159    if(!buf)
00160       return;
00161    buf->vtbl->unmap(buf);
00162 }
00163 
00164 
00165 static INLINE void
00166 pb_get_base_buffer( struct pb_buffer *buf,
00167                     struct pb_buffer **base_buf,
00168                     unsigned *offset )
00169 {
00170    assert(buf);
00171    if(!buf) {
00172       base_buf = NULL;
00173       offset = 0;
00174       return;
00175    }
00176    buf->vtbl->get_base_buffer(buf, base_buf, offset);
00177 }
00178 
00179 
00180 static INLINE void 
00181 pb_destroy(struct pb_buffer *buf)
00182 {
00183    assert(buf);
00184    if(!buf)
00185       return;
00186    buf->vtbl->destroy(buf);
00187 }
00188 
00189 
00190 /* XXX: thread safety issues!
00191  */
00192 static INLINE void
00193 pb_reference(struct pb_buffer **dst,
00194              struct pb_buffer *src)
00195 {
00196    if (src) 
00197       src->base.refcount++;
00198 
00199    if (*dst && --(*dst)->base.refcount == 0)
00200       pb_destroy( *dst );
00201 
00202    *dst = src;
00203 }
00204 
00205 
00210 static INLINE boolean
00211 pb_check_alignment(size_t requested, size_t provided)
00212 {
00213    return requested <= provided && (provided % requested) == 0 ? TRUE : FALSE;
00214 }
00215 
00216 
00221 static INLINE boolean
00222 pb_check_usage(unsigned requested, unsigned provided)
00223 {
00224    return (requested & provided) == requested ? TRUE : FALSE;
00225 }
00226 
00227 
00232 struct pb_buffer *
00233 pb_malloc_buffer_create(size_t size, 
00234                         const struct pb_desc *desc);
00235 
00236 
00237 void 
00238 pb_init_winsys(struct pipe_winsys *winsys);
00239 
00240 
00241 #ifdef __cplusplus
00242 }
00243 #endif
00244 
00245 #endif /*PB_BUFFER_H_*/

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