From 7d1a04e499564212a2a9aace12b05f424a357d3f Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 7 Nov 2007 08:05:09 -0700 Subject: Add winsys->surface_release() to complement winsys->surface_alloc(). pipe_surface now has a pointer to the winsys which create/owns the surface. This allows clean surface deallocation w/out a rendering context. --- src/mesa/pipe/p_inlines.h | 16 +++++----------- src/mesa/pipe/p_state.h | 3 +++ src/mesa/pipe/p_winsys.h | 2 ++ src/mesa/pipe/xlib/xm_api.c | 11 +++-------- src/mesa/pipe/xlib/xm_buffer.c | 24 +++++++++--------------- src/mesa/pipe/xlib/xm_surface.c | 8 ++++---- src/mesa/pipe/xlib/xm_winsys.c | 15 ++++++++++++++- src/mesa/pipe/xlib/xmesaP.h | 11 +++++------ 8 files changed, 45 insertions(+), 45 deletions(-) (limited to 'src/mesa/pipe') diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h index ea666fa20a..2418d016e1 100644 --- a/src/mesa/pipe/p_inlines.h +++ b/src/mesa/pipe/p_inlines.h @@ -29,7 +29,8 @@ #define P_INLINES_H #include "p_context.h" -//#include "p_util.h" +#include "p_winsys.h" + /** * Set 'ptr' to point to 'region' and update reference counting. @@ -68,16 +69,9 @@ pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf) { assert(ptr); if (*ptr) { - /* unreference the old thing */ - struct pipe_surface *oldSurf = *ptr; - assert(oldSurf->refcount > 0); - oldSurf->refcount--; - if (oldSurf->refcount == 0) { - /* free the old region */ - pipe_region_reference(&oldSurf->region, NULL); - FREE( oldSurf ); - } - *ptr = NULL; + struct pipe_winsys *winsys = (*ptr)->winsys; + winsys->surface_release(winsys, ptr); + assert(!*ptr); } if (surf) { /* reference the new thing */ diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 0e1a038c2e..848c32701f 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -60,6 +60,8 @@ struct pipe_surface; /* opaque type */ struct pipe_buffer_handle; +struct pipe_winsys; + /*** *** State objects @@ -281,6 +283,7 @@ struct pipe_surface unsigned width, height; unsigned offset; /**< offset from start of region, in bytes */ unsigned refcount; + struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ }; diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h index 5bc6e6475a..e4c888ad33 100644 --- a/src/mesa/pipe/p_winsys.h +++ b/src/mesa/pipe/p_winsys.h @@ -86,6 +86,8 @@ struct pipe_winsys struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws, unsigned format); + void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s); + /** * The buffer manager is modeled after the dri_bufmgr interface, which * in turn is modeled after the ARB_vertex_buffer_object extension, diff --git a/src/mesa/pipe/xlib/xm_api.c b/src/mesa/pipe/xlib/xm_api.c index 939dfe745b..ec889ca34f 100644 --- a/src/mesa/pipe/xlib/xm_api.c +++ b/src/mesa/pipe/xlib/xm_api.c @@ -301,6 +301,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, { XMesaBuffer b; GLframebuffer *fb; + struct pipe_winsys *winsys = xmesa_get_pipe_winsys(); ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); @@ -328,7 +329,7 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, /* * Front renderbuffer */ - b->frontxrb = xmesa_create_renderbuffer(NULL, 0, &vis->mesa_visual, GL_FALSE); + b->frontxrb = xmesa_create_renderbuffer(winsys, 0, &vis->mesa_visual, GL_FALSE); if (!b->frontxrb) { _mesa_free(b); return NULL; @@ -337,18 +338,12 @@ create_xmesa_buffer(XMesaDrawable d, BufferType type, b->frontxrb->drawable = d; b->frontxrb->pixmap = (XMesaPixmap) d; _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &b->frontxrb->St.Base); -#if 0 /* sketch... */ - { - struct pipe_surface *front_surf; - front_surf = xmesa_create_front_surface(vis, d); - } -#endif /* * Back renderbuffer */ if (vis->mesa_visual.doubleBufferMode) { - b->backxrb = xmesa_create_renderbuffer(NULL, 0, &vis->mesa_visual, GL_TRUE); + b->backxrb = xmesa_create_renderbuffer(winsys, 0, &vis->mesa_visual, GL_TRUE); if (!b->backxrb) { /* XXX free front xrb too */ _mesa_free(b); diff --git a/src/mesa/pipe/xlib/xm_buffer.c b/src/mesa/pipe/xlib/xm_buffer.c index b4a05ac685..7dc85bf2eb 100644 --- a/src/mesa/pipe/xlib/xm_buffer.c +++ b/src/mesa/pipe/xlib/xm_buffer.c @@ -241,6 +241,12 @@ alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height) static void xmesa_delete_renderbuffer(struct gl_renderbuffer *rb) { + struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); + if (xrb->St.surface) { + struct pipe_winsys *ws = xrb->St.surface->winsys; + ws->surface_release(ws, &xrb->St.surface); + } + /* XXX Note: the ximage or Pixmap attached to this renderbuffer * should probably get freed here, but that's currently done in * XMesaDestroyBuffer(). @@ -289,11 +295,6 @@ xmesa_alloc_front_storage(GLcontext *ctx, struct gl_renderbuffer *rb, if (!xrb->St.surface || !xrb->St.surface->region) finish_surface_init(ctx, xrb); -#if 0 - xmesa_set_renderbuffer_funcs(xrb, xmesa->pixelformat, - xmesa->xm_visual->BitsPerPixel); -#endif - /* surface info */ xms->surface.width = width; xms->surface.height = height; @@ -353,11 +354,6 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, xrb->origin4 = NULL; } -#if 0 - xmesa_set_renderbuffer_funcs(xrb, xmesa->pixelformat, - xmesa->xm_visual->BitsPerPixel); -#endif - if (!xrb->St.surface || !xrb->St.surface->region) finish_surface_init(ctx, xrb); @@ -381,11 +377,11 @@ xmesa_alloc_back_storage(GLcontext *ctx, struct gl_renderbuffer *rb, * renderbuffers. */ struct xmesa_renderbuffer * -xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual, +xmesa_create_renderbuffer(struct pipe_winsys *winsys, + GLuint name, const GLvisual *visual, GLboolean backBuffer) { struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer); - struct pipe_context *pipe = NULL;/*ctx->st->pipe;*/ if (xrb) { GLuint name = 0; GLuint pipeFormat = 0; @@ -416,11 +412,9 @@ xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual, xrb->St.Base.IndexBits = visual->indexBits; } /* only need to set Red/Green/EtcBits fields for user-created RBs */ - - xrb->St.surface = xmesa_new_color_surface(pipe, pipeFormat); + xrb->St.surface = xmesa_new_color_surface(winsys, pipeFormat); xms = (struct xmesa_surface *) xrb->St.surface; xms->xrb = xrb; - } return xrb; } diff --git a/src/mesa/pipe/xlib/xm_surface.c b/src/mesa/pipe/xlib/xm_surface.c index 9969cc728d..43e5050747 100644 --- a/src/mesa/pipe/xlib/xm_surface.c +++ b/src/mesa/pipe/xlib/xm_surface.c @@ -609,7 +609,7 @@ clear_32bit_ximage_surface(struct pipe_context *pipe, struct pipe_surface *ps, * have special/unique quad read/write functions for X. */ struct pipe_surface * -xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) +xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint pipeFormat) { struct xmesa_surface *xms = CALLOC_STRUCT(xmesa_surface); @@ -617,15 +617,14 @@ xmesa_new_color_surface(struct pipe_context *pipe, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; + xms->surface.winsys = winsys; /* Note, the region we allocate doesn't actually have any storage * since we're drawing into an XImage or Pixmap. * The region's size will get set in the xmesa_alloc_front/back_storage() * functions. */ - if (pipe) - xms->surface.region = pipe->winsys->region_alloc(pipe->winsys, - 1, 0, 0, 0x0); + xms->surface.region = winsys->region_alloc(winsys, 1, 1, 1, 0x0); return &xms->surface; } @@ -645,6 +644,7 @@ xmesa_surface_alloc(struct pipe_context *pipe, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; + xms->surface.winsys = pipe->winsys; return &xms->surface; } diff --git a/src/mesa/pipe/xlib/xm_winsys.c b/src/mesa/pipe/xlib/xm_winsys.c index f7e55ed8f7..b73fcab68d 100644 --- a/src/mesa/pipe/xlib/xm_winsys.c +++ b/src/mesa/pipe/xlib/xm_winsys.c @@ -284,6 +284,7 @@ xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) xms->surface.format = pipeFormat; xms->surface.refcount = 1; + xms->surface.winsys = ws; #if 0 /* * This is really just a softpipe surface, not an XImage/Pixmap surface. @@ -295,13 +296,24 @@ xm_surface_alloc(struct pipe_winsys *ws, GLuint pipeFormat) +static void +xm_surface_release(struct pipe_winsys *ws, struct pipe_surface **s) +{ + struct pipe_surface *surf = *s; + if (surf->region) + winsys->region_release(winsys, &surf->region); + free(surf); + *s = NULL; +} + + /** * Return pointer to a pipe_winsys object. * For Xlib, this is a singleton object. * Nothing special for the Xlib driver so no subclassing or anything. */ -static struct pipe_winsys * +struct pipe_winsys * xmesa_get_pipe_winsys(void) { static struct pipe_winsys *ws = NULL; @@ -325,6 +337,7 @@ xmesa_get_pipe_winsys(void) ws->region_release = xm_region_release; ws->surface_alloc = xm_surface_alloc; + ws->surface_release = xm_surface_release; ws->flush_frontbuffer = xm_flush_frontbuffer; ws->wait_idle = xm_wait_idle; diff --git a/src/mesa/pipe/xlib/xmesaP.h b/src/mesa/pipe/xlib/xmesaP.h index c70dc67608..ba0ccdbcec 100644 --- a/src/mesa/pipe/xlib/xmesaP.h +++ b/src/mesa/pipe/xlib/xmesaP.h @@ -51,10 +51,6 @@ typedef struct { } bgr_t; -struct xmesa_renderbuffer; - - - /** Framebuffer pixel formats */ enum pixel_format { PF_Index, /**< Color Index mode */ @@ -451,7 +447,8 @@ extern const int xmesa_kernel1[16]; */ extern struct xmesa_renderbuffer * -xmesa_create_renderbuffer(GLcontext *ctx, GLuint name, const GLvisual *visual, +xmesa_create_renderbuffer(struct pipe_winsys *winsys, + GLuint name, const GLvisual *visual, GLboolean backBuffer); extern void @@ -545,8 +542,10 @@ extern struct pipe_surface * xmesa_surface_alloc(struct pipe_context *pipe, GLuint format); extern struct pipe_surface * -xmesa_new_color_surface(struct pipe_context *pipe, GLuint format); +xmesa_new_color_surface(struct pipe_winsys *winsys, GLuint format); +extern struct pipe_winsys * +xmesa_get_pipe_winsys(void); extern void xmesa_get_tile(struct pipe_context *pipe, struct pipe_surface *ps, -- cgit v1.2.3