mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-03 09:01:40 -05:00
viewporter: fix src buffer bounds check
The surface scale and transform are applied before the viewport.
Closes: https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3766
(cherry picked from commit 4fbe648faf)
This commit is contained in:
parent
f070bab7db
commit
b05fef20ff
1 changed files with 14 additions and 4 deletions
|
|
@ -131,6 +131,19 @@ static void viewport_handle_resource_destroy(struct wl_resource *resource) {
|
|||
viewport_destroy(viewport);
|
||||
}
|
||||
|
||||
static bool check_src_buffer_bounds(const struct wlr_surface_state *state) {
|
||||
int width = state->buffer_width / state->scale;
|
||||
int height = state->buffer_height / state->scale;
|
||||
if (state->transform & WL_OUTPUT_TRANSFORM_90) {
|
||||
int tmp = width;
|
||||
width = height;
|
||||
height = tmp;
|
||||
}
|
||||
|
||||
struct wlr_fbox box = state->viewport.src;
|
||||
return box.x + box.width <= width && box.y + box.height <= height;
|
||||
}
|
||||
|
||||
static void viewport_handle_surface_client_commit(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_viewport *viewport =
|
||||
|
|
@ -148,10 +161,7 @@ static void viewport_handle_surface_client_commit(struct wl_listener *listener,
|
|||
}
|
||||
|
||||
if (state->viewport.has_src && state->buffer != NULL &&
|
||||
(state->viewport.src.x + state->viewport.src.width >
|
||||
state->buffer_width ||
|
||||
state->viewport.src.y + state->viewport.src.height >
|
||||
state->buffer_height)) {
|
||||
!check_src_buffer_bounds(state)) {
|
||||
wl_resource_post_error(viewport->resource, WP_VIEWPORT_ERROR_OUT_OF_BUFFER,
|
||||
"source rectangle out of buffer bounds");
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue