2013-02-28 18:55:02 +00:00
|
|
|
/*
|
2013-09-09 16:37:33 +00:00
|
|
|
* This file is part of mpv video player.
|
2013-02-28 18:55:02 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-02-28 18:55:02 +00:00
|
|
|
*
|
2013-09-09 16:37:33 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2013-02-28 18:55:02 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-02-28 18:55:02 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-02-28 18:55:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPLAYER_WAYLAND_COMMON_H
|
|
|
|
#define MPLAYER_WAYLAND_COMMON_H
|
|
|
|
|
|
|
|
#include <wayland-client.h>
|
2017-10-01 20:16:49 +00:00
|
|
|
#include "input/event.h"
|
2021-06-26 21:12:03 +00:00
|
|
|
#include "vo.h"
|
2013-02-28 18:55:02 +00:00
|
|
|
|
2023-02-08 02:03:35 +00:00
|
|
|
typedef struct {
|
|
|
|
uint32_t format;
|
|
|
|
uint32_t padding;
|
|
|
|
uint64_t modifier;
|
|
|
|
} wayland_format;
|
|
|
|
|
2019-10-14 17:16:42 +00:00
|
|
|
struct wayland_opts {
|
2022-05-31 13:36:15 +00:00
|
|
|
int configure_bounds;
|
wayland: add support for content-type protocol
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.
2022-11-15 21:51:45 +00:00
|
|
|
int content_type;
|
2023-02-20 03:32:50 +00:00
|
|
|
bool disable_vsync;
|
2019-11-26 23:36:35 +00:00
|
|
|
int edge_pixels_pointer;
|
|
|
|
int edge_pixels_touch;
|
2019-10-14 17:16:42 +00:00
|
|
|
};
|
|
|
|
|
2013-07-18 15:35:28 +00:00
|
|
|
struct vo_wayland_state {
|
2022-05-30 17:58:57 +00:00
|
|
|
struct m_config_cache *vo_opts_cache;
|
|
|
|
struct mp_log *log;
|
|
|
|
struct mp_vo_opts *vo_opts;
|
|
|
|
struct vo *vo;
|
|
|
|
struct wayland_opts *opts;
|
|
|
|
struct wl_callback *frame_callback;
|
|
|
|
struct wl_compositor *compositor;
|
|
|
|
struct wl_subcompositor *subcompositor;
|
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_registry *registry;
|
|
|
|
struct wl_shm *shm;
|
|
|
|
struct wl_surface *surface;
|
2023-06-04 03:08:36 +00:00
|
|
|
struct wl_surface *osd_surface;
|
|
|
|
struct wl_subsurface *osd_subsurface;
|
2022-05-30 17:58:57 +00:00
|
|
|
struct wl_surface *video_surface;
|
2023-02-17 10:13:30 +00:00
|
|
|
struct wl_surface *callback_surface;
|
2022-05-30 17:58:57 +00:00
|
|
|
struct wl_subsurface *video_subsurface;
|
2021-06-26 21:12:03 +00:00
|
|
|
|
|
|
|
/* Geometry */
|
2017-10-01 20:16:49 +00:00
|
|
|
struct mp_rect geometry;
|
2021-06-26 21:12:03 +00:00
|
|
|
struct mp_rect window_size;
|
|
|
|
struct wl_list output_list;
|
|
|
|
struct vo_wayland_output *current_output;
|
2022-05-31 13:36:15 +00:00
|
|
|
int bounded_height;
|
|
|
|
int bounded_width;
|
2020-02-12 18:26:24 +00:00
|
|
|
int reduced_height;
|
2021-06-26 21:12:03 +00:00
|
|
|
int reduced_width;
|
2021-08-06 16:47:16 +00:00
|
|
|
int toplevel_width;
|
|
|
|
int toplevel_height;
|
2021-06-26 21:12:03 +00:00
|
|
|
|
|
|
|
/* State */
|
|
|
|
bool activated;
|
|
|
|
bool has_keyboard_input;
|
|
|
|
bool focused;
|
2019-10-10 19:14:40 +00:00
|
|
|
bool frame_wait;
|
2021-06-27 14:55:33 +00:00
|
|
|
bool hidden;
|
2023-07-17 18:59:51 +00:00
|
|
|
bool locked_size;
|
2020-08-18 17:55:01 +00:00
|
|
|
bool state_change;
|
2023-07-17 19:14:36 +00:00
|
|
|
bool tiled;
|
2020-08-18 17:55:01 +00:00
|
|
|
bool toplevel_configured;
|
2021-06-26 21:12:03 +00:00
|
|
|
int display_fd;
|
|
|
|
int mouse_x;
|
|
|
|
int mouse_y;
|
|
|
|
int pending_vo_events;
|
2023-01-23 20:16:43 +00:00
|
|
|
double scaling;
|
2021-06-26 21:12:03 +00:00
|
|
|
int timeout_count;
|
|
|
|
int wakeup_pipe[2];
|
|
|
|
|
wayland: add support for content-type protocol
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.
2022-11-15 21:51:45 +00:00
|
|
|
/* content-type */
|
|
|
|
/* TODO: unvoid these if required wayland protocols is bumped to 1.27+ */
|
|
|
|
void *content_type_manager;
|
|
|
|
void *content_type;
|
|
|
|
int current_content_type;
|
|
|
|
|
2023-05-19 22:07:25 +00:00
|
|
|
/* cursor-shape */
|
|
|
|
/* TODO: unvoid these if required wayland protocols is bumped to 1.32+ */
|
|
|
|
void *cursor_shape_manager;
|
|
|
|
void *cursor_shape_device;
|
|
|
|
|
2023-01-23 20:16:43 +00:00
|
|
|
/* fractional-scale */
|
|
|
|
/* TODO: unvoid these if required wayland protocols is bumped to 1.31+ */
|
|
|
|
void *fractional_scale_manager;
|
|
|
|
void *fractional_scale;
|
|
|
|
|
2021-06-26 21:12:03 +00:00
|
|
|
/* idle-inhibit */
|
|
|
|
struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager;
|
|
|
|
struct zwp_idle_inhibitor_v1 *idle_inhibitor;
|
|
|
|
|
2022-05-30 17:58:57 +00:00
|
|
|
/* linux-dmabuf */
|
|
|
|
struct zwp_linux_dmabuf_v1 *dmabuf;
|
2023-06-12 19:34:50 +00:00
|
|
|
struct zwp_linux_dmabuf_feedback_v1 *dmabuf_feedback;
|
2023-02-08 02:03:35 +00:00
|
|
|
wayland_format *format_map;
|
2022-07-07 10:03:21 +00:00
|
|
|
uint32_t format_size;
|
2023-02-28 09:39:50 +00:00
|
|
|
bool using_dmabuf_wayland;
|
2021-06-26 21:12:03 +00:00
|
|
|
|
|
|
|
/* presentation-time */
|
2019-10-10 19:14:40 +00:00
|
|
|
struct wp_presentation *presentation;
|
2023-01-14 01:28:46 +00:00
|
|
|
struct vo_wayland_feedback_pool *fback_pool;
|
2022-06-10 16:49:28 +00:00
|
|
|
struct mp_present *present;
|
2021-04-16 19:55:15 +00:00
|
|
|
int64_t refresh_interval;
|
2022-10-04 16:05:00 +00:00
|
|
|
bool use_present;
|
2019-10-10 19:14:40 +00:00
|
|
|
|
2022-11-16 01:52:56 +00:00
|
|
|
/* single-pixel-buffer */
|
|
|
|
/* TODO: unvoid this if required wayland-protocols is bumped to 1.27+ */
|
|
|
|
void *single_pixel_manager;
|
|
|
|
|
2022-05-30 17:58:57 +00:00
|
|
|
/* xdg-decoration */
|
|
|
|
struct zxdg_decoration_manager_v1 *xdg_decoration_manager;
|
|
|
|
struct zxdg_toplevel_decoration_v1 *xdg_toplevel_decoration;
|
|
|
|
int requested_decoration;
|
|
|
|
|
|
|
|
/* xdg-shell */
|
|
|
|
struct xdg_wm_base *wm_base;
|
|
|
|
struct xdg_surface *xdg_surface;
|
|
|
|
struct xdg_toplevel *xdg_toplevel;
|
|
|
|
|
|
|
|
/* viewporter */
|
|
|
|
struct wp_viewporter *viewporter;
|
|
|
|
struct wp_viewport *viewport;
|
2023-06-04 03:08:36 +00:00
|
|
|
struct wp_viewport *osd_viewport;
|
2022-05-30 17:58:57 +00:00
|
|
|
struct wp_viewport *video_viewport;
|
|
|
|
|
2017-10-01 20:16:49 +00:00
|
|
|
/* Input */
|
2021-06-26 21:12:03 +00:00
|
|
|
struct wl_keyboard *keyboard;
|
2017-10-01 20:16:49 +00:00
|
|
|
struct wl_pointer *pointer;
|
2021-06-26 21:12:03 +00:00
|
|
|
struct wl_seat *seat;
|
2017-10-01 20:16:49 +00:00
|
|
|
struct wl_touch *touch;
|
|
|
|
struct xkb_context *xkb_context;
|
|
|
|
struct xkb_keymap *xkb_keymap;
|
|
|
|
struct xkb_state *xkb_state;
|
2021-06-26 21:12:03 +00:00
|
|
|
uint32_t keyboard_code;
|
wayland: handle modifier keys correctly
I don't know why we've been doing this wrong for so long or how I didn't
notice until now. Wayland specifically has an event for handling
modifiers. We even named it "keyboard_handle_modifiers" in the code.
What we should do is just get the modifier and save it after the xkb
state is updated. Then later if the user does something else (press
another key or clicks the mouse button), the saved modifier key is
applied. If you let go of the modifier at any point, the xkb will just
update its state again and we save a 0 again here (i.e. no modifier).
There is one bit of an edge case however. If a key is pressed BEFORE the
modifier, then we have to handle the mp_input_put_key in the modifier
event instead since the ordering is not guarenteed. What we do here is
keep track of the mpkey as well as the mpmod. However if we are unable
to find a matching mpkey and the key state is pressed down, assume it's
a modifery key that was pressed and don't update mpkey. That way
whenever the modifier event does happen, it can correctly handle this
and we know that the keys must be pressed down if we end up there in the
code path.
As another fun historical note, the xkb_keysym_to_utf8 line was actually
written by wm4 himself in 460ef9c7a4bd2527f7f17eb8c95eeff3b67455f8
nearly 10 years ago. As the commit shows, it was clearly intended to
handle modifiers (if lookupkey finds nothing, then try to find a mod
instead). Of course, this is extremely dated and wayland hasn't worked
like that in ages. This branch never actually did anything, and thus
we'll remove it here along with modifier lookup changes.
This solves bizarre issues with modifiers not working with random keys
while working fine with others (don't ask me why). Fixes #10286 and
fixes #11945.
2023-07-15 19:20:27 +00:00
|
|
|
int mpkey;
|
|
|
|
int mpmod;
|
2017-10-01 20:16:49 +00:00
|
|
|
|
|
|
|
/* DND */
|
|
|
|
struct wl_data_device *dnd_ddev;
|
2021-06-26 21:12:03 +00:00
|
|
|
struct wl_data_device_manager *dnd_devman;
|
2017-10-01 20:16:49 +00:00
|
|
|
struct wl_data_offer *dnd_offer;
|
|
|
|
enum mp_dnd_action dnd_action;
|
|
|
|
char *dnd_mime_type;
|
|
|
|
int dnd_fd;
|
2021-06-26 21:12:03 +00:00
|
|
|
int dnd_mime_score;
|
2017-10-01 20:16:49 +00:00
|
|
|
|
|
|
|
/* Cursor */
|
|
|
|
struct wl_cursor_theme *cursor_theme;
|
|
|
|
struct wl_cursor *default_cursor;
|
|
|
|
struct wl_surface *cursor_surface;
|
2019-02-04 10:27:49 +00:00
|
|
|
bool cursor_visible;
|
2021-06-26 21:12:03 +00:00
|
|
|
int allocated_cursor_scale;
|
|
|
|
uint32_t pointer_id;
|
2013-02-28 18:55:02 +00:00
|
|
|
};
|
|
|
|
|
2022-04-07 04:01:21 +00:00
|
|
|
bool vo_wayland_check_visible(struct vo *vo);
|
2023-01-08 19:16:47 +00:00
|
|
|
bool vo_wayland_init(struct vo *vo);
|
2023-01-08 20:02:13 +00:00
|
|
|
bool vo_wayland_reconfig(struct vo *vo);
|
2022-04-07 04:01:21 +00:00
|
|
|
|
2022-05-30 17:19:23 +00:00
|
|
|
int vo_wayland_allocate_memfd(struct vo *vo, size_t size);
|
2021-06-26 21:12:03 +00:00
|
|
|
int vo_wayland_control(struct vo *vo, int *events, int request, void *arg);
|
|
|
|
|
2023-01-23 20:16:43 +00:00
|
|
|
void vo_wayland_handle_fractional_scale(struct vo_wayland_state *wl);
|
2023-02-27 11:12:09 +00:00
|
|
|
void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha);
|
2021-06-26 21:12:03 +00:00
|
|
|
void vo_wayland_sync_swap(struct vo_wayland_state *wl);
|
2017-10-01 20:16:49 +00:00
|
|
|
void vo_wayland_uninit(struct vo *vo);
|
2016-07-21 11:25:30 +00:00
|
|
|
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_us);
|
wayland: shuffle around the render loop again
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.
2021-05-23 19:36:19 +00:00
|
|
|
void vo_wayland_wait_frame(struct vo_wayland_state *wl);
|
2021-06-26 21:12:03 +00:00
|
|
|
void vo_wayland_wakeup(struct vo *vo);
|
2013-02-28 18:55:02 +00:00
|
|
|
|
|
|
|
#endif /* MPLAYER_WAYLAND_COMMON_H */
|