From 394768f5acf66ad76e62106534ac9870c3b31ec7 Mon Sep 17 00:00:00 2001 From: OBattler Date: Wed, 29 Dec 2021 20:53:32 +0100 Subject: [PATCH] In default mode, the SDL2 renderers now use UpdateTexture(). --- src/include/86box/plat.h | 1 + src/win/win.c | 8 ++++++++ src/win/win_sdl.c | 40 +++++++++++++++++++++++++++++++++++++++- src/win/win_ui.c | 2 ++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 78795d757..3a605fe6b 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -126,6 +126,7 @@ extern void plat_vidsize(int x, int y); extern void plat_setfullscreen(int on); extern void plat_resize(int x, int y); extern void plat_vidapi_enable(int enabled); +extern void plat_vidapi_reload(void); extern void plat_vid_reload_options(void); extern uint32_t plat_language_code(char* langcode); extern void plat_language_code_r(uint32_t lcid, char* outbuf, int len); diff --git a/src/win/win.c b/src/win/win.c index 7f35f6d0b..27386b5b7 100644 --- a/src/win/win.c +++ b/src/win/win.c @@ -1194,6 +1194,14 @@ plat_vid_reload_options(void) vid_apis[vid_api].reload(); } + +void +plat_vidapi_reload(void) +{ + vid_apis[vid_api].reload(); +} + + /* Sets up the program language before initialization. */ uint32_t plat_language_code(char* langcode) diff --git a/src/win/win_sdl.c b/src/win/win_sdl.c index 3a898f43c..11315c3b5 100644 --- a/src/win/win_sdl.c +++ b/src/win/win_sdl.c @@ -230,6 +230,42 @@ sdl_stretch(int *w, int *h, int *x, int *y) static void sdl_blit(int x, int y, int w, int h) +{ + SDL_Rect r_src; + int ret; + + 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(); + return; + } + + SDL_LockMutex(sdl_mutex); + + r_src.x = x; + r_src.y = y; + r_src.w = w; + r_src.h = h; + SDL_UpdateTexture(sdl_tex, &r_src, &(buffer32->line[y][x]), 2048 * sizeof(uint32_t)); + video_blit_complete(); + + SDL_RenderClear(sdl_render); + + r_src.x = x; + r_src.y = y; + r_src.w = w; + r_src.h = h; + + ret = SDL_RenderCopy(sdl_render, sdl_tex, &r_src, 0); + if (ret) + sdl_log("SDL: unable to copy texture to renderer (%s)\n", sdl_GetError()); + + SDL_RenderPresent(sdl_render); + SDL_UnlockMutex(sdl_mutex); +} + + +static void +sdl_blit_ex(int x, int y, int w, int h) { SDL_Rect r_src; void *pixeldata; @@ -478,7 +514,7 @@ sdl_init_common(int flags) atexit(sdl_close); /* Register our renderer! */ - video_setblit(sdl_blit); + video_setblit((video_grayscale || invert_display) ? sdl_blit_ex : sdl_blit); sdl_enabled = 1; sdl_mutex = SDL_CreateMutex(); @@ -582,4 +618,6 @@ sdl_reload(void) SDL_UnlockMutex(sdl_mutex); } + + video_setblit((video_grayscale || invert_display) ? sdl_blit_ex : sdl_blit); } diff --git a/src/win/win_ui.c b/src/win/win_ui.c index f2d00ef1c..40f9068b0 100644 --- a/src/win/win_ui.c +++ b/src/win/win_ui.c @@ -805,6 +805,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case IDM_VID_INVERT: video_toggle_option(hmenu, &invert_display, IDM_VID_INVERT); video_copy = (video_grayscale || invert_display) ? video_transform_copy : memcpy; + plat_vidapi_reload(); break; case IDM_VID_OVERSCAN: @@ -838,6 +839,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) CheckMenuItem(hmenu, IDM_VID_GRAY_RGB+video_grayscale, MF_UNCHECKED); video_grayscale = LOWORD(wParam) - IDM_VID_GRAY_RGB; video_copy = (video_grayscale || invert_display) ? video_transform_copy : memcpy; + plat_vidapi_reload(); CheckMenuItem(hmenu, IDM_VID_GRAY_RGB+video_grayscale, MF_CHECKED); device_force_redraw(); config_save();