Commit Graph

11479 Commits

Author SHA1 Message Date
Jonas Ådahl
112cca75e2 kms/impl-device: Remove deadline timer arming from queue_update()
queue_update() in a previous iteration was called in two situations:

 * A page flip was already pending, meaning if we would commit an
   update, it'd fail with EBUSY.
 * A update was marked as "always-defer" meaning it should only be
   processed from the deadline callback (would there be one). These were
   used for cursor-only updates.

In the latter, we had to arm the deadline timer when queuing a new
update, if it wasn't armed already, while in the former, we would
currently idle, waiting for the page flip callback. At that callback
would the deadline timer be re-armed again.

Since we're only handling the former now, we'll never need to arm the
timer again, so remove code doing so. The code removed were never
actually executed anymore, after the "always-defer" flag on updates was
removed.

Fixes: 27ed069766 ("kms/impl-device: Add deadline based KMS commit scheduling")
Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2940
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3150>
2023-08-07 15:59:18 +00:00
Daniel van Vugt
bafea13e95 kms/impl-device: Handle empty updates properly
This fixes freezes on cursor movement when:

1. meta_onscreen_native_finish_frame would create an empty update.
2. maybe_update_cursor_plane would leave it empty (!cursor_invalidated).
3. do_process would fail to recognise a non-null empty update as an error.
4. meta_kms_impl_device_handle_update would fail to send feedback on errors
   from do_process, because do_process is meant to do it.
5. Page flip listeners would wait forever for feedback that never comes.

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2923,
       https://gitlab.gnome.org/GNOME/mutter/-/issues/2924,
       https://gitlab.gnome.org/GNOME/mutter/-/issues/2926,
       https://gitlab.gnome.org/GNOME/mutter/-/issues/2933

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3138>
2023-08-07 16:51:43 +08:00
Daniel van Vugt
b516b009fa kms/impl-device: Treat handling update as flushing
Primary plane updates were forgetting to do this in OnscreenNative, but
rather than do it for each post there we should simply do it for each
post.

This fixes cursor stutter in the fallback path (not using deadline timers)
where needs_flush_crtcs would remain populated but CRTC_NEEDS_FLUSH would
never be emitted, because handle_flush hadn't been called for the last
post.

This is safe as the current use of scheduled flushing is only for cursor
updates, and since cursor updates happen on the same thread as processing,
and due to the fact that we always use the most up to date cursor position
when flushing, we never risk leaving an old cursor state unflushed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3138>
2023-08-07 16:50:36 +08:00
Daniel van Vugt
7493ed39ce kms/impl-device: Avoid retrying a failing deadline timer
So as to not fill the log with:
Failed to determine deadline: drmWaitVBlank failed: Operation not permitted

This currently happens on nvidia-drm but hopefully Nvidia will fix that
in future.

Relates to: https://gitlab.gnome.org/GNOME/mutter/-/issues/2923,
            https://gitlab.gnome.org/GNOME/mutter/-/issues/2924

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3138>
2023-08-07 16:30:32 +08:00
Daniel van Vugt
5a33e98431 kms/update: Remove unused is_flushing function
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3148>
2023-08-04 09:37:33 +00:00
Daniel van Vugt
6c97bd79d7 kms/cursor-manager: Fix backwards FB_UNCHANGED flag
It was causing the simple/legacy backend to never upload cursor buffers.

Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2927,
       https://gitlab.gnome.org/GNOME/mutter/-/issues/2931

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3144>
2023-08-02 16:15:11 +08:00
Michel Dänzer
679457373a tests/kvm: Use git fetch --depth=1
Otherwise it fetches the full history of the target tag, which is a lot
of data for the Linux kernel.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3141>
2023-07-30 16:29:33 +00:00
Robert Mader
7f19739e6b native/cogl-utils: Add YUV formats
As well as required subformats. This makes the YUV formats available in
zwp_linux_dmabuf_v1.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
2023-07-25 21:24:35 +00:00
Niels De Graef
239912cc1f wayland/dma-buf: Add support for YUV formats
Implement importing of multi-plane formats. For now, only support
importing planes individually using "sub-formats". This is the most
commonly driver-supported approach in the moment, used by other
Wayland compositors as well.

In the future we will additionally want to support importing the formats
directly and let the drivers handle conversion internally.

