backend/drm: add assertions

This commit is contained in:
emersion 2018-09-17 22:25:20 +02:00
parent 02231554c8
commit 139a905924
3 changed files with 48 additions and 29 deletions

View File

@ -15,8 +15,14 @@
#include "backend/drm/drm.h" #include "backend/drm/drm.h"
#include "util/signal.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) { 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); scan_drm_connectors(drm);
return true; return true;
} }
@ -26,7 +32,7 @@ static void backend_destroy(struct wlr_backend *backend) {
return; 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); restore_drm_outputs(drm);
@ -50,7 +56,7 @@ static void backend_destroy(struct wlr_backend *backend) {
static struct wlr_renderer *backend_get_renderer( static struct wlr_renderer *backend_get_renderer(
struct wlr_backend *backend) { 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) { if (drm->parent) {
return drm->parent->renderer.wlr_rend; 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); wl_list_init(&drm->outputs);
drm->fd = gpu_fd; 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; drm->drm_invalidated.notify = drm_invalidated;
wlr_session_signal_add(session, gpu_fd, &drm->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_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; return drm->session;
} }

View File

@ -205,16 +205,22 @@ void finish_drm_resources(struct wlr_drm_backend *drm) {
free(drm->planes); 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, static bool drm_connector_make_current(struct wlr_output *output,
int *buffer_age) { 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); return make_drm_surface_current(&conn->crtc->primary->surf, buffer_age);
} }
static bool drm_connector_swap_buffers(struct wlr_output *output, static bool drm_connector_swap_buffers(struct wlr_output *output,
pixman_region32_t *damage) { pixman_region32_t *damage) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!drm->session->active) { if (!drm->session->active) {
return false; 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) { 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_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (conn->crtc) { if (conn->crtc) {
return drm->iface->crtc_get_gamma_size(drm, 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, static bool drm_connector_set_gamma(struct wlr_output *output,
uint32_t size, uint16_t *r, uint16_t *g, uint16_t *b) { 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_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!conn->crtc) { if (!conn->crtc) {
return false; 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, static bool drm_connector_export_dmabuf(struct wlr_output *output,
struct wlr_dmabuf_attributes *attribs) { struct wlr_dmabuf_attributes *attribs) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!drm->session->active) { if (!drm->session->active) {
return false; 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); 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; struct wlr_drm_crtc *crtc = conn->crtc;
if (!crtc) { if (!crtc) {
return; 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) { bool enable_drm_connector(struct wlr_output *output, bool enable) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (conn->state != WLR_DRM_CONN_CONNECTED if (conn->state != WLR_DRM_CONN_CONNECTED
&& conn->state != WLR_DRM_CONN_NEEDS_MODESET) { && conn->state != WLR_DRM_CONN_NEEDS_MODESET) {
return false; 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, static bool drm_connector_set_mode(struct wlr_output *output,
struct wlr_output_mode *mode) { struct wlr_output_mode *mode) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (conn->crtc == NULL) { if (conn->crtc == NULL) {
// Maybe we can steal a CRTC from a disabled output // Maybe we can steal a CRTC from a disabled output
realloc_crtcs(drm, NULL); 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, bool wlr_drm_connector_add_mode(struct wlr_output *output,
const drmModeModeInfo *modeinfo) { 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); assert(modeinfo);
if (modeinfo->type != DRM_MODE_TYPE_USERDEF) { 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, static bool drm_connector_set_cursor(struct wlr_output *output,
struct wlr_texture *texture, int32_t scale, struct wlr_texture *texture, int32_t scale,
enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y, enum wl_output_transform transform,
bool update_texture) { int32_t hotspot_x, int32_t hotspot_y, bool update_texture) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
if (!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, static bool drm_connector_move_cursor(struct wlr_output *output,
int x, int y) { int x, int y) {
struct wlr_drm_connector *conn = (struct wlr_drm_connector *)output; struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
struct wlr_drm_backend *drm = (struct wlr_drm_backend *)output->backend; struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
if (!conn->crtc) { if (!conn->crtc) {
return false; 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) { 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); drm_connector_cleanup(conn);
wl_event_source_remove(conn->retry_pageflip); wl_event_source_remove(conn->retry_pageflip);
wl_list_remove(&conn->link); wl_list_remove(&conn->link);
@ -742,7 +749,8 @@ static const int32_t subpixel_map[] = {
}; };
static void dealloc_crtc(struct wlr_drm_connector *conn) { 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) { if (conn->crtc == NULL) {
return; return;
} }
@ -1121,7 +1129,8 @@ void scan_drm_connectors(struct wlr_drm_backend *drm) {
static void page_flip_handler(int fd, unsigned seq, static void page_flip_handler(int fd, unsigned seq,
unsigned tv_sec, unsigned tv_usec, void *user) { unsigned tv_sec, unsigned tv_usec, void *user) {
struct wlr_drm_connector *conn = 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; conn->pageflip_pending = false;
if (conn->state != WLR_DRM_CONN_CONNECTED || conn->crtc == NULL) { if (conn->state != WLR_DRM_CONN_CONNECTED || conn->crtc == NULL) {

View File

@ -138,6 +138,8 @@ struct wlr_drm_connector {
struct wl_list link; 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 check_drm_features(struct wlr_drm_backend *drm);
bool init_drm_resources(struct wlr_drm_backend *drm); bool init_drm_resources(struct wlr_drm_backend *drm);
void finish_drm_resources(struct wlr_drm_backend *drm); void finish_drm_resources(struct wlr_drm_backend *drm);