Commit Graph

2543 Commits

Author SHA1 Message Date
Jonas Ådahl
46ec29458d cogl/texture: Add a bit more debug logging
We fall back to slicing if the non-sliced allocation failed, but we
didn't log why. Also log why allocating a slice failed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1648>
2020-12-18 16:19:05 +00:00
Jonas Ådahl
96842fc570 cogl/texture-2d-sliced: Don't double-free slice array when alloc failed
If texture allocation failed for a sliced 2D texture, the alloc()
function would free the slices immediately, but not clear the pointer to
the slices array. When the code attempting to allocate the texture then
freed the texture object, the cleanup functions tried to free the slices
array again, since it wasn't NULL.

Fix this by clearing the slices array after freeing it.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1580
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1648>
2020-12-18 16:19:05 +00:00
Georges Basile Stavracas Neto
d57bdb0b44 cogl/framebuffer: Add COGL_EXPORT to public function
An oversight of 038a3170bf.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1627>
2020-12-14 09:21:30 -03:00
Daniel van Vugt
a793b4eef5 cogl: Add new 'sync-{primitive,frame}' options for COGL_DEBUG
This allows profilers to trace the callers of whatever is spending the
most time on the GPU, and to measure render times more accurately.
Previously such information was hidden as it completed in the
background (asynchronously) after we call swap buffers.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1327>
2020-11-20 17:30:55 +00:00
Jonas Dreßler
4e63ed524e tests: Use ClutterStage "after-paint" instead of ClutterActor "paint"
The "paint" signal of ClutterActor is deprecated and will be removed. We
have a good replacement to get notified about stage paints nowadays,
that is "after-paint" on ClutterStage, so switch to that signal where it
makes sense.

I didn't bother to update the few tests (namely Clutters
conform/texture-fbo.c, conform/text-cache.c,
interactive/test-cogl-multitexture.c and Cogls
conform/test-multitexture.c, conform/test-texture-mipmaps.c) where it's
harder to replace the signal since we don't build those anyway.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1522
2020-10-23 22:06:58 +02:00
Uday Kiran Pichika
d504086ebf cogl: correcting the cogl trace log
Remove the extra & symbol appearing in cogl debug log

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1517
2020-10-21 12:10:16 +00:00
Daniel van Vugt
0501d3020e cogl-winsys-egl: Log the color depth in use
Enable it with environment `COGL_DEBUG=winsys`.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1387
2020-10-20 09:53:52 +00:00
Georges Basile Stavracas Neto
1f99395d20 clutter: Use graphene_matrix_inverse()
Instead of our own implementation that upscales, then downscales back,
use graphene_matrix_inverse() directly. This is possible after switching
to a z-near value that doesn't have problems with float precision.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1489
2020-10-16 13:37:44 -03:00
Jonas Ådahl
2aea404b14 cogl: Use memory management helpers more
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
88c830b9ab cogl/framebuffer: Move allocation and y-flip-ness to non-abstract types
Now that CoglFramebuffer is a GObject, we can start moving things to the
proper places.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
eb14da3874 cogl: Turn CoglFramebuffer, CoglOffscreen and CoglOnscreen into GObjects
A first step towards abandoning the CoglObject type system: convert
CoglFramebuffer, CoglOffscreen and CoglOnscreen into GObjects.
CoglFramebuffer is turned into an abstract GObject, while the two others
are currently final. The "winsys" and "platform" are still sprinkled
'void *' in the the non-abstract type instances however.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
ea2f4efaef cogl: Remove cogl_offscreen_new_to_texture()
It's no longer used, and has been deprecated for a long time.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
e7ac3e2715 cogl/framebuffer: Clean up cleanup function
Use cogl_clear_object() and g_clear_pointer() helpers.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
aa99e505ad cogl/framebuffer: Move public struct fields to private struct
This will limit accidental manipulation of the framebuffer struct
fields, while also paving the way to change to GObject type hierarchy.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
ffde1c0124 cogl/onscreen: Remove unused _cogl_onscreen_new()
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
209b78afd8 cogl/framebuffer/gl: Move OpenGL driver fields to private struct
It's driver specific, so it shouldn't be kept in the generic data
structure.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:38 +00:00
Jonas Ådahl
e720ef1ceb cogl/framebuffer: Fix argument naming to blit_framebuffer()
The first argument is the framebuffer operated on, so in order to stay
consistest, rename 'src' to 'framebuffer'. The second is the
destination. The destination is commonly referred to as 'dst' elsewhere,
so rename 'dest' to 'dst'.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:37 +00:00
Jonas Ådahl
4edcc21a5c cogl/framebuffer: Remove alignment of struct fields
They weren't all aligned anyway.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:37 +00:00
Jonas Ådahl
e7b923289a cogl/framebuffer: Fix enum declaration coding style
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1496
2020-10-16 16:17:37 +00:00
Daniel van Vugt
df65f05e27 cogl: Remove unused swap-related COGL_FEATURE_ID_ flags
What we actually use is `COGL_WINSYS_FEATURE_SWAP_BUFFERS_EVENT`, which
is also set in the same locations.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1297
2020-10-14 16:27:23 +00:00
Georges Basile Stavracas Neto
b5749a8b27 Remove CoglMatrix
Adios, amiga.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:48 +00:00
Georges Basile Stavracas Neto
090973e538 cogl/tests: Use graphene APIs
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
2020-10-06 15:34:48 +00:00
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