Commit Graph

5987 Commits

Author SHA1 Message Date
der richter 86fa9b18a3 osdep/mac: make mac naming of files, folders and function consistent
rename all macOS namings (osx, macosx, macOS, macos, apple) to mac, to
make naming consistent.
2024-02-28 15:52:47 +01:00
Dudemanguy 661f45377a wayland: drop some unneeded curly braces (no-op)
Not sure why all of these single line if's were being braced. Probably
some cargo cult from years ago but might as well fix it now since it's
bothering me.
2024-02-27 22:18:12 +00:00
Dudemanguy f0a6578259 wayland: drop buffer scale for cursor as well
Could have been done in e32554cd57, but I
skipped it there. However, using viewporter is actually a win here.
There's been a longstanding issue in upstream wayland* exactly related
to this. I even forgot about cd7a7a1de8
which was made for this exactly problem and explains the random
spawn_cursor calls. Anyways, just not using buffer scale and instead
scaling the cursor surface via viewporter works just fine and completely
sidesteps this problem. This means we can drop the random looking
spawn_cursor calls and some additional checks.

*: https://gitlab.freedesktop.org/wayland/wayland/-/issues/194
2024-02-27 22:18:12 +00:00
Dudemanguy 34c0a67ace wayland: rename configured to geometry_configured (no-op)
Makes it clearer.
2024-02-27 22:18:12 +00:00
Dudemanguy 7b03a2ff17 wayland: fix check for set_surface_scaling
We don't want to use this if we have fractional scaling or version 6 of
the wl_surface interface which has a preferred buffer scale event which
is superior to this. We were checking in the important place (surface
entrance events) but not technically in the output. So just move the
conditional to set_surface_scaling itself. Also through the VO_EVENT_DPI
in there for convenience.
2024-02-27 22:18:12 +00:00
der richter c15307244f mac: remove unnecessary metal layer colour space update
this logic was copied from the cocoa-cb opengl backend, since it was
assumed both layers work similar. apparently they don't and a nil value
on the metal layer means use the display colour profile, while on the
opengl layer it means undefined behaviour.

this also fixes a problem with the target-colorspace-hint option, since
moltenvk needs to set this colour space itself for a proper hint. both
mechanism would compete to set the colour space.
2024-02-27 14:03:15 +01:00
der richter 7a1b387aa9 mac: set layer content scale on init
usually the content scale updates automatically, though on init it is
possible the wrong scale is used for the initial rendering leading to a
wrongly sized surface.

properly set the initial content scale of the layer.
2024-02-27 14:02:08 +01:00
der richter a7c4a113b8 cocoa-cb: remove pre-allocation and initialise only when used
cocoa-cb was always pre-allocated in the Application itself because
libmpv needs to be set up before usage, an opengl context has to be set
and because it was decided mac specific code should be kept out of
libmpv.

this means that a completely working libmpv and opengl renderer was set
up even if it wasn't used. leading to unnecessary log message, resources
being used or reserved on the system that might not be used, triggering
of dedicated GPU unnecessarily and many other things.

even if not optimal, this wasn't the biggest problem since we only had
that one working vo on macOS. though now that we have a vulkan
gpu(-next) backend on macOS that was made the default, we always have
that dangling cocoa-cb instance, which is completely unnecessary.

move the cocoa-cb initialisation into libmpv preinit function and only
init cocoa-cb when we are a standalone App and cocoa-cb support is build
into.
2024-02-27 14:01:38 +01:00
Dudemanguy fa0fccc2a7 vo_gpu_next: simplify pl_clear_mode enum mapping
No reason for there to be two columns and this also fixes a
-Wenum-conversion warning on clang.
2024-02-26 20:07:43 -06:00
Dudemanguy bc4003d219 vo_gpu_next: add --border-background option
Allow for setting the border background independently from the
background option.
2024-02-26 16:46:00 +00:00
Dudemanguy be198c0f0a vo_gpu_next: support --background option
Requires using the new pl_clear_mode enum in libplacebo.
2024-02-26 16:46:00 +00:00
Dudemanguy 183f63c8c9 vo_gpu: pre-multiply alpha when dealing with background colors
This was simply wrong for who knows how long.
2024-02-26 16:46:00 +00:00
Dudemanguy c72c47204d vo_gpu/vo_gpu_next: rework --alpha into --background option
The --alpha option currently covers two related but different concepts:
whether or not to ignore the alpha component and possibly blending it
with a background. Because of the way the option currently works, it is
impossible to have a transparent window (which requires setting
--alpha=yes) while blending it with the background at the same time. To
solve this, let's rework it so it it superseded by the background
option.

