aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wlr/types/wlr_output.h9
-rw-r--r--types/wlr_export_dmabuf_v1.c2
-rw-r--r--types/wlr_output.c15
-rw-r--r--types/wlr_screencopy_v1.c2
4 files changed, 28 insertions, 0 deletions
diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h
index cd05cfb4..dff9f4eb 100644
--- a/include/wlr/types/wlr_output.h
+++ b/include/wlr/types/wlr_output.h
@@ -137,6 +137,8 @@ struct wlr_output {
struct wl_event_source *idle_frame;
struct wl_event_source *idle_done;
+ int attach_render_locks; // number of locks forcing rendering
+
struct wl_list cursors; // wlr_output_cursor::link
struct wlr_output_cursor *hardware_cursor;
int software_cursor_locks; // number of locks forcing software cursors
@@ -288,6 +290,13 @@ bool wlr_output_export_dmabuf(struct wlr_output *output,
struct wlr_dmabuf_attributes *attribs);
struct wlr_output *wlr_output_from_resource(struct wl_resource *resource);
/**
+ * Locks the output to only use rendering instead of direct scan-out. This is
+ * useful if direct scan-out needs to be temporarily disabled (e.g. during
+ * screen capture). There must be as many unlocks as there have been locks to
+ * restore the original state. There should never be an unlock before a lock.
+ */
+void wlr_output_lock_attach_render(struct wlr_output *output, bool lock);
+/**
* Locks the output to only use software cursors instead of hardware cursors.
* This is useful if hardware cursors need to be temporarily disabled (e.g.
* during screen capture). There must be as many unlocks as there have been
diff --git a/types/wlr_export_dmabuf_v1.c b/types/wlr_export_dmabuf_v1.c
index fa3ae5dc..4519350e 100644
--- a/types/wlr_export_dmabuf_v1.c
+++ b/types/wlr_export_dmabuf_v1.c
@@ -34,6 +34,7 @@ static void frame_destroy(struct wlr_export_dmabuf_frame_v1 *frame) {
if (frame == NULL) {
return;
}
+ wlr_output_lock_attach_render(frame->output, false);
if (frame->cursor_locked) {
wlr_output_lock_software_cursors(frame->output, false);
}
@@ -126,6 +127,7 @@ static void manager_handle_capture_output(struct wl_client *client,
return;
}
+ wlr_output_lock_attach_render(frame->output, true);
if (overlay_cursor) {
wlr_output_lock_software_cursors(frame->output, true);
frame->cursor_locked = true;
diff --git a/types/wlr_output.c b/types/wlr_output.c
index aa6ddc31..c39b07b3 100644
--- a/types/wlr_output.c
+++ b/types/wlr_output.c
@@ -497,6 +497,9 @@ bool wlr_output_attach_buffer(struct wlr_output *output,
if (!output->impl->attach_buffer) {
return false;
}
+ if (output->attach_render_locks > 0) {
+ return false;
+ }
// If the output has at least one software cursor, refuse to attach the
// buffer
@@ -614,6 +617,18 @@ struct wlr_output *wlr_output_from_resource(struct wl_resource *resource) {
return wl_resource_get_user_data(resource);
}
+void wlr_output_lock_attach_render(struct wlr_output *output, bool lock) {
+ if (lock) {
+ ++output->attach_render_locks;
+ } else {
+ assert(output->attach_render_locks > 0);
+ --output->attach_render_locks;
+ }
+ wlr_log(WLR_DEBUG, "%s direct scan-out on output '%s' (locks: %d)",
+ lock ? "Disabling" : "Enabling", output->name,
+ output->attach_render_locks);
+}
+
static void output_cursor_damage_whole(struct wlr_output_cursor *cursor);
void wlr_output_lock_software_cursors(struct wlr_output *output, bool lock) {
diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c
index 42945839..d6e3938d 100644
--- a/types/wlr_screencopy_v1.c
+++ b/types/wlr_screencopy_v1.c
@@ -23,6 +23,7 @@ static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) {
if (frame == NULL) {
return;
}
+ wlr_output_lock_attach_render(frame->output, false);
if (frame->cursor_locked) {
wlr_output_lock_software_cursors(frame->output, false);
}
@@ -143,6 +144,7 @@ static void frame_handle_copy(struct wl_client *client,
output->needs_frame = true;
wlr_output_schedule_frame(output);
+ wlr_output_lock_attach_render(output, true);
if (frame->overlay_cursor) {
wlr_output_lock_software_cursors(output, true);
frame->cursor_locked = true;