mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2026-04-25 21:04:41 +03:00
Switch to ext-image-* protocols
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# dulcepan
|
||||
|
||||
A screenshot tool for Wayland compositors. Requires wlr-screencopy-unstable-v1
|
||||
support.
|
||||
A screenshot tool for Wayland compositors. Requires ext-image-capture-source-v1
|
||||
and ext-image-copy-capture-v1 support.
|
||||
|
||||
Discuss in [#eclairs on Libera.Chat].
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ add_project_arguments(cc.get_supported_arguments([
|
||||
m = cc.find_library('m')
|
||||
|
||||
wayland_client = dependency('wayland-client')
|
||||
wayland_protos = dependency('wayland-protocols')
|
||||
wayland_protos = dependency('wayland-protocols', version: '>=1.37')
|
||||
|
||||
cairo = dependency('cairo')
|
||||
pixman = dependency('pixman-1')
|
||||
|
||||
@@ -14,12 +14,17 @@ wayland_scanner_client = generator(
|
||||
)
|
||||
|
||||
client_protocols = [
|
||||
wl_protocol_dir / 'stable/tablet/tablet-v2.xml', # cursor-shape dependency
|
||||
# cursor-shape-v1 dependency
|
||||
wl_protocol_dir / 'stable/tablet/tablet-v2.xml',
|
||||
wl_protocol_dir / 'stable/viewporter/viewporter.xml',
|
||||
wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml', # layer-shell dependency
|
||||
# wlr-layer-shell-unstable-v1 dependency
|
||||
wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml',
|
||||
wl_protocol_dir / 'staging/cursor-shape/cursor-shape-v1.xml',
|
||||
# ext-image-capture-source-v1 dependency
|
||||
wl_protocol_dir / 'staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml',
|
||||
wl_protocol_dir / 'staging/ext-image-capture-source/ext-image-capture-source-v1.xml',
|
||||
wl_protocol_dir / 'staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml',
|
||||
'wlr-layer-shell-unstable-v1.xml',
|
||||
'wlr-screencopy-unstable-v1.xml',
|
||||
]
|
||||
|
||||
client_protos_src = []
|
||||
|
||||
@@ -1,232 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="wlr_screencopy_unstable_v1">
|
||||
<copyright>
|
||||
Copyright © 2018 Simon Ser
|
||||
Copyright © 2019 Andri Yngvason
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice (including the next
|
||||
paragraph) shall be included in all copies or substantial portions of the
|
||||
Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<description summary="screen content capturing on client buffers">
|
||||
This protocol allows clients to ask the compositor to copy part of the
|
||||
screen content to a client buffer.
|
||||
|
||||
Warning! The protocol described in this file is experimental and
|
||||
backward incompatible changes may be made. Backward compatible changes
|
||||
may be added together with the corresponding interface version bump.
|
||||
Backward incompatible changes are done by bumping the version number in
|
||||
the protocol and interface names and resetting the interface version.
|
||||
Once the protocol is to be declared stable, the 'z' prefix and the
|
||||
version number in the protocol and interface names are removed and the
|
||||
interface version number is reset.
|
||||
</description>
|
||||
|
||||
<interface name="zwlr_screencopy_manager_v1" version="3">
|
||||
<description summary="manager to inform clients and begin capturing">
|
||||
This object is a manager which offers requests to start capturing from a
|
||||
source.
|
||||
</description>
|
||||
|
||||
<request name="capture_output">
|
||||
<description summary="capture an output">
|
||||
Capture the next frame of an entire output.
|
||||
</description>
|
||||
<arg name="frame" type="new_id" interface="zwlr_screencopy_frame_v1"/>
|
||||
<arg name="overlay_cursor" type="int"
|
||||
summary="composite cursor onto the frame"/>
|
||||
<arg name="output" type="object" interface="wl_output"/>
|
||||
</request>
|
||||
|
||||
<request name="capture_output_region">
|
||||
<description summary="capture an output's region">
|
||||
Capture the next frame of an output's region.
|
||||
|
||||
The region is given in output logical coordinates, see
|
||||
xdg_output.logical_size. The region will be clipped to the output's
|
||||
extents.
|
||||
</description>
|
||||
<arg name="frame" type="new_id" interface="zwlr_screencopy_frame_v1"/>
|
||||
<arg name="overlay_cursor" type="int"
|
||||
summary="composite cursor onto the frame"/>
|
||||
<arg name="output" type="object" interface="wl_output"/>
|
||||
<arg name="x" type="int"/>
|
||||
<arg name="y" type="int"/>
|
||||
<arg name="width" type="int"/>
|
||||
<arg name="height" type="int"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the manager">
|
||||
All objects created by the manager will still remain valid, until their
|
||||
appropriate destroy request has been called.
|
||||
</description>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_screencopy_frame_v1" version="3">
|
||||
<description summary="a frame ready for copy">
|
||||
This object represents a single frame.
|
||||
|
||||
When created, a series of buffer events will be sent, each representing a
|
||||
supported buffer type. The "buffer_done" event is sent afterwards to
|
||||
indicate that all supported buffer types have been enumerated. The client
|
||||
will then be able to send a "copy" request. If the capture is successful,
|
||||
the compositor will send a "flags" followed by a "ready" event.
|
||||
|
||||
For objects version 2 or lower, wl_shm buffers are always supported, ie.
|
||||
the "buffer" event is guaranteed to be sent.
|
||||
|
||||
If the capture failed, the "failed" event is sent. This can happen anytime
|
||||
before the "ready" event.
|
||||
|
||||
Once either a "ready" or a "failed" event is received, the client should
|
||||
destroy the frame.
|
||||
</description>
|
||||
|
||||
<event name="buffer">
|
||||
<description summary="wl_shm buffer information">
|
||||
Provides information about wl_shm buffer parameters that need to be
|
||||
used for this frame. This event is sent once after the frame is created
|
||||
if wl_shm buffers are supported.
|
||||
</description>
|
||||
<arg name="format" type="uint" enum="wl_shm.format" summary="buffer format"/>
|
||||
<arg name="width" type="uint" summary="buffer width"/>
|
||||
<arg name="height" type="uint" summary="buffer height"/>
|
||||
<arg name="stride" type="uint" summary="buffer stride"/>
|
||||
</event>
|
||||
|
||||
<request name="copy">
|
||||
<description summary="copy the frame">
|
||||
Copy the frame to the supplied buffer. The buffer must have a the
|
||||
correct size, see zwlr_screencopy_frame_v1.buffer and
|
||||
zwlr_screencopy_frame_v1.linux_dmabuf. The buffer needs to have a
|
||||
supported format.
|
||||
|
||||
If the frame is successfully copied, a "flags" and a "ready" events are
|
||||
sent. Otherwise, a "failed" event is sent.
|
||||
</description>
|
||||
<arg name="buffer" type="object" interface="wl_buffer"/>
|
||||
</request>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="already_used" value="0"
|
||||
summary="the object has already been used to copy a wl_buffer"/>
|
||||
<entry name="invalid_buffer" value="1"
|
||||
summary="buffer attributes are invalid"/>
|
||||
</enum>
|
||||
|
||||
<enum name="flags" bitfield="true">
|
||||
<entry name="y_invert" value="1" summary="contents are y-inverted"/>
|
||||
</enum>
|
||||
|
||||
<event name="flags">
|
||||
<description summary="frame flags">
|
||||
Provides flags about the frame. This event is sent once before the
|
||||
"ready" event.
|
||||
</description>
|
||||
<arg name="flags" type="uint" enum="flags" summary="frame flags"/>
|
||||
</event>
|
||||
|
||||
<event name="ready">
|
||||
<description summary="indicates frame is available for reading">
|
||||
Called as soon as the frame is copied, indicating it is available
|
||||
for reading. This event includes the time at which presentation happened
|
||||
at.
|
||||
|
||||
The timestamp is expressed as tv_sec_hi, tv_sec_lo, tv_nsec triples,
|
||||
each component being an unsigned 32-bit value. Whole seconds are in
|
||||
tv_sec which is a 64-bit value combined from tv_sec_hi and tv_sec_lo,
|
||||
and the additional fractional part in tv_nsec as nanoseconds. Hence,
|
||||
for valid timestamps tv_nsec must be in [0, 999999999]. The seconds part
|
||||
may have an arbitrary offset at start.
|
||||
|
||||
After receiving this event, the client should destroy the object.
|
||||
</description>
|
||||
<arg name="tv_sec_hi" type="uint"
|
||||
summary="high 32 bits of the seconds part of the timestamp"/>
|
||||
<arg name="tv_sec_lo" type="uint"
|
||||
summary="low 32 bits of the seconds part of the timestamp"/>
|
||||
<arg name="tv_nsec" type="uint"
|
||||
summary="nanoseconds part of the timestamp"/>
|
||||
</event>
|
||||
|
||||
<event name="failed">
|
||||
<description summary="frame copy failed">
|
||||
This event indicates that the attempted frame copy has failed.
|
||||
|
||||
After receiving this event, the client should destroy the object.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="delete this object, used or not">
|
||||
Destroys the frame. This request can be sent at any time by the client.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<!-- Version 2 additions -->
|
||||
<request name="copy_with_damage" since="2">
|
||||
<description summary="copy the frame when it's damaged">
|
||||
Same as copy, except it waits until there is damage to copy.
|
||||
</description>
|
||||
<arg name="buffer" type="object" interface="wl_buffer"/>
|
||||
</request>
|
||||
|
||||
<event name="damage" since="2">
|
||||
<description summary="carries the coordinates of the damaged region">
|
||||
This event is sent right before the ready event when copy_with_damage is
|
||||
requested. It may be generated multiple times for each copy_with_damage
|
||||
request.
|
||||
|
||||
The arguments describe a box around an area that has changed since the
|
||||
last copy request that was derived from the current screencopy manager
|
||||
instance.
|
||||
|
||||
The union of all regions received between the call to copy_with_damage
|
||||
and a ready event is the total damage since the prior ready event.
|
||||
</description>
|
||||
<arg name="x" type="uint" summary="damaged x coordinates"/>
|
||||
<arg name="y" type="uint" summary="damaged y coordinates"/>
|
||||
<arg name="width" type="uint" summary="current width"/>
|
||||
<arg name="height" type="uint" summary="current height"/>
|
||||
</event>
|
||||
|
||||
<!-- Version 3 additions -->
|
||||
<event name="linux_dmabuf" since="3">
|
||||
<description summary="linux-dmabuf buffer information">
|
||||
Provides information about linux-dmabuf buffer parameters that need to
|
||||
be used for this frame. This event is sent once after the frame is
|
||||
created if linux-dmabuf buffers are supported.
|
||||
</description>
|
||||
<arg name="format" type="uint" summary="fourcc pixel format"/>
|
||||
<arg name="width" type="uint" summary="buffer width"/>
|
||||
<arg name="height" type="uint" summary="buffer height"/>
|
||||
</event>
|
||||
|
||||
<event name="buffer_done" since="3">
|
||||
<description summary="all buffer types reported">
|
||||
This event is sent once after all buffer events have been sent.
|
||||
|
||||
The client should proceed to create a buffer of one of the supported
|
||||
types, and send a "copy" request.
|
||||
</description>
|
||||
</event>
|
||||
</interface>
|
||||
</protocol>
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdnoreturn.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#include <wayland-util.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
@@ -60,17 +61,19 @@ struct dp_output {
|
||||
struct wl_callback *redraw_callback;
|
||||
bool needs_redraw;
|
||||
|
||||
struct zwlr_screencopy_frame_v1 *frame;
|
||||
bool has_frame;
|
||||
// XXX: this is completely untested
|
||||
bool y_invert;
|
||||
struct ext_image_capture_source_v1 *source;
|
||||
struct ext_image_copy_capture_session_v1 *session;
|
||||
|
||||
struct ext_image_copy_capture_frame_v1 *frame;
|
||||
enum wl_shm_format frame_format;
|
||||
bool has_frame_format;
|
||||
|
||||
struct wl_buffer *frame_buffer;
|
||||
int32_t frame_stride;
|
||||
uint32_t frame_format;
|
||||
void *frame_data;
|
||||
size_t frame_size;
|
||||
|
||||
bool captured;
|
||||
|
||||
// wl_buffer is NULL if uninitialized
|
||||
struct dp_buffer swapchain[DP_SWAPCHAIN_LEN];
|
||||
|
||||
@@ -186,7 +189,9 @@ struct dp_state {
|
||||
struct wp_viewporter *viewporter;
|
||||
struct wl_shm *shm;
|
||||
struct zwlr_layer_shell_v1 *layer_shell;
|
||||
struct zwlr_screencopy_manager_v1 *screencopy_manager;
|
||||
|
||||
struct ext_output_image_capture_source_manager_v1 *output_image_capture_source_manager;
|
||||
struct ext_image_copy_capture_manager_v1 *image_copy_capture_manager;
|
||||
|
||||
// Optional
|
||||
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
|
||||
@@ -242,6 +247,8 @@ void dp_select_notify_pointer_position(
|
||||
|
||||
void dp_select_toggle_whole(struct dp_selection *selection, struct dp_output *output);
|
||||
|
||||
bool dp_format_supported(enum wl_shm_format format);
|
||||
|
||||
void dp_save(struct dp_state *state);
|
||||
|
||||
void dp_log_error(const char *fmt, ...);
|
||||
|
||||
22
src/main.c
22
src/main.c
@@ -8,9 +8,10 @@
|
||||
|
||||
#include "cursor-shape-v1-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"
|
||||
|
||||
static void registry_handle_global(void *data, struct wl_registry *registry, uint32_t name,
|
||||
const char *interface, uint32_t version) {
|
||||
@@ -27,9 +28,12 @@ static void registry_handle_global(void *data, struct wl_registry *registry, uin
|
||||
state->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
||||
} else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) {
|
||||
state->layer_shell = wl_registry_bind(registry, name, &zwlr_layer_shell_v1_interface, 1);
|
||||
} else if (strcmp(interface, zwlr_screencopy_manager_v1_interface.name) == 0) {
|
||||
state->screencopy_manager =
|
||||
wl_registry_bind(registry, name, &zwlr_screencopy_manager_v1_interface, 1);
|
||||
} else if (strcmp(interface, ext_output_image_capture_source_manager_v1_interface.name) == 0) {
|
||||
state->output_image_capture_source_manager = wl_registry_bind(
|
||||
registry, name, &ext_output_image_capture_source_manager_v1_interface, 1);
|
||||
} else if (strcmp(interface, ext_image_copy_capture_manager_v1_interface.name) == 0) {
|
||||
state->image_copy_capture_manager =
|
||||
wl_registry_bind(registry, name, &ext_image_copy_capture_manager_v1_interface, 1);
|
||||
} else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
|
||||
state->cursor_shape_manager =
|
||||
wl_registry_bind(registry, name, &wp_cursor_shape_manager_v1_interface, 1);
|
||||
@@ -88,8 +92,10 @@ static void run(struct dp_state *state) {
|
||||
dp_log_fatal("The compositor has no wl_shm");
|
||||
} else if (state->layer_shell == NULL) {
|
||||
dp_log_fatal("The compositor has no zwlr_layer_shell_v1");
|
||||
} else if (state->screencopy_manager == NULL) {
|
||||
dp_log_fatal("The compositor has no zwlr_screencopy_manager_v1");
|
||||
} else if (state->output_image_capture_source_manager == NULL) {
|
||||
dp_log_fatal("The compositor has no ext_output_image_capture_source_manager_v1");
|
||||
} else if (state->image_copy_capture_manager == NULL) {
|
||||
dp_log_fatal("The compositor has no ext_image_copy_capture_manager_v1");
|
||||
}
|
||||
|
||||
if (wl_list_empty(&state->outputs)) {
|
||||
@@ -148,7 +154,9 @@ static void run(struct dp_state *state) {
|
||||
wp_viewporter_destroy(state->viewporter);
|
||||
wl_shm_destroy(state->shm);
|
||||
zwlr_layer_shell_v1_destroy(state->layer_shell);
|
||||
zwlr_screencopy_manager_v1_destroy(state->screencopy_manager);
|
||||
|
||||
ext_output_image_capture_source_manager_v1_destroy(state->output_image_capture_source_manager);
|
||||
ext_image_copy_capture_manager_v1_destroy(state->image_copy_capture_manager);
|
||||
|
||||
if (state->cursor_shape_manager) {
|
||||
wp_cursor_shape_manager_v1_destroy(state->cursor_shape_manager);
|
||||
|
||||
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);
|
||||
|
||||
10
src/save.c
10
src/save.c
@@ -58,7 +58,7 @@ static pixman_format_code_t shm_to_pixman(enum wl_shm_format shm_format) {
|
||||
return formats[i].pixman;
|
||||
}
|
||||
}
|
||||
dp_log_fatal("failed to get a matching Pixman format for wl_shm format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void write_png(FILE *fp, pixman_image_t *image, int width, int height, int level) {
|
||||
@@ -106,6 +106,10 @@ static void write_ppm(FILE *fp, pixman_image_t *image, int width, int height) {
|
||||
}
|
||||
}
|
||||
|
||||
bool dp_format_supported(enum wl_shm_format format) {
|
||||
return shm_to_pixman(format) != 0;
|
||||
}
|
||||
|
||||
void dp_save(struct dp_state *state) {
|
||||
struct dp_selection *selection = &state->selection;
|
||||
struct dp_output *output = selection->output;
|
||||
@@ -117,14 +121,14 @@ void dp_save(struct dp_state *state) {
|
||||
pixman_format_code_t pixman_format = shm_to_pixman(output->frame_format);
|
||||
|
||||
pixman_image_t *frame_image = pixman_image_create_bits(
|
||||
pixman_format, output->width, output->height, output->frame_data, output->frame_stride);
|
||||
pixman_format, output->width, output->height, output->frame_data, output->width * 4);
|
||||
|
||||
static const pixman_fixed_t cosines[] = {pixman_fixed_1, 0, -pixman_fixed_1, 0};
|
||||
|
||||
pixman_fixed_t scale_x = (output->transform & WL_OUTPUT_TRANSFORM_FLIPPED) != 0
|
||||
? -pixman_fixed_1
|
||||
: pixman_fixed_1;
|
||||
pixman_fixed_t scale_y = output->y_invert ? -pixman_fixed_1 : pixman_fixed_1;
|
||||
pixman_fixed_t scale_y = pixman_fixed_1;
|
||||
|
||||
struct pixman_transform frame_transform;
|
||||
pixman_transform_init_identity(&frame_transform);
|
||||
|
||||
Reference in New Issue
Block a user