Co-Authored-By: Robert Mader <robert.mader@collabora.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
2023-07-25 21:24:35 +00:00
Robert Mader
b15e14e027 native/cogl-utils: Add MetaMultiTextureFormat section
So they can be derived from the DRM format as well.

While updating the users, ensure we don't announce support for
DRM formats in zwp_linux_dmabuf_v1 if the MetaMultiTextureFormat is
INVALID. This will be used for YUV subformats in following commits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
2023-07-25 21:24:35 +00:00
Niels De Graef
3dd9f15eba shaped-texture: Start using MetaMultiTexture
To be able to later support more complex YUV formats, we need to make
sure that MetaShapedTexture (the one who will actually render the
texture) can use the MetaMultiTexture class.

Co-Authored-By: Robert Mader <robert.mader@collabora.com>
Co-Authored-By: Daniel van Vugt <daniel.van.vugt@canonical.com>
Co-Authored-By: Sebastian Wick <sebastian.wick@redhat.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
2023-07-25 21:24:35 +00:00
Niels De Graef
5181a826d1 compositor: Add MetaMultiTexture class
In future commits, we want to be able to handle more complex textures,
such as video frames which are encoded in a YUV-pixel format and have
multiple planes (which each map to a separate texture).

To accomplish this, we introduce a new object `MetaMultiTexture`: this
object can deal with more complex formats by handling multiple
`CoglTexture`s.

It supports shaders for pixel format conversion from YUV to RGBA, as
well as blending. While custom bleding is currently only required for
YUV formats, we also implement it for RGB ones. This allows us to
simplify code in other places and will be needed in the future once
we want to support blending between different color spaces.

Co-Authored-By: Robert Mader <robert.mader@collabora.com>
Co-Authored-By: Sebastian Wick <sebastian.wick@redhat.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2191>
2023-07-25 21:24:35 +00:00
Jonas Ådahl
358c10de14 kms/cursor-manager: Only update cursor plane relevant device on mode set
When we see a mode set, the cursor manager will update all the cursor
planes so they are set correctly as part of the mode set. KMS updates
are always per-device, and what was wrong was that it didn't filter out
CRTCs on devices that wasn't part of the mode set.

Reported-by: Michel Dänzer <mdaenzer@redhat.com>
Tested-by: Michel Dänzer <mdaenzer@redhat.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3130>
2023-07-23 10:16:19 +00:00
Sebastian Keller
7faf4a308e constraints: Delay initial maximization until after reparenting is done
For SSD windows the decoration window from the frames client might have
a different maximization state than the client window and would end up
restoring it once shown. Avoid this issue by waiting until all
reparenting is done before applying the initial maximization (and
minimization).

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2579
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3035>
2023-07-21 11:38:17 +00:00
Daniel van Vugt
626498348b stage-impl: Blit damage regions of all ages when using a shadow FB
Original idea by Gert van de Kraats, modified to avoid having an
unused intermediate swap_region.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2602
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3117>
2023-07-21 10:43:18 +00:00
Jonas Ådahl
e96475bb8d build: Use correct variable for gathering built headers
We added things unused variable, which is a bit useless.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3131>
2023-07-21 07:59:54 +00:00
Daniel van Vugt
f5ff0f732a onscreen/native: Forget the view pointer when it is detached
Otherwise it would linger after a hotplug event, pointing to the old
(destroyed) view. And it's much easier to debug a NULL pointer than
a pointer to freed memory.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3118>
2023-07-20 23:28:49 +00:00
Michel Dänzer
e95499038d frames: Fix XGetWMNormalHints return value check
It returns non-0 if there are any hints in the WM_NORMAL_HINTS
property, 0 if there are none.

Fixes the mouse cursor changing to the resize shape over the decorations
of non-resizable windows.

Fixes: c7b3d8c607 ("frames: Push error traps around various X11 calls")
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3096>
2023-07-20 10:19:22 +00:00
Daniel van Vugt
db0870b114 cursor-renderer/native: Removed unused HW_CURSOR_BUFFER_COUNT
It stopped being used in e52641c4b6.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3129>
2023-07-20 15:08:49 +08:00
Gergo Koteles
7b04e8be15 wayland: Find touch grab sequence in subsurfaces also
With libdecor, window moving/resizing only works with
the pointer, not with touch.
The meta_wayland_pointer_can_grab_surface checks for subsurfaces,
but the meta_wayland_touch_find_grab_sequence does not.

Add a similar subsurface check to
meta_wayland_touch_find_grab_sequence.

