00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00137
00138 return (struct pb_buffer *)buf;
00139 }
00140
00141
00142
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
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