OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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);
110 bool need_buf = _screen.dst_ptr ==
nullptr;
115 _screen.dst_ptr =
nullptr;
131 if (_sdl_surface != _sdl_real_surface) {
132 SDL_BlitSurface(_sdl_surface, &r, _sdl_real_surface, &r);
134 SDL_UpdateWindowSurfaceRects(this->
sdl_window, &r, 1);
159 _sdl_real_surface = SDL_GetWindowSurface(this->
sdl_window);
160 if (_sdl_real_surface ==
nullptr)
usererror(
"SDL2: Couldn't get window surface: %s", SDL_GetError());
162 if (!force && w == _sdl_real_surface->w && h == _sdl_real_surface->h)
return false;
165 if (_sdl_rgb_surface !=
nullptr) {
166 SDL_FreeSurface(_sdl_rgb_surface);
167 _sdl_rgb_surface =
nullptr;
171 _sdl_rgb_surface = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
172 if (_sdl_rgb_surface ==
nullptr)
usererror(
"SDL2: Couldn't allocate shadow surface: %s", SDL_GetError());
174 _sdl_surface = _sdl_rgb_surface;
176 _sdl_surface = _sdl_real_surface;
186 _screen.width = _sdl_surface->w;
187 _screen.height = _sdl_surface->h;
188 _screen.pitch = _sdl_surface->pitch / (bpp / 8);
198 return _sdl_surface->pixels;
int first_dirty
The first dirty element.
Factory for the SDL video driver.
void CDECL usererror(const char *s,...)
Error handling for fatal user errors.
@ PFE_VIDEO
Speed of painting drawn video buffer.
virtual Blitter::PaletteAnimation UsePaletteAnimation()=0
Check if the blitter uses palette animation at all.
std::mutex lock
synchronization for playback status fields
How all blitters should look like.
virtual uint8 GetScreenDepth()=0
Get the screen depth this blitter works for.
void ReleaseVideoPointer() override
Hand video buffer back to the painting backend.
void PaintThread() override
Thread function for threaded drawing.
bool AllocateBackingStore(int w, int h, bool force=false) override
(Re-)create the backing store.
Colour palette[256]
Current palette. Entry 0 has to be always fully transparent!
std::condition_variable_any * draw_signal
Signal to draw the next frame.
Palette local_palette
Copy of _cur_palette.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
int count_dirty
The number of dirty elements.
std::recursive_mutex * draw_mutex
Mutex to keep the access to the shared memory controlled.
static bool IsEmptyRect(const Rect &r)
Check if a rectangle is empty.
@ PALETTE_ANIMATION_VIDEO_BACKEND
Palette animation should be done by video backend (8bpp only!)
Rect dirty_rect
Rectangle encompassing the dirty area of the video buffer.
@ PALETTE_ANIMATION_NONE
No palette animation.
volatile bool draw_continue
Should we keep continue drawing?
Palette _cur_palette
Current palette.
void Paint() override
Paint the window.
void UpdatePalette(const Colour *pal, uint first, uint length)
Update the stored palette.
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...
@ PALETTE_ANIMATION_BLITTER
The blitter takes care of the palette animation.
void * GetVideoPointer() override
Get a pointer to the video buffer.
struct SDL_Window * sdl_window
Main SDL window.