Changeset - r24913:8df991aa7a76
[Not reviewed]
master
0 2 0
Patric Stout - 4 years ago 2021-02-11 08:34:10
truebrain@openttd.org
Codechange: [SDL2] Move SDLSurface code to its own function

This increases readability, and allow future subdrivers to not
use SDLSurface to draw.
2 files changed with 23 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/video/sdl2_v.cpp
Show inline comments
 
@@ -309,19 +309,33 @@ bool VideoDriver_SDL::CreateMainWindow(u
 

	
 
bool VideoDriver_SDL::CreateMainSurface(uint w, uint h, bool resize)
 
{
 
	int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
 

	
 
	GetAvailableVideoMode(&w, &h);
 
	DEBUG(driver, 1, "SDL2: using mode %ux%ux%d", w, h, bpp);
 
	DEBUG(driver, 1, "SDL2: using mode %ux%u", w, h);
 

	
 
	if (!this->CreateMainWindow(w, h)) return false;
 
	if (resize) SDL_SetWindowSize(_sdl_window, w, h);
 

	
 
	if (!this->AllocateBackingStore(w, h, true)) return false;
 

	
 
	/* When in full screen, we will always have the mouse cursor
 
	 * within the window, even though SDL does not give us the
 
	 * appropriate event to know this. */
 
	if (_fullscreen) _cursor.in_window = true;
 

	
 
	BlitterFactory::GetCurrentBlitter()->PostResize();
 

	
 
	GameSizeChanged();
 
	return true;
 
}
 

	
 
bool VideoDriver_SDL::AllocateBackingStore(int w, int h, bool force)
 
{
 
	int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
 

	
 
	_sdl_real_surface = SDL_GetWindowSurface(_sdl_window);
 
	if (_sdl_real_surface == nullptr) {
 
		DEBUG(driver, 0, "SDL2: Couldn't get window surface: %s", SDL_GetError());
 
		return false;
 
	}
 
	if (_sdl_real_surface == nullptr) usererror("SDL2: Couldn't get window surface: %s", SDL_GetError());
 

	
 
	if (!force && w == _sdl_real_surface->w && h == _sdl_real_surface->h) return false;
 

	
 
	/* Free any previously allocated rgb surface. */
 
	if (_sdl_rgb_surface != nullptr) {
 
@@ -331,11 +345,7 @@ bool VideoDriver_SDL::CreateMainSurface(
 

	
 
	if (bpp == 8) {
 
		_sdl_rgb_surface = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
 

	
 
		if (_sdl_rgb_surface == nullptr) {
 
			DEBUG(driver, 0, "SDL2: Couldn't allocate shadow surface: %s", SDL_GetError());
 
			return false;
 
		}
 
		if (_sdl_rgb_surface == nullptr) usererror("SDL2: Couldn't allocate shadow surface: %s", SDL_GetError());
 

	
 
		_sdl_surface = _sdl_rgb_surface;
 
	} else {
 
@@ -356,14 +366,6 @@ bool VideoDriver_SDL::CreateMainSurface(
 

	
 
	MakePalette();
 

	
 
	/* When in full screen, we will always have the mouse cursor
 
	 * within the window, even though SDL does not give us the
 
	 * appropriate event to know this. */
 
	if (_fullscreen) _cursor.in_window = true;
 

	
 
	BlitterFactory::GetCurrentBlitter()->PostResize();
 

	
 
	GameSizeChanged();
 
	return true;
 
}
 

	
src/video/sdl2_v.h
Show inline comments
 
@@ -57,6 +57,7 @@ private:
 
	bool CreateMainSurface(uint w, uint h, bool resize);
 
	bool CreateMainWindow(uint w, uint h);
 
	const char *Initialize();
 
	bool AllocateBackingStore(int w, int h, bool force = false);
 

	
 
#ifdef __EMSCRIPTEN__
 
	/* Convert a constant pointer back to a non-constant pointer to a member function. */
0 comments (0 inline, 0 general)