Closes: GNOME/mutter#2872
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3125>
2023-07-19 13:07:51 +00:00
Bilal Elmoussaoui
b852bbba47 cleanup: Stop translating nick/blurb for pspecs
As those strings are intended to be used by some UI but nothing uses
that in reality except GStreamer.
So drop them similar to what GTK did at
https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4717

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3101>
2023-07-19 11:33:59 +00:00
Robert Mader
efe884a97f wayland: Remove DRM_FORMAT_MOD_INVALID defines
In both cases we already unconditionally import drm_fourcc.h and all
distros shipping recent Mutter should by now have versions of that file
containing MOD_INVALID.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
96778aa8b1 wayland/dma-buf: Make use of meta-cogl-drm-formats
Removing duplication, making it easier to add new formats and ensuring
that the native backend and Wayland clients can use the same formats.

Also improve related build files so the Wayland backend can be build
without the native backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
192d6686cf backend/cogl-utils: Move, rename to cogl-drm-formats and clean up
1. Move into the new 'common' folder and build for Wayland as well
   so we will be able to share the code in follow-up commits.

2. Rename to cogl-drm-formats to make it more obvious that the format
   map is more than an utility these days.

3. Drop the unused CoglTextureComponents part (see also previous
   commit).

4. Move the map to the header, simplifying some future use-cases.

5. Sync formats with MetaWaylandBuffer and MetaWaylandDmaBufBuffer and
   also use newly introduced opaque formats where appropriate.
   This avoids duplicated code, ensures that new drm-formats added to
   the dmabuf protocol have an adequate representation in Cogl from which
   information like alpha support can be easily derived and finally
   ensures we don't crash if the mappings got out of sync.

6. Remove some likely untested formats. In case some of these are
   actually needed on certain hardware, we can test whether we got
   the correct mapping by also adding support for the corresponding
   wl_shm_format in MetaWaylandBuffer by extending the gradient test in
   https://gitlab.freedesktop.org/jadahl/wayland-test-clients

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
ae88e13c5a wayland/buffer: Clean up format map
Use the newly introduced opaque formats where appropriate, allowing us
to drop the custom components handling.

Also use pre-mult alpha. This may slightly improve upload times
and should generally be more correct.

Tested with `weston-simple-shm`, ensuring the alpha channel still gets
ignored for opaque formats, and `gradient-test` from
https://gitlab.freedesktop.org/jadahl/wayland-test-clients

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Sebastian Wick
ae5512bc05 cogl/tests: Do not blend for texture format paint tests
The default cogl blend string is
`RGBA = ADD (SRC_COLOR, DST_COLOR*(1-SRC_COLOR[A]))` which is alpha
blending with premult fragment results. We do not clear the src
framebuffer and even if we did set alpha to 1 in the src fb, the
resulting alpha would be 1 and we want to check the alpha of the
fragment color.

Just turn off any kind of blending instead and write out the fragment
color to the fb.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Sebastian Wick
d79e4c182e cogl/tests: Fix float->int, int->float conversions
To obtain a float between 0 and 1 we have to devide the integer by the
highest possible value instead of the number of values.

Fixes off by one errors in the tests on some hardware/driver
combinations.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
4097cbbb53 cogl: Extend tests and fix RGB2101010 opaque formats
Notably fix several cases where bitmap packing was broken, resulting in
visual corruption with the GLES2 backend. These were reproducible with
the gradient-test from
https://gitlab.freedesktop.org/jadahl/wayland-test-clients

Also extend testing similar to the RGB8888 formats.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Robert Mader
f04209dcbf cogl: Add RGB8888 opaque format variants
So we can properly handle matching DRM and WL_SHM formats in a unified
manner.

Add extensive testing between these and existing pre-multiplied alpha
formats, i.e. all formats we support on Wayland.

Note that unfortunately for some format combinations  the value in the
alpha channel is not cleared as expected, likely because of fast-paths
in Cogl. If both source and destination format is opaque, it always
works, however. This thereby includes all cases where they are the same.

Co-Authored-By: Jonas Ådahl <jadahl@gmail.com>
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3065>
2023-07-19 10:39:55 +00:00
Jonas Ådahl
6841153ad7 tests/kms-device: Add test for scheduled no-ops
We can schedule an update from the cursor manager, but that doesn't mean
there will be an actual plane assignment changed at the time of the
update processing, since for example we might have "touched" a CRTC, but
already left it before the processing started, meaning we have nothing
to change after all.

