summaryrefslogtreecommitdiffstats
path: root/video/out/wayland_common.h
Commit message (Collapse)AuthorAgeFilesLines
* vo_dmabuf_wayland: drop linux-dmabuf-v2 (again)Dudemanguy2023-06-161-4/+0
| | | | | | 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.
* wayland: bump wayland-protocols to 1.25Dudemanguy2023-06-161-2/+1
| | | | | 1.27 would have been nicer but ubuntu 22.04 is on 1.25 so we'll just compromise.
* wayland: use correct x/y coordinates for the cursorDudemanguy2023-03-081-2/+0
| | | | | | | | | | | | | While adding fractional scale support, the coordinates for wayland changed to always include the scaling parameter. The pointer stuff actually did too. However, the check_for_resize function used the unscaled, local surface coordinates. Likely, it was neccesary at the time since wl->geometry used to report unscaled coordinates. In light of that, we can just simply use mouse_x/y instead for this function to make it work correctly with the right/bottom edges. mouse_unscaled becomes completely unneccesary, so just drop it. Some minor style changes included just because.
* wayland: request frame callbacks on the topmost surfaceDaniel van Vugt2023-02-281-0/+1
| | | | | | | | | | | | Which is wl->video_surface for vo_dmabuf_wayland. Listening on wl->surface results in freezes if it is occluded and culled by the compositor. Which mutter does, and the wl_surface::frame spec warns about: > A server should avoid signaling the frame callbacks if the > surface is not visible in any way, e.g. the surface is off-screen, > or completely obscured by other opaque surfaces.
* wayland: deduplicate and cache detection of dmabuf-waylandDaniel van Vugt2023-02-281-0/+1
|
* 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.
* options: transition options from OPT_FLAG to OPT_BOOLChristoph Heinrich2023-02-211-1/+1
| | | | | | c78482045444c488bb7948305d583a55d17cd236 introduced a bool option type as a replacement for the flag type, but didn't actually transition and remove the flag type because it would have been too much mundane work.
* Revert "vo_dmabuf_wayland: drop support for linux-dmabuf-v2"Dudemanguy2023-02-181-1/+4
| | | | | | | | | | | 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-1/+7
|
* wayland: add wp-fractional-scale-v1 supportDudemanguy2023-01-241-1/+7
| | | | | | | | | | | | | This protocol is pretty important since it finally lets us solve the longstanding issue of fractional scaling in wayland (no more mpv doing rendering over the target resolution and then being scaled down). This protocol also can completely replace the buffer_scale usage that we are currently using for integer scaling so hopefully this can be removed sometime in the future. Note that vo_dmabuf_wayland is omitted from the fractional scale handling because we want the compositor to handle all the scaling for that VO. Fixes #9443.
* wayland: rewrite geometry and scaling handlingDudemanguy2023-01-241-1/+0
| | | | | | | | | 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.
* wayland: store presentation feedbacks in a poolDudemanguy2023-01-131-1/+1
| | | | | | | | | Officially, the most cursed part of the wayland code in mpv (third or fourth try now?) This time, let's allocate a pool during init (arbitrarily set to the maximum swapchain length mpv allows, 8; don't even know if this actually works in wayland). Then we add/remove feedbacks from the pool during the lifecycle of the VO, and clean it up all at the end. Hopefully, this does the trick for good this time.
* Revert "wayland: dispatch and wait for compositor events in uninit"Dudemanguy2023-01-131-0/+1
| | | | | | | | | | | This ended up being a bad idea. The problem is that it introduces ordering when destroying events (something we weren't worried about before) and Lynne pointed out a problem with the callback not also being destroyed before the surface in IRC. Just undo this and go with a different approach (next commit). P.S. the wayland_dispatch_events name change is kept though because I like that better. This reverts commit aa8ddfcdf30c4ffb38f3ec5d6663bbabf0b7b4df.
* vo_dmabuf_wayland: drop support for linux-dmabuf-v2Dudemanguy2023-01-121-4/+0
| | | | | | | | | 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.
* wayland: make vo_wayland_reconfig a boolDudemanguy2023-01-081-1/+1
| | | | | | This was already returning true/false but the type was int. Also simplify a few places in the wayland contexts where we can just return the value of this function instead of doing redundant checks.
* vo: change vo_platform_init to boolDudemanguy2023-01-081-1/+1
| | | | | | | | There's several functions that are used for initializing mpv on a certain platform (x11, wayland, etc.). These currently are all int, but they actually return 1 and 0 like a boolean. This gets a bit confusing because actual vo preinit functions return 0 and -1 instead. Just make these all bool instead and return true/false to make it clearer.
* wayland: dispatch and wait for compositor events in uninitDudemanguy2023-01-031-1/+0
| | | | | | | | | | Similar to some other issues we've had with unprocessed compositor events. When quitting mpv, there's two things we should be doing: dispatching any last minute wayland events and then waiting for a compositor reply. Luckily, there's already an internal helper for this (renamed to wayland_dispatch_events for consistency) that we can use. All of the special casing of wl->feedback becomes unneccesary and we can remove this from vo_wayland_state with this method. Fixes #110022.
* vo_dmabuf_wayland: use single-pixel-buffer-v1LaserEyess2022-11-201-0/+4
| | | | | | | 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.
* wayland: add support for content-type protocolDudemanguy2022-11-151-0/+7
| | | | | | | | | | | | | | | | | | | | The content-type protocol allows mpv to send compositor a hint about the type of content being displayed on its surface so it could potentially make some sort of optimization. Fundamentally, this is pretty simple but since this requires a very new wayland-protocols version (1.27), we have to mess with the build to add a new define and add a bunch of if's in here. The protocol itself exposes 4 different types of content: none, photo, video, and game. To do that, let's add a new option (wayland-content-type) that lets users control what hint to send to the compossitor. Since the previous commit adds a VOCTRL that notifies us about the content being displayed, we can also add an auto value to this option. As you'd expect, the compositor hint would be set to photo if mpv's core detects an image, video for other things, and it is set to none for the special case of forcing a window when there is not a video track. For completion's sake, game is also allowed as a value for this option, but in practice there shouldn't be a reason to use that.
* build: add an additional check for wayland-protocols 1.24Dudemanguy2022-10-291-1/+2
| | | | | | | | | | | | | | | | | 666cb91cf12a4f8b42087530104513b0fc4ba16d added support for v4 of the dmabuf protocol. This was meant to be optional and the fallback support for the old v2 (dates back to 2017[0] well before the 1.15 wayland-protocol version we depend on) was maintained. However, v4 added several new functions and structs that of course aren't defined in old protocol versions so naturally this breaks the build on those systems. Since this is just a niche feature and not really critical to overall wayland support in mpv, just give in and add another check in the build system and #if out the newer stuff in wayland_common. v4 of linux-dmabuf depends on wayland protocols 1-24[1], so go ahead and make that our new check. Fixes #10807. [0]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/commit/a840b3634ad637b237f238d2efb9ab8f4712d5f4 [1]: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/commit/8a5cd28a0e84911a5339855cb32ed63fb57ea40a
* video/out/wayland_common: adjust decoration disagreement log levelJan Ekström2022-10-271-1/+0
| | | | | | | | | | | | | Originally, I considered warning once to be useful for figuring out whether the change in logic regarding resetting requested mode actually fixed the reported issue or not, but alas not everyone was happy with that decision. Thus the log level will always be debug. This enables us to lose one level of indent as well as a variable, which is always positive. Additionally, make the message more explicit regarding what could possibly be implied by the mismatch, as it seems like this was not always clear.
* video/out/wayland_common: clear decoration request even if compositor disagreesJan Ekström2022-10-261-0/+1
| | | | | | | | | Otherwise mpv and the compositor can end up in an eternal loop where mpv requests one mode, and compositor tells that the mode is not that (and will most likely not change). Additionally, log these mismatches - first time as a warning, and later as debug logging.
* wayland: bump dmabuf protocol to version 4Emmanuel Gil Peyrot2022-10-261-1/+5
| | | | | | | | | | | | | | | | | 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.
* wayland: correctly handle non-CLOCK_MONOTONIC clocksDudemanguy2022-10-061-0/+1
| | | | | | | | | | | | | The wayland presentation time code currently always assumes that only CLOCK_MONOTONIC can be used. There is a naive attempt to ignore clocks other than CLOCK_MONOTONIC, but the logic is actually totally wrong and the timestamps would be used anyway. Fix this by checking a use_present bool (similar to use_present in xorg) which is set to true if we receive a valid clock in the clockid event. Additionally, allow CLOCK_MONOTONIC_RAW as a valid clockid. In practice, it should be the same as CLOCK_MONOTONIC for us (ntp/adjustime difference wouldn't matter). Since this is a linux-specific clock, add a define for it if it is not found.
* wayland: add support for configure boundsDudemanguy2022-08-141-0/+3
| | | | | | | | | | | | | | | In wayland-protocols 1.25, xdg-shell got a version bump which added the configure_bounds event. The compositor can send this to clients to indicate that they should not resize past a certain size. For mpv, we'll choose to only listen to this on reconfig events (i.e. when the window first appears and if the video resolution changes later in the playlist). However, this behavior is still exposed as a user option (default on) because it will neccesarily conflict with a user setting a specific geometry size and/or window scale. Presumably, if someone is setting a really large size that goes beyond the bounds of their monitor, they actually want it like that. The wayland-protocols version is newer-ish, but we can get around having to poke the build system by just using a define that exists in the generated xdg-shell header.
* vo: move wayland presentation to separate filesDudemanguy2022-06-191-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Wayland had some specific code that it used for implementing the presentation time protocol. It turns out that xorg's present extension is extremely similar, so it would be silly to duplicate this whole mess again. Factor this out to separate, independent code and introduce the mp_present struct which is used for handling the ust/msc values and some other associated values. Also, add in some helper functions so all the dirty details live specifically in present_sync. The only wayland-specific part is actually obtaining ust/msc values. Since only wayland or xorg are expected to use this, add a conditional to the build that only adds this file when either one of those are present. You may observe that sbc is completely omitted. This field existed in wayland, but was completely unused (presentation time doesn't return this). Xorg's present extension also doesn't use this so just get rid of it all together. The actual calculation is slightly altered so it is correct for our purposes. We want to get the presentation event of the last frame that was just occured (this function executes right after the buffer swap). The adjustment is to just remove the vsync_duration subtraction. Also, The overly-complicated queue approach is removed. This has no actual use in practice (on wayland or xorg). Presentation statistics are only ever used after the immediate preceding swap to update vsync timings or thrown away.
* vo: move allocate_memfd method to wayland_commonAaron Boxer2022-05-301-0/+1
|
* vo_vaapi_wayland/wayland_common: code style fixesDudemanguy2022-05-301-31/+35
| | | | | | | | A bad person (AKA me) merged this stuff without paying close enough attention to the code style. Reformat this to be in-line with the rest of the wayland code and general mpv style (braces for functions on the next line, horizontally aligning arguments, some cosmetic cleanups for wayland_common.h, etc.).
* vo: add new vaapi-wayland driverAaron Boxer2022-05-241-0/+11
| | | | | | | This driver makes use of dmabuffer and viewporter interfaces to enable efficient display of vaapi surfaces, avoiding any unnecessary colour space conversion, and avoiding scaling or colour conversion using GPU shader resources.
* wayland: unify visibility checking codeDudemanguy2022-04-111-0/+2
| | | | | | | | | | | A bit of a personal pet peeve. vulkan, opengl, and wlshm all had different methods for doing wayland's "check for visibility before drawing" thing. The specific backend doesn't matter in this case and the logic should all be shared. Additionally, the external swapchain that the opengl code on wayland uses is done away with and it instead copies vulkan by using a param. This keeps things looking more uniform across backends and also makes it easier to extend to other platforms (see the next couple of commits).
* wayland: remove bogus scale_change variableDudemanguy2021-11-081-1/+0
| | | | | | | | | This was originally added in f2afae55e95b4b1eec1aeb828ba6ff1f0695d993 for unclear reasons (way to go me). This concept is clearly incorrect. It doesn't matter what state the window is in. As soon as mpv detects a scale change, it needs to reset the buffer scale of the window. Just remove all this junk and put wl_surface_set_buffer_scale in set_surface_scaling like it should be. Related issue: #9426.
* wayland: further xdg-decoration/border refinementsDudemanguy2021-09-281-0/+1
| | | | | | | | | | | | The value of the border option should always match what the actual state of the window is. Previously if a compositor rejected the request by mpv, it did not correct itself. Also add some code to keep track of decoration requests. Anytime the state is changed, make the last saved request again (doesn't hurt and seems like intuitive behavior). Unfortunately, this isn't foolproof since options only send callback if the value is changed. (ex. on sway if the floating window has no border, and then is titled, setting the border value to "yes" does nothing since tiling the window already set the border value to "yes").
* wayland: improve behavior with touch eventsDudemanguy2021-08-081-1/+0
| | | | | | | | | | | | | | | | | | | | | | | There's currently some touch related code in mpv wayland, but clearly nobody actually uses because it's a broken mess. Initially an attempt to distinguish between two finger touches and one finger touch was made, but there's not a good way to make this work. For whatever reason, initiating either xdg_toplevel_resize or xdg_toplevel_move blocks any other touch events from occurring (at least in plasma). Trying to call these functions anywhere else is not really useful since the serial will be invalid outside of the touch down events (well it would work in the touch up event but that's just silly). Anyways, let's just make this work sanely. Eliminate the touch entries variable completely because it's pointless. Only one finger event is ever considered at a time. Touches besides the initial one are all ignored. If a user touches and drags within the touch edge radius, then a resize event occurs. If the user touches and drags elsewhere on the window, a move event occurs. A single tap displays the osc (which is clickable if you tap again). A double tap toggles fullscreen. Additionally, the default touch edge radius of 64 pixels is way too big (at least I think so). Cut this in half to 32 which feels a lot better (on a pinephone using plasma mobile anyway).
* wayland: keep track of toplevel width/height againDudemanguy2021-08-061-0/+2
| | | | | | | | | | | | | | Regression from 24357cb. It's ugly but unfortunately keeping tracking of the last toplevel width and height really is the best way to solve this problem and removing it was a mistake. Compositors don't always send width/height coordinates of the actual window. The easiest way to trigger this is by changing window-scale/current-window-scale and then unfocusing the window. The compositor will send another toplevel configure event with coordinates of the window before the resize. Maybe compositors could be smarter but multiple ones do this (sway, gnome, plasma), so just keep the old workaround. The only difference this time is that the toplevel width/height is saved at the very beginning which also covers the case where it equals 0 (i.e. weston).
* wayland: cleanup handle_toplevel_configDudemanguy2021-08-031-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The source of many geometry woes. There's some loosely related toplevel things that should be cleaned up/fixed. First of all, VO_EVENT_LIVE_RESIZING is actually completely useless. It might have been useful sometime in the past, but there's no point. It doesn't "speed up" resizing in any way and appears to be originally for cocoa. Just remove it. Way back in the day, toplevel_width/height was added as a workaround for when we got uncoorperative (i.e. wrong) width/height coordinates from the compositor in this event. Basically it could happen due to numerous reasons but a lack of atomic commits was part of the reason and also mpv's geometry handling then was a lot rougher. We *shouldn't* need this workaround anymore. The width/height values are only used exactly when we need them. If mpv sets geometry on its own, it should still be the right dimensions. Related to the above, mpv never actually propertly handled the case where width or height was equal to 0. According to the xdg-shell spec, "If the width or height arguments are zero, it means the client should decided its own window dimension." An example of a compositor doing this is weston. It's, unsurprisingly, broken. Getting out of fullscreen or a maximized state does not restore the old window size like it should. The right way to handle this is to just return near the end of the function if we have a 0 for either argument and before any geometry is set (wl->geometry's width or height can never be zero). Luckily, state changes are already being detected so they just trigger the goto when needed. Finally, e2c24ad mistakenly removed the VO_EVENT_EXPOSE. There are edge cases where this is needed and it's safer to just force a redraw here when the window gets activated again. Just force wl->hidden to false first and then trigger the expose.
* wayland: refactor surface scalingDudemanguy2021-06-301-0/+1
| | | | | | | | | | | | | | | Another day, another wayland refactor. Way back when, dcc3c2e added support for the hidpi-window-scale option (something you probably should never set to no but whatever) to wayland. Well technically, it never had any runtime toggling support (don't remember if detecting when vo_opts changed was possible or not then; maybe not). Anyways in the process of fixing that, I went ahead and refactored how this is all handled. The key difference is that when hidpi-window-scale is disabled, wl->scaling is directly set to 1 instead of forcibly setting wl->current_output->scale to 1. Note that scaling operations don't always require a geometry reset/resize so set_surface_scaling needs to be separate from set_geometry. The logic here is kind of complicated but it (should) be correct.
* wayland: always be sure to initially try to renderDudemanguy2021-06-271-1/+1
| | | | | | | | | | | | | | | | | | | A subtle regression from c26d833. On sway if mpv was set to be a floating window in the config, set_buffer_scale would actually get applied twice according to the wayland log. That meant a 1920x1080 window would appear as a 960x540 window if the scale of the wl_output was set to 2. This only affected egl on sway (didn't occur on weston and was too lazy to try anything else; probably they were fine). Since wl->render is initially false, that meant that the very first run through the render loop returns false. This probably caused something weird to happen with the set_buffer_scale calls (the egl window gets created and everything but mpv doesn't write to it just yet) which makes the set_buffer_scale call happen an extra time. Since it was always intended for mpv to initally render, this is worth fixing. Just chnage wl->render to wl->hidden (again) and flip the bools around. That way, the initial false value results in render == true and mpv tries to draw on the first pass. This fixes the weird scaling behavior because reasons.
* wayland: reorganize wayland common codeDudemanguy2021-06-261-77/+54
| | | | | | | Mostly a cosmetic change that (hopefully) makes things look better. Some functions and structs that were previously being exported in the wayland header were made static to the wayland_common.c file (these shouldn't be accessed by anyone else).
* wayland: shuffle around the render loop againDudemanguy2021-05-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Take two. f4e89dd went wrong by moving vo_wayland_wait_frame before start_frame was called. Whether or not this matters depends on the compositor, but some weird things can happen. Basically, it's a scheduling issue. vo_wayland_wait_frame queues all events and sends them to the server to process (with no blocking if presentation time is available). If mpv changes state while rendering (and this function is called before every frame is drawn), then that event also gets dispatched and sent to the compositor. This, in some cases, can cause some funny behavior because the next frame gets attached to the surface while the old buffer is getting released. It's safer to call this function after the swap already happens and well before mpv calls its next draw. There's no weird scheduling of events, and the compositor log is more normal. The second part of this is to fix some stuttering issues. This is mostly just conjecture, but probably what was happening was this thing called "composition". The easiest way to see this is to play a video on the default audio sync mode (probably easiest to see on a typical 23.976 video). Have that in a window and float it over firefox (floating windows are bloat on a tiling wm anyway). Then in firefox, do some short bursts of smooth scrolling (likely uses egl). Some stutter in video rendering could be observed, particularly in panning shots. Compositors are supposed to prevent tearing so what likely was happening was that the compositor was simply holding the buffer a wee bit longer to make sure it happened in sync with the smooth scrolling. Because the mpv code waits precisely on presentation time, the loop would timeout on occasion instead of receiving the frame callback. This would then lead to a skipped frame when rendering and thus causing stuttering. The fix is simple: just only count consecutive timeouts as not receiving frame callback. If a compositor holds the mpv buffer slightly longer to avoid tearing, then we will definitely receive frame callback on the next round of the render loop. This logic also appears to be sound for plasma (funfact: Plasma always returns frame callback even when the window is hidden. Not sure what's up with that, but luckily it doesn't matter to us.), so get rid of the goofy 1/vblank_time thing and just keep it a simple > 1 check.
* wayland: simplify render loopDudemanguy2021-05-221-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Thi