diff options
author | emersion <contact@emersion.fr> | 2018-09-17 22:25:20 +0200 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-09-18 11:06:01 +0200 |
commit | 139a905924e9c6cd22613dfbbe73c4642c993e41 (patch) | |
tree | 407d120898ff0a4c64de9a2d180ad07bd0d67e36 | |
parent | 02231554c843e8903e45ff3a96c65a8c4f836cce (diff) |
backend/drm: add assertions
-rw-r--r-- | backend/drm/backend.c | 18 | ||||
-rw-r--r-- | backend/drm/drm.c | 57 | ||||
-rw-r--r-- | include/backend/drm/drm.h | 2 |
3 files changed, 48 insertions, 29 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 1df5cdd1..bba79bda 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -15,8 +15,14 @@ #include "backend/drm/drm.h" #include "util/signal.h" +struct wlr_drm_backend *get_drm_backend_from_backend( + struct wlr_backend *wlr_backend) { + assert(wlr_backend_is_drm(wlr_backend)); + return (struct wlr_drm_backend *)wlr_backend; +} + static bool backend_start(struct wlr_backend *backend) { - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; + struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); scan_drm_connectors(drm); return true; } @@ -26,7 +32,7 @@ static void backend_destroy(struct wlr_backend *backend) { return; } - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; + struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); restore_drm_outputs(drm); @@ -50,7 +56,7 @@ static void backend_destroy(struct wlr_backend *backend) { static struct wlr_renderer *backend_get_renderer( struct wlr_backend *backend) { - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; + struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); if (drm->parent) { return drm->parent->renderer.wlr_rend; @@ -141,7 +147,9 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, wl_list_init(&drm->outputs); drm->fd = gpu_fd; - drm->parent = (struct wlr_drm_backend *)parent; + if (parent != NULL) { + drm->parent = get_drm_backend_from_backend(parent); + } drm->drm_invalidated.notify = drm_invalidated; wlr_session_signal_add(session, gpu_fd, &drm->drm_invalidated); @@ -187,6 +195,6 @@ error_fd: } struct wlr_session *wlr_drm_backend_get_session(struct wlr_backend *backend) { - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; + struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend); return drm->session; } diff --git a/backend/drm/drm.c b/backend/drm/drm.c index eac3a312..8e7c421d 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -205,16 +205,22 @@ void finish_drm_resources(struct wlr_drm_backend *drm) { free(drm->planes); } +static struct wlr_drm_connector *get_drm_connector_from_output( + struct wlr_output *wlr_output) { + assert(wlr_output_is_drm(wlr_output)); + return (struct wlr_drm_connector *)wlr_output; +} + static bool drm_connector_make_current(struct wlr_output *output, int *buffer_age) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); return make_drm_surface_current(&conn->crtc->primary->surf, buffer_age); } static bool drm_connector_swap_buffers(struct wlr_output *output, pixman_region32_t *damage) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (!drm->session->active) { return false; } @@ -254,8 +260,8 @@ static void fill_empty_gamma_table(uint32_t size, } static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (conn->crtc) { return drm->iface->crtc_get_gamma_size(drm, conn->crtc); @@ -266,8 +272,8 @@ static uint32_t drm_connector_get_gamma_size(struct wlr_output *output) { static bool drm_connector_set_gamma(struct wlr_output *output, uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (!conn->crtc) { return false; @@ -297,8 +303,8 @@ static bool drm_connector_set_gamma(struct wlr_output *output, static bool drm_connector_export_dmabuf(struct wlr_output *output, struct wlr_dmabuf_attributes *attribs) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (!drm->session->active) { return false; @@ -321,7 +327,8 @@ static void drm_connector_start_renderer(struct wlr_drm_connector *conn) { wlr_log(WLR_DEBUG, "Starting renderer on output '%s'", conn->output.name); - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; + struct wlr_drm_backend *drm = + get_drm_backend_from_backend(conn->output.backend); struct wlr_drm_crtc *crtc = conn->crtc; if (!crtc) { return; @@ -361,8 +368,8 @@ static void attempt_enable_needs_modeset(struct wlr_drm_backend *drm) { } bool enable_drm_connector(struct wlr_output *output, bool enable) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (conn->state != WLR_DRM_CONN_CONNECTED && conn->state != WLR_DRM_CONN_NEEDS_MODESET) { return false; @@ -456,8 +463,8 @@ static void drm_connector_cleanup(struct wlr_drm_connector *conn); static bool drm_connector_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (conn->crtc == NULL) { // Maybe we can steal a CRTC from a disabled output realloc_crtcs(drm, NULL); @@ -496,7 +503,7 @@ static bool drm_connector_set_mode(struct wlr_output *output, bool wlr_drm_connector_add_mode(struct wlr_output *output, const drmModeModeInfo *modeinfo) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); assert(modeinfo); if (modeinfo->type != DRM_MODE_TYPE_USERDEF) { @@ -528,10 +535,10 @@ static void drm_connector_transform(struct wlr_output *output, static bool drm_connector_set_cursor(struct wlr_output *output, struct wlr_texture *texture, int32_t scale, - enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y, - bool update_texture) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + enum wl_output_transform transform, + int32_t hotspot_x, int32_t hotspot_y, bool update_texture) { + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); struct wlr_drm_crtc *crtc = conn->crtc; if (!crtc) { @@ -664,8 +671,8 @@ static bool drm_connector_set_cursor(struct wlr_output *output, static bool drm_connector_move_cursor(struct wlr_output *output, int x, int y) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); + struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend); if (!conn->crtc) { return false; } @@ -700,7 +707,7 @@ static bool drm_connector_move_cursor(struct wlr_output *output, } static void drm_connector_destroy(struct wlr_output *output) { - struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; + struct wlr_drm_connector *conn = get_drm_connector_from_output(output); drm_connector_cleanup(conn); wl_event_source_remove(conn->retry_pageflip); wl_list_remove(&conn->link); @@ -742,7 +749,8 @@ static const int32_t subpixel_map[] = { }; static void dealloc_crtc(struct wlr_drm_connector *conn) { - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; + struct wlr_drm_backend *drm = + get_drm_backend_from_backend(conn->output.backend); if (conn->crtc == NULL) { return; } @@ -1121,7 +1129,8 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) { static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec, void *user) { struct wlr_drm_connector *conn = user; - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; + struct wlr_drm_backend *drm = + get_drm_backend_from_backend(conn->output.backend); conn->pageflip_pending = false; if (conn->state != WLR_DRM_CONN_CONNECTED || conn->crtc == NULL) { diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 6fe031e2..ac23cd9a 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -138,6 +138,8 @@ struct wlr_drm_connector { struct wl_list link; }; +struct wlr_drm_backend *get_drm_backend_from_backend( + struct wlr_backend *wlr_backend); bool check_drm_features(struct wlr_drm_backend *drm); bool init_drm_resources(struct wlr_drm_backend *drm); void finish_drm_resources(struct wlr_drm_backend *drm); |