11#include "../openttd.h"
12#include "../error_func.h"
13#include "../gfx_func.h"
15#include "../blitter/factory.hpp"
16#include "../network/network.h"
18#include "../progress.h"
19#include "../core/geometry_func.hpp"
20#include "../fileio_func.h"
21#include "../framerate_type.h"
22#include "../window_func.h"
26#include <condition_variable>
28# include <emscripten.h>
29# include <emscripten/html5.h>
32#include "../safeguards.h"
36static SDL_Surface *_sdl_surface;
37static SDL_Surface *_sdl_rgb_surface;
38static SDL_Surface *_sdl_real_surface;
39static SDL_Palette *_sdl_palette;
41void VideoDriver_SDL_Default::UpdatePalette()
53 SDL_SetSurfacePalette(_sdl_surface, _sdl_palette);
56void VideoDriver_SDL_Default::MakePalette()
58 if (_sdl_palette ==
nullptr) {
59 _sdl_palette = SDL_AllocPalette(256);
60 if (_sdl_palette ==
nullptr) UserError(
"SDL2: Couldn't allocate palette: {}", SDL_GetError());
64 this->UpdatePalette();
66 if (_sdl_surface != _sdl_real_surface) {
87 SDL_SetSurfacePalette(_sdl_real_surface, _sdl_palette);
102 this->UpdatePalette();
121 if (_sdl_surface != _sdl_real_surface) {
122 SDL_BlitSurface(_sdl_surface, &r, _sdl_real_surface, &r);
124 SDL_UpdateWindowSurfaceRects(this->
sdl_window, &r, 1);
133 _sdl_real_surface = SDL_GetWindowSurface(this->
sdl_window);
134 if (_sdl_real_surface ==
nullptr) UserError(
"SDL2: Couldn't get window surface: {}", SDL_GetError());
136 if (!force && w == _sdl_real_surface->w && h == _sdl_real_surface->h)
return false;
139 if (_sdl_rgb_surface !=
nullptr) {
140 SDL_FreeSurface(_sdl_rgb_surface);
141 _sdl_rgb_surface =
nullptr;
145 _sdl_rgb_surface = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
146 if (_sdl_rgb_surface ==
nullptr) UserError(
"SDL2: Couldn't allocate shadow surface: {}", SDL_GetError());
148 _sdl_surface = _sdl_rgb_surface;
150 _sdl_surface = _sdl_real_surface;
160 _screen.width = _sdl_surface->w;
161 _screen.height = _sdl_surface->h;
162 _screen.pitch = _sdl_surface->pitch / (bpp / 8);
172 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.
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...
@ None
No palette animation.
@ Blitter
The blitter takes care of the palette animation.
@ VideoBackend
Palette animation should be done by video backend (8bpp only!)
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!