Skip to content
Commits on Source (6)
......@@ -27,6 +27,10 @@
#ifndef WESTON_MATRIX_H
#define WESTON_MATRIX_H
#include <stdbool.h>
#include <wayland-server-protocol.h>
#ifdef __cplusplus
extern "C" {
#endif
......@@ -66,6 +70,13 @@ int
weston_matrix_invert(struct weston_matrix *inverse,
const struct weston_matrix *matrix);
bool
weston_matrix_needs_filtering(const struct weston_matrix *matrix);
bool
weston_matrix_to_transform(const struct weston_matrix *mat,
enum wl_output_transform *transform);
#ifdef __cplusplus
}
#endif
......
......@@ -666,17 +666,17 @@ drm_head_find_by_connector(struct drm_backend *backend, uint32_t connector_id);
static inline bool
drm_view_transform_supported(struct weston_view *ev, struct weston_output *output)
{
struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
/* This will incorrectly disallow cases where the combination of
* buffer and view transformations match the output transform.
* Fixing this requires a full analysis of the transformation
* chain. */
if (ev->transform.enabled &&
ev->transform.matrix.type >= WESTON_MATRIX_TRANSFORM_ROTATE)
struct weston_matrix transform;
enum wl_output_transform wt;
weston_view_buffer_to_output_matrix(ev, output, &transform);
/* if false, the transform doesn't map to any of the standard
* (ie: 90 degree) output transformations. */
if (!weston_matrix_to_transform(&transform, &wt))
return false;
if (viewport->buffer.transform != output->transform)
if (wt != WL_OUTPUT_TRANSFORM_NORMAL)
return false;
return true;
......
......@@ -90,9 +90,6 @@
#define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */
static void
weston_output_update_matrix(struct weston_output *output);
static void
weston_output_transform_scale_init(struct weston_output *output,
uint32_t transform, uint32_t scale);
......@@ -104,6 +101,16 @@ weston_compositor_build_view_list(struct weston_compositor *compositor,
static char *
weston_output_create_heads_string(struct weston_output *output);
static void
paint_node_update(struct weston_paint_node *pnode)
{
struct weston_matrix tmp_matrix;
weston_view_buffer_to_output_matrix(pnode->view, pnode->output,
&tmp_matrix);
pnode->needs_filtering = weston_matrix_needs_filtering(&tmp_matrix);
}
static struct weston_paint_node *
weston_paint_node_create(struct weston_surface *surface,
struct weston_view *view,
......@@ -144,6 +151,8 @@ weston_paint_node_create(struct weston_surface *surface,
wl_list_init(&pnode->z_order_link);
paint_node_update(pnode);
return pnode;
}
......@@ -810,6 +819,16 @@ weston_surface_to_buffer_region(struct weston_surface *surface,
free(dest_rects);
}
WL_EXPORT void
weston_view_buffer_to_output_matrix(const struct weston_view *view,
const struct weston_output *output,
struct weston_matrix *matrix)
{
*matrix = view->surface->buffer_to_surface_matrix;
weston_matrix_multiply(matrix, &view->transform.matrix);
weston_matrix_multiply(matrix, &output->matrix);
}
WL_EXPORT void
weston_view_move_to_plane(struct weston_view *view,
struct weston_plane *plane)
......@@ -1832,7 +1851,7 @@ fixed_round_up_to_int(wl_fixed_t f)
return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f);
}
static void
WESTON_EXPORT_FOR_TESTS void
convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out,
int32_t width, int32_t height,
uint32_t transform,
......@@ -2771,8 +2790,10 @@ view_ensure_paint_node(struct weston_view *view, struct weston_output *output)
return NULL;
pnode = weston_view_find_paint_node(view, output);
if (pnode)
if (pnode) {
paint_node_update(pnode);
return pnode;
}
return weston_paint_node_create(view->surface, view, output);
}
......@@ -3700,7 +3721,7 @@ weston_surface_commit_subsurface_order(struct weston_surface *surface)
}
}
static void
WESTON_EXPORT_FOR_TESTS void
weston_surface_build_buffer_matrix(const struct weston_surface *surface,
struct weston_matrix *matrix)
{
......@@ -6224,7 +6245,7 @@ weston_region_global_to_output(pixman_region32_t *dst,
weston_matrix_transform_region(dst, &output->matrix, src);
}
static void
WESTON_EXPORT_FOR_TESTS void
weston_output_update_matrix(struct weston_output *output)
{
weston_matrix_init(&output->matrix);
......
......@@ -367,6 +367,10 @@ weston_view_takes_input_at_point(struct weston_view *view, int x, int y);
void
weston_view_move_to_plane(struct weston_view *view,
struct weston_plane *plane);
void
weston_view_buffer_to_output_matrix(const struct weston_view *view,
const struct weston_output *output,
struct weston_matrix *matrix);
pixman_box32_t
weston_matrix_transform_rect(struct weston_matrix *matrix,
......@@ -468,6 +472,8 @@ struct weston_paint_node {
/* Mutable members: */
bool needs_filtering;
/* struct weston_output::paint_node_z_order_list */
struct wl_list z_order_link;
......@@ -490,6 +496,19 @@ wl_data_device_manager_init(struct wl_display *display);
bool
weston_output_set_color_outcome(struct weston_output *output);
void
weston_surface_build_buffer_matrix(const struct weston_surface *surface,
struct weston_matrix *matrix);
void
weston_output_update_matrix(struct weston_output *output);
void
convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out,
int32_t width, int32_t height,
uint32_t transform,
int32_t scale);
/* User authentication for remote backends */
bool
......
......@@ -1032,8 +1032,7 @@ draw_paint_node(struct weston_paint_node *pnode,
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
if (pnode->view->transform.enabled ||
pnode->output->current_scale != pnode->surface->buffer_viewport.buffer.scale)
if (pnode->needs_filtering)
filter = GL_LINEAR;
else
filter = GL_NEAREST;
......
......@@ -26,6 +26,7 @@
#include "config.h"
#include <assert.h>
#include <float.h>
#include <string.h>
#include <stdlib.h>
......@@ -270,3 +271,248 @@ weston_matrix_invert(struct weston_matrix *inverse,
return 0;
}
static bool
near_zero(float a)
{
if (fabs(a) > 0.00001)
return false;
return true;
}
static float
get_el(const struct weston_matrix *matrix, int row, int col)
{
assert(row >= 0 && row <= 3);
assert(col >= 0 && col <= 3);
return matrix->d[col * 4 + row];
}
static bool
near_zero_at(const struct weston_matrix *matrix, int row, int col)
{
return near_zero(get_el(matrix, row, col));
}
static bool
near_one_at(const struct weston_matrix *matrix, int row, int col)
{
return near_zero(get_el(matrix, row, col) - 1.0);
}
static bool
near_pm_one_at(const struct weston_matrix *matrix, int row, int col)
{
return near_zero(fabs(get_el(matrix, row, col)) - 1.0);
}
static bool
near_int_at(const struct weston_matrix *matrix, int row, int col)
{
float el = get_el(matrix, row, col);
return near_zero(roundf(el) - el);
}
/* Lazy decompose the matrix to figure out whether its operations will
* cause an image to look ugly without some kind of filtering.
*
* while this is a 3D transformation matrix, we only concern ourselves
* with 2D for this test. We do use some small rounding to try to catch
* sequences of operations that lead back to a matrix that doesn't
* require filters.
*
* We assume the matrix won't be used to transform a vector with w != 1.0
*
* Filtering will be necessary when:
* a non-integral translation is applied
* non-affine (perspective) translation is in use
* any scaling (other than -1) is in use
* a rotation that isn't a multiple of 90 degrees about Z is present
*/
WL_EXPORT bool
weston_matrix_needs_filtering(const struct weston_matrix *matrix)
{
/* check for non-integral X/Y translation - ignore Z */
if (!near_int_at(matrix, 0, 3) ||
!near_int_at(matrix, 1, 3))
return true;
/* Any transform matrix that matches this will be non-affine. */
if (!near_zero_at(matrix, 3, 0) ||
!near_zero_at(matrix, 3, 1) ||
!near_zero_at(matrix, 3, 2) ||
!near_pm_one_at(matrix, 3, 3))
return true;
/* Check for anything that could come from a rotation that isn't
* around the Z axis:
* [ ? ? 0 ? ]
* [ ? ? 0 ? ]
* [ 0 0 ±1 ? ]
* [ ? ? ? 1 ]
* It's not clear that we'd realistically see a -1 in [2][2], but
* it wouldn't require filtering if we did, so allow it.
*/
if (!near_zero_at(matrix, 0, 2) ||
!near_zero_at(matrix, 1, 2) ||
!near_zero_at(matrix, 2, 0) ||
!near_zero_at(matrix, 2, 1) ||
!near_pm_one_at(matrix, 2, 2))
return true;
/* We've culled the low hanging fruit, now let's match the only
* matrices left we don't have to filter, before defaulting to
* filtering.
*
* These are a combination of testing rotation and scaling at once: */
if (near_pm_one_at(matrix, 0, 0)) {
/* This could be a multiple of 90 degree rotation about Z,
* possibly with a flip, if the matrix is of the form:
* [ ±1 0 0 ? ]
* [ 0 ±1 0 ? ]
* [ 0 0 1 ? ]
* [ 0 0 0 1 ]
* Forcing ±1 excludes non-unity scale.
*/
if (near_zero_at(matrix, 1, 0) &&
near_zero_at(matrix, 0, 1) &&
near_pm_one_at(matrix, 1, 1))
return false;
}
if (near_zero_at(matrix, 0, 0)) {
/* This could be a multiple of 90 degree rotation about Z,
* possibly with a flip, if the matrix is of the form:
* [ 0 ±1 0 ? ]
* [ ±1 0 0 ? ]
* [ 0 0 1 ? ]
* [ 0 0 0 1 ]
* Forcing ±1 excludes non-unity scale.
*/
if (near_zero_at(matrix, 1, 1) &&
near_pm_one_at(matrix, 1, 0) &&
near_pm_one_at(matrix, 0, 1))
return false;
}
/* The matrix wasn't "simple" enough to classify with dumb
* heuristics, so recommend filtering */
return true;
}
/** Examine a matrix to see if it applies a standard output transform.
*
* \param mat matrix to examine
* \param[out] transform the transform, if applicable
* \return true if a standard transform is present
* Note that the check only considers rotations and flips.
* If any other scale or translation is present, those may have to
* be dealt with by the caller in some way.
*/
WL_EXPORT bool
weston_matrix_to_transform(const struct weston_matrix *mat,
enum wl_output_transform *transform)
{
/* As a first pass we can eliminate any matrix that doesn't have
* zeroes in these positions:
* [ ? ? 0 ? ]
* [ ? ? 0 ? ]
* [ 0 0 ? ? ]
* [ 0 0 0 ? ]
* As they will be non-affine, or rotations about axes
* other than Z.
*/
if (!near_zero_at(mat, 2, 0) ||
!near_zero_at(mat, 3, 0) ||
!near_zero_at(mat, 2, 1) ||
!near_zero_at(mat, 3, 1) ||
!near_zero_at(mat, 0, 2) ||
!near_zero_at(mat, 1, 2) ||
!near_zero_at(mat, 3, 2))
return false;
/* Enforce the form:
* [ ? ? 0 ? ]
* [ ? ? 0 ? ]
* [ 0 0 ? ? ]
* [ 0 0 0 1 ]
* While we could scale all the elements by a constant to make
* 3,3 == 1, we choose to be lazy and not bother. A matrix
* that doesn't fit this form seems likely to be too complicated
* to pass the other checks.
*/
if (!near_one_at(mat, 3, 3))
return false;
if (near_zero_at(mat, 0, 0)) {
if (!near_zero_at(mat, 1, 1))
return false;
/* We now have a matrix like:
* [ 0 A 0 ? ]
* [ B 0 0 ? ]
* [ 0 0 ? ? ]
* [ 0 0 0 1 ]
* When transforming a vector with a matrix of this form, the X
* and Y coordinates are effectively exchanged, so we have a
* 90 or 270 degree rotation (not 0 or 180), and could have
* a flip depending on the signs of A and B.
*
* We don't require A and B to have the same absolute value,
* so there may be independent scales in the X or Y dimensions.
*/
if (get_el(mat, 0, 1) > 0) {
/* A is positive */
if (get_el(mat, 1, 0) > 0)
*transform = WL_OUTPUT_TRANSFORM_FLIPPED_90;
else
*transform = WL_OUTPUT_TRANSFORM_90;
} else {
/* A is negative */
if (get_el(mat, 1, 0) > 0)
*transform = WL_OUTPUT_TRANSFORM_270;
else
*transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
}
} else if (near_zero_at(mat, 1, 0)) {
if (!near_zero_at(mat, 0, 1))
return false;
/* We now have a matrix like:
* [ A 0 0 ? ]
* [ 0 B 0 ? ]
* [ 0 0 ? ? ]
* [ 0 0 0 1 ]
* This case won't exchange the X and Y inputs, so the
* transform is 0 or 180 degrees. We could have a flip
* depending on the signs of A and B.
*
* We don't require A and B to have the same absolute value,
* so there may be independent scales in the X or Y dimensions.
*/
if (get_el(mat, 0, 0) > 0) {
/* A is positive */
if (get_el(mat, 1, 1) > 0)
*transform = WL_OUTPUT_TRANSFORM_NORMAL;
else
*transform = WL_OUTPUT_TRANSFORM_FLIPPED_180;
} else {
/* A is negative */
if (get_el(mat, 1, 1) > 0)
*transform = WL_OUTPUT_TRANSFORM_FLIPPED;
else
*transform = WL_OUTPUT_TRANSFORM_180;
}
} else {
return false;
}
return true;
}
/*
* Copyright © 2022 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.
*/
#include "config.h"
#include <assert.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <wayland-client.h>
#include "libweston-internal.h"
#include "libweston/matrix.h"
#include "weston-test-client-helper.h"
static void
transform_expect(struct weston_matrix *a, bool valid, enum wl_output_transform ewt)
{
enum wl_output_transform wt;
assert(weston_matrix_to_transform(a, &wt) == valid);
if (valid)
assert(wt == ewt);
}
TEST(transformation_matrix)
{
struct weston_matrix a, b;
int i;
weston_matrix_init(&a);
weston_matrix_init(&b);
weston_matrix_multiply(&a, &b);
assert(a.type == 0);
/* Make b a matrix that rotates a surface on the x,y plane by 90
* degrees counter-clockwise */
weston_matrix_rotate_xy(&b, 0, -1);
assert(b.type == WESTON_MATRIX_TRANSFORM_ROTATE);
for (i = 0; i < 10; i++) {
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_90);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_180);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_270);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
}
weston_matrix_init(&b);
/* Make b a matrix that rotates a surface on the x,y plane by 45
* degrees counter-clockwise. This should alternate between a
* standard transform and a rotation that fails to match any
* known rotations. */
weston_matrix_rotate_xy(&b, cos(-M_PI / 4.0), sin(-M_PI / 4.0));
assert(b.type == WESTON_MATRIX_TRANSFORM_ROTATE);
for (i = 0; i < 10; i++) {
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_90);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_180);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_270);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
assert(a.type == WESTON_MATRIX_TRANSFORM_ROTATE);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
}
weston_matrix_init(&b);
/* Make b a matrix that rotates a surface on the x,y plane by 45
* degrees counter-clockwise. This should alternate between a
* standard transform and a rotation that fails to match any known
* rotations. */
weston_matrix_rotate_xy(&b, cos(-M_PI / 4.0), sin(-M_PI / 4.0));
/* Flip a */
weston_matrix_scale(&a, -1.0, 1.0, 1.0);
for (i = 0; i < 10; i++) {
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
/* Since we're not translated or scaled, any matrix that
* matches a standard wl_output_transform should not need
* filtering when used to transform images - but any
* matrix that fails to match will. */
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_90);
assert(!weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_180);
assert(!weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_270);
assert(!weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED);
assert(!weston_matrix_needs_filtering(&a));
}
weston_matrix_init(&a);
/* Flip a around Y*/
weston_matrix_scale(&a, 1.0, -1.0, 1.0);
for (i = 0; i < 100; i++) {
/* Throw some arbitrary translation in here to make sure it
* doesn't have any impact. */
weston_matrix_translate(&a, 31.0, -25.0, 0.0);
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_270);
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED);
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_90);
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_180);
}
/* Scale shouldn't matter, as long as it's positive */
weston_matrix_scale(&a, 4.0, 3.0, 1.0);
/* Invert b so it rotates the opposite direction, go back the other way. */
weston_matrix_invert(&b, &b);
for (i = 0; i < 100; i++) {
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_90);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_270);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, false, 0);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_FLIPPED_180);
assert(weston_matrix_needs_filtering(&a));
}
/* Flipping Y should return us from here to normal */
weston_matrix_scale(&a, 1.0, -1.0, 1.0);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
weston_matrix_init(&a);
weston_matrix_init(&b);
weston_matrix_translate(&b, 0.5, -0.75, 0);
/* Crawl along with translations, 0.5 and .75 will both hit an integer multiple
* at the same time every 4th step, so assert that only the 4th steps don't need
* filtering */
for (i = 0; i < 100; i++) {
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(weston_matrix_needs_filtering(&a));
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(!weston_matrix_needs_filtering(&a));
}
weston_matrix_init(&b);
weston_matrix_scale(&b, 1.5, 2.0, 1.0);
for (i = 0; i < 10; i++) {
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(weston_matrix_needs_filtering(&a));
}
weston_matrix_invert(&b, &b);
for (i = 0; i < 9; i++) {
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(weston_matrix_needs_filtering(&a));
}
/* Last step should bring us back to a matrix that doesn't need
* a filter */
weston_matrix_multiply(&a, &b);
transform_expect(&a, true, WL_OUTPUT_TRANSFORM_NORMAL);
assert(!weston_matrix_needs_filtering(&a));
}
static void
simple_weston_surface_prepare(struct weston_surface *surf,
int buffer_width, int buffer_height,
int surface_width, int surface_height,
int scale, uint32_t transform,
int src_x, int src_y,
int src_width, int src_height)
{
struct weston_buffer_viewport vp = {
.buffer = {
.transform = transform,
.scale = scale,
.src_x = wl_fixed_from_int(src_x),
.src_y = wl_fixed_from_int(src_y),
.src_width = wl_fixed_from_int(src_width),
.src_height = wl_fixed_from_int(src_height),
},
.surface = {
.width = surface_width,
.height = surface_height,
},
};
surf->buffer_viewport = vp;
convert_size_by_transform_scale(&surf->width_from_buffer,
&surf->height_from_buffer,
buffer_width,
buffer_height,
transform,
scale);
weston_surface_build_buffer_matrix(surf,
&surf->surface_to_buffer_matrix);
weston_matrix_invert(&surf->buffer_to_surface_matrix,
&surf->surface_to_buffer_matrix);
}
static void
surface_test_all_transforms(struct weston_surface *surf,
int buffer_width, int buffer_height,
int surface_width, int surface_height,
int scale, int src_x, int src_y,
int src_width, int src_height)
{
int transform;
for (transform = WL_OUTPUT_TRANSFORM_NORMAL;
transform <= WL_OUTPUT_TRANSFORM_FLIPPED_270; transform++) {
simple_weston_surface_prepare(surf,
buffer_width, buffer_height,
surface_width, surface_height,
scale, transform,
src_x, src_y,
src_width, src_height);
transform_expect(&surf->surface_to_buffer_matrix,
true, transform);
}
}
TEST(surface_matrix_to_standard_transform)
{
struct weston_surface surf;
int scale;
for (scale = 1; scale < 8; scale++) {
/* A simple case */
surface_test_all_transforms(&surf, 500, 700, -1, -1, scale,
0, 0, 500, 700);
/* Translate the source corner */
surface_test_all_transforms(&surf, 500, 700, -1, -1, scale,
70, 20, 500, 700);
/* Get some scaling (and fractional translation) in there */
surface_test_all_transforms(&surf, 723, 300, 512, 77, scale,
120, 10, 200, 200);
}
}
static void
simple_weston_output_prepare(struct weston_output *output,
int x, int y, int width, int height,
int scale, uint32_t transform)
{
output->x = x;
output->y = y;
output->width = width;
output->height = height;
output->current_scale = scale;
output->transform = transform;
weston_output_update_matrix(output);
}
static void
output_test_all_transforms(struct weston_output *output,
int x, int y, int width, int height, int scale)
{
int transform;
for (transform = WL_OUTPUT_TRANSFORM_NORMAL;
transform <= WL_OUTPUT_TRANSFORM_FLIPPED_270; transform++) {
simple_weston_output_prepare(output, x, y, width, height,
scale, transform);
/* The inverse matrix takes us from output to global space,
* which makes it the one that will have the expected
* standard transform.
*/
transform_expect(&output->matrix, true, transform);
}
}
TEST(output_matrix_to_standard_transform)
{
struct weston_output output;
int scale;
/* Just a few arbitrary sizes and positions to make sure we have
* scales and translations.
*/
for (scale = 1; scale < 8; scale++) {
output_test_all_transforms(&output, 0, 0, 1024, 768, scale);
output_test_all_transforms(&output, 1000, 1000, 1024, 768, scale);
output_test_all_transforms(&output, 1024, 768, 1920, 1080, scale);
}
}
......@@ -176,6 +176,10 @@ tests = [
'name': 'matrix',
'dep_objs': [ dep_libm ]
},
{
'name': 'matrix-transform',
'dep_objs': dep_libm,
},
{ 'name': 'output-damage', },
{ 'name': 'output-transforms', },
{ 'name': 'plugin-registry', },
......