Add a test case that checks that this works properly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
c96e835d56 thread/impl: Set the task source priority to rather high
Tasks should have high, but not highest priority. Roughly the aim is

  page flip feedback > composited updates > cursor updates

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
e52641c4b6 cursor-renderer/native: Replace HW cursor with KMS cursor manager
This removes the old hardware cursor management code and outsources it
to MetaKmsCursorManager. What the native cursor renderer still does,
however, is the preprocessing i.e. rotating/scaling cursor that wouldn't
otherwise be fit for a cursor plane.

The cursor DRM buffers are instead of being per cursor sprite now per
CRTC, meaning we don't need to stop doing hardware cursors if part of
the cursor is on an output that doesn't support it. This is why the
whole scale/transform code changed from being per GPU to per CRTC.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
ade2aa71ed tests/kvm: Bump timeout to 60 s
It can be quite slow to set up the test environment inside the VM, as
well as outside, leaving very little time for the test itself. While
it'd be nice to not run the mock env etc outside the VM, let's just bump
the timeout for now, to avoid unnecessary timeout failures.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
7a821345db tests/kms/device: Test cursor updates just before turning off CRTC
If we turn of a CRTC, we might have invalidated the cursor manager for
the same CRTC, but that should not mean a cursor plane is assigned when
turning off the CRTC.

Add a test case for this.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
6d873036e0 Add KMS cursor manager
This new manager object intends to take over management of the cursor
plane from the native cursor renderer. It's API is intended to be used
from the main thread, except for the _in_input() function, but mainly
operates in the KMS context, i.e. the KMS thread.

It makes use of an "update filter" that is called before each
MetaKmsUpdate is turned into a atomic KMS commit or a set of legacy
drmMode*() API calls. When the cursor position has been invalidated,
it'll assign the cursor plane in the filter callback, using an as up to
date as possible pointer position as the source for the cursor plane
position.

Cursor updates from the input thread schedules updates for the affected
CRTCs which will cause the filter to be run, potentially for cursor-only
commits.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
5a798989c4 seat/native: Add run impl task helper
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-18 23:51:34 +02:00
Jonas Ådahl
ef64279035 seat/impl: Add signal for pointer motions
This signal is emitted directly in the input thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 23:42:38 +02:00
Jonas Ådahl
f4b76727db stage-view: Add API to inhibit cursor overlay painting
This adds some plumbing to get the "default" paint flags for regular
stage painting, where one either wants to paint the overlay, or not.

If inhibited, the 'no-cursors' paint flag is used, otherwise the 'none'
flag. This will be used to allow having a per stage view hw cursor
state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 23:42:38 +02:00
Jonas Ådahl
5d35138df0 cursor-renderer: Make 'handled_by_backend' state 'needs_overlay'
This will, conceptually, and eventually, allow a backend to both want an
overlay, while still handling it by default.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 23:42:38 +02:00
Jonas Ådahl
3b2f95cb1f kms/update: Add destroy-notify to result listener user data
No thread guarantees, users need to handle it themselves.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 23:42:38 +02:00
Jonas Ådahl
27ed069766 kms/impl-device: Add deadline based KMS commit scheduling
This makes it possible to post KMS updates that will always defer until
just before the scanout deadline. This is useful to allow queuing cursor
updates where we don't want to post them to KMS immediately, but rather
wait until as late as possible to get lower latency.

We cannot delay primary plane compositions however, and this is due to
how the kernel may prioritize GPU work - not until a pipeline gets
attached to a atomic commit will it in some drivers get bumped to high
priority. This means we still need to post any update that depends on
OpenGL pipelines as soon as possible.

To avoid working on compositing, then getting stomped on the feet by the
deadline scheduler, the deadline timer is disarmed whenever there is a
frame currently being painted. This will still allow new cursor updates
to arrive during composition, but will delay the actual KMS commit until
the primary plane update has been posted.

Still, even for cursor-only we still need higher than default timing
capabilities, thus the deadline scheduler depends on the KMS thread
getting real-time scheduling priority. When the thread isn't realtime
scheduled, the KMS thread instead asks the main thread to "flush" the
commit as part of the regular frame update. A flushing update means one
that isn't set to always defer and has a latching CRTC.

