From 13dc05cfd2a7d593c9610ab029cec6cd7cac70c3 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 13 Sep 2021 21:02:15 +0200 Subject: [PATCH] Removed the useless double-buffering in video/video.c, improves performance and reduces RAM usage. --- src/include/86box/video.h | 2 +- src/video/video.c | 14 ++++---------- src/vnc.c | 2 +- src/win/win_opengl.c | 10 ++++++++-- src/win/win_sdl.c | 14 +++++++------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/include/86box/video.h b/src/include/86box/video.h index be7591dc7..479312d1a 100644 --- a/src/include/86box/video.h +++ b/src/include/86box/video.h @@ -84,7 +84,7 @@ typedef rgb_t PALETTE[256]; extern int changeframecount; extern volatile int screenshots; -extern bitmap_t *buffer32, *render_buffer; +extern bitmap_t *buffer32; extern PALETTE cgapal, cgapal_mono[6]; extern uint32_t pal_lookup[256]; diff --git a/src/video/video.c b/src/video/video.c index 008228a00..66323f079 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -74,7 +74,6 @@ volatile int screenshots = 0; bitmap_t *buffer32 = NULL; -bitmap_t *render_buffer = NULL; uint8_t fontdat[2048][8]; /* IBM CGA font */ uint8_t fontdatm[2048][16]; /* IBM MDA font */ uint8_t fontdatw[512][32]; /* Wyse700 font */ @@ -364,7 +363,7 @@ video_take_screenshot(const char *fn, int startx, int starty, int y1, int y2, in for (y = 0; y < h; ++y) { b_rgb[y] = (png_byte *) malloc(png_get_rowbytes(png_ptr, info_ptr)); for (x = 0; x < w; ++x) { - temp = render_buffer->dat[(y * w) + x]; + temp = buffer32->line[starty + y][startx + x]; b_rgb[y][(x) * 3 + 0] = (temp >> 16) & 0xff; b_rgb[y][(x) * 3 + 1] = (temp >> 8) & 0xff; @@ -436,19 +435,16 @@ void blit_thread(void *param) thread_reset_event(blit_data.wake_blit_thread); MTR_BEGIN("video", "blit_thread"); - if (blit_data.y2 > 0) { + if ((video_grayscale || invert_display) && blit_data.y2 > 0) { for (yy = blit_data.y1; yy < blit_data.y2; yy++) { if (((blit_data.y + yy) >= 0) && ((blit_data.y + yy) < buffer32->h)) { - if (video_grayscale || invert_display) - video_transform_copy(&(render_buffer->dat)[yy * blit_data.w], &(buffer32->line[blit_data.y + yy][blit_data.x]), blit_data.w); - else - memcpy(&(render_buffer->dat)[yy * blit_data.w], &(buffer32->line[blit_data.y + yy][blit_data.x]), blit_data.w << 2); + video_transform_copy(&(buffer32->line[blit_data.y + yy][blit_data.x]), &(buffer32->line[blit_data.y + yy][blit_data.x]), blit_data.w); } } } if (screenshots) { - if (render_buffer != NULL) + if (buffer32 != NULL) video_screenshot(blit_data.x, blit_data.y, blit_data.y1, blit_data.y2, blit_data.w, blit_data.h); screenshots--; video_log("screenshot taken, %i left\n", screenshots); @@ -833,7 +829,6 @@ video_init(void) /* Account for overscan. */ buffer32 = create_bitmap(2048 + 64, 2048 + 64); - render_buffer = create_bitmap(2048 + 64, 2048 + 64); for (c = 0; c < 64; c++) { cgapal[c + 64].r = (((c & 4) ? 2 : 0) | ((c & 0x10) ? 1 : 0)) * 21; @@ -902,7 +897,6 @@ video_close(void) free(video_8togs); free(video_6to8); - destroy_bitmap(render_buffer); destroy_bitmap(buffer32); if (fontdatksc5601) { diff --git a/src/vnc.c b/src/vnc.c index 09c00831f..5f687a9f3 100644 --- a/src/vnc.c +++ b/src/vnc.c @@ -176,7 +176,7 @@ vnc_blit(int x, int y, int y1, int y2, int w, int h) p = (uint32_t *)&(((uint32_t *)rfb->frameBuffer)[yy*VNC_MAX_X]); if ((y+yy) >= 0 && (y+yy) < VNC_MAX_Y) - memcpy(p, &(render_buffer->dat[yy * w]), w*4); + memcpy(p, &(buffer32->line[yy]), w*4); } video_blit_complete(); diff --git a/src/win/win_opengl.c b/src/win/win_opengl.c index 9d44fc47e..1d8239af8 100644 --- a/src/win/win_opengl.c +++ b/src/win/win_opengl.c @@ -810,14 +810,20 @@ static void opengl_main(void* param) static void opengl_blit(int x, int y, int y1, int y2, int w, int h) { - if (y1 == y2 || h <= 0 || render_buffer == NULL || thread == NULL || + int yy; + + if (y1 == y2 || h <= 0 || buffer32 == NULL || thread == NULL || atomic_flag_test_and_set(&blit_info[write_pos].in_use)) { video_blit_complete(); return; } - memcpy(blit_info[write_pos].buffer, &(render_buffer->dat)[y1 * w], w * (y2 - y1) * sizeof(uint32_t)); + for (yy = y1; yy < y2; yy++) { + if ((y + yy) >= 0 && (y + yy) < buffer32->h) + memcpy(blit_info[write_pos].buffer + (yy * w * 4), + &(((uint32_t *) buffer32->line[y + yy])[x]), w * 4); + } video_blit_complete(); diff --git a/src/win/win_sdl.c b/src/win/win_sdl.c index 8a748fb2b..c5978501f 100644 --- a/src/win/win_sdl.c +++ b/src/win/win_sdl.c @@ -234,24 +234,24 @@ sdl_blit(int x, int y, int y1, int y2, int w, int h) SDL_Rect r_src; int ret; - if (!sdl_enabled || (y1 == y2) || (h <= 0) || (render_buffer == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) { + if (!sdl_enabled || (y1 == y2) || (h <= 0) || (buffer32 == NULL) || (sdl_render == NULL) || (sdl_tex == NULL)) { video_blit_complete(); return; } SDL_LockMutex(sdl_mutex); - r_src.x = 0; - r_src.y = y1; + r_src.x = x; + r_src.y = y; r_src.w = w; - r_src.h = y2 - y1; - SDL_UpdateTexture(sdl_tex, &r_src, &(render_buffer->dat)[y1 * w], w * 4); + r_src.h = h; + SDL_UpdateTexture(sdl_tex, &r_src, &(buffer32->line[y][x]), (2048 + 64) * 4); video_blit_complete(); SDL_RenderClear(sdl_render); - r_src.x = 0; - r_src.y = 0; + r_src.x = x; + r_src.y = y; r_src.w = w; r_src.h = h;