ScummVM API documentation
sdl.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef PLATFORM_SDL_H
23 #define PLATFORM_SDL_H
24 
25 #include "backends/platform/sdl/sdl-sys.h"
26 
27 #include "backends/modular-backend.h"
28 #include "backends/mixer/sdl/sdl-mixer.h"
29 #include "backends/events/sdl/sdl-events.h"
30 #include "backends/log/log.h"
31 #include "backends/platform/sdl/sdl-window.h"
32 
33 #include "common/array.h"
34 
35 #ifdef USE_OPENGL
36 #define USE_MULTIPLE_RENDERERS
37 #endif
38 
39 #ifdef USE_DISCORD
40 class DiscordPresence;
41 #endif
42 
47 public:
48  OSystem_SDL();
49  virtual ~OSystem_SDL();
50 
56  void init() override;
57 
58  bool hasFeature(Feature f) override;
59  void setFeatureState(Feature f, bool enable) override;
60  bool getFeatureState(Feature f) override;
61 
62  // Override functions from ModularBackend and OSystem
63  void initBackend() override;
64  void engineInit() override;
65  void engineDone() override;
66  void quit() override;
67  void fatalError() override;
70 
71  // Logging
72  void logMessage(LogMessageType::Type type, const char *message) override;
73 
74  Common::String getSystemLanguage() const override;
75 
76 #if SDL_VERSION_ATLEAST(2, 0, 0)
77  // Clipboard
78  bool hasTextInClipboard() override;
80  bool setTextInClipboard(const Common::U32String &text) override;
81 
82  void messageBox(LogMessageType::Type type, const char *message) override;
83 #endif
84 
85 #if SDL_VERSION_ATLEAST(2, 0, 14)
86  bool openUrl(const Common::String &url) override;
87 #endif
88 
89  void setWindowCaption(const Common::U32String &caption) override;
90  void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0) override;
92  uint32 getMillis(bool skipRecord = false) override;
93  void delayMillis(uint msecs) override;
94  void getTimeAndDate(TimeDate &td, bool skipRecord = false) const override;
95  MixerManager *getMixerManager() override;
98  uint32 getDoubleClickTime() const override;
99 
100  // Default paths
101  virtual Common::Path getDefaultIconsPath();
102  virtual Common::Path getDefaultDLCsPath();
103  virtual Common::Path getScreenshotsPath();
104 
105 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
107  OpenGL::ContextType getOpenGLType() const override { return _oglType; }
108 #endif
109 #if defined(USE_OPENGL) && defined(USE_GLAD)
110  void *getOpenGLProcAddress(const char *name) const override;
111 #endif
112 
113 protected:
114  bool _inited;
115  bool _initedSDL;
116 #ifdef USE_SDL_NET
117  bool _initedSDLnet;
118 #endif
119 
120 #ifdef USE_DISCORD
121  DiscordPresence *_presence;
122 #endif
123 
133 
138  Common::EventSource *_eventSourceWrapper;
139 
144 
145  SdlGraphicsManager::State _gfxManagerState;
146 
147 #if defined(USE_OPENGL_GAME) || defined(USE_OPENGL_SHADERS)
148  // Graphics capabilities
149  void detectOpenGLFeaturesSupport();
150  void detectAntiAliasingSupport();
151 
152  OpenGL::ContextType _oglType;
153  bool _supportsFrameBuffer;
154  bool _supportsShaders;
155  Common::Array<uint> _antiAliasLevels;
156 #endif
157 
161  virtual void initSDL();
162 
167 
168  // Logging
169  virtual Common::WriteStream *createLogFile();
170  Backends::Log::Log *_logger;
171 
172 #ifdef USE_MULTIPLE_RENDERERS
173  enum GraphicsManagerType {
174  GraphicsManagerSurfaceSDL,
175 #ifdef USE_OPENGL
176  GraphicsManagerOpenGL,
177 #endif
178  GraphicsManagerCount
179  };
180 
181  typedef Common::Array<GraphicsMode> GraphicsModeArray;
182  GraphicsModeArray _graphicsModes;
183  Common::Array<int> _graphicsModeIds;
184  int _graphicsMode;
185  int _firstMode[GraphicsManagerCount];
186  int _lastMode[GraphicsManagerCount];
187  int _defaultMode[GraphicsManagerCount];
188 
192  void setupGraphicsModes();
193 
197  void clearGraphicsModes();
198 
199  virtual GraphicsManagerType getDefaultGraphicsManager() const;
200  SdlGraphicsManager *createGraphicsManager(SdlEventSource *sdlEventSource, SdlWindow *window, GraphicsManagerType type);
201  const OSystem::GraphicsMode *getSupportedGraphicsModes() const override;
202  int getDefaultGraphicsMode() const override;
203  bool setGraphicsMode(int mode, uint flags) override;
204  int getGraphicsMode() const override;
205 #endif
206 
207  virtual uint32 getOSDoubleClickTime() const { return 0; }
208  virtual const char * const *buildHelpDialogData() override;
209 };
210 
211 #endif
bool setGraphicsMode(int mode, uint flags=kGfxModeNoFlags) override
Definition: modular-backend.h:149
Definition: sdl.h:46
void initBackend() override
void getTimeAndDate(TimeDate &td, bool skipRecord=false) const override
Definition: modular-backend.h:48
virtual void messageBox(LogMessageType::Type type, const char *message)
Definition: system.h:1904
Definition: system.h:106
Definition: str.h:59
SdlWindow * _window
Definition: sdl.h:143
void setFeatureState(Feature f, bool enable) override
bool getFeatureState(Feature f) override
Definition: sdl-events.h:40
Definition: stream.h:77
Definition: sdl-graphics.h:38
Definition: log.h:41
virtual void initSDL()
virtual Common::Array< uint > getSupportedAntiAliasingLevels() const
Definition: system.h:876
Definition: array.h:52
Definition: system.h:730
void addSysArchivesToSearchSet(Common::SearchSet &s, int priority=0) override
void engineDone() override
Common::SaveFileManager * getSavefileManager() override
Feature
Definition: system.h:403
Common::Path _logFilePath
Definition: sdl.h:132
uint32 getMillis(bool skipRecord=false) override
uint32 getDoubleClickTime() const override
Definition: path.h:52
void delayMillis(uint msecs) override
virtual const char *const * buildHelpDialogData() override
const GraphicsMode * getSupportedGraphicsModes() const override
void fatalError() override
Type
Definition: log.h:33
int getDefaultGraphicsMode() const override
Definition: sdl-graphics.h:109
int getGraphicsMode() const override
virtual bool openUrl(const Common::String &url)
Definition: system.h:1978
virtual bool hasTextInClipboard()
Definition: system.h:1942
virtual bool setTextInClipboard(const Common::U32String &text)
Definition: system.h:1964
Definition: timer.h:40
Definition: ustr.h:57
virtual OpenGL::ContextType getOpenGLType() const
Definition: system.h:890
Definition: archive.h:312
Definition: hardware-input.h:199
Common::KeymapArray getGlobalKeymaps() override
Common::MutexInternal * createMutex() override
void init() override
void setWindowCaption(const Common::U32String &caption) override
Definition: mixer.h:31
Common::TimerManager * getTimerManager() override
SdlEventSource * _eventSource
Definition: sdl.h:137
void logMessage(LogMessageType::Type type, const char *message) override
void engineInit() override
Definition: savefile.h:142
virtual Common::U32String getTextFromClipboard()
Definition: system.h:1953
bool hasFeature(Feature f) override
Definition: events.h:259
Definition: mutex.h:40
Definition: sdl-window.h:30
virtual AudioCDManager * createAudioCDManager()
void quit() override
Definition: audiocd.h:33
Common::HardwareInputSet * getHardwareInputSet() override
Common::String getSystemLanguage() const override