10 #include "../stdafx.h"
11 #include "../openttd.h"
12 #include "../gfx_func.h"
14 #include "../blitter/factory.hpp"
15 #include "../network/network.h"
16 #include "../thread.h"
17 #include "../progress.h"
18 #include "../core/random_func.hpp"
19 #include "../core/math_func.hpp"
20 #include "../core/mem_func.hpp"
21 #include "../core/geometry_func.hpp"
22 #include "../fileio_func.h"
23 #include "../framerate_type.h"
24 #include "../window_func.h"
28 #include <condition_variable>
30 # include <emscripten.h>
31 # include <emscripten/html5.h>
34 #include "../safeguards.h"
38 static SDL_Surface *_sdl_surface;
39 static SDL_Surface *_sdl_rgb_surface;
40 static SDL_Surface *_sdl_real_surface;
41 static SDL_Palette *_sdl_palette;
43 void VideoDriver_SDL_Default::UpdatePalette()
55 SDL_SetSurfacePalette(_sdl_surface, _sdl_palette);
58 void VideoDriver_SDL_Default::MakePalette()
60 if (_sdl_palette ==
nullptr) {
61 _sdl_palette = SDL_AllocPalette(256);
62 if (_sdl_palette ==
nullptr)
usererror(
"SDL2: Couldn't allocate palette: %s", SDL_GetError());
70 if (_sdl_surface != _sdl_real_surface) {
91 SDL_SetSurfacePalette(_sdl_real_surface, _sdl_palette);
125 if (_sdl_surface != _sdl_real_surface) {
126 SDL_BlitSurface(_sdl_surface, &r, _sdl_real_surface, &r);
128 SDL_UpdateWindowSurfaceRects(this->
sdl_window, &r, 1);
137 _sdl_real_surface = SDL_GetWindowSurface(this->
sdl_window);
138 if (_sdl_real_surface ==
nullptr)
usererror(
"SDL2: Couldn't get window surface: %s", SDL_GetError());
140 if (!force && w == _sdl_real_surface->w && h == _sdl_real_surface->h)
return false;
143 if (_sdl_rgb_surface !=
nullptr) {
144 SDL_FreeSurface(_sdl_rgb_surface);
145 _sdl_rgb_surface =
nullptr;
149 _sdl_rgb_surface = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
150 if (_sdl_rgb_surface ==
nullptr)
usererror(
"SDL2: Couldn't allocate shadow surface: %s", SDL_GetError());
152 _sdl_surface = _sdl_rgb_surface;
154 _sdl_surface = _sdl_real_surface;
164 _screen.width = _sdl_surface->w;
165 _screen.height = _sdl_surface->h;
166 _screen.pitch = _sdl_surface->pitch / (bpp / 8);
176 return _sdl_surface->pixels;