summaryrefslogtreecommitdiffstats
path: root/video/out/vo_dmabuf_wayland.c
Commit message (Collapse)AuthorAgeFilesLines
* vo_dmabuf_wayland: correct full window size calculationDudemanguy2023-10-051-1/+3
| | | | | | | | | | | 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.
* vo_dmabuf_wayland: free frame if the visibility check failsDudemanguy2023-10-041-1/+4
| | | | | | Forgotten in 7b8a30fc8132203bc93d35ac887682d2044ad5a9. Every other case either is either a dummy frame (no allocated memory) or we manage it as part of the usual wayland buffer release.
* vo_dmabuf_wayland: eliminate an extra frame copyDudemanguy2023-10-031-26/+28
| | | | | | | | | | | | | | 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).
* vo_dmabuf_wayland: attach solid buffer when using force windowDudemanguy2023-10-021-1/+10
| | | | | | | | | | | | | | e125da2096d97ec7e64701bf6289705a24c31729 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.
* vo_dmabuf_wayland: assume counter-clockwise rotationsDudemanguy2023-09-291-1/+4
| | | | | | | | | | | | | | 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
* vo_dmabuf_wayland: support osd rendering when there's no videoDudemanguy2023-09-211-23/+28
| | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: support 90 degree rotationsDudemanguy2023-09-171-0/+3
| | | | | | | 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.
* vo_dmabuf_wayland: unmap osd surface when not neededRobert Mader2023-08-281-1/+9
| | | | | | | Attaching a NULL buffer unmaps the surface, allowing compositors to skip blending the empty buffer. Closes #12236
* build: remove outdated generated directoryDudemanguy2023-07-311-3/+3
| | | | | | | | | | | | | | | | 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.
* draw_bmp: fix overflowing coordinates in mark_rcsDudemanguy2023-07-301-4/+0
| | | | | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: correctly handle force-windowDudemanguy2023-07-231-1/+7
| | | | | | | | | 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.
* vo_dmabuf_wayland: error out if compositor doesn't support the formatDudemanguy2023-07-141-2/+71
| | | | | | | | | | | | 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
* build: make dmabuf-wayland a build option and require drmDudemanguy2023-07-141-7/+1
| | | | | | | 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.
* vo_dmabuf_wayland: guard in destroy_osd_buffersDudemanguy2023-07-121-0/+3
| | | | *sigh*
* vo_dmabuf_wayland: stop lazy loading hwdecDudemanguy2023-07-121-17/+12
| | | | | | | | | 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.
* vo_dmabuf_wayland: don't try to get pts without frame->currentDudemanguy2023-07-121-1/+2
| | | | Fixes a segfault with --force-window=immediate.
* vo_dmabuf_wayland: add osd supportDudemanguy2023-07-121-8/+210
| | | | | | | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: init wl_list at the top of preinitDudemanguy2023-07-121-2/+2
| | | | | | 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.
* vo_dmabuf_wayland: stop guarding viewport interfacesDudemanguy2023-07-121-4/+2
| | | | | | 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.
* vo_dmabuf_wayland: drop linux-dmabuf-v2 (again)Dudemanguy2023-06-161-2/+2
| | | | | | 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.
* vo_dmabuf_wayland: update the image of pending buffersDudemanguy2023-06-141-7/+3
| | | | | | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: use a minimum of 15 buffersDudemanguy2023-06-141-1/+1
| | | | | | | | | | | | | 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.
* vo: hwdec: Pass the ra_ctx to hwdecs instead of just the raPhilip Langdale2023-05-281-3/+3
| | | | | | 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.
* vo_dmabuf_wayland: rewrite around wl_listDudemanguy2023-05-241-119/+245
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* various: fix typosHarri Nieminen2023-03-281-1/+1
| | | | Found by codespell
* wayland: use bool type for alpha framebuffer trackingRay Smith2023-02-281-1/+1
| | | | | | | | | 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.
* Revert "vo_dmabuf_wayland: drop support for linux-dmabuf-v2"Dudemanguy2023-02-181-2/+2
| | | | | | | | | | | 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 a5b9d529eec8d4bb6fc858143337c3573ec8afd0.
* vo_dmabuf_wayland: reject hw formats not supported by compositorAaron Boxer2023-02-111-4/+8
|
* vo_dmabuf_wayland: add purgatory list to buffer pool to avoid memory leaksAaron Boxer2023-02-051-3/+3
|
* vo_dmabuf_wayland: ensure buffer pool is cleaned at start of uninitAaron Boxer2023-02-051-1/+1
|
* vo_dmabuf_wayland: simplify buffer pool resetAaron Boxer2023-02-051-12/+9
|
* vo_dmabuf_wayland: only resize when a new frame is about to be drawnAaron Boxer2023-02-051-4/+12
|
* vo_dmabuf_wayland: close file handles when surface export failsAaron Boxer2023-01-281-2/+9
| | | | file handles may still be opened despite failure
* vo_dmabuf_wayland: plug leaking file descriptor from solid buffer poolAaron Boxer2023-01-281-0/+1
|
* wayland: rewrite geometry and scaling handlingDudemanguy2023-01-241-5/+2
| | | | | | | | | 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.
* vo_dmabuf_wayland: drop support for linux-dmabuf-v2Dudemanguy2023-01-121-2/+2
| | | | | | | | | 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.
* vo_dmabuf_wayland: support panscan and panningAaron Boxer2023-01-111-1/+38
|
* vo_dmabuf_wayland: goto err instead of returningDudemanguy2023-01-081-11/+11
| | | | | 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.
* vo_dmabuf_wayland: use single-pixel-buffer-v1LaserEyess2022-11-201-18/+30
| | | | | | | 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.
* wlbuf_pool.h: add headers for forward declarationsLaserEyess2022-11-201-1/+1
| | | | | | 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.
* wayland: error out if essential protocol support is missingDudemanguy2022-11-151-0/+25
| | | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: improve error handling exporting VA surfaceAaron Boxer2022-11-071-23/+25
| | | | | 1. check for all error conditions when calling vaExportSurfaceHandle 2. only clean up valid descriptors
* vo_dmabuf_wayland: use special ra_ctx_create_by_nameDudemanguy2022-10-281-5/+1
| | | | | | | | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: load all hwdecs in preinitDudemanguy2022-10-281-1/+1
| | | | | | | | | | | 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).
* vo_dmabuf_wayland: fix DRM builds with no VAAPIDave Craig2022-10-271-3/+7
| | | | | | 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.
* wayland: bump dmabuf protocol to version 4Emmanuel Gil Peyrot2022-10-261-3/+3
| | | | | | | | | | | | | | | | | 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.
* vo_dmabuf_wayland: wayland VO displaying dmabuf buffersAaron Boxer2022-10-261-0/+361
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