22 #ifndef BACKENDS_GRAPHICS_SURFACESDL_GRAPHICS_H 23 #define BACKENDS_GRAPHICS_SURFACESDL_GRAPHICS_H 25 #include "backends/graphics/graphics.h" 26 #include "backends/graphics/sdl/sdl-graphics.h" 27 #include "graphics/pixelformat.h" 28 #include "graphics/scaler.h" 29 #include "graphics/scalerplugin.h" 30 #include "common/events.h" 31 #include "common/mutex.h" 33 #include "backends/events/sdl/sdl-events.h" 35 #include "backends/platform/sdl/sdl-sys.h" 39 #define USE_SDL_DEBUG_FOCUSRECT 60 int getDefaultGraphicsMode()
const override;
62 int getGraphicsMode()
const override;
63 uint getDefaultScaler()
const override;
64 uint getDefaultScaleFactor()
const override;
65 bool setScaler(uint mode,
int factor)
override;
66 uint getScaler()
const override;
67 uint getScaleFactor()
const override;
72 #if SDL_VERSION_ATLEAST(2, 0, 0) 74 int getDefaultStretchMode()
const override;
75 bool setStretchMode(
int mode)
override;
76 int getStretchMode()
const override;
79 int getScreenChangeID()
const override {
return _screenChangeCount; }
81 void beginGFXTransaction()
override;
84 int16 getHeight()
const override;
85 int16 getWidth()
const override;
89 void setPalette(
const byte *colors, uint start, uint num)
override;
90 void grabPalette(byte *colors, uint start, uint num)
const override;
91 virtual void initGraphicsSurface();
98 #if SDL_VERSION_ATLEAST(3, 0, 0) 104 void copyRectToScreen(
const void *buf,
int pitch,
int x,
int y,
int w,
int h)
override;
106 void unlockScreen()
override;
107 void fillScreen(uint32 col)
override;
108 void fillScreen(
const Common::Rect &r, uint32 col)
override;
109 void updateScreen()
override;
110 void setFocusRectangle(
const Common::Rect& rect)
override;
111 void clearFocusRectangle()
override;
114 void clearOverlay()
override;
116 void copyRectToOverlay(
const void *buf,
int pitch,
int x,
int y,
int w,
int h)
override;
117 int16 getOverlayHeight()
const override {
return _videoMode.overlayHeight; }
118 int16 getOverlayWidth()
const override {
return _videoMode.overlayWidth; }
120 void setMouseCursor(
const void *buf, uint w, uint h,
int hotspotX,
int hotspotY, uint32 keycolor,
bool dontScale =
false,
const Graphics::PixelFormat *format = NULL,
const byte *mask = NULL)
override;
121 void setMouseCursor(
const void *buf, uint w, uint h,
int hotspotX,
int hotspotY, uint32 keycolor,
bool dontScale,
const Graphics::PixelFormat *format,
const byte *mask,
bool disableKeyColor);
122 void setCursorPalette(
const byte *colors, uint start, uint num)
override;
134 void notifyResize(
const int width,
const int height)
override;
136 #if defined(USE_IMGUI) && (defined(USE_IMGUI_SDLRENDERER2) || defined(USE_IMGUI_SDLRENDERER3)) 137 void *getImGuiTexture(
const Graphics::Surface &image,
const byte *palette,
int palCount)
override;
138 void freeImGuiTexture(
void *texture)
override;
144 SDL_Surface *_osdMessageSurface;
146 uint8 _osdMessageAlpha;
148 uint32 _osdMessageFadeStartTime;
151 kOSDFadeOutDelay = 2 * 1000,
152 kOSDFadeOutDuration = 500,
153 kOSDInitialAlpha = 80
156 SDL_Rect getOSDMessageRect()
const;
158 void removeOSDMessage();
160 SDL_Surface *_osdIconSurface;
162 SDL_Rect getOSDIconRect()
const;
174 bool isAuto()
const {
return (_kw | _kh) == 0; }
176 int kw()
const {
return _kw; }
177 int kh()
const {
return _kh; }
183 return _videoMode.aspectRatioCorrection;
186 return _videoMode.scaleFactor;
191 virtual void setupHardwareSize();
193 void fixupResolutionForAspectRatio(
AspectRatio desiredAspectRatio,
int &width,
int &height)
const;
195 #if SDL_VERSION_ATLEAST(2, 0, 0) 198 SDL_Renderer *_renderer;
199 SDL_Texture *_screenTexture;
200 void deinitializeRenderer();
201 void recreateScreenTexture();
203 virtual SDL_Surface *SDL_SetVideoMode(
int width,
int height,
int bpp, Uint32 flags);
204 virtual void SDL_UpdateRects(SDL_Surface *screen,
int numrects, SDL_Rect *rects);
205 int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors,
int firstcolor,
int ncolors);
206 int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
207 int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
221 void detectSupportedFormats();
229 SDL_Surface *_overlayscreen;
232 bool _isDoubleBuf, _isHwPalette;
235 kTransactionNone = 0,
236 kTransactionActive = 1,
237 kTransactionRollback = 2
243 bool needUpdatescreen;
244 #if SDL_VERSION_ATLEAST(2, 0, 0) 245 bool needTextureUpdate;
246 bool needDisplayResize;
255 needUpdatescreen =
false;
257 #if SDL_VERSION_ATLEAST(2, 0, 0) 258 needTextureUpdate =
false;
259 needDisplayResize =
false;
262 formatChanged =
false;
272 bool aspectRatioCorrection;
277 #if SDL_VERSION_ATLEAST(2, 0, 0) 285 int screenWidth, screenHeight;
286 int overlayWidth, overlayHeight;
287 int hardwareWidth, hardwareHeight;
295 aspectRatioCorrection =
false;
299 mode = GFX_SURFACESDL;
300 #if SDL_VERSION_ATLEAST(2, 0, 0) 321 #if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0) 335 uint8 _originalBitsPerPixel;
338 int _transactionMode;
341 bool _displayDisabled;
345 Scaler *_scaler, *_mouseScaler;
346 uint _maxExtraPixels;
349 bool _screenIsLocked;
352 int _screenChangeCount;
355 NUM_DIRTY_RECT = 100,
363 SDL_Rect _dirtyRectList[2 * NUM_DIRTY_RECT];
366 SDL_Rect _prevDirtyRectList[NUM_DIRTY_RECT];
367 int _numPrevDirtyRects;
384 MousePos() : w(0), h(0), hotX(0), hotY(0),
385 rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0),
390 SDL_Rect _mouseLastRect, _mouseNextRect;
393 uint32 _mouseKeyColor;
397 bool _disableMouseKeyColor;
398 byte _mappedMouseKeyColor;
399 bool _cursorDontScale;
400 bool _cursorPaletteDisabled;
401 SDL_Surface *_mouseOrigSurface;
402 SDL_Surface *_mouseSurface;
406 int _currentShakeXOffset;
407 int _currentShakeYOffset;
410 SDL_Color *_currentPalette;
411 uint _paletteDirtyStart, _paletteDirtyEnd;
413 SDL_Color *_overlayPalette;
414 bool _isInOverlayPalette;
417 SDL_Color *_cursorPalette;
425 #ifdef USE_SDL_DEBUG_FOCUSRECT 426 bool _enableFocusRectDebugCode;
427 bool _enableFocusRect;
431 virtual void addDirtyRect(
int x,
int y,
int w,
int h,
bool inOverlay,
bool realCoordinates =
false);
433 virtual void drawMouse();
434 virtual void undrawMouse();
435 virtual void blitCursor();
437 virtual void internUpdateScreen();
438 virtual void updateScreen(SDL_Rect *dirtyRectList,
int actualDirtyRects);
440 virtual bool loadGFXMode();
441 virtual void unloadGFXMode();
442 virtual bool hotswapGFXMode();
444 virtual void setAspectRatioCorrection(
bool enable);
445 void setFilteringMode(
bool enable);
446 void setVSync(
bool enable);
448 bool saveScreenshot(
const Common::Path &filename)
const override;
449 virtual void setGraphicsModeIntern();
450 virtual void getDefaultResolution(uint &w, uint &h);
453 void setFullscreenMode(
bool enable);
454 void handleScalerHotkeys(uint mode,
int factor);
460 Common::Point convertOverlayToGame(
const int x,
const int y)
const {
461 if (getOverlayWidth() == 0 || getOverlayHeight() == 0) {
462 error(
"convertOverlayToGame called without a valid overlay");
466 y * getHeight() / getOverlayHeight());
473 Common::Point convertGameToOverlay(
const int x,
const int y)
const {
474 if (getWidth() == 0 || getHeight() == 0) {
475 error(
"convertGameToOverlay called without a valid overlay");
479 y * getOverlayHeight() / getHeight());
488 bool _needRestoreAfterOverlay;
489 bool _prevForceRedraw;
490 bool _prevCursorNeedsRedraw;
Definition: surfacesdl-graphics.h:369
bool notifyEvent(const Common::Event &event) override
int getGameRenderScale() const override
Definition: surfacesdl-graphics.h:185
Definition: surfacesdl-graphics.h:268
Definition: sdl-events.h:40
Definition: sdl-graphics.h:38
void handleResizeImpl(const int width, const int height) override
Feature
Definition: system.h:403
void notifyVideoExpose() override
void notifyResize(const int width, const int height) override
Common::Mutex _graphicsMutex
Definition: surfacesdl-graphics.h:423
bool gameNeedsAspectRatioCorrection() const override
Definition: surfacesdl-graphics.h:182
TransactionError
Definition: system.h:1155
Definition: scalerplugin.h:150
SDL_Surface * _screen
Definition: surfacesdl-graphics.h:211
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: surfacesdl-graphics.h:240
SDL_Surface * _tmpscreen
Definition: surfacesdl-graphics.h:225
Definition: surfacesdl-graphics.h:168
Definition: surfacesdl-graphics.h:50
void grabPalette(byte *colors, uint start, uint num) const override
SDL_Surface * _tmpscreen2
Definition: surfacesdl-graphics.h:227
void setPalette(const byte *colors, uint start, uint num) override
Definition: scalerplugin.h:28
Graphics::PixelFormat convertSDLPixelFormat(SDL_PixelFormat *in) const
Definition: sdl-window.h:30