The verbose KMS debug logging makes the processing take too long, making
us more likely to miss the deadline. Avoid this by increasing the
evasion length when debug logging is enabled. Not the best, but better
than changing the behavior completely.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 23:42:38 +02:00
Jonas Ådahl
48501236ec kms: Move error codes to main header
Some will be used outside of meta-kms*.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
ee87654224 kms/update: Add helper to checking if an update passed
Instead of comparing values, just add a `did_pass()` helper.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
5bed90114d kms/update: Treat NULL main context as default for page flips too
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
40caa6d87c kms/update: Use callback helper to free page flip listener data
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
6059d8f42d kms/page-flip: Make destroy notify function optional
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
587da92b0a kms: Mark mode set updates as such
This is currently unused, but will be later used to distinguish betwen
per frame/CRTC updates and device wide ones.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
a7954f4a75 onscreen/native: Move out timeval to timestamp helper
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
17a78303d0 kms: Make result listener take a vtable too
As with the page flip listener, prepare to make result listeners more
capable by allowing more vfuncs for the same listener instance in the
future.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
f97f0f2781 thread: Document the behavior of meta_thread_post_impl_task()
Specifically in what contexts things are invoked.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
6ed75c6253 thread: Allow passing a NULL callback vfunc
This is useful when one just wants to free something, which can be done
using the passed destroy notify function.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
0d5d1745ce thread: Push the thread-default main context
Makes g_main_context_get_thread_default() do the right thing.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
59ba952661 thread: Always add impl thread context as callback source
This is helpful when we add callbacks that should be dispatched in the
KMS impl thread.

This invalidates an assumption about callbacks not being in the impl
context, so some asserts for that are also removed.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
84ff167328 thread: Add private API to flush callbacks for main context
This will be used to flush out certain callbacks when switching thread
type.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
2617bd8e72 thread/impl: Add 'reset' signal
This signal is emitted before terminating the thread, but also when
resetting the thread type. This is to allow thread implementations to
make sure they have no stale pending callbacks to any old main contexts.

This commit "terminates" the impl thread even if there is no actual
thread; this is to trigger the "reset" signal, also when switching from
a user thread to a kernel thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
bedec579b8 tests/kms/updates: Use async update API
We ignored the feedback and entered a temporary main loop, so no need to
do things sync.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
15a91e9fd4 kms/update: Stop sealing updates
This isn't very useful anymore, since posting an update takes ownership
of it. Not sealing it also means e.g. more listeners can be added after
posting.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
54d9fab161 kms: Ask to be real time scheduled
This will allow more time sensitive scheduling strategies.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
6da3e9eb69 thread/impl: Add API to tell whether its realtime scheduled
Will be used by thread impl's to decide whether they can rely on real
time scheduling or not.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
e92e4fe64d thread: Register with profiler
This means we can add COGL_TRACE*() instrumentation that is grouped
correctly in sysprof. If kernel threading is enabled, they will end up
in a "Compositor (KMS thread)" group (ignoring translations).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
bd2fa92c29 thread: Support making threads real time scheduled
Real time scheduling is needed for better control of when we commit
updates to the kernel, so add a property to MetaThread that, if the
thread implementation uses a kernel thread and not a user thread, RTKit
is asked to make the thread real time scheduled using the maximum
priority allowed.

Currently RTKit doesn't support the GetAll() D-Bus properties method, so
some fall back code is added, as GDBusProxy depends on GetAll() working
to make the cached properties up to date. Once
https://github.com/heftig/rtkit/pull/30 lands and becomes widely
available in distributions, the work around can be dropped.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
276ebbf5ee kms: Use a kernel thread by default
Also add an API to inhibit the kernel thread from being used, and make
MetaRenderDeviceEglStream inhibit the kernel thread from being used if
it's active.

The reason for this is that the MetaRenderDeviceEGlStream is used when
using EGLStreams instead of KMS for page flipping. This means the actual
page flipping happens as a side effect of using EGL/OpenGL, which can't
easily be done off thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
788ad43e17 thread: Allow switching thread type
This will be necessary in order to default to 'kernel' and then switch
to 'user' if the thread instance can no longer be properly multi
threaded.

To avoid having the same thread impl creating and destroying
GMainContext's, this also means always creating a GMainContext for the
thread-impl. When running in user-thread mode, the GMainContext is
wrapped in a wrapper source and dispatched as part of the real main
thread GMainContext, and when in kernel-thread mode, it runs
independently in the dedicated thread.

