Add wlr_output::enabled

This commit is contained in:
emersion 2018-01-04 12:46:15 +01:00
parent ce3a48c316
commit 771263380c
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
8 changed files with 66 additions and 48 deletions

View File

@ -257,6 +257,8 @@ static void wlr_drm_connector_enable(struct wlr_output *output, bool enable) {
if (enable) { if (enable) {
wlr_drm_connector_start_renderer(conn); wlr_drm_connector_start_renderer(conn);
} }
wlr_output_update_enabled(&conn->output, enable);
} }
static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in, static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in,
@ -722,7 +724,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
drmModeFreeConnector(drm_conn); drmModeFreeConnector(drm_conn);
continue; continue;
} }
wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl); wlr_output_init(&wlr_conn->output, &drm->backend, &output_impl,
drm->display);
struct wl_event_loop *ev = wl_display_get_event_loop(drm->display); struct wl_event_loop *ev = wl_display_get_event_loop(drm->display);
wlr_conn->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip, wlr_conn->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip,
@ -792,7 +795,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link); wl_list_insert(&wlr_conn->output.modes, &mode->wlr_mode.link);
} }
wlr_output_create_global(&wlr_conn->output, drm->display); wlr_output_update_enabled(&wlr_conn->output, true);
wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET;
wlr_log(L_INFO, "Sending modesetting signal for '%s'", wlr_log(L_INFO, "Sending modesetting signal for '%s'",
@ -802,7 +805,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
drm_conn->connection != DRM_MODE_CONNECTED) { drm_conn->connection != DRM_MODE_CONNECTED) {
wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name);
wlr_output_destroy_global(&wlr_conn->output); wlr_output_update_enabled(&wlr_conn->output, false);
wlr_drm_connector_cleanup(wlr_conn); wlr_drm_connector_cleanup(wlr_conn);
} }

View File

@ -15,7 +15,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) {
struct wlr_headless_output *output; struct wlr_headless_output *output;
wl_list_for_each(output, &backend->outputs, link) { wl_list_for_each(output, &backend->outputs, link) {
wl_event_source_timer_update(output->frame_timer, output->frame_delay); wl_event_source_timer_update(output->frame_timer, output->frame_delay);
wlr_output_create_global(&output->wlr_output, backend->display); wlr_output_update_enabled(&output->wlr_output, true);
wl_signal_emit(&backend->backend.events.output_add, wl_signal_emit(&backend->backend.events.output_add,
&output->wlr_output); &output->wlr_output);
} }

View File

@ -105,7 +105,8 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
return NULL; return NULL;
} }
output->backend = backend; output->backend = backend;
wlr_output_init(&output->wlr_output, &backend->backend, &output_impl); wlr_output_init(&output->wlr_output, &backend->backend, &output_impl,
backend->display);
struct wlr_output *wlr_output = &output->wlr_output; struct wlr_output *wlr_output = &output->wlr_output;
output->egl_surface = egl_create_surface(&backend->egl, width, height); output->egl_surface = egl_create_surface(&backend->egl, width, height);
@ -138,7 +139,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
if (backend->started) { if (backend->started) {
wl_event_source_timer_update(output->frame_timer, output->frame_delay); wl_event_source_timer_update(output->frame_timer, output->frame_delay);
wlr_output_create_global(wlr_output, backend->display); wlr_output_update_enabled(wlr_output, true);
wl_signal_emit(&backend->backend.events.output_add, wlr_output); wl_signal_emit(&backend->backend.events.output_add, wlr_output);
} }

View File

@ -261,7 +261,8 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
wlr_log(L_ERROR, "Failed to allocate wlr_wl_backend_output"); wlr_log(L_ERROR, "Failed to allocate wlr_wl_backend_output");
return NULL; return NULL;
} }
wlr_output_init(&output->wlr_output, &backend->backend, &output_impl); wlr_output_init(&output->wlr_output, &backend->backend, &output_impl,
backend->local_display);
struct wlr_output *wlr_output = &output->wlr_output; struct wlr_output *wlr_output = &output->wlr_output;
wlr_output_update_custom_mode(wlr_output, 1280, 720, 0); wlr_output_update_custom_mode(wlr_output, 1280, 720, 0);
@ -325,7 +326,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
} }
wl_list_insert(&backend->outputs, &output->link); wl_list_insert(&backend->outputs, &output->link);
wlr_output_create_global(wlr_output, backend->local_display); wlr_output_update_enabled(wlr_output, true);
wl_signal_emit(&backend->backend.events.output_add, wlr_output); wl_signal_emit(&backend->backend.events.output_add, wlr_output);
return wlr_output; return wlr_output;

