Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Implement the viewporter protocol #2092

Merged
merged 7 commits into from
Jun 17, 2020
Merged

Conversation

emersion
Copy link
Member

@emersion emersion commented Mar 31, 2020

The viewporter protocol allows clients to ask the compositor to crop and scale buffers during composition. This allows clients to avoid having to crop and scale in an intermediary buffer. The use-cases are:

  • Xwayland games that expect to be able to perform modeset
  • Video players that present DMA-BUFs coming out of VA-API
  • Optimized scrolling in web browsers

TODO:

  • Apply viewport transforms to damage
  • Error out when src_width or src_height are not integers and destination size is not set
  • Compositor implementation: Add support for viewporter sway#5433

Test plan:

  • weston-scaler -s
  • weston-scaler -d
  • weston-scaler -b

Future plans: wire this up with direct scan-out. With my wlr_output_layer proposal, I think we can extend the API to allow compositors to feed src/dst rectangles to the backend:

/**
 * Set the layer's final size. If the size is different from the attached buffer's,
 * the buffer will be scaled.
 */
void wlr_output_layer_scale(struct wlr_output_layer *layer, int width, int height);
/**
 * Set the layer's source box. This defines what area of the buffer will be used
 * as a source. This can be used to crop the buffer.
 */
void wlr_output_layer_set_src_box(struct wlr_output_layer *layer,
        const struct wlr_fbox *box);

wlr_output_layer_scale maps directly to the CRTC_W and CRTC_H KMS properties. wlr_output_layer_set_buffer_src_box maps directly to the SRC_* KMS properties.

Closes: #633


Breaking change: renderer implementations need to be updated, render_texture_with_matrix has been replaced with render_subtexture_with_matrix which allows specifying a source rectangle.

@emersion emersion force-pushed the viewporter branch 2 times, most recently from 3c4f35e to 44a04ad Compare April 27, 2020 12:25
types/wlr_surface.c Outdated Show resolved Hide resolved
@emersion emersion force-pushed the viewporter branch 2 times, most recently from d638b89 to 9ffc06f Compare June 8, 2020 12:11
emersion added a commit to emersion/sway that referenced this pull request Jun 8, 2020
@@ -32,6 +32,11 @@ struct wlr_renderer {
} events;
};

struct wlr_texture_box {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a very good name. Maybe something like wlr_fbox would be better?

texcoord is a vector of coordinates, with the first member being the X
axis value and the second member being the Y axis value. It makes more
sense to use the accessors with the same names.
emersion added a commit to emersion/sway that referenced this pull request Jun 8, 2020
@emersion emersion changed the title [WIP] Implement the viewporter protocol Implement the viewporter protocol Jun 8, 2020
@emersion emersion marked this pull request as ready for review June 8, 2020 16:09
@emersion
Copy link
Member Author

emersion commented Jun 8, 2020

This is now ready for review.

@ddevault ddevault added the breaking Breaking change in public API label Jun 8, 2020
@ddevault
Copy link
Contributor

ddevault commented Jun 8, 2020

On a first pass, this LGTM. Would like @ascent12's thoughts and pending some discussions in IRC.

Same as wlr_box, but for floating-point numbers.
This renders only a subset of the texture, instead of the full texture.
This field contains the viewport source and destination parameters. It's
intended to be updated by a third-party protocol, for instance
viewporter.
emersion added a commit to emersion/sway that referenced this pull request Jun 8, 2020
@emersion emersion removed the breaking Breaking change in public API label Jun 8, 2020
@emersion
Copy link
Member Author

emersion commented Jun 8, 2020

Removed the "breaking" label, this isn't a breaking change.

Update to use wlr_fbox.

@emersion
Copy link
Member Author

emersion commented Jun 8, 2020

Ah, this is a breaking change for custom renderers. My bad.

@emersion emersion added the breaking Breaking change in public API label Jun 8, 2020
This helper allows compositors to retrieve the buffer source box in
buffer-local coordinates.
@emersion
Copy link
Member Author

Ping @ascent12

@ddevault
Copy link
Contributor

Thanks!

@ddevault ddevault merged commit 9e68ed2 into swaywm:master Jun 17, 2020
@emersion emersion deleted the viewporter branch June 17, 2020 15:32
ddevault pushed a commit to swaywm/sway that referenced this pull request Jun 17, 2020
@emersion emersion added this to the 0.11.0 milestone Jul 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking Breaking change in public API
Development

Successfully merging this pull request may close these issues.

Add viewporter protocol
4 participants