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 setCursorPalette(
const byte *colors, uint start, uint num)
override;
129 void notifyResize(
const int width,
const int height)
override;
134 SDL_Surface *_osdMessageSurface;
136 uint8 _osdMessageAlpha;
138 uint32 _osdMessageFadeStartTime;
141 kOSDFadeOutDelay = 2 * 1000,
142 kOSDFadeOutDuration = 500,
143 kOSDInitialAlpha = 80
146 SDL_Rect getOSDMessageRect()
const;
148 void removeOSDMessage();
150 SDL_Surface *_osdIconSurface;
152 SDL_Rect getOSDIconRect()
const;
164 bool isAuto()
const {
return (_kw | _kh) == 0; }
166 int kw()
const {
return _kw; }
167 int kh()
const {
return _kh; }
173 return _videoMode.aspectRatioCorrection;
176 return _videoMode.scaleFactor;
181 virtual void setupHardwareSize();
183 void fixupResolutionForAspectRatio(
AspectRatio desiredAspectRatio,
int &width,
int &height)
const;
185 #if SDL_VERSION_ATLEAST(2, 0, 0) 188 SDL_Renderer *_renderer;
189 SDL_Texture *_screenTexture;
190 void deinitializeRenderer();
191 void recreateScreenTexture();
193 virtual SDL_Surface *SDL_SetVideoMode(
int width,
int height,
int bpp, Uint32 flags);
194 virtual void SDL_UpdateRects(SDL_Surface *screen,
int numrects, SDL_Rect *rects);
195 int SDL_SetColors(SDL_Surface *surface, SDL_Color *colors,
int firstcolor,
int ncolors);
196 int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha);
197 int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
211 void detectSupportedFormats();
219 SDL_Surface *_overlayscreen;
222 bool _isDoubleBuf, _isHwPalette;
225 kTransactionNone = 0,
226 kTransactionActive = 1,
227 kTransactionRollback = 2
233 bool needUpdatescreen;
234 #if SDL_VERSION_ATLEAST(2, 0, 0) 235 bool needTextureUpdate;
236 bool needDisplayResize;
245 needUpdatescreen =
false;
247 #if SDL_VERSION_ATLEAST(2, 0, 0) 248 needTextureUpdate =
false;
249 needDisplayResize =
false;
252 formatChanged =
false;
262 bool aspectRatioCorrection;
267 #if SDL_VERSION_ATLEAST(2, 0, 0) 275 int screenWidth, screenHeight;
276 int overlayWidth, overlayHeight;
277 int hardwareWidth, hardwareHeight;
285 aspectRatioCorrection =
false;
289 mode = GFX_SURFACESDL;
290 #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;
383 uint32 _mouseKeyColor;
387 byte _mappedMouseKeyColor;
388 bool _cursorDontScale;
389 bool _cursorPaletteDisabled;
390 SDL_Surface *_mouseOrigSurface;
391 SDL_Surface *_mouseSurface;
395 int _currentShakeXOffset;
396 int _currentShakeYOffset;
399 SDL_Color *_currentPalette;
400 uint _paletteDirtyStart, _paletteDirtyEnd;
402 SDL_Color *_overlayPalette;
403 bool _isInOverlayPalette;
406 SDL_Color *_cursorPalette;
414 #ifdef USE_SDL_DEBUG_FOCUSRECT 415 bool _enableFocusRectDebugCode;
416 bool _enableFocusRect;
420 virtual void addDirtyRect(
int x,
int y,
int w,
int h,
bool inOverlay,
bool realCoordinates =
false);
422 virtual void drawMouse();
423 virtual void undrawMouse();
424 virtual void blitCursor();
426 virtual void internUpdateScreen();
427 virtual void updateScreen(SDL_Rect *dirtyRectList,
int actualDirtyRects);
429 virtual bool loadGFXMode();
430 virtual void unloadGFXMode();
431 virtual bool hotswapGFXMode();
433 virtual void setAspectRatioCorrection(
bool enable);
434 void setFilteringMode(
bool enable);
435 void setVSync(
bool enable);
437 bool saveScreenshot(
const Common::Path &filename)
const override;
438 virtual void setGraphicsModeIntern();
439 virtual void getDefaultResolution(uint &w, uint &h);
442 void setFullscreenMode(
bool enable);
443 void handleScalerHotkeys(uint mode,
int factor);
449 Common::Point convertOverlayToGame(
const int x,
const int y)
const {
450 if (getOverlayWidth() == 0 || getOverlayHeight() == 0) {
451 error(
"convertOverlayToGame called without a valid overlay");
455 y * getHeight() / getOverlayHeight());
462 Common::Point convertGameToOverlay(
const int x,
const int y)
const {
463 if (getWidth() == 0 || getHeight() == 0) {
464 error(
"convertGameToOverlay called without a valid overlay");
468 y * getOverlayHeight() / getHeight());
477 bool _needRestoreAfterOverlay;
478 bool _prevForceRedraw;
479 bool _prevCursorNeedsRedraw;
Definition: surfacesdl-graphics.h:359
bool notifyEvent(const Common::Event &event) override
int getGameRenderScale() const override
Definition: surfacesdl-graphics.h:175
Definition: surfacesdl-graphics.h:258
Definition: sdl-events.h:40
Definition: sdl-graphics.h:38
void handleResizeImpl(const int width, const int height) override
Feature
Definition: system.h:417
void notifyVideoExpose() override
void notifyResize(const int width, const int height) override
Common::Mutex _graphicsMutex
Definition: surfacesdl-graphics.h:412
bool gameNeedsAspectRatioCorrection() const override
Definition: surfacesdl-graphics.h:172
TransactionError
Definition: system.h:1148
Definition: scalerplugin.h:150
SDL_Surface * _screen
Definition: surfacesdl-graphics.h:201
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: surfacesdl-graphics.h:230
SDL_Surface * _tmpscreen
Definition: surfacesdl-graphics.h:215
Definition: surfacesdl-graphics.h:158
Definition: surfacesdl-graphics.h:50
void grabPalette(byte *colors, uint start, uint num) const override
SDL_Surface * _tmpscreen2
Definition: surfacesdl-graphics.h:217
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