viewporter Module

WpViewporter

class pywayland.protocol.viewporter.WpViewporter

Surface cropping and scaling

The global interface exposing surface cropping and scaling capabilities is used to instantiate an interface extension for a WlSurface object. This extended interface will then allow cropping and scaling the surface contents, effectively disconnecting the direct relationship between the buffer and the surface size.

destroy()

Request – opcode 0 (attached to Resource instance)

Unbind from the cropping and scaling interface

Informs the server that the client will not be using this protocol object anymore. This does not affect any other objects, WpViewport objects included.

get_viewport(surface)

Request – opcode 1 (attached to Resource instance)

Extend surface interface for crop and scale

Instantiate an interface extension for the given WlSurface to crop and scale its content. If the given WlSurface already has a WpViewport object associated, the viewport_exists protocol error is raised.

Parameters:surface (WlSurface) – the surface
Returns:WpViewport – the new viewport interface id

WpViewport

class pywayland.protocol.viewporter.WpViewport

Crop and scale interface to a WlSurface

An additional interface to a WlSurface object, which allows the client to specify the cropping and scaling of the surface contents.

This interface works with two concepts: the source rectangle (src_x, src_y, src_width, src_height), and the destination size (dst_width, dst_height). The contents of the source rectangle are scaled to the destination size, and content outside the source rectangle is ignored. This state is double- buffered, and is applied on the next WlSurface.commit().

The two parts of crop and scale state are independent: the source rectangle, and the destination size. Initially both are unset, that is, no scaling is applied. The whole of the current WlBuffer is used as the source, and the surface size is as defined in WlSurface.attach().

If the destination size is set, it causes the surface size to become dst_width, dst_height. The source (rectangle) is scaled to exactly this size. This overrides whatever the attached WlBuffer size is, unless the WlBuffer is NULL. If the WlBuffer is NULL, the surface has no content and therefore no size. Otherwise, the size is always at least 1x1 in surface local coordinates.

If the source rectangle is set, it defines what area of the WlBuffer is taken as the source. If the source rectangle is set and the destination size is not set, then src_width and src_height must be integers, and the surface size becomes the source rectangle size. This results in cropping without scaling. If src_width or src_height are not integers and destination size is not set, the bad_size protocol error is raised when the surface state is applied.

The coordinate transformations from buffer pixel coordinates up to the surface-local coordinates happen in the following order: 1. buffer_transform (WlSurface.set_buffer_transform()) 2. buffer_scale (WlSurface.set_buffer_scale()) 3. crop and scale (WpViewport.set*) This means, that the source rectangle coordinates of crop and scale are given in the coordinates after the buffer transform and scale, i.e. in the coordinates that would be the surface- local coordinates if the crop and scale was not applied.

If src_x or src_y are negative, the bad_value protocol error is raised. Otherwise, if the source rectangle is partially or completely outside of the non-NULL WlBuffer, then the out_of_buffer protocol error is raised when the surface state is applied. A NULL WlBuffer does not raise the out_of_buffer error.

The x, y arguments of WlSurface.attach() are applied as normal to the surface. They indicate how many pixels to remove from the surface size from the left and the top. In other words, they are still in the surface- local coordinate system, just like dst_width and dst_height are.

If the WlSurface associated with the WpViewport is destroyed, all WpViewport requests except ‘destroy’ raise the protocol error no_surface.

If the WpViewport object is destroyed, the crop and scale state is removed from the WlSurface. The change will be applied on the next WlSurface.commit().

destroy()

Request – opcode 0 (attached to Resource instance)

Remove scaling and cropping from the surface

The associated wl_surface’s crop and scale state is removed. The change is applied on the next WlSurface.commit().

set_source(x, y, width, height)

Request – opcode 1 (attached to Resource instance)

Set the source rectangle for cropping

Set the source rectangle of the associated WlSurface. See WpViewport for the description, and relation to the WlBuffer size.

If all of x, y, width and height are -1.0, the source rectangle is unset instead. Any other set of values where width or height are zero or negative, or x or y are negative, raise the bad_value protocol error.

The crop and scale state is double-buffered state, and will be applied on the next WlSurface.commit().

Parameters:
  • x (fixed) – source rectangle x
  • y (fixed) – source rectangle y
  • width (fixed) – source rectangle width
  • height (fixed) – source rectangle height
set_destination(width, height)

Request – opcode 2 (attached to Resource instance)

Set the surface size for scaling

Set the destination size of the associated WlSurface. See WpViewport for the description, and relation to the WlBuffer size.

If width is -1 and height is -1, the destination size is unset instead. Any other pair of values for width and height that contains zero or negative values raises the bad_value protocol error.

The crop and scale state is double-buffered state, and will be applied on the next WlSurface.commit().

Parameters:
  • width (int) – surface width
  • height (int) – surface height