mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2026-04-26 21:14:40 +03:00
Switch to ext-image-* protocols
This commit is contained in:
129
src/output.c
129
src/output.c
@@ -5,14 +5,17 @@
|
||||
#include <wayland-client-protocol.h>
|
||||
|
||||
#include "dulcepan.h"
|
||||
#include "ext-image-capture-source-v1-protocol.h"
|
||||
#include "ext-image-copy-capture-v1-protocol.h"
|
||||
#include "viewporter-protocol.h"
|
||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
||||
#include "wlr-screencopy-unstable-v1-protocol.h"
|
||||
|
||||
// Initialiation flow:
|
||||
// - Wait for mode+transform info
|
||||
// - Wait for done, compute transformed size
|
||||
// - Prepare surfaces, get a frame, wait for it to be ready
|
||||
// - Wait for the output configuration, compute transformed size
|
||||
// - Create a source, a session, and a frame
|
||||
// - Create and prepare surfaces
|
||||
// - Wait for the session information, capture the frame
|
||||
// - Wait for the frame
|
||||
// - Commit the main surface, wait for a configure event
|
||||
// - Save effective size, put the frame buffer on the main surface
|
||||
// - The output is initialized
|
||||
@@ -21,7 +24,7 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface
|
||||
uint32_t serial, uint32_t width, uint32_t height) {
|
||||
struct dp_output *output = data;
|
||||
|
||||
if (!output->has_frame) {
|
||||
if (!output->captured) {
|
||||
// Ignore configures that came too early
|
||||
return;
|
||||
}
|
||||
@@ -51,10 +54,6 @@ static void layer_surface_handle_configure(void *data, struct zwlr_layer_surface
|
||||
wp_viewport_set_destination(
|
||||
output->select_viewport, output->effective_width, output->effective_height);
|
||||
|
||||
if (output->y_invert) {
|
||||
wl_surface_set_buffer_transform(output->main_surface, WL_OUTPUT_TRANSFORM_FLIPPED_180);
|
||||
}
|
||||
|
||||
wl_surface_attach(output->main_surface, output->frame_buffer, 0, 0);
|
||||
wl_surface_commit(output->main_surface);
|
||||
|
||||
@@ -71,54 +70,100 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
|
||||
.closed = layer_surface_handle_closed,
|
||||
};
|
||||
|
||||
static void frame_handle_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t format,
|
||||
uint32_t width, uint32_t height, uint32_t stride) {
|
||||
static void session_handle_buffer_size(void *data,
|
||||
struct ext_image_copy_capture_session_v1 *session, uint32_t width, uint32_t height) {
|
||||
struct dp_output *output = data;
|
||||
|
||||
if (output->frame_buffer != NULL) {
|
||||
wl_buffer_destroy(output->frame_buffer);
|
||||
}
|
||||
|
||||
if ((int32_t)width != output->width || (int32_t)height != output->height) {
|
||||
dp_log_fatal("Output/buffer size mismatch: mode=%" PRIi32 "x%" PRIi32 ", buffer=%" PRIu32
|
||||
"x%" PRIu32,
|
||||
output->width, output->height, width, height);
|
||||
}
|
||||
|
||||
output->frame_format = format;
|
||||
output->frame_stride = (int)stride;
|
||||
output->frame_buffer = dp_buffer_create(output->state, output->width, output->height,
|
||||
output->frame_stride, output->frame_format, &output->frame_data, &output->frame_size);
|
||||
zwlr_screencopy_frame_v1_copy(output->frame, output->frame_buffer);
|
||||
}
|
||||
|
||||
static void frame_handle_flags(void *data, struct zwlr_screencopy_frame_v1 *frame, uint32_t flags) {
|
||||
static void session_handle_shm_format(
|
||||
void *data, struct ext_image_copy_capture_session_v1 *session, uint32_t format) {
|
||||
struct dp_output *output = data;
|
||||
if ((flags & ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT) != 0) {
|
||||
output->y_invert = true;
|
||||
if (!output->has_frame_format && dp_format_supported(format)) {
|
||||
output->frame_format = format;
|
||||
output->has_frame_format = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void frame_handle_ready(void *data, struct zwlr_screencopy_frame_v1 *frame,
|
||||
uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec) {
|
||||
static void session_handle_dmabuf_device(
|
||||
void *data, struct ext_image_copy_capture_session_v1 *session, struct wl_array *device) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
static void session_handle_dmabuf_format(void *data,
|
||||
struct ext_image_copy_capture_session_v1 *session, uint32_t format,
|
||||
struct wl_array *modifiers) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
static void session_handle_done(void *data, struct ext_image_copy_capture_session_v1 *session) {
|
||||
struct dp_output *output = data;
|
||||
if (!output->has_frame_format) {
|
||||
dp_log_fatal("Output %s: no suitable SHM format", output->name);
|
||||
}
|
||||
|
||||
output->frame_buffer = dp_buffer_create(output->state, output->width, output->height,
|
||||
output->width * 4, output->frame_format, &output->frame_data, &output->frame_size);
|
||||
|
||||
ext_image_copy_capture_frame_v1_attach_buffer(output->frame, output->frame_buffer);
|
||||
ext_image_copy_capture_frame_v1_capture(output->frame);
|
||||
}
|
||||
|
||||
static void session_handle_stopped(void *data, struct ext_image_copy_capture_session_v1 *session) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
static const struct ext_image_copy_capture_session_v1_listener session_listener = {
|
||||
.buffer_size = session_handle_buffer_size,
|
||||
.shm_format = session_handle_shm_format,
|
||||
.dmabuf_device = session_handle_dmabuf_device,
|
||||
.dmabuf_format = session_handle_dmabuf_format,
|
||||
.done = session_handle_done,
|
||||
.stopped = session_handle_stopped,
|
||||
};
|
||||
|
||||
static void frame_handle_transform(
|
||||
void *data, struct ext_image_copy_capture_frame_v1 *frame, uint32_t transform) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
static void frame_handle_damage(void *data, struct ext_image_copy_capture_frame_v1 *frame,
|
||||
int32_t x, int32_t y, int32_t width, int32_t height) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
static void frame_handle_presentation_time(void *data,
|
||||
struct ext_image_copy_capture_frame_v1 *frame, uint32_t tv_sec_hi, uint32_t tv_sec_lo,
|
||||
uint32_t tv_nsec) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
static void frame_handle_ready(void *data, struct ext_image_copy_capture_frame_v1 *frame) {
|
||||
struct dp_output *output = data;
|
||||
|
||||
zwlr_screencopy_frame_v1_destroy(output->frame);
|
||||
ext_image_copy_capture_frame_v1_destroy(output->frame);
|
||||
output->frame = NULL;
|
||||
|
||||
output->has_frame = true;
|
||||
output->captured = true;
|
||||
|
||||
wl_surface_commit(output->main_surface);
|
||||
}
|
||||
|
||||
static void frame_handle_failed(void *data, struct zwlr_screencopy_frame_v1 *frame) {
|
||||
static void frame_handle_failed(
|
||||
void *data, struct ext_image_copy_capture_frame_v1 *frame, uint32_t reason) {
|
||||
// Shouldn't happen?
|
||||
struct dp_output *output = data;
|
||||
dp_log_fatal("Output %s: failed to copy a frame", output->name);
|
||||
dp_log_fatal("Output %s: failed to capture a frame, reason %" PRIu32, output->name, reason);
|
||||
}
|
||||
|
||||
static const struct zwlr_screencopy_frame_v1_listener frame_listener = {
|
||||
.buffer = frame_handle_buffer,
|
||||
.flags = frame_handle_flags,
|
||||
static const struct ext_image_copy_capture_frame_v1_listener frame_listener = {
|
||||
.transform = frame_handle_transform,
|
||||
.damage = frame_handle_damage,
|
||||
.presentation_time = frame_handle_presentation_time,
|
||||
.ready = frame_handle_ready,
|
||||
.failed = frame_handle_failed,
|
||||
};
|
||||
@@ -201,9 +246,16 @@ static void output_handle_done(void *data, struct wl_output *wl_output) {
|
||||
|
||||
struct dp_state *state = output->state;
|
||||
|
||||
output->frame = zwlr_screencopy_manager_v1_capture_output(
|
||||
state->screencopy_manager, state->show_cursors, output->wl_output);
|
||||
zwlr_screencopy_frame_v1_add_listener(output->frame, &frame_listener, output);
|
||||
output->source = ext_output_image_capture_source_manager_v1_create_source(
|
||||
state->output_image_capture_source_manager, output->wl_output);
|
||||
|
||||
output->session =
|
||||
ext_image_copy_capture_manager_v1_create_session(state->image_copy_capture_manager,
|
||||
output->source, EXT_IMAGE_COPY_CAPTURE_MANAGER_V1_OPTIONS_PAINT_CURSORS);
|
||||
ext_image_copy_capture_session_v1_add_listener(output->session, &session_listener, output);
|
||||
|
||||
output->frame = ext_image_copy_capture_session_v1_create_frame(output->session);
|
||||
ext_image_copy_capture_frame_v1_add_listener(output->frame, &frame_listener, output);
|
||||
|
||||
output->main_surface = wl_compositor_create_surface(state->compositor);
|
||||
output->main_layer_surface = zwlr_layer_shell_v1_get_layer_surface(state->layer_shell,
|
||||
@@ -459,6 +511,9 @@ void dp_output_destroy(struct dp_output *output) {
|
||||
}
|
||||
}
|
||||
|
||||
ext_image_copy_capture_session_v1_destroy(output->session);
|
||||
ext_image_capture_source_v1_destroy(output->source);
|
||||
|
||||
wl_subsurface_destroy(output->select_subsurface);
|
||||
wp_viewport_destroy(output->select_viewport);
|
||||
wl_surface_destroy(output->select_surface);
|
||||
|
||||
Reference in New Issue
Block a user