sw_winsys.c File Reference

Include dependency graph for sw_winsys.c:

Go to the source code of this file.

Data Structures

struct  sw_pipe_winsys
 Totally software-based winsys layer. More...
struct  sw_pipe_buffer
 subclass of pipe_buffer More...

Functions

static struct sw_pipe_buffersw_pipe_buffer (struct pipe_buffer *b)
 cast wrapper
static unsigned round_up (unsigned n, unsigned multiple)
 Round n up to next multiple.
static const char * get_name (struct pipe_winsys *pws)
static struct pipe_bufferbuffer_create (struct pipe_winsys *pws, unsigned alignment, unsigned usage, unsigned size)
 Create new pipe_buffer and allocate storage of given size.
static struct pipe_bufferuser_buffer_create (struct pipe_winsys *pws, void *ptr, unsigned bytes)
 Create buffer which wraps user-space data.
static void * buffer_map (struct pipe_winsys *pws, struct pipe_buffer *buf, unsigned flags)
static void buffer_unmap (struct pipe_winsys *pws, struct pipe_buffer *buf)
static void buffer_destroy (struct pipe_winsys *pws, struct pipe_buffer *buf)
static struct pipe_surfacesurface_alloc (struct pipe_winsys *ws)
 Called via winsys->surface_alloc() to create new surfaces.
static int surface_alloc_storage (struct pipe_winsys *winsys, struct pipe_surface *surf, unsigned width, unsigned height, enum pipe_format format, unsigned flags, unsigned tex_usage)
static void surface_release (struct pipe_winsys *winsys, struct pipe_surface **s)
static void fence_reference (struct pipe_winsys *sws, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence)
static int fence_signalled (struct pipe_winsys *sws, struct pipe_fence_handle *fence, unsigned flag)
static int fence_finish (struct pipe_winsys *sws, struct pipe_fence_handle *fence, unsigned flag)
struct pipe_winsyscreate_sw_winsys (void)
 Create/return a new pipe_winsys object.


Function Documentation

static struct pipe_buffer* buffer_create ( struct pipe_winsys pws,
unsigned  alignment,
unsigned  usage,
unsigned  size 
) [static, read]

Create new pipe_buffer and allocate storage of given size.

Definition at line 93 of file sw_winsys.c.

References align_malloc(), pipe_buffer::alignment, sw_pipe_buffer::Base, CALLOC_STRUCT, sw_pipe_buffer::Data, MAX2, pipe_buffer::refcount, pipe_buffer::size, and pipe_buffer::usage.

00097 {
00098    struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
00099    if (!buffer)
00100       return NULL;
00101 
00102    buffer->Base.refcount = 1;
00103    buffer->Base.alignment = alignment;
00104    buffer->Base.usage = usage;
00105    buffer->Base.size = size;
00106 
00107    /* align to 16-byte multiple for Cell */
00108    buffer->Data = align_malloc(size, MAX2(alignment, 16));
00109 
00110    return &buffer->Base;
00111 }

static void buffer_destroy ( struct pipe_winsys pws,
struct pipe_buffer buf 
) [static]

Definition at line 151 of file sw_winsys.c.

References align_free(), sw_pipe_buffer::Data, sw_pipe_buffer(), and sw_pipe_buffer::UserBuffer.

00152 {
00153    struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
00154 
00155    if (buffer->Data && !buffer->UserBuffer) {
00156       align_free(buffer->Data);
00157       buffer->Data = NULL;
00158    }
00159 
00160    free(buffer);
00161 }

static void* buffer_map ( struct pipe_winsys pws,
struct pipe_buffer buf,
unsigned  flags 
) [static]

Definition at line 134 of file sw_winsys.c.

References sw_pipe_buffer::Data, sw_pipe_buffer::Mapped, and sw_pipe_buffer().

00135 {
00136    struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
00137    buffer->Mapped = buffer->Data;
00138    return buffer->Mapped;
00139 }

static void buffer_unmap ( struct pipe_winsys pws,
struct pipe_buffer buf 
) [static]

Definition at line 143 of file sw_winsys.c.

References sw_pipe_buffer::Mapped, and sw_pipe_buffer().

00144 {
00145    struct sw_pipe_buffer *buffer = sw_pipe_buffer(buf);
00146    buffer->Mapped = NULL;
00147 }

struct pipe_winsys* create_sw_winsys ( void   )  [read]

Create/return a new pipe_winsys object.

Definition at line 256 of file sw_winsys.c.

References sw_pipe_winsys::Base, buffer_create(), pipe_winsys::buffer_create, buffer_destroy(), pipe_winsys::buffer_destroy, buffer_map(), pipe_winsys::buffer_map, buffer_unmap(), pipe_winsys::buffer_unmap, CALLOC_STRUCT, fence_finish(), pipe_winsys::fence_finish, fence_reference(), pipe_winsys::fence_reference, fence_signalled(), pipe_winsys::fence_signalled, pipe_winsys::flush_frontbuffer, get_name(), pipe_winsys::get_name, surface_alloc(), pipe_winsys::surface_alloc, surface_alloc_storage(), pipe_winsys::surface_alloc_storage, surface_release(), pipe_winsys::surface_release, user_buffer_create(), and pipe_winsys::user_buffer_create.

