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

50 Commits

Author SHA1 Message Date
Dudemanguy
c243946338 vo_dmabuf_wayland: scale smarter in hidpi situations
Previously, all scaling was forced to 1 with this vo and all coordinates
were calculated as if the scale was 1. This works since viewport relies
on the compositor completely for scaling so it doesn't really matter if
we don't draw directly to the correct size since the compositor will
just scale the rest for us. This does have some downsides however since
the OSD text might not be drawn at the actual resolution of the final
size of the video.

We can instead handle this by getting rid of the dmabuf_wayland specific
scaling logic and using the same values as everything else. In the
resize in vo_dmabuf_wayland, we just need to adjust the viewport
destination calls so they go to the wayland local coordinates and not
the physical ones. This should ensure that vo_dmabuf_wayland directly
goes to the desired size and the compositor doesn't need to operate on
it after the fact.
2024-01-27 05:12:12 +00:00
Dudemanguy
e32554cd57 wayland: drop buffer_scale use for viewporter
The core wayland protocol way of handling scaling is to use the
buffer_scale mechanism. But this sucks in several ways for reasons I
won't list here and fractional scaling rightly avoids this altogether
and uses a buffer_scale of 1 (i.e. not setting it) along with
viewporter. When originally implemented, this was only specifically used
when the fractional scale protocol was available, but we actually can
use it as a full replacement instead. This means that mpv now hard
requires viewporter, but this protocol is supported by everyone and is
one of the few that is actually stable.

How it works is the same regardless of fractional scaling or not. When
the compositor has a scale value not equal to 1, it will always scale
the client by that factor (unless you set buffer_scale). What we do here
is pass a viewporter size that exactly undos the compositor-side scale
(sans a possible rounding error). So what we are left with is just the
exactly physical pixels we want to display. Fixes #13316.
2024-01-27 05:12:12 +00:00
Kacper Michajłow
d5222ece6b vo: don't pass VADRMPRIMESurfaceDescriptor by value 2023-11-28 10:46:16 +01:00
Dudemanguy
61aecfabfd vo_dmabuf_wayland: correct full window size calculation
The current calculation makes the implicit assumption that the margins
on both sides are always equal (the 2 times multiplication). This isn't
true though. For example, a 720p video fullscreened on a 1680x1050
display will have a top margin of 52 but a bottom margin of 53. The
current calculation just multiplies 52 by 2, so it's off by one. Fix
this by adding together all the margins together (left + right or top +
bottom) then adding that to the dst window size (width or height). This
way, we get the full size of the window for the viewport. Fixes #12554.
2023-10-05 22:28:37 +00:00
Dudemanguy
8641cbaab6 vo_dmabuf_wayland: free frame if the visibility check fails
Forgotten in 7b8a30fc81. Every other case
either is either a dummy frame (no allocated memory) or we manage it as
part of the usual wayland buffer release.
2023-10-04 16:21:47 -05:00
Dudemanguy
7b8a30fc81 vo_dmabuf_wayland: eliminate an extra frame copy
When implementing vo_dmabuf_wayland, it always did a copy of the image
from the current frame and worked with that. The reason was because
mpv's core held onto the frame and caused some timing issues and
rendering glitches depending on when it freed the image. This is pretty
easy to fix: just make vo_dmabuf_wayland manage the the frames. In vo.h,
we add a boolean that a VO can set to make them manage freeing frames
directly. After doing this, change the buffers in vo_dmabuf_wayland to
store the whole vo_frame instead of just the image. Then, just modify
some things a bit so frame is freed instead of the image. Now, we should
truly have zero-copy playback. Well as long as you don't use libass to
render anything (that's still a copy from system memory).
2023-10-03 23:45:20 +00:00
Dudemanguy
47dec1c7c2 vo_dmabuf_wayland: attach solid buffer when using force window
e125da2096 changed the z order of the
surfaces a bit, but it turns out this has a side effect. If the aspect
ratio of the actual video doesn't match your display, the osd surface
doesn't scale properly and gets clipped. Put the z ordering back where
it used to be. Instead when we have the force window case, simply attach
the already existing solid buffer to the video surface. This allows the
osd surface to actually draw over it instead of always being obscured so
it satisfies the case of not having any real video frames but still
wanting to draw the osd. Also don't mess with any of the viewport source
setting stuff with force window. Weston complains about it, and it's
nonsensical anyway. Fixes #12547.
2023-10-02 15:58:03 -05:00
Dudemanguy
27ef1725e7 vo_dmabuf_wayland: assume counter-clockwise rotations
In practice, most compositors implement the rotation clockwise which
matches mpv's option, but amusingly this is actually incorrect.
According to the spec*, wayland buffer rotations are counter-clockwise.
So with this assumption in mind, in order for the rotation to match
mpv's usual semantics, the 90 degree and 270 degree positions need to be
flipped. Of course, this will make the VO rotate the wrong way on most
compositors, but this is what the spec says (sway master is known to
currently be correct). Fixes #12508 (sort of but will break the rotation
direction on other compositors. Oh well).

