swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit 18acb9d5da07d984be4663c9513fb1af68c419de
parent 1b0c5c6271a711c499815c7a2b3a49da7c4b2e4a
Author: Michael Forney <mforney@mforney.org>
Date:   Sat,  2 Aug 2014 19:00:44 -0700

Make view_attach return a negative error code instead of just false

This way, the compositor can appropriately handle EACCES from a failed
page flip.

Diffstat:
Mlibswc/compositor.c | 18++++++++++--------
Mlibswc/cursor_plane.c | 26+++++++++++++++-----------
Mlibswc/framebuffer_plane.c | 37++++++++++++++++++++++---------------
Mlibswc/pointer.c | 6+++---
Mlibswc/view.c | 11++++++-----
Mlibswc/view.h | 6+++---
6 files changed, 59 insertions(+), 45 deletions(-)

diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -43,6 +43,7 @@ #include "util.h" #include "view.h" +#include <errno.h> #include <stdlib.h> #include <stdio.h> #include <assert.h> @@ -273,8 +274,8 @@ static void renderer_repaint(struct target * target, wld_flush(swc.drm->renderer); } -static bool renderer_attach(struct compositor_view * view, - struct wld_buffer * client_buffer) +static int renderer_attach(struct compositor_view * view, + struct wld_buffer * client_buffer) { struct wld_buffer * buffer; bool was_proxy = view->buffer != view->base.buffer; @@ -300,7 +301,7 @@ static bool renderer_attach(struct compositor_view * view, client_buffer->format, WLD_FLAG_MAP); if (!buffer) - return false; + return -ENOMEM; } else { @@ -324,7 +325,7 @@ static bool renderer_attach(struct compositor_view * view, view->buffer = buffer; - return true; + return 0; } static void renderer_flush_view(struct compositor_view * view) @@ -408,12 +409,13 @@ static bool update(struct view * base) return true; } -static bool attach(struct view * base, struct wld_buffer * buffer) +static int attach(struct view * base, struct wld_buffer * buffer) { struct compositor_view * view = (void *) base; + int ret; - if (!renderer_attach(view, buffer)) - return false; + if ((ret = renderer_attach(view, buffer)) < 0) + return ret; if (view->visible && view->base.buffer) { @@ -433,7 +435,7 @@ static bool attach(struct view * base, struct wld_buffer * buffer) } } - return true; + return 0; } static bool move(struct view * base, int32_t x, int32_t y) diff --git a/libswc/cursor_plane.c b/libswc/cursor_plane.c @@ -38,9 +38,10 @@ static bool update(struct view * view) return true; } -static bool attach(struct view * view, struct wld_buffer * buffer) +static int attach(struct view * view, struct wld_buffer * buffer) { struct cursor_plane * plane = wl_container_of(view, plane, view); + int ret; if (buffer) { @@ -49,28 +50,31 @@ static bool attach(struct view * view, struct wld_buffer * buffer) if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object)) { ERROR("Could not get export buffer to DRM handle\n"); - return false; + /* XXX: Not the best error code, but we don't know better until wld + * returns an actual error code. */ + return -EINVAL; } - if (drmModeSetCursor(swc.drm->fd, plane->crtc, object.u32, - buffer->width, buffer->height) != 0) + ret = drmModeSetCursor(swc.drm->fd, plane->crtc, object.u32, + buffer->width, buffer->height); + + if (ret < 0) { - ERROR("Could not set cursor: %s\n", strerror(errno)); - return false; + ERROR("Could not set cursor: %s\n", strerror(-ret)); + return ret; } } else { - if (drmModeSetCursor(swc.drm->fd, plane->crtc, 0, 0, 0) != 0) + if ((ret = drmModeSetCursor(swc.drm->fd, plane->crtc, 0, 0, 0)) < 0) { - ERROR("Could not unset cursor: %s\n", strerror(errno)); - return false; + ERROR("Could not unset cursor: %s\n", strerror(-ret)); + return ret; } } view_set_size_from_buffer(view, buffer); - - return true; + return 0; } static bool move(struct view * view, int32_t x, int32_t y) diff --git a/libswc/framebuffer_plane.c b/libswc/framebuffer_plane.c @@ -84,10 +84,11 @@ static void send_frame(void * data) view_frame(&plane->view, swc_time()); } -static bool attach(struct view * view, struct wld_buffer * buffer) +static int attach(struct view * view, struct wld_buffer * buffer) { struct framebuffer_plane * plane = wl_container_of(view, plane, view); union wld_object object; + int ret; if (!wld_export(buffer, WLD_USER_OBJECT_FRAMEBUFFER, &object)) { @@ -96,17 +97,19 @@ static bool attach(struct view * view, struct wld_buffer * buffer) if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object)) { ERROR("Could not get buffer handle\n"); - return false; + return -EINVAL; } if (!(framebuffer = malloc(sizeof *framebuffer))) - return false; + return -ENOMEM; - if (drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32, - buffer->pitch, object.u32, &framebuffer->id) != 0) + ret = drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32, + buffer->pitch, object.u32, &framebuffer->id); + + if (ret < 0) { free(framebuffer); - return false; + return ret; } framebuffer->exporter.export = &framebuffer_export; @@ -119,9 +122,11 @@ static bool attach(struct view * view, struct wld_buffer * buffer) if (plane->need_modeset) { - if (drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0, - plane->connectors.data, plane->connectors.size / 4, - &plane->mode.info) == 0) + ret = drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0, + plane->connectors.data, plane->connectors.size / 4, + &plane->mode.info); + + if (ret == 0) { wl_event_loop_add_idle(swc.event_loop, &send_frame, plane); plane->need_modeset = false; @@ -129,21 +134,23 @@ static bool attach(struct view * view, struct wld_buffer * buffer) else { ERROR("Could not set CRTC to next framebuffer: %s\n", - strerror(errno)); - return false; + strerror(-ret)); + return ret; } } else { - if (drmModePageFlip(swc.drm->fd, plane->crtc, object.u32, - DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler) != 0) + ret = drmModePageFlip(swc.drm->fd, plane->crtc, object.u32, + DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler); + + if (ret < 0) { ERROR("Page flip failed: %s\n", strerror(errno)); - return false; + return ret; } } - return true; + return 0; } static bool move(struct view * view, int32_t x, int32_t y) diff --git a/libswc/pointer.c b/libswc/pointer.c @@ -73,13 +73,13 @@ static bool update(struct view * view) return true; } -static bool attach(struct view * view, struct wld_buffer * buffer) +static int attach(struct view * view, struct wld_buffer * buffer) { struct pointer * pointer = wl_container_of(view, pointer, cursor.view); struct swc_surface * surface = pointer->cursor.surface; if (surface && !pixman_region32_not_empty(&surface->state.damage)) - return true; + return 0; wld_set_target_buffer(swc.shm->renderer, pointer->cursor.buffer); wld_fill_rectangle(swc.shm->renderer, 0x00000000, 0, 0, 64, 64); @@ -95,7 +95,7 @@ static bool attach(struct view * view, struct wld_buffer * buffer) if (view_set_size_from_buffer(view, buffer)) view_update_screens(view); - return true; + return 0; } static bool move(struct view * view, int32_t x, int32_t y) diff --git a/libswc/view.c b/libswc/view.c @@ -47,9 +47,11 @@ void view_finalize(struct view * view) wld_buffer_unreference(view->buffer); } -bool view_attach(struct view * view, struct wld_buffer * buffer) +int view_attach(struct view * view, struct wld_buffer * buffer) { - if (view->impl->attach(view, buffer)) + int ret; + + if ((ret = view->impl->attach(view, buffer)) == 0) { if (view->buffer) wld_buffer_unreference(view->buffer); @@ -58,10 +60,9 @@ bool view_attach(struct view * view, struct wld_buffer * buffer) wld_buffer_reference(buffer); view->buffer = buffer; - return true; } - else - return false; + + return ret; } bool view_update(struct view * view) diff --git a/libswc/view.h b/libswc/view.h @@ -95,7 +95,7 @@ struct view struct view_impl { bool (* update)(struct view * view); - bool (* attach)(struct view * view, struct wld_buffer * buffer); + int (* attach)(struct view * view, struct wld_buffer * buffer); bool (* move)(struct view * view, int32_t x, int32_t y); }; @@ -104,9 +104,9 @@ struct view_impl * * If buffer is NULL, the previous buffer is removed from the view. * - * @return Whether or not the buffer was successfully attached to the view. + * @return 0 on success, negative error code otherwise. */ -bool view_attach(struct view * view, struct wld_buffer * buffer); +int view_attach(struct view * view, struct wld_buffer * buffer); /** * Display a new frame consisting of the currently attached buffer.