From e43934e2d2219bdd9a99c78463aa47cfc0404dcd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 10 Jun 2024 18:41:05 +0200 Subject: Remove video_alignment_padding variable, replace with putting capture content in the center with frame resolution and capture resolution diff --- src/capture/kms.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/capture/kms.c') diff --git a/src/capture/kms.c b/src/capture/kms.c index be7e58d..e479019 100644 --- a/src/capture/kms.c +++ b/src/capture/kms.c @@ -10,6 +10,10 @@ #define HDMI_STATIC_METADATA_TYPE1 0 #define HDMI_EOTF_SMPTE_ST2084 2 +static int max_int(int a, int b) { + return a > b ? a : b; +} + /* TODO: On monitor reconfiguration, find monitor x, y, width and height again. Do the same for nvfbc. */ typedef struct { @@ -82,9 +86,6 @@ int gsr_capture_kms_start(gsr_capture_kms *self, const char *display_to_capture, self->base.video_codec_context->height = FFALIGN(self->capture_size.y, 2); } - self->base.video_alignment_padding.x = self->base.video_codec_context->width - self->capture_size.x; - self->base.video_alignment_padding.y = self->base.video_codec_context->height - self->capture_size.y; - frame->width = self->base.video_codec_context->width; frame->height = self->base.video_codec_context->height; return 0; @@ -300,8 +301,11 @@ bool gsr_capture_kms_capture(gsr_capture_kms *self, AVFrame *frame, bool hdr, bo const float texture_rotation = monitor_rotation_to_radians(self->monitor_rotation); + const int target_x = max_int(0, frame->width / 2 - self->capture_size.x / 2); + const int target_y = max_int(0, frame->height / 2 - self->capture_size.y / 2); + gsr_color_conversion_draw(&self->base.color_conversion, self->base.input_texture, - (vec2i){self->base.video_alignment_padding.x / 2, self->base.video_alignment_padding.y / 2}, self->capture_size, + (vec2i){target_x, target_y}, self->capture_size, capture_pos, self->capture_size, texture_rotation, false); @@ -332,8 +336,8 @@ bool gsr_capture_kms_capture(gsr_capture_kms *self, AVFrame *frame, bool hdr, bo break; } - cursor_pos.x += (self->base.video_alignment_padding.x / 2); - cursor_pos.y += (self->base.video_alignment_padding.y / 2); + cursor_pos.x += target_x; + cursor_pos.y += target_y; const intptr_t img_attr_cursor[] = { EGL_LINUX_DRM_FOURCC_EXT, cursor_drm_fd->pixel_format, -- cgit v1.2.3