Viewporter
wp_viewporter
全局接口,用于暴露 surface 裁剪和缩放功能,可为 wl_surface 对象实例化一个接口扩展。该扩展接口允许裁剪和缩放 surface 内容,从而断开缓冲区与 surface 尺寸之间的直接关联。
destroy()
通知服务器客户端将不再使用此协议对象。这不会影响任何其他对象,包括 wp_viewport 对象。
get_viewport(id: new_id<wp_viewport>, surface: object<wl_surface>)
参数 | 类型 | 描述 |
|---|---|---|
| id | new_id<wp_viewport> | the new viewport interface id |
| surface | object<wl_surface> | the surface |
为给定的 wl_surface 实例化一个接口扩展,以裁剪和缩放其内容。如果给定的 wl_surface 已经关联了一个 wp_viewport 对象,则会触发 viewport_exists 协议错误。
wp_viewport
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()
移除关联 wl_surface 的裁剪和缩放状态。更改将在下次 wl_surface.commit 时应用。
参数 | 类型 | 描述 |
|---|---|---|
| x | fixed | source rectangle x |
| y | fixed | source rectangle y |
| width | fixed | source rectangle width |
| height | fixed | source rectangle height |
设置关联 wl_surface 的源矩形。参见 wp_viewport 的描述及其与 wl_buffer 尺寸的关系。
如果 x、y、width 和 height 均为 -1.0,则取消设置源矩形。任何其他 width 或 height 为零或负数、或 x 或 y 为负数的值组合将触发 bad_value 协议错误。
裁剪和缩放状态是双缓冲的,参见 wl_surface.commit。
设置关联 wl_surface 的目标尺寸。参见 wp_viewport 的描述及其与 wl_buffer 尺寸的关系。
如果 width 为 -1 且 height 为 -1,则取消设置目标尺寸。任何其他包含零或负值的 width 和 height 组合将触发 bad_value 协议错误。
裁剪和缩放状态是双缓冲的,参见 wl_surface.commit。
error { bad_value, bad_size, out_of_buffer, no_surface }
参数 | 值 | 描述 |
|---|---|---|
| bad_value | 0 | width 或 height 为零或负数 |
| bad_size | 1 | 目标尺寸不是整数 |
| out_of_buffer | 2 | 源矩形超出内容区域范围 |
| no_surface | 3 | wl_surface 已被销毁 |
合成器支持
Cage | COSMIC | GameScope | Hyprland | Jay | KWin | Labwc | Louvre | Mir | Muffin | Mutter | niri | phoc | river | Sway | Treeland | Wayfire | Weston | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wp_viewporter | 1 | 1 | x | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Copyright
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.