From patchwork Sat Dec 14 01:25:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 3344011 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6E2229F2A9 for ; Sat, 14 Dec 2013 01:27:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A2AD620707 for ; Sat, 14 Dec 2013 01:27:02 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id CBA9A20702 for ; Sat, 14 Dec 2013 01:27:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD6AA10D733 for ; Fri, 13 Dec 2013 17:27:01 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from keithp.com (home.keithp.com [63.227.221.253]) by gabe.freedesktop.org (Postfix) with ESMTP id D56A4FB7D6; Fri, 13 Dec 2013 17:25:55 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id 711DB1488009; Fri, 13 Dec 2013 17:25:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from keithp.com ([127.0.0.1]) by localhost (keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id beaS8EacupxY; Fri, 13 Dec 2013 17:25:50 -0800 (PST) Received: by keithp.com (Postfix, from userid 1033) id 2F2BB148800F; Fri, 13 Dec 2013 17:25:34 -0800 (PST) Received: from miki.keithp.com (localhost [127.0.0.1]) by keithp.com (Postfix) with ESMTP id 26BFC1498012; Fri, 13 Dec 2013 17:25:34 -0800 (PST) Received: by miki.keithp.com (Postfix, from userid 1001) id A849BDB2; Fri, 13 Dec 2013 17:25:31 -0800 (PST) From: Keith Packard To: mesa-dev@lists.freedesktop.org Subject: [PATCH 05/18] dri3: Free resources when drawable is destroyed. Date: Fri, 13 Dec 2013 17:25:17 -0800 Message-Id: <1386984330-26074-6-git-send-email-keithp@keithp.com> X-Mailer: git-send-email 1.8.4.4 In-Reply-To: <1386984330-26074-1-git-send-email-keithp@keithp.com> References: <1386984330-26074-1-git-send-email-keithp@keithp.com> Cc: dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Always nice to clean up after ourselves. Signed-off-by: Keith Packard --- src/glx/dri3_glx.c | 17 ++++++++++++++++- src/glx/dri3_priv.h | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index 1834c6d..4c0dc29 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -266,13 +266,25 @@ dri3_create_context(struct glx_screen *base, } static void +dri3_free_render_buffer(struct dri3_drawable *pdraw, struct dri3_buffer *buffer); + +static void dri3_destroy_drawable(__GLXDRIdrawable *base) { struct dri3_screen *psc = (struct dri3_screen *) base->psc; struct dri3_drawable *pdraw = (struct dri3_drawable *) base; + xcb_connection_t *c = XGetXCBConnection(pdraw->base.psc->dpy); + int i; (*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); } @@ -736,6 +748,7 @@ dri3_alloc_render_buffer(struct glx_screen *glx_screen, Drawable draw, fence_fd); buffer->pixmap = pixmap; + buffer->own_pixmap = true; buffer->sync_fence = sync_fence; buffer->shm_fence = shm_fence; 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; 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); xshmfence_unmap_shm(buffer->shm_fence); (*psc->image->destroyImage)(buffer->image); @@ -987,6 +1001,7 @@ dri3_get_pixmap_buffer(__DRIdrawable *driDrawable, goto no_image; buffer->pixmap = pixmap; + buffer->own_pixmap = false; buffer->width = bp_reply->width; buffer->height = bp_reply->height; buffer->buffer_type = buffer_type; diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h index 4bffeb7..2990c4f 100644 --- a/src/glx/dri3_priv.h +++ b/src/glx/dri3_priv.h @@ -89,6 +89,7 @@ struct dri3_buffer { uint32_t sync_fence; /* XID of X SyncFence object */ struct xshmfence *shm_fence; /* pointer to xshmfence object */ GLboolean busy; /* Set on swap, cleared on IdleNotify */ + GLboolean own_pixmap; /* We allocated the pixmap ID, free on destroy */ void *driverPrivate; uint32_t size; @@ -171,6 +172,8 @@ dri3_pixmap_buf_id(enum dri3_buffer_type buffer_type) return DRI3_FRONT_ID; } +#define DRI3_NUM_BUFFERS (1 + DRI3_MAX_BACK) + struct dri3_drawable { __GLXDRIdrawable base; __DRIdrawable *driDrawable; @@ -194,7 +197,7 @@ struct dri3_drawable { uint64_t previous_time; unsigned frames; - struct dri3_buffer *buffers[1 + DRI3_MAX_BACK]; + struct dri3_buffer *buffers[DRI3_NUM_BUFFERS]; int cur_back; int depth;