dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Keith Packard <keithp@keithp.com>
To: mesa-dev@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Subject: [PATCH 05/18] dri3: Free resources when drawable is destroyed.
Date: Fri, 13 Dec 2013 17:25:17 -0800	[thread overview]
Message-ID: <1386984330-26074-6-git-send-email-keithp@keithp.com> (raw)
In-Reply-To: <1386984330-26074-1-git-send-email-keithp@keithp.com>

Always nice to clean up after ourselves.

Signed-off-by: Keith Packard <keithp@keithp.com>
---
 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;
 
-- 
1.8.4.4

  parent reply	other threads:[~2013-12-14  1:25 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-14  1:25 [PATCH 00/18] dri3+gallium patch series Keith Packard
2013-12-14  1:25 ` [PATCH 01/18] Remove glBlendColor and glBlendEquations decls from glext.h Keith Packard
2013-12-14  2:28   ` [Mesa-dev] " Kenneth Graunke
2013-12-14  6:56     ` Keith Packard
2013-12-20 18:24   ` Ian Romanick
2013-12-14  1:25 ` [PATCH 02/18] dri/swrast: Passing dri_context * instead of gl_context* to driContextSetFlags Keith Packard
2013-12-14  1:25 ` [PATCH 03/18] Don't use libudev for glx/dri3 Keith Packard
2013-12-14  1:25 ` [PATCH 04/18] dri3: Switch to libxshmfence version 1.1 Keith Packard
2013-12-14  2:35   ` [Mesa-dev] " Kenneth Graunke
2013-12-14  7:00     ` Keith Packard
2013-12-14  1:25 ` Keith Packard [this message]
2013-12-14  1:25 ` [PATCH 06/18] dri3: Clean up struct dri3_drawable Keith Packard
2013-12-14  1:25 ` [PATCH 07/18] dri3: Track full 64-bit SBC numbers, instead of just 32-bits Keith Packard
2013-12-14  1:25 ` [PATCH 08/18] dri3: Fix dri3_wait_for_sbc to wait for completion of requested SBC Keith Packard
2013-12-14  1:25 ` [PATCH 09/18] dri3: Enable GLX_INTEL_swap_event Keith Packard
2013-12-14  1:25 ` [PATCH 10/18] i965: Correct check for re-bound buffer in intel_update_image_buffer Keith Packard
2013-12-14  1:25 ` [PATCH 11/18] i965: Set fast color clear mcs_state on newly allocated image miptrees Keith Packard
2013-12-14  1:25 ` [PATCH 12/18] dri3: Rename DRI3_MAX_BACK to DRI3_NUM_BACK Keith Packard
2013-12-14  1:25 ` [PATCH 13/18] dri3: Flush XCB before blocking for special events Keith Packard
2013-12-14  1:25 ` [PATCH 14/18] dri3, i915, i965: Add __DRI_IMAGE_FOURCC_SARGB8888 Keith Packard
2013-12-14  1:25 ` [PATCH 15/18] gallium: Add __DRIimageDriverExtension support to gallium Keith Packard
2013-12-14 11:27   ` Marek Olšák
2013-12-27 20:27     ` Keith Packard
2014-01-03 20:03       ` Marek Olšák
2013-12-14  1:25 ` [PATCH 16/18] gallium/dri: fix unsetting of format when encountering depth/stencil Keith Packard
2013-12-14  1:25 ` [PATCH 17/18] nvc0: fix segfault if nv50_miptree_from_handle() fails Keith Packard
2013-12-14  1:25 ` [PATCH 18/18] gallium: Use base.stamp for all drawable invalidation checks Keith Packard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386984330-26074-6-git-send-email-keithp@keithp.com \
    --to=keithp@keithp.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=mesa-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).