mirror of
https://github.com/hyprwm/xdg-desktop-portal-hyprland.git
synced 2024-11-26 07:55:58 +01:00
Add functions to clean simple_buffer.{data,buffer} in wlr_screencast.c
This commit is contained in:
parent
f23e9e4921
commit
c6253415c0
1 changed files with 25 additions and 17 deletions
|
@ -19,15 +19,23 @@
|
||||||
#include "xdpw.h"
|
#include "xdpw.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
|
static void wlr_frame_buffer_clear(struct xdpw_screencast_instance *cast) {
|
||||||
|
if (cast->simple_frame.data != NULL) {
|
||||||
|
munmap(cast->simple_frame.data, cast->simple_frame.size);
|
||||||
|
cast->simple_frame.data = NULL;
|
||||||
|
}
|
||||||
|
if (cast->simple_frame.buffer != NULL) {
|
||||||
|
wl_buffer_destroy(cast->simple_frame.buffer);
|
||||||
|
cast->simple_frame.buffer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void xdpw_wlr_frame_free(struct xdpw_screencast_instance *cast) {
|
void xdpw_wlr_frame_free(struct xdpw_screencast_instance *cast) {
|
||||||
zwlr_screencopy_frame_v1_destroy(cast->wlr_frame);
|
zwlr_screencopy_frame_v1_destroy(cast->wlr_frame);
|
||||||
cast->wlr_frame = NULL;
|
cast->wlr_frame = NULL;
|
||||||
// TODO: reuse this buffer unless we quit or error out
|
// TODO: reuse this buffer unless we quit or error out
|
||||||
if (cast->quit || cast->err) {
|
if (cast->quit || cast->err) {
|
||||||
munmap(cast->simple_frame.data, cast->simple_frame.size);
|
wlr_frame_buffer_clear(cast);
|
||||||
cast->simple_frame.data = NULL;
|
|
||||||
wl_buffer_destroy(cast->simple_frame.buffer);
|
|
||||||
cast->simple_frame.buffer = NULL;
|
|
||||||
logprint(TRACE, "xdpw: simple_frame buffer destroyed");
|
logprint(TRACE, "xdpw: simple_frame buffer destroyed");
|
||||||
}
|
}
|
||||||
logprint(TRACE, "wlroots: frame destroyed");
|
logprint(TRACE, "wlroots: frame destroyed");
|
||||||
|
@ -100,6 +108,18 @@ static struct wl_buffer *create_shm_buffer(struct xdpw_screencast_instance *cast
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wlr_frame_buffer_chparam(struct xdpw_screencast_instance *cast,
|
||||||
|
uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
||||||
|
|
||||||
|
logprint(DEBUG, "wlroots: reset buffer");
|
||||||
|
cast->simple_frame.width = width;
|
||||||
|
cast->simple_frame.height = height;
|
||||||
|
cast->simple_frame.stride = stride;
|
||||||
|
cast->simple_frame.size = stride * height;
|
||||||
|
cast->simple_frame.format = format;
|
||||||
|
wlr_frame_buffer_clear(cast);
|
||||||
|
}
|
||||||
|
|
||||||
static void wlr_frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,
|
static void wlr_frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,
|
||||||
uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
|
||||||
struct xdpw_screencast_instance *cast = data;
|
struct xdpw_screencast_instance *cast = data;
|
||||||
|
@ -108,19 +128,7 @@ static void wlr_frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,
|
||||||
cast->wlr_frame = frame;
|
cast->wlr_frame = frame;
|
||||||
if (cast->simple_frame.width != width || cast->simple_frame.height != height || cast->simple_frame.stride != stride || cast->simple_frame.format != format) {
|
if (cast->simple_frame.width != width || cast->simple_frame.height != height || cast->simple_frame.stride != stride || cast->simple_frame.format != format) {
|
||||||
logprint(TRACE, "wlroots: buffer properties changed");
|
logprint(TRACE, "wlroots: buffer properties changed");
|
||||||
if (cast->simple_frame.data != NULL) {
|
wlr_frame_buffer_chparam(cast, format, width, height, stride);
|
||||||
munmap(cast->simple_frame.data, cast->simple_frame.size);
|
|
||||||
cast->simple_frame.data = NULL;
|
|
||||||
}
|
|
||||||
if (cast->simple_frame.buffer != NULL) {
|
|
||||||
wl_buffer_destroy(cast->simple_frame.buffer);
|
|
||||||
cast->simple_frame.buffer = NULL;
|
|
||||||
}
|
|
||||||
cast->simple_frame.width = width;
|
|
||||||
cast->simple_frame.height = height;
|
|
||||||
cast->simple_frame.stride = stride;
|
|
||||||
cast->simple_frame.size = stride * height;
|
|
||||||
cast->simple_frame.format = format;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cast->simple_frame.buffer == NULL && cast->simple_frame.data == NULL) {
|
if (cast->simple_frame.buffer == NULL && cast->simple_frame.data == NULL) {
|
||||||
|
|
Loading…
Reference in a new issue