From 3eaf882a662f719845ead1017e28a121cbce86fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 18 Dec 2007 22:01:35 +0000 Subject: [PATCH] gallium: Alternative mm_bufmgr_create_from_buffer constructor for mm pool managers. --- src/mesa/pipe/pipebuffer/pb_bufmgr.h | 11 ++++++++++- src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c | 34 ++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr.h b/src/mesa/pipe/pipebuffer/pb_bufmgr.h index 0e6c3a8..12e3632 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr.h +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr.h @@ -65,7 +65,7 @@ struct buffer_manager /* XXX: we will likely need more allocation flags */ struct pipe_buffer * (*create_buffer)( struct buffer_manager *mgr, - size_t size); + size_t size ); void (*destroy)( struct buffer_manager *mgr ); @@ -96,6 +96,15 @@ struct buffer_manager * mm_bufmgr_create(struct buffer_manager *provider, size_t size, size_t align2); +/** + * Same as mm_bufmgr_create. + * + * Buffer will be release when the manager is destroyed. + */ +struct buffer_manager * +mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, + size_t size, size_t align2); + /** * Fenced buffer manager. diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c index 8e6dcf1..e184655 100644 --- a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c +++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c @@ -218,11 +218,14 @@ mm_bufmgr_destroy(struct buffer_manager *mgr) struct buffer_manager * -mm_bufmgr_create(struct buffer_manager *provider, - size_t size, size_t align2) +mm_bufmgr_create_from_buffer(struct pipe_buffer *buffer, + size_t size, size_t align2) { struct mm_buffer_manager *mm; + if(!buffer) + return NULL; + mm = (struct mm_buffer_manager *)calloc(1, sizeof(*mm)); if (!mm) return NULL; @@ -237,9 +240,7 @@ mm_bufmgr_create(struct buffer_manager *provider, _glthread_INIT_MUTEX(mm->mutex); - mm->buffer = provider->create_buffer(provider, size); - if (!mm->buffer) - goto failure; + mm->buffer = buffer; mm->map = buffer_map(mm->buffer, PIPE_BUFFER_FLAG_READ | PIPE_BUFFER_FLAG_WRITE ); @@ -257,9 +258,28 @@ if(mm->heap) mmDestroy(mm->heap); if(mm->map) buffer_unmap(mm->buffer); - if(mm->buffer) - buffer_release(mm->buffer); if(mm) free(mm); return NULL; } + + +struct buffer_manager * +mm_bufmgr_create(struct buffer_manager *provider, + size_t size, size_t align2) +{ + struct pipe_buffer *buffer; + struct buffer_manager *mgr; + + buffer = provider->create_buffer(provider, size); + if (!buffer) + return NULL; + + mgr = mm_bufmgr_create_from_buffer(buffer, size, align2); + if (!mgr) { + buffer_release(buffer); + return NULL; + } + + return mgr; +} -- 2.7.4