surface 裁剪和缩放

全局接口,用于暴露 surface 裁剪和缩放功能,可为 wl_surface 对象实例化一个接口扩展。该扩展接口允许裁剪和缩放 surface 内容,从而断开缓冲区与 surface 尺寸之间的直接关联。

destroy
类型: destructor
destroy()
从裁剪和缩放接口解绑

通知服务器客户端将不再使用此协议对象。这不会影响任何其他对象,包括 wp_viewport 对象。

get_viewport(id: new_id<wp_viewport>, surface: object<wl_surface>)
参数
类型
描述
idnew_id<wp_viewport>
the new viewport interface id
surfaceobject<wl_surface>
the surface
扩展 surface 接口以支持裁剪和缩放

为给定的 wl_surface 实例化一个接口扩展,以裁剪和缩放其内容。如果给定的 wl_surface 已经关联了一个 wp_viewport 对象,则会触发 viewport_exists 协议错误。

error { viewport_exists } 
参数
描述
viewport_exists0
该 surface 已关联了一个 viewport 对象

wp_viewport

版本 1
wl_surface 的裁剪和缩放接口

wl_surface 对象的附加接口,允许客户端指定 surface 内容的裁剪和缩放。

此接口涉及两个概念:源矩形(src_x, src_y, src_width, src_height)和目标尺寸(dst_width, dst_height)。源矩形的内容被缩放到目标尺寸,源矩形之外的内容将被忽略。此状态是双缓冲的,参见 wl_surface.commit。

裁剪和缩放状态的两个部分是独立的:源矩形和目标尺寸。初始状态下两者均未设置,即不应用任何缩放。当前 wl_buffer 的全部内容用作源,surface 尺寸由 wl_surface.attach 定义。

如果设置了目标尺寸,它将使 surface 尺寸变为 dst_width, dst_height。源(矩形)被精确地缩放到此尺寸。这会覆盖已附加的 wl_buffer 的尺寸,除非 wl_buffer 为 NULL。如果 wl_buffer 为 NULL,surface 没有内容因此没有尺寸。否则,尺寸在 surface 本地坐标中始终至少为 1x1。

如果设置了源矩形,它定义了从 wl_buffer 中取出作为源的区域。如果设置了源矩形但未设置目标尺寸,则 src_width 和 src_height 必须为整数,且 surface 尺寸变为源矩形的尺寸。这将实现裁剪而不缩放。如果 src_width 或 src_height 不是整数且未设置目标尺寸,则在应用 surface 状态时将触发 bad_size 协议错误。

从缓冲区像素坐标到 surface 本地坐标的转换按以下顺序进行: 1. buffer_transform(wl_surface.set_buffer_transform) 2. buffer_scale(wl_surface.set_buffer_scale) 3. 裁剪和缩放(wp_viewport.set*) 这意味着裁剪和缩放的源矩形坐标是在缓冲区变换和缩放之后的坐标中给出的,即在未应用裁剪和缩放时将作为 surface 本地坐标的坐标。

如果 src_x 或 src_y 为负数,将触发 bad_value 协议错误。否则,如果源矩形部分或完全位于非 NULL 的 wl_buffer 之外,则在应用 surface 状态时将触发 out_of_buffer 协议错误。NULL 的 wl_buffer 不会触发 out_of_buffer 错误。

如果与 wp_viewport 关联的 wl_surface 被销毁,除 'destroy' 之外的所有 wp_viewport 请求都会触发 no_surface 协议错误。

如果 wp_viewport 对象被销毁,裁剪和缩放状态将从 wl_surface 中移除。该更改将在下次 wl_surface.commit 时应用。

destroy
类型: destructor
destroy()
移除 surface 的缩放和裁剪

移除关联 wl_surface 的裁剪和缩放状态。更改将在下次 wl_surface.commit 时应用。

set_source(x: fixed, y: fixed, width: fixed, height: fixed)
参数
类型
描述
xfixed
source rectangle x
yfixed
source rectangle y
widthfixed
source rectangle width
heightfixed
source rectangle height
设置裁剪的源矩形

设置关联 wl_surface 的源矩形。参见 wp_viewport 的描述及其与 wl_buffer 尺寸的关系。

如果 x、y、width 和 height 均为 -1.0,则取消设置源矩形。任何其他 width 或 height 为零或负数、或 x 或 y 为负数的值组合将触发 bad_value 协议错误。

裁剪和缩放状态是双缓冲的,参见 wl_surface.commit。

set_destination(width: int, height: int)
参数
类型
描述
widthint
surface width
heightint
surface height
设置缩放的 surface 尺寸

设置关联 wl_surface 的目标尺寸。参见 wp_viewport 的描述及其与 wl_buffer 尺寸的关系。

如果 width 为 -1 且 height 为 -1,则取消设置目标尺寸。任何其他包含零或负值的 width 和 height 组合将触发 bad_value 协议错误。

裁剪和缩放状态是双缓冲的,参见 wl_surface.commit。

参数
描述
bad_value0
width 或 height 为零或负数
bad_size1
目标尺寸不是整数
out_of_buffer2
源矩形超出内容区域范围
no_surface3
wl_surface 已被销毁

合成器支持

Cage
Cage
0.2.0
COSMIC
COSMIC
1.0.0~beta.8
GameScope
GameScope
3.15.14
Hyprland
Hyprland
0.52.1
Jay
1.12.0
KWin
KWin
6.6
Labwc
Labwc
0.9.2
Louvre
Louvre
2.14.1
Mir
Mir
2.26
Muffin
Muffin
6.6.0
Mutter
Mutter
49.2
niri
niri
25.11
phoc
phoc
0.52
river
river
0.3.13
Sway
Sway
1.11
Treeland
Treeland
0.8.0
Wayfire
Wayfire
0.9.0
Weston
Weston
14.0.2
wp_viewporter
1
1
x
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

Copyright © 2013-2016 Collabora, Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Footer

© 2026 Wayland Explorer

本网站与 Wayland 官方项目无任何关联。网站所有内容均根据 Wayland 协议 XML 文件自动生成。

本网站使用的 Visual Studio Code - Codicons 遵循 CC BY 4.0 许可。