aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics
diff options
context:
space:
mode:
authorCameron Cawley2019-03-01 16:13:13 +0000
committerBastien Bouclet2019-03-03 13:44:10 +0100
commit342733cee6c9dc3db94ff88cb2278a501150bc1c (patch)
treed9e923bc5bca83d1f148b6e5f00198a935689946 /backends/graphics
parent4c708dc97f5c515ba01aee0d5610489fa43fa1f9 (diff)
downloadscummvm-rg350-342733cee6c9dc3db94ff88cb2278a501150bc1c.tar.gz
scummvm-rg350-342733cee6c9dc3db94ff88cb2278a501150bc1c.tar.bz2
scummvm-rg350-342733cee6c9dc3db94ff88cb2278a501150bc1c.zip
SDL: Add a function to convert from SDL_PixelFormat to Graphics::PixelFormat
Diffstat (limited to 'backends/graphics')
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.cpp32
-rw-r--r--backends/graphics/surfacesdl/surfacesdl-graphics.h6
-rw-r--r--backends/graphics/wincesdl/wincesdl-graphics.cpp11
3 files changed, 19 insertions, 30 deletions
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index dd334f3814..37965d057e 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -493,6 +493,14 @@ static void maskToBitCount(Uint32 mask, uint8 &numBits, uint8 &shift) {
}
#endif
+Graphics::PixelFormat SurfaceSdlGraphicsManager::convertSDLPixelFormat(SDL_PixelFormat *in) const {
+ return Graphics::PixelFormat(in->BytesPerPixel,
+ 8 - in->Rloss, 8 - in->Gloss,
+ 8 - in->Bloss, 8 - in->Aloss,
+ in->Rshift, in->Gshift,
+ in->Bshift, in->Ashift);
+}
+
void SurfaceSdlGraphicsManager::detectSupportedFormats() {
_supportedFormats.clear();
@@ -570,11 +578,7 @@ void SurfaceSdlGraphicsManager::detectSupportedFormats() {
if (_hwScreen) {
// Get our currently set hardware format
- Graphics::PixelFormat hwFormat(_hwScreen->format->BytesPerPixel,
- 8 - _hwScreen->format->Rloss, 8 - _hwScreen->format->Gloss,
- 8 - _hwScreen->format->Bloss, 8 - _hwScreen->format->Aloss,
- _hwScreen->format->Rshift, _hwScreen->format->Gshift,
- _hwScreen->format->Bshift, _hwScreen->format->Ashift);
+ Graphics::PixelFormat hwFormat = convertSDLPixelFormat(_hwScreen->format);
// Workaround to SDL not providing an accurate Aloss value on Mac OS X.
if (_hwScreen->format->Amask == 0)
@@ -1041,17 +1045,7 @@ bool SurfaceSdlGraphicsManager::loadGFXMode() {
if (_overlayscreen == NULL)
error("allocating _overlayscreen failed");
- _overlayFormat.bytesPerPixel = _overlayscreen->format->BytesPerPixel;
-
- _overlayFormat.rLoss = _overlayscreen->format->Rloss;
- _overlayFormat.gLoss = _overlayscreen->format->Gloss;
- _overlayFormat.bLoss = _overlayscreen->format->Bloss;
- _overlayFormat.aLoss = _overlayscreen->format->Aloss;
-
- _overlayFormat.rShift = _overlayscreen->format->Rshift;
- _overlayFormat.gShift = _overlayscreen->format->Gshift;
- _overlayFormat.bShift = _overlayscreen->format->Bshift;
- _overlayFormat.aShift = _overlayscreen->format->Ashift;
+ _overlayFormat = convertSDLPixelFormat(_overlayscreen->format);
_tmpscreen2 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.overlayWidth + 3, _videoMode.overlayHeight + 3,
16,
@@ -2362,11 +2356,7 @@ void SurfaceSdlGraphicsManager::displayMessageOnOSD(const char *msg) {
Graphics::Surface dst;
dst.init(_osdMessageSurface->w, _osdMessageSurface->h, _osdMessageSurface->pitch, _osdMessageSurface->pixels,
- Graphics::PixelFormat(_osdMessageSurface->format->BytesPerPixel,
- 8 - _osdMessageSurface->format->Rloss, 8 - _osdMessageSurface->format->Gloss,
- 8 - _osdMessageSurface->format->Bloss, 8 - _osdMessageSurface->format->Aloss,
- _osdMessageSurface->format->Rshift, _osdMessageSurface->format->Gshift,
- _osdMessageSurface->format->Bshift, _osdMessageSurface->format->Ashift));
+ convertSDLPixelFormat(_osdMessageSurface->format));
// Render the message, centered, and in white
for (i = 0; i < lines.size(); i++) {
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 3866bc3810..3315533d80 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -118,6 +118,12 @@ protected:
virtual void setPalette(const byte *colors, uint start, uint num) override;
virtual void grabPalette(byte *colors, uint start, uint num) const override;
+ /**
+ * Convert from the SDL pixel format to Graphics::PixelFormat
+ * @param in The SDL pixel format to convert
+ * @param out A pixel format to be written to
+ */
+ Graphics::PixelFormat convertSDLPixelFormat(SDL_PixelFormat *in) const;
public:
virtual void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
virtual Graphics::Surface *lockScreen() override;
diff --git a/backends/graphics/wincesdl/wincesdl-graphics.cpp b/backends/graphics/wincesdl/wincesdl-graphics.cpp
index 1677ecac06..8e51f43efa 100644
--- a/backends/graphics/wincesdl/wincesdl-graphics.cpp
+++ b/backends/graphics/wincesdl/wincesdl-graphics.cpp
@@ -883,15 +883,8 @@ bool WINCESdlGraphicsManager::loadGFXMode() {
InitScalers(555);
else
InitScalers(565);
- _overlayFormat.bytesPerPixel = _hwscreen->format->BytesPerPixel;
- _overlayFormat.rLoss = _hwscreen->format->Rloss;
- _overlayFormat.gLoss = _hwscreen->format->Gloss;
- _overlayFormat.bLoss = _hwscreen->format->Bloss;
- _overlayFormat.aLoss = _hwscreen->format->Aloss;
- _overlayFormat.rShift = _hwscreen->format->Rshift;
- _overlayFormat.gShift = _hwscreen->format->Gshift;
- _overlayFormat.bShift = _hwscreen->format->Bshift;
- _overlayFormat.aShift = _hwscreen->format->Ashift;
+
+ _overlayFormat = convertSDLPixelFormat(_hwscreen->format);
// Need some extra bytes around when using 2xSaI
_tmpscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth + 3, _videoMode.screenHeight + 3, 16, _hwscreen->format->Rmask, _hwscreen->format->Gmask, _hwscreen->format->Bmask, _hwscreen->format->Amask);