Split two helper functions out of weston_surface_update_transform() to:
- make the code clearer
- update the bounding box properly even if transformation fails
- unify the return point
Also add a comment on what matrix.d[12] is.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Extract the core into a function that does not call
weston_surface_update_transform() or schedule repaint.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Computing the real maximal opaque screen aligned rectangle of a
transformed surface is hard. Let's drop the opaque optimisation
instead.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
When a transformed (rotated) surface is continuously resized from its
top-left corner, its location will drift. This is due to accumulating
rounding errors in transforming an offset from surface-local to global
coordinates in surface_attach().
Diminish the drift down to unobservable level by changing the
weston_surface global position from integer to float.
The offset transformation is now done without rounding. To preserve the
precision, wl_shell::configure() interface must use floats, and so does
weston_surface_configure(), too.
The con of this patch is that it adds inconsistency to the surface
position coordinates: sometimes they are floats, sometimes integers.
Commit a0d6dc4f26 lost one line of code in
the refactoring, and so did not reset the surface damage on repaint
anymore. This causes damage to only accumulate, leading to a full
display redraw every cycle and hiding damage tracking issues.
Put the damage clear back.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
The uniform location variables should be signed, according to the OpenGL
ES 2 specification. Moreover, GL_NONE, i.e. 0, is not an invalid nor
special location; it is actually used as a valid uniform location.
Change struct weston_shader uniform members to signed.
Stop using 0 for identifying a non-existing uniform, use -1 instead.
Furthermore, as the spec says a) glGetUniformLocation() will return -1
for non-active/existing uniforms, and b) glUniform*() function will
simply ignore all calls with location -1, we can simplify the code. We
don't have to avoid locating uniforms that don't exist, and we don't
need to test for them in weston_surface_draw() either.
Remove the micro-optimisation that avoids setting 'alpha' uniform if it
has not changed, in the name of simplification.
Unify shader creation by dropping init_solid_shader(), and calling
weston_shader_init() instead. The downside is that we compile the vertex
shader twice at startup now.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
The x, y offsets in attach request are in surface-local coordinates, as
that is the only coordinate system the clients know about. The offset
must be transformed to global coordinate system to be applied properly.
This approximately fixes the top-left resizing of transformed surfaces.
However, it suffers from drift due to accumulating rounding errors in
continuous resizing.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Change weston_surface_damage*() functions to use the full surface
bounding box or call surface_compute_bbox() to find the bounding box for
an arbitrary rectangle.
This should fix all rendering artifacts for non-opaque (i.e. ARGB)
transformed surfaces.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Use the bounding box to compute an approximation of which output
contains most of the surface.
Move the region32 init outside the loop, and fini it, too.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
If we ever have transformed cursor surfaces, we would better use the
bounding box to check if it is on the given output.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Use the proper bounding box in clipping the surface repaint area. Fixes
excessive clipping for transformed surfaces.
Also don't leak the region32 on early return.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
weston_surface::transform.boundingbox depends on width and height, and
therefore geometry.dirty flag, so move width and height into geometry.
Fix all users and check that the dirty flag is set.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Compute a surface bounding box, especially for transformed surfaces, for
which one cannot simply use x,y,width,height.
The bounding box depends on width and height, so these are now under the
geometry.dirty flag.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
weston_surface::transform.position depends on x,y, and therefore the
dirty flag, so move x and y into geometry.
Also add the missing dirty flags.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Put the surface translation (absolute position) into the surface
transformations list. This allows to set additional transformations
before and after the global translation.
Having the translation cached, changing the surface x,y now requires to
set the geometry.dirty flag.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Previously, if a surface was transformed, it repainted as a whole,
regardless of the computed repaint region. As damage regions determine
repaint regions and whether a surface is considered for drawing at all,
this lead to disappearing surfaces if all surfaces were considered
transformed. Also transparent transformed surfaces were redrawn without
the surfaces below being properly redrawn, leading to alpha-saturation.
Fix that by making texture_region() use the proper global-to-surface
coordinate transformation for texture coordinates. This makes it
possible to call texture_region() also for transformed surfaces.
As texture coordinates may now lie outside the valid texture image, the
fragment shader is modified to check the fragment texture coordinates.
The special path texture_transformed_surface() is no longer used and is
removed.
This change fixes many of the rendering artifacts related to transformed
surfaces.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
For unifying the coordinate system handling, introduce functions for
converting explicitly between the global and the surface local
coordinate systems.
Use these functions in the input path, replacing
weston_surface_transform().
In the draw path, rewrite transform_vertex() to take in surface local
coordinates.
As shell now uses the new functions, the rotation origin is properly
placed in the middle of the surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Add the key binding Super+Alt+MouseLeftButton to start rotating a
surface by dragging. The rotation is removed, when the drag is near the
rotation origin.
Rotated surface are a stress test for input event coordinate
transformations, damage region tracking, draw transformations, and
window move and resize orientation.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
When converting input coordinates from global to surface-local system,
apply the full inverse surface transformation instead of just
translation.
Move weston_surface_update_transform() implementation realier in the
file, no changes.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
The compositor will likely do an order of magnitude less matrix
inversions than point transformations with an inverse, hence we do not
really need the optimised path for single-shot invert-and-transform.
Expose only the computing of the explicit inverse matrix in the API.
However, the matrix inversion tests need access to the internal
functions. Designate a unit test build by #defining UNIT_TEST, and
export the internal functions in that case.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Implement 4x4 matrix inversion based on LU-decomposition with partial
pivoting.
Instead of simply computing the inverse matrix explicitly, introduce the
type struct weston_inverse_matrix for storing the LU-decomposition and
the permutation from pivoting. Using doubles, this struct has greater
precision than struct weston_matrix.
If you need only few (less than 5, presumably) multiplications with the
inverse matrix, is it cheaper to use weston_inverse_matrix, and not
compute the inverse matrix explicitly into a weston_matrix.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Remove the inverse matrix member from struct weston_transform. It is
easier (and probably faster, too) to create and store only forward
transformation matrices in a list, multiply them once, and then invert
the final matrix, rather than creating both forward and inverse
matrices, and multiplying both.
Add a stub for the 4x4 matrix inversion function.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Having at most one transformation object attached to a surface is not
enough anymore. If we have a surface that needs to be scaled to
fullscreen, and then we have the zoom animation, we already need two
transformations combined.
Implement support for multiple transformations by adding a transformation
list. The final transformation is the ordered composite of those in the
list. To avoid traversing the list every single time, add a dirty flag,
and cache the final transformation.
The existing transformation users (only zoom) are converted.
Note: surface drawing should honour all kinds of transformations, but
not damage region code nor input event translating code take
transformations into account, AFAICT. Therefore anything but translation
will probably behave badly until they are fixed.
Cc: Juan Zhao <juan.j.zhao@linux.intel.com>
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
This removes more special cases from weston_output_repaint() and we
avoid creating and destroying the surface for each animation frame.
We gain another special case in weston_compositor_top(), but that's
less of a problem, and we'll fix that later.
We've trimmed down the actual repaint loop to just iterating through the
surface list and calling weston_surface_draw(), so we push that to the
backend without too much code duplication.
This was supposed to draw black borders around a fullscreen surface that
was smaller than the output. We don't want to special case that in the
repaint loop, but may use a different shader or such. And we want the
surface to have an opaque region that covers the output so that that
will eliminate overdraw of lower surfaces.