mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-03-03 01:41:10 -05:00
Support direct scanout with src crop and dst boxes
Enable scene-tree direct scanout of a single buffer with various options for scaling and source crop. This is intended to support direct scanout for fullscreen video with/without scaling, letterboxing/pillarboxing (e.g. 4:3 content on a 16:9 display), and source crop (e.g. when 1920x1088 planes are used for 1920x1080 video). This works by explicitly specifying the source crop and destination box for the primary buffer in the output state. DRM atomic and libliftoff backends will turn this into a crop and scale of the plane (assuming the hardware supports that). For the Wayland/X11/DRM-legacy backends I just reject this so scanout will be disabled. The previous behaviour is preserved if buffer_src_box and buffer_dst_box are unset: the buffer is displayed at native size at the top-left of the output with no crop. The change to `struct wlr_output_state` makes this a binary breaking change (but this works transparently for scene-tree compositors like labwc after a recompile).
This commit is contained in:
parent
47fb00f66d
commit
c87ab6465d
10 changed files with 230 additions and 59 deletions
|
|
@ -548,14 +548,37 @@ static uint32_t output_compare_state(struct wlr_output *output,
|
|||
static bool output_basic_test(struct wlr_output *output,
|
||||
const struct wlr_output_state *state) {
|
||||
if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
|
||||
// If the size doesn't match, reject buffer (scaling is not
|
||||
// supported)
|
||||
struct wlr_fbox src_box;
|
||||
output_state_get_buffer_src_box(state, &src_box);
|
||||
|
||||
// Source box must be contained within the buffer
|
||||
if (src_box.x < 0.0 || src_box.y < 0.0 ||
|
||||
src_box.x + src_box.width > state->buffer->width ||
|
||||
src_box.y + src_box.height > state->buffer->height) {
|
||||
wlr_log(WLR_ERROR, "Tried to commit with invalid buffer_src_box");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Source box must not be empty (but it can be smaller than 1 pixel,
|
||||
// some DRM devices support sub-pixel crops)
|
||||
if (wlr_fbox_empty(&src_box)) {
|
||||
wlr_log(WLR_ERROR, "Tried to commit with an empty buffer_src_box");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Destination box cannot be entirely off-screen (but it also doesn't
|
||||
// have to be entirely on-screen). This also checks the dst box is
|
||||
// not empty.
|
||||
int pending_width, pending_height;
|
||||
output_pending_resolution(output, state,
|
||||
&pending_width, &pending_height);
|
||||
if (state->buffer->width != pending_width ||
|
||||
state->buffer->height != pending_height) {
|
||||
wlr_log(WLR_DEBUG, "Primary buffer size mismatch");
|
||||
output_pending_resolution(output, state, &pending_width, &pending_height);
|
||||
struct wlr_box output_box = {
|
||||
.width = pending_width,
|
||||
.height = pending_height
|
||||
};
|
||||
struct wlr_box dst_box;
|
||||
output_state_get_buffer_dst_box(state, &dst_box);
|
||||
if (!wlr_box_intersection(&output_box, &output_box, &dst_box)) {
|
||||
wlr_log(WLR_ERROR, "Primary buffer is entirely off-screen or 0-sized");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -845,6 +868,39 @@ void output_defer_present(struct wlr_output *output, struct wlr_output_event_pre
|
|||
deferred_present_event_handle_idle, deferred);
|
||||
}
|
||||
|
||||
void output_state_get_buffer_src_box(const struct wlr_output_state *state,
|
||||
struct wlr_fbox *out) {
|
||||
out->x = state->buffer_src_box.x;
|
||||
out->y = state->buffer_src_box.y;
|
||||
// If the source box is unset then default to the whole buffer.
|
||||
if (state->buffer_src_box.width == 0.0 &&
|
||||
state->buffer_src_box.height == 0.0) {
|
||||
out->width = (double)state->buffer->width;
|
||||
out->height = (double)state->buffer->height;
|
||||
} else {
|
||||
out->width = state->buffer_src_box.width;
|
||||
out->height = state->buffer_src_box.height;
|
||||
}
|
||||
}
|
||||
|
||||
void output_state_get_buffer_dst_box(const struct wlr_output_state *state,
|
||||
struct wlr_box *out) {
|
||||
out->x = state->buffer_dst_box.x;
|
||||
out->y = state->buffer_dst_box.y;
|
||||
// If the dst box is unset then default to source crop size (which itself
|
||||
// defaults to the whole buffer size if unset)
|
||||
if (state->buffer_dst_box.width == 0 &&
|
||||
state->buffer_dst_box.height == 0) {
|
||||
struct wlr_fbox src_box;
|
||||
output_state_get_buffer_src_box(state, &src_box);
|
||||
out->width = (int)src_box.width;
|
||||
out->height = (int)src_box.height;
|
||||
} else {
|
||||
out->width = state->buffer_dst_box.width;
|
||||
out->height = state->buffer_dst_box.height;
|
||||
}
|
||||
}
|
||||
|
||||
void wlr_output_send_request_state(struct wlr_output *output,
|
||||
const struct wlr_output_state *state) {
|
||||
uint32_t unchanged = output_compare_state(output, state);
|
||||
|
|
|
|||
|
|
@ -142,6 +142,8 @@ bool wlr_output_state_copy(struct wlr_output_state *dst,
|
|||
WLR_OUTPUT_STATE_WAIT_TIMELINE |
|
||||
WLR_OUTPUT_STATE_SIGNAL_TIMELINE);
|
||||
copy.buffer = NULL;
|
||||
copy.buffer_src_box = (struct wlr_fbox){0};
|
||||
copy.buffer_dst_box = (struct wlr_box){0};
|
||||
pixman_region32_init(©.damage);
|
||||
copy.gamma_lut = NULL;
|
||||
copy.gamma_lut_size = 0;
|
||||
|
|
@ -150,6 +152,8 @@ bool wlr_output_state_copy(struct wlr_output_state *dst,
|
|||
|
||||
if (src->committed & WLR_OUTPUT_STATE_BUFFER) {
|
||||
wlr_output_state_set_buffer(©, src->buffer);
|
||||
copy.buffer_src_box = src->buffer_src_box;
|
||||
copy.buffer_dst_box = src->buffer_dst_box;
|
||||
}
|
||||
|
||||
if (src->committed & WLR_OUTPUT_STATE_DAMAGE) {
|
||||
|
|
|
|||
|
|
@ -1831,6 +1831,7 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry,
|
|||
return false;
|
||||
}
|
||||
|
||||
// The native size of the buffer after any transform is applied
|
||||
int default_width = buffer->buffer->width;
|
||||
int default_height = buffer->buffer->height;
|
||||
wlr_output_transform_coords(buffer->transform, &default_width, &default_height);
|
||||
|
|
@ -1839,11 +1840,6 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry,
|
|||
.height = default_height,
|
||||
};
|
||||
|
||||
if (!wlr_fbox_empty(&buffer->src_box) &&
|
||||
!wlr_fbox_equal(&buffer->src_box, &default_box)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer->transform != data->transform) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1851,10 +1847,6 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry,
|
|||
struct wlr_box node_box = { .x = entry->x, .y = entry->y };
|
||||
scene_node_get_size(node, &node_box.width, &node_box.height);
|
||||
|
||||
if (!wlr_box_equal(&data->logical, &node_box)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer->primary_output == scene_output) {
|
||||
struct wlr_linux_dmabuf_feedback_v1_init_options options = {
|
||||
.main_renderer = scene_output->output->renderer,
|
||||
|
|
@ -1871,6 +1863,12 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!wlr_fbox_empty(&buffer->src_box) &&
|
||||
!wlr_fbox_equal(&buffer->src_box, &default_box)) {
|
||||
pending.buffer_src_box = buffer->src_box;
|
||||
}
|
||||
pending.buffer_dst_box = node_box;
|
||||
|
||||
wlr_output_state_set_buffer(&pending, buffer->buffer);
|
||||
if (buffer->wait_timeline != NULL) {
|
||||
wlr_output_state_set_wait_timeline(&pending, buffer->wait_timeline, buffer->wait_point);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue