dri3: Free resources when drawable is destroyed.

Always nice to clean up after ourselves.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Keith Packard
2013-11-21 21:30:07 -08:00
committed by Kenneth Graunke
parent 568a27588d
commit 95b04850d0
2 changed files with 20 additions and 2 deletions

View File

@@ -265,14 +265,26 @@ dri3_create_context(struct glx_screen *base,
0, NULL, &error); 0, NULL, &error);
} }
static void
dri3_free_render_buffer(struct dri3_drawable *pdraw, struct dri3_buffer *buffer);
static void static void
dri3_destroy_drawable(__GLXDRIdrawable *base) dri3_destroy_drawable(__GLXDRIdrawable *base)
{ {
struct dri3_screen *psc = (struct dri3_screen *) base->psc; struct dri3_screen *psc = (struct dri3_screen *) base->psc;
struct dri3_drawable *pdraw = (struct dri3_drawable *) base; struct dri3_drawable *pdraw = (struct dri3_drawable *) base;
xcb_connection_t *c = XGetXCBConnection(pdraw->base.psc->dpy);
int i;
(*psc->core->destroyDrawable) (pdraw->driDrawable); (*psc->core->destroyDrawable) (pdraw->driDrawable);
for (i = 0; i < DRI3_NUM_BUFFERS; i++) {
if (pdraw->buffers[i])
dri3_free_render_buffer(pdraw, pdraw->buffers[i]);
}
if (pdraw->special_event)
xcb_unregister_for_special_event(c, pdraw->special_event);
free(pdraw); free(pdraw);
} }
@@ -736,6 +748,7 @@ dri3_alloc_render_buffer(struct glx_screen *glx_screen, Drawable draw,
fence_fd); fence_fd);
buffer->pixmap = pixmap; buffer->pixmap = pixmap;
buffer->own_pixmap = true;
buffer->sync_fence = sync_fence; buffer->sync_fence = sync_fence;
buffer->shm_fence = shm_fence; buffer->shm_fence = shm_fence;
buffer->width = width; buffer->width = width;
@@ -769,7 +782,8 @@ dri3_free_render_buffer(struct dri3_drawable *pdraw, struct dri3_buffer *buffer)
struct dri3_screen *psc = (struct dri3_screen *) pdraw->base.psc; struct dri3_screen *psc = (struct dri3_screen *) pdraw->base.psc;
xcb_connection_t *c = XGetXCBConnection(pdraw->base.psc->dpy); xcb_connection_t *c = XGetXCBConnection(pdraw->base.psc->dpy);
xcb_free_pixmap(c, buffer->pixmap); if (buffer->own_pixmap)
xcb_free_pixmap(c, buffer->pixmap);
xcb_sync_destroy_fence(c, buffer->sync_fence); xcb_sync_destroy_fence(c, buffer->sync_fence);
xshmfence_unmap_shm(buffer->shm_fence); xshmfence_unmap_shm(buffer->shm_fence);
(*psc->image->destroyImage)(buffer->image); (*psc->image->destroyImage)(buffer->image);
@@ -987,6 +1001,7 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable,
goto no_image; goto no_image;
buffer->pixmap = pixmap; buffer->pixmap = pixmap;
buffer->own_pixmap = false;
buffer->width = bp_reply->width; buffer->width = bp_reply->width;
buffer->height = bp_reply->height; buffer->height = bp_reply->height;
buffer->buffer_type = buffer_type; buffer->buffer_type = buffer_type;

View File

@@ -89,6 +89,7 @@ struct dri3_buffer {
uint32_t sync_fence; /* XID of X SyncFence object */ uint32_t sync_fence; /* XID of X SyncFence object */
struct xshmfence *shm_fence; /* pointer to xshmfence object */ struct xshmfence *shm_fence; /* pointer to xshmfence object */
GLboolean busy; /* Set on swap, cleared on IdleNotify */ GLboolean busy; /* Set on swap, cleared on IdleNotify */
GLboolean own_pixmap; /* We allocated the pixmap ID, free on destroy */
void *driverPrivate; void *driverPrivate;
uint32_t size; uint32_t size;
@@ -171,6 +172,8 @@ dri3_pixmap_buf_id(enum dri3_buffer_type buffer_type)
return DRI3_FRONT_ID; return DRI3_FRONT_ID;
} }
#define DRI3_NUM_BUFFERS (1 + DRI3_MAX_BACK)
struct dri3_drawable { struct dri3_drawable {
__GLXDRIdrawable base; __GLXDRIdrawable base;
__DRIdrawable *driDrawable; __DRIdrawable *driDrawable;
@@ -194,7 +197,7 @@ struct dri3_drawable {
uint64_t previous_time; uint64_t previous_time;
unsigned frames; unsigned frames;
struct dri3_buffer *buffers[1 + DRI3_MAX_BACK]; struct dri3_buffer *buffers[DRI3_NUM_BUFFERS];
int cur_back; int cur_back;
int depth; int depth;