output: refactor backend API

This updates the backend part of the output API. This is mostly renaming:
make_current becomes attach_render and swap_buffers becomes commit.

This also fixes the RDP backend to support NULL damage.
This commit is contained in:
Simon Ser 2019-04-23 19:26:21 +03:00 committed by Drew DeVault
parent 23e37e7b1d
commit 9a0f8a194c
14 changed files with 136 additions and 108 deletions

View File

@ -238,14 +238,13 @@ static struct wlr_drm_connector *get_drm_connector_from_output(
return (struct wlr_drm_connector *)wlr_output;
}
static bool drm_connector_make_current(struct wlr_output *output,
static bool drm_connector_attach_render(struct wlr_output *output,
int *buffer_age) {
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) {
static bool drm_connector_commit(struct wlr_output *output) {
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) {
@ -258,6 +257,11 @@ static bool drm_connector_swap_buffers(struct wlr_output *output,
}
struct wlr_drm_plane *plane = crtc->primary;
pixman_region32_t *damage = NULL;
if (output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &output->pending.damage;
}
struct gbm_bo *bo = swap_drm_surface_buffers(&plane->surf, damage);
if (drm->parent) {
bo = copy_drm_surface_mgpu(&plane->mgpu_surf, bo);
@ -334,7 +338,7 @@ bool set_drm_connector_gamma(struct wlr_output *output, size_t size,
bool ok = drm->iface->crtc_set_gamma(drm, conn->crtc, size, _r, _g, _b);
if (ok) {
wlr_output_update_needs_swap(output);
wlr_output_update_needs_commit(output);
free(conn->crtc->gamma_table);
conn->crtc->gamma_table = gamma_table;
@ -673,7 +677,7 @@ static bool drm_connector_set_cursor(struct wlr_output *output,
return false;
}
wlr_output_update_needs_swap(output);
wlr_output_update_needs_commit(output);
}
if (!update_texture) {
@ -733,7 +737,7 @@ static bool drm_connector_set_cursor(struct wlr_output *output,
}
bool ok = drm->iface->crtc_set_cursor(drm, crtc, bo);
if (ok) {
wlr_output_update_needs_swap(output);
wlr_output_update_needs_commit(output);
}
return ok;
}
@ -770,7 +774,7 @@ static bool drm_connector_move_cursor(struct wlr_output *output,
bool ok = drm->iface->crtc_move_cursor(drm, conn->crtc, box.x, box.y);
if (ok) {
wlr_output_update_needs_swap(output);
wlr_output_update_needs_commit(output);
}
return ok;
}
@ -832,8 +836,8 @@ static const struct wlr_output_impl output_impl = {
.set_cursor = drm_connector_set_cursor,
.move_cursor = drm_connector_move_cursor,
.destroy = drm_connector_destroy,
.make_current = drm_connector_make_current,
.swap_buffers = drm_connector_swap_buffers,
.attach_render = drm_connector_attach_render,
.commit = drm_connector_commit,
.set_gamma = set_drm_connector_gamma,
.get_gamma_size = drm_connector_get_gamma_size,
.export_dmabuf = drm_connector_export_dmabuf,
@ -1431,7 +1435,7 @@ static void drm_connector_cleanup(struct wlr_drm_connector *conn) {
wl_event_source_remove(conn->output.idle_frame);
conn->output.idle_frame = NULL;
}
conn->output.needs_swap = false;
conn->output.needs_commit = false;
conn->output.frame_pending = false;
/* Fallthrough */

View File

@ -56,15 +56,15 @@ static void output_transform(struct wlr_output *wlr_output,
output->wlr_output.transform = transform;
}
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
struct wlr_headless_output *output =
headless_output_from_output(wlr_output);
return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
buffer_age);
}
static bool output_swap_buffers(struct wlr_output *wlr_output,
pixman_region32_t *damage) {
static bool output_commit(struct wlr_output *wlr_output) {
// Nothing needs to be done for pbuffers
wlr_output_send_present(wlr_output, NULL);
return true;
@ -86,8 +86,8 @@ static const struct wlr_output_impl output_impl = {
.set_custom_mode = output_set_custom_mode,
.transform = output_transform,
.destroy = output_destroy,
.make_current = output_make_current,
.swap_buffers = output_swap_buffers,
.attach_render = output_attach_render,
.commit = output_commit,
};
bool wlr_output_is_headless(struct wlr_output *wlr_output) {

View File

@ -23,12 +23,12 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output,
return true;
}
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
return true;
}
static bool output_swap_buffers(struct wlr_output *wlr_output,
pixman_region32_t *damage) {
static bool output_commit(struct wlr_output *wlr_output) {
return true;
}
@ -45,8 +45,8 @@ static const struct wlr_output_impl output_impl = {
.transform = output_transform,
.set_custom_mode = output_set_custom_mode,
.destroy = output_destroy,
.make_current = output_make_current,
.swap_buffers = output_swap_buffers,
.attach_render = output_attach_render,
.commit = output_commit,
};
bool wlr_output_is_noop(struct wlr_output *wlr_output) {

View File

@ -69,7 +69,8 @@ static void output_transform(struct wlr_output *wlr_output,
output->wlr_output.transform = transform;
}
static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) {
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
struct wlr_rdp_output *output =
rdp_output_from_output(wlr_output);
return wlr_egl_make_current(&output->backend->egl, output->egl_surface,
@ -169,31 +170,39 @@ static bool nsc_swap_buffers(
return true;
}
static bool output_swap_buffers(
struct wlr_output *wlr_output, pixman_region32_t *damage) {
if (!pixman_region32_not_empty(damage)) {
return true;
}
static bool output_commit(struct wlr_output *wlr_output) {
struct wlr_rdp_output *output =
rdp_output_from_output(wlr_output);
bool ret = false;
// Update shadow buffer
pixman_region32_t output_region;
pixman_region32_init(&output_region);
pixman_region32_union_rect(&output_region, &output_region,
0, 0, wlr_output->width, wlr_output->height);
pixman_region32_t *damage = &output_region;
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &wlr_output->pending.damage;
}
int x = damage->extents.x1;
int y = damage->extents.y1;
int width = damage->extents.x2 - damage->extents.x1;
int height = damage->extents.y2 - damage->extents.y1;
// Update shadow buffer
struct wlr_renderer *renderer =
wlr_backend_get_renderer(&output->backend->backend);
// TODO performance: add support for flags
if (!wlr_renderer_read_pixels(renderer, WL_SHM_FORMAT_XRGB8888,
NULL, pixman_image_get_stride(output->shadow_surface),
width, height, damage->extents.x1, damage->extents.y1,
damage->extents.x1, damage->extents.y1,
pixman_image_get_data(output->shadow_surface))) {
return false;
ret = wlr_renderer_read_pixels(renderer, WL_SHM_FORMAT_XRGB8888,
NULL, pixman_image_get_stride(output->shadow_surface),
width, height, x, y, x, y,
pixman_image_get_data(output->shadow_surface));
if (!ret) {
goto out;
}
// Send along to clients
bool ret = false;
rdpSettings *settings = output->context->peer->settings;
if (settings->RemoteFxCodec) {
ret = rfx_swap_buffers(output, damage);
@ -202,8 +211,16 @@ static bool output_swap_buffers(
} else {
// This would perform like ass so why bother
wlr_log(WLR_ERROR, "Raw updates are not supported; use rfx or nsc");
ret = false;
}
if (!ret) {
goto out;
}
wlr_output_send_present(wlr_output, NULL);
out:
pixman_region32_fini(&output_region);
return ret;
}
@ -224,8 +241,8 @@ static const struct wlr_output_impl output_impl = {
.set_custom_mode = output_set_custom_mode,
.transform = output_transform,
.destroy = output_destroy,
.make_current = output_make_current,
.swap_buffers = output_swap_buffers,
.attach_render = output_attach_render,
.commit = output_commit,
};
bool wlr_output_is_rdp(struct wlr_output *wlr_output) {

View File

@ -50,7 +50,7 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output,
return true;
}
static bool output_make_current(struct wlr_output *wlr_output,
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
struct wlr_wl_output *output =
get_wl_output_from_output(wlr_output);
@ -58,8 +58,7 @@ static bool output_make_current(struct wlr_output *wlr_output,
buffer_age);
}
static bool output_swap_buffers(struct wlr_output *wlr_output,
pixman_region32_t *damage) {
static bool output_commit(struct wlr_output *wlr_output) {
struct wlr_wl_output *output =
get_wl_output_from_output(wlr_output);
@ -71,6 +70,11 @@ static bool output_swap_buffers(struct wlr_output *wlr_output,
output->frame_callback = wl_surface_frame(output->surface);
wl_callback_add_listener(output->frame_callback, &frame_listener, output);
pixman_region32_t *damage = NULL;
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &wlr_output->pending.damage;
}
if (!wlr_egl_swap_buffers(&output->backend->egl,
output->egl_surface, damage)) {
return false;
@ -220,8 +224,8 @@ static const struct wlr_output_impl output_impl = {
.set_custom_mode = output_set_custom_mode,
.transform = output_transform,
.destroy = output_destroy,
.make_current = output_make_current,
.swap_buffers = output_swap_buffers,
.attach_render = output_attach_render,
.commit = output_commit,
.set_cursor = output_set_cursor,
.move_cursor = output_move_cursor,
.schedule_frame = output_schedule_frame,

View File

@ -46,7 +46,7 @@ static void handle_x11_event(struct wlr_x11_backend *x11,
struct wlr_x11_output *output =
get_x11_output_from_window_id(x11, ev->window);
if (output != NULL) {
wlr_output_update_needs_swap(&output->wlr_output);
wlr_output_update_needs_commit(&output->wlr_output);
}
break;
}

View File

@ -95,7 +95,7 @@ static void output_destroy(struct wlr_output *wlr_output) {
free(output);
}
static bool output_make_current(struct wlr_output *wlr_output,
static bool output_attach_render(struct wlr_output *wlr_output,
int *buffer_age) {
struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
struct wlr_x11_backend *x11 = output->x11;
@ -103,11 +103,15 @@ static bool output_make_current(struct wlr_output *wlr_output,
return wlr_egl_make_current(&x11->egl, output->surf, buffer_age);
}
static bool output_swap_buffers(struct wlr_output *wlr_output,
pixman_region32_t *damage) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
static bool output_commit(struct wlr_output *wlr_output) {
struct wlr_x11_output *output = get_x11_output_from_output(wlr_output);
struct wlr_x11_backend *x11 = output->x11;
pixman_region32_t *damage = NULL;
if (wlr_output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &wlr_output->pending.damage;
}
if (!wlr_egl_swap_buffers(&x11->egl, output->surf, damage)) {
return false;
}
@ -120,8 +124,8 @@ static const struct wlr_output_impl output_impl = {
.set_custom_mode = output_set_custom_mode,
.transform = output_transform,
.destroy = output_destroy,
.make_current = output_make_current,
.swap_buffers = output_swap_buffers,
.attach_render = output_attach_render,
.commit = output_commit,
};
struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {

View File

@ -26,8 +26,8 @@ struct wlr_output_impl {
int32_t hotspot_x, int32_t hotspot_y, bool update_texture);
bool (*move_cursor)(struct wlr_output *output, int x, int y);
void (*destroy)(struct wlr_output *output);
bool (*make_current)(struct wlr_output *output, int *buffer_age);
bool (*swap_buffers)(struct wlr_output *output, pixman_region32_t *damage);
bool (*attach_render)(struct wlr_output *output, int *buffer_age);
bool (*commit)(struct wlr_output *output);
bool (*set_gamma)(struct wlr_output *output, size_t size,
const uint16_t *r, const uint16_t *g, const uint16_t *b);
size_t (*get_gamma_size)(struct wlr_output *output);
@ -43,7 +43,7 @@ void wlr_output_update_mode(struct wlr_output *output,
void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width,
int32_t height, int32_t refresh);
void wlr_output_update_enabled(struct wlr_output *output, bool enabled);
void wlr_output_update_needs_swap(struct wlr_output *output);
void wlr_output_update_needs_commit(struct wlr_output *output);
void wlr_output_damage_whole(struct wlr_output *output);
void wlr_output_send_frame(struct wlr_output *output);
void wlr_output_send_present(struct wlr_output *output,

View File

@ -97,7 +97,7 @@ struct wlr_output {
enum wl_output_subpixel subpixel;
enum wl_output_transform transform;
bool needs_swap;
bool needs_commit;
// damage for cursors and fullscreen surface, in output-local coordinates
pixman_region32_t damage;
bool frame_pending;
@ -110,7 +110,7 @@ struct wlr_output {
struct wl_signal frame;
// Emitted when buffers need to be swapped (because software cursors or
// fullscreen damage or because of backend-specific logic)
struct wl_signal needs_swap;
struct wl_signal needs_commit;
// Emitted right before buffer swap
struct wl_signal swap_buffers; // wlr_output_event_swap_buffers
// Emitted right after the buffer has been presented to the user

View File

@ -48,7 +48,7 @@ struct wlr_output_damage {
struct wl_listener output_mode;
struct wl_listener output_transform;
struct wl_listener output_scale;
struct wl_listener output_needs_swap;
struct wl_listener output_needs_commit;
struct wl_listener output_frame;
};

View File

@ -260,7 +260,7 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
const struct wlr_output_impl *impl, struct wl_display *display) {
assert(impl->make_current && impl->swap_buffers && impl->transform);
assert(impl->attach_render && impl->commit && impl->transform);
if (impl->set_cursor || impl->move_cursor) {
assert(impl->set_cursor && impl->move_cursor);
}
@ -273,7 +273,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend,
wl_list_init(&output->cursors);
wl_list_init(&output->resources);
wl_signal_init(&output->events.frame);
wl_signal_init(&output->events.needs_swap);
wl_signal_init(&output->events.needs_commit);
wl_signal_init(&output->events.swap_buffers);
wl_signal_init(&output->events.present);
wl_signal_init(&output->events.enable);
@ -363,7 +363,7 @@ struct wlr_output_mode *wlr_output_preferred_mode(struct wlr_output *output) {
}
bool wlr_output_attach_render(struct wlr_output *output, int *buffer_age) {
if (!output->impl->make_current(output, buffer_age)) {
if (!output->impl->attach_render(output, buffer_age)) {
return false;
}
@ -373,7 +373,7 @@ bool wlr_output_attach_render(struct wlr_output *output, int *buffer_age) {
bool wlr_output_preferred_read_format(struct wlr_output *output,
enum wl_shm_format *fmt) {
if (!output->impl->make_current(output, NULL)) {
if (!output->impl->attach_render(output, NULL)) {
return false;
}
@ -407,43 +407,41 @@ bool wlr_output_commit(struct wlr_output *output) {
output->idle_frame = NULL;
}
if (output->pending.committed & WLR_OUTPUT_STATE_BUFFER) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
pixman_region32_t *damage = NULL;
if (output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &output->pending.damage;
}
struct wlr_output_event_swap_buffers event = {
.output = output,
.when = &now,
.damage = damage,
};
wlr_signal_emit_safe(&output->events.swap_buffers, &event);
if (!output->impl->swap_buffers(output, damage)) {
return false;
}
struct wlr_output_cursor *cursor;
wl_list_for_each(cursor, &output->cursors, link) {
if (!cursor->enabled || !cursor->visible || cursor->surface == NULL) {
continue;
}
wlr_surface_send_frame_done(cursor->surface, &now);
}
output->frame_pending = true;
output->needs_swap = false;
output_state_clear(&output->pending);
return true;
} else {
if (!(output->pending.committed & WLR_OUTPUT_STATE_BUFFER)) {
wlr_log(WLR_ERROR, "Tried to commit without attaching a buffer");
return false;
}
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
pixman_region32_t *damage = NULL;
if (output->pending.committed & WLR_OUTPUT_STATE_DAMAGE) {
damage = &output->pending.damage;
}
struct wlr_output_event_swap_buffers event = {
.output = output,
.when = &now,
.damage = damage,
};
wlr_signal_emit_safe(&output->events.swap_buffers, &event);
if (!output->impl->commit(output)) {
return false;
}
struct wlr_output_cursor *cursor;
wl_list_for_each(cursor, &output->cursors, link) {
if (!cursor->enabled || !cursor->visible || cursor->surface == NULL) {
continue;
}
wlr_surface_send_frame_done(cursor->surface, &now);
}
output->frame_pending = true;
output->needs_commit = false;
output_state_clear(&output->pending);
return true;
}
@ -522,9 +520,9 @@ bool wlr_output_export_dmabuf(struct wlr_output *output,
return output->impl->export_dmabuf(output, attribs);
}
void wlr_output_update_needs_swap(struct wlr_output *output) {
output->needs_swap = true;
wlr_signal_emit_safe(&output->events.needs_swap, output);
void wlr_output_update_needs_commit(struct wlr_output *output) {
output->needs_commit = true;
wlr_signal_emit_safe(&output->events.needs_commit, output);
}
void wlr_output_damage_whole(struct wlr_output *output) {
@ -533,7 +531,7 @@ void wlr_output_damage_whole(struct wlr_output *output) {
pixman_region32_union_rect(&output->damage, &output->damage, 0, 0,
width, height);
wlr_output_update_needs_swap(output);
wlr_output_update_needs_commit(output);
}
struct wlr_output *wlr_output_from_resource(struct wl_resource *resource) {
@ -679,7 +677,7 @@ static void output_cursor_damage_whole(struct wlr_output_cursor *cursor) {
output_cursor_get_box(cursor, &box);
pixman_region32_union_rect(&cursor->output->damage, &cursor->output->damage,
box.x, box.y, box.width, box.height);
wlr_output_update_needs_swap(cursor->output);
wlr_output_update_needs_commit(cursor->output);
}
static void output_cursor_reset(struct wlr_output_cursor *cursor) {

View File

@ -31,9 +31,10 @@ static void output_handle_scale(struct wl_listener *listener, void *data) {
wlr_output_damage_add_whole(output_damage);
}
static void output_handle_needs_swap(struct wl_listener *listener, void *data) {
static void output_handle_needs_commit(struct wl_listener *listener,
void *data) {
struct wlr_output_damage *output_damage =
wl_container_of(listener, output_damage, output_needs_swap);
wl_container_of(listener, output_damage, output_needs_commit);
pixman_region32_union(&output_damage->current, &output_damage->current,
&output_damage->output->damage);
wlr_output_schedule_frame(output_damage->output);
@ -75,8 +76,8 @@ struct wlr_output_damage *wlr_output_damage_create(struct wlr_output *output) {
output_damage->output_transform.notify = output_handle_transform;
wl_signal_add(&output->events.scale, &output_damage->output_scale);
output_damage->output_scale.notify = output_handle_scale;
wl_signal_add(&output->events.needs_swap, &output_damage->output_needs_swap);
output_damage->output_needs_swap.notify = output_handle_needs_swap;
wl_signal_add(&output->events.needs_commit, &output_damage->output_needs_commit);
output_damage->output_needs_commit.notify = output_handle_needs_commit;
wl_signal_add(&output->events.frame, &output_damage->output_frame);
output_damage->output_frame.notify = output_handle_frame;
@ -92,7 +93,7 @@ void wlr_output_damage_destroy(struct wlr_output_damage *output_damage) {
wl_list_remove(&output_damage->output_mode.link);
wl_list_remove(&output_damage->output_transform.link);
wl_list_remove(&output_damage->output_scale.link);
wl_list_remove(&output_damage->output_needs_swap.link);
wl_list_remove(&output_damage->output_needs_commit.link);
wl_list_remove(&output_damage->output_frame.link);
pixman_region32_fini(&output_damage->current);
for (size_t i = 0; i < WLR_OUTPUT_DAMAGE_PREVIOUS_LEN; ++i) {
@ -102,7 +103,7 @@ void wlr_output_damage_destroy(struct wlr_output_damage *output_damage) {
}
bool wlr_output_damage_make_current(struct wlr_output_damage *output_damage,
bool *needs_swap, pixman_region32_t *damage) {
bool *needs_commit, pixman_region32_t *damage) {
struct wlr_output *output = output_damage->output;
int buffer_age = -1;
@ -136,7 +137,7 @@ bool wlr_output_damage_make_current(struct wlr_output_damage *output_damage,
}
}
*needs_swap = output->needs_swap || pixman_region32_not_empty(damage);
*needs_commit = output->needs_commit || pixman_region32_not_empty(damage);
return true;
}

View File

@ -135,8 +135,8 @@ static void frame_handle_copy(struct wl_client *client,
wl_resource_add_destroy_listener(buffer_resource, &frame->buffer_destroy);
frame->buffer_destroy.notify = frame_handle_buffer_destroy;
// Schedule a buffer swap
output->needs_swap = true;
// Schedule a buffer commit
output->needs_commit = true;
wlr_output_schedule_frame(output);
if (frame->overlay_cursor) {

View File

@ -145,8 +145,8 @@ static void screenshooter_shoot(struct wl_client *client,
state->frame_listener.notify = output_handle_frame;
wl_signal_add(&output->events.swap_buffers, &state->frame_listener);
// Schedule a buffer swap
output->needs_swap = true;
// Schedule a buffer commit
output->needs_commit = true;
wlr_output_schedule_frame(output);
}