Merge branch 'capture' into 'master'

wlr_ext_image_copy_capture_v1: only copy damaged regions in copy_shm

See merge request wlroots/wlroots!5133
This commit is contained in:
YaoBing Xiao 2026-03-16 03:05:12 +08:00
commit 3556fb4b7b

View file

@ -133,20 +133,49 @@ out:
} }
static bool copy_shm(void *data, uint32_t format, size_t stride, static bool copy_shm(void *data, uint32_t format, size_t stride,
struct wlr_buffer *src, struct wlr_renderer *renderer) { struct wlr_buffer *src, struct wlr_renderer *renderer,
const pixman_region32_t *damage) {
// TODO: bypass renderer if source buffer supports data ptr access // TODO: bypass renderer if source buffer supports data ptr access
struct wlr_texture *texture = wlr_texture_from_buffer(renderer, src); struct wlr_texture *texture = wlr_texture_from_buffer(renderer, src);
if (!texture) { if (!texture) {
return false; return false;
} }
// TODO: only copy damaged region bool ok = true;
bool ok = wlr_texture_read_pixels(texture, &(struct wlr_texture_read_pixels_options){
if (damage && !pixman_region32_empty(damage)) {
int rects_len = 0;
const pixman_box32_t *rects = pixman_region32_rectangles(damage, &rects_len);
for (int i = 0; i < rects_len; i++) {
const pixman_box32_t *rect = &rects[i];
int width = rect->x2 - rect->x1;
int height = rect->y2 - rect->y1;
if (width <= 0 || height <= 0) {
continue;
}
ok = wlr_texture_read_pixels(texture, &(struct wlr_texture_read_pixels_options){
.data = data, .data = data,
.format = format, .format = format,
.stride = stride, .stride = stride,
.dst_x = rect->x1,
.dst_y = rect->y1,
.src_box = {
.x = rect->x1,
.y = rect->y1,
.width = width,
.height = height,
},
}); });
if (!ok) {
break;
}
}
}
wlr_texture_destroy(texture); wlr_texture_destroy(texture);
return ok; return ok;
@ -182,7 +211,7 @@ bool wlr_ext_image_copy_capture_frame_v1_copy_buffer(struct wlr_ext_image_copy_c
ok = false; ok = false;
failure_reason = EXT_IMAGE_COPY_CAPTURE_FRAME_V1_FAILURE_REASON_BUFFER_CONSTRAINTS; failure_reason = EXT_IMAGE_COPY_CAPTURE_FRAME_V1_FAILURE_REASON_BUFFER_CONSTRAINTS;
} else { } else {
ok = copy_shm(data, format, stride, src, renderer); ok = copy_shm(data, format, stride, src, renderer, &frame->buffer_damage);
} }
wlr_buffer_end_data_ptr_access(dst); wlr_buffer_end_data_ptr_access(dst);
} }