0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00
Commit Graph

6170 Commits

Author SHA1 Message Date
nanahi
9a861c930b image_writer: fix TOCTOU in screenshot filename generation
The screenshot command is documented to not overwrite existing files.
However, there is a race window between the filename is generated with
gen_fname and when the file is open to write. Specifically, the
convert_image function in this window can be very time consuming
depending on video and screenshot image format and size. This results
in existing file being overwritten because the file writing functions
don't check for the existance of file.

Fix this be opening the file in exclusive mode. Add overwrite parameter to
write_image for other operations that are documented to overwrite existing
files, like screenshot-to-file. Note that for write_avif, checking
existance is used instead because avio_open does not support exclusive
open mode.
2024-03-19 19:30:27 +01:00
Kacper Michajłow
374470d471 repack: add restrict qualifier to src/dst pointers
Allows compiler to do its job and optimize this code. We don't really
want to repack in-place.
2024-03-19 13:04:05 +01:00
nanahi
e0b517985b win32: resolve dropped shell links (Windows shortcuts)
When a shell link is dropped onto the mpv window, the file name will be
replaced by the file name of its target so that the linked file is played.
2024-03-19 11:34:00 +01:00
Leo Izen
3e7d36c295 video/image_writer: attach MDVC metadata and CLLI metadata
This commit allows image_writer to attach HDR metadata to AVFrames via
the corresponding AVFrameSideData attachments, if present. It does this
by calling pl_avframe_set_color, already used by mp_image_to_avframe.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
2024-03-19 09:49:04 +01:00
llyyr
f914947dda vo_gpu_next: make dither-depth=auto mean 8 bpc for non-d3d11 SDR
Fixes the issue described in https://github.com/mpv-player/mpv/issues/11862
for SDR files for non-d3d11 gpu-api. We currently don't have a smarter
way to get the real on-the-wire bpc for other APIs, so this is the best
that can be done.
2024-03-19 09:06:01 +01:00
llyyr
16ae76948d vulkan: remove color_depth stub
Needed for the next commit
2024-03-19 09:06:01 +01:00
nanahi
a6f8d1d961 vo_gpu_next: fix -Wembedded-directive warning
warning: embedding a directive within macro arguments has undefined behavior
2024-03-19 08:58:18 +01:00
nanahi
59f23f5c29 video/out/gpu/spirv: fix warning: zero size arrays are an extension 2024-03-19 08:58:18 +01:00
nanahi
82a186567e various: fix -Wold-style-declaration warning
warning: `static' is not at beginning of declaration
2024-03-19 08:58:18 +01:00
nanahi
4f381f2137 video/out/placebo/utils: fix -Wignored-qualifiers warning
warning: type qualifiers ignored on function return type
2024-03-19 08:58:18 +01:00
Kacper Michajłow
cbe30f614d vo_gpu_next: don't render ASS subtitles at HDR colorspace
Upstream ASS specification says that all subtitles should be rendered
with color primaries and transfer matching their associated video. But
as expected after further discussion the decision has been made to
fallback to SDR mode in case of HDR video.

See-Also: 649a7c2e1f/libass/ass_types.h (L233-L237)
See-Also: libass/libass#297
See-Also: mpv-player#13381
Fixes: mpv-player#13673
2024-03-18 21:24:06 +01:00
Kacper Michajłow
c155c18023 win32: remove all NC area on Windows 10 with --title-bar=no
Windows 10 top bar height cannot be adjusted individually when
WS_CAPTION is enabled due to buggy DWM NC drawing behavior. The issue is
fixed in Windows 11.

To keep consistent window look remove the border on each side, but only
on Windows 10.
2024-03-18 02:22:28 +00:00
Kacper Michajłow
e8b085fbb5 win32: add helper function to check Windows 10 build number 2024-03-18 02:22:28 +00:00
Kacper Michajłow
bb15c50658 win32: adjust top border offset when title bar is disabled
Windows 11 draws border regardless, so we are 1px off on window size,
blending border with one line of video. Fix that by adding the border to
our internal windows size calculation.

Windows 10 on the other hand has a bug where specifying left and top NC
area will trigger title bar drawn in full height always. Keep old
behaviour in this case. Also while there is similar "visible" border
there, it seems to be transparent on Windows 10.

For high contrast themes, don't adjust title bar height and instead
remove WS_CAPTION to have the same border all around the window, as DWM
doesn't make borders invisible in this case.
2024-03-18 02:22:28 +00:00
Kacper Michajłow
1764d772ad win32: add DWMWA_VISIBLE_FRAME_BORDER_THICKNESS definition 2024-03-18 02:22:28 +00:00
Kacper Michajłow
3045f1458d win32: use dpi aware GetSystemMetricsForDpi 2024-03-18 02:22:28 +00:00
nanahi
ee586c526d win32: update maximized state when leaving fullscreen
If the window-maximized is set while in fullscreen, it needs to be applied
when leaving fullscreen, as noted in the comment.
2024-03-18 01:58:53 +00:00
nanahi
2be8976d59 win32: fix window maximized state after setting window size
With runtime geometry change, currently it only results in a
SetWindowPos call to resize the window. However, SetWindowPos doesn't
change the window maximized state, so Windows still thinks that the
window is maximized even though it no longer covers the whole workspace.
This results in visual glitches, and if the window is dragged afterwards
it's "restored" again.

Fix this by correctly setting the window maximized state in this case.
2024-03-18 01:58:53 +00:00
nanahi
8a9749b8a5 wayland_common: respect compositor's preferenced size on state change
Currently mpv always uses the previous window size when unmaximizing
or exiting fullscreen. This disregards compositor's preferenced size in
the configure event, resulting in wrong window size if changing window
state and size are delivered in the same configure event.

It's better to always respect the preferenced size instead, unless
the state change is due to runtime geometry change, where we want
to use our preference.
2024-03-17 14:59:26 +00:00
nanahi
ea33d52a4a wayland_common: always use the current geometry for prepare_resize
In the xdg_toplevel_configure handler, in some cases the geometry is
not equal to the width and height in the event. This can happen
when runtime geometry change is requested (a new size is set),
or in the case of wl->state_change || width == 0 || height == 0
(the old size is used).

However, prepare_resize always uses the width and height in the event
and not the corrected geometry here. This causes
xdg_surface_set_window_geometry using the wrong value resulting in
wrong size of window decoration. Amusingly, the debug message right
above it uses the correct size.

Fix this by using the updated geometry size instead. Since now all
prepare_resize have parameters of 0, the width and height parameters
are no longer needed.

Fixes: 828dd65ef8
2024-03-17 14:59:26 +00:00
nanahi
25ae54dd84 x11_common: unmaximize window on runtime geometry change
8e793bde78 made that changing geometry
while maximized has no effect until the window is unmaximazed. However,
this behavior is inconsistent with setting window-scale on all of win32,
wayland, and x11, which always unmaximizes the window and sets the
window size.

Since setting geometry is conceptually similar to setting window-scale
(both change the window size), they should have the same behavior.
If not fullscreen, unmaximize window on runtime geometry change to
keep the behavior consistent with window-scale.
2024-03-17 14:59:26 +00:00
nanahi
4370dc0cb6 win32: support runtime geometry update
Similar to other platforms. Also make sure that the x/y positions are set
on geometry update.
2024-03-17 14:59:26 +00:00
nanahi
f236e249a4 x11_common: fix window x/y position when updating geometry on runtime
Currently, setting geometry on runtime only changes the window size
but not the position. This is because reset_size is only set if
the window size is changed, and vo_x11_highlevel_resize doesn't set
the window position without force_window_position enabled. Fix this
by setting the related flags and perform a window move when
geometry is updated.

Fixes 8e793bde78.
2024-03-17 14:59:26 +00:00
Kacper Michajłow
7265bde26a gpu-next: add support for --dither-depth=auto
On supported APIs.
Fixes: https://github.com/mpv-player/mpv/issues/11862
2024-03-17 14:28:00 +01:00
Kacper Michajłow
16e3d7dca6 d3d11: get real on the wire bits per color channel 2024-03-17 14:28:00 +01:00
Kacper Michajłow
2b0c7b1aa4 d3d11: add mp_get_dxgi_output_desc 2024-03-17 14:28:00 +01:00
der richter
3afcaeb71a mac/view: optimise drag and drop event handling 2024-03-16 15:29:27 +01:00
der richter
a4eddf742d mac/input: move scroll wheel event handling into input helper 2024-03-16 15:29:27 +01:00
der richter
9a4c673dd7 mac/input: optimise mouse movement enabled check 2024-03-16 15:29:27 +01:00
der richter
db4eac140d mac/input: move mouse event handling into input helper 2024-03-16 15:29:27 +01:00
sfan5
830f6ccd6b vo_{drm,wlshm}: make query_format checks more correct
We're using mp_sws here, so we should ask it for format support
and not the underlying library (usually swscale) directly.
2024-03-16 13:27:34 +01:00
sfan5
aa75a0e9d2 vo_drm: add support for YUYV format
As the first aligned format this required a fix to reconfig().

Adding the other component-swapped formats in this group would be trivial
but I checked the DRM database [1] and no driver exists that supports
one of those but not YUYV and this is quite fringe as-is, so I opted not to.

[1] <https://drmdb.emersion.fr/formats>
2024-03-16 13:27:34 +01:00
sfan5
bc8038cffd vo_{drm,wlshm,x11}: add support for video-target-params 2024-03-16 13:27:34 +01:00
sfan5
2893b7d0f5 vo: move target_params into responsibility of VO
The VO generic code tries to be helpful and resets this after
each reconfig. However for the simpler VOs the target params
are constant after a reconfig or even for the entire lifetime.
So it's clearly better to let the VO decide.

This also allows the VO to use a static buffer instead.
2024-03-16 13:27:34 +01:00
sfan5
44f54357ca context_drm_egl: log fallback correctly
Currently a theoretical concern because we handle all existing formats.
2024-03-16 13:27:34 +01:00
sfan5
6b452788c4 vo_drm: add support for BGR formats 2024-03-16 13:27:34 +01:00
sfan5
93a5059e8c vo_drm: use native matching pixel format for XRGB2101010 2024-03-16 13:27:34 +01:00
der richter
3ef3bbf93d mac/event: move key event handling to input helper and optimise it 2024-03-14 23:33:15 +01:00
der richter
18fb71498b mac/events: remove redundant functions and optimise input helper usage
some redundant functions that jump through hoops.
2024-03-14 23:33:15 +01:00
der richter
055e9cd93e mac/helper: move input ctx related functionality into new input helper
also make functions thread safe.
2024-03-14 23:33:15 +01:00
Dudemanguy
5dd2d19519 wayland_common: move WAYLAND_DISPLAY check above vo_wayland_state init
Segfaults otherwise on uninit because some objects are created while
others are not. Move it to the very top since the purpose of this is to
skip wayland initialization entirely while autoprobing.

Fixes f6f1721101.
2024-03-13 20:23:10 -05:00
nanahi
f6f1721101 wayland_common: require WAYLAND_DISPLAY to be set for initialization
Currently, Wayland is above X11 and DRM in probe order. The success
of automatic probing depends on the fact that unsuitable backends
would fail to initialize. For example, X11 backend (which uses Xlib)
fails to initialize if DISPLAY environment variable is not set, so
starting mpv in VT console will pick the DRM backend as expected,
even when an X server is running in another VT.

However, libwayland-client used by the Wayland backend has the
"helpful" behavior of falling back to "wayland-0" if WAYLAND_DISPLAY
is not set. This breaks autoprobing if mpv is started from X server
or VT console while a running Wayland compositor running in another
VT (or even running as an X client) is using "wayland-0" for protocol
socket name: mpv will start playing in the Wayland compsitor instead
of using the X11 or DRM backends.

Similar to DISPLAY for X server, We should consider exporting
WAYLAND_DISPLAY to child processes the responsibility of Wayland
compositors, and any compositor not doing this should be considered
broken. Thus we now require WAYLAND_DISPLAY to be set for the
backend initialization to succeed to make sure that autoprobing
works as intended.
2024-03-13 22:39:43 +00:00
Dudemanguy
38b5dcb441 vo_gpu/vo_gpu_next: fix transparency in glx
It seems that GLX requires us to explicitly set opts.want alpha before
ra_ctx_create is called. b7fd232524
rearranged the function calls in a way made this not work. Fix this by
rearranging it again so the value is set before ra_ctx is created.
2024-03-13 22:39:31 +00:00
nanahi
27fb4c474f vo_gpu: fix broken chroma plane for rotated semi-planar formats
For image formats with 2 or more chroma planes such as YU12, there is
a plane merging pass for these planes calling finish_pass_tex which
does a format conversion. After this conversion, the cscale shader
afterwards works properly.

However, for image formats with only 1 chroma plane (semi-planar formats),
including NV12 and P010, this merging pass is never called, which breaks
the cscale shader afterwards if the video is rotated with subsampled
chroma.

Fix this by adding an explicit conversion pass if this situation is
detected after the pre-scale hooks, so if there are shaders hooking on
CHROMA (like the deband filter) and the conversion is done by pass_hook
already, this conversion won't be called.
2024-03-11 21:29:57 +01:00
der richter
0ec385bc76 options: remove --focus-on-open and add --focus-on
replaces the old focus-on-open option with a more generic focus-on
options that can be extended.

adjust the only platform that uses that option.

Fixes #8337
2024-03-10 14:53:07 +01:00
Kacper Michajłow
024edb2991 vf_format: add hdr10plus sub-parameter to format video filter 2024-03-09 05:58:52 +00:00
Kacper Michajłow
d9c1e9bc5c mp_image: add Dolby Vision metadata mapping
Remove side-loading metadata in vo_gpu_next.c and remove unneded
side-data duplication.
2024-03-09 05:58:52 +00:00
Kacper Michajłow
05c8d5a93a csputils: add missing PL_COLOR_SYSTEM names 2024-03-09 05:58:52 +00:00
Kacper Michajłow
391261f757 mp_image: add mp_image_params_static_equal for finer comparision
In case of dynamic HDR metadata is present.
2024-03-09 05:58:52 +00:00
Dudemanguy
120b0ac412 wayland: always rescale geometry if in a fullscreen/maximized state
This should only be a problem during initialization. If in a
multi-monitor setup, mpv guesses the wrong scale value and the user
passes --fs, the scaled size will be wrong and you have to unfullscreen
and fullscreen again to fix it. This is because rescale geometry won't
do anything if the value of hidpi-window-scale is false (the default) so
the geometry is never rescaled to the correct value thus the wrong size.
Normally, mpv will just correct itself after subsequent events occur but
because it is considered a locked size (as it should be), we avoid doing
any other resizing events thus it never gets corrected. Fix this by just
always rescaling the geometry in the locked size case. It shouldn't
matter elsewhere because mpv will always have the correct scale value
and the possibility of having the wrong one is only possible on startup.

Fixes ded181f642
2024-03-09 04:27:29 +00:00
Kacper Michajłow
580bc69d0c vo_gpu_next: infer target parameters
This allows us to read them back.
2024-03-07 21:12:12 +02:00
Kacper Michajłow
fc5d533a66 vo_gpu_next: add support for video-target-params 2024-03-07 21:12:12 +02:00
Kacper Michajłow
da3bfc96e9 vo: add video-target-params property 2024-03-07 21:12:12 +02:00
Kacper Michajłow
d471f2902e mp_image: add imgfmt_name to mp_image_params
Convenience to override name if imgfmt is not set.

Allows to create mp_image_params without setting imgfmt. Will be useful
for the next change where mp_imgfmt is not available. This is workaround
that will be remved once all codebase switches to pl_fmt.
2024-03-07 21:12:12 +02:00
der richter
8a37f0f693 mac/menu: add explicit menu type instead of an inferred type
with the use of an explicit type we can removed inferred type checks
like separators/services menu by name or menus by sub configs.
2024-03-07 01:03:52 +01:00
der richter
fe35baa88e mac/menu: rewrite menu bar in swift 2024-03-07 01:03:52 +01:00
der richter
68c61fd89f mac/vulkan: directly retrieve current render size without caching
the render size cached in ctx->vo->dwidth/dheight can be outdated in
some circumstances at the time the context needs resizing. instead use
the current render size.
2024-03-06 23:37:32 +02:00
der richter
6016423427 mac/vulkan: workaround for MoltenVK problem that causes flicker
MoltenVK itself tries to work around a supposedly Metal problem that
itself causes flicker, black screens or broken rendering. it sets the
drawableSize to 1x1 to forcefully complete the presentation. though if
1x1 resolution frame is presented it causes a visual flicker or rather
a solid coloured frame. it causes even more problems since sometimes it
does not reset the drawableSize to the proper resolution and keeps
rendering everything in 1x1.

work around this workaround by discarding drawableSize that are <=1 in
any direction.

Fixes #13505
2024-03-06 23:37:32 +02:00
nanahi
9c03b7569b wayland_common: fix pointer serial conflict
c2129c18f8 saves the button down serial to
pointer_serial of the seat so that it can be used for window dragging
later. However, this overwrites the serial saved at the enter event.
Since the serial in wl_pointer_set_cursor must be the latest
wl_pointer_enter serial number sent to the client, if a button down
serial overwrites that, setting cursor no longer works until the cursor
enters the window next time.

Fix this by using separate serials for these two types of events.
2024-03-05 17:35:04 +01:00
1nsane000
03bfd797f6 video/filter: add field order support for built in deinterlacers
refqueue gets the field of the frame from mp_image which almost always(if not
always) assumes bottom field order first. By default this behavior should not
change but specifying the field order should bypass this.
2024-03-04 17:41:40 -08:00
1nsane000
38a8e9bcba options: add --deinterlace-field-parity option
Previously there was no way to specify the field order of interlaced videos
when deinterlacing with inbuilt filters. Lavfi deinterlacers seemed to prefer
top field order while inbuilt ones (vdpaupp, vavpp, d3d11vpp) seemed to prefer
bottom field order. The default "auto" option should work exactly as before
while specifying either "tff" or "bff" should force the specified field order
2024-03-04 17:41:40 -08:00
Dudemanguy
c1029aaa82 wayland: fix missing lround in cursor surface
Missed in f0a6578259.
2024-03-04 22:42:46 +01:00
Dudemanguy
781f78fb3a wayland: guess the first hidpi frame better
It's been a longstanding issue in wayland* that the first frame on a
hidpi screen will have wrong scaling. A well behaved client immediately
corrects this, but it's noticeable and also can affect window placement
due to the way resizng works. Preferred scale from the fractional
protocol and preferred buffer scale can actually solve this problem. It
depends on compositors mostly, but one could simply send the event
before the client maps its surface so it knows what the correct scale is
in the first place. I'm not sure if any compositors currently behave
like this (sway seems to still require the client to render before
sending any scaling information at least), but it makes to sense to
account for this possibility.

*: https://gitlab.freedesktop.org/wayland/wayland/-/issues/133
2024-03-04 22:42:46 +01:00
Kacper Michajłow
9325ebe817 vo_gpu_next: render subtitles at video colorspace 2024-03-02 15:57:02 +00:00
Kacper Michajłow
9189e8982a vo_gpu: add missing PL_COLOR_TRC_ST428 case in lcms 2024-03-01 18:11:43 +00:00
nanahi
34055919f5 wayland_common: toplevel resize fixes
Explicitly send an UP event after the client finishes a resize for
touch event, don't resize if locked_size is set for touch event,
and use the correct type for resize edges.
2024-03-01 18:25:12 +01:00
nanahi
fb02626cd9 w32_common: make dragging asynchronous
VOCTRLs are processed in the GUI thread through the mp_dispatch mechanism.
Window dragging requests are asynchronous on x11 and wayland, so the item
is processed quickly without problem. However, currently win32 uses the
SendMessage call for this, which is synchronous. This causes the playback
to stop while the dragging request is being processed because the
dispatch queue is blocked.

Work around this by setting a flag instead if the window dragging is
requested, and immediately starts dragging after processing the dispatch
queue. This doesn't block the dispatch queue while also avoiding any
extra latency added by the Windows message queue.
2024-03-01 18:25:12 +01:00
nanahi
4b8c47d20b w32_common: re-add fullscreen check when start dragging
5736737750 removed the check because it was
not needed to prevent fullscreen window from being dragged. However, this
causes an undesirable behavior: when using a touch screen to drag a window
on Windows 11, DWM shrinks the window content a bit with an acrylic
backdrop to indicate that the window is being dragged. This also happens
when trying to drag the window in fullscreen. Add the check to prevent
this from happening.
2024-03-01 18:25:12 +01:00
nanahi
092f556898 input: centralize VO dragging
Currently, VO dragging logic is hardcoded into each VO, where a left mouse
button down event unconditionally begins dragging if the VO dragging test
passes. This method is extremely unflexible as the VO has no knowledge of
what is happening in the input system: while begin dragging with the second
click of a doubleclick is undesired, it cannot determine whether a click
is a double click or not because it's determined by the input system.

The better way to do it is to handle it somewhere in the downstream
consumers of the events instead, as they have more information to make
this decision. The input system is the perfect place for this as the logic
for checking doubleclick already exists. So just issue a begin-vo-dragging
command if it detects a left mouse button down which isn't also a
doubleclick in this case, and delete all hardcoded VO dragging logic
in win32, x11, and wayland.

Note that this solution hardcodes left mouse button down for now, but
because the VO dragging is now centralized, it's possible to make more
improvements, such as a deadzone mechanism to fix the conflict with
MBTN_LEFT mouse bind.
2024-03-01 18:25:12 +01:00
nanahi
c2129c18f8 wayland_common: implement VOCTRL_BEGIN_DRAGGING
This allows begin-vo-dragging command to initialize a vo dragging request
for wayland. The last mouse button press seat and serial is used for the
request if it is not consumed by interactive resizing.
2024-03-01 18:25:12 +01:00
nanahi
14c5da6f50 w32_common: implement VOCTRL_BEGIN_DRAGGING
This allows begin-vo-dragging command to initialize a vo dragging request
for win32. Also set dragging to release all keys like for other platforms.
The hard-coded left mouse button down trigger is scheduled to be removed
in a later commit.
2024-03-01 18:25:12 +01:00
nanahi
6eedf9b1e9 x11_common: implement VOCTRL_BEGIN_DRAGGING
This allows begin-vo-dragging command to initialize a vo dragging request
for x11. The last mouse button press event is used for _NET_WM_MOVERESIZE.
The hard-coded left mouse button down trigger is scheduled to be removed
in a later commit.
2024-03-01 18:25:12 +01:00
nanahi
9d03b83a6c command: add begin-vo-dragging command
This command initializes a vo dragging request for VOs that implement
the new VOCTRL_BEGIN_DRAGGING voctrl. This allows scripts to begin vo
dragging for any button press event.
2024-03-01 18:25:12 +01:00
sfan5
dafced8a8a wayland_common: fix type of dnd_action
The default value of -1 and comparisons >= 0 only work properly
with an int type.
2024-02-29 17:24:05 +01:00
sfan5
878b76f75e wayland_common: fix initialization order issue with protocols
This broke DND under (apparently) GNOME and KWin, but not sway.

fixes: 2274311b25
2024-02-29 17:24:05 +01:00
sfan5
78cedac844 wayland_common: fix DND read error handling 2024-02-29 17:24:05 +01:00
sfan5
dec29e82ac wayland_common: read DND data in larger chunks 2024-02-29 17:24:05 +01:00
sfan5
98f7f9e25e wayland_common: log if DND fails
This can happen if the compositor or applications don't behave correctly,
so let the user know to aid debugging.
2024-02-29 17:24:05 +01:00
sfan5
f36ab2c609 wayland_common: free DND resources on shutdown and error
This leaked only in edge cases, if at all.
2024-02-29 17:24:05 +01:00
der richter
15c48f3dc1 cocoa-cb: render on main queue instead of dedicated queue
initially we drew on a dedicated render queue to circumvent certain
bottlenecks on the main queue, like concurrent events that could lead
to late drawing.

though due to the way cocoa works we need to draw an the main queue
otherwise we get undefined behaviour that could lead to crashes.

Fixes #10276
2024-02-29 16:40:52 +01:00
der richter
7758f6f50e mac/vulkan: set NSView as layer delegate like recommended by MoltenVK 2024-02-29 16:38:10 +01:00
der richter
be6c22f93b mac/vulkan: remove old deprecated VK_MVK_macos_surface extension remains 2024-02-29 14:06:14 +01:00
Kacper Michajłow
0897604298 various: avoid function pointer casts
The opt validator functions are casted to generic validator, which has
erased type for value. Calling function by pointer of different
definition is an UB.

Avoid that by generating wrapper function that does proper argument type
conversion and calls validator function. Type erased functions have
mangled type in the name.

Fixes UBSAN failures on Clang 17, which enabled fsanitize=function by
default.
2024-02-28 16:04:02 +00:00
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
nanahi
e0ddc0f69e vulkan/context_win: make --alpha work and runtime changeable
If libplacebo manages to create a vulkan swapchain that allows
alpha composition mode to be controlled by the DWM API,
this makes it runtime changeable.
2024-02-17 16:06:33 +00:00
nanahi
095038b1bc opengl/context_win: make --alpha runtime changeable
Same as d3d11, but since SetPixelFormat can be only called once,
cAlphaBits in PIXELFORMATDESCRIPTOR must be set to make this work.
2024-02-17 16:06:33 +00:00
nanahi
8de67a4af5 d3d11: make --alpha runtime changeable
The DWM compositor transparency API is runtime changeable.
Handle this in update_render_opts.
2024-02-17 16:06:33 +00:00
nanahi
117622cd4a opengl/context_win: make --alpha=yes work
Specify cAlphaBits in PIXELFORMATDESCRIPTOR makes the pixel format
transparent, as is already the case for d3d11. Also makes the
window transparent when --alpha=yes is used.

Works on --vo=gpu and --vo=gpu-next.
2024-02-17 16:06:33 +00:00
nanahi
a61026aec3 d3d11: set window to transparent if --alpha=yes is specified
This makes --alpha=yes work with d3d11 and --d3d11-flip=no.
transparent window doesn't work with flip model swapchain by design.
2024-02-17 16:06:33 +00:00
nanahi
cef378b0a3 w32_common: add function to control window transparency state
Use the DWM API to enable and disable compositor transparency.
2024-02-17 16:06:33 +00:00
Dudemanguy
c0c32b270e vo_gpu_next: don't add 0 width/height sub bitmaps to pl_overlay
Previously, libplacebo would fail to render the image since mpv was
feeding it bogus bitmaps with 0 width/height. An easy way to encounter
this would be to set sub-scale to 0 with bitmap/image subs.
2024-02-16 22:46:31 +01:00
Dudemanguy
25bba7c811 vo_gpu_next: move the frame->redraw check for blended subtitles
Cosmetic. Since the previous commit eliminated wasteful redraws, nuke
the comment while we're at it.
2024-02-15 16:43:11 +00:00
Kacper Michajłow
5098a27e66 vo: ensure that frames are not eaten on reconfig
This avoids clearing the queued frame and the currently displayed one on
VO reconfiguration requests that happen when new frames arrive. Instead,
let those frames be fully displayed.

Fixes mf:// playback issues introduced after commit ef11d31.

Instead of removing the frame timing check embrace and fix it to wake up
the playloop as needed. The frame display duration is problematic to
handle as both VO and playloop thread would already be sleeping, but in
certain use cases it is needed to display frames in full, so in this
case, let the VO sleep to the end of frame, wake up the core as
requested and go back sleeping.

Note that this patch series reintroduces 0c9ac5835, which is esenitally
fixed in this commit. It is still not perfect, but it is better than
just busy waiting on playloop, even if those events when this would be
needed are quite rare.
2024-02-15 16:39:58 +00:00
Kacper Michajłow
a329bb546c Reapply "video: remove another redundant wakeup"
This reverts commit 44c398c3e1.
2024-02-15 16:39:58 +00:00
Kacper Michajłow
0bf4da0f5e Revert "vo: remove frame timing check from vo_still_displaying()"
This reverts commit ef11d31c3a.
2024-02-15 16:39:58 +00:00
sfan5
4981690fb6 x11_common: fix Xft.dpi detection ignoring --hidpi-window-scale
closes #13466
fixes: 4b69164147
2024-02-12 13:51:25 +01:00
nanahi
71598ca07e various: replace dead links in comments
Replace various dead links with live replacements or archives.
Less friction for anyone who wants to look up these references.
2024-02-11 04:01:24 +00:00
Guido Cella
86e0882733 wayland: don't press keys again when releasing modifiers
Since 1f8013ff3f, if you release a modifier before a regular key on
Wayland, that key gets immediately pressed again because
keyboard_handle_modifiers() calls mp_input_put_key() regardless of
whether a modifier is pressed or released, e.g. if you press Ctrl+s it
easy to take an another screenshot with s by accident. Fix this by
releasing keys when releasing modifiers.

Ideally, releasing the modifier should input the key alone after
--input-ar-delay, while this patch disables it forever, e.g. on X11 if
you type something in the console, hold Ctrl+h, and release Ctrl, it
starts typing h instead of deleting characters. This doesn't work
because keyboard_handle_key() is only called when you first press a key,
while on X11 KeyPress keeps getting sent as you hold down the key. But
this difference in behavior between X11 and Wayland can also be
reproduced with GTK and Qt applications, so I guess this is acceptable.
2024-02-11 04:01:14 +00:00
Philip Langdale
f5c4f0b0f4 hwdec_drmprime: check for AV_PIX_FMT_P210 before using it
This isn't present in older ffmpeg releases.

Fixes #13454
2024-02-10 13:29:04 -08:00
Dudemanguy
a45518cf57 wayland: set current_output on surface leave if applicable
When the mpv surface leaves the output, we no longer mark it as the
current output. However, this implicitly depends on there being a
preceding surface entrance event to a different output. This is not
necessarily the case. Consider moving the window from monitor 1, to
monitor 1-2, and then back to 1 again. mpv gets the entrance event to
monitor 2 and sets that as the current output to work off of. Then when
you move back to only monitor 1, it removes monitor 2 from the current
output. However, monitor 1 is not updated again as the current output
because there is not a new surface entrance event in this case (the
window never left). So the numbers that mpv's core is using are
incorrect and for the wrong monitor. Luckily, we already keep track of
what outputs the mpv surface is currently on no matter how many there
are so it is simply a matter of setting current output again in the
leave event if we have a different output that has the mpv surface.

Ref: https://github.com/swaywm/sway/issues/7932
2024-02-08 22:26:15 +00:00
Kacper Michajłow
9ce2bafbe9 vo_vdpau: cosmetic changes to timings
Remove unneded range check.
Print time difference with more precision.
Use the same data formats for fps and interval as in other VOs.
2024-02-07 14:45:07 +00:00