View File

@ -181,7 +181,8 @@ static int signal_frame(void *data) {
static void init_atom(struct wlr_x11_backend *x11, struct wlr_x11_atom *atom, static void init_atom(struct wlr_x11_backend *x11, struct wlr_x11_atom *atom,
uint8_t only_if_exists, const char *name) { uint8_t only_if_exists, const char *name) {
atom->cookie = xcb_intern_atom(x11->xcb_conn, only_if_exists, strlen(name), name); atom->cookie = xcb_intern_atom(x11->xcb_conn, only_if_exists, strlen(name),
name);
atom->reply = xcb_intern_atom_reply(x11->xcb_conn, atom->cookie, NULL); atom->reply = xcb_intern_atom_reply(x11->xcb_conn, atom->cookie, NULL);
} }
@ -201,7 +202,8 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) {
output->x11 = x11; output->x11 = x11;
wlr_output_init(&output->wlr_output, &x11->backend, &output_impl); wlr_output_init(&output->wlr_output, &x11->backend, &output_impl,
x11->wl_display);
snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1"); snprintf(output->wlr_output.name, sizeof(output->wlr_output.name), "X11-1");
output->win = xcb_generate_id(x11->xcb_conn); output->win = xcb_generate_id(x11->xcb_conn);
@ -224,7 +226,7 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) {
xcb_map_window(x11->xcb_conn, output->win); xcb_map_window(x11->xcb_conn, output->win);
xcb_flush(x11->xcb_conn); xcb_flush(x11->xcb_conn);
wlr_output_create_global(&output->wlr_output, x11->wl_display); wlr_output_update_enabled(&output->wlr_output, true);
wl_signal_emit(&x11->backend.events.output_add, output); wl_signal_emit(&x11->backend.events.output_add, output);
wl_signal_emit(&x11->backend.events.input_add, &x11->keyboard_dev); wl_signal_emit(&x11->backend.events.input_add, &x11->keyboard_dev);

View File

@ -26,14 +26,11 @@ struct wlr_output_impl {
}; };
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl); const struct wlr_output_impl *impl, struct wl_display *display);
void wlr_output_free(struct wlr_output *output);
void wlr_output_update_mode(struct wlr_output *output, void wlr_output_update_mode(struct wlr_output *output,
struct wlr_output_mode *mode); struct wlr_output_mode *mode);
void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width, void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width,
int32_t height, int32_t refresh); int32_t height, int32_t refresh);
struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, void wlr_output_update_enabled(struct wlr_output *output, bool enabled);
struct wl_display *display);
void wlr_output_destroy_global(struct wlr_output *wlr_output);
#endif #endif

View File

