summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/xlib
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2008-01-25 20:53:31 +0000
committerKeith Whitwell <keith@tungstengraphics.com>2008-01-25 20:53:31 +0000
commit1e0d30a515e4cac891b6c590f12a33e0e8a8e295 (patch)
tree72ffec9e89bd0bd9202fcfc39f5e7bdf881adcf2 /src/mesa/pipe/xlib
parent756d52ec12c41ee90ee9598dc9028cc134806bd2 (diff)
gallium: rename pipe_buffer_handle to pipe_buffer, rework pipebuffer/ code
Provide an actual definition of the pipe_buffer struct, containing the parameters used to create the buffer, and its refcount. Shift refcounting buffers out of the winsys interface, similar to surfaces & textures. Rework pipebuffer/ to reflect the fact these changes, and also Michel's reworking of the buffer interface.
Diffstat (limited to 'src/mesa/pipe/xlib')
-rw-r--r--src/mesa/pipe/xlib/xm_winsys.c80
-rw-r--r--src/mesa/pipe/xlib/xm_winsys_aub.c44
-rw-r--r--src/mesa/pipe/xlib/xm_winsys_aub.h4
3 files changed, 51 insertions, 77 deletions
diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c
index cb043ef394..c3cd22eea3 100644
--- a/src/mesa/pipe/xlib/xm_winsys.c
+++ b/src/mesa/pipe/xlib/xm_winsys.c
@@ -40,6 +40,7 @@
#include "pipe/p_format.h"
#include "pipe/p_context.h"
#include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
#include "pipe/softpipe/sp_winsys.h"
#ifdef GALLIUM_CELL
@@ -57,9 +58,8 @@
*/
struct xm_buffer
{
+ struct pipe_buffer base;
boolean userBuffer; /** Is this a user-space buffer? */
- int refcount;
- unsigned size;
void *data;
void *mapped;
};
@@ -106,63 +106,44 @@ xmesa_softpipe_winsys(struct softpipe_winsys *spws)
* buffer pointer...
*/
static INLINE struct xm_buffer *
-xm_bo( struct pipe_buffer_handle *bo )
+xm_buffer( struct pipe_buffer *buf )
{
- return (struct xm_buffer *) bo;
+ return (struct xm_buffer *)buf;
}
-static INLINE struct pipe_buffer_handle *
-pipe_bo( struct xm_buffer *bo )
-{
- return (struct pipe_buffer_handle *) bo;
-}
/* Most callbacks map direcly onto dri_bufmgr operations:
*/
static void *
-xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
+xm_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
unsigned flags)
{
- struct xm_buffer *xm_buf = xm_bo(buf);
+ struct xm_buffer *xm_buf = xm_buffer(buf);
xm_buf->mapped = xm_buf->data;
return xm_buf->mapped;
}
static void
-xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer_handle *buf)
+xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
{
- struct xm_buffer *xm_buf = xm_bo(buf);
+ struct xm_buffer *xm_buf = xm_buffer(buf);
xm_buf->mapped = NULL;
}
static void
-xm_buffer_reference(struct pipe_winsys *pws,
- struct pipe_buffer_handle **ptr,
- struct pipe_buffer_handle *buf)
+xm_buffer_destroy(struct pipe_winsys *pws,
+ struct pipe_buffer *buf)
{
- if (*ptr) {
- struct xm_buffer *oldBuf = xm_bo(*ptr);
- oldBuf->refcount--;
- assert(oldBuf->refcount >= 0);
- if (oldBuf->refcount == 0) {
- if (oldBuf->data) {
- if (!oldBuf->userBuffer)
- align_free(oldBuf->data);
- oldBuf->data = NULL;
- }
- free(oldBuf);
- }
- *ptr = NULL;
- }
+ struct xm_buffer *oldBuf = xm_buffer(buf);
- assert(!(*ptr));
-
- if (buf) {
- struct xm_buffer *newBuf = xm_bo(buf);
- newBuf->refcount++;
- *ptr = buf;
+ if (oldBuf->data) {
+ if (!oldBuf->userBuffer)
+ align_free(oldBuf->data);
+ oldBuf->data = NULL;
}
+
+ free(oldBuf);
}
@@ -174,7 +155,7 @@ static void
xmesa_display_surface_tiled(XMesaBuffer b, const struct pipe_surface *surf)
{
XImage *ximage = b->tempImage;
- struct xm_buffer *xm_buf = xm_bo(surf->buffer);
+ struct xm_buffer *xm_buf = xm_buffer(surf->buffer);
const uint tilesPerRow = (surf->width + TILE_SIZE - 1) / TILE_SIZE;
uint x, y;
@@ -214,7 +195,7 @@ void
xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf)
{
XImage *ximage = b->tempImage;
- struct xm_buffer *xm_buf = xm_bo(surf->buffer);
+ struct xm_buffer *xm_buf = xm_buffer(surf->buffer);
const struct xmesa_surface *xm_surf
= xmesa_surface((struct pipe_surface *) surf);
@@ -272,35 +253,38 @@ xm_get_name(struct pipe_winsys *pws)
}
-static struct pipe_buffer_handle *
+static struct pipe_buffer *
xm_buffer_create(struct pipe_winsys *pws,
unsigned alignment,
unsigned usage,
unsigned size)
{
struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
- buffer->refcount = 1;
+ buffer->base.refcount = 1;
+ buffer->base.alignment = alignment;
+ buffer->base.usage = usage;
+ buffer->base.size = size;
/* align to 16-byte multiple for Cell */
buffer->data = align_malloc(size, max(alignment, 16));
- buffer->size = size;
- return pipe_bo(buffer);
+ return &buffer->base;
}
/**
* Create buffer which wraps user-space data.
*/
-static struct pipe_buffer_handle *
+static struct pipe_buffer *
xm_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
{
struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
+ buffer->base.refcount = 1;
+ buffer->base.size = bytes;
buffer->userBuffer = TRUE;
- buffer->refcount = 1;
buffer->data = ptr;
- buffer->size = bytes;
- return pipe_bo(buffer);
+
+ return &buffer->base;
}
@@ -376,7 +360,7 @@ xm_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
surf->refcount--;
if (surf->refcount == 0) {
if (surf->buffer)
- winsys->buffer_reference(winsys, &surf->buffer, NULL);
+ pipe_buffer_reference(winsys, &surf->buffer, NULL);
free(surf);
}
*s = NULL;
@@ -407,7 +391,7 @@ xmesa_get_pipe_winsys_aub(void)
ws->user_buffer_create = xm_user_buffer_create;
ws->buffer_map = xm_buffer_map;
ws->buffer_unmap = xm_buffer_unmap;
- ws->buffer_reference = xm_buffer_reference;
+ ws->buffer_destroy = xm_buffer_destroy;
ws->surface_alloc = xm_surface_alloc;
ws->surface_alloc_storage = xm_surface_alloc_storage;
diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.c b/src/mesa/pipe/xlib/xm_winsys_aub.c
index 28dd07bc6e..bf41570257 100644
--- a/src/mesa/pipe/xlib/xm_winsys_aub.c
+++ b/src/mesa/pipe/xlib/xm_winsys_aub.c
@@ -38,6 +38,7 @@
#include "pipe/p_winsys.h"
#include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
#include "pipe/i965simple/brw_winsys.h"
#include "brw_aub.h"
#include "xm_winsys_aub.h"
@@ -79,22 +80,22 @@ aub_pipe_winsys( struct pipe_winsys *winsys )
static INLINE struct aub_buffer *
-aub_bo( struct pipe_buffer_handle *bo )
+aub_bo( struct pipe_buffer *bo )
{
return (struct aub_buffer *)bo;
}
-static INLINE struct pipe_buffer_handle *
+static INLINE struct pipe_buffer *
pipe_bo( struct aub_buffer *bo )
{
- return (struct pipe_buffer_handle *)bo;
+ return (struct pipe_buffer *)bo;
}
static void *aub_buffer_map(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
+ struct pipe_buffer *buf,
unsigned flags )
{
struct aub_buffer *sbo = aub_bo(buf);
@@ -109,7 +110,7 @@ static void *aub_buffer_map(struct pipe_winsys *winsys,
}
static void aub_buffer_unmap(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf)
+ struct pipe_buffer *buf)
{
struct aub_pipe_winsys *iws = aub_pipe_winsys(winsys);
struct aub_buffer *sbo = aub_bo(buf);
@@ -132,26 +133,15 @@ static void aub_buffer_unmap(struct pipe_winsys *winsys,
static void
-aub_buffer_reference(struct pipe_winsys *winsys,
- struct pipe_buffer_handle **ptr,
- struct pipe_buffer_handle *buf)
+aub_buffer_destroy(struct pipe_winsys *winsys,
+ struct pipe_buffer *buf)
{
- if (*ptr) {
- assert(aub_bo(*ptr)->refcount != 0);
- if (--(aub_bo(*ptr)->refcount) == 0)
- free(*ptr);
- *ptr = NULL;
- }
-
- if (buf) {
- aub_bo(buf)->refcount++;
- *ptr = buf;
- }
+ free(buf);
}
void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
+ struct pipe_buffer *buf,
unsigned long offset,
unsigned long size,
const void *data,
@@ -206,7 +196,7 @@ void xmesa_display_aub( /* struct pipe_winsys *winsys, */
/* Pipe has no concept of pools. We choose the tex/region pool
* for all buffers.
*/
-static struct pipe_buffer_handle *
+static struct pipe_buffer *
aub_buffer_create(struct pipe_winsys *winsys,
unsigned alignment,
unsigned usage,
@@ -231,7 +221,7 @@ aub_buffer_create(struct pipe_winsys *winsys,
}
-static struct pipe_buffer_handle *
+static struct pipe_buffer *
aub_user_buffer_create(struct pipe_winsys *winsys, void *ptr, unsigned bytes)
{
struct aub_buffer *sbo;
@@ -312,7 +302,7 @@ aub_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
surf->refcount--;
if (surf->refcount == 0) {
if (surf->buffer)
- winsys->buffer_reference(winsys, &surf->buffer, NULL);
+ pipe_buffer_reference(winsys, &surf->buffer, NULL);
free(surf);
}
*s = NULL;
@@ -351,7 +341,7 @@ xmesa_create_pipe_winsys_aub( void )
iws->winsys.user_buffer_create = aub_user_buffer_create;
iws->winsys.buffer_map = aub_buffer_map;
iws->winsys.buffer_unmap = aub_buffer_unmap;
- iws->winsys.buffer_reference = aub_buffer_reference;
+ iws->winsys.buffer_destroy = aub_buffer_destroy;
iws->winsys.flush_frontbuffer = aub_flush_frontbuffer;
iws->winsys.printf = aub_printf;
iws->winsys.get_name = aub_get_name;
@@ -439,7 +429,7 @@ static void aub_i965_batch_dword( struct brw_winsys *sws,
}
static void aub_i965_batch_reloc( struct brw_winsys *sws,
- struct pipe_buffer_handle *buf,
+ struct pipe_buffer *buf,
unsigned access_flags,
unsigned delta )
{
@@ -450,7 +440,7 @@ static void aub_i965_batch_reloc( struct brw_winsys *sws,
}
static unsigned aub_i965_get_buffer_offset( struct brw_winsys *sws,
- struct pipe_buffer_handle *buf,
+ struct pipe_buffer *buf,
unsigned access_flags )
{
return aub_bo(buf)->offset;
@@ -482,7 +472,7 @@ static void aub_i965_batch_flush( struct brw_winsys *sws,
static void aub_i965_buffer_subdata_typed(struct brw_winsys *winsys,
- struct pipe_buffer_handle *buf,
+ struct pipe_buffer *buf,
unsigned long offset,
unsigned long size,
const void *data,
diff --git a/src/mesa/pipe/xlib/xm_winsys_aub.h b/src/mesa/pipe/xlib/xm_winsys_aub.h
index c0fe449107..7bee199116 100644
--- a/src/mesa/pipe/xlib/xm_winsys_aub.h
+++ b/src/mesa/pipe/xlib/xm_winsys_aub.h
@@ -30,7 +30,7 @@
struct pipe_context;
struct pipe_winsys;
-struct pipe_buffer_handle;
+struct pipe_buffer;
struct pipe_surface;
struct pipe_winsys *
@@ -47,7 +47,7 @@ xmesa_create_i965simple( struct pipe_winsys *winsys );
void xmesa_buffer_subdata_aub(struct pipe_winsys *winsys,
- struct pipe_buffer_handle *buf,
+ struct pipe_buffer *buf,
unsigned long offset,
unsigned long size,
const void *data,