10 #include "../stdafx.h"
11 #include "../openttd.h"
12 #include "../error_func.h"
13 #include "../gfx_func.h"
15 #include "../blitter/factory.hpp"
16 #include "../network/network.h"
17 #include "../thread.h"
18 #include "../progress.h"
19 #include "../core/random_func.hpp"
20 #include "../core/math_func.hpp"
21 #include "../core/mem_func.hpp"
22 #include "../core/geometry_func.hpp"
23 #include "../fileio_func.h"
24 #include "../framerate_type.h"
25 #include "../window_func.h"
29 #include <condition_variable>
31 # include <emscripten.h>
32 # include <emscripten/html5.h>
35 #include "../safeguards.h"
39 static SDL_Surface *_sdl_surface;
40 static SDL_Surface *_sdl_rgb_surface;
41 static SDL_Surface *_sdl_real_surface;
42 static SDL_Palette *_sdl_palette;
44 void VideoDriver_SDL_Default::UpdatePalette()
56 SDL_SetSurfacePalette(_sdl_surface, _sdl_palette);
59 void VideoDriver_SDL_Default::MakePalette()
61 if (_sdl_palette ==
nullptr) {
62 _sdl_palette = SDL_AllocPalette(256);
63 if (_sdl_palette ==
nullptr) UserError(
"SDL2: Couldn't allocate palette: {}", SDL_GetError());
67 this->UpdatePalette();
69 if (_sdl_surface != _sdl_real_surface) {
90 SDL_SetSurfacePalette(_sdl_real_surface, _sdl_palette);
105 this->UpdatePalette();
124 if (_sdl_surface != _sdl_real_surface) {
125 SDL_BlitSurface(_sdl_surface, &r, _sdl_real_surface, &r);
127 SDL_UpdateWindowSurfaceRects(this->
sdl_window, &r, 1);
136 _sdl_real_surface = SDL_GetWindowSurface(this->
sdl_window);
137 if (_sdl_real_surface ==
nullptr) UserError(
"SDL2: Couldn't get window surface: {}", SDL_GetError());
139 if (!force && w == _sdl_real_surface->w && h == _sdl_real_surface->h)
return false;
142 if (_sdl_rgb_surface !=
nullptr) {
143 SDL_FreeSurface(_sdl_rgb_surface);
144 _sdl_rgb_surface =
nullptr;
148 _sdl_rgb_surface = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
149 if (_sdl_rgb_surface ==
nullptr) UserError(
"SDL2: Couldn't allocate shadow surface: {}", SDL_GetError());
151 _sdl_surface = _sdl_rgb_surface;
153 _sdl_surface = _sdl_real_surface;
163 _screen.width = _sdl_surface->w;
164 _screen.height = _sdl_surface->h;
165 _screen.pitch = _sdl_surface->pitch / (bpp / 8);
175 return _sdl_surface->pixels;
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
How all blitters should look like.
virtual uint8_t GetScreenDepth()=0
Get the screen depth this blitter works for.
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
@ PALETTE_ANIMATION_NONE
No palette animation.
@ PALETTE_ANIMATION_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
@ PALETTE_ANIMATION_BLITTER
The blitter takes care of the palette animation.
virtual void PaletteAnimate(const Palette &palette)=0
Called when the 8bpp palette is changed; you should redraw all pixels on the screen that are equal to...
Factory for the SDL video driver.
Palette local_palette
Current palette to use for drawing.
Rect dirty_rect
Rectangle encompassing the dirty area of the video buffer.
struct SDL_Window * sdl_window
Main SDL window.
bool AllocateBackingStore(int w, int h, bool force=false) override
(Re-)create the backing store.
void * GetVideoPointer() override
Get a pointer to the video buffer.
void Paint() override
Paint the window.
@ PFE_VIDEO
Speed of painting drawn video buffer.
bool IsEmptyRect(const Rect &r)
Check if a rectangle is empty.
bool CopyPalette(Palette &local_palette, bool force_copy)
Copy the current palette if the palette was updated.
Default backend of the SDL2 video driver.
int first_dirty
The first dirty element.
int count_dirty
The number of dirty elements.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!