@ -36,19 +36,19 @@ struct wlr_output_impl;
struct wlr_output { struct wlr_output {
const struct wlr_output_impl *impl; const struct wlr_output_impl *impl;
struct wlr_backend *backend; struct wlr_backend *backend;
struct wl_display *display;
struct wl_global *wl_global; struct wl_global *wl_global;
struct wl_list wl_resources; struct wl_list wl_resources;
uint32_t flags;
char name[16]; char name[16];
char make[48]; char make[48];
char model[16]; char model[16];
char serial[16]; char serial[16];
float scale;
int32_t width, height;
int32_t refresh; // mHz
int32_t phys_width, phys_height; // mm int32_t phys_width, phys_height; // mm
bool enabled;
float scale;
enum wl_output_subpixel subpixel; enum wl_output_subpixel subpixel;
enum wl_output_transform transform; enum wl_output_transform transform;
bool needs_swap; bool needs_swap;
@ -58,6 +58,8 @@ struct wlr_output {
// Note: some backends may have zero modes // Note: some backends may have zero modes
struct wl_list modes; struct wl_list modes;
struct wlr_output_mode *current_mode; struct wlr_output_mode *current_mode;
int32_t width, height;
int32_t refresh; // mHz
struct { struct {
struct wl_signal frame; struct wl_signal frame;

View File

@ -113,38 +113,39 @@ static void wl_output_bind(struct wl_client *wl_client, void *data,
wl_output_send_to_resource(wl_resource); wl_output_send_to_resource(wl_resource);
} }
static void handle_display_destroy(struct wl_listener *listener, void *data) { static void wlr_output_create_global(struct wlr_output *output) {
struct wlr_output *output = if (output->wl_global != NULL) {
wl_container_of(listener, output, display_destroy); return;
wlr_output_destroy_global(output); }
} struct wl_global *wl_global = wl_global_create(output->display,
&wl_output_interface, 3, output, wl_output_bind);
struct wl_global *wlr_output_create_global(struct wlr_output *wlr_output, output->wl_global = wl_global;
struct wl_display *display) { }
if (wlr_output->wl_global != NULL) {
return wlr_output->wl_global; static void wlr_output_destroy_global(struct wlr_output *output) {
} if (output->wl_global == NULL) {
struct wl_global *wl_global = wl_global_create(display,
&wl_output_interface, 3, wlr_output, wl_output_bind);
wlr_output->wl_global = wl_global;
wlr_output->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &wlr_output->display_destroy);
return wl_global;
}
void wlr_output_destroy_global(struct wlr_output *wlr_output) {
if (wlr_output->wl_global == NULL) {
return; return;
} }
wl_list_remove(&wlr_output->display_destroy.link);
struct wl_resource *resource, *tmp; struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &wlr_output->wl_resources) { wl_resource_for_each_safe(resource, tmp, &output->wl_resources) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
wl_global_destroy(wlr_output->wl_global); wl_global_destroy(output->wl_global);
wlr_output->wl_global = NULL; output->wl_global = NULL;
}
void wlr_output_update_enabled(struct wlr_output *output, bool enabled) {
if (output->enabled == enabled) {
return;
}
output->enabled = enabled;
if (enabled) {
wlr_output_create_global(output);
} else {
wlr_output_destroy_global(output);
}
} }
static void wlr_output_update_matrix(struct wlr_output *output) { static void wlr_output_update_matrix(struct wlr_output *output) {
@ -248,11 +249,18 @@ void wlr_output_set_scale(struct wlr_output *output, float scale) {
wl_signal_emit(&output->events.scale, output); wl_signal_emit(&output->events.scale, output);
} }
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_output *output =
wl_container_of(listener, output, display_destroy);
wlr_output_destroy_global(output);
}
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl) { const struct wlr_output_impl *impl, struct wl_display *display) {
assert(impl->make_current && impl->swap_buffers && impl->transform); assert(impl->make_current && impl->swap_buffers && impl->transform);
output->backend = backend; output->backend = backend;
output->impl = impl; output->impl = impl;
output->display = display;
wl_list_init(&output->modes); wl_list_init(&output->modes);
output->transform = WL_OUTPUT_TRANSFORM_NORMAL; output->transform = WL_OUTPUT_TRANSFORM_NORMAL;
output->scale = 1; output->scale = 1;
@ -264,6 +272,9 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
wl_signal_init(&output->events.scale); wl_signal_init(&output->events.scale);
wl_signal_init(&output->events.transform); wl_signal_init(&output->events.transform);
wl_signal_init(&output->events.destroy); wl_signal_init(&output->events.destroy);
output->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &output->display_destroy);
} }
void wlr_output_destroy(struct wlr_output *output) { void wlr_output_destroy(struct wlr_output *output) {
@ -271,6 +282,7 @@ void wlr_output_destroy(struct wlr_output *output) {
return; return;
} }
wl_list_remove(&output->display_destroy.link);
wlr_output_destroy_global(output); wlr_output_destroy_global(output);
wlr_output_set_fullscreen_surface(output, NULL); wlr_output_set_fullscreen_surface(output, NULL);