diff options
author | TechGeekNZ <git@tech.geek.nz> | 2020-06-04 18:23:57 +1200 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2020-06-04 09:05:21 +0100 |
commit | cdd2892c49f0fa7b6a197a463cfa84ba0edcb20d (patch) | |
tree | d8b76fe7aa7f6b705f71780366ebb289566076d3 /src/video | |
parent | 1507902d0083b4983d59efdd3859dde0a9b19fa3 (diff) | |
download | openttd-cdd2892c49f0fa7b6a197a463cfa84ba0edcb20d.tar.xz |
Codechange: Realign SDL driver with SDL2 driver to ease maintenance and emphasise differences.
Diffstat (limited to 'src/video')
-rw-r--r-- | src/video/sdl2_v.cpp | 4 | ||||
-rw-r--r-- | src/video/sdl_v.cpp | 29 |
2 files changed, 17 insertions, 16 deletions
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 0442a0e87..0dff1af4c 100644 --- 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 index fba6166c9..98777a87d 100644 --- 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 = false) 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 = false) 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 = false) * 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(uint w, uint h) 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(uint w, uint h) _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 StringList &parm) } 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)) { |