--background controls what kind of background to set for the image if
possible. It can be blended with the set background color, with tiles,
or not blended at all (the last one is still broken on X11/mesa except
for GLX, *sigh*). In this new paradigm, --alpha=no has no real purpose
because you can simply set the background to color and whatever color
you want for exactly the same effect. So the option is removed. Instead,
the hint set by windowing backends (i.e. setting
ra_ctx->opts.want_alpha) can by done with the --background option.

As an aside, the colors in vo_gpu are currently bugged due to not
pre-multiplying the alpha and it seems no one ever noticed. The next
commit fixes that. vo_gpu_next support happens latter since it requires
new things from libplacebo.

Fixes #9615.
2024-02-26 16:46:00 +00:00
Dudemanguy c774b5f517 player: rename --background to --background-color
This better represents what it actually does. --background will be used
for another, related option in the next commit.
2024-02-26 16:46:00 +00:00
Dudemanguy b7fd232524 vo_gpu/vo_gpu_next: set ctx->opts.want_alpha in specific functions
Currently this was being duplicated on init and on runtime updates
between both VOs. Since the conditions for setting this will get more
complicated in the future commits, it's better to just handle it in one
place. We could combine the vo_gpu and vo_gpu_next handling into one
single function but vo_gpu_next has an additional condition for
determining alpha that vo_gpu_does not, so we'll leave these separate
for simplicity. Also this technically fixes a memory leak where gl_opts
weren't being freed.
2024-02-26 16:46:00 +00:00
sfan5 bbbc0e248b hwdec/dmabuf_interop: reduce magic constant use 2024-02-26 17:37:20 +01:00
sfan5 73556036a2 hwdec/dmabuf_interop_gl: migrate to EXT_EGL_image_storage on desktop GL
As it turns out OES_EGL_image is only defined for OpenGL ES.
OpenGL drivers implement this extension anyway because it used to be
the only way of importing EGLImages into GL.

An equivalent extension for OpenGL was defined with EXT_EGL_image_storage.
The only difference is the interaction with immutability, which requires
textures to be recreated since they can be bound only once.

Note: this commit can in theory cause certain systems to lose vaapi / drmprime
support. Since EXT_EGL_image_storage is 7 years old this hopefully doesn't happen.
If it does, the init checks can be relaxed to still permit OES_EGL_image.
2024-02-26 17:37:20 +01:00
sfan5 1ae0282c1b hwdec/dmabuf_interop_gl: refactor texture creation
no functional changes in preparation for the next commit
2024-02-26 17:37:20 +01:00
sfan5 c294408ce0 hwdec/dmabuf_interop_gl: restyle macros to fit line length 2024-02-26 17:37:20 +01:00
sfan5 861e9566f6 video: don't define IMGFMT_VULKAN conditionally
We generally try to avoid that due to the #ifdef mess.
The equivalent format is defined in ffmpeg 4.4 while our interop code
requires a higher version, but that doesn't cause any problems.
2024-02-26 17:37:20 +01:00
Dudemanguy 76472e1ba8 wayland: remove old sway/wlroots hack
It's actually been like this for years, but wlroots doesn't keep track
of resizes a client does independent of the compositor. When using sway,
this leads to weird behavior with floating clients resizing themselves
back to the old size if you unfocus it. mpv has been working around this
for a long time, but it's really annoying to selectively ignore events
based on a weird heuristic. Since Sway finally fixed this bug, let's go
ahead and drop this crap. Note that other wlroots compositors may
possibly experience a regression if they didn't correct for this like
sway does, but it's for their own good.
2024-02-26 15:51:16 +00:00
nanahi 6ecdedabe5 vo_gpu_next: fix win32 io wrap
Fixes 84015959cc
2024-02-26 09:37:24 +01:00
David Vaughan a8a314b829 input: add insert-next support for drag-and-drop
This commit adds a DND_INSERT_NEXT action option for drag-and-drop,
allows for selecting it through the --drag-and-drop=insert-next option,
and adds the necessary plumbing to make that happen when something is
dragged onto the player.
2024-02-26 02:03:21 +00:00
nanahi 3e8d69e3e8 image_writer: cleanup leftover files if image writing fails
This avoids leaving an empty/corrupt file if fopen succeeds but
image writing fails afterwards.
2024-02-25 11:37:44 +01:00
Dudemanguy 17d9abd08f player/command: handle runtime toggling of hidpi-window-scale
Wayland was the only backend that attempted this, but it can be done in
a centralized place for anything that supports this. hidpi-window-scale
is just the same as a normal window scale but with the OS DPI as the
factor.
2024-02-24 20:31:08 +00:00
Dudemanguy a3648ddac8 win32: clean up hidpi window scale behavior
Same as X11. An accurate dpi scale should always be reported and
UNFS_WINDOW_SIZE shouldn't take dpi scale as an additional multiplier.
2024-02-24 20:31:08 +00:00
Dudemanguy 006822434a x11: clean up hidpi-window-scale behavior
Several related things but in a nutshell makes it more like wayland.

