pipe_surface now has a pointer to the winsys which create/owns the surface.
This allows clean surface deallocation w/out a rendering context.
if (surf) {
surf->format = format;
surf->refcount = 1;
+ surf->winsys = winsys;
}
return surf;
}
+static void
+intel_i915_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
+{
+ struct pipe_surface *surf = *s;
+ surf->refcount--;
+ if (surf->refcount == 0) {
+ if (surf->region)
+ winsys->region_release(winsys, &surf->region);
+ free(surf);
+ }
+ *s = NULL;
+}
+
+
+
static void
intel_printf( struct pipe_winsys *sws, const char *fmtString, ... )
{
iws->winsys.region_release = intel_i915_region_release;
iws->winsys.surface_alloc = intel_i915_surface_alloc;
+ iws->winsys.surface_release = intel_i915_surface_release;
return &iws->winsys;
}
#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.
{
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 */
/* opaque type */
struct pipe_buffer_handle;
+struct pipe_winsys;
+
/***
*** State objects
unsigned width, height;
unsigned offset; /**< offset from start of region, in bytes */
unsigned refcount;
+ struct pipe_winsys *winsys; /**< winsys which owns/created the surface */
};
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,
{
XMesaBuffer b;
GLframebuffer *fb;
+ struct pipe_winsys *winsys = xmesa_get_pipe_winsys();
ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER);
/*
* 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;
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);
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().
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;
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);
* 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;
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;
}
* 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);
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;
}
xms->surface.format = pipeFormat;
xms->surface.refcount = 1;
+ xms->surface.winsys = pipe->winsys;
return &xms->surface;
}
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.
+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;
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;
} bgr_t;
-struct xmesa_renderbuffer;
-
-
-
/** Framebuffer pixel formats */
enum pixel_format {
PF_Index, /**< Color Index mode */
*/
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
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,
st_renderbuffer_delete(struct gl_renderbuffer *rb)
{
struct st_renderbuffer *strb = st_renderbuffer(rb);
- GET_CURRENT_CONTEXT(ctx);
- if (ctx) {
- struct pipe_context *pipe = ctx->st->pipe;
- ASSERT(strb);
- if (strb && strb->surface) {
- if (strb->surface->region) {
- pipe->winsys->region_release(pipe->winsys, &strb->surface->region);
- }
- free(strb->surface);
- }
- }
- else {
- _mesa_warning(NULL, "st_renderbuffer_delete() called, but no current context");
+ ASSERT(strb);
+ if (strb->surface) {
+ struct pipe_winsys *ws = strb->surface->winsys;
+ ws->surface_release(ws, &strb->surface);
}
free(strb);
}