Commit Graph

2521 Commits

Author SHA1 Message Date
Georges Basile Stavracas Neto
182b51774e cogl: Use graphene APIs
These are the easy, trivial ones.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:48 +00:00
Georges Basile Stavracas Neto
9e1004da0c cogl/matrix-stack: Use graphene APIs
This one is a bit tricky. The tl;dr; is that switching from right-hand
multiplication to left-hand multiplication required applying the stack
from left to root. This actually allowed simplifying the code a bit,
since CoglMatrixEntry only stores a pointer to its parent, and that's
all we need to know for left-hand multiplication.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:48 +00:00
Georges Basile Stavracas Neto
d03ffe1e97 cogl/matrix-stack: Embed graphene matrices in entry structs
Instead of heap allocated graphene matrices, embed them into the
entries themselves. That makes the matrix magazine unused, and thus
also remove it.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:48 +00:00
Georges Basile Stavracas Neto
5db1f67d44 clutter/stage: Setup 2D view internally
Move and simplify cogl_matrix_view_2d_in_perspective() to inside
ClutterStage, since it's the only consumer of this API, and remove
it from Cogl.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
db23ee5829 cogl/matrix: Move inverse calculation to cogl-graphene.c
This special precision-bearing calculation will be used in other
places, so better share them all here.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
3e0c961b76 Replace the CoglMatrix type by graphene_matrix_t
CoglMatrix already is a typedef to graphene_matrix_t. This commit
simply drops the CoglMatrix type, and align parameters. There is
no functional change here, it's simply a find-and-replace commit.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
cedb5318da cogl/matrix: Relocate and update projection and transform APIs
Ideally, we would use Graphene to do that, however as of now Graphene
lacks these APIs so we still need these helpers. Since we're preparing
to get rid of CoglMatrix, move them to a separate file, and rename them
with the 'cogl_graphene' prefix.

Since I'm already touching the world with this change, I'm also renaming
cogl_matrix_transform_point() to cogl_graphene_matrix_project_point(),
as per XXX comment, to make it consistent with the transform/projection
semantics in place.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
050053a114 cogl/matrix: Remove custom boxed type
Given that CoglMatrix is simply a typedef to graphene_matrix_t, we can
remove all the GType machinery and reuse Graphene's.

Also remove the clutter-cogl helper, and cogl_matrix_to_graphene_matrix()
which is now unused.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
5b8c0dca68 cogl/matrix: Make CoglMatrix a typedef to graphene_matrix_t
After the previous commit, the only field in the CoglMatrix structure is
a graphene_matrix_t. That means that CoglMatrix is effectively a graphene
matrix now, and the CoglMatrix struct isn't that much useful anymore.

Remove the CoglMatrix structure and make the CoglMatrix type a typedef to
graphene_matrix_t.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
eaa795a266 cogl/matrix: Remove cached inverse and flags
Remove the cached inverse, and dirty flags, and typedef CoglMatrix to
graphene_matrix_t itself. I preverved the type for this commit to help
reducing the commit size, next commits will remove the CoglMatrix type.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
2e986ed3e8 cogl/matrix: Add graphene_matrix_t utility function
CoglMatrix doesn't have a 1:1 mapping of graphene functions, and
sometimes it's just not worth adding wrappers over it. It is easier
to expose the internal graphene_matrix_t and let callers use it
directly.

Add new cogl_matrix_get_graphene_matrix() helper function, and
simplify Clutter's matrix progress function.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
6c695ec39d cogl/matrix: Remove extra padding
We don't need to preserve ABI anymore.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
1c41bfbcbb cogl/matrix: Update outdated documentation and comments
No direct access of matrix entries is allowed anymore; and we
use graphene_matrix_t internally.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
1adc9c7c4a cogl/matrix: Update copyright headers
There's no trace of Mesa's matrix anymore.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
70397c5e72 cogl/matrix: Use graphene_matrix_t internally
Instead of listing all matrix cells as floats, and the inverse
as a 16-length float array, use graphene_matrix_t in the structure
itself.

With this commit, all from/to CoglMatrix conversions are gone. It
is also not possible to initialize a CoglMatrix using the macro
anymore.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
51094de8c4 cogl/matrix: Rename and change cogl_matrix_get_array()
Rename cogl_matrix_get_array() to cogl_matrix_to_float(), and
make it copy the floats to an out argument instead of returning
a pointer to the casted CoglMatrix struct.

The naming change is specifically made to match graphene's,
and ease the transition.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
b878938de4 cogl/matrix: Cleanup flags and turn them into an enum
The only pair of flags we really care now is the DIRTY_INVERSE
and SINGULAR flags, used when computing the inverse.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
947e538454 cogl/matrix: Remove unused defines
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
7d7981e059 cogl/matrix: Remove matrix type
We can remove it since the most important type (identity) is now
detected through a simple graphene check.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
a96f0d7537 cogl/matrix: Get value using graphene matrix
Internally, a graphene_matrix_t representing the same transform that
of a CoglMatrix is the same matrix but transposed, so in order to get
the same element given a column and row for a matrix as if it would
be located in Cogl, it is necessary to swap the row and column when
retrieving it from the graphene matrix.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
45f3e15b63 cogl/matrix: Check identity using graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
9b65f74eb8 cogl/matrix: Remove dead code
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
ada5e67f7e cogl/matrix: Calculate inverse using graphene matrices
Turns out inverting a matrix was the largest chunk of the CoglMatrix
code. By switching to Graphene, a lot of it can go away. The inverse
is still cached in the CoglMatrix struct itself, to preserve the
optimization.

