From 69f572395b1be3ae26cb3c6b2fc62e95689a55ce Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 18 Jan 2022 01:55:05 +0100 Subject: [PATCH 1/2] Improved the performance of sdl_blit_ex(), closes #1995. --- src/win/win_sdl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/win/win_sdl.c b/src/win/win_sdl.c index 4fc735a1c..cf5afb809 100644 --- a/src/win/win_sdl.c +++ b/src/win/win_sdl.c @@ -274,6 +274,7 @@ sdl_blit_ex(int x, int y, int w, int h) SDL_Rect r_src; void *pixeldata; int pitch, ret; + int row; if (!sdl_enabled || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) { video_blit_complete(); @@ -284,7 +285,8 @@ sdl_blit_ex(int x, int y, int w, int h) SDL_LockTexture(sdl_tex, 0, &pixeldata, &pitch); - video_copy(pixeldata, &(buffer32->line[y][x]), h * 2048 * sizeof(uint32_t)); + for (row = 0; row < h; ++row) + video_copy(&(((uint8_t *) pixeldata)[row * 2048 * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (screenshots) video_screenshot((uint32_t *) pixeldata, 0, 0, 2048); From f87010c484da15e2e48b82f018a7501b3956c32f Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 18 Jan 2022 13:13:22 +0100 Subject: [PATCH 2/2] Applied the fix to the OpenGL Core renderer as well. --- src/win/win_opengl.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/win/win_opengl.c b/src/win/win_opengl.c index 99843cd9f..9bb13561d 100644 --- a/src/win/win_opengl.c +++ b/src/win/win_opengl.c @@ -872,6 +872,8 @@ static void opengl_main(void* param) static void opengl_blit(int x, int y, int w, int h) { + int row; + if ((x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || (thread == NULL) || atomic_flag_test_and_set(&blit_info[write_pos].in_use)) { @@ -879,7 +881,8 @@ static void opengl_blit(int x, int y, int w, int h) return; } - video_copy(blit_info[write_pos].buffer, &(buffer32->line[y][x]), h * ROW_LENGTH * sizeof(uint32_t)); + for (row = 0; row < h; ++row) + video_copy(&(((uint8_t *) blit_info[write_pos].buffer)[row * ROW_LENGTH * sizeof(uint32_t)]), &(buffer32->line[y + row][x]), w * sizeof(uint32_t)); if (screenshots) video_screenshot(blit_info[write_pos].buffer, 0, 0, ROW_LENGTH);