Changeset - r24744:6381326705ae
[Not reviewed]
master
0 1 0
Patric Stout - 4 years ago 2021-02-11 10:19:05
truebrain@openttd.org
Codechange: [SDL2] Don't use globals if we can do with locals
1 file changed with 4 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/video/sdl2_v.cpp
Show inline comments
 
@@ -49,28 +49,24 @@ static volatile bool _draw_continue;
 
static Palette _local_palette;
 
static SDL_Palette *_sdl_palette;
 

	
 
#ifdef __EMSCRIPTEN__
 
/** Whether we just had a window-enter event. */
 
static bool _cursor_new_in_window = false;
 
#endif
 

	
 
#define MAX_DIRTY_RECTS 100
 
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS];
 
static int _num_dirty_rects;
 

	
 
/* Size of window */
 
static int _window_size_w;
 
static int _window_size_h;
 

	
 
void VideoDriver_SDL::MakeDirty(int left, int top, int width, int height)
 
{
 
	if (_num_dirty_rects < MAX_DIRTY_RECTS) {
 
		_dirty_rects[_num_dirty_rects].x = left;
 
		_dirty_rects[_num_dirty_rects].y = top;
 
		_dirty_rects[_num_dirty_rects].w = width;
 
		_dirty_rects[_num_dirty_rects].h = height;
 
	}
 
	_num_dirty_rects++;
 
}
 

	
 
static void UpdatePalette()
 
@@ -920,43 +916,45 @@ bool VideoDriver_SDL::ChangeResolution(i
 
{
 
	std::unique_lock<std::recursive_mutex> lock;
 
	if (_draw_mutex != nullptr) lock = std::unique_lock<std::recursive_mutex>(*_draw_mutex);
 

	
 
	return CreateMainSurface(w, h, true);
 
}
 

	
 
bool VideoDriver_SDL::ToggleFullscreen(bool fullscreen)
 
{
 
	std::unique_lock<std::recursive_mutex> lock;
 
	if (_draw_mutex != nullptr) lock = std::unique_lock<std::recursive_mutex>(*_draw_mutex);
 

	
 
	int w, h;
 

	
 
	/* Remember current window size */
 
	if (fullscreen) {
 
		SDL_GetWindowSize(_sdl_window, &_window_size_w, &_window_size_h);
 
		SDL_GetWindowSize(_sdl_window, &w, &h);
 

	
 
		/* Find fullscreen window size */
 
		SDL_DisplayMode dm;
 
		if (SDL_GetCurrentDisplayMode(0, &dm) < 0) {
 
			DEBUG(driver, 0, "SDL_GetCurrentDisplayMode() failed: %s", SDL_GetError());
 
		} else {
 
			SDL_SetWindowSize(_sdl_window, dm.w, dm.h);
 
		}
 
	}
 

	
 
	DEBUG(driver, 1, "SDL2: Setting %s", fullscreen ? "fullscreen" : "windowed");
 
	int ret = SDL_SetWindowFullscreen(_sdl_window, fullscreen ? SDL_WINDOW_FULLSCREEN : 0);
 
	if (ret == 0) {
 
		/* Switching resolution succeeded, set fullscreen value of window. */
 
		_fullscreen = fullscreen;
 
		if (!fullscreen) SDL_SetWindowSize(_sdl_window, _window_size_w, _window_size_h);
 
		if (!fullscreen) SDL_SetWindowSize(_sdl_window, w, h);
 
	} else {
 
		DEBUG(driver, 0, "SDL_SetWindowFullscreen() failed: %s", SDL_GetError());
 
	}
 

	
 
	return ret == 0;
 
}
 

	
 
bool VideoDriver_SDL::AfterBlitterChange()
 
{
 
	assert(BlitterFactory::GetCurrentBlitter()->GetScreenDepth() != 0);
 
	int w, h;
 
	SDL_GetWindowSize(_sdl_window, &w, &h);
0 comments (0 inline, 0 general)