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,
const Graphics::PixelFormat *format,
const byte *mask,
frac_t scaleX,
frac_t scaleY)
override;
121 void setMouseCursor(
const void *buf, uint w, uint h,
int hotspotX,
int hotspotY, uint32 keycolor,
const Graphics::PixelFormat *format,
const byte *mask,
frac_t scaleX,
frac_t scaleY,
bool disableKeyColor);
122 void setCursorPalette(
const byte *colors, uint start, uint num)
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);
219 void detectSupportedFormats();
227 SDL_Surface *_overlayscreen;
230 bool _isDoubleBuf, _isHwPalette;
233 kTransactionNone = 0,
234 kTransactionActive = 1,
235 kTransactionRollback = 2
241 bool needUpdatescreen;
242#if SDL_VERSION_ATLEAST(2, 0, 0)
243 bool needTextureUpdate;
244 bool needDisplayResize;
251 needUpdatescreen =
false;
253#if SDL_VERSION_ATLEAST(2, 0, 0)
254 needTextureUpdate =
false;
255 needDisplayResize =
false;
257 formatChanged =
false;
266 bool aspectRatioCorrection;
271#if SDL_VERSION_ATLEAST(2, 0, 0)
279 int screenWidth, screenHeight;
280 int overlayWidth, overlayHeight;
281 int hardwareWidth, hardwareHeight;
287 aspectRatioCorrection =
false;
291 mode = GFX_SURFACESDL;
292#if SDL_VERSION_ATLEAST(2, 0, 0)
311#if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0)
325 uint8 _originalBitsPerPixel;
328 int _transactionMode;
331 bool _displayDisabled;
335 Scaler *_scaler, *_mouseScaler;
336 uint _maxExtraPixels;
339 bool _screenIsLocked;
342 int _screenChangeCount;
345 NUM_DIRTY_RECT = 100,
353 SDL_Rect _dirtyRectList[2 * NUM_DIRTY_RECT];
356 SDL_Rect _prevDirtyRectList[NUM_DIRTY_RECT];
357 int _numPrevDirtyRects;
374 MousePos() : w(0), h(0), hotX(0), hotY(0),
375 rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0),
380 SDL_Rect _mouseLastRect, _mouseNextRect;
382 uint32 _mouseKeyColor;
383 bool _disableMouseKeyColor;
384 byte _mappedMouseKeyColor;
387 bool _cursorPaletteDisabled;
388 SDL_Surface *_mouseOrigSurface;
389 SDL_Surface *_mouseSurface;
393 int _currentShakeXOffset;
394 int _currentShakeYOffset;
397 SDL_Color *_currentPalette;
398 uint _paletteDirtyStart, _paletteDirtyEnd;
400 SDL_Color *_overlayPalette;
401 bool _isInOverlayPalette;
404 SDL_Color *_cursorPalette;
412#ifdef USE_SDL_DEBUG_FOCUSRECT
413 bool _enableFocusRectDebugCode;
414 bool _enableFocusRect;
418 virtual void addDirtyRect(
int x,
int y,
int w,
int h,
bool inOverlay,
bool realCoordinates =
false);
420 virtual void drawMouse();
421 virtual void undrawMouse();
422 virtual void blitCursor();
424 virtual void internUpdateScreen();
425 virtual void updateScreen(SDL_Rect *dirtyRectList,
int actualDirtyRects);
427 virtual bool loadGFXMode();
428 virtual void unloadGFXMode();
429 virtual bool hotswapGFXMode();
431 virtual void setAspectRatioCorrection(
bool enable);
432 void setFilteringMode(
bool enable);
433 void setVSync(
bool enable);
435 bool saveScreenshot(
const Common::Path &filename)
const override;
436 virtual void setGraphicsModeIntern();
437 virtual void getDefaultResolution(uint &w, uint &h);
443 void setFullscreenMode(
bool enable);
444 void handleScalerHotkeys(uint mode,
int factor);
450 Common::Point convertOverlayToGame(
const int x,
const int y)
const {
451 if (getOverlayWidth() == 0 || getOverlayHeight() == 0) {
452 error(
"convertOverlayToGame called without a valid overlay");
456 y * getHeight() / getOverlayHeight());
463 Common::Point convertGameToOverlay(
const int x,
const int y)
const {
464 if (getWidth() == 0 || getHeight() == 0) {
465 error(
"convertGameToOverlay called without a valid overlay");
469 y * getOverlayHeight() / getHeight());
478 bool _needRestoreAfterOverlay;
479 bool _prevForceRedraw;
480 bool _prevCursorNeedsRedraw;
Definition: scalerplugin.h:28
Definition: scalerplugin.h:150
Definition: sdl-events.h:40
Definition: sdl-graphics.h:38
Definition: sdl-window.h:30
Definition: surfacesdl-graphics.h:168
Definition: surfacesdl-graphics.h:50
bool gameNeedsAspectRatioCorrection() const override
Definition: surfacesdl-graphics.h:182
bool canSwitchFullscreen() const override
Definition: surfacesdl-graphics.h:440
void notifyResize(const int width, const int height) override
SDL_Surface * _tmpscreen2
Definition: surfacesdl-graphics.h:225
void notifyVideoExpose() override
void grabPalette(byte *colors, uint start, uint num) const override
bool notifyEvent(const Common::Event &event) override
Graphics::PixelFormat convertSDLPixelFormat(SDL_PixelFormat *in) const
int getGameRenderScale() const override
Definition: surfacesdl-graphics.h:185
Common::Mutex _graphicsMutex
Definition: surfacesdl-graphics.h:410
void handleResizeImpl(const int width, const int height) override
SDL_Surface * _screen
Definition: surfacesdl-graphics.h:209
SDL_Surface * _tmpscreen
Definition: surfacesdl-graphics.h:223
void setPalette(const byte *colors, uint start, uint num) override
int32 frac_t
Definition: frac.h:52
Feature
Definition: system.h:415
TransactionError
Definition: system.h:1188
@ kGfxModeNoFlags
Definition: system.h:790
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: surfacesdl-graphics.h:359
Definition: surfacesdl-graphics.h:238
Definition: surfacesdl-graphics.h:262