00257 {
00258    struct sw_pipe_winsys *ws = CALLOC_STRUCT(sw_pipe_winsys);
00259    if (!ws)
00260       return NULL;
00261 
00262    /* Fill in this struct with callbacks that pipe will need to
00263     * communicate with the window system, buffer manager, etc. 
00264     */
00265    ws->Base.buffer_create = buffer_create;
00266    ws->Base.user_buffer_create = user_buffer_create;
00267    ws->Base.buffer_map = buffer_map;
00268    ws->Base.buffer_unmap = buffer_unmap;
00269    ws->Base.buffer_destroy = buffer_destroy;
00270 
00271    ws->Base.surface_alloc = surface_alloc;
00272    ws->Base.surface_alloc_storage = surface_alloc_storage;
00273    ws->Base.surface_release = surface_release;
00274 
00275    ws->Base.fence_reference = fence_reference;
00276    ws->Base.fence_signalled = fence_signalled;
00277    ws->Base.fence_finish = fence_finish;
00278 
00279    ws->Base.flush_frontbuffer = NULL; /* not implemented here! */
00280 
00281    ws->Base.get_name = get_name;
00282 
00283    return &ws->Base;
00284 }

static int fence_finish ( struct pipe_winsys sws,
struct pipe_fence_handle *  fence,
unsigned  flag 
) [static]

Definition at line 244 of file sw_winsys.c.

00246 {
00247    /* no-op */
00248    return 0;
00249 }

static void fence_reference ( struct pipe_winsys sws,
struct pipe_fence_handle **  ptr,
struct pipe_fence_handle *  fence 
) [static]

Definition at line 227 of file sw_winsys.c.

00229 {
00230    /* no-op */
00231 }

static int fence_signalled ( struct pipe_winsys sws,
struct pipe_fence_handle *  fence,
unsigned  flag 
) [static]

Definition at line 235 of file sw_winsys.c.

00237 {
00238    /* no-op */
00239    return 0;
00240 }

static const char* get_name ( struct pipe_winsys pws  )  [static]

Definition at line 85 of file sw_winsys.c.

00086 {
00087    return "software";
00088 }

static unsigned round_up ( unsigned  n,
unsigned  multiple 
) [static]

Round n up to next multiple.

Definition at line 78 of file sw_winsys.c.

00079 {
00080    return (n + multiple - 1) & ~(multiple - 1);
00081 }

static struct pipe_surface* surface_alloc ( struct pipe_winsys ws  )  [static, read]

Called via winsys->surface_alloc() to create new surfaces.

Definition at line 168 of file sw_winsys.c.

References CALLOC_STRUCT, pipe_surface::refcount, and pipe_surface::winsys.

00169 {
00170    struct pipe_surface *surf = CALLOC_STRUCT(pipe_surface);
00171    if (!surf)
00172       return NULL;
00173 
00174    surf->refcount = 1;
00175    surf->winsys = ws;
00176 
00177    return surf;
00178 }

static int surface_alloc_storage ( struct pipe_winsys winsys,
struct pipe_surface surf,
unsigned  width,
unsigned  height,
enum pipe_format  format,
unsigned  flags,
unsigned  tex_usage 
) [static]

Definition at line 182 of file sw_winsys.c.

References assert, pipe_surface::block, pipe_surface::buffer, pipe_winsys::buffer_create, pipe_surface::format, pipe_surface::height, pipe_surface::nblocksx, pipe_surface::nblocksy, pf_get_block(), pf_get_nblocksx(), pf_get_nblocksy(), PIPE_BUFFER_USAGE_PIXEL, round_up(), pipe_format_block::size, pipe_surface::stride, pipe_surface::usage, and pipe_surface::width.

00188 {
00189    const unsigned alignment = 64;
00190 
00191    surf->width = width;
00192    surf->height = height;
00193    surf->format = format;
00194    pf_get_block(surf->format, &surf->block);
00195    surf->nblocksx = pf_get_nblocksx(&surf->block, width);
00196    surf->nblocksy = pf_get_nblocksy(&surf->block, height);
00197    surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
00198    surf->usage = flags;
00199 
00200    assert(!surf->buffer);
00201    surf->buffer = winsys->buffer_create(winsys, alignment,
00202                                         PIPE_BUFFER_USAGE_PIXEL,
00203                                         surf->stride * height);
00204    if(!surf->buffer)
00205       return -1;
00206    
00207    return 0;
00208 }

static void surface_release ( struct pipe_winsys winsys,
struct pipe_surface **  s 
) [static]

Definition at line 212 of file sw_winsys.c.

References assert, pipe_surface::buffer, pipe_surface::refcount, pipe_surface::texture, and winsys_buffer_reference().

00213 {
00214    struct pipe_surface *surf = *s;
00215    assert(!surf->texture);
00216    surf->refcount--;
00217    if (surf->refcount == 0) {
00218       if (surf->buffer)
00219          winsys_buffer_reference(winsys, &surf->buffer, NULL);
00220       free(surf);
00221    }
00222    *s = NULL;
00223 }

static struct sw_pipe_buffer* sw_pipe_buffer ( struct pipe_buffer b  )  [static, read]

cast wrapper

Definition at line 68 of file sw_winsys.c.

00069 {
00070    return (struct sw_pipe_buffer *) b;
00071 }

static struct pipe_buffer* user_buffer_create ( struct pipe_winsys pws,
void *  ptr,
unsigned  bytes 
) [static, read]

Create buffer which wraps user-space data.

Definition at line 118 of file sw_winsys.c.

References sw_pipe_buffer::Base, CALLOC_STRUCT, sw_pipe_buffer::Data, pipe_buffer::refcount, pipe_buffer::size, TRUE, and sw_pipe_buffer::UserBuffer.

00119 {
00120    struct sw_pipe_buffer *buffer = CALLOC_STRUCT(sw_pipe_buffer);
00121    if (!buffer)
00122       return NULL;
00123 
00124    buffer->Base.refcount = 1;
00125    buffer->Base.size = bytes;
00126    buffer->UserBuffer = TRUE;
00127    buffer->Data = ptr;
00128 
00129    return &buffer->Base;
00130 }


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