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:
committed by
Kristian Høgsberg
parent
73e9f86e2c
commit
b0420aeb3d
+5
-5
@@ -47,7 +47,7 @@ struct box {
|
|||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
struct wl_scaler *scaler;
|
struct wl_scaler *scaler;
|
||||||
struct wl_surface_scaler *surface_scaler;
|
struct wl_viewport *viewport;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -138,12 +138,12 @@ global_handler(struct display *display, uint32_t name,
|
|||||||
box->scaler = display_bind(display, name,
|
box->scaler = display_bind(display, name,
|
||||||
&wl_scaler_interface, 1);
|
&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));
|
widget_get_wl_surface(box->widget));
|
||||||
|
|
||||||
wl_surface_scaler_set(box->surface_scaler,
|
wl_viewport_set(box->viewport,
|
||||||
src_x, src_y, src_width, src_height,
|
src_x, src_y, src_width, src_height,
|
||||||
SURFACE_WIDTH, SURFACE_HEIGHT); /* dst */
|
SURFACE_WIDTH, SURFACE_HEIGHT); /* dst */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-14
@@ -40,31 +40,31 @@
|
|||||||
<description summary="unbind from the cropping and scaling interface">
|
<description summary="unbind from the cropping and scaling interface">
|
||||||
Informs the server that the client will not be using this
|
Informs the server that the client will not be using this
|
||||||
protocol object anymore. This does not affect any other objects,
|
protocol object anymore. This does not affect any other objects,
|
||||||
wl_surface_scaler objects included.
|
wl_viewport objects included.
|
||||||
</description>
|
</description>
|
||||||
</request>
|
</request>
|
||||||
|
|
||||||
<enum name="error">
|
<enum name="error">
|
||||||
<entry name="scaler_exists" value="0"
|
<entry name="viewport_exists" value="0"
|
||||||
summary="the surface already has a scaler object associated"/>
|
summary="the surface already has a viewport object associated"/>
|
||||||
</enum>
|
</enum>
|
||||||
|
|
||||||
<request name="get_surface_scaler">
|
<request name="get_viewport">
|
||||||
<description summary="extend surface interface for crop and scale">
|
<description summary="extend surface interface for crop and scale">
|
||||||
Instantiate an interface extension for the given wl_surface to
|
Instantiate an interface extension for the given wl_surface to
|
||||||
crop and scale its content. If the given wl_surface already has
|
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.
|
protocol error is raised.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<arg name="id" type="new_id" interface="wl_surface_scaler"
|
<arg name="id" type="new_id" interface="wl_viewport"
|
||||||
summary="the new scaler interface id"/>
|
summary="the new viewport interface id"/>
|
||||||
<arg name="surface" type="object" interface="wl_surface"
|
<arg name="surface" type="object" interface="wl_surface"
|
||||||
summary="the surface"/>
|
summary="the surface"/>
|
||||||
</request>
|
</request>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<interface name="wl_surface_scaler" version="1">
|
<interface name="wl_viewport" version="1">
|
||||||
<description summary="crop and scale interface to a wl_surface">
|
<description summary="crop and scale interface to a wl_surface">
|
||||||
An additional interface to a wl_surface object, which allows the
|
An additional interface to a wl_surface object, which allows the
|
||||||
client to specify the cropping and scaling of the surface
|
client to specify the cropping and scaling of the surface
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
the surface-local coordinates happen in the following order:
|
the surface-local coordinates happen in the following order:
|
||||||
1. buffer_transform (wl_surface.set_buffer_transform)
|
1. buffer_transform (wl_surface.set_buffer_transform)
|
||||||
2. buffer_scale (wl_surface.set_buffer_scale)
|
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
|
This means, that the source rectangle coordinates of crop and scale
|
||||||
are given in the coordinates after the buffer transform 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
|
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
|
still in the surface-local coordinate system, just like dst_width
|
||||||
and dst_height are.
|
and dst_height are.
|
||||||
|
|
||||||
If the wl_surface associated with the wl_surface_scaler is
|
If the wl_surface associated with the wl_viewport is destroyed,
|
||||||
destroyed, the wl_surface_scaler object becomes inert.
|
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
|
state is removed from the wl_surface. The change will be applied
|
||||||
on the next wl_surface.commit.
|
on the next wl_surface.commit.
|
||||||
</description>
|
</description>
|
||||||
@@ -128,8 +128,8 @@
|
|||||||
<request name="set">
|
<request name="set">
|
||||||
<description summary="set the crop and scale state">
|
<description summary="set the crop and scale state">
|
||||||
Set the crop and scale state of the associated wl_surface. See
|
Set the crop and scale state of the associated wl_surface. See
|
||||||
wl_surface_scaler for the description, and relation to the
|
wl_viewport for the description, and relation to the wl_buffer
|
||||||
wl_buffer size.
|
size.
|
||||||
|
|
||||||
The bad_value protocol error is raised if src_width or
|
The bad_value protocol error is raised if src_width or
|
||||||
src_height is negative, or if dst_width or dst_height is not
|
src_height is negative, or if dst_width or dst_height is not
|
||||||
|
|||||||
+38
-38
@@ -483,12 +483,12 @@ weston_surface_create(struct weston_compositor *compositor)
|
|||||||
|
|
||||||
surface->buffer_viewport.transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
surface->buffer_viewport.transform = WL_OUTPUT_TRANSFORM_NORMAL;
|
||||||
surface->buffer_viewport.scale = 1;
|
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->pending.buffer_viewport = surface->buffer_viewport;
|
||||||
surface->output = NULL;
|
surface->output = NULL;
|
||||||
surface->pending.newly_attached = 0;
|
surface->pending.newly_attached = 0;
|
||||||
|
|
||||||
surface->surface_scaler_resource = NULL;
|
surface->viewport_resource = NULL;
|
||||||
|
|
||||||
pixman_region32_init(&surface->damage);
|
pixman_region32_init(&surface->damage);
|
||||||
pixman_region32_init(&surface->opaque);
|
pixman_region32_init(&surface->opaque);
|
||||||
@@ -720,7 +720,7 @@ static void
|
|||||||
scaler_surface_to_buffer(struct weston_surface *surface,
|
scaler_surface_to_buffer(struct weston_surface *surface,
|
||||||
float sx, float sy, float *bx, float *by)
|
float sx, float sy, float *bx, float *by)
|
||||||
{
|
{
|
||||||
if (surface->buffer_viewport.scaler_set) {
|
if (surface->buffer_viewport.viewport_set) {
|
||||||
double a, b;
|
double a, b;
|
||||||
|
|
||||||
a = sx / surface->buffer_viewport.dst_width;
|
a = sx / surface->buffer_viewport.dst_width;
|
||||||
@@ -1295,7 +1295,7 @@ weston_surface_set_size_from_buffer(struct weston_surface *surface)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surface->buffer_viewport.scaler_set) {
|
if (surface->buffer_viewport.viewport_set) {
|
||||||
surface->width = surface->buffer_viewport.dst_width;
|
surface->width = surface->buffer_viewport.dst_width;
|
||||||
surface->height = surface->buffer_viewport.dst_height;
|
surface->height = surface->buffer_viewport.dst_height;
|
||||||
return;
|
return;
|
||||||
@@ -2103,7 +2103,7 @@ weston_surface_commit(struct weston_surface *surface)
|
|||||||
|
|
||||||
/* wl_surface.set_buffer_transform */
|
/* wl_surface.set_buffer_transform */
|
||||||
/* wl_surface.set_buffer_scale */
|
/* wl_surface.set_buffer_scale */
|
||||||
/* wl_surface_scaler.set */
|
/* wl_viewport.set */
|
||||||
surface->buffer_viewport = surface->pending.buffer_viewport;
|
surface->buffer_viewport = surface->pending.buffer_viewport;
|
||||||
|
|
||||||
/* wl_surface.attach */
|
/* 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_transform */
|
||||||
/* wl_surface.set_buffer_scale */
|
/* wl_surface.set_buffer_scale */
|
||||||
/* wl_surface_scaler.set */
|
/* wl_viewport.set */
|
||||||
surface->buffer_viewport = sub->cached.buffer_viewport;
|
surface->buffer_viewport = sub->cached.buffer_viewport;
|
||||||
|
|
||||||
/* wl_surface.attach */
|
/* wl_surface.attach */
|
||||||
@@ -3454,41 +3454,41 @@ weston_output_transform_coordinate(struct weston_output *output,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
destroy_surface_scaler(struct wl_resource *resource)
|
destroy_viewport(struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
struct weston_surface *surface =
|
struct weston_surface *surface =
|
||||||
wl_resource_get_user_data(resource);
|
wl_resource_get_user_data(resource);
|
||||||
|
|
||||||
surface->surface_scaler_resource = NULL;
|
surface->viewport_resource = NULL;
|
||||||
surface->pending.buffer_viewport.scaler_set = 0;
|
surface->pending.buffer_viewport.viewport_set = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
surface_scaler_destroy(struct wl_client *client,
|
viewport_destroy(struct wl_client *client,
|
||||||
struct wl_resource *resource)
|
struct wl_resource *resource)
|
||||||
{
|
{
|
||||||
wl_resource_destroy(resource);
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
surface_scaler_set(struct wl_client *client,
|
viewport_set(struct wl_client *client,
|
||||||
struct wl_resource *resource,
|
struct wl_resource *resource,
|
||||||
wl_fixed_t src_x,
|
wl_fixed_t src_x,
|
||||||
wl_fixed_t src_y,
|
wl_fixed_t src_y,
|
||||||
wl_fixed_t src_width,
|
wl_fixed_t src_width,
|
||||||
wl_fixed_t src_height,
|
wl_fixed_t src_height,
|
||||||
int32_t dst_width,
|
int32_t dst_width,
|
||||||
int32_t dst_height)
|
int32_t dst_height)
|
||||||
{
|
{
|
||||||
struct weston_surface *surface =
|
struct weston_surface *surface =
|
||||||
wl_resource_get_user_data(resource);
|
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 ||
|
if (wl_fixed_to_double(src_width) < 0 ||
|
||||||
wl_fixed_to_double(src_height) < 0) {
|
wl_fixed_to_double(src_height) < 0) {
|
||||||
wl_resource_post_error(resource,
|
wl_resource_post_error(resource,
|
||||||
WL_SURFACE_SCALER_ERROR_BAD_VALUE,
|
WL_VIEWPORT_ERROR_BAD_VALUE,
|
||||||
"source dimensions must be non-negative (%fx%f)",
|
"source dimensions must be non-negative (%fx%f)",
|
||||||
wl_fixed_to_double(src_width),
|
wl_fixed_to_double(src_width),
|
||||||
wl_fixed_to_double(src_height));
|
wl_fixed_to_double(src_height));
|
||||||
@@ -3497,13 +3497,13 @@ surface_scaler_set(struct wl_client *client,
|
|||||||
|
|
||||||
if (dst_width <= 0 || dst_height <= 0) {
|
if (dst_width <= 0 || dst_height <= 0) {
|
||||||
wl_resource_post_error(resource,
|
wl_resource_post_error(resource,
|
||||||
WL_SURFACE_SCALER_ERROR_BAD_VALUE,
|
WL_VIEWPORT_ERROR_BAD_VALUE,
|
||||||
"destination dimensions must be positive (%dx%d)",
|
"destination dimensions must be positive (%dx%d)",
|
||||||
dst_width, dst_height);
|
dst_width, dst_height);
|
||||||
return;
|
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_x = src_x;
|
||||||
surface->pending.buffer_viewport.src_y = src_y;
|
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;
|
surface->pending.buffer_viewport.dst_height = dst_height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_surface_scaler_interface surface_scaler_interface = {
|
static const struct wl_viewport_interface viewport_interface = {
|
||||||
surface_scaler_destroy,
|
viewport_destroy,
|
||||||
surface_scaler_set
|
viewport_set
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -3526,37 +3526,37 @@ scaler_destroy(struct wl_client *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
scaler_get_surface_scaler(struct wl_client *client,
|
scaler_get_viewport(struct wl_client *client,
|
||||||
struct wl_resource *scaler,
|
struct wl_resource *scaler,
|
||||||
uint32_t id,
|
uint32_t id,
|
||||||
struct wl_resource *surface_resource)
|
struct wl_resource *surface_resource)
|
||||||
{
|
{
|
||||||
struct weston_surface *surface = wl_resource_get_user_data(surface_resource);
|
struct weston_surface *surface = wl_resource_get_user_data(surface_resource);
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
|
|
||||||
if (surface->surface_scaler_resource) {
|
if (surface->viewport_resource) {
|
||||||
wl_resource_post_error(scaler,
|
wl_resource_post_error(scaler,
|
||||||
WL_SCALER_ERROR_SCALER_EXISTS,
|
WL_SCALER_ERROR_VIEWPORT_EXISTS,
|
||||||
"a surface scaler for that surface already exists");
|
"a viewport for that surface already exists");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
resource = wl_resource_create(client, &wl_surface_scaler_interface,
|
resource = wl_resource_create(client, &wl_viewport_interface,
|
||||||
1, id);
|
1, id);
|
||||||
if (resource == NULL) {
|
if (resource == NULL) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_resource_set_implementation(resource, &surface_scaler_interface,
|
wl_resource_set_implementation(resource, &viewport_interface,
|
||||||
surface, destroy_surface_scaler);
|
surface, destroy_viewport);
|
||||||
|
|
||||||
surface->surface_scaler_resource = resource;
|
surface->viewport_resource = resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_scaler_interface scaler_interface = {
|
static const struct wl_scaler_interface scaler_interface = {
|
||||||
scaler_destroy,
|
scaler_destroy,
|
||||||
scaler_get_surface_scaler
|
scaler_get_viewport
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
+5
-5
@@ -660,10 +660,10 @@ struct weston_buffer_viewport {
|
|||||||
/* wl_surface.set_scaling_factor */
|
/* wl_surface.set_scaling_factor */
|
||||||
int32_t scale;
|
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
|
* called yet (before this is called there is no
|
||||||
* cropping or scaling on the surface) */
|
* 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_x, src_y;
|
||||||
wl_fixed_t src_width, src_height;
|
wl_fixed_t src_width, src_height;
|
||||||
@@ -861,8 +861,8 @@ struct weston_surface {
|
|||||||
struct weston_buffer_viewport buffer_viewport;
|
struct weston_buffer_viewport buffer_viewport;
|
||||||
int keep_buffer; /* bool for backends to prevent early release */
|
int keep_buffer; /* bool for backends to prevent early release */
|
||||||
|
|
||||||
/* wl_surface_scaler resource for this surface */
|
/* wl_viewport resource for this surface */
|
||||||
struct wl_resource *surface_scaler_resource;
|
struct wl_resource *viewport_resource;
|
||||||
|
|
||||||
/* All the pending state, that wl_surface.commit will apply. */
|
/* All the pending state, that wl_surface.commit will apply. */
|
||||||
struct {
|
struct {
|
||||||
@@ -887,7 +887,7 @@ struct weston_surface {
|
|||||||
|
|
||||||
/* wl_surface.set_buffer_transform */
|
/* wl_surface.set_buffer_transform */
|
||||||
/* wl_surface.set_scaling_factor */
|
/* wl_surface.set_scaling_factor */
|
||||||
/* wl_surface_scaler.set */
|
/* wl_viewport.set */
|
||||||
struct weston_buffer_viewport buffer_viewport;
|
struct weston_buffer_viewport buffer_viewport;
|
||||||
} pending;
|
} pending;
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -257,23 +257,23 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
|
|||||||
pixman_double_to_fixed ((double)-ev->geometry.y));
|
pixman_double_to_fixed ((double)-ev->geometry.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ev->surface->buffer_viewport.scaler_set) {
|
if (ev->surface->buffer_viewport.viewport_set) {
|
||||||
double scaler_x, scaler_y, scaler_width, scaler_height;
|
double viewport_x, viewport_y, viewport_width, viewport_height;
|
||||||
double ratio_x, ratio_y;
|
double ratio_x, ratio_y;
|
||||||
|
|
||||||
scaler_x = wl_fixed_to_double(ev->surface->buffer_viewport.src_x);
|
viewport_x = wl_fixed_to_double(ev->surface->buffer_viewport.src_x);
|
||||||
scaler_y = wl_fixed_to_double(ev->surface->buffer_viewport.src_y);
|
viewport_y = wl_fixed_to_double(ev->surface->buffer_viewport.src_y);
|
||||||
scaler_width = wl_fixed_to_double(ev->surface->buffer_viewport.src_width);
|
viewport_width = wl_fixed_to_double(ev->surface->buffer_viewport.src_width);
|
||||||
scaler_height = wl_fixed_to_double(ev->surface->buffer_viewport.src_height);
|
viewport_height = wl_fixed_to_double(ev->surface->buffer_viewport.src_height);
|
||||||
|
|
||||||
ratio_x = scaler_width / ev->surface->buffer_viewport.dst_width;
|
ratio_x = viewport_width / ev->surface->buffer_viewport.dst_width;
|
||||||
ratio_y = scaler_height / ev->surface->buffer_viewport.dst_height;
|
ratio_y = viewport_height / ev->surface->buffer_viewport.dst_height;
|
||||||
|
|
||||||
pixman_transform_scale(&transform, NULL,
|
pixman_transform_scale(&transform, NULL,
|
||||||
pixman_double_to_fixed(ratio_x),
|
pixman_double_to_fixed(ratio_x),
|
||||||
pixman_double_to_fixed(ratio_y));
|
pixman_double_to_fixed(ratio_y));
|
||||||
pixman_transform_translate(&transform, NULL, pixman_double_to_fixed(scaler_x),
|
pixman_transform_translate(&transform, NULL, pixman_double_to_fixed(viewport_x),
|
||||||
pixman_double_to_fixed(scaler_y));
|
pixman_double_to_fixed(viewport_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
pixman_transform_scale(&transform, NULL,
|
pixman_transform_scale(&transform, NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user