Commit Graph

2609 Commits

Author SHA1 Message Date
Carlos Garnacho
9e10d2fa88 cogl: Drop "volatile" from static GTypes in manual registration
As documented in g_once_init_enter(): "While @location has a volatile qualifier,
this is a historical artifact and the pointer passed to it should not be
volatile.". And effectively this now warns with modern glibc.

Drop the "volatile" qualifier from these static variables as it's expected.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1785>
2021-03-22 10:47:51 +00:00
Jonas Ådahl
ec14f51ae3 cogl/onscreen/egl: Remove platform pointer
It's not used anymore, so remove it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1759>
2021-03-08 15:02:30 +00:00
Ivan Molodetskikh
47183a94eb cogl/frame-info: Add VSYNC flag
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:11 +00:00
Ivan Molodetskikh
9123aa4e84 cogl/frame-info: Add ZERO_COPY flag
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:11 +00:00
Ivan Molodetskikh
c96fb181ab cogl/frame-info: Add sequence
It will be used for the presentation-time Wayland protocol.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:11 +00:00
Ivan Molodetskikh
5d8cb2786b cogl: Remove get_monotonic_time_ns()
It's no longer needed. Everything else uses and assumes
g_get_monotonic_time().

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:11 +00:00
Ivan Molodetskikh
4ba2df0bd2 cogl: Remove cogl_get_clock_time()
It's no longer used.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:11 +00:00
Ivan Molodetskikh
4810164885 cogl: Make presentation time always MONOTONIC
This concerns only the cases when the presentation timestamp is received
directly from the device (from KMS or from GLX). In the majority of
cases this timestamp is already MONOTONIC. When it isn't, after this
commit, the current value of the MONOTONIC clock is sampled instead.

