From 29fcff95c79237090761bfb7a62983699779e598 Mon Sep 17 00:00:00 2001 From: Michael Martin Date: Sat, 17 Aug 2019 20:56:25 -0700 Subject: [PATCH] Generalize more common elements of graphics backends, isolate backend-specific parts --- sc2/src/libs/graphics/sdl/opengl.c | 9 +++++++-- sc2/src/libs/graphics/sdl/opengl.h | 1 - sc2/src/libs/graphics/sdl/pure.c | 10 ++++++++++ sc2/src/libs/graphics/sdl/sdl_common.c | 8 +------- sc2/src/libs/graphics/sdl/sdl_common.h | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/sc2/src/libs/graphics/sdl/opengl.c b/sc2/src/libs/graphics/sdl/opengl.c index 686326407..59728c8f1 100644 --- a/sc2/src/libs/graphics/sdl/opengl.c +++ b/sc2/src/libs/graphics/sdl/opengl.c @@ -52,6 +52,7 @@ static BOOLEAN first_init = TRUE; static void TFB_GL_Preprocess (int force_full_redraw, int transition_amount, int fade_amount); static void TFB_GL_Postprocess (void); +static void TFB_GL_UploadTransitionScreen (void); static void TFB_GL_Scaled_ScreenLayer (SCREEN screen, Uint8 a, SDL_Rect *rect); static void TFB_GL_Unscaled_ScreenLayer (SCREEN screen, Uint8 a, SDL_Rect *rect); static void TFB_GL_ColorLayer (Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_Rect *rect); @@ -59,12 +60,14 @@ static void TFB_GL_ColorLayer (Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_Rect *rec static TFB_GRAPHICS_BACKEND opengl_scaled_backend = { TFB_GL_Preprocess, TFB_GL_Postprocess, + TFB_GL_UploadTransitionScreen, TFB_GL_Scaled_ScreenLayer, TFB_GL_ColorLayer }; static TFB_GRAPHICS_BACKEND opengl_unscaled_backend = { TFB_GL_Preprocess, TFB_GL_Postprocess, + TFB_GL_UploadTransitionScreen, TFB_GL_Unscaled_ScreenLayer, TFB_GL_ColorLayer }; @@ -96,6 +99,7 @@ ReInit_Screen (SDL_Surface **screen, SDL_Surface *template, int w, int h) static int AttemptColorDepth (int flags, int width, int height, int bpp) { + SDL_Surface *SDL_Video; int videomode_flags; ScreenColorDepth = bpp; ScreenWidthActual = width; @@ -298,7 +302,8 @@ TFB_GL_InitGraphics (int driver, int flags, int width, int height) return 0; } -void TFB_GL_UploadTransitionScreen (void) +static void +TFB_GL_UploadTransitionScreen (void) { GL_Screens[TFB_SCREEN_TRANSITION].updated.x = 0; GL_Screens[TFB_SCREEN_TRANSITION].updated.y = 0; @@ -307,7 +312,7 @@ void TFB_GL_UploadTransitionScreen (void) GL_Screens[TFB_SCREEN_TRANSITION].dirty = TRUE; } -void +static void TFB_GL_ScanLines (void) { int y; diff --git a/sc2/src/libs/graphics/sdl/opengl.h b/sc2/src/libs/graphics/sdl/opengl.h index 2b57349c7..3b80f3796 100644 --- a/sc2/src/libs/graphics/sdl/opengl.h +++ b/sc2/src/libs/graphics/sdl/opengl.h @@ -23,7 +23,6 @@ int TFB_GL_InitGraphics (int driver, int flags, int width, int height); int TFB_GL_ConfigureVideo (int driver, int flags, int width, int height, int togglefullscreen); -void TFB_GL_UploadTransitionScreen (void); #ifdef HAVE_OPENGL #ifdef WIN32 diff --git a/sc2/src/libs/graphics/sdl/pure.c b/sc2/src/libs/graphics/sdl/pure.c index 78fd62483..1421ac9cf 100644 --- a/sc2/src/libs/graphics/sdl/pure.c +++ b/sc2/src/libs/graphics/sdl/pure.c @@ -20,6 +20,7 @@ #include "scalers.h" #include "libs/log.h" +static SDL_Surface *SDL_Video = NULL; static SDL_Surface *fade_color_surface = NULL; static SDL_Surface *fade_temp = NULL; static SDL_Surface *scaled_display = NULL; @@ -32,18 +33,21 @@ static void TFB_Pure_Scaled_Preprocess (int force_full_redraw, int transition_am static void TFB_Pure_Scaled_Postprocess (void); static void TFB_Pure_Unscaled_Preprocess (int force_full_redraw, int transition_amount, int fade_amount); static void TFB_Pure_Unscaled_Postprocess (void); +static void TFB_Pure_UploadTransitionScreen (void); static void TFB_Pure_ScreenLayer (SCREEN screen, Uint8 a, SDL_Rect *rect); static void TFB_Pure_ColorLayer (Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_Rect *rect); static TFB_GRAPHICS_BACKEND pure_scaled_backend = { TFB_Pure_Scaled_Preprocess, TFB_Pure_Scaled_Postprocess, + TFB_Pure_UploadTransitionScreen, TFB_Pure_ScreenLayer, TFB_Pure_ColorLayer }; static TFB_GRAPHICS_BACKEND pure_unscaled_backend = { TFB_Pure_Unscaled_Preprocess, TFB_Pure_Unscaled_Postprocess, + TFB_Pure_UploadTransitionScreen, TFB_Pure_ScreenLayer, TFB_Pure_ColorLayer }; @@ -402,6 +406,12 @@ TFB_Pure_Unscaled_Postprocess (void) updated.w, updated.h); } +static void +TFB_Pure_UploadTransitionScreen (void) +{ + /* This is a no-op in SDL1 Pure mode */ +} + static void TFB_Pure_ScreenLayer (SCREEN screen, Uint8 a, SDL_Rect *rect) { diff --git a/sc2/src/libs/graphics/sdl/sdl_common.c b/sc2/src/libs/graphics/sdl/sdl_common.c index 461a64831..4d19849e1 100644 --- a/sc2/src/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/libs/graphics/sdl/sdl_common.c @@ -35,7 +35,6 @@ #include "libs/vidlib.h" #include SDL_INCLUDE(SDL_thread.h) -SDL_Surface *SDL_Video; SDL_Surface *SDL_Screen; SDL_Surface *TransitionScreen; @@ -584,12 +583,7 @@ TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, void TFB_UploadTransitionScreen (void) { -#ifdef HAVE_OPENGL - if (GraphicsDriver == TFB_GFXDRIVER_SDL_OPENGL) - { - TFB_GL_UploadTransitionScreen (); - } -#endif + graphics_backend->uploadTransitionScreen (); } void diff --git a/sc2/src/libs/graphics/sdl/sdl_common.h b/sc2/src/libs/graphics/sdl/sdl_common.h index 489f946b7..2e1a60c8a 100644 --- a/sc2/src/libs/graphics/sdl/sdl_common.h +++ b/sc2/src/libs/graphics/sdl/sdl_common.h @@ -30,13 +30,13 @@ typedef struct _tfb_graphics_backend { void (*preprocess) (int force_redraw, int transition_amount, int fade_amount); void (*postprocess) (void); + void (*uploadTransitionScreen) (void); void (*screen) (SCREEN screen, Uint8 alpha, SDL_Rect *rect); void (*color) (Uint8 r, Uint8 g, Uint8 b, Uint8 a, SDL_Rect *rect); } TFB_GRAPHICS_BACKEND; extern TFB_GRAPHICS_BACKEND *graphics_backend; -extern SDL_Surface *SDL_Video; extern SDL_Surface *SDL_Screen; extern SDL_Surface *TransitionScreen;