diff options
author | Simon Ser <contact@emersion.fr> | 2023-02-07 19:25:38 +0100 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2023-02-07 13:35:56 -0500 |
commit | b4ce0a30c1d8d7f2af82f4da5858c1379f8399a1 (patch) | |
tree | 89ccc0947511e12379ca550c532279ec97d0a3b4 | |
parent | ipc: add ability to subscribe to output event (diff) | |
download | sway-b4ce0a30c1d8d7f2af82f4da5858c1379f8399a1.tar.gz sway-b4ce0a30c1d8d7f2af82f4da5858c1379f8399a1.tar.zst sway-b4ce0a30c1d8d7f2af82f4da5858c1379f8399a1.zip |
Use wlr_linux_dmabuf_feedback_v1_init_with_options()
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3933
Closes: https://github.com/swaywm/sway/issues/7436
Closes: https://github.com/swaywm/sway/pull/7437
-rw-r--r-- | sway/tree/container.c | 70 |
1 files changed, 7 insertions, 63 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index dbe88028..fa76dd6a 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -3,14 +3,10 @@ | |||
3 | #include <drm_fourcc.h> | 3 | #include <drm_fourcc.h> |
4 | #include <stdint.h> | 4 | #include <stdint.h> |
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <string.h> | ||
7 | #include <strings.h> | ||
8 | #include <sys/stat.h> | ||
9 | #include <wayland-server-core.h> | 6 | #include <wayland-server-core.h> |
10 | #include <wlr/types/wlr_linux_dmabuf_v1.h> | 7 | #include <wlr/types/wlr_linux_dmabuf_v1.h> |
11 | #include <wlr/types/wlr_output_layout.h> | 8 | #include <wlr/types/wlr_output_layout.h> |
12 | #include <wlr/types/wlr_subcompositor.h> | 9 | #include <wlr/types/wlr_subcompositor.h> |
13 | #include <wlr/render/drm_format_set.h> | ||
14 | #include "linux-dmabuf-unstable-v1-protocol.h" | 10 | #include "linux-dmabuf-unstable-v1-protocol.h" |
15 | #include "cairo_util.h" | 11 | #include "cairo_util.h" |
16 | #include "pango.h" | 12 | #include "pango.h" |
@@ -1060,16 +1056,6 @@ void container_end_mouse_operation(struct sway_container *container) { | |||
1060 | } | 1056 | } |
1061 | } | 1057 | } |
1062 | 1058 | ||
1063 | static bool devid_from_fd(int fd, dev_t *devid) { | ||
1064 | struct stat stat; | ||
1065 | if (fstat(fd, &stat) != 0) { | ||
1066 | sway_log_errno(SWAY_ERROR, "fstat failed"); | ||
1067 | return false; | ||
1068 | } | ||
1069 | *devid = stat.st_rdev; | ||
1070 | return true; | ||
1071 | } | ||
1072 | |||
1073 | static void set_fullscreen(struct sway_container *con, bool enable) { | 1059 | static void set_fullscreen(struct sway_container *con, bool enable) { |
1074 | if (!con->view) { | 1060 | if (!con->view) { |
1075 | return; | 1061 | return; |
@@ -1096,60 +1082,18 @@ static void set_fullscreen(struct sway_container *con, bool enable) { | |||
1096 | } | 1082 | } |
1097 | 1083 | ||
1098 | struct sway_output *output = con->pending.workspace->output; | 1084 | struct sway_output *output = con->pending.workspace->output; |
1099 | struct wlr_output *wlr_output = output->wlr_output; | ||
1100 | |||
1101 | // TODO: add wlroots helpers for all of this stuff | ||
1102 | |||
1103 | const struct wlr_drm_format_set *renderer_formats = | ||
1104 | wlr_renderer_get_dmabuf_texture_formats(server.renderer); | ||
1105 | assert(renderer_formats); | ||
1106 | 1085 | ||
1107 | int renderer_drm_fd = wlr_renderer_get_drm_fd(server.renderer); | 1086 | const struct wlr_linux_dmabuf_feedback_v1_init_options options = { |
1108 | int backend_drm_fd = wlr_backend_get_drm_fd(wlr_output->backend); | 1087 | .main_renderer = server.renderer, |
1109 | if (renderer_drm_fd < 0 || backend_drm_fd < 0) { | 1088 | .scanout_primary_output = output->wlr_output, |
1110 | return; | 1089 | }; |
1111 | } | 1090 | struct wlr_linux_dmabuf_feedback_v1 feedback = {0}; |
1112 | 1091 | if (!wlr_linux_dmabuf_feedback_v1_init_with_options(&feedback, &options)) { | |
1113 | dev_t render_dev, scanout_dev; | ||
1114 | if (!devid_from_fd(renderer_drm_fd, &render_dev) || | ||
1115 | !devid_from_fd(backend_drm_fd, &scanout_dev)) { | ||
1116 | return; | ||
1117 | } | ||
1118 | |||
1119 | const struct wlr_drm_format_set *output_formats = | ||
1120 | wlr_output_get_primary_formats(output->wlr_output, | ||
1121 | WLR_BUFFER_CAP_DMABUF); | ||
1122 | if (!output_formats) { | ||
1123 | return; | ||
1124 | } | ||
1125 | |||
1126 | struct wlr_drm_format_set scanout_formats = {0}; | ||
1127 | if (!wlr_drm_format_set_intersect(&scanout_formats, | ||
1128 | output_formats, renderer_formats)) { | ||
1129 | return; | 1092 | return; |
1130 | } | 1093 | } |
1131 | |||
1132 | struct wlr_linux_dmabuf_feedback_v1_tranche tranches[] = { | ||
1133 | { | ||
1134 | .target_device = scanout_dev, | ||
1135 | .flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT, | ||
1136 | .formats = &scanout_formats, | ||
1137 | }, | ||
1138 | { | ||
1139 | .target_device = render_dev, | ||
1140 | .formats = renderer_formats, | ||
1141 | }, | ||
1142 | }; | ||
1143 | |||
1144 | const struct wlr_linux_dmabuf_feedback_v1 feedback = { | ||
1145 | .main_device = render_dev, | ||
1146 | .tranches = tranches, | ||
1147 | .tranches_len = sizeof(tranches) / sizeof(tranches[0]), | ||
1148 | }; | ||
1149 | wlr_linux_dmabuf_v1_set_surface_feedback(server.linux_dmabuf_v1, | 1094 | wlr_linux_dmabuf_v1_set_surface_feedback(server.linux_dmabuf_v1, |
1150 | con->view->surface, &feedback); | 1095 | con->view->surface, &feedback); |
1151 | 1096 | wlr_linux_dmabuf_feedback_v1_finish(&feedback); | |
1152 | wlr_drm_format_set_finish(&scanout_formats); | ||
1153 | } | 1097 | } |
1154 | 1098 | ||
1155 | static void container_fullscreen_workspace(struct sway_container *con) { | 1099 | static void container_fullscreen_workspace(struct sway_container *con) { |