Sometimes we need to duplicate an existing drm_fb, e.g. when pageflipping to the same buffer to kickstart the repaint loop. To handle situations like these, and simplify resource management for dumb and cursor buffers, refcount drm_fb.
Signed-off-by: Daniel Stone <dani...@collabora.com> Differential Revision: https://phabricator.freedesktop.org/D1491 --- libweston/compositor-drm.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c index aaf871d..6f4a873 100644 --- a/libweston/compositor-drm.c +++ b/libweston/compositor-drm.c @@ -137,6 +137,8 @@ struct drm_fb { BUFFER_GBM_SURFACE, /**< internal EGL rendering */ } type; + int refcnt; + uint32_t fb_id, stride, handle, size; int width, height; int fd; @@ -299,6 +301,8 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int height, if (!fb) return NULL; + fb->refcnt = 1; + switch (format) { case GBM_FORMAT_XRGB8888: bpp = 32; @@ -379,6 +383,13 @@ err_fb: } static struct drm_fb * +drm_fb_ref(struct drm_fb *fb) +{ + fb->refcnt++; + return fb; +} + +static struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend, uint32_t format) { @@ -387,12 +398,13 @@ drm_fb_get_from_bo(struct gbm_bo *bo, int ret; if (fb) - return fb; + return drm_fb_ref(fb); fb = zalloc(sizeof *fb); if (fb == NULL) return NULL; + fb->refcnt = 1; fb->bo = bo; fb->width = gbm_bo_get_width(bo); @@ -458,6 +470,10 @@ drm_fb_unref(struct drm_fb *fb) if (!fb) return; + assert(fb->refcnt > 0); + if (--fb->refcnt > 0) + return; + switch (fb->type) { case BUFFER_PIXMAN_DUMB: /* nothing: pixman buffers are destroyed manually */ -- 2.9.3 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel