aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-12-02 10:37:07 +0100
committerSimon Ser <contact@emersion.fr>2021-06-02 11:08:52 +0200
commit9e9be83a58382b61caa86b1aeca77b8794099569 (patch)
tree9f07899e1a764ef06b566541c3d20e318ba459a2
parentde51df277010e9f67d8e87cfdda0ca0a01e9ef0a (diff)
backend/drm: implement get_cursor_formats and get_cursor_size
-rw-r--r--backend/drm/backend.c30
-rw-r--r--backend/drm/drm.c36
-rw-r--r--include/backend/drm/drm.h4
3 files changed, 70 insertions, 0 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index 2caf76bd..c7a72a35 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <errno.h>
+#include <drm_fourcc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -238,6 +239,35 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
goto error_event;
}
+ if (drm->parent) {
+ // We'll perform a multi-GPU copy for all submitted buffers, we need
+ // to be able to texture from them
+ struct wlr_renderer *renderer = drm->renderer.wlr_rend;
+ const struct wlr_drm_format_set *texture_formats =
+ wlr_renderer_get_dmabuf_texture_formats(renderer);
+ if (texture_formats == NULL) {
+ wlr_log(WLR_ERROR, "Failed to query renderer texture formats");
+ goto error_event;
+ }
+
+ for (size_t i = 0; i < texture_formats->len; i++) {
+ const struct wlr_drm_format *fmt = texture_formats->formats[i];
+ if (fmt->len == 0) {
+ // Modifiers aren't supported. The implicit modifier changes
+ // from a GPU to the other, so we can only accept linear
+ // buffers
+ wlr_drm_format_set_add(&drm->mgpu_formats, fmt->format,
+ DRM_FORMAT_MOD_LINEAR);
+ continue;
+ }
+
+ for (size_t j = 0; j < fmt->len; j++) {
+ wlr_drm_format_set_add(&drm->mgpu_formats, fmt->format,
+ fmt->modifiers[j]);
+ }
+ }
+ }
+
drm->session_destroy.notify = handle_session_destroy;
wl_signal_add(&session->events.destroy, &drm->session_destroy);
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 2c9560f1..9e2c870b 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -26,9 +26,17 @@
#include "backend/drm/util.h"
#include "render/pixel_format.h"
#include "render/swapchain.h"
+#include "types/wlr_buffer.h"
#include "util/signal.h"
bool check_drm_features(struct wlr_drm_backend *drm) {
+ if (drmGetCap(drm->fd, DRM_CAP_CURSOR_WIDTH, &drm->cursor_width)) {
+ drm->cursor_width = 64;
+ }
+ if (drmGetCap(drm->fd, DRM_CAP_CURSOR_HEIGHT, &drm->cursor_height)) {
+ drm->cursor_height = 64;
+ }
+
uint64_t cap;
if (drmGetCap(drm->fd, DRM_CAP_PRIME, &cap) ||
!(cap & DRM_PRIME_CAP_IMPORT)) {
@@ -1004,6 +1012,32 @@ static void drm_connector_destroy_output(struct wlr_output *output) {
memset(&conn->output, 0, sizeof(struct wlr_output));
}
+static const struct wlr_drm_format_set *drm_connector_get_cursor_formats(
+ struct wlr_output *output, uint32_t buffer_caps) {
+ if (!(buffer_caps & WLR_BUFFER_CAP_DMABUF)) {
+ return NULL;
+ }
+ struct wlr_drm_connector *conn = get_drm_connector_from_output(output);
+ if (!conn->crtc) {
+ return false;
+ }
+ struct wlr_drm_plane *plane = conn->crtc->cursor;
+ if (!plane) {
+ return false;
+ }
+ if (conn->backend->parent) {
+ return &conn->backend->mgpu_formats;
+ }
+ return &plane->formats;
+}
+
+static void drm_connector_get_cursor_size(struct wlr_output *output,
+ int *width, int *height) {
+ struct wlr_drm_backend *drm = get_drm_backend_from_backend(output->backend);
+ *width = (int)drm->cursor_width;
+ *height = (int)drm->cursor_height;
+}
+
static const struct wlr_output_impl output_impl = {
.set_cursor = drm_connector_set_cursor,
.move_cursor = drm_connector_move_cursor,
@@ -1014,6 +1048,8 @@ static const struct wlr_output_impl output_impl = {
.rollback_render = drm_connector_rollback_render,
.get_gamma_size = drm_connector_get_gamma_size,
.export_dmabuf = drm_connector_export_dmabuf,
+ .get_cursor_formats = drm_connector_get_cursor_formats,
+ .get_cursor_size = drm_connector_get_cursor_size,
};
bool wlr_output_is_drm(struct wlr_output *output) {
diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h
index 13ccd672..ec19918b 100644
--- a/include/backend/drm/drm.h
+++ b/include/backend/drm/drm.h
@@ -87,6 +87,10 @@ struct wlr_drm_backend {
struct wlr_drm_renderer renderer;
struct wlr_session *session;
+
+ uint64_t cursor_width, cursor_height;
+
+ struct wlr_drm_format_set mgpu_formats;
};
enum wlr_drm_connector_state {