mirror of
https://repo.dec05eba.com/gpu-screen-recorder
synced 2026-03-31 09:07:13 +09:00
Fix screenshot with region not working correctly for some sizes and possibly crashing
This commit is contained in:
@@ -132,6 +132,8 @@ typedef void(*__GLXextFuncPtr)(void);
|
||||
#define GL_ONE_MINUS_SRC_ALPHA 0x0303
|
||||
#define GL_DEBUG_OUTPUT 0x92E0
|
||||
#define GL_SCISSOR_TEST 0x0C11
|
||||
#define GL_PACK_ALIGNMENT 0x0D05
|
||||
#define GL_UNPACK_ALIGNMENT 0x0CF5
|
||||
|
||||
#define GL_VENDOR 0x1F00
|
||||
#define GL_RENDERER 0x1F01
|
||||
@@ -269,6 +271,7 @@ struct gsr_egl {
|
||||
void (*glEnable)(unsigned int cap);
|
||||
void (*glDisable)(unsigned int cap);
|
||||
void (*glBlendFunc)(unsigned int sfactor, unsigned int dfactor);
|
||||
void (*glPixelStorei)(unsigned int pname, int param);
|
||||
int (*glGetUniformLocation)(unsigned int program, const char *name);
|
||||
void (*glUniform1f)(int location, float v0);
|
||||
void (*glUniform2f)(int location, float v0, float v1);
|
||||
|
||||
@@ -221,16 +221,14 @@ static int gsr_capture_kms_start(gsr_capture *cap, gsr_capture_metadata *capture
|
||||
|
||||
if(self->params.output_resolution.x > 0 && self->params.output_resolution.y > 0) {
|
||||
self->params.output_resolution = scale_keep_aspect_ratio(self->capture_size, self->params.output_resolution);
|
||||
capture_metadata->width = FFALIGN(self->params.output_resolution.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->params.output_resolution.y, 2);
|
||||
capture_metadata->width = self->params.output_resolution.x;
|
||||
capture_metadata->height = self->params.output_resolution.y;
|
||||
} else if(self->params.region_size.x > 0 && self->params.region_size.y > 0) {
|
||||
self->params.output_resolution = self->params.region_size;
|
||||
capture_metadata->width = FFALIGN(self->params.region_size.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->params.region_size.y, 2);
|
||||
capture_metadata->width = self->params.region_size.x;
|
||||
capture_metadata->height = self->params.region_size.y;
|
||||
} else {
|
||||
self->params.output_resolution = self->capture_size;
|
||||
capture_metadata->width = FFALIGN(self->capture_size.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->capture_size.y, 2);
|
||||
capture_metadata->width = self->capture_size.x;
|
||||
capture_metadata->height = self->capture_size.y;
|
||||
}
|
||||
|
||||
self->fast_path_failed = self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && !gl_driver_version_greater_than(&self->params.egl->gpu_info, 24, 0, 9);
|
||||
|
||||
@@ -323,17 +323,16 @@ static int gsr_capture_nvfbc_start(gsr_capture *cap, gsr_capture_metadata *captu
|
||||
goto error_cleanup;
|
||||
}
|
||||
|
||||
capture_metadata->width = FFALIGN(self->tracking_width, 2);
|
||||
capture_metadata->height = FFALIGN(self->tracking_height, 2);
|
||||
capture_metadata->width = self->tracking_width;
|
||||
capture_metadata->height = self->tracking_height;
|
||||
|
||||
if(self->params.output_resolution.x > 0 && self->params.output_resolution.y > 0) {
|
||||
self->params.output_resolution = scale_keep_aspect_ratio((vec2i){capture_metadata->width, capture_metadata->height}, self->params.output_resolution);
|
||||
capture_metadata->width = FFALIGN(self->params.output_resolution.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->params.output_resolution.y, 2);
|
||||
capture_metadata->width = self->params.output_resolution.x;
|
||||
capture_metadata->height = self->params.output_resolution.y;
|
||||
} else if(self->params.region_size.x > 0 && self->params.region_size.y > 0) {
|
||||
self->params.output_resolution = self->params.region_size;
|
||||
capture_metadata->width = FFALIGN(self->params.region_size.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->params.region_size.y, 2);
|
||||
capture_metadata->width = self->params.region_size.x;
|
||||
capture_metadata->height = self->params.region_size.y;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -298,13 +298,12 @@ static int gsr_capture_portal_start(gsr_capture *cap, gsr_capture_metadata *capt
|
||||
}
|
||||
|
||||
if(self->params.output_resolution.x == 0 && self->params.output_resolution.y == 0) {
|
||||
self->params.output_resolution = self->capture_size;
|
||||
capture_metadata->width = FFALIGN(self->capture_size.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->capture_size.y, 2);
|
||||
capture_metadata->width = self->capture_size.x;
|
||||
capture_metadata->height = self->capture_size.y;
|
||||
} else {
|
||||
self->params.output_resolution = scale_keep_aspect_ratio(self->capture_size, self->params.output_resolution);
|
||||
capture_metadata->width = FFALIGN(self->params.output_resolution.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->params.output_resolution.y, 2);
|
||||
capture_metadata->width = self->params.output_resolution.x;
|
||||
capture_metadata->height = self->params.output_resolution.y;
|
||||
}
|
||||
|
||||
self->fast_path_failed = self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && !gl_driver_version_greater_than(&self->params.egl->gpu_info, 24, 0, 9);
|
||||
|
||||
@@ -113,12 +113,11 @@ static int gsr_capture_xcomposite_start(gsr_capture *cap, gsr_capture_metadata *
|
||||
self->params.egl->glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
if(self->params.output_resolution.x == 0 && self->params.output_resolution.y == 0) {
|
||||
self->params.output_resolution = self->texture_size;
|
||||
capture_metadata->width = FFALIGN(self->texture_size.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->texture_size.y, 2);
|
||||
capture_metadata->width = self->texture_size.x;
|
||||
capture_metadata->height = self->texture_size.y;
|
||||
} else {
|
||||
capture_metadata->width = FFALIGN(self->params.output_resolution.x, 2);
|
||||
capture_metadata->height = FFALIGN(self->params.output_resolution.y, 2);
|
||||
capture_metadata->width = self->params.output_resolution.x;
|
||||
capture_metadata->height = self->params.output_resolution.y;
|
||||
}
|
||||
|
||||
self->fast_path_failed = self->params.egl->gpu_info.vendor == GSR_GPU_VENDOR_AMD && !gl_driver_version_greater_than(&self->params.egl->gpu_info, 24, 0, 9);
|
||||
|
||||
@@ -324,6 +324,7 @@ static bool gsr_egl_load_gl(gsr_egl *self, void *library) {
|
||||
{ (void**)&self->glEnable, "glEnable" },
|
||||
{ (void**)&self->glDisable, "glDisable" },
|
||||
{ (void**)&self->glBlendFunc, "glBlendFunc" },
|
||||
{ (void**)&self->glPixelStorei, "glPixelStorei" },
|
||||
{ (void**)&self->glGetUniformLocation, "glGetUniformLocation" },
|
||||
{ (void**)&self->glUniform1f, "glUniform1f" },
|
||||
{ (void**)&self->glUniform2f, "glUniform2f" },
|
||||
@@ -448,6 +449,8 @@ bool gsr_egl_load(gsr_egl *self, gsr_window *window, bool is_monitor_capture, bo
|
||||
|
||||
self->glEnable(GL_BLEND);
|
||||
self->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
self->glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
self->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
if(enable_debug) {
|
||||
self->glEnable(GL_DEBUG_OUTPUT);
|
||||
|
||||
@@ -138,6 +138,9 @@ static bool gsr_video_encoder_nvenc_start(gsr_video_encoder *encoder, AVCodecCon
|
||||
return false;
|
||||
}
|
||||
|
||||
video_codec_context->width = FFALIGN(video_codec_context->width, 2);
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 2);
|
||||
|
||||
if(video_codec_context->width < 128)
|
||||
video_codec_context->width = 128;
|
||||
|
||||
|
||||
@@ -167,6 +167,13 @@ static bool gsr_video_encoder_vaapi_start(gsr_video_encoder *encoder, AVCodecCon
|
||||
} else {
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 16);
|
||||
}
|
||||
} else {
|
||||
video_codec_context->width = FFALIGN(video_codec_context->width, 2);
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 2);
|
||||
}
|
||||
|
||||
if(FFALIGN(video_codec_context->width, 2) != FFALIGN(frame->width, 2) || FFALIGN(video_codec_context->height, 2) != FFALIGN(frame->height, 2)) {
|
||||
fprintf(stderr, "gsr warning: gsr_video_encoder_vaapi_start: black bars have been added to the video because of a bug in AMD drivers/hardware. Record with h264 codec instead (-k h264) to get around this issue\n");
|
||||
}
|
||||
|
||||
if(video_codec_context->width < 128)
|
||||
|
||||
@@ -165,6 +165,18 @@ static void gsr_video_encoder_vulkan_stop(gsr_video_encoder_vulkan *self, AVCode
|
||||
static bool gsr_video_encoder_vulkan_start(gsr_video_encoder *encoder, AVCodecContext *video_codec_context, AVFrame *frame) {
|
||||
gsr_video_encoder_vulkan *self = encoder->priv;
|
||||
|
||||
video_codec_context->width = FFALIGN(video_codec_context->width, 2);
|
||||
video_codec_context->height = FFALIGN(video_codec_context->height, 2);
|
||||
|
||||
if(video_codec_context->width < 128)
|
||||
video_codec_context->width = 128;
|
||||
|
||||
if(video_codec_context->height < 128)
|
||||
video_codec_context->height = 128;
|
||||
|
||||
frame->width = video_codec_context->width;
|
||||
frame->height = video_codec_context->height;
|
||||
|
||||
if(!gsr_video_encoder_vulkan_setup_context(self, video_codec_context)) {
|
||||
gsr_video_encoder_vulkan_stop(self, video_codec_context);
|
||||
return false;
|
||||
|
||||
@@ -2533,8 +2533,6 @@ static gsr_capture* create_capture_impl(std::string &window_str, vec2i output_re
|
||||
region_position.y -= monitor_pos.y;
|
||||
}
|
||||
|
||||
fprintf(stderr, "region: %dx%d+%d+%d\n", region_size.x, region_size.y, region_position.x, region_position.y);
|
||||
|
||||
capture = create_monitor_capture(window_str, output_resolution, region_size, region_position, egl, fps, hdr, color_range, record_cursor, color_depth);
|
||||
if(!capture)
|
||||
_exit(1);
|
||||
@@ -4012,6 +4010,9 @@ int main(int argc, char **argv) {
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
capture_metadata.width = video_codec_context->width;
|
||||
capture_metadata.height = video_codec_context->height;
|
||||
|
||||
gsr_color_conversion_params color_conversion_params;
|
||||
memset(&color_conversion_params, 0, sizeof(color_conversion_params));
|
||||
color_conversion_params.color_range = color_range;
|
||||
|
||||
Reference in New Issue
Block a user