# HG changeset patch # User TechGeekNZ # Date 2020-06-04 06:23:57 # Node ID 6391ca82e5606df7bbb35c86631329928949a074 # Parent 66942fe231b05c19e78085014a3f9015aee68bbc Codechange: Realign SDL driver with SDL2 driver to ease maintenance and emphasise differences. diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -170,9 +170,7 @@ static void DrawSurfaceToScreen() } else { if (_sdl_surface != _sdl_realscreen) { for (int i = 0; i < n; i++) { - SDL_BlitSurface( - _sdl_surface, &_dirty_rects[i], - _sdl_realscreen, &_dirty_rects[i]); + SDL_BlitSurface(_sdl_surface, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); } } diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -31,7 +31,7 @@ static FVideoDriver_SDL iFVideoDriver_SDL; -static SDL_Surface *_sdl_screen; +static SDL_Surface *_sdl_surface; static SDL_Surface *_sdl_realscreen; static bool _all_modes; @@ -73,11 +73,11 @@ static void UpdatePalette(bool init = fa pal[i].unused = 0; } - SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty); + SDL_SetColors(_sdl_surface, pal, _local_palette.first_dirty, _local_palette.count_dirty); - if (_sdl_screen != _sdl_realscreen && init) { + if (_sdl_surface != _sdl_realscreen && init) { /* When using a shadow surface, also set our palette on the real screen. This lets SDL - * allocate as much colors (or approximations) as + * allocate as many colors (or approximations) as * possible, instead of using only the default SDL * palette. This allows us to get more colors exactly * right and might allow using better approximations for @@ -99,7 +99,7 @@ static void UpdatePalette(bool init = fa SDL_SetColors(_sdl_realscreen, pal, _local_palette.first_dirty, _local_palette.count_dirty); } - if (_sdl_screen != _sdl_realscreen && !init) { + if (_sdl_surface != _sdl_realscreen && !init) { /* We're not using real hardware palette, but are letting SDL * approximate the palette during shadow -> screen copy. To * change the palette, we need to recopy the entire screen. @@ -110,7 +110,7 @@ static void UpdatePalette(bool init = fa * best mapping of shadow palette colors to real palette * colors from scratch. */ - SDL_BlitSurface(_sdl_screen, nullptr, _sdl_realscreen, nullptr); + SDL_BlitSurface(_sdl_surface, nullptr, _sdl_realscreen, nullptr); SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); } } @@ -155,17 +155,20 @@ static void DrawSurfaceToScreen() if (n == 0) return; _num_dirty_rects = 0; + if (n > MAX_DIRTY_RECTS) { - if (_sdl_screen != _sdl_realscreen) { - SDL_BlitSurface(_sdl_screen, nullptr, _sdl_realscreen, nullptr); + if (_sdl_surface != _sdl_realscreen) { + SDL_BlitSurface(_sdl_surface, nullptr, _sdl_realscreen, nullptr); } + SDL_UpdateRect(_sdl_realscreen, 0, 0, 0, 0); } else { - if (_sdl_screen != _sdl_realscreen) { + if (_sdl_surface != _sdl_realscreen) { for (int i = 0; i < n; i++) { - SDL_BlitSurface(_sdl_screen, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); + SDL_BlitSurface(_sdl_surface, &_dirty_rects[i], _sdl_realscreen, &_dirty_rects[i]); } } + SDL_UpdateRects(_sdl_realscreen, n, _dirty_rects); } } @@ -308,7 +311,7 @@ bool VideoDriver_SDL::CreateMainSurface( if (want_hwpalette) DEBUG(driver, 1, "SDL: requesting hardware palette"); /* Free any previously allocated shadow surface */ - if (_sdl_screen != nullptr && _sdl_screen != _sdl_realscreen) SDL_FreeSurface(_sdl_screen); + if (_sdl_surface != nullptr && _sdl_surface != _sdl_realscreen) SDL_FreeSurface(_sdl_surface); if (_sdl_realscreen != nullptr) { if (_requested_hwpalette != want_hwpalette) { @@ -375,7 +378,7 @@ bool VideoDriver_SDL::CreateMainSurface( _screen.height = newscreen->h; _screen.pitch = newscreen->pitch / (bpp / 8); _screen.dst_ptr = newscreen->pixels; - _sdl_screen = newscreen; + _sdl_surface = newscreen; /* When in full screen, we will always have the mouse cursor * within the window, even though SDL does not give us the @@ -610,7 +613,7 @@ const char *VideoDriver_SDL::Start(const } else if (SDL_WasInit(SDL_INIT_VIDEO) == 0) { ret_code = SDL_InitSubSystem(SDL_INIT_VIDEO); } - if (ret_code == -1) return SDL_GetError(); + if (ret_code < 0) return SDL_GetError(); GetVideoModes(); if (!CreateMainSurface(_cur_resolution.width, _cur_resolution.height)) {