Align dmabuf backend with screencopy backend
parent
a7b4859611
commit
640b12184d
|
@ -25,6 +25,7 @@ struct wl_output;
|
||||||
|
|
||||||
enum dmabuf_capture_status {
|
enum dmabuf_capture_status {
|
||||||
DMABUF_CAPTURE_UNSPEC = 0,
|
DMABUF_CAPTURE_UNSPEC = 0,
|
||||||
|
DMABUF_CAPTURE_IN_PROGRESS,
|
||||||
DMABUF_CAPTURE_CANCELLED,
|
DMABUF_CAPTURE_CANCELLED,
|
||||||
DMABUF_CAPTURE_FATAL,
|
DMABUF_CAPTURE_FATAL,
|
||||||
DMABUF_CAPTURE_DONE
|
DMABUF_CAPTURE_DONE
|
||||||
|
@ -48,16 +49,17 @@ struct dmabuf_frame {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dmabuf_capture {
|
struct dmabuf_capture {
|
||||||
|
struct zwlr_export_dmabuf_manager_v1* manager;
|
||||||
struct zwlr_export_dmabuf_frame_v1* zwlr_frame;
|
struct zwlr_export_dmabuf_frame_v1* zwlr_frame;
|
||||||
struct dmabuf_frame frame;
|
struct dmabuf_frame frame;
|
||||||
|
|
||||||
|
bool overlay_cursor;
|
||||||
|
struct wl_output* output;
|
||||||
enum dmabuf_capture_status status;
|
enum dmabuf_capture_status status;
|
||||||
void (*on_done)(struct dmabuf_capture*);
|
void (*on_done)(struct dmabuf_capture*);
|
||||||
|
|
||||||
void* userdata;
|
void* userdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dmabuf_capture*
|
int dmabuf_capture_start(struct dmabuf_capture* self);
|
||||||
dmabuf_capture_start(struct zwlr_export_dmabuf_manager_v1* manager,
|
|
||||||
bool overlay_cursor, struct wl_output* output,
|
|
||||||
void (*on_done)(struct dmabuf_capture*));
|
|
||||||
void dmabuf_capture_stop(struct dmabuf_capture* self);
|
void dmabuf_capture_stop(struct dmabuf_capture* self);
|
||||||
|
|
36
src/dmabuf.c
36
src/dmabuf.c
|
@ -19,15 +19,16 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
|
|
||||||
|
#include "logging.h"
|
||||||
#include "dmabuf.h"
|
#include "dmabuf.h"
|
||||||
#include "wlr-export-dmabuf-unstable-v1.h"
|
#include "wlr-export-dmabuf-unstable-v1.h"
|
||||||
|
|
||||||
void dmabuf_capture_stop(struct dmabuf_capture* self)
|
void dmabuf_capture_stop(struct dmabuf_capture* self)
|
||||||
{
|
{
|
||||||
if (self->zwlr_frame)
|
if (self->zwlr_frame) {
|
||||||
zwlr_export_dmabuf_frame_v1_destroy(self->zwlr_frame);
|
zwlr_export_dmabuf_frame_v1_destroy(self->zwlr_frame);
|
||||||
|
self->zwlr_frame = NULL;
|
||||||
free(self);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmabuf_frame_start(void* data,
|
static void dmabuf_frame_start(void* data,
|
||||||
|
@ -75,10 +76,10 @@ static void dmabuf_frame_ready(void* data,
|
||||||
{
|
{
|
||||||
struct dmabuf_capture* self = data;
|
struct dmabuf_capture* self = data;
|
||||||
|
|
||||||
|
dmabuf_capture_stop(self);
|
||||||
|
|
||||||
self->status = DMABUF_CAPTURE_DONE;
|
self->status = DMABUF_CAPTURE_DONE;
|
||||||
self->on_done(self);
|
self->on_done(self);
|
||||||
|
|
||||||
dmabuf_capture_stop(self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmabuf_frame_cancel(void* data,
|
static void dmabuf_frame_cancel(void* data,
|
||||||
|
@ -89,22 +90,13 @@ static void dmabuf_frame_cancel(void* data,
|
||||||
|
|
||||||
self->status = reason == ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_PERMANENT
|
self->status = reason == ZWLR_EXPORT_DMABUF_FRAME_V1_CANCEL_REASON_PERMANENT
|
||||||
? DMABUF_CAPTURE_FATAL : DMABUF_CAPTURE_DONE;
|
? DMABUF_CAPTURE_FATAL : DMABUF_CAPTURE_DONE;
|
||||||
self->on_done(self);
|
|
||||||
|
|
||||||
dmabuf_capture_stop(self);
|
dmabuf_capture_stop(self);
|
||||||
|
self->on_done(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dmabuf_capture*
|
int dmabuf_capture_start(struct dmabuf_capture* self)
|
||||||
dmabuf_capture_start(struct zwlr_export_dmabuf_manager_v1* manager,
|
|
||||||
bool overlay_cursor, struct wl_output* output,
|
|
||||||
void (*on_done)(struct dmabuf_capture*))
|
|
||||||
{
|
{
|
||||||
struct dmabuf_capture* self = calloc(1, sizeof(*self));
|
|
||||||
if (!self)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
self->on_done = on_done;
|
|
||||||
|
|
||||||
static const struct zwlr_export_dmabuf_frame_v1_listener
|
static const struct zwlr_export_dmabuf_frame_v1_listener
|
||||||
dmabuf_frame_listener = {
|
dmabuf_frame_listener = {
|
||||||
.frame = dmabuf_frame_start,
|
.frame = dmabuf_frame_start,
|
||||||
|
@ -114,14 +106,16 @@ dmabuf_capture_start(struct zwlr_export_dmabuf_manager_v1* manager,
|
||||||
};
|
};
|
||||||
|
|
||||||
self->zwlr_frame =
|
self->zwlr_frame =
|
||||||
zwlr_export_dmabuf_manager_v1_capture_output(manager,
|
zwlr_export_dmabuf_manager_v1_capture_output(self->manager,
|
||||||
overlay_cursor,
|
self->overlay_cursor,
|
||||||
output);
|
self->output);
|
||||||
if (!self->zwlr_frame)
|
if (!self->zwlr_frame)
|
||||||
return NULL;
|
return -1;
|
||||||
|
|
||||||
|
self->status = DMABUF_CAPTURE_IN_PROGRESS;
|
||||||
|
|
||||||
zwlr_export_dmabuf_frame_v1_add_listener(self->zwlr_frame,
|
zwlr_export_dmabuf_frame_v1_add_listener(self->zwlr_frame,
|
||||||
&dmabuf_frame_listener, self);
|
&dmabuf_frame_listener, self);
|
||||||
|
|
||||||
return self;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
31
src/main.c
31
src/main.c
|
@ -53,13 +53,13 @@ struct wayvnc {
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
|
|
||||||
struct renderer renderer;
|
struct renderer renderer;
|
||||||
struct zwlr_export_dmabuf_manager_v1* export_manager;
|
|
||||||
const struct output* selected_output;
|
const struct output* selected_output;
|
||||||
struct dmabuf_capture* capture;
|
|
||||||
|
|
||||||
struct wl_shm* wl_shm;
|
struct wl_shm* wl_shm;
|
||||||
struct zwlr_screencopy_manager_v1* screencopy_manager;
|
struct zwlr_screencopy_manager_v1* screencopy_manager;
|
||||||
|
|
||||||
|
struct dmabuf_capture dmabuf_backend;
|
||||||
|
|
||||||
uv_poll_t wayland_poller;
|
uv_poll_t wayland_poller;
|
||||||
uv_prepare_t flusher;
|
uv_prepare_t flusher;
|
||||||
uv_signal_t signal_handler;
|
uv_signal_t signal_handler;
|
||||||
|
@ -172,7 +172,7 @@ static void registry_add(void* data, struct wl_registry* registry,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(interface, zwlr_export_dmabuf_manager_v1_interface.name) == 0) {
|
if (strcmp(interface, zwlr_export_dmabuf_manager_v1_interface.name) == 0) {
|
||||||
self->export_manager =
|
self->dmabuf_backend.manager =
|
||||||
wl_registry_bind(registry, id,
|
wl_registry_bind(registry, id,
|
||||||
&zwlr_export_dmabuf_manager_v1_interface,
|
&zwlr_export_dmabuf_manager_v1_interface,
|
||||||
1);
|
1);
|
||||||
|
@ -205,7 +205,7 @@ static void registry_remove(void* data, struct wl_registry* registry,
|
||||||
void wayvnc_destroy(struct wayvnc* self)
|
void wayvnc_destroy(struct wayvnc* self)
|
||||||
{
|
{
|
||||||
output_list_destroy(&self->outputs);
|
output_list_destroy(&self->outputs);
|
||||||
zwlr_export_dmabuf_manager_v1_destroy(self->export_manager);
|
zwlr_export_dmabuf_manager_v1_destroy(self->dmabuf_backend.manager);
|
||||||
wl_display_disconnect(self->display);
|
wl_display_disconnect(self->display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,12 +231,15 @@ static int init_wayland(struct wayvnc* self)
|
||||||
wl_display_roundtrip(self->display);
|
wl_display_roundtrip(self->display);
|
||||||
wl_display_dispatch(self->display);
|
wl_display_dispatch(self->display);
|
||||||
|
|
||||||
if (!self->export_manager) {
|
if (!self->dmabuf_backend.manager) {
|
||||||
log_error("Compositor does not support %s.\n",
|
log_error("Compositor does not support %s.\n",
|
||||||
zwlr_export_dmabuf_manager_v1_interface.name);
|
zwlr_export_dmabuf_manager_v1_interface.name);
|
||||||
goto export_manager_failure;
|
goto export_manager_failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self->dmabuf_backend.on_done = on_capture_done;
|
||||||
|
self->dmabuf_backend.userdata = self;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
export_manager_failure:
|
export_manager_failure:
|
||||||
|
@ -252,6 +255,7 @@ int wayvnc_select_first_output(struct wayvnc* self)
|
||||||
|
|
||||||
wl_list_for_each(out, &self->outputs, link) {
|
wl_list_for_each(out, &self->outputs, link) {
|
||||||
self->selected_output = out;
|
self->selected_output = out;
|
||||||
|
self->dmabuf_backend.output = out->wl_output;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,15 +340,7 @@ int init_nvnc(struct wayvnc* self, const char* addr, uint16_t port)
|
||||||
|
|
||||||
int wayvnc_start_capture(struct wayvnc* self)
|
int wayvnc_start_capture(struct wayvnc* self)
|
||||||
{
|
{
|
||||||
self->capture = dmabuf_capture_start(self->export_manager, false,
|
return dmabuf_capture_start(&self->dmabuf_backend);
|
||||||
self->selected_output->wl_output,
|
|
||||||
on_capture_done);
|
|
||||||
if (!self->capture)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
self->capture->userdata = self;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_damage_check_done(struct pixman_region16* damage, void* userdata)
|
void on_damage_check_done(struct pixman_region16* damage, void* userdata)
|
||||||
|
@ -399,6 +395,8 @@ void on_capture_done(struct dmabuf_capture* capture)
|
||||||
struct wayvnc* self = capture->userdata;
|
struct wayvnc* self = capture->userdata;
|
||||||
|
|
||||||
switch (capture->status) {
|
switch (capture->status) {
|
||||||
|
case DMABUF_CAPTURE_IN_PROGRESS:
|
||||||
|
break;
|
||||||
case DMABUF_CAPTURE_FATAL:
|
case DMABUF_CAPTURE_FATAL:
|
||||||
log_error("Fatal error while capturing. Exiting...\n");
|
log_error("Fatal error while capturing. Exiting...\n");
|
||||||
wayvnc_exit();
|
wayvnc_exit();
|
||||||
|
@ -454,12 +452,9 @@ int main(int argc, char* argv[])
|
||||||
if (wayvnc_start_capture(&self) < 0)
|
if (wayvnc_start_capture(&self) < 0)
|
||||||
goto capture_failure;
|
goto capture_failure;
|
||||||
|
|
||||||
self.capture->userdata = &self;
|
|
||||||
|
|
||||||
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||||
|
|
||||||
if (self.capture)
|
dmabuf_capture_stop(&self.dmabuf_backend);
|
||||||
dmabuf_capture_stop(self.capture);
|
|
||||||
|
|
||||||
if (self.current_fb) nvnc_fb_unref(self.current_fb);
|
if (self.current_fb) nvnc_fb_unref(self.current_fb);
|
||||||
if (self.last_fb) nvnc_fb_unref(self.last_fb);
|
if (self.last_fb) nvnc_fb_unref(self.last_fb);
|
||||||
|
|
Loading…
Reference in New Issue