The alternative is to store the clock id alongside the timestamp, with
possible values of MONOTONIC, REALTIME (from KMS) and GETTIMEOFDAY (from
GLX; this might be the same as REALTIME, I'm not sure), and then
"convert" the timestamp to MONOTONIC when needed. An example of such a
conversion was done in compositor.c (removed in this commit). It would
also be needed for the presentation-time Wayland protocol. However, it
seems that the vast majority of up-to-date systems are using MONOTONIC
anyway, making this effort not justified.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:11 +00:00
Ivan Molodetskikh
d8606829c4 cogl: Report presentation time in microseconds
KMS and GLX device timestamps have microsecond precision, and whenever
we sample the time ourselves it's not the real presentation time anyway,
so nanosecond precision for that case is unnecessary.

The presentation timestamp in ClutterFrameInfo is in microseconds, too,
so this commit makes them have the same precision.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:10 +00:00
Ivan Molodetskikh
9d54ef3994 cogl/frame-info: Add HW_CLOCK flag
A flag indicating whether the presentation timestamp was provided by the
display hardware (rather than sampled in user space).

It will be used for the presentation-time Wayland protocol.

This is definitely the case for page_flip_handler(), and I'm assuming
this is also the case for the two instances in the GLX code.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1484>
2021-03-08 09:48:10 +00:00
Robert Mader
df4508e8cf cogl: Stop using GSlice
It has been inofficially deprecated for years, is known to cause issues
with valgrind and potentially hides memory corruption.
Lets stop using it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1512>
2021-02-22 13:51:30 +01:00
Jonas Ådahl
7ddbcd1fd2 cogl/journal: Don't sometimes hold a ref on the framebuffer
d42f1873fc introduced a semi circular
reference between the CoglFramebuffer, and CoglJournal, where
CoglJournal would keep a reference on the CoglFramebuffer when there
were any entries in the journal log.

To avoid risking leaking these objects indefinitely, when freeing
objects without doing anything that triggered a flush, CoglFramebuffer
had a "filter" on cogl_object_unref() calls, which knew
about under what conditions CoglJournal had a reference to it. When it
could detect that there were only the journal itself holding such a
reference, it'd flush the journal, effectively releasing the reference
the journal held, thus freeing itself, as well as the journal.

When CoglFramebuffer was ported to be implemented using GObject instead
of CoglObject, this "filter" was missed, causing not only awkward but
infrequent leaks, but also situations where we'd flush journals when
only the journal itself held the last reference to the framebuffer,
meaning the journal would free the framebuffer, thus itself, in the
middle of flushing, causing memory corruption and crashes.

A way to detect this, by asserting on CoglObject reference count during
flush, is by adding the `g_assert()` as described below, which will
assert instead cause memory corruption.

void
_cogl_journal_flush (CoglJournal *journal
{
   ...
   _cogl_journal_discard (journal);
+  g_assert (journal->_parent.ref_count > 0);
   ...
}

Fix this by making CoglFramebuffer the owner of the journal, which it
already was, and remove any circle referencing that was there before, as
it is not needed given that the CoglFramebuffer pointer is guaranteed to
be valid for the lifetime of CoglJournal as the framebuffer is the owner
of the journal.

However, to not miss flushing before tearing down, which is important as
this flushes painting calls to the driver that is important for e.g.
using the result of those journal entries, flush the journal the first
time cogl_framebuffer_dispose() is called, before doing anything else.

This also adds a test case. Without having broken the circular
reference, the test would fail on g_assert_null (offscreen), as it would
have been "leaked" at this point, but the actual memory corruption would
be a result of the `cogl_texture_get_data()` call, which flushes the
framebuffer, and causes the 'mid-flush' destruction of the journal
described above. Note that the texture keeps track of dependent
framebuffers, but it does not hold any references to them.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1474
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1735>
2021-02-18 16:59:00 +00:00
Jonas Ådahl
30e1c51b33 Change all g_memdup() to g_memdup2()
Using g_memdup() is dangerous due to the type of the size argument. See
https://gitlab.gnome.org/GNOME/glib/-/issues/2319 and
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1926 for details.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1708>
2021-02-04 19:16:28 +01:00
Jonas Ådahl
9a21f97ce1 cogl/gl-framebuffer: Remove hard coding type name
Either "onscreen" or "offscreen" was logged as the type; replace this
with the actual type name.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:47 +00:00
Jonas Ådahl
b07994b606 cogl: Use 'is_y_flipped()' instead of instance-of checking
This is what it was effectively used for in these places, so use the
appropriate API instead.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:47 +00:00
Jonas Ådahl
6b5d7f45cb cogl/gl-framebuffer: Check Y-flipped-ness instead of framebuffer type
In a few places coordinates were flipped if driven framebuffer was or
wasn't a CoglOffscreen. Change this to use the existing Y-flipped-ness
class vfunc.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
102aa59ce3 cogl/gl-framebuffer: Move stereo mode state flushing to backend
It's currently only handled by a surface backend framebuffer (assuming
the right GLX extensions are available). While it's theoretically
possible to do the same with the offcreen by having multiple textures,
it's not supported, so leave the FBO variant with a single warning if we
end up there.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
dd55c3699c cogl/gl-framebuffer: GObject:ify helper functions
The object was still pretending to be CoglFramebuffer itself, by using
naming and calling conventions making it seem like that. Fix that by
passing around the driver instead of the framebuffer.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
0fcb26075f cogl/framebuffer: Move read_pixels_into_bitmap() to driver class
This was the last driver vfunc used specifically to implement the
CoglFramebuffer driver.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
1e5f105836 cogl/framebuffer: Move attribute drawing to driver class
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
392ffaeeb4 cogl/framebuffer: Move discard_buffers() to driver sub types
It was implemented slightly different depending on whether it was for a
surface or FBO, so move it to their corresponding GL driver types.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
b7c6865225 cogl/framebuffer: Move flush() and finish() to driver class
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
1b3937491c cogl/framebuffer: Move clear() to CoglFramebufferDriver
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
4f3b57c841 cogl/onscreen: Move buffer age getter vfunc to class
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
b2482a2069 cogl: Add CoglX11Onscreen interface
Mutter needs to fetch the X11 Window ID from the onscreen and did that
by using an X11 specific API on the CoglOnscreen, where the X11 type was
"expanded" (Window -> uint32_t). Change this by introducing an interface
called CoglX11Onscreen, implemented by both the Xlib and GLX onscreen
implementations, that keeps the right type (Window), while avoiding X11
specific API for CoglOnscreen.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
4ec0975e91 cogl/onscreen: Remove explicit 'resizable':ness
Mutter didn't use the APIs for resizeability of CoglOnscreens but
managed the size itself. For the native backend we don't ever resize
onscreens. Thus, remove this unused functionality.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
e43b95cd11 cogl/onscreen: Remove show()/hide()
Not used, and not relevant.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
b0ec3a3ad7 cogl/test-utils: Skip "showing" the onscreen
Tests pass anyway.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
0fdf6a6405 cogl/onscreen: Move direct scanout to CoglOnscreen class
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
f663567405 cogl/onscreen: Move binding to onscreen class
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
fe72876b20 cogl/onscreen: Make swap_buffer/region CoglOnscreen class vfuncs
No need to go via the "winsys" vtable.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
60e1516b1c cogl/gl-framebuffer: Split up into FBO and back drivers
One is for when we're painting to the back buffer (onscreen), and the
other when we're painting to an FBO (offscreen).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
a6b0376a6c cogl: Add 'framebuffer' debug topic
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
d136c6510b cogl: Init framebuffer driver up front
The framebuffer driver was lazilly initialized on demand in some cases
(onscreen), and up front other (offscreen). Replace this with a more
predictable up front initialization, done at framebuffer allocation.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
58eb1e87bf cogl/offscreen: Move struct to C file
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:46 +00:00
Jonas Ådahl
ece714c5c6 cogl/gl-framebuffer: Move struct fields into private
This makes it possible to make type derivable.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
e3de0be678 cogl: Move "flush framebuffers" under the context scope
It was namespaced as a CoglFramebuffer function, but was passed two
framebuffers, and operated on state kept in CoglContext. Move and rename
accordingly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
5be5529269 cogl: Add CoglFramebufferDriver base type
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
c7ea0b3d54 cogl/offscreen: Pass ColgOffscreenFlag when allocating
So that the allocation functions don't need to peek at the cached flag
struct field.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
cac5938238 cogl/gl-framebuffer: Fix allocate flag variable name
It was called 'flags' which would conflict with a variable containing a
CoglOffscreenFlag that will be added later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
1bee9e0d53 cogl/offscreen: Remove alloation_flags struct field
Was unused.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
408d4c9f09 cogl/offscreen: Remove depth buffer texture field
It was never set, so it was just some dead code.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
8910b3e7bc cogl/offscreen: Move CoglGlFbo struct to GL driver
It was only used there, so put it in the driver private struct.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
e9e37dd0d1 cogl/offscreen: Move CoglOffscreen code to its own file
Moving the external direct struct access will come later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
391866d415 cogl/gl-framebuffer: Rename CoglGLFramebuffer CoglGlFbo
The CoglGLFramebuffer (not CoglGlFramebuffer) is a private struct for
keeping track of the framebuffer object. To avoid confusing with
CoglGlFramebuffer, rename it CoglGlFbo.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
f56b0abaef cogl/gl-framebuffer: Make it a GObject
This way we can have separate types per modes of operation (e.g. if it's
backed by an EGLSurface or single texture), instead of being dependent
on a certain type (onscreen vs offscreen).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
0e376f4dda cogl/framebuffer-gl: Rename from CoglFramebufferGl to CoglGlFramebuffer
This is to follow the convention [ParentName][ChildName] representing
inheritance. As this does not inherit CoglFramebuffer, rename it
CoglGlFramebuffer.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
0936d7bd06 cogl/onscreen: Use CoglFramebufferClass::allocate() to init
Instead of calling "init_onscreen()" on two different separate vtables
from the allocate() funtion, just have the CoglOnscreen sub types
themself implement allocate() and initialize in there.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
0b568b68c6 Make all CoglOnscreen sub types inherit CoglOnscreen
Thins means that e.g. MetaOnscreenNative now inherits CoglOnscreenEgl,
which inherits CoglOnscreen which inherits CoglFramebuffer, all being
the same GObject instance.

This makes it necessary to the one creating the onscreen to know what it
wants to create. For the X11 backend, the type of renderer (Xlib EGL or
GLX) determines the type, and for the native backend, it's currently
always MetaOnscreenNative.

The "winsys" vfunc entries related to onscreens hasn't been moved yet,
that will come later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00
Jonas Ådahl
f60943afc9 cogl/onscreen/egl: Move struct fields to instance private
This is so a derivable type can be declared later.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1514>
2021-01-30 09:11:45 +00:00