Rather than magically trying to infer what the buffer is and what we
should do with it when we go to destroy it, add an explicit type
instead.

Signed-off-by: Daniel Stone <[email protected]>

Differential Revision: https://phabricator.freedesktop.org/D1488
---
 libweston/compositor-drm.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 4ef7343..5b4c28d 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -130,10 +130,16 @@ struct drm_mode {
 };
 
 struct drm_fb {
+       enum {
+               BUFFER_INVALID = 0, /**< never used */
+               BUFFER_CLIENT, /**< directly sourced from client */
+               BUFFER_PIXMAN_DUMB, /**< internal Pixman rendering */
+               BUFFER_GBM_SURFACE, /**< internal EGL rendering */
+       } type;
+
        uint32_t fb_id, stride, handle, size;
        int width, height;
        int fd;
-       int is_client_buffer;
        struct weston_buffer_reference buffer_ref;
 
        /* Used by gbm fbs */
@@ -290,6 +296,7 @@ drm_fb_create_dumb(struct drm_backend *b, int width, int 
height,
        if (ret)
                goto err_fb;
 
+       fb->type = BUFFER_PIXMAN_DUMB;
        fb->handle = create_arg.handle;
        fb->stride = create_arg.pitch;
        fb->size = create_arg.size;
@@ -352,6 +359,8 @@ 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;
 
@@ -440,9 +449,6 @@ static void
 drm_fb_set_buffer(struct drm_fb *fb, struct weston_buffer *buffer)
 {
        assert(fb->buffer_ref.buffer == NULL);
-
-       fb->is_client_buffer = 1;
-
        weston_buffer_reference(&fb->buffer_ref, buffer);
 }
 
@@ -452,15 +458,19 @@ drm_output_release_fb(struct drm_output *output, struct 
drm_fb *fb)
        if (!fb)
                return;
 
-       if (fb->map &&
-            (fb != output->dumb[0] && fb != output->dumb[1])) {
-               drm_fb_destroy_dumb(fb);
-       } else if (fb->bo) {
-               if (fb->is_client_buffer)
-                       gbm_bo_destroy(fb->bo);
-               else
-                       gbm_surface_release_buffer(output->gbm_surface,
-                                                  fb->bo);
+       switch (fb->type) {
+       case BUFFER_PIXMAN_DUMB:
+               /* nothing: pixman buffers are destroyed manually */
+               break;
+       case BUFFER_CLIENT:
+               gbm_bo_destroy(fb->bo);
+               break;
+       case BUFFER_GBM_SURFACE:
+               gbm_surface_release_buffer(output->gbm_surface, fb->bo);
+               break;
+       default:
+               assert(NULL);
+               break;
        }
 }
 
@@ -565,6 +575,7 @@ drm_output_prepare_scanout_view(struct drm_output *output,
                return NULL;
        }
 
+       output->next->type = BUFFER_CLIENT;
        drm_fb_set_buffer(output->next, buffer);
 
        return &output->fb_plane;
@@ -591,6 +602,7 @@ drm_output_render_gl(struct drm_output *output, 
pixman_region32_t *damage)
                gbm_surface_release_buffer(output->gbm_surface, bo);
                return;
        }
+       output->next->type = BUFFER_GBM_SURFACE;
 }
 
 static void
@@ -1060,6 +1072,7 @@ drm_output_prepare_overlay_view(struct drm_output *output,
                return NULL;
        }
 
+       s->next->type = BUFFER_CLIENT;
        drm_fb_set_buffer(s->next, ev->surface->buffer_ref.buffer);
 
        box = pixman_region32_extents(&ev->transform.boundingbox);
-- 
2.9.3

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to