OpenTTD Source  1.11.0-beta2
sdl_v.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef VIDEO_SDL_H
11 #define VIDEO_SDL_H
12 
13 #include "video_driver.hpp"
14 
16 class VideoDriver_SDL : public VideoDriver {
17 public:
18  const char *Start(const StringList &param) override;
19 
20  void Stop() override;
21 
22  void MakeDirty(int left, int top, int width, int height) override;
23 
24  void MainLoop() override;
25 
26  bool ChangeResolution(int w, int h) override;
27 
28  bool ToggleFullscreen(bool fullscreen) override;
29 
30  bool AfterBlitterChange() override;
31 
32  void AcquireBlitterLock() override;
33 
34  void ReleaseBlitterLock() override;
35 
36  bool ClaimMousePointer() override;
37 
38  const char *GetName() const override { return "sdl"; }
39 
40 protected:
41  void InputLoop() override;
42  bool LockVideoBuffer() override;
43  void UnlockVideoBuffer() override;
44  void Paint() override;
45  void PaintThread() override;
46  void CheckPaletteAnim() override;
47  bool PollEvent() override;
48 
49 private:
50  std::unique_lock<std::recursive_mutex> draw_lock;
51 
52  bool CreateMainSurface(uint w, uint h);
53  void SetupKeyboard();
54 
55  static void PaintThreadThunk(VideoDriver_SDL *drv);
56 };
57 
60 public:
61  FVideoDriver_SDL() : DriverFactoryBase(Driver::DT_VIDEO, 5, "sdl", "SDL Video Driver") {}
62  Driver *CreateInstance() const override { return new VideoDriver_SDL(); }
63 };
64 
65 #endif /* VIDEO_SDL_H */
VideoDriver_SDL::UnlockVideoBuffer
void UnlockVideoBuffer() override
Unlock a previously locked video buffer.
Definition: sdl_v.cpp:790
VideoDriver_SDL::LockVideoBuffer
bool LockVideoBuffer() override
Make sure the video buffer is ready for drawing.
Definition: sdl_v.cpp:784
VideoDriver_SDL
The SDL video driver.
Definition: sdl_v.h:16
VideoDriver_SDL::Start
const char * Start(const StringList &param) override
Start this driver.
Definition: sdl_v.cpp:604
VideoDriver
The base of all video drivers.
Definition: video_driver.hpp:28
VideoDriver_SDL::GetName
const char * GetName() const override
Get the name of this driver.
Definition: sdl_v.h:38
DriverFactoryBase::DriverFactoryBase
DriverFactoryBase(Driver::Type type, int priority, const char *name, const char *description)
Construct a new DriverFactory.
Definition: driver.cpp:206
VideoDriver_SDL::ReleaseBlitterLock
void ReleaseBlitterLock() override
Release any lock(s) required to be held when changing blitters.
Definition: sdl_v.cpp:779
VideoDriver_SDL::ToggleFullscreen
bool ToggleFullscreen(bool fullscreen) override
Change the full screen setting.
Definition: sdl_v.cpp:752
VideoDriver_SDL::MainLoop
void MainLoop() override
Perform the actual drawing.
Definition: sdl_v.cpp:681
VideoDriver_SDL::AcquireBlitterLock
void AcquireBlitterLock() override
Acquire any lock(s) required to be held when changing blitters.
Definition: sdl_v.cpp:774
VideoDriver_SDL::MakeDirty
void MakeDirty(int left, int top, int width, int height) override
Mark a particular area dirty.
Definition: sdl_v.cpp:53
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:58
VideoDriver_SDL::ChangeResolution
bool ChangeResolution(int w, int h) override
Change the resolution of the window.
Definition: sdl_v.cpp:744
VideoDriver_SDL::PollEvent
bool PollEvent() override
Process a single system event.
Definition: sdl_v.cpp:509
FVideoDriver_SDL
Factory for the SDL video driver.
Definition: sdl_v.h:59
VideoDriver_SDL::AfterBlitterChange
bool AfterBlitterChange() override
Callback invoked after the blitter was changed.
Definition: sdl_v.cpp:769
VideoDriver_SDL::CheckPaletteAnim
void CheckPaletteAnim() override
Process any pending palette animation.
Definition: sdl_v.cpp:125
video_driver.hpp
Driver::DT_VIDEO
@ DT_VIDEO
A video driver.
Definition: driver.h:44
VideoDriver_SDL::InputLoop
void InputLoop() override
Handle input logic, is CTRL pressed, should we fast-forward, etc.
Definition: sdl_v.cpp:652
VideoDriver_SDL::Paint
void Paint() override
Paint the window.
Definition: sdl_v.cpp:151
FVideoDriver_SDL::CreateInstance
Driver * CreateInstance() const override
Create an instance of this driver-class.
Definition: sdl_v.h:62
VideoDriver_SDL::PaintThread
void PaintThread() override
Thread function for threaded drawing.
Definition: sdl_v.cpp:177
Driver
A driver for communicating with the user.
Definition: driver.h:23
VideoDriver_SDL::Stop
void Stop() override
Stop this driver.
Definition: sdl_v.cpp:644
DriverFactoryBase
Base for all driver factories.
Definition: driver.h:59