*: https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output-enum-transform
2023-09-29 17:00:05 +02:00
Dudemanguy
e125da2096 vo_dmabuf_wayland: support osd rendering when there's no video
The osd support was originally written with the requirement that we have
actual frames getting delivered to the VO. This isn't always the case
though. If you force a window on a blank audio file for example, then
there will be no frame thus draw_frame did nothing. Since the previous
commit allows us to reliably detect this, we can rearrange the code
around a little bit to make this possible. A key change is to make the
osd_subsurface have wl->surface as the parent. This is seemingly
required otherwise the osd_surface buffers are never visible above the
empty video_surface when we have a black window. Also nuke the desync
call since it's completely pointless. Fixes #12429.
2023-09-21 14:08:52 +00:00
Dudemanguy
ed5c744aa9 vo_dmabuf_wayland: support 90 degree rotations
All we have to do is set VO_CAP_ROTATE90 and then use buffer transform.
Maybe ideally we would rotate with vavpp instead if possible, but this
would be a convoluted mess that I'm not really interested in dealing
with right now.
2023-09-17 19:29:59 -05:00
Robert Mader
5a690a168a vo_dmabuf_wayland: unmap osd surface when not needed
Attaching a NULL buffer unmaps the surface, allowing compositors to skip
blending the empty buffer.

Closes #12236
2023-08-28 18:16:10 +00:00
Dudemanguy
0bed2a2263 build: remove outdated generated directory
This only existed as essentially a workaround for meson's behavior and
to maintain compatibility with the waf build. Since waf put everything
in a generated subdirectory, we had to put make a subdirectory called
"generated" in the source for meson so stuff could go to the right
place. Well now we don't need to do that anymore. Move the meson.build
files around so they go in the appropriate place in the subdirectory of
the source tree and change the paths of the headers accordingly. A
couple of important things to note.

1. mpv.com now gets made in build/player/mpv.com (necessary because of
   a meson limitation)
2. The macos icon generation path is shortened to
   TOOLS/osxbundle/icon.icns.inc.