However, switching to graphene_matrix_t to calculate the inverse has
a challenge: float precision. We had to work around it here, and it
needs an explanation.

The way to detect whether a matrix is invertible or not (i.e.
whether it's not a "singular" matrix, or not) is by checking
if the determinant equals 0. So far, so good.

Both graphene_matrix_t and CoglMatrix use single-precision
floats to store their 4x4 matrices. Graphene uses vectorized
operations to optimize determinant calculation, while Cogl
tries to keep track of the matrix type and has special-purpose
determinant functions for different matrix types (the most
common one being a 3D matrix).

Cogl, however, has a fundamentally flawed check for whether
the matrix is invertible or not. Have a look:

```
float det;

…

if (det*det < 1e-25)
   return FALSE;
```

Notice that 1e-25 is *way* smaller than FLT_EPSILON. This
check is fundamentally flawed.

"In practice, what does it break?", the reader might ask.
Well, in this case, the answer is opposite of that: Cogl
inverts matrices that should not be invertible. Let's see
an example: the model-view-projection of a 4K monitor. It
looks like this:

```
| +0,002693 +0,000000 +0,000000 +0,000000 |
| +0,000000 -0,002693 +0,000000 +0,000000 |
| +0,000000 +0,000000 +0,002693 +0,000000 |
| -5,169809 +2,908017 -5,036834 +1,000000 |
```

The determinant of this matrix is -0.000000019530306557.
It evidently is smaller than FLT_EPSILON. In this situation,
Cogl would happily calculate the inverse matrix, whereas
Graphene (correctly) bails out and thinks it's a singular
matrix.

This commit works around that by exploiting the maths around
it. The basis of it is:

  inverse(scalar * M) = (1/scalar) * M'

which can be extrapolated to:

  inverse(M) = scalar * inverse(scalar * M) = M'

In other words, scaling the to-be-inversed matrix, then
scaling the inverse matrix by the same factor, gives us
the desired inverse. In this commit, the scale is calculated
as 1 / (smallest value in the diagonal).

I'm sorry for everyone that has to read through this :(

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
cb733f8fbc cogl/matrix: Orthographic with graphene matrices
And remove all the custom matrix multiplication functions altogether.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:47 +00:00
Georges Basile Stavracas Neto
b3318688f8 cogl/matrix: Don't debug-print inverse matrix
All multiplication functions need to go away eventually, and this is
the penultimate place we're ising the 4x4 multiplication function.

Remove it.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
dd3c15a8a8 cogl/matrix: Euler-rotate with graphene matrices
Nothing outstanding here.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
1f0e8fb23c cogl/tests: Remove euler test
Next commits, and this patchset in general, will make this patchset
obsolete, since it'll only test graphene types against each other.
If at all useful, the Euler test should be moved to graphene.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
b1472a6015 cogl/matrix: Project and transpose using graphene matrices
Use dot products to simplify calculations. Because the 'w' column of
the matrix is always summed, use 1.f in the 'w' component of the point
vector.

Because CoglMatrix is column-major and graphene_matrix_t is row-major,
it is necessary to transpose the matrix before retrieving the rows.
When we switch CoglMatrix to be row-major, this transposition will
go away.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
5d84f73aa0 cogl/matrix: Skew using graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
3ea8af1489 cogl/matrix: Frustum with graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
dad710adaa cogl/matrix: Transpose using graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
0dbd6d3a80 cogl/matrix: Look-at using graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
2b7a73e0c3 cogl/matrix: Compare using graphene matrices
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
06db70ea28 cogl/matrix: Scale using graphene matrices
Boring.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
ade28eeaf3 cogl/matrix: Rotate using graphene matrices
This is pretty similar to the other conversions, except we need to
store the matrix flags before operating on it, and update it using
this old value after. That's because cogl_matrix_init_from_array()
marks the matrix as entirely dirty, and we don't want that.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
02a30f2a22 cogl/matrix: Multiply using graphene matrices
At this point, we are still only changing CoglMatrix APIs internally, and
it should still produce the same output as before.

To achieve this, using graphens matrix implementation, we need to exploit
some knowledge about conventions used in Cogl and graphene respectively.

In Cogl, transformation matrices are equivalent to those of affine
transformation matrices. The convention used by graphene, however, is to
operate on matrices that are transposed compared to their affine
counterparts.

So for example, let's say we want to multiply the affine matrices A and B,
to get C.

  A × B = C

The first step is to convert A and B to graphene matrices. We do this by
importing the floating point array, importing it directly using graphene.

Cogl exports its matrix to a column major floating point array. When we
import this in graphene, being row major, we end up with the same matrix,
only transposed.

Cogl       Graphene

  A   <===>   Aᵀ
  B   <===>   Bᵀ

We then multiply these imported matrices in reverse

  Bᵀ × Aᵀ

which in turn, due to ABᵀ = BᵀAᵀ, gives us

  Bᵀ × Aᵀ = (A × B)ᵀ

Our original goal was to find C, thus we know that

  A × B = C

That means we can shuffle things around a bit.

  A × B = C

  Bᵀ × Aᵀ = (A × B)ᵀ

  Bᵀ × Aᵀ = Cᵀ

With the same conversion as done when going from Cogl to graphene, only
the other way around, we still end up effectively transposing the matrix
during the conversion.

Graphene      Cogl

   Cᵀ  <===>   C

Thus when converting Cᵀ to Cogl, we in fact end up with C.

(Explanation authored by Jonas Ådahl)

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
2b9ce99ff2 cogl/matrix: Translate using graphene
Add conversion helpers (from and to graphene_matrix_t), and replace
the translation code to use graphene matrices internally.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
8e125fbab6 cogl/matrix: Add cogl_matrix_get_value
This will allow us stop accessing members of the structure
directly. Also mark all struct members as private.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
fe0a325e9f cogl/matrix: Import skew functions from Clutter
Graphene provides skewing as part of graphene_matrix_t API, and it'll
be easier for the transition to just expose similar API surfaces.

Move the matrix skew methods to CoglMatrix.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
566b081cd7 cogl/tests: Compare matrices using array
We'll remove direct access to CoglMatrix struct fields, so update
the test to not access them already.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
eee2e331fd cogl/matrix: Add constant identity initializer
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
a761caf079 cogl/matrix: Add cogl_matrix_init_from_matrix initializer
It does a simple memcpy() to clone the entire structure. This will
be necessary for a smoother removal of ClutterMatrix.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Georges Basile Stavracas Neto
1a9f9b0164 cogl: Remove unused header
Not included nor used anywhere.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:46 +00:00
Simon McVittie
8ae641aa24 cogl tests: Show the actual output from tests if VERBOSE is set
Writing tests' output to a log file makes them difficult to debug when
the test might be running on an autobuilder or CI system where only
stdout/stderr are recorded. This is particularly troublesome if a
failure is only reproducible on a particular autobuilder.

Recent Automake versions have the convention that detailed output from
failing tests is written to stdout/stderr, not just to log files, when
the VERBOSE environment variable is set; borrow that convention as a
trigger for producing detailed test output.

This was originally cogl!14, but applies equally to mutter's fork of cogl.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1273

Signed-off-by: Simon McVittie <smcv@debian.org>
2020-09-28 13:58:19 +00:00
Daniel van Vugt
647eec5f7f cogl: Flush specific framebuffers
This resolves a couple of FIXMEs. The FIXME comments were right in
stating that not *all* journals needed flushing, only the one we
are trying to put on screen needs flushing.

However we can't eliminate all flushes because the winsys swap calls
that follow go directly into OpenGL which knows nothing about cogl
journalling. So the journal *must* be flushed before the swap, to give
OpenGL the correct state.

P.S. If this turns out to cause any bugs then the next best answer is
to just remove the FIXME comments. Because flushing is still the right
thing to do.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1362
2020-09-18 11:59:52 +00:00
Jonas Ådahl
6e3ecadb79 backends/native: Fall back to compositing if direct scanout failed
Even when a direct client buffer has a compatible format, stride and
modifier for direct scanout, drmModePageFlip() may still fail sometimes.

From testing, it has been observed that it may seemingly randomly fail
with ENOSPC, where all subsequent attempts later on the same CRTC
failing with EBUSY.

Handle this by falling back to flipping after having composited a full
frame again.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1410
2020-09-17 12:17:35 +00:00
Jonas Ådahl
7d822459de cogl/renderer: Set error in dmabuf constructor fallback
When the CoglRenderer didn't set the DMA buffer constructor vfunc, we
return NULL. What we didn't do was set the error, meaning the caller
would crash if it tried to look up why DMA buffer construction failed.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1430
2020-09-14 16:03:17 +00:00
Georges Basile Stavracas Neto
21a21e7f68 cogl/scanout: Allow blitting to framebuffer
This will be used when screencasting monitors so that if
there's scanout in place, it'll still be possible to blit
it to a PipeWire-owned framebuffer, and stream it.

Add a new 'blit_to_framebuffer' vfunc to CoglScanout, and
implement it in MetaDrmBufferGbm.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1421
2020-09-01 13:05:24 -03:00
Robert Mader
1f557a502b cogl/context: Add API to create named pipelines
In certain situations it's desirable to keep pipelines around for
the whole lifetime of the session. In order to not leak them and
properly clean them up on shutdown, introduce a new mechanism to
create named pipelines that are bound to their correstponding
context and may be used across file boundries.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1372
2020-08-31 15:47:08 +00:00
Björn Daase
285f2a2124 cogl: Fix spelling of CoglPipelineStateComparator
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1410
2020-08-29 09:10:31 +00:00