mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-05-05 07:38:22 +02:00
protocol: rename wl_surface_scaler to wl_viewport
This seems like a better name, and will not conflict if someone later extends wl_surface with a request scaler_set (yeah, unlikely). This code was written by Jonny Lamb, I just diffed his branches and made a patch for Weston. Cc: Jonny Lamb <jonny.lamb@collabora.co.uk> Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
parent
73e9f86e2c
commit
b0420aeb3d
5 changed files with 72 additions and 72 deletions
|
|
@ -47,7 +47,7 @@ struct box {
|
|||
int width, height;
|
||||
|
||||
struct wl_scaler *scaler;
|
||||
struct wl_surface_scaler *surface_scaler;
|
||||
struct wl_viewport *viewport;
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
@ -138,12 +138,12 @@ global_handler(struct display *display, uint32_t name,
|
|||
box->scaler = display_bind(display, name,
|
||||
&wl_scaler_interface, 1);
|
||||
|
||||
box->surface_scaler = wl_scaler_get_surface_scaler(box->scaler,
|
||||
box->viewport = wl_scaler_get_viewport(box->scaler,
|
||||
widget_get_wl_surface(box->widget));
|
||||
|
||||
wl_surface_scaler_set(box->surface_scaler,
|
||||
src_x, src_y, src_width, src_height,
|
||||
SURFACE_WIDTH, SURFACE_HEIGHT); /* dst */
|
||||
wl_viewport_set(box->viewport,
|
||||
src_x, src_y, src_width, src_height,
|
||||
SURFACE_WIDTH, SURFACE_HEIGHT); /* dst */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,31 +40,31 @@
|
|||
<description summary="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,
|
||||
wl_surface_scaler objects included.
|
||||
wl_viewport objects included.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="scaler_exists" value="0"
|
||||
summary="the surface already has a scaler object associated"/>
|
||||
<entry name="viewport_exists" value="0"
|
||||
summary="the surface already has a viewport object associated"/>
|
||||
</enum>
|
||||
|
||||
<request name="get_surface_scaler">
|
||||
<request name="get_viewport">
|
||||
<description summary="extend surface interface for crop and scale">
|
||||
Instantiate an interface extension for the given wl_surface to
|
||||
crop and scale its content. If the given wl_surface already has
|
||||
a wl_surface_scaler object associated, the scaler_exists
|
||||
a wl_viewport object associated, the viewport_exists
|
||||
protocol error is raised.
|
||||
</description>
|
||||
|
||||
<arg name="id" type="new_id" interface="wl_surface_scaler"
|
||||
summary="the new scaler interface id"/>
|
||||
<arg name="id" type="new_id" interface="wl_viewport"
|
||||
summary="the new viewport interface id"/>
|
||||
<arg name="surface" type="object" interface="wl_surface"
|
||||
summary="the surface"/>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="wl_surface_scaler" version="1">
|
||||
<interface name="wl_viewport" version="1">
|
||||
<description summary="crop and scale interface to a wl_surface">
|
||||
An additional interface to a wl_surface object, which allows the
|
||||
client to specify the cropping and scaling of the surface
|
||||
|
|
@ -89,7 +89,7 @@
|
|||
the surface-local coordinates happen in the following order:
|
||||
1. buffer_transform (wl_surface.set_buffer_transform)
|
||||
2. buffer_scale (wl_surface.set_buffer_scale)
|
||||
3. crop and scale (wl_surface_scaler.set)
|
||||
3. crop and scale (wl_viewport.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
|
||||
|
|
@ -105,10 +105,10 @@
|
|||
still in the surface-local coordinate system, just like dst_width
|
||||
and dst_height are.
|
||||
|
||||
If the wl_surface associated with the wl_surface_scaler is
|
||||
destroyed, the wl_surface_scaler object becomes inert.
|
||||
If the wl_surface associated with the wl_viewport is destroyed,
|
||||
the wl_viewport object becomes inert.
|
||||
|
||||
If the wl_surface_scaler object is destroyed, the crop and scale
|
||||
If the wl_viewport object is destroyed, the crop and scale
|
||||
state is removed from the wl_surface. The change will be applied
|
||||
on the next wl_surface.commit.
|
||||
</description>
|
||||
|
|
@ -128,8 +128,8 @@
|
|||
<request name="set">
|
||||
<description summary="set the crop and scale state">
|
||||
Set the crop and scale state of the associated wl_surface. See
|
||||
wl_surface_scaler for the description, and relation to the
|
||||
wl_buffer size.
|
||||
wl_viewport for the description, and relation to the wl_buffer
|
||||
size.
|
||||
|
||||
The bad_value protocol error is raised if src_width or
|
||||
src_height is negative, or if dst_width or dst_height is not
|
||||
|
|
|
|||
|
|
@ -483,12 +483,12 @@ weston_surface_create(struct weston_compositor *compositor)
|
|||
|
||||
surface->buffer_viewport.transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||
surface->buffer_viewport.scale = 1;
|
||||
surface->buffer_viewport.scaler_set = 0;
|
||||
surface->buffer_viewport.viewport_set = 0;
|
||||
surface->pending.buffer_viewport = surface->buffer_viewport;
|
||||
surface->output = NULL;
|
||||
surface->pending.newly_attached = 0;
|
||||
|
||||
surface->surface_scaler_resource = NULL;
|
||||
surface->viewport_resource = NULL;
|
||||
|
||||
pixman_region32_init(&surface->damage);
|
||||
pixman_region32_init(&surface->opaque);
|
||||
|
|
@ -720,7 +720,7 @@ static void
|
|||
scaler_surface_to_buffer(struct weston_surface *surface,
|
||||
float sx, float sy, float *bx, float *by)
|
||||
{
|
||||
if (surface->buffer_viewport.scaler_set) {
|
||||
if (surface->buffer_viewport.viewport_set) {
|
||||
double a, b;
|
||||
|
||||
a = sx / surface->buffer_viewport.dst_width;
|
||||
|
|
@ -1295,7 +1295,7 @@ weston_surface_set_size_from_buffer(struct weston_surface *surface)
|
|||
return;
|
||||
}
|
||||
|
||||
if (surface->buffer_viewport.scaler_set) {
|
||||
if (surface->buffer_viewport.viewport_set) {
|
||||
surface->width = surface->buffer_viewport.dst_width;
|
||||
surface->height = surface->buffer_viewport.dst_height;
|
||||
return;
|
||||
|
|
@ -2103,7 +2103,7 @@ weston_surface_commit(struct weston_surface *surface)
|
|||
|
||||
/* wl_surface.set_buffer_transform */
|
||||
/* wl_surface.set_buffer_scale */
|
||||
/* wl_surface_scaler.set */
|
||||
/* wl_viewport.set */
|
||||
surface->buffer_viewport = surface->pending.buffer_viewport;
|
||||
|
||||
/* wl_surface.attach */
|
||||
|
|
@ -2329,7 +2329,7 @@ weston_subsurface_commit_from_cache(struct weston_subsurface *sub)
|
|||
|
||||
/* wl_surface.set_buffer_transform */
|
||||
/* wl_surface.set_buffer_scale */
|
||||
/* wl_surface_scaler.set */
|
||||
/* wl_viewport.set */
|
||||
surface->buffer_viewport = sub->cached.buffer_viewport;
|
||||
|
||||
/* wl_surface.attach */
|
||||
|
|
@ -3454,41 +3454,41 @@ weston_output_transform_coordinate(struct weston_output *output,
|
|||
}
|
||||
|
||||
static void
|
||||
destroy_surface_scaler(struct wl_resource *resource)
|
||||
destroy_viewport(struct wl_resource *resource)
|
||||
{
|
||||
struct weston_surface *surface =
|
||||
wl_resource_get_user_data(resource);
|
||||
|
||||
surface->surface_scaler_resource = NULL;
|
||||
surface->pending.buffer_viewport.scaler_set = 0;
|
||||
surface->viewport_resource = NULL;
|
||||
surface->pending.buffer_viewport.viewport_set = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
surface_scaler_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
viewport_destroy(struct wl_client *client,
|
||||
struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static void
|
||||
surface_scaler_set(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
wl_fixed_t src_x,
|
||||
wl_fixed_t src_y,
|
||||
wl_fixed_t src_width,
|
||||
wl_fixed_t src_height,
|
||||
int32_t dst_width,
|
||||
int32_t dst_height)
|
||||
viewport_set(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
wl_fixed_t src_x,
|
||||
wl_fixed_t src_y,
|
||||
wl_fixed_t src_width,
|
||||
wl_fixed_t src_height,
|
||||
int32_t dst_width,
|
||||
int32_t dst_height)
|
||||
{
|
||||
struct weston_surface *surface =
|
||||
wl_resource_get_user_data(resource);
|
||||
|
||||
assert(surface->surface_scaler_resource != NULL);
|
||||
assert(surface->viewport_resource != NULL);
|
||||
|
||||
if (wl_fixed_to_double(src_width) < 0 ||
|
||||
wl_fixed_to_double(src_height) < 0) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SURFACE_SCALER_ERROR_BAD_VALUE,
|
||||
WL_VIEWPORT_ERROR_BAD_VALUE,
|
||||
"source dimensions must be non-negative (%fx%f)",
|
||||
wl_fixed_to_double(src_width),
|
||||
wl_fixed_to_double(src_height));
|
||||
|
|
@ -3497,13 +3497,13 @@ surface_scaler_set(struct wl_client *client,
|
|||
|
||||
if (dst_width <= 0 || dst_height <= 0) {
|
||||
wl_resource_post_error(resource,
|
||||
WL_SURFACE_SCALER_ERROR_BAD_VALUE,
|
||||
WL_VIEWPORT_ERROR_BAD_VALUE,
|
||||
"destination dimensions must be positive (%dx%d)",
|
||||
dst_width, dst_height);
|
||||
return;
|
||||
}
|
||||
|
||||
surface->pending.buffer_viewport.scaler_set = 1;
|
||||
surface->pending.buffer_viewport.viewport_set = 1;
|
||||
|
||||
surface->pending.buffer_viewport.src_x = src_x;
|
||||
surface->pending.buffer_viewport.src_y = src_y;
|
||||
|
|
@ -3513,9 +3513,9 @@ surface_scaler_set(struct wl_client *client,
|
|||
surface->pending.buffer_viewport.dst_height = dst_height;
|
||||
}
|
||||
|
||||
static const struct wl_surface_scaler_interface surface_scaler_interface = {
|
||||
surface_scaler_destroy,
|
||||
surface_scaler_set
|
||||
static const struct wl_viewport_interface viewport_interface = {
|
||||
viewport_destroy,
|
||||
viewport_set
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
@ -3526,37 +3526,37 @@ scaler_destroy(struct wl_client *client,
|
|||
}
|
||||
|
||||
static void
|
||||
scaler_get_surface_scaler(struct wl_client *client,
|
||||
struct wl_resource *scaler,
|
||||
uint32_t id,
|
||||
struct wl_resource *surface_resource)
|
||||
scaler_get_viewport(struct wl_client *client,
|
||||
struct wl_resource *scaler,
|
||||
uint32_t id,
|
||||
struct wl_resource *surface_resource)
|
||||
{
|
||||
struct weston_surface *surface = wl_resource_get_user_data(surface_resource);
|
||||
struct wl_resource *resource;
|
||||
|
||||
if (surface->surface_scaler_resource) {
|
||||
if (surface->viewport_resource) {
|
||||
wl_resource_post_error(scaler,
|
||||
WL_SCALER_ERROR_SCALER_EXISTS,
|
||||
"a surface scaler for that surface already exists");
|
||||
WL_SCALER_ERROR_VIEWPORT_EXISTS,
|
||||
"a viewport for that surface already exists");
|
||||
return;
|
||||
}
|
||||
|
||||
resource = wl_resource_create(client, &wl_surface_scaler_interface,
|
||||
resource = wl_resource_create(client, &wl_viewport_interface,
|
||||
1, id);
|
||||
if (resource == NULL) {
|
||||
wl_client_post_no_memory(client);
|
||||
return;
|
||||
}
|
||||
|
||||
wl_resource_set_implementation(resource, &surface_scaler_interface,
|
||||
surface, destroy_surface_scaler);
|
||||
wl_resource_set_implementation(resource, &viewport_interface,
|
||||
surface, destroy_viewport);
|
||||
|
||||
surface->surface_scaler_resource = resource;
|
||||
surface->viewport_resource = resource;
|
||||
}
|
||||
|
||||
static const struct wl_scaler_interface scaler_interface = {
|
||||
scaler_destroy,
|
||||
scaler_get_surface_scaler
|
||||
scaler_get_viewport
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -660,10 +660,10 @@ struct weston_buffer_viewport {
|
|||
/* wl_surface.set_scaling_factor */
|
||||
int32_t scale;
|
||||
|
||||
/* bool for whether wl_surface_scaler.set has been
|
||||
/* bool for whether wl_viewport.set has been
|
||||
* called yet (before this is called there is no
|
||||
* cropping or scaling on the surface) */
|
||||
int scaler_set; /* bool */
|
||||
int viewport_set; /* bool */
|
||||
|
||||
wl_fixed_t src_x, src_y;
|
||||
wl_fixed_t src_width, src_height;
|
||||
|
|
@ -861,8 +861,8 @@ struct weston_surface {
|
|||
struct weston_buffer_viewport buffer_viewport;
|
||||
int keep_buffer; /* bool for backends to prevent early release */
|
||||
|
||||
/* wl_surface_scaler resource for this surface */
|
||||
struct wl_resource *surface_scaler_resource;
|
||||
/* wl_viewport resource for this surface */
|
||||
struct wl_resource *viewport_resource;
|
||||
|
||||
/* All the pending state, that wl_surface.commit will apply. */
|
||||
struct {
|
||||
|
|
@ -887,7 +887,7 @@ struct weston_surface {
|
|||
|
||||
/* wl_surface.set_buffer_transform */
|
||||
/* wl_surface.set_scaling_factor */
|
||||
/* wl_surface_scaler.set */
|
||||
/* wl_viewport.set */
|
||||
struct weston_buffer_viewport buffer_viewport;
|
||||
} pending;
|
||||
|
||||
|
|
|
|||
|
|
@ -257,23 +257,23 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
|
|||
pixman_double_to_fixed ((double)-ev->geometry.y));
|
||||
}
|
||||
|
||||
if (ev->surface->buffer_viewport.scaler_set) {
|
||||
double scaler_x, scaler_y, scaler_width, scaler_height;
|
||||
if (ev->surface->buffer_viewport.viewport_set) {
|
||||
double viewport_x, viewport_y, viewport_width, viewport_height;
|
||||
double ratio_x, ratio_y;
|
||||
|
||||
scaler_x = wl_fixed_to_double(ev->surface->buffer_viewport.src_x);
|
||||
scaler_y = wl_fixed_to_double(ev->surface->buffer_viewport.src_y);
|
||||
scaler_width = wl_fixed_to_double(ev->surface->buffer_viewport.src_width);
|
||||
scaler_height = wl_fixed_to_double(ev->surface->buffer_viewport.src_height);
|
||||
viewport_x = wl_fixed_to_double(ev->surface->buffer_viewport.src_x);
|
||||
viewport_y = wl_fixed_to_double(ev->surface->buffer_viewport.src_y);
|
||||
viewport_width = wl_fixed_to_double(ev->surface->buffer_viewport.src_width);
|
||||
viewport_height = wl_fixed_to_double(ev->surface->buffer_viewport.src_height);
|
||||
|
||||
ratio_x = scaler_width / ev->surface->buffer_viewport.dst_width;
|
||||
ratio_y = scaler_height / ev->surface->buffer_viewport.dst_height;
|
||||
ratio_x = viewport_width / ev->surface->buffer_viewport.dst_width;
|
||||
ratio_y = viewport_height / ev->surface->buffer_viewport.dst_height;
|
||||
|
||||
pixman_transform_scale(&transform, NULL,
|
||||
pixman_double_to_fixed(ratio_x),
|
||||
pixman_double_to_fixed(ratio_y));
|
||||
pixman_transform_translate(&transform, NULL, pixman_double_to_fixed(scaler_x),
|
||||
pixman_double_to_fixed(scaler_y));
|
||||
pixman_transform_translate(&transform, NULL, pixman_double_to_fixed(viewport_x),
|
||||
pixman_double_to_fixed(viewport_y));
|
||||
}
|
||||
|
||||
pixman_transform_scale(&transform, NULL,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue