summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/xlib/xm_winsys.c
diff options
context:
space:
mode:
authorBen Skeggs <skeggsb@gmail.com>2008-01-27 12:35:33 +1100
committerBen Skeggs <skeggsb@gmail.com>2008-01-27 12:35:33 +1100
commita556034514582dc8e1b8b65f56020031d513331b (patch)
tree182aaf4be24733e2943f9e39cfb86bc22f942efb /src/mesa/pipe/xlib/xm_winsys.c
parent9043323f1437f9c6791845b3ddbb9af912b45110 (diff)
parentb717de3238a028a3fdfbaf13eb02dbde262f03e7 (diff)
Merge branch 'upstream-gallium-0.1' into darktama-gallium-0.1
Diffstat (limited to 'src/mesa/pipe/xlib/xm_winsys.c')
-rw-r--r--src/mesa/pipe/xlib/xm_winsys.c149
1 files changed, 42 insertions, 107 deletions
diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c
index 10dc09b13c..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,105 +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;
}
-}
-static int
-xm_buffer_data(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
- unsigned size, const void *data, unsigned usage )
-{
- struct xm_buffer *xm_buf = xm_bo(buf);
- assert(!xm_buf->userBuffer);
- if (xm_buf->size != size) {
- if (xm_buf->data)
- align_free(xm_buf->data);
- /* align to 16-byte multiple for Cell */
- xm_buf->data = align_malloc(size, 16);
- xm_buf->size = size;
- }
- if (data)
- memcpy(xm_buf->data, data, size);
- return 0;
-}
-
-static int
-xm_buffer_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
- unsigned long offset, unsigned long size, const void *data)
-{
- struct xm_buffer *xm_buf = xm_bo(buf);
- GLubyte *b = (GLubyte *) xm_buf->data;
- assert(!xm_buf->userBuffer);
- assert(b);
- memcpy(b + offset, data, size);
- return 0;
-}
-
-static int
-xm_buffer_get_subdata(struct pipe_winsys *pws, struct pipe_buffer_handle *buf,
- unsigned long offset, unsigned long size, void *data)
-{
- const struct xm_buffer *xm_buf = xm_bo(buf);
- const GLubyte *b = (GLubyte *) xm_buf->data;
- assert(!xm_buf->userBuffer);
- assert(b);
- memcpy(data, b + offset, size);
- return 0;
+ free(oldBuf);
}
@@ -216,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;
@@ -256,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);
@@ -314,30 +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 flags,
- unsigned hints)
+ unsigned usage,
+ unsigned size)
{
struct xm_buffer *buffer = CALLOC_STRUCT(xm_buffer);
- buffer->refcount = 1;
- return pipe_bo(buffer);
+ 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));
+
+ 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;
}
@@ -359,7 +306,6 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys,
unsigned flags)
{
const unsigned alignment = 64;
- int ret;
surf->width = width;
surf->height = height;
@@ -372,19 +318,11 @@ xm_surface_alloc_storage(struct pipe_winsys *winsys,
#endif
assert(!surf->buffer);
- surf->buffer = winsys->buffer_create(winsys, alignment, 0, 0);
+ surf->buffer = winsys->buffer_create(winsys, alignment,
+ PIPE_BUFFER_USAGE_PIXEL,
+ surf->pitch * surf->cpp * height);
if(!surf->buffer)
return -1;
-
- ret = winsys->buffer_data(winsys,
- surf->buffer,
- surf->pitch * surf->cpp * height,
- NULL,
- 0);
- if(ret) {
- winsys->buffer_reference(winsys, &surf->buffer, NULL);
- return ret;
- }
return 0;
}
@@ -405,7 +343,7 @@ xm_surface_alloc(struct pipe_winsys *ws)
xms->surface.winsys = ws;
#ifdef GALLIUM_CELL
- if (getenv("GALLIUM_CELL")) {
+ if (!getenv("GALLIUM_NOCELL")) {
xms->tileSize = 32; /** probably temporary */
}
#endif
@@ -422,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;
@@ -453,10 +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_data = xm_buffer_data;
- ws->buffer_subdata = xm_buffer_subdata;
- ws->buffer_get_subdata = xm_buffer_get_subdata;
+ ws->buffer_destroy = xm_buffer_destroy;
ws->surface_alloc = xm_surface_alloc;
ws->surface_alloc_storage = xm_surface_alloc_storage;
@@ -511,7 +446,7 @@ xmesa_create_pipe_context(XMesaContext xmesa, uint pixelformat)
struct pipe_context *pipe;
#ifdef GALLIUM_CELL
- if (getenv("GALLIUM_CELL")) {
+ if (!getenv("GALLIUM_NOCELL")) {
struct cell_winsys *cws = cell_get_winsys(pixelformat);
pipe = cell_create_context(pws, cws);
if (pipe)