This has the consequence that the wrapper source will always have the
priority of the highest impl context GSource, but only after it has
dispatched once. Would we need it earlier than that, we either need a
way to introspect existing sources in a GMainContext and their
priorities, or manually track known sources in MetaThreadImpl.

The wrapper source will never be below 0, as that'd mean it could reach
INT_MAX priority if it had no more sources attached to it, meaning it'd
never be dispatched again.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 21:19:34 +02:00
Jonas Ådahl
33b33aa370 onscreen/native: Post updates asynchronously
Results are handled in callbacks anyway, there is no need to wait for
the KMS thread to finish.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
718c78a365 kms: Add API to pass updates asynchronously
While doing this, rename the old synchronous functions to more clearly
communicate that they expect to actually process the update during the
call, not just post it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
e4a8fc93a1 thread: Add destroy notify function for post user data
The destroy notify function can be called on any thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
7c9d4b8c7c kms/result-listener: Allow setting a custom main context
While the default when passing NULL will be the main context of the main
thread, make it possible to specify another main context, so that
result handlers can be invoked on the right thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
1e0367bf08 tests/kms/update: Move out some repetitive code into helper
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
1350b5e260 thread: Make it possible to run sync tasks from any thread
When a task is posted from a non-main thread, a user thread still needs
to go via the queue and be signalled using the condition, just as if it
was a kernel thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
d77b5935cd kms/update: Allow page flip callback listeners on any thread
This hooks into the MetaThread GMainContext callback machinery just
added; and allows receiving page flip callbacks on any thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
f83c30bae5 thread: Support queuing callbacks on any thread
Callbacks could be queued to be invoked either on the impl side or the
main thread side of the thread; change this to take a GMainContext,
which effectively means a callback can be queued to be invoked on any
thread that has a GMainLoop running on its own GMainContext.

Flushing is made to handle flushing callbacks synchronously on all
threads. This works by keeping a hash table of queued callbacks per
thread (GMainContext); when flushing (from the main thread), callbacks
on the main thread context is flushed, followed by synchronization with
all the other threads.

meta_thread_flush_callbacks() is changed to no longer return the number
of dispatched callbacks; it becomes much harder when there are N queues
spread across multiple threads. Since it wasn't used for anything, just
drop the counting, making life slightly easier.

Feedback to thread tasks are however always queued on the callers
thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 17:23:31 +02:00
Jonas Ådahl
ae48019cce tests/kms: Run tests with kernel/user thread too
This means each test is run 4 times:

 * with atomic mode setting using a kernel thread,
 * with atomic mode setting using a user thread,
 * with legacy mode setting using a kernel thread, and
 * with legacy mode setting using a user thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
f1356ce5d3 kms: Add debug env var to configure thread implementation type
Set MUTTER_DEBUG_KMS_THREAD_TYPE to either 'kernel' or 'user', and the
MetaThread backend will be either a kernel thread or a user thread.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
8b612a6150 thread: Introduce kernel thread support
This commit makes it possible to create a MetaThread where the
MetaThreadImpl side runs in a real thread, instead of a artificially
separated impl context.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
4c317eae07 thread: Make callback handling thread safe
This is in preparation for introducing kernel threads, where proper
synchronization becomes necessary.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
915bceb5a0 thread: Add name to threads
So far this is used to assign names to relevant sources, but will used
to name the kernel threads, when they are introduced.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
251722ec4e thread: Flush tasks and callbacks on finalize
This will make sure no tasks or callbacks are unexpectedly dropped,
potentially leaking or leaving things in an unexpected state.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
261624538c tests/thread: Quit main loop in idle callback if in impl thread
This isn't a problem for user space threads, as there are no race
conditions, but when kernel thread support is introduced, we must make
sure that e.g. the main loop is actually running before quitting it.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
50b0d8cb18 tests/thread: Test mixing async and sync task
The expected behaivor is that the sync task will "flush" the async
tasks, i.e. to maintain task order.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
069bee0ce8 tests/thread: Test multiple queued tasks
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
aa723e7207 thread: Add support for posting async task
This uses the queue that was introduced when migrating impl task
management from MetaThread to MetaThreadImpl, with the exception that
it's now fully used as an actual queue. It now has a GSource that sits
on the right GMainContext that is dispatched whenever there are tasks to
execute.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
fda883e859 thread: Move context and task management to impl side
It's the impl side that wants to add impl side idle sources, or fd
sources, etc, so make it part of MetaThreadImpl.

