diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-08-13 10:51:50 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2017-08-13 11:38:03 -0400 |
commit | 41e735242dc8788618bb668ad70ea164e47099db (patch) | |
tree | 79b474aec3b822da9a8f64e3347603d4bb1920a5 | |
parent | 43868168897f628fe75157be9ab38ea63310c920 (diff) |
Remove wlr_output_state, update backends
-rw-r--r-- | backend/drm/backend.c | 7 | ||||
-rw-r--r-- | backend/drm/drm-atomic.c | 8 | ||||
-rw-r--r-- | backend/drm/drm-legacy.c | 4 | ||||
-rw-r--r-- | backend/drm/drm.c | 106 | ||||
-rw-r--r-- | backend/wayland/backend.c | 8 | ||||
-rw-r--r-- | backend/wayland/output.c | 85 | ||||
-rw-r--r-- | backend/wayland/wl_seat.c | 18 | ||||
-rw-r--r-- | include/backend/drm.h | 14 | ||||
-rw-r--r-- | include/backend/wayland.h | 12 | ||||
-rw-r--r-- | include/wlr/interfaces/wlr_output.h | 22 | ||||
-rw-r--r-- | include/wlr/types/wlr_output.h | 4 | ||||
-rw-r--r-- | types/wlr_output.c | 25 |
12 files changed, 149 insertions, 164 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c index d0cdc234..a2c9dff3 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -28,8 +28,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *_backend) { } struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend; for (size_t i = 0; backend->outputs && i < backend->outputs->length; ++i) { - struct wlr_output_state *output = backend->outputs->items[i]; - wlr_output_destroy(output->base); + struct wlr_drm_output *output = backend->outputs->items[i]; + wlr_output_destroy(&output->output); } wlr_udev_signal_remove(backend->udev, &backend->drm_invalidated); @@ -61,7 +61,7 @@ static void session_signal(struct wl_listener *listener, void *data) { wlr_log(L_INFO, "DRM fd resumed"); for (size_t i = 0; i < backend->outputs->length; ++i) { - struct wlr_output_state *output = backend->outputs->items[i]; + struct wlr_drm_output *output = backend->outputs->items[i]; wlr_drm_output_start_renderer(output); if (!output->crtc) { @@ -69,7 +69,6 @@ static void session_signal(struct wl_listener *listener, void *data) { } struct wlr_drm_plane *plane = output->crtc->cursor; - backend->iface->crtc_set_cursor(backend, output->crtc, plane ? plane->cursor_bo : NULL); } diff --git a/backend/drm/drm-atomic.c b/backend/drm/drm-atomic.c index 7111799d..64028812 100644 --- a/backend/drm/drm-atomic.c +++ b/backend/drm/drm-atomic.c @@ -42,8 +42,8 @@ static bool atomic_end(int drm_fd, struct atomic *atom) { return true; } -static bool atomic_commit(int drm_fd, struct atomic *atom, struct wlr_output_state *output, - uint32_t flag) { +static bool atomic_commit(int drm_fd, struct atomic *atom, + struct wlr_drm_output *output, uint32_t flag) { if (atom->failed) { return false; } @@ -88,7 +88,7 @@ static void set_plane_props(struct atomic *atom, struct wlr_drm_plane *plane, } static bool atomic_crtc_pageflip(struct wlr_drm_backend *backend, - struct wlr_output_state *output, + struct wlr_drm_output *output, struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) { if (mode) { @@ -114,7 +114,7 @@ static bool atomic_crtc_pageflip(struct wlr_drm_backend *backend, } static void atomic_conn_enable(struct wlr_drm_backend *backend, - struct wlr_output_state *output, bool enable) { + struct wlr_drm_output *output, bool enable) { struct wlr_drm_crtc *crtc = output->crtc; struct atomic atom; diff --git a/backend/drm/drm-legacy.c b/backend/drm/drm-legacy.c index 8caca193..5077fcab 100644 --- a/backend/drm/drm-legacy.c +++ b/backend/drm/drm-legacy.c @@ -6,7 +6,7 @@ #include "backend/drm-util.h" static bool legacy_crtc_pageflip(struct wlr_drm_backend *backend, - struct wlr_output_state *output, struct wlr_drm_crtc *crtc, + struct wlr_drm_output *output, struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) { if (mode) { drmModeSetCrtc(backend->fd, crtc->id, fb_id, 0, 0, @@ -19,7 +19,7 @@ static bool legacy_crtc_pageflip(struct wlr_drm_backend *backend, } static void legacy_conn_enable(struct wlr_drm_backend *backend, - struct wlr_output_state *output, bool enable) { + struct wlr_drm_output *output, bool enable) { drmModeConnectorSetProperty(backend->fd, output->connector, output->props.dpms, enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); } diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 8b6d97d3..13d5aa0b 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -282,11 +282,13 @@ static void wlr_drm_plane_swap_buffers(struct wlr_drm_renderer *renderer, plane->back = gbm_surface_lock_front_buffer(plane->gbm); } -static void wlr_drm_output_make_current(struct wlr_output_state *output) { +static void wlr_drm_output_make_current(struct wlr_output *_output) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; wlr_drm_plane_make_current(output->renderer, output->crtc->primary); } -static void wlr_drm_output_swap_buffers(struct wlr_output_state *output) { +static void wlr_drm_output_swap_buffers(struct wlr_output *_output) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); struct wlr_drm_renderer *renderer = output->renderer; @@ -299,7 +301,7 @@ static void wlr_drm_output_swap_buffers(struct wlr_output_state *output) { output->pageflip_pending = true; } -void wlr_drm_output_start_renderer(struct wlr_output_state *output) { +void wlr_drm_output_start_renderer(struct wlr_drm_output *output) { if (output->state != WLR_DRM_OUTPUT_CONNECTED) { return; } @@ -322,12 +324,13 @@ void wlr_drm_output_start_renderer(struct wlr_output_state *output) { bo = plane->back; } - drmModeModeInfo *mode = &output->base->current_mode->state->mode; + drmModeModeInfo *mode = &output->output.current_mode->state->mode; backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode); output->pageflip_pending = true; } -static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) { +static void wlr_drm_output_enable(struct wlr_output *_output, bool enable) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); if (output->state != WLR_DRM_OUTPUT_CONNECTED) { @@ -389,7 +392,7 @@ static void realloc_planes(struct wlr_drm_backend *backend, const uint32_t *crtc } static void realloc_crtcs(struct wlr_drm_backend *backend, - struct wlr_output_state *output) { + struct wlr_drm_output *output) { uint32_t crtc[backend->num_crtcs]; uint32_t crtc_res[backend->num_crtcs]; uint32_t possible_crtc[backend->outputs->length]; @@ -402,7 +405,7 @@ static void realloc_crtcs(struct wlr_drm_backend *backend, size_t index; for (size_t i = 0; i < backend->outputs->length; ++i) { - struct wlr_output_state *o = backend->outputs->items[i]; + struct wlr_drm_output *o = backend->outputs->items[i]; if (o == output) { index = i; } @@ -441,7 +444,7 @@ static void realloc_crtcs(struct wlr_drm_backend *backend, } if (crtc_res[i] != crtc[i]) { - struct wlr_output_state *o = backend->outputs->items[crtc_res[i]]; + struct wlr_drm_output *o = backend->outputs->items[crtc_res[i]]; o->crtc = &backend->crtcs[i]; } } @@ -449,12 +452,13 @@ static void realloc_crtcs(struct wlr_drm_backend *backend, realloc_planes(backend, crtc_res); } -static bool wlr_drm_output_set_mode(struct wlr_output_state *output, +static bool wlr_drm_output_set_mode(struct wlr_output *_output, struct wlr_output_mode *mode) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); - wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", output->base->name, + wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", output->output.name, mode->width, mode->height, mode->refresh); drmModeConnector *conn = drmModeGetConnector(backend->fd, output->connector); @@ -464,7 +468,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output, } if (conn->connection != DRM_MODE_CONNECTED || conn->count_modes == 0) { - wlr_log(L_ERROR, "%s is not connected", output->base->name); + wlr_log(L_ERROR, "%s is not connected", output->output.name); goto error_output; } @@ -482,28 +486,28 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output, realloc_crtcs(backend, output); if (!output->crtc) { - wlr_log(L_ERROR, "Unable to match %s with a CRTC", output->base->name); + wlr_log(L_ERROR, "Unable to match %s with a CRTC", output->output.name); goto error_enc; } struct wlr_drm_crtc *crtc = output->crtc; - wlr_log(L_DEBUG, "%s: crtc=%ju ovr=%jd pri=%jd cur=%jd", output->base->name, + wlr_log(L_DEBUG, "%s: crtc=%ju ovr=%jd pri=%jd cur=%jd", output->output.name, crtc - backend->crtcs, crtc->overlay ? crtc->overlay - backend->overlay_planes : -1, crtc->primary ? crtc->primary - backend->primary_planes : -1, crtc->cursor ? crtc->cursor - backend->cursor_planes : -1); output->state = WLR_DRM_OUTPUT_CONNECTED; - output->width = output->base->width = mode->width; - output->height = output->base->height = mode->height; - output->base->current_mode = mode; - wl_signal_emit(&output->base->events.resolution, output->base); + output->width = output->output.width = mode->width; + output->height = output->output.height = mode->height; + output->output.current_mode = mode; + wl_signal_emit(&output->output.events.resolution, &output->output); // Since realloc_crtcs can deallocate planes on OTHER outputs, // we actually need to reinitalise all of them for (size_t i = 0; i < backend->outputs->length; ++i) { - struct wlr_output_state *output = backend->outputs->items[i]; - struct wlr_output_mode *mode = output->base->current_mode; + struct wlr_drm_output *output = backend->outputs->items[i]; + struct wlr_output_mode *mode = output->output.current_mode; struct wlr_drm_crtc *crtc = output->crtc; if (output->state != WLR_DRM_OUTPUT_CONNECTED) { @@ -533,13 +537,14 @@ error_output: return false; } -static void wlr_drm_output_transform(struct wlr_output_state *output, +static void wlr_drm_output_transform(struct wlr_output *output, enum wl_output_transform transform) { - output->base->transform = transform; + output->transform = transform; } -static bool wlr_drm_output_set_cursor(struct wlr_output_state *output, +static bool wlr_drm_output_set_cursor(struct wlr_output *_output, const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); struct wlr_drm_renderer *renderer = output->renderer; @@ -588,7 +593,7 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output, // OpenGL will read the pixels out upside down, // so we need to flip the image vertically wlr_matrix_texture(plane->matrix, plane->width, plane->height, - output->base->transform ^ WL_OUTPUT_TRANSFORM_FLIPPED_180); + output->output.transform ^ WL_OUTPUT_TRANSFORM_FLIPPED_180); plane->wlr_rend = wlr_gles2_renderer_init(&backend->backend); if (!plane->wlr_rend) { @@ -638,14 +643,16 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output, return backend->iface->crtc_set_cursor(backend, crtc, bo); } -static bool wlr_drm_output_move_cursor(struct wlr_output_state *output, +static bool wlr_drm_output_move_cursor(struct wlr_output *_output, int x, int y) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); return backend->iface->crtc_move_cursor(backend, output->crtc, x, y); } -static void wlr_drm_output_destroy(struct wlr_output_state *output) { +static void wlr_drm_output_destroy(struct wlr_output *_output) { + struct wlr_drm_output *output = (struct wlr_drm_output *)_output; wlr_drm_output_cleanup(output, true); free(output); } @@ -662,7 +669,7 @@ static struct wlr_output_impl output_impl = { }; static int find_id(const void *item, const void *cmp_to) { - const struct wlr_output_state *output = item; + const struct wlr_drm_output *output = item; const uint32_t *id = cmp_to; if (output->connector < *id) { @@ -700,7 +707,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { continue; } - struct wlr_output_state *output; + struct wlr_drm_output *output; int index = list_seq_find(backend->outputs, find_id, &conn->connector_id); if (index == -1) { @@ -710,14 +717,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { drmModeFreeConnector(conn); continue; } - - output->base = wlr_output_create(&output_impl, output); - if (!output->base) { - wlr_log_errno(L_ERROR, "Allocation failed"); - drmModeFreeConnector(conn); - free(output); - continue; - } + wlr_output_init(&output->output, &output_impl); output->renderer = &backend->renderer; output->state = WLR_DRM_OUTPUT_DISCONNECTED; @@ -730,10 +730,10 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { drmModeFreeEncoder(curr_enc); } - output->base->phys_width = conn->mmWidth; - output->base->phys_height = conn->mmHeight; - output->base->subpixel = subpixel_map[conn->subpixel]; - snprintf(output->base->name, sizeof(output->base->name), "%s-%"PRIu32, + output->output.phys_width = conn->mmWidth; + output->output.phys_height = conn->mmHeight; + output->output.subpixel = subpixel_map[conn->subpixel]; + snprintf(output->output.name, sizeof(output->output.name), "%s-%"PRIu32, conn_get_name(conn->connector_type), conn->connector_type_id); @@ -743,12 +743,12 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { size_t edid_len = 0; uint8_t *edid = wlr_drm_get_prop_blob(backend->fd, output->connector, output->props.edid, &edid_len); - parse_edid(output->base, edid_len, edid); + parse_edid(&output->output, edid_len, edid); free(edid); - wlr_output_create_global(output->base, backend->display); + wlr_output_create_global(&output->output, backend->display); list_add(backend->outputs, output); - wlr_log(L_INFO, "Found display '%s'", output->base->name); + wlr_log(L_INFO, "Found display '%s'", output->output.name); } else { output = backend->outputs->items[index]; } @@ -756,7 +756,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { if (output->state == WLR_DRM_OUTPUT_DISCONNECTED && conn->connection == DRM_MODE_CONNECTED) { - wlr_log(L_INFO, "'%s' connected", output->base->name); + wlr_log(L_INFO, "'%s' connected", output->output.name); wlr_log(L_INFO, "Detected modes:"); for (int i = 0; i < conn->count_modes; ++i) { @@ -773,16 +773,16 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { wlr_log(L_INFO, " %"PRId32"@%"PRId32"@%"PRId32, mode->width, mode->height, mode->refresh); - list_add(output->base->modes, mode); + list_add(output->output.modes, mode); } output->state = WLR_DRM_OUTPUT_NEEDS_MODESET; - wlr_log(L_INFO, "Sending modesetting signal for '%s'", output->base->name); - wl_signal_emit(&backend->backend.events.output_add, output->base); + wlr_log(L_INFO, "Sending modesetting signal for '%s'", output->output.name); + wl_signal_emit(&backend->backend.events.output_add, &output->output); } else if (output->state == WLR_DRM_OUTPUT_CONNECTED && conn->connection != DRM_MODE_CONNECTED) { - wlr_log(L_INFO, "'%s' disconnected", output->base->name); + wlr_log(L_INFO, "'%s' disconnected", output->output.name); wlr_drm_output_cleanup(output, false); } @@ -794,7 +794,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec, void *user) { - struct wlr_output_state *output = user; + struct wlr_drm_output *output = user; struct wlr_drm_backend *backend = wl_container_of(output->renderer, backend, renderer); @@ -810,7 +810,7 @@ static void page_flip_handler(int fd, unsigned seq, } if (backend->session->active) { - wl_signal_emit(&output->base->events.frame, output->base); + wl_signal_emit(&output->output.events.frame, &output->output); } } @@ -824,7 +824,7 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) { return 1; } -static void restore_output(struct wlr_output_state *output, int fd) { +static void restore_output(struct wlr_drm_output *output, int fd) { // Wait for any pending pageflips to finish while (output->pageflip_pending) { wlr_drm_event(fd, 0, NULL); @@ -840,7 +840,7 @@ static void restore_output(struct wlr_output_state *output, int fd) { drmModeFreeCrtc(crtc); } -void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) { +void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) { if (!output) { return; } @@ -875,8 +875,8 @@ void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) { restore_output(output, renderer->fd); } wlr_log(L_INFO, "Emmiting destruction signal for '%s'", - output->base->name); - wl_signal_emit(&backend->backend.events.output_remove, output->base); + output->output.name); + wl_signal_emit(&backend->backend.events.output_remove, &output->output); break; case WLR_DRM_OUTPUT_DISCONNECTED: break; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 8ca63036..467d137b 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -111,11 +111,11 @@ bool wlr_backend_is_wl(struct wlr_backend *b) { return b->impl == &backend_impl; } -struct wlr_output *wlr_wl_output_for_surface(struct wlr_wl_backend *backend, - struct wl_surface *surface) { +struct wlr_wl_backend_output *wlr_wl_output_for_surface( + struct wlr_wl_backend *backend, struct wl_surface *surface) { for (size_t i = 0; i < backend->outputs->length; ++i) { - struct wlr_output *output = backend->outputs->items[i]; - if (output->state->surface == surface) { + struct wlr_wl_backend_output *output = backend->outputs->items[i]; + if (output->surface == surface) { return output; } } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 5416f112..6a7b9e54 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -12,10 +12,8 @@ static struct wl_callback_listener frame_listener; static void surface_frame_callback(void *data, struct wl_callback *cb, uint32_t time) { - struct wlr_output_state *output = data; - assert(output); - - struct wlr_output *wlr_output = output->wlr_output; + struct wlr_output *wlr_output = data; + assert(wlr_output); wl_signal_emit(&wlr_output->events.frame, wlr_output); wl_callback_destroy(cb); } @@ -24,7 +22,8 @@ static struct wl_callback_listener frame_listener = { .done = surface_frame_callback }; -static void wlr_wl_output_make_current(struct wlr_output_state *output) { +static void wlr_wl_output_make_current(struct wlr_output *_output) { + struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; if (!eglMakeCurrent(output->backend->egl.display, output->egl_surface, output->egl_surface, output->backend->egl.context)) { @@ -32,7 +31,8 @@ static void wlr_wl_output_make_current(struct wlr_output_state *output) { } } -static void wlr_wl_output_swap_buffers(struct wlr_output_state *output) { +static void wlr_wl_output_swap_buffers(struct wlr_output *_output) { + struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; output->frame_callback = wl_surface_frame(output->surface); wl_callback_add_listener(output->frame_callback, &frame_listener, output); if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) { @@ -40,13 +40,15 @@ static void wlr_wl_output_swap_buffers(struct wlr_output_state *output) { } } -static void wlr_wl_output_transform(struct wlr_output_state *output, +static void wlr_wl_output_transform(struct wlr_output *_output, enum wl_output_transform transform) { - output->wlr_output->transform = transform; + struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; + output->wlr_output.transform = transform; } -static void wlr_wl_output_destroy(struct wlr_output_state *output) { - wl_signal_emit(&output->backend->backend.events.output_remove, output->wlr_output); +static void wlr_wl_output_destroy(struct wlr_output *_output) { + struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output; + wl_signal_emit(&output->backend->backend.events.output_remove, &output->wlr_output); if (output->frame_callback) { wl_callback_destroy(output->frame_callback); } @@ -65,21 +67,20 @@ static struct wlr_output_impl output_impl = { }; void handle_ping(void* data, struct wl_shell_surface* ssurface, uint32_t serial) { - struct wlr_output_state *output = data; + struct wlr_wl_backend_output *output = data; assert(output && output->shell_surface == ssurface); wl_shell_surface_pong(ssurface, serial); } void handle_configure(void *data, struct wl_shell_surface *wl_shell_surface, uint32_t edges, int32_t width, int32_t height){ - struct wlr_output_state *ostate = data; - assert(ostate && ostate->shell_surface == wl_shell_surface); - struct wlr_output *output = ostate->wlr_output; - wl_egl_window_resize(ostate->egl_window, width, height, 0, 0); - output->width = width; - output->height = height; - wlr_output_update_matrix(output); - wl_signal_emit(&output->events.resolution, output); + struct wlr_wl_backend_output *output = data; + assert(output && output->shell_surface == wl_shell_surface); + wl_egl_window_resize(output->egl_window, width, height, 0, 0); + output->wlr_output.width = width; + output->wlr_output.height = height; + wlr_output_update_matrix(&output->wlr_output); + wl_signal_emit(&output->wlr_output.events.resolution, output); } void handle_popup_done(void *data, struct wl_shell_surface *wl_shell_surface) { @@ -100,18 +101,13 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { return NULL; } - struct wlr_output_state *ostate; - if (!(ostate = calloc(sizeof(struct wlr_output_state), 1))) { + struct wlr_wl_backend_output *output; + if (!(output = calloc(sizeof(struct wlr_wl_backend_output), 1))) { wlr_log(L_ERROR, "Failed to allocate wlr_output_state"); return NULL; } - - struct wlr_output *wlr_output = wlr_output_create(&output_impl, ostate); - if (!wlr_output) { - free(ostate); - wlr_log_errno(L_ERROR, "Allocation failed"); - return NULL; - } + wlr_output_init(&output->wlr_output, &output_impl); + struct wlr_output *wlr_output = &output->wlr_output; wlr_output->width = 640; wlr_output->height = 480; @@ -122,26 +118,27 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { backend->outputs->length + 1); wlr_output_update_matrix(wlr_output); - ostate->backend = backend; - ostate->wlr_output = wlr_output; + output->backend = backend; // TODO: error handling - ostate->surface = wl_compositor_create_surface(backend->compositor); - ostate->shell_surface = wl_shell_get_shell_surface(backend->shell, ostate->surface); + output->surface = wl_compositor_create_surface(backend->compositor); + output->shell_surface = + wl_shell_get_shell_surface(backend->shell, output->surface); - wl_shell_surface_set_class(ostate->shell_surface, "sway"); - wl_shell_surface_set_title(ostate->shell_surface, "sway-wl"); - wl_shell_surface_add_listener(ostate->shell_surface, &shell_surface_listener, ostate); - wl_shell_surface_set_toplevel(ostate->shell_surface); + wl_shell_surface_set_class(output->shell_surface, "sway"); + wl_shell_surface_set_title(output->shell_surface, "sway-wl"); + wl_shell_surface_add_listener(output->shell_surface, + &shell_surface_listener, output); + wl_shell_surface_set_toplevel(output->shell_surface); - ostate->egl_window = wl_egl_window_create(ostate->surface, + output->egl_window = wl_egl_window_create(output->surface, wlr_output->width, wlr_output->height); - ostate->egl_surface = wlr_egl_create_surface(&backend->egl, ostate->egl_window); + output->egl_surface = wlr_egl_create_surface(&backend->egl, output->egl_window); // start rendering loop per callbacks by rendering first frame - if (!eglMakeCurrent(ostate->backend->egl.display, - ostate->egl_surface, ostate->egl_surface, - ostate->backend->egl.context)) { + if (!eglMakeCurrent(output->backend->egl.display, + output->egl_surface, output->egl_surface, + output->backend->egl.context)) { wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error()); return false; } @@ -150,10 +147,10 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); - ostate->frame_callback = wl_surface_frame(ostate->surface); - wl_callback_add_listener(ostate->frame_callback, &frame_listener, ostate); + output->frame_callback = wl_surface_frame(output->surface); + wl_callback_add_listener(output->frame_callback, &frame_listener, output); - if (!eglSwapBuffers(ostate->backend->egl.display, ostate->egl_surface)) { + if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) { wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); return false; } diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 80cc194d..99a67df5 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -17,14 +17,9 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, wl_fixed_t surface_y) { struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); - struct wlr_output* output = wlr_wl_output_for_surface(dev->state->backend, - surface); - - if (!output) { - wlr_log(L_ERROR, "pointer entered invalid surface"); - return; - } - + struct wlr_wl_backend_output* output = + wlr_wl_output_for_surface(dev->state->backend, surface); + assert(output); dev->pointer->state->current_output = output; } @@ -40,16 +35,13 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, struct wlr_input_device *dev = data; assert(dev && dev->pointer && dev->pointer->state); struct wlr_pointer_state *state = dev->pointer->state; - - if(!state->current_output) { + if (!state->current_output) { wlr_log(L_ERROR, "pointer motion event without current output"); return; } - int width, height; - wl_egl_window_get_attached_size(state->current_output->state->egl_window, + wl_egl_window_get_attached_size(state->current_output->egl_window, &width, &height); - struct wlr_event_pointer_motion_absolute wlr_event; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; diff --git a/include/backend/drm.h b/include/backend/drm.h index 686d9f30..858b4616 100644 --- a/include/backend/drm.h +++ b/include/backend/drm.h @@ -12,6 +12,7 @@ #include <wlr/backend/session.h> #include <wlr/backend/drm.h> +#include <wlr/types/wlr_output.h> #include <wlr/egl.h> #include <wlr/util/list.h> @@ -137,8 +138,9 @@ struct wlr_output_mode_state { drmModeModeInfo mode; }; -struct wlr_output_state { - struct wlr_output *base; +struct wlr_drm_output { + struct wlr_output output; + enum wlr_drm_output_state state; uint32_t connector; @@ -161,10 +163,10 @@ struct wlr_output_state { struct wlr_drm_interface { // Enable or disable DPMS for output void (*conn_enable)(struct wlr_drm_backend *backend, - struct wlr_output_state *output, bool enable); + struct wlr_drm_output *output, bool enable); // Pageflip on crtc. If mode is non-NULL perform a full modeset using it. bool (*crtc_pageflip)(struct wlr_drm_backend *backend, - struct wlr_output_state *output, struct wlr_drm_crtc *crtc, + struct wlr_drm_output *output, struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode); // Enable the cursor buffer on crtc. Set bo to NULL to disable bool (*crtc_set_cursor)(struct wlr_drm_backend *backend, @@ -177,11 +179,11 @@ struct wlr_drm_interface { bool wlr_drm_check_features(struct wlr_drm_backend *drm); bool wlr_drm_resources_init(struct wlr_drm_backend *drm); void wlr_drm_resources_free(struct wlr_drm_backend *drm); -void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore); +void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore); void wlr_drm_scan_connectors(struct wlr_drm_backend *state); int wlr_drm_event(int fd, uint32_t mask, void *data); -void wlr_drm_output_start_renderer(struct wlr_output_state *output); +void wlr_drm_output_start_renderer(struct wlr_drm_output *output); #endif diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 3097c8cf..da4465fa 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -6,6 +6,7 @@ #include <wayland-egl.h> #include <wlr/egl.h> #include <wlr/backend/wayland.h> +#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_input_device.h> #include <wlr/util/list.h> @@ -29,9 +30,10 @@ struct wlr_wl_backend { char *seat_name; }; -struct wlr_output_state { +struct wlr_wl_backend_output { + struct wlr_output wlr_output; + struct wlr_wl_backend *backend; - struct wlr_output *wlr_output; struct wl_surface *surface; struct wl_shell_surface *shell_surface; struct wl_egl_window *egl_window; @@ -47,12 +49,12 @@ struct wlr_input_device_state { struct wlr_pointer_state { enum wlr_axis_source axis_source; - struct wlr_output *current_output; + struct wlr_wl_backend_output *current_output; }; void wlr_wl_registry_poll(struct wlr_wl_backend *backend); -struct wlr_output *wlr_wl_output_for_surface(struct wlr_wl_backend *backend, - struct wl_surface *surface); +struct wlr_wl_backend_output *wlr_wl_output_for_surface( + struct wlr_wl_backend *backend, struct wl_surface *surface); extern const struct wl_seat_listener seat_listener; diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 5f9bfdd2..efc8ef43 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -4,21 +4,19 @@ #include <stdbool.h> struct wlr_output_impl { - void (*enable)(struct wlr_output_state *state, bool enable); - bool (*set_mode)(struct wlr_output_state *state, - struct wlr_output_mode *mode); - void (*transform)(struct wlr_output_state *state, + void (*enable)(struct wlr_output *output, bool enable); + bool (*set_mode)(struct wlr_output *output, struct wlr_output_mode *mode); + void (*transform)(struct wlr_output *output, enum wl_output_transform transform); - bool (*set_cursor)(struct wlr_output_state *state, - const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height); - bool (*move_cursor)(struct wlr_output_state *state, int x, int y); - void (*destroy)(struct wlr_output_state *state); - void (*make_current)(struct wlr_output_state *state); - void (*swap_buffers)(struct wlr_output_state *state); + bool (*set_cursor)(struct wlr_output *output, const uint8_t *buf, + int32_t stride, uint32_t width, uint32_t height); + bool (*move_cursor)(struct wlr_output *output, int x, int y); + void (*destroy)(struct wlr_output *output); + void (*make_current)(struct wlr_output *output); + void (*swap_buffers)(struct wlr_output *output); }; -struct wlr_output *wlr_output_create(struct wlr_output_impl *impl, - struct wlr_output_state *state); +void wlr_output_init(struct wlr_output *output, const struct wlr_output_impl *impl); void wlr_output_free(struct wlr_output *output); void wlr_output_update_matrix(struct wlr_output *output); struct wl_global *wlr_output_create_global( diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index e57217c2..a669e3bb 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -14,12 +14,10 @@ struct wlr_output_mode { }; struct wlr_output_impl; -struct wlr_output_state; struct wlr_output { const struct wlr_output_impl *impl; - struct wlr_output_state *state; - void *user_data; + struct wl_global *wl_global; struct wl_list wl_resources; diff --git a/types/wlr_output.c b/types/wlr_output.c index 249ac5b8..1f8da45f 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -92,27 +92,24 @@ void wlr_output_update_matrix(struct wlr_output *output) { wlr_matrix_texture(output->transform_matrix, output->width, output->height, output->transform); } -struct wlr_output *wlr_output_create(struct wlr_output_impl *impl, - struct wlr_output_state *state) { - struct wlr_output *output = calloc(1, sizeof(struct wlr_output)); +void wlr_output_init(struct wlr_output *output, + const struct wlr_output_impl *impl) { output->impl = impl; - output->state = state; output->modes = list_create(); output->transform = WL_OUTPUT_TRANSFORM_NORMAL; wl_signal_init(&output->events.frame); wl_signal_init(&output->events.resolution); - return output; } void wlr_output_enable(struct wlr_output *output, bool enable) { - output->impl->enable(output->state, enable); + output->impl->enable(output, enable); } bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode) { if (!output->impl || !output->impl->set_mode) { return false; } - bool result = output->impl->set_mode(output->state, mode); + bool result = output->impl->set_mode(output, mode); if (result) { wlr_output_update_matrix(output); } @@ -121,13 +118,13 @@ bool wlr_output_set_mode(struct wlr_output *output, struct wlr_output_mode *mode void wlr_output_transform(struct wlr_output *output, enum wl_output_transform transform) { - output->impl->transform(output->state, transform); + output->impl->transform(output, transform); wlr_output_update_matrix(output); } bool wlr_output_set_cursor(struct wlr_output *output, const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) { - if (output->impl->set_cursor && output->impl->set_cursor(output->state, buf, + if (output->impl->set_cursor && output->impl->set_cursor(output, buf, stride, width, height)) { output->cursor.is_sw = false; return true; @@ -167,7 +164,7 @@ bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) { return false; } - return output->impl->move_cursor(output->state, x, y); + return output->impl->move_cursor(output, x, y); } void wlr_output_destroy(struct wlr_output *output) { @@ -175,10 +172,10 @@ void wlr_output_destroy(struct wlr_output *output) { return; } - output->impl->destroy(output->state); + output->impl->destroy(output); for (size_t i = 0; output->modes && i < output->modes->length; ++i) { struct wlr_output_mode *mode = output->modes->items[i]; - free(mode->state); + free(mode); free(mode); } list_free(output->modes); @@ -198,7 +195,7 @@ void wlr_output_effective_resolution(struct wlr_output *output, } void wlr_output_make_current(struct wlr_output *output) { - output->impl->make_current(output->state); + output->impl->make_current(output); } void wlr_output_swap_buffers(struct wlr_output *output) { @@ -212,5 +209,5 @@ void wlr_output_swap_buffers(struct wlr_output *output) { wlr_render_with_matrix(output->cursor.renderer, output->cursor.texture, &matrix); } - output->impl->swap_buffers(output->state); + output->impl->swap_buffers(output); } |