diff options
Diffstat (limited to 'src/mesa/pipe/pipebuffer/pb_buffer_malloc.c')
-rw-r--r-- | src/mesa/pipe/pipebuffer/pb_buffer_malloc.c | 51 |
1 files changed, 24 insertions, 27 deletions
diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c index 65ad51e1e7..f0ff1d347e 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c @@ -37,20 +37,21 @@ #include <assert.h> #include <stdlib.h> +#include "pipe/p_util.h" #include "pb_buffer.h" struct malloc_buffer { - struct pipe_buffer base; + struct pb_buffer base; void *data; }; -extern const struct pipe_buffer_vtbl malloc_buffer_vtbl; +extern const struct pb_vtbl malloc_buffer_vtbl; -static inline struct malloc_buffer * -malloc_buffer(struct pipe_buffer *buf) +static INLINE struct malloc_buffer * +malloc_buffer(struct pb_buffer *buf) { assert(buf); assert(buf->vtbl == &malloc_buffer_vtbl); @@ -59,22 +60,15 @@ malloc_buffer(struct pipe_buffer *buf) static void -malloc_buffer_reference(struct pipe_buffer *buf) +malloc_buffer_destroy(struct pb_buffer *buf) { - /* no-op */ -} - - -static void -malloc_buffer_release(struct pipe_buffer *buf) -{ - free(malloc_buffer(buf)->data); - free(buf); + align_free(malloc_buffer(buf)->data); + FREE(buf); } static void * -malloc_buffer_map(struct pipe_buffer *buf, +malloc_buffer_map(struct pb_buffer *buf, unsigned flags) { return malloc_buffer(buf)->data; @@ -82,15 +76,15 @@ malloc_buffer_map(struct pipe_buffer *buf, static void -malloc_buffer_unmap(struct pipe_buffer *buf) +malloc_buffer_unmap(struct pb_buffer *buf) { /* No-op */ } static void -malloc_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +malloc_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { *base_buf = buf; @@ -98,33 +92,36 @@ malloc_buffer_get_base_buffer(struct pipe_buffer *buf, } -const struct pipe_buffer_vtbl +const struct pb_vtbl malloc_buffer_vtbl = { - malloc_buffer_reference, - malloc_buffer_release, + malloc_buffer_destroy, malloc_buffer_map, malloc_buffer_unmap, malloc_buffer_get_base_buffer }; -struct pipe_buffer * -malloc_buffer_create(unsigned size) +struct pb_buffer * +pb_malloc_buffer_create(size_t size, + const struct pb_desc *desc) { struct malloc_buffer *buf; /* TODO: accept an alignment parameter */ /* TODO: do a single allocation */ - buf = (struct malloc_buffer *)malloc(sizeof(struct malloc_buffer)); + buf = (struct malloc_buffer *)MALLOC(sizeof(struct malloc_buffer)); if(!buf) return NULL; buf->base.vtbl = &malloc_buffer_vtbl; - - buf->data = malloc(size); + buf->base.base.alignment = desc->alignment; + buf->base.base.usage = desc->usage; + buf->base.base.size = size; + + buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment); if(!buf->data) { - free(buf); + FREE(buf); return NULL; } |