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();
100 void copyRectToScreen(
const void *buf,
int pitch,
int x,
int y,
int w,
int h)
override;
102 void unlockScreen()
override;
103 void fillScreen(uint32 col)
override;
104 void fillScreen(
const Common::Rect &r, uint32 col)
override;
105 void updateScreen()
override;
106 void setFocusRectangle(
const Common::Rect& rect)
override;
107 void clearFocusRectangle()
override;
110 void clearOverlay()
override;
112 void copyRectToOverlay(
const void *buf,
int pitch,
int x,
int y,
int w,
int h)
override;
113 int16 getOverlayHeight()
const override {
return _videoMode.overlayHeight; }
114 int16 getOverlayWidth()
const override {
return _videoMode.overlayWidth; }
116 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;
117 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);
118 void setCursorPalette(
const byte *colors, uint start, uint num)
override;
130 void notifyResize(
const int width,
const int height)
override;
132 #if defined(USE_IMGUI) && defined(USE_IMGUI_SDLRENDERER2) 133 void *getImGuiTexture(
const Graphics::Surface &image,
const byte *palette,
int palCount)
override;
134 void freeImGuiTexture(
void *texture)
override;
140 SDL_Surface *_osdMessageSurface;
142 uint8 _osdMessageAlpha;
144 uint32 _osdMessageFadeStartTime;
147 kOSDFadeOutDelay = 2 * 1000,
148 kOSDFadeOutDuration = 500,
149 kOSDInitialAlpha = 80
152 SDL_Rect getOSDMessageRect()
const;
154 void removeOSDMessage();
156 SDL_Surface *_osdIconSurface;
158 SDL_Rect getOSDIconRect()
const;
170 bool isAuto()
const {
return (_kw | _kh) == 0; }
172 int kw()
const {
return _kw; }
173 int kh()
const {
return _kh; }
179 return _videoMode.aspectRatioCorrection;
182 return _videoMode.scaleFactor;
187 virtual void setupHardwareSize();
189 void fixupResolutionForAspectRatio(
AspectRatio desiredAspectRatio,
int &width,
int &height)
const;
191 #if SDL_VERSION_ATLEAST(2, 0, 0) 194 SDL_Renderer *_renderer;
195 SDL_Texture *_screenTexture;
196 void deinitializeRenderer();
197 void recreateScreenTexture();
199 virtual SDL_Surface *SDL_SetVideoMode(
int width,
int height,
int bpp, Uint32 flags);
200 virtual void SDL_UpdateRects(SDL_Surface *screen,
int numrects, SDL_Rect *rects);
201 int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors,
int firstcolor,
int ncolors);
202 int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
203 int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
217 void detectSupportedFormats();
225 SDL_Surface *_overlayscreen;
228 bool _isDoubleBuf, _isHwPalette;
231 kTransactionNone = 0,
232 kTransactionActive = 1,
233 kTransactionRollback = 2
239 bool needUpdatescreen;
240 #if SDL_VERSION_ATLEAST(2, 0, 0) 241 bool needTextureUpdate;
242 bool needDisplayResize;
251 needUpdatescreen =
false;
253 #if SDL_VERSION_ATLEAST(2, 0, 0) 254 needTextureUpdate =
false;
255 needDisplayResize =
false;
258 formatChanged =
false;
268 bool aspectRatioCorrection;
273 #if SDL_VERSION_ATLEAST(2, 0, 0) 281 int screenWidth, screenHeight;
282 int overlayWidth, overlayHeight;
283 int hardwareWidth, hardwareHeight;
291 aspectRatioCorrection =
false;
295 mode = GFX_SURFACESDL;
296 #if SDL_VERSION_ATLEAST(2, 0, 0) 317 #if defined(WIN32) && !SDL_VERSION_ATLEAST(2, 0, 0) 331 uint8 _originalBitsPerPixel;
334 int _transactionMode;
337 bool _displayDisabled;
341 Scaler *_scaler, *_mouseScaler;
342 uint _maxExtraPixels;
345 bool _screenIsLocked;
348 int _screenChangeCount;
351 NUM_DIRTY_RECT = 100,
359 SDL_Rect _dirtyRectList[2 * NUM_DIRTY_RECT];
362 SDL_Rect _prevDirtyRectList[NUM_DIRTY_RECT];
363 int _numPrevDirtyRects;
380 MousePos() : w(0), h(0), hotX(0), hotY(0),
381 rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0),
386 SDL_Rect _mouseLastRect, _mouseNextRect;
389 uint32 _mouseKeyColor;
393 bool _disableMouseKeyColor;
394 byte _mappedMouseKeyColor;
395 bool _cursorDontScale;
396 bool _cursorPaletteDisabled;
397 SDL_Surface *_mouseOrigSurface;
398 SDL_Surface *_mouseSurface;
402 int _currentShakeXOffset;
403 int _currentShakeYOffset;
406 SDL_Color *_currentPalette;
407 uint _paletteDirtyStart, _paletteDirtyEnd;
409 SDL_Color *_overlayPalette;
410 bool _isInOverlayPalette;
413 SDL_Color *_cursorPalette;
421 #ifdef USE_SDL_DEBUG_FOCUSRECT 422 bool _enableFocusRectDebugCode;
423 bool _enableFocusRect;
427 virtual void addDirtyRect(
int x,
int y,
int w,
int h,
bool inOverlay,
bool realCoordinates =
false);
429 virtual void drawMouse();
430 virtual void undrawMouse();
431 virtual void blitCursor();
433 virtual void internUpdateScreen();
434 virtual void updateScreen(SDL_Rect *dirtyRectList,
int actualDirtyRects);
436 virtual bool loadGFXMode();
437 virtual void unloadGFXMode();
438 virtual bool hotswapGFXMode();
440 virtual void setAspectRatioCorrection(
bool enable);
441 void setFilteringMode(
bool enable);
442 void setVSync(
bool enable);
444 bool saveScreenshot(
const Common::Path &filename)
const override;
445 virtual void setGraphicsModeIntern();
446 virtual void getDefaultResolution(uint &w, uint &h);
449 void setFullscreenMode(
bool enable);
450 void handleScalerHotkeys(uint mode,
int factor);
456 Common::Point convertOverlayToGame(
const int x,
const int y)
const {
457 if (getOverlayWidth() == 0 || getOverlayHeight() == 0) {
458 error(
"convertOverlayToGame called without a valid overlay");
462 y * getHeight() / getOverlayHeight());
469 Common::Point convertGameToOverlay(
const int x,
const int y)
const {
470 if (getWidth() == 0 || getHeight() == 0) {
471 error(
"convertGameToOverlay called without a valid overlay");
475 y * getOverlayHeight() / getHeight());
484 bool _needRestoreAfterOverlay;
485 bool _prevForceRedraw;
486 bool _prevCursorNeedsRedraw;
Definition: surfacesdl-graphics.h:365
bool notifyEvent(const Common::Event &event) override
int getGameRenderScale() const override
Definition: surfacesdl-graphics.h:181
Definition: surfacesdl-graphics.h:264
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:419
bool gameNeedsAspectRatioCorrection() const override
Definition: surfacesdl-graphics.h:178
TransactionError
Definition: system.h:1155
Definition: scalerplugin.h:150
SDL_Surface * _screen
Definition: surfacesdl-graphics.h:207
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: surfacesdl-graphics.h:236
SDL_Surface * _tmpscreen
Definition: surfacesdl-graphics.h:221
Definition: surfacesdl-graphics.h:164
Definition: surfacesdl-graphics.h:50
void grabPalette(byte *colors, uint start, uint num) const override
SDL_Surface * _tmpscreen2
Definition: surfacesdl-graphics.h:223
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