export-dmabuf: disable hardware cursors if desired

Also make the frame resource inert when sending "ready".
This commit is contained in:
emersion 2018-09-18 11:48:04 +02:00
parent 928572c14d
commit 3df602a62d
3 changed files with 28 additions and 3 deletions

View File

@ -45,6 +45,7 @@ struct capture_context {
/* Target */ /* Target */
struct wl_output *target_output; struct wl_output *target_output;
bool with_cursor;
/* Main frame callback */ /* Main frame callback */
struct zwlr_export_dmabuf_frame_v1 *frame_callback; struct zwlr_export_dmabuf_frame_v1 *frame_callback;
@ -454,7 +455,7 @@ static const struct zwlr_export_dmabuf_frame_v1_listener frame_listener = {
static void register_cb(struct capture_context *ctx) { static void register_cb(struct capture_context *ctx) {
ctx->frame_callback = zwlr_export_dmabuf_manager_v1_capture_output( ctx->frame_callback = zwlr_export_dmabuf_manager_v1_capture_output(
ctx->export_manager, 0, ctx->target_output); ctx->export_manager, ctx->with_cursor, ctx->target_output);
zwlr_export_dmabuf_frame_v1_add_listener(ctx->frame_callback, zwlr_export_dmabuf_frame_v1_add_listener(ctx->frame_callback,
&frame_listener, ctx); &frame_listener, ctx);
@ -802,6 +803,7 @@ int main(int argc, char *argv[]) {
} }
ctx.target_output = o->output; ctx.target_output = o->output;
ctx.with_cursor = true;
ctx.hw_device_type = av_hwdevice_find_type_by_name(argv[2]); ctx.hw_device_type = av_hwdevice_find_type_by_name(argv[2]);
ctx.hardware_device = argv[3]; ctx.hardware_device = argv[3];

View File

@ -9,6 +9,7 @@
#ifndef WLR_TYPES_WLR_EXPORT_DMABUF_V1_H #ifndef WLR_TYPES_WLR_EXPORT_DMABUF_V1_H
#define WLR_TYPES_WLR_EXPORT_DMABUF_V1_H #define WLR_TYPES_WLR_EXPORT_DMABUF_V1_H
#include <stdbool.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/render/dmabuf.h> #include <wlr/render/dmabuf.h>
@ -22,6 +23,8 @@ struct wlr_export_dmabuf_frame_v1 {
struct wlr_dmabuf_attributes attribs; struct wlr_dmabuf_attributes attribs;
struct wlr_output *output; struct wlr_output *output;
bool cursor_locked;
struct wl_listener output_swap_buffers; struct wl_listener output_swap_buffers;
}; };

View File

@ -29,14 +29,26 @@ static const struct zwlr_export_dmabuf_frame_v1_interface frame_impl = {
.destroy = frame_handle_destroy, .destroy = frame_handle_destroy,
}; };
static void frame_handle_resource_destroy(struct wl_resource *resource) { static void frame_destroy(struct wlr_export_dmabuf_frame_v1 *frame) {
struct wlr_export_dmabuf_frame_v1 *frame = frame_from_resource(resource); if (frame == NULL) {
return;
}
if (frame->cursor_locked) {
wlr_output_lock_software_cursors(frame->output, false);
}
wl_list_remove(&frame->link); wl_list_remove(&frame->link);
wl_list_remove(&frame->output_swap_buffers.link); wl_list_remove(&frame->output_swap_buffers.link);
wlr_dmabuf_attributes_finish(&frame->attribs); wlr_dmabuf_attributes_finish(&frame->attribs);
// Make the frame resource inert
wl_resource_set_user_data(frame->resource, NULL);
free(frame); free(frame);
} }
static void frame_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_export_dmabuf_frame_v1 *frame = frame_from_resource(resource);
frame_destroy(frame);
}
static void frame_output_handle_swap_buffers(struct wl_listener *listener, static void frame_output_handle_swap_buffers(struct wl_listener *listener,
void *data) { void *data) {
struct wlr_export_dmabuf_frame_v1 *frame = struct wlr_export_dmabuf_frame_v1 *frame =
@ -51,6 +63,7 @@ static void frame_output_handle_swap_buffers(struct wl_listener *listener,
uint32_t tv_sec_lo = tv_sec & 0xFFFFFFFF; uint32_t tv_sec_lo = tv_sec & 0xFFFFFFFF;
zwlr_export_dmabuf_frame_v1_send_ready(frame->resource, zwlr_export_dmabuf_frame_v1_send_ready(frame->resource,
tv_sec_hi, tv_sec_lo, event->when->tv_nsec); tv_sec_hi, tv_sec_lo, event->when->tv_nsec);
frame_destroy(frame);
} }
@ -96,6 +109,7 @@ static void manager_handle_capture_output(struct wl_client *client,
if (!output->impl->export_dmabuf) { if (!output->impl->export_dmabuf) {
zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource, zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource,
ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_PERMANENT); ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_PERMANENT);
frame_destroy(frame);
return; return;
} }
@ -103,9 +117,15 @@ static void manager_handle_capture_output(struct wl_client *client,
if (!wlr_output_export_dmabuf(output, attribs)) { if (!wlr_output_export_dmabuf(output, attribs)) {
zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource, zwlr_export_dmabuf_frame_v1_send_cancel(frame->resource,
ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_TEMPORARY); ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_TEMPORARY);
frame_destroy(frame);
return; return;
} }
if (overlay_cursor) {
wlr_output_lock_software_cursors(frame->output, true);
frame->cursor_locked = true;
}
uint32_t frame_flags = ZWLR_EXPORT_DMABUF_FRAME_V1_FLAGS_TRANSIENT; uint32_t frame_flags = ZWLR_EXPORT_DMABUF_FRAME_V1_FLAGS_TRANSIENT;
uint32_t mod_high = attribs->modifier >> 32; uint32_t mod_high = attribs->modifier >> 32;
uint32_t mod_low = attribs->modifier & 0xFFFFFFFF; uint32_t mod_low = attribs->modifier & 0xFFFFFFFF;