pb_buffer.h File Reference

Generic code for buffers. More...

Include dependency graph for pb_buffer.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pb_desc
 Buffer description. More...
struct  pb_buffer
 Base class for all pb_* buffers. More...
struct  pb_vtbl
 Virtual function table for the buffer storage operations. More...

Functions

static struct pipe_bufferpb_pipe_buffer (struct pb_buffer *pbuf)
static struct pb_bufferpb_buffer (struct pipe_buffer *buf)
static void * pb_map (struct pb_buffer *buf, unsigned flags)
static void pb_unmap (struct pb_buffer *buf)
static void pb_get_base_buffer (struct pb_buffer *buf, struct pb_buffer **base_buf, unsigned *offset)
static void pb_destroy (struct pb_buffer *buf)
static void pb_reference (struct pb_buffer **dst, struct pb_buffer *src)
static boolean pb_check_alignment (size_t requested, size_t provided)
 Utility function to check whether the provided alignment is consistent with the requested or not.
static boolean pb_check_usage (unsigned requested, unsigned provided)
 Utility function to check whether the provided alignment is consistent with the requested or not.
struct pb_bufferpb_malloc_buffer_create (size_t size, const struct pb_desc *desc)
 Malloc-based buffer to store data that can't be used by the graphics hardware.
void pb_init_winsys (struct pipe_winsys *winsys)


Detailed Description

Generic code for buffers.

Behind a pipe buffle handle there can be DMA buffers, client (or user) buffers, regular malloced buffers, etc. This file provides an abstract base buffer handle that allows the driver to cope with all those kinds of buffers in a more flexible way.

There is no obligation of a winsys driver to use this library. And a pipe driver should be completly agnostic about it.

Author:
Jos´┐Ż Fonseca <jrfonseca@tungstengraphics.com>

Definition in file pb_buffer.h.


Function Documentation

static struct pb_buffer* pb_buffer ( struct pipe_buffer buf  )  [static, read]

Definition at line 133 of file pb_buffer.h.

References assert.

00134 {
00135    assert(buf);
00136    /* Could add a magic cookie check on debug builds.
00137     */
00138    return (struct pb_buffer *)buf;
00139 }

static boolean pb_check_alignment ( size_t  requested,
size_t  provided 
) [static]

Utility function to check whether the provided alignment is consistent with the requested or not.

Definition at line 211 of file pb_buffer.h.

References FALSE, and TRUE.

00212 {
00213    return requested <= provided && (provided % requested) == 0 ? TRUE : FALSE;
00214 }

static boolean pb_check_usage ( unsigned  requested,
unsigned  provided 
) [static]

Utility function to check whether the provided alignment is consistent with the requested or not.

Definition at line 222 of file pb_buffer.h.

References FALSE, and TRUE.

00223 {
00224    return (requested & provided) == requested ? TRUE : FALSE;
00225 }

static void pb_destroy ( struct pb_buffer buf  )  [static]

Definition at line 181 of file pb_buffer.h.

References assert, pb_vtbl::destroy, and pb_buffer::vtbl.

00182 {
00183    assert(buf);
00184    if(!buf)
00185       return;
00186    buf->vtbl->destroy(buf);
00187 }

static void pb_get_base_buffer ( struct pb_buffer buf,
struct pb_buffer **  base_buf,
unsigned *  offset 
) [static]

Definition at line 166 of file pb_buffer.h.

References assert, pb_vtbl::get_base_buffer, and pb_buffer::vtbl.

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 }

void pb_init_winsys ( struct pipe_winsys winsys  ) 

Definition at line 164 of file pb_winsys.c.

References pipe_winsys::buffer_destroy, pipe_winsys::buffer_map, pipe_winsys::buffer_unmap, pb_winsys_buffer_destroy(), pb_winsys_buffer_map(), pb_winsys_buffer_unmap(), pb_winsys_user_buffer_create(), and pipe_winsys::user_buffer_create.

struct pb_buffer* pb_malloc_buffer_create ( size_t  size,
const struct pb_desc desc 
) [read]

Malloc-based buffer to store data that can't be used by the graphics hardware.

Definition at line 104 of file pb_buffer_malloc.c.

References align_malloc(), pb_desc::alignment, pipe_buffer::alignment, pb_buffer::base, malloc_buffer::base, CALLOC_STRUCT, malloc_buffer::data, FREE, pipe_buffer::refcount, pipe_buffer::size, pb_desc::usage, pipe_buffer::usage, and pb_buffer::vtbl.

00106 {
00107    struct malloc_buffer *buf;
00108    
00109    /* TODO: do a single allocation */
00110    
00111    buf = CALLOC_STRUCT(malloc_buffer);
00112    if(!buf)
00113       return NULL;
00114 
00115    buf->base.base.refcount = 1;
00116    buf->base.base.alignment = desc->alignment;
00117    buf->base.base.usage = desc->usage;
00118    buf->base.base.size = size;
00119    buf->base.vtbl = &malloc_buffer_vtbl;
00120 
00121    buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment);
00122    if(!buf->data) {
00123       FREE(buf);
00124       return NULL;
00125    }
00126 
00127    return &buf->base;
00128 }

static void* pb_map ( struct pb_buffer buf,
unsigned  flags 
) [static]

Definition at line 145 of file pb_buffer.h.

References assert, pb_vtbl::map, and pb_buffer::vtbl.

00147 {
00148    assert(buf);
00149    if(!buf)
00150       return NULL;
00151    return buf->vtbl->map(buf, flags);
00152 }

static struct pipe_buffer* pb_pipe_buffer ( struct pb_buffer pbuf  )  [static, read]

Definition at line 125 of file pb_buffer.h.

References assert, and pb_buffer::base.

00126 {
00127    assert(pbuf);
00128    return &pbuf->base;
00129 }

static void pb_reference ( struct pb_buffer **  dst,
struct pb_buffer src 
) [static]

Definition at line 193 of file pb_buffer.h.

References pb_buffer::base, pb_destroy(), and pipe_buffer::refcount.

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 }

static void pb_unmap ( struct pb_buffer buf  )  [static]

Definition at line 156 of file pb_buffer.h.

References assert, pb_vtbl::unmap, and pb_buffer::vtbl.

00157 {
00158    assert(buf);
00159    if(!buf)
00160       return;
00161    buf->vtbl->unmap(buf);
00162 }


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