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());
68 if (_sdl_surface != _sdl_real_surface) {
89 SDL_SetSurfacePalette(_sdl_real_surface, _sdl_palette);
123 if (_sdl_surface != _sdl_real_surface) {
124 SDL_BlitSurface(_sdl_surface, &r, _sdl_real_surface, &r);
126 SDL_UpdateWindowSurfaceRects(this->
sdl_window, &r, 1);
135 _sdl_real_surface = SDL_GetWindowSurface(this->
sdl_window);
136 if (_sdl_real_surface ==
nullptr)
usererror(
"SDL2: Couldn't get window surface: %s", SDL_GetError());
138 if (!force && w == _sdl_real_surface->w && h == _sdl_real_surface->h)
return false;
141 if (_sdl_rgb_surface !=
nullptr) {
142 SDL_FreeSurface(_sdl_rgb_surface);
143 _sdl_rgb_surface =
nullptr;
147 _sdl_rgb_surface = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
148 if (_sdl_rgb_surface ==
nullptr)
usererror(
"SDL2: Couldn't allocate shadow surface: %s", SDL_GetError());
150 _sdl_surface = _sdl_rgb_surface;
152 _sdl_surface = _sdl_real_surface;
162 _screen.width = _sdl_surface->w;
163 _screen.height = _sdl_surface->h;
164 _screen.pitch = _sdl_surface->pitch / (bpp / 8);
174 return _sdl_surface->pixels;