This changes things to be GAsyncQueue based. While things are still
technically single threaded, the GAsyncQueue type is used as later we'll
introduce queuing tasks asynchronously, then eventually queuing across
thread barriers.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
229904cb4b kms: Use MetaThread source helpers directly
No need to have thin meta_kms_* wrappers, just use the meta_thread_*
functions directly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:36 +02:00
Jonas Ådahl
2e025eea0e tests: Add MetaThread tests
Tests posting sync tasks, posting callbacks, adding impl side fd
sources, callback flushing, impl side idle callbacks.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:51:35 +02:00
Jonas Ådahl
7277592255 thread: Initialize using GInitable
To later add error handling.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:45:00 +02:00
Jonas Ådahl
a6baa77eab kms: Split out impl/non-impl separation into MetaThread(Impl)
It currently does exactly what MetaKms and MetaKmsImpl did regarding the
context separation, which is to isolate what may eventually run on a KMS
thread into a separate unit. It works somewhat like a "user thread",
i.e. not a real thread, but will eventually learn how to spawn a
"kernel thread", but provide the same API from the outside.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:45:00 +02:00
Jonas Ådahl
7fea24d585 cursor-renderer: Realize texture before using it for its size
If we don't, well return an empty size, despite it in practice
shouldn't.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2777>
2023-07-17 12:45:00 +02:00
Olivier Fourdan
6d0b682d98 remote-desktop/eis: Add support for ConnectToEIS.
Remote desktop version 2 added a new method ConnectToEIS .

ConnectToEIS allows clients to requests a file descriptor from the
compositor which can then be used directly from libei.

Once established, the communication between compositor and application
is direct, without the need to go through the portal process(es).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Olivier Fourdan
812eeddfde backends/eis: Add a new API to get the fd from MetaEIS
This is preparation work for supporting ConnectToEIS.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Peter Hutterer
a6d406d7bf backends/eis: Hook eis into the debug system
To be enabled with MUTTER_DEBUG=eis

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Peter Hutterer
a20aa28af0 backends/eis: Add EIS client support
This adds support for EIS clients in the form of MetaEis and
MetaEisClient.

The purpose is to allow clients to connect and send emulated input events
using EIS.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
2059273f57 tests/input-capture: Add test for ATK input capture
Cally should not see the events when they are captured.

[ofourdan] Wait for paint before checking button count.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
1513eccc03 tests/input-capture: Test that a11y isn't triggered when capturing
Accessibility should be handled on the receiving end, if needed. Make
sure this is the case by listening on some signals, verifying they are
only triggered if we're not capturing input.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
2fb3bdf774 input-capture: Hook up capturing of events to active session
This adds the actual input capturing rerouting that takes events and
first hands them to the input capture session, would it be active.
Events are right now not actually processed in any way, but will
eventually be passed to a libei client using libeis.

A key binding for allowing cancelling the capture session is added
(defaults to <Super><Shift>Escape) to avoid getting stuck in case the client
doesn't even terminate the session.

The added test case makes sure that the pointer moves again after
pressing the keybinding.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
38d1666049 clutter/event: Set the constrained relative motion too
When a relative pointer motion gets constrained (e.g. a monitor edge or
barrier), save the constrained relative motion delta too.

This will later be used to send the remaining motion delta to input
capture clients.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
a170f2a82b seat/impl: Move out the GSource implementation to a helper object
This will help adding similar sources that work practically the same.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
3bd401f33a backend: Add input capture getter
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
f9b18d90c6 keybindings: Make event handlers take a const ClutterEvent
This avoids discarding the const qualifier.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
a2bdce2c8e clutter/seat: Add seat name
This is similar to the existing seat-id that is part of MetaSeatNative,
but meant to be passed to created input capture seats.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00
Jonas Ådahl
e917b7de43 clutter/stage: Add input-only grabs
An input only grab is a ClutterGrab on the stage that doesn't have an
explicit actor associated with it. This is useful for cases where event
should be captured as if focus was stolen to some mysterious place that
doesn't have anything in the scene graph that represents it.

Internally, it's implemented using a 0x0 sized actor attached directly
to the stage, and a clutter action that consumes the events. An
input-only grab takes a handler, user data and a destroy function for
the user data. These are handed to the ClutterAction, which handles the
actual event handling.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2628>
2023-07-14 22:23:45 +00:00