1. Remove unneeded --hidpi-window-scale checks. The backend should
   always report the actual dpi value regardless of what this option
   says.
2. Remove dpi_scale factors from UNFS_WINDOW_SIZE VOCTRLs. It makes
   things more complicated and unintuitive for no reason. A window scale
   of 1 should mean 1. It annoyed a few years ago in #9437, and I agree
   with them (wayland was never implemented like this).
3. Change the dpi log messages to be more brief and remove the unneeded
   comments about prescaling.
2024-02-24 20:31:08 +00:00
nanahi 3e17d9da8f vo_gpu: use fbo texture height for fragment coordinate calculation
Previous fix only worked when the video output doesn't have vertical
black bars. This fixes the cases like fullscreen, video-zoom etc.

Fixes: https://github.com/mpv-player/mpv/pull/13528
2024-02-24 21:12:17 +01:00
nanahi 84015959cc osdep/io: move I/O utility functions to misc/io_utils
The purpose of osdep/io is to provide a wrapper for POSIX I/O functions
on Windows. The last 2 functions are utility functions which don't serve
this purpose.
Move them to a separate file.
2024-02-23 21:35:57 +01:00
nanahi ae1a4ed28a vo_gpu: fix fragment coordinate calculation when dithering
When doing the dithering pass, the fragment coordinate is queried, but
doesn't take the fbo texture flipped property into account. This results
in different dithering patterns when toggling between fbo flipped and
non-flipped state. This can be reproduced with --vo=gpu --gpu-api=opengl
and easily seen with --dither-depth=1 when toggling between playing and
pausing.

Fix this by flipping the fragment y coordinate if the fbo is flipped
when calculating dithering coordinate.
2024-02-22 12:35:40 +01:00
nanahi 74f2260cd6 vo_gpu: fix fragment coordinate calculation when drawing checkerboard
When redrawing cached frames while the fbo texture is flipped,
the texture after drawing to screen pass will be flipped when blitting.
However, when rendering the checkerboard, the fragment coordinate
doesn't take this into account, so the coordinate before flipping is used,
resulting in different checkerboard location when toggling between
flipped and non-flipped state. This can be reproduced with --vo=gpu
and --gpu-api=opengl: the checkerboard patterns when playing and
pausing are different (vertically flipped).

Fix this by flipping the fragment y coordinate if the fbo is flipped
when calculating checkerboard coordinate.
2024-02-22 12:35:40 +01:00
nanahi 531704e35d x11_common: handle window dragging in ButtonPress event
Begin the _NET_WM_MOVERESIZE window dragging in ButtonPress event
to match the behavior of win32 and wayland, simplify logic by dropping
the win_drag_button1_down hack required by the old method, and fix a race
condition described in commit 19f101db68,
which happens when moving the mouse and releasing the button at the same time.

The race condition can be easily triggered when using a touch screen
(tested with libinput driver), where a tap is translated to MotionNotify,
ButtonPress, MotionNotify, and ButtonRelease in sequence, with the last 2
events having the same timestamp. This has caused some window managers to
not stop dragging after the ButtonRelease, resulting in window being stuck
in dragging state after a single tap.
2024-02-21 22:39:28 +01:00
der richter d954646d29 various: make mentions of macOS consistent
change all mentions and variations of OSX, OS X, MacOSX, MacOS X, etc
consistent. use the official naming macOS.
2024-02-21 20:46:53 +01:00
der richter 0e441525cf vo: make libmpv last in the auto-probing order for cocoa-cb only
this partially reverts commit 7b5a258. back then the only properly
working vo on macOS was cocoa-cb (libmpv). it would always use the
deprecated opengl cocoa backend or no vo at all. because of that libmpv
was moved to the top of the auto-probing order, so the preferred vo
was used on macOS only.

we now have a working vulkan gpu/gpu-next backend on macOS which should
be the new default vo. though disabling the auto-probing again for
libmpv would probably cause the undesired behaviour on macOS that
cocoa-cb would never be auto selected again. especially if not build
with vulkan support or without vulkan driver on macOS, this would lead
to no video output at all. so instead of completely reverting the
mentioned commit, we instead move libmpv to the bottom of the
auto-probing order but only auto select it when mpv was built with
cocoa-cb support. this restores the previous behaviour on all other
platforms besides macOS, but also lets us auto select cocoa-cb if
supported.
2024-02-20 20:42:02 +01:00
Julian Orth 0ef78c1aa5 wayland_common: update pointer serial on pointer_enter 2024-02-18 18:21:02 +00:00
der richter ac275a823d cocoa-cb: lock CGLContext on uninit and manual redraw
this fixes a crash on quit, when a CATransaction from a system owned
thread/event is happening at the same time. locking the context
synchronises these access and prevents the race condition.

