[PATCH weston 17/68] compositor-drm: Refactor destroy drm_fb function
Daniel Stone
daniels at collabora.com
Fri Dec 9 19:57:32 UTC 2016
From: Tomohito Esaki <etom at igel.co.jp>
The drm_fb destroy callback to mostly the same thing regardless of
whether the buffer is a dumb buffer or gbm buffer. This patch refactors
the common parts into a new function that can be called for both cases.
[daniels: Rebased on top of fb->fd changes, cosmetic changes.]
Differential Revision: https://phabricator.freedesktop.org/D1489
Signed-off-by: Tomohito Esaki <etom at igel.co.jp>
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
libweston/compositor-drm.c | 61 +++++++++++++++++++++++-----------------------
1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index af43a15..7dbfc6b 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -251,16 +251,39 @@ drm_sprite_crtc_supported(struct drm_output *output, struct drm_sprite *sprite)
}
static void
-drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
+drm_fb_destroy(struct drm_fb *fb)
{
- struct drm_fb *fb = data;
+ drmModeRmFB(fb->fd, fb->fb_id);
+ weston_buffer_reference(&fb->buffer_ref, NULL);
+ free(fb);
+}
+
+static void
+drm_fb_destroy_dumb(struct drm_fb *fb)
+{
+ struct drm_mode_destroy_dumb destroy_arg;
- if (fb->fb_id)
- drmModeRmFB(fb->fd, fb->fb_id);
+ if (!fb)
+ return;
- weston_buffer_reference(&fb->buffer_ref, NULL);
+ assert(fb->type == BUFFER_PIXMAN_DUMB);
+
+ munmap(fb->map, fb->size);
+
+ memset(&destroy_arg, 0, sizeof(destroy_arg));
+ destroy_arg.handle = fb->handle;
+ drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
+
+ drm_fb_destroy(fb);
+}
+
+static void
+drm_fb_destroy_gbm(struct gbm_bo *bo, void *data)
+{
+ struct drm_fb *fb = data;
- free(data);
+ assert(fb->type == BUFFER_GBM_SURFACE || fb->type == BUFFER_CLIENT);
+ drm_fb_destroy(fb);
}
static struct drm_fb *
@@ -359,30 +382,6 @@ err_fb:
return NULL;
}
-static void
-drm_fb_destroy_dumb(struct drm_fb *fb)
-{
- struct drm_mode_destroy_dumb destroy_arg;
-
- assert(fb->type == BUFFER_PIXMAN_DUMB);
-
- if (!fb->map)
- return;
-
- if (fb->fb_id)
- drmModeRmFB(fb->fd, fb->fb_id);
-
- weston_buffer_reference(&fb->buffer_ref, NULL);
-
- munmap(fb->map, fb->size);
-
- memset(&destroy_arg, 0, sizeof(destroy_arg));
- destroy_arg.handle = fb->handle;
- drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_arg);
-
- free(fb);
-}
-
static struct drm_fb *
drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
uint32_t format, enum drm_fb_type type)
@@ -450,7 +449,7 @@ drm_fb_get_from_bo(struct gbm_bo *bo, struct drm_backend *backend,
goto err_free;
}
- gbm_bo_set_user_data(bo, fb, drm_fb_destroy_callback);
+ gbm_bo_set_user_data(bo, fb, drm_fb_destroy_gbm);
return fb;
--
2.9.3
More information about the wayland-devel
mailing list