2023-07-31 19:00:06 +00:00
Dudemanguy
b7bf5e619f draw_bmp: fix overflowing coordinates in mark_rcs
This is yet another unfortunate side effect of the width % SLICE_W == 0
special case. While looping through these rectangles, the rc->x1 value
on the final loop can be greater than the actual total width. This will
cause a buffer overflow if using the mp_draw_sub_overlay API. 2 of the
current VOs that use that work around it by adjusting the values
returned, but the better fix is to correct what's actually given in the
rectangles so you can safely use the values. As for the fix, it's simply
ensuring that rc->x1 doesn't extend beyond p->w with a MPCLAMP.
Previously, the code would always naively add SLICE_W (256) to rc->x0
which would easily extend past the actual width in many cases. The
adjustments in vo_vaapi and vo_dmabuf_wayland are dropped and in theory
vo_direct3d should work now since we can just trust the values given to
us in the rectangles. How nice.
2023-07-30 20:06:20 +02:00
Dudemanguy
783e2bf138 vo_dmabuf_wayland: correctly handle force-window
Since this works by mpctx giving us a dummy image, we can be reasonably
be confident that when we receive a matching imgfmt with no underlying
hw_subfmt that this is simply force window from the player. Just allow
this to go through the usual wayland logic and skip the hwdec checking.
When we get the real image later, it will still error out on the
compositors that don't have proper support.
2023-07-23 04:55:26 +00:00
Dudemanguy
1f683401aa vo_dmabuf_wayland: error out if compositor doesn't support the format
This was never implemented so in cases where the compositor didn't have
support for the underlying format, the window would just be black and
quite unhelpful. Well it turns out that fixing this is actually really
easy because mpv has reconfig2 which returns the entire mp_image on
every reconfig. We can just use that mp_image to try and obtain the
format and modifier pair and then use that to check against what we know
the compositor supports. If there are any problems, error out
gracefully. Some code duplication with the vaapi/drmprime importers, but
it's probably better to keep these separate. Fixes #11198 and fixes #11664
2023-07-14 14:24:45 +00:00
Dudemanguy
2616b2b11e build: make dmabuf-wayland a build option and require drm
It makes more sense as an option at this point. Also libdrm is not
optional at all. You have to get a drm format and modifier for this to
even work (the VO will just fail without DRM). Just hard require it and
remove the guards. vaapi can remain optional.
2023-07-14 14:24:45 +00:00
Dudemanguy
33130741f4 vo_dmabuf_wayland: guard in destroy_osd_buffers
*sigh*
2023-07-12 22:20:20 -05:00
Dudemanguy
7409f4a6c9 vo_dmabuf_wayland: stop lazy loading hwdec
The implementation was copied from vo_gpu/vo_gpu_next but fundamentally
it doesn't make sense for this VO. Hardware decoding is not optional in
vo_dmabuf_wayland. We should be sure to request and load all supported
formats in the preinit and fail if there are any problems. There should
be no functional change from before, but it's more conceptually correct
this way.
2023-07-12 16:59:59 -05:00
Dudemanguy
b57cf110c9 vo_dmabuf_wayland: don't try to get pts without frame->current
Fixes a segfault with --force-window=immediate.
2023-07-12 16:59:47 -05:00
Dudemanguy
c958990833 vo_dmabuf_wayland: add osd support
This adds osd support via shm buffers using a similar approach that the
normal buffers do, but it differs in a few key areas. One thing to note
is that sway and weston actually handle this extremely differently which
required all the abstractions here. In particular, weston does not cope
well with destroying the wl_buffer from shm outside of the release
handler at all (i.e. it segfaults). The workaround here is to simply
attach a NULL to the osd surface and do a surface commit before we
destroy the buffers. This is reasonable enough and seems to work well
although it's pretty weird. Sway is more straightforward although it
actually releases the osd buffer when the window goes out of sight.
Also, I found that it doesn't always release every buffer before you
close it unlike weston seems to do which is part of the reason all this
bookkeeping is required. I don't know if there's any other compositor
out there that can possibly handle vo_dmabuf_wayland right now, but
suffering through these two is good enough for now I think.
2023-07-12 19:19:54 +00:00
Dudemanguy
180a3df1f1 vo_dmabuf_wayland: init wl_list at the top of preinit
Otherwise, we could fail and skip to uninit without initalizing this
which then will segfault because the list is null and accessed while
trying to destroy buffers.
2023-07-12 19:19:54 +00:00
Dudemanguy
a890d7be2a vo_dmabuf_wayland: stop guarding viewport interfaces
It's entirely pointless. Not having viewport is already a fatal error
for this VO as it cannot possibly work without that protocol. Just drop
all these redundant if's.
2023-07-12 19:19:54 +00:00
Dudemanguy
650c53df50 vo_dmabuf_wayland: drop linux-dmabuf-v2 (again)
It was done once before but later reverted for testing reasons. This
time it's permanent though since I can test this VO on ARM and with an
up to date system.
2023-06-16 14:46:59 +00:00
Dudemanguy
f5e828ac25 vo_dmabuf_wayland: update the image of pending buffers
When using a display-* video-sync mode, it is possible for buffers with
a matching id to already have an image associated with them (i.e. the
compositor hasn't released it yet). Previously, it was thought that we
could just unref, return null, and make a new buffer but this eventually
leads to a fatal error that originates from libwayland itself which
stops playback. Admittedly, the reason for the error is a bit nebulous
but likely it seems to be some kind of mismatch between dmabuf params
and the associated image with the buffer.

However, we can simplify this process greatly. Instead when the
previously mentioned edge case happens, the old image can simply be
freed and we give the buffer the new image. This saves creating a new
buffer and also avoids that nasty libwayland error. A nice win-win all
around. Fixes #11773.
2023-06-14 12:21:10 -05:00
Dudemanguy
4d4837b84e vo_dmabuf_wayland: use a minimum of 15 buffers
vo_dmabuf_wayland has a pool of wl_buffers that it cycles through when
drawing frame. There needs to be at least some minimum number otherwise
a flickering artifact occurs where old frames are mistakenly repeated.
When using display-resample and other similar modes, it seems more
buffers are required (more drawing happens so it makes sense) and the
current minimum of 8 isn't good enough. Let's just bump this to 15. It's
also a random ad hoc number, but as far as I know there's not really a
way to predict how many buffers a random video may need. From testing,
it works fine and overall 15 is still a tiny amount of objects to create
considering the lifetime of a video, so we'll just go with this.
2023-06-14 12:00:23 -05:00
Philip Langdale
085f3e31a0 vo: hwdec: Pass the ra_ctx to hwdecs instead of just the ra
We will need the full ra_ctx to be able to look up all the state
required to initialise an ffmpeg vulkan hwcontext, so pass let's
pass the ra_ctx instead of just the ra.
2023-05-28 15:46:05 -07:00
Dudemanguy
c1de4bb745 vo_dmabuf_wayland: rewrite around wl_list
vo_dmabuf_wayland worked by allocating entries to a pool and then having
a lot of complex logic dealing with releasing buffers, pending entries,
etc. along with some other not so nice things. Instead, we can rewrite
this logic so that the wl_buffers created by the imported dmabuf is
instead stored in a linked list, wl_list. We can simply append our
buffers to the list when needed and destroy everything at the end. On
every frame, we can check the ids of our surfaces and reuse existing
buffers, so in practice there will only ever be a handful at a time.
Some other small changes were made in an attempt to organize the
vaapi/drmprime code a little better as well.

An important change is to always enforce at least a minimum number of
buffers. Certain formats would not make enough unique buffers, and this
results in flickering/artifacts occuring. The old way to attempt to deal
with this was to clear out all the existing buffers and remake them, but
this gets complicated and also didn't always work. An easy solution to
this is just create more buffers which appears to solve this problem.
The actual number needed is not really based on anything solid, but 8
is a reasonable number to create for the lifetime of a file and it seems
to do the trick.

Additionally, seeking/loading new files can result in flicker artificts
due to buffers being reused when they shouldn't. When that happens, we
flip a bool so all the buffers get destroyed in draw_frame to avoid any
visual glitches.
2023-05-24 21:53:17 +00:00
Harri Nieminen
292a5868cb various: fix typos
Found by codespell
2023-03-28 19:29:44 +00:00
Ray Smith
8a43fc0e9a wayland: use bool type for alpha framebuffer tracking
ra_ctx_opts.want_alpha and vo_wayland_set_opaque_region's alpha
argument are only used as bool but both are ints. Particularly for the
function argument, passing a 0 or 1 is confusing - at first glance it
looks like you're specifying an alpha value of 0 or 1.

Since they're only used as bools, make them bools.
2023-02-28 14:53:32 +00:00
Dudemanguy
e2cdc23af0 Revert "vo_dmabuf_wayland: drop support for linux-dmabuf-v2"
This was originally dropped because it was thought to be unneeded at the
time, but at least some devices (rockchip) apparently are still on old
compositors that use linux-dmabuf v2. It's not much code, and for
testing purposes it's good to have around since it's hard to test
drmprime otherwise. Some minor additions are here to support the newly
added vaapi-format mapping in v2 of the protocol.

This reverts commit a5b9d529ee.
2023-02-18 02:21:54 +00:00
Aaron Boxer
49fd6caa43 vo_dmabuf_wayland: reject hw formats not supported by compositor 2023-02-11 00:46:46 +00:00
Aaron Boxer
a3340645be vo_dmabuf_wayland: add purgatory list to buffer pool to avoid memory leaks 2023-02-05 23:27:08 +00:00
Aaron Boxer
6803903e0c vo_dmabuf_wayland: ensure buffer pool is cleaned at start of uninit 2023-02-05 23:27:08 +00:00
Aaron Boxer
ce6efc782f vo_dmabuf_wayland: simplify buffer pool reset 2023-02-05 23:27:08 +00:00
Aaron Boxer
f1f6eaa3de vo_dmabuf_wayland: only resize when a new frame is about to be drawn 2023-02-05 23:27:08 +00:00
Aaron Boxer
881f820fdf vo_dmabuf_wayland: close file handles when surface export fails
file handles may still be opened despite failure
2023-01-28 16:54:48 +01:00
Aaron Boxer
e3618002e3 vo_dmabuf_wayland: plug leaking file descriptor from solid buffer pool 2023-01-28 16:54:48 +01:00
Dudemanguy
006ec9ce43 wayland: rewrite geometry and scaling handling
This is in preparation for fractional scaling support. Basically, redo
all the coordinates in wayland so that wl->geometry is equal exactly to
what is being put out to the screen (no extra wl->scaling multiplication
required). The wl->vdparams variable is also eliminated for simplicity.
This changes mpv's behavior on wayland with hidpi scaling but that will
be addressed in more detail with the next commit.
2023-01-24 00:04:39 +00:00
Dudemanguy
a5b9d529ee vo_dmabuf_wayland: drop support for linux-dmabuf-v2
The only real reason this was ever supported is because it was
dramatically simpler than v4, so it was put in as an initial
implementation. Later, v4 support was added and we left v2 for
compatibility, but let's just drop it. Compositors all use v4 nowadays,
and v2 is significantly limited (no modifier support for example). It's
better to just remove this dead code for simplicity.
2023-01-12 17:42:35 +00:00
Aaron Boxer
865a159244 vo_dmabuf_wayland: support panscan and panning 2023-01-11 18:10:40 +00:00
Dudemanguy
c5af54eb35 vo_dmabuf_wayland: goto err instead of returning
Returning early is clearly wrong. It should use to goto to cleanup after
itself. Also renamed from error_out to err for purely comestic reasons.
2023-01-08 12:19:14 -06:00
LaserEyess
a62f71bfbe vo_dmabuf_wayland: use single-pixel-buffer-v1
The new single-pixel-buffer protocol is designed to optimize the case
for using a solid color as an underlay wl_surface. It works the same as
the wl_shm 1x1 pixel trick currently used, but it allows the compositor
to make optimizations with more certainty than the wl_shm trick.
2022-11-20 19:13:59 +00:00
LaserEyess
303178e645 wlbuf_pool.h: add headers for forward declarations
This was previously implicitly included by the order of headers in
vo_dmabuf_wayland.c, but it is better to make it an explicit and reorder
the headers properly.
2022-11-20 19:13:59 +00:00
Dudemanguy
295ceab382 wayland: error out if essential protocol support is missing
Related issue: #10868. While most protocols are in theory optional, a
small amount of them are absolutely essential and nothing will work
without them. We should make sure to error out in those cases and not
try to actually do anything. For wayland support in general,
wl_compositor support is obviously required. If there is no wl_surface,
you can't do anything. Additionally, vo_wlshm quite obviously requires
wl_shm so mark that one as well. vo_dmabuf_wayland needs linux_dmabuf,
viewporter, wl_shm, and wl_subcompositor. In practice, these are all
very standard protocols and shouldn't be missing but the linked issue
above is at least one example where a compositor was stuck on an ancient
version of a wayland interface.
2022-11-15 14:42:02 +00:00
Aaron Boxer
00e3c90fb1 vo_dmabuf_wayland: improve error handling exporting VA surface
1. check for all error conditions when calling vaExportSurfaceHandle
2. only clean up valid descriptors
2022-11-07 16:42:01 +00:00
Dudemanguy
adb556bf15 vo_dmabuf_wayland: use special ra_ctx_create_by_name
vo_dmabuf_wayland has its own ra and context so it can handle all the
different hwdec correctly. Unfortunately, this API was pretty clearly
designed with vo_gpu/vo_gpu_next in mind and has a lot of concepts that
don't make sense for vo_dmabuf_wayland. We still want to bolt on a
ra_ctx, but instead let's rework the ra_ctx logic a little bit. First,
this introduces a hidden bool within the ra_ctx_fns that is used to hide
the wldmabuf context from users as an option (unlike the other usual
contexts). We also want to make sure that hidden contexts wouldn't be
autoprobed in the usual ra_ctx_create, so we be sure to skip those in
that function. Additionally, let's create a new ra_ctx_create_by_name
function which does exactly what says. It specifically selects a context
based on a passed string. This function has no probing or option logic
is simplified just for what vo_dmabuf_wayland needs. The api/context
validations functions are modified just a little bit to make sure hidden
contexts are skipped and the documentation is updated to remove this
entries. Fixes #10793.
2022-10-28 02:36:46 +00:00
Dudemanguy
31af37f877 vo_dmabuf_wayland: load all hwdecs in preinit
vo_gpu and vo_gpu_next typically load hwdec interops on demand and
vo_dmabuf_wayland naively copied this logic. This is actually wrong
however since draw_frame in the VO always inherently relies on hwdec
being fully loaded. This can lead to a race condition during startup
which happens with --force-window=immediate. Avoid this by simply always
loading all the interops. In the case of vo_dmabuf_wayland, this is not
really a big deal since there's only vaapi and drmprime to load. Also
fixes #10791 (the other half).
2022-10-28 02:36:46 +00:00
Dave Craig
6e274dc8d8 vo_dmabuf_wayland: fix DRM builds with no VAAPI
Building on DRM platform without VAAPI broke because of misuse of
HAVE_VAAPI with #ifdef in place of #if. Also, the hwcontext_drm.h
header is not required for VAAPI builds, only DRM builds.
2022-10-27 18:41:37 +00:00
Emmanuel Gil Peyrot
666cb91cf1 wayland: bump dmabuf protocol to version 4
Pulled from https://github.com/mpv-player/mpv/pull/10382

The zwp_linux_dmabuf_v1 protocol version 4 provides a file descriptor
containing both formats and modifiers, which makes it possible for the
compositor to import the buffers onto planes using explicit modifiers.

This is an extremely important efficiency improvement, as the 3D
hardware can be left powered off altogether, the vaapi buffer being sent
directly from the video hardware to the display controller.

It could be possible to support zwp_linux_dmabuf_v1 version 3 as well,
but there is no reason beyond compatibility with old stacks.  I would
recommend to ditch version 2 as well, as modifier-less formats aren’t
very useful nowadays.
2022-10-26 18:41:47 +00:00
Aaron Boxer
7358b9d371 vo_dmabuf_wayland: wayland VO displaying dmabuf buffers
Wayland VO that can display images from either vaapi or drm hwdec

The PR adds the following changes:

1. a context_wldmabuf context with no gl dependencies
2. no-op ra_wldmabuf and dmabuf_interop_wldmabuf objects
   no-op because there is no need to map/unmap the drmprime buffer,
    and there is no need to manage any textures.

Tested on both x86_64 and rk3399 AArch64
2022-10-26 18:41:47 +00:00