the draw operation induced by any display call from the CAOpenGLLayer
doesn't need that lock, since the display function already does lock
that current context.

Fixes #11681
2024-02-18 17:25:05 +01:00
Dudemanguy bd5b80ba2c vo_gpu_next: fix some lut-related memory leaks 2024-02-17 18:56:20 +00:00
Dudemanguy 85e84f6d92 vo_gpu_next: move gpu-next opts to specific sub option
This matches the general workflow in the codebase. We keep a cache of
these new options and update them if needed.

Fixes #13481 and fixes #11518.
2024-02-17 18:56:20 +00:00
Dudemanguy 073858fcdd vo: remove VOCTRL_SET_EQUALIZER and simplify into UPDATE_VIDEO
Since 03cf150ff3, the only purpose of this
VOCTRL was to signal a redraw to the vo. It actualy could have been
removed in 531868fe0d, but this was
missed. The UPDATE_VIDEO flag is better anyway because it allows us to
handle a wide variety of options scattered around that require the VO to
update itself and redraw. We can remove both of the custom callbacks in
vo.c and only leave the VOCTRL_VO_OPTS_CHANGED one. Additionally, that
commit also introduced vo_set_want_redraw, but this is redundant and not
needed. The VOs that use VOCTRL_UPDATE_RENDER_OPTS already set
vo->want_redraw, and those are the only VOs where these options are
relevant in the first place. So we can remove this as well and just let
the big callback in player/command do everything.
2024-02-17 18:56:20 +00:00
nanahi fb33bb7fc4 wayland_common: drop shape device check when spawning cursor
It's only necessary to check the existance of cursor_shape_manager.
Also drop the pointer check to handle multi-seat since a removed seat
sets the cursor_seat to NULL.
2024-02-17 16:09:41 +00:00
nanahi b441a5dd1f wayland_common: properly determine has_keyboard_input
Track has_keyboard_input per seat and consider mpv having keyboard input
if at least one seat has keyboard input.
2024-02-17 16:09:41 +00:00
nanahi a6ae2e7e60 wayland_common: handle scroll accumulation for each seat
Since it's needed to determine whether an axis event has axis_value120,
do this per seat to avoid interference between seats.
2024-02-17 16:09:41 +00:00
nanahi 04bc6a4a43 wayland_common: handle keyboard state per seat
Avoids modifiers from mulitple seats from interfering with each other
and messing up xkb states.
2024-02-17 16:09:41 +00:00
nanahi b6dcf9ecee wayland_common: set cursor visibility for all seats for voctrl
For VOCTRL_SET_CURSOR_VISIBILITY, set cursors visibility for all seats.
The return is VO_NOTAVAIL is none of the seats have cursor, and
VO_FALSE if setting visibility failed for at least one seat.
2024-02-17 16:09:41 +00:00
nanahi b86768b356 wayland_common: handle removal of seats 2024-02-17 16:09:41 +00:00
nanahi cdca02a34d wayland_common: prevent cursor_seat stale reference
Set it to NULL on vo uninit.
2024-02-17 16:09:41 +00:00
nanahi a593a9ec12 wayland_common: handle cursor_shape_device per seat
The cursor_shape_device is per pointer, which is per seat. Handle it
together with other seat objects. This in turn also handles cursor
visibility per seat.
2024-02-17 16:09:41 +00:00
nanahi 27d973ba34 wayland_common: drop unnecessary xdg_toplevel null check
The vo init already fails if xdg_toplevel creation fails, so these
checks after the vo is initialized is unnecessary.
2024-02-17 16:09:41 +00:00
nanahi 2274311b25 wayland_common: implement multi-seat support
On a multi-seat setup, wl_registry_global advertises wl_seat multiple times,
one for each seat. if wl->seat is already set, the previous value will be
overwritten, preventing it from being freed.

Additionally, if the latter seat doesn't have the capabilities of the
former seat, the keyboard/pointer/touch input devices will be destroyed
because the current wl_seat_capabilities doesn't distinguish between
different seats. This casues keyboard/pointer/touch not working if the
latter seat has no such capabilities.

Fix this by implementing multi-seat support.
This allows receiving inputs from all devices on all seats.
All seat-specific objects (wl_keyboard/pointer/touch, wl_data_device)
are grouped with their respective seats so they can be managed together.

Note that currently inputs from all seats are interleaved with each other
and modify the same global input states.
2024-02-17 16:09:41 +00:00
nanahi 5557eda842 wayland_common: indentation nit 2024-02-17 16:09:41 +00:00