From 8447a3650e7de2fc780c1c354f70bf0d119622b3 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 3 Jun 2009 23:36:23 +0000 Subject: Applying the temporary 16-bit SDL hack. svn-id: r41152 --- backends/platform/sdl/graphics.cpp | 96 +++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 78b8bd8c63..389a7a0735 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -407,6 +407,20 @@ bool OSystem_SDL::loadGFXMode() { } } +#ifdef ENABLE_16BIT + // + // Create the surface that contains the 16 bit game data + // + _screen16 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, + 16, + 0x7C00, + 0x3E0, + 0x1F, + 0); //555, not 565 + if (_screen16 == NULL) + error("allocating _screen16 failed"); +#endif + // // Create the surface used for the graphics in 16 bit before scaling, and also the overlay // @@ -484,10 +498,17 @@ bool OSystem_SDL::loadGFXMode() { } void OSystem_SDL::unloadGFXMode() { +#ifdef ENABLE_16BIT + if (_screen16) { + SDL_FreeSurface(_screen16); + _screen16 = NULL; + } +#else if (_screen) { SDL_FreeSurface(_screen); _screen = NULL; } +#endif if (_hwscreen) { SDL_FreeSurface(_hwscreen); @@ -519,14 +540,23 @@ void OSystem_SDL::unloadGFXMode() { } bool OSystem_SDL::hotswapGFXMode() { +#ifdef ENABLE_16BIT + if (!_screen16) +#else if (!_screen) +#endif return false; // Keep around the old _screen & _overlayscreen so we can restore the screen data // after the mode switch. +#ifdef ENABLE_16BIT + SDL_Surface *old_screen = _screen16; + _screen16 = NULL; +#else SDL_Surface *old_screen = _screen; - SDL_Surface *old_overlayscreen = _overlayscreen; _screen = NULL; +#endif + SDL_Surface *old_overlayscreen = _overlayscreen; _overlayscreen = NULL; // Release the HW screen surface @@ -544,7 +574,11 @@ bool OSystem_SDL::hotswapGFXMode() { if (!loadGFXMode()) { unloadGFXMode(); +#ifdef ENABLE_16BIT + _screen16 = old_screen; +#else _screen = old_screen; +#endif _overlayscreen = old_overlayscreen; return false; @@ -554,7 +588,11 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_SetColors(_screen, _currentPalette, 0, 256); // Restore old screen content +#ifdef ENABLE_16BIT + SDL_BlitSurface(old_screen, NULL, _screen16, NULL); +#else SDL_BlitSurface(old_screen, NULL, _screen, NULL); +#endif SDL_BlitSurface(old_overlayscreen, NULL, _overlayscreen, NULL); // Free the old surfaces @@ -636,7 +674,11 @@ void OSystem_SDL::internUpdateScreen() { #endif if (!_overlayVisible) { +#ifdef ENABLE_16BIT + origSurf = _screen16; +#else origSurf = _screen; +#endif srcSurf = _tmpscreen; width = _videoMode.screenWidth; height = _videoMode.screenHeight; @@ -781,6 +823,12 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int assert (_transactionMode == kTransactionNone); assert(src); +#ifdef ENABLE_16BIT + if (_screen16 == NULL) { + warning("OSystem_SDL::copyRectToScreen: _screen16 == NULL"); + return; + } +#endif if (_screen == NULL) { warning("OSystem_SDL::copyRectToScreen: _screen == NULL"); return; @@ -829,11 +877,29 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int } // Try to lock the screen surface +#ifdef ENABLE_16BIT + if (SDL_LockSurface(_screen16) == -1) +#else if (SDL_LockSurface(_screen) == -1) +#endif error("SDL_LockSurface failed: %s", SDL_GetError()); - byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; +#ifdef ENABLE_16BIT + byte *dst = (byte *)_screen16->pixels + y * _videoMode.screenWidth * 2 + x * 2; + if (_videoMode.screenWidth == w && pitch == w * 2) { + memcpy(dst, src, h*w*2); + } else { + do { + memcpy(dst, src, w * 2); + src += pitch; + dst += _videoMode.screenWidth * 2; + } while (--h); + } + // Unlock the screen surface + SDL_UnlockSurface(_screen16); +#else + byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; if (_videoMode.screenWidth == pitch && pitch == w) { memcpy(dst, src, h*w); } else { @@ -846,6 +912,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int // Unlock the screen surface SDL_UnlockSurface(_screen); +#endif } Graphics::Surface *OSystem_SDL::lockScreen() { @@ -859,14 +926,26 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _screenIsLocked = true; // Try to lock the screen surface +#ifdef ENABLE_16BIT + if (SDL_LockSurface(_screen16) == -1) +#else if (SDL_LockSurface(_screen) == -1) +#endif error("SDL_LockSurface failed: %s", SDL_GetError()); +#ifdef ENABLE_16BIT + _framebuffer.pixels = _screen16->pixels; + _framebuffer.w = _screen16->w; + _framebuffer.h = _screen16->h; + _framebuffer.pitch = _screen16->pitch; + _framebuffer.bytesPerPixel = 2; +#else _framebuffer.pixels = _screen->pixels; _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; _framebuffer.bytesPerPixel = 1; +#endif return &_framebuffer; } @@ -879,7 +958,11 @@ void OSystem_SDL::unlockScreen() { _screenIsLocked = false; // Unlock the screen surface +#ifdef ENABLE_16BIT + SDL_UnlockSurface(_screen16); +#else SDL_UnlockSurface(_screen); +#endif // Trigger a full screen update _forceFull = true; @@ -1054,8 +1137,13 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // since we don't actually set the palette until the screen is updated. // But it could indicate a programming error, so let's warn about it. +#ifdef ENABLE_16BIT + if (!_screen16) + warning("OSystem_SDL::setPalette: _screen16 == NULL"); +#else if (!_screen) warning("OSystem_SDL::setPalette: _screen == NULL"); +#endif const byte *b = colors; uint i; @@ -1179,7 +1267,11 @@ void OSystem_SDL::clearOverlay() { dst.x = dst.y = 1; src.w = dst.w = _videoMode.screenWidth; src.h = dst.h = _videoMode.screenHeight; +#ifdef ENABLE_16BIT + if (SDL_BlitSurface(_screen16, &src, _tmpscreen, &dst) != 0) +#else if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0) +#endif error("SDL_BlitSurface failed: %s", SDL_GetError()); SDL_LockSurface(_tmpscreen); -- cgit v1.2.3 From f8361b5c53b96faddb56024bb932ce46b7005dbf Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 5 Jun 2009 06:41:04 +0000 Subject: Converted cursor code to use 16-bit. svn-id: r41191 --- backends/platform/sdl/graphics.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 389a7a0735..1a80b9be19 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1438,8 +1438,13 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); +#ifdef ENABLE_16BIT + _mouseData = (byte *)malloc(w * h * 2); + memcpy(_mouseData, buf, w * h * 2); +#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); +#endif blitCursor(); } @@ -1481,12 +1486,24 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { color = *srcPtr; +#ifdef ENABLE_16BIT + if (color != _mouseKeyColor) { // transparent, don't draw + int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; + int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; + int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + r, g, b); + } + dstPtr += 2; + srcPtr += 2; +#else if (color != _mouseKeyColor) { // transparent, don't draw *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, palette[color].r, palette[color].g, palette[color].b); } dstPtr += 2; srcPtr++; +#endif } dstPtr += _mouseOrigSurface->pitch - w * 2; } -- cgit v1.2.3 From 9789ba7f28d2c0a093adda01435306f28e91fede Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 5 Jun 2009 08:09:37 +0000 Subject: Corrected backend to be able to accept a 16-bit mouseKeyColor without overflow svn-id: r41194 --- backends/platform/sdl/graphics.cpp | 47 ++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 1a80b9be19..fadd7a376c 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1403,7 +1403,8 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { +#ifdef ENABLE_16BIT +void OSystem_SDL::setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale) { if (w == 0 || h == 0) return; @@ -1438,13 +1439,51 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); -#ifdef ENABLE_16BIT _mouseData = (byte *)malloc(w * h * 2); memcpy(_mouseData, buf, w * h * 2); -#else + + blitCursor(); +} +#endif + +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { + if (w == 0 || h == 0) + return; + + _mouseCurState.hotX = hotspot_x; + _mouseCurState.hotY = hotspot_y; + + _mouseKeyColor = keycolor; + + _cursorTargetScale = cursorTargetScale; + + if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) { + _mouseCurState.w = w; + _mouseCurState.h = h; + + if (_mouseOrigSurface) + SDL_FreeSurface(_mouseOrigSurface); + + // Allocate bigger surface because AdvMame2x adds black pixel at [0,0] + _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, + _mouseCurState.w + 2, + _mouseCurState.h + 2, + 16, + _hwscreen->format->Rmask, + _hwscreen->format->Gmask, + _hwscreen->format->Bmask, + _hwscreen->format->Amask); + + if (_mouseOrigSurface == NULL) + error("allocating _mouseOrigSurface failed"); + SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey); + } + + free(_mouseData); + _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); -#endif + blitCursor(); } -- cgit v1.2.3 From 56e5920bba753820c457c078237a8c06241302ed Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 6 Jun 2009 01:16:04 +0000 Subject: Corrected cursor display errors introduced by revision 41204, reimplemented 16-bit cursor support in a less hacky, but still temporary way. svn-id: r41209 --- backends/platform/sdl/graphics.cpp | 92 ++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 54 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index fadd7a376c..8ecf4ecda1 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1404,49 +1404,19 @@ void OSystem_SDL::warpMouse(int x, int y) { } #ifdef ENABLE_16BIT -void OSystem_SDL::setMouseCursor16(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint16 keycolor, int cursorTargetScale) { - if (w == 0 || h == 0) - return; - - _mouseCurState.hotX = hotspot_x; - _mouseCurState.hotY = hotspot_y; - - _mouseKeyColor = keycolor; - - _cursorTargetScale = cursorTargetScale; - - if (_mouseCurState.w != (int)w || _mouseCurState.h != (int)h) { - _mouseCurState.w = w; - _mouseCurState.h = h; - - if (_mouseOrigSurface) - SDL_FreeSurface(_mouseOrigSurface); - - // Allocate bigger surface because AdvMame2x adds black pixel at [0,0] - _mouseOrigSurface = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, - _mouseCurState.w + 2, - _mouseCurState.h + 2, - 16, - _hwscreen->format->Rmask, - _hwscreen->format->Gmask, - _hwscreen->format->Bmask, - _hwscreen->format->Amask); - - if (_mouseOrigSurface == NULL) - error("allocating _mouseOrigSurface failed"); - SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, kMouseColorKey); +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, uint8 bitDepth) { + uint32 colmask = 0xFF; + uint8 byteDepth = bitDepth >> 3; + for (int i = byteDepth; i > 1; i--) { + colmask <<= 8; + colmask |= 0xFF; } + keycolor &= colmask; - free(_mouseData); - - _mouseData = (byte *)malloc(w * h * 2); - memcpy(_mouseData, buf, w * h * 2); - - blitCursor(); -} +#else +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { #endif -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { if (w == 0 || h == 0) return; @@ -1480,14 +1450,24 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, } free(_mouseData); +#ifdef ENABLE_16BIT + _mouseData = (byte *)malloc(w * h * byteDepth); + memcpy(_mouseData, buf, w * h * byteDepth); + blitCursor(bitDepth); +#else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); blitCursor(); +#endif } +#ifdef ENABLE_16BIT +void OSystem_SDL::blitCursor(uint8 bitDepth) { +#else void OSystem_SDL::blitCursor() { +#endif byte *dstPtr; const byte *srcPtr = _mouseData; byte color; @@ -1526,22 +1506,26 @@ void OSystem_SDL::blitCursor() { for (j = 0; j < w; j++) { color = *srcPtr; #ifdef ENABLE_16BIT - if (color != _mouseKeyColor) { // transparent, don't draw - int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; - int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; - int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; - *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, - r, g, b); - } - dstPtr += 2; - srcPtr += 2; -#else - if (color != _mouseKeyColor) { // transparent, don't draw - *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, - palette[color].r, palette[color].g, palette[color].b); + if (bitDepth == 16) { + if (color != _mouseKeyColor) { // transparent, don't draw + int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; + int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; + int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + r, g, b); + } + dstPtr += 2; + srcPtr += 2; + } else { +#endif + if (color != _mouseKeyColor) { // transparent, don't draw + *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, + palette[color].r, palette[color].g, palette[color].b); + } + dstPtr += 2; + srcPtr++; +#ifdef ENABLE_16BIT } - dstPtr += 2; - srcPtr++; #endif } dstPtr += _mouseOrigSurface->pitch - w * 2; -- cgit v1.2.3 From 4087a3e6e8ebc0b519fc4c178a29696bd64fdd6f Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 6 Jun 2009 08:02:45 +0000 Subject: Corrected 16-bit cursor blit errors on GFX mode change. svn-id: r41212 --- backends/platform/sdl/graphics.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 8ecf4ecda1..81e137e19c 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -332,7 +332,11 @@ void OSystem_SDL::setGraphicsModeIntern() { // Even if the old and new scale factors are the same, we may have a // different scaler for the cursor now. +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } int OSystem_SDL::getGraphicsMode() const { @@ -600,7 +604,11 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_FreeSurface(old_overlayscreen); // Update cursor to new scale +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif // Blit everything to the screen internUpdateScreen(); @@ -1163,7 +1171,11 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // Some games blink cursors with palette if (_cursorPaletteDisabled) +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { @@ -1192,7 +1204,11 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { _cursorPaletteDisabled = false; +#ifdef ENABLE_16BIT + blitCursor(_cursorBitDepth); +#else blitCursor(); +#endif } void OSystem_SDL::setShakePos(int shake_pos) { @@ -1412,7 +1428,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, colmask |= 0xFF; } keycolor &= colmask; - + _cursorBitDepth = bitDepth; #else void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { #endif -- cgit v1.2.3 From 0323638ce933e1dea7dd81b35a6646a9773a01ea Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 6 Jun 2009 08:41:03 +0000 Subject: Streamlined the cursor blitting changes introduced in revision 41412 svn-id: r41213 --- backends/platform/sdl/graphics.cpp | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 81e137e19c..2872c71f44 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -332,11 +332,7 @@ void OSystem_SDL::setGraphicsModeIntern() { // Even if the old and new scale factors are the same, we may have a // different scaler for the cursor now. -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } int OSystem_SDL::getGraphicsMode() const { @@ -604,11 +600,7 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_FreeSurface(old_overlayscreen); // Update cursor to new scale -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif // Blit everything to the screen internUpdateScreen(); @@ -1171,11 +1163,7 @@ void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { // Some games blink cursors with palette if (_cursorPaletteDisabled) -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } void OSystem_SDL::grabPalette(byte *colors, uint start, uint num) { @@ -1204,11 +1192,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { _cursorPaletteDisabled = false; -#ifdef ENABLE_16BIT - blitCursor(_cursorBitDepth); -#else blitCursor(); -#endif } void OSystem_SDL::setShakePos(int shake_pos) { @@ -1469,21 +1453,15 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, #ifdef ENABLE_16BIT _mouseData = (byte *)malloc(w * h * byteDepth); memcpy(_mouseData, buf, w * h * byteDepth); - - blitCursor(bitDepth); #else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); +#endif blitCursor(); -#endif } -#ifdef ENABLE_16BIT -void OSystem_SDL::blitCursor(uint8 bitDepth) { -#else void OSystem_SDL::blitCursor() { -#endif byte *dstPtr; const byte *srcPtr = _mouseData; byte color; @@ -1522,7 +1500,7 @@ void OSystem_SDL::blitCursor() { for (j = 0; j < w; j++) { color = *srcPtr; #ifdef ENABLE_16BIT - if (bitDepth == 16) { + if (_cursorBitDepth == 16) { if (color != _mouseKeyColor) { // transparent, don't draw int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; -- cgit v1.2.3 From 0a793f08a4d198f3f766214ed4ce85ac51ccea5e Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 10 Jun 2009 05:35:18 +0000 Subject: SDL backend now dynamically generates 8 or 16-bit color surface depending on engine request (using ad-hoc format). svn-id: r41416 --- backends/platform/sdl/graphics.cpp | 244 ++++++++++++++++++++++++------------- 1 file changed, 158 insertions(+), 86 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 2872c71f44..142fa94dba 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -97,6 +97,9 @@ void OSystem_SDL::beginGFXTransaction(void) { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; +#ifdef ENABLE_16BIT + _transactionDetails.formatChanged = false; +#endif _oldVideoMode = _videoMode; } @@ -127,6 +130,12 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.screenHeight = _oldVideoMode.screenHeight; _videoMode.overlayWidth = _oldVideoMode.overlayWidth; _videoMode.overlayHeight = _oldVideoMode.overlayHeight; +#ifdef ENABLE_16BIT + } else if (_videoMode.format != _oldVideoMode.format) { + errors |= kTransactionPixelFormatNotSupported; + + _videoMode.format = _oldVideoMode.format; +#endif } if (_videoMode.fullscreen == _oldVideoMode.fullscreen && @@ -143,6 +152,32 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } } +#ifdef ENABLE_16BIT + if (_transactionDetails.formatChanged) { + _screenFormat = getPixelFormat(_videoMode.format); + if (!_transactionDetails.sizeChanged) { + unloadGFXMode(); + if (!loadGFXMode()) { + if (_oldVideoMode.setup) { + _transactionMode = kTransactionRollback; + errors |= endGFXTransaction(); + } + } else { + setGraphicsModeIntern(); + clearOverlay(); + + _videoMode.setup = true; + _modeChanged = true; + // OSystem_SDL::pollEvent used to update the screen change count, + // but actually it gives problems when a video mode was changed + // but OSystem_SDL::pollEvent was not called. This for example + // caused a crash under certain circumstances when doing an RTL. + // To fix this issue we update the screen change count right here. + _screenChangeCount++; + } + } + } +#endif if (_transactionDetails.sizeChanged) { unloadGFXMode(); if (!loadGFXMode()) { @@ -186,7 +221,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } else if (_transactionDetails.needUpdatescreen) { setGraphicsModeIntern(); internUpdateScreen(); - } + } _transactionMode = kTransactionNone; return (TransactionError)errors; @@ -339,6 +374,102 @@ int OSystem_SDL::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } +#ifdef ENABLE_16BIT +Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) +{ + bool typeAccepted = false; + Graphics::ColorFormat format; + + while (!formatList.empty() && !typeAccepted) + { + typeAccepted = false; + format = formatList.front(); + + //no need to keep searching if the screen + //is already in one of the desired formats + if (format == _videoMode.format) + return format; + + formatList.pop_front(); + switch (format & Graphics::kFormatTypeMask) + { + case Graphics::kFormat8Bit: + if (format == Graphics::kFormat8Bit) + return format; + break; + case Graphics::kFormatRGB555: + case Graphics::kFormatARGB1555: + case Graphics::kFormatRGB565: + typeAccepted = true; + break; + } + + if (!typeAccepted) + continue; + + switch (format & Graphics::kFormatOrderMask) { + case Graphics::kFormatRGB: + case Graphics::kFormatRGBA: + return format; + default: + break; + } + } + return Graphics::kFormat8Bit; +} + +void OSystem_SDL::initFormat(Graphics::ColorFormat format) { + assert(_transactionMode == kTransactionActive); + + //avoid redundant format changes + if (format == _videoMode.format) + return; + + _videoMode.format = format; + _transactionDetails.formatChanged = true; + +} + +//This should only ever be called with a format that is known supported. +Graphics::PixelFormat OSystem_SDL::getPixelFormat(Graphics::ColorFormat format) { + Graphics::PixelFormat result; + switch (format & Graphics::kFormatTypeMask) { + case Graphics::kFormatARGB1555: + result.aLoss = 7; + result.bytesPerPixel = 2; + result.rLoss = result.gLoss = result.bLoss = 3; + case Graphics::kFormatRGB555: + result.aLoss = 8; + result.bytesPerPixel = 2; + result.rLoss = result.gLoss = result.bLoss = 3; + break; + case Graphics::kFormatRGB565: + result.bytesPerPixel = 2; + result.aLoss = 8; + result.gLoss = 2; + result.rLoss = result.bLoss = 3; + break; + case Graphics::kFormat8Bit: + default: + result.bytesPerPixel = 1; + result.rShift = result.gShift = result.bShift = result.aShift = 0; + result.rLoss = result.gLoss = result.bLoss = result.aLoss = 8; + return result; + } + switch (format & Graphics::kFormatOrderMask) + { + default: + case Graphics::kFormatRGBA: + result.aShift = 0; + case Graphics::kFormatRGB: + result.bShift = result.aBits(); + result.gShift = result.bShift + result.bBits(); + result.rShift = result.gShift + result.gBits(); + break; + } + return result; +} +#endif void OSystem_SDL::initSize(uint w, uint h) { assert(_transactionMode == kTransactionActive); @@ -384,9 +515,21 @@ bool OSystem_SDL::loadGFXMode() { // // Create the surface that contains the 8 bit game data // +#ifdef ENABLE_16BIT + _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, + _screenFormat.bytesPerPixel << 3, + ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift , + ((1 << _screenFormat.gBits()) - 1) << _screenFormat.gShift , + ((1 << _screenFormat.bBits()) - 1) << _screenFormat.bShift , + ((1 << _screenFormat.aBits()) - 1) << _screenFormat.aShift ); + if (_screen == NULL) + error("allocating _screen failed"); + +#else _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0); if (_screen == NULL) error("allocating _screen failed"); +#endif // // Create the surface that contains the scaled graphics in 16 bit mode @@ -407,20 +550,6 @@ bool OSystem_SDL::loadGFXMode() { } } -#ifdef ENABLE_16BIT - // - // Create the surface that contains the 16 bit game data - // - _screen16 = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, - 16, - 0x7C00, - 0x3E0, - 0x1F, - 0); //555, not 565 - if (_screen16 == NULL) - error("allocating _screen16 failed"); -#endif - // // Create the surface used for the graphics in 16 bit before scaling, and also the overlay // @@ -498,17 +627,10 @@ bool OSystem_SDL::loadGFXMode() { } void OSystem_SDL::unloadGFXMode() { -#ifdef ENABLE_16BIT - if (_screen16) { - SDL_FreeSurface(_screen16); - _screen16 = NULL; - } -#else if (_screen) { SDL_FreeSurface(_screen); _screen = NULL; } -#endif if (_hwscreen) { SDL_FreeSurface(_hwscreen); @@ -540,22 +662,13 @@ void OSystem_SDL::unloadGFXMode() { } bool OSystem_SDL::hotswapGFXMode() { -#ifdef ENABLE_16BIT - if (!_screen16) -#else if (!_screen) -#endif return false; // Keep around the old _screen & _overlayscreen so we can restore the screen data // after the mode switch. -#ifdef ENABLE_16BIT - SDL_Surface *old_screen = _screen16; - _screen16 = NULL; -#else SDL_Surface *old_screen = _screen; _screen = NULL; -#endif SDL_Surface *old_overlayscreen = _overlayscreen; _overlayscreen = NULL; @@ -574,11 +687,7 @@ bool OSystem_SDL::hotswapGFXMode() { if (!loadGFXMode()) { unloadGFXMode(); -#ifdef ENABLE_16BIT - _screen16 = old_screen; -#else _screen = old_screen; -#endif _overlayscreen = old_overlayscreen; return false; @@ -588,11 +697,7 @@ bool OSystem_SDL::hotswapGFXMode() { SDL_SetColors(_screen, _currentPalette, 0, 256); // Restore old screen content -#ifdef ENABLE_16BIT - SDL_BlitSurface(old_screen, NULL, _screen16, NULL); -#else SDL_BlitSurface(old_screen, NULL, _screen, NULL); -#endif SDL_BlitSurface(old_overlayscreen, NULL, _overlayscreen, NULL); // Free the old surfaces @@ -674,11 +779,7 @@ void OSystem_SDL::internUpdateScreen() { #endif if (!_overlayVisible) { -#ifdef ENABLE_16BIT - origSurf = _screen16; -#else origSurf = _screen; -#endif srcSurf = _tmpscreen; width = _videoMode.screenWidth; height = _videoMode.screenHeight; @@ -823,12 +924,6 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int assert (_transactionMode == kTransactionNone); assert(src); -#ifdef ENABLE_16BIT - if (_screen16 == NULL) { - warning("OSystem_SDL::copyRectToScreen: _screen16 == NULL"); - return; - } -#endif if (_screen == NULL) { warning("OSystem_SDL::copyRectToScreen: _screen == NULL"); return; @@ -877,27 +972,20 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int } // Try to lock the screen surface -#ifdef ENABLE_16BIT - if (SDL_LockSurface(_screen16) == -1) -#else if (SDL_LockSurface(_screen) == -1) -#endif error("SDL_LockSurface failed: %s", SDL_GetError()); #ifdef ENABLE_16BIT - byte *dst = (byte *)_screen16->pixels + y * _videoMode.screenWidth * 2 + x * 2; - if (_videoMode.screenWidth == w && pitch == w * 2) { - memcpy(dst, src, h*w*2); + byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; + if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { + memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); } else { do { - memcpy(dst, src, w * 2); + memcpy(dst, src, w * _screenFormat.bytesPerPixel); src += pitch; - dst += _videoMode.screenWidth * 2; + dst += _videoMode.screenWidth * _screenFormat.bytesPerPixel; } while (--h); } - - // Unlock the screen surface - SDL_UnlockSurface(_screen16); #else byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x; if (_videoMode.screenWidth == pitch && pitch == w) { @@ -909,10 +997,10 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int dst += _videoMode.screenWidth; } while (--h); } +#endif // Unlock the screen surface SDL_UnlockSurface(_screen); -#endif } Graphics::Surface *OSystem_SDL::lockScreen() { @@ -926,24 +1014,16 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _screenIsLocked = true; // Try to lock the screen surface -#ifdef ENABLE_16BIT - if (SDL_LockSurface(_screen16) == -1) -#else if (SDL_LockSurface(_screen) == -1) -#endif error("SDL_LockSurface failed: %s", SDL_GetError()); -#ifdef ENABLE_16BIT - _framebuffer.pixels = _screen16->pixels; - _framebuffer.w = _screen16->w; - _framebuffer.h = _screen16->h; - _framebuffer.pitch = _screen16->pitch; - _framebuffer.bytesPerPixel = 2; -#else _framebuffer.pixels = _screen->pixels; _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; +#ifdef ENABLE_16BIT + _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel; +#else _framebuffer.bytesPerPixel = 1; #endif @@ -958,11 +1038,7 @@ void OSystem_SDL::unlockScreen() { _screenIsLocked = false; // Unlock the screen surface -#ifdef ENABLE_16BIT - SDL_UnlockSurface(_screen16); -#else SDL_UnlockSurface(_screen); -#endif // Trigger a full screen update _forceFull = true; @@ -1133,17 +1209,17 @@ int16 OSystem_SDL::getWidth() { void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { assert(colors); +#ifdef ENABLE_16BIT + if (_screenFormat.bytesPerPixel > 1) + return; //not using a paletted pixel format +#endif + // Setting the palette before _screen is created is allowed - for now - // since we don't actually set the palette until the screen is updated. // But it could indicate a programming error, so let's warn about it. -#ifdef ENABLE_16BIT - if (!_screen16) - warning("OSystem_SDL::setPalette: _screen16 == NULL"); -#else if (!_screen) warning("OSystem_SDL::setPalette: _screen == NULL"); -#endif const byte *b = colors; uint i; @@ -1267,11 +1343,7 @@ void OSystem_SDL::clearOverlay() { dst.x = dst.y = 1; src.w = dst.w = _videoMode.screenWidth; src.h = dst.h = _videoMode.screenHeight; -#ifdef ENABLE_16BIT - if (SDL_BlitSurface(_screen16, &src, _tmpscreen, &dst) != 0) -#else if (SDL_BlitSurface(_screen, &src, _tmpscreen, &dst) != 0) -#endif error("SDL_BlitSurface failed: %s", SDL_GetError()); SDL_LockSurface(_tmpscreen); -- cgit v1.2.3 From b4c44a018b636a9805c725f9a286e58be554afc2 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 10 Jun 2009 08:41:33 +0000 Subject: Code formatting svn-id: r41420 --- backends/platform/sdl/graphics.cpp | 99 ++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 51 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 142fa94dba..4035bdb661 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -375,13 +375,11 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } #ifdef ENABLE_16BIT -Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) -{ +Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) { bool typeAccepted = false; Graphics::ColorFormat format; - while (!formatList.empty() && !typeAccepted) - { + while (!formatList.empty() && !typeAccepted) { typeAccepted = false; format = formatList.front(); @@ -391,28 +389,27 @@ Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List formatList) { +Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List formatList) { bool typeAccepted = false; - Graphics::ColorFormat format; + Graphics::ColorMode format; - while (!formatList.empty() && !typeAccepted) { + while (!formatList.empty()) { typeAccepted = false; format = formatList.front(); @@ -389,33 +366,21 @@ Graphics::ColorFormat OSystem_SDL::findCompatibleFormat(Common::List> 3; - for (int i = byteDepth; i > 1; i--) { - colmask <<= 8; - colmask |= 0xFF; - } - keycolor &= colmask; - _cursorBitDepth = bitDepth; +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { + keycolor &= (1 << (_screenFormat.bytesPerPixel << 3)) - 1; #else void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { #endif @@ -1520,8 +1467,8 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, free(_mouseData); #ifdef ENABLE_16BIT - _mouseData = (byte *)malloc(w * h * byteDepth); - memcpy(_mouseData, buf, w * h * byteDepth); + _mouseData = (byte *)malloc(w * h * _screenFormat.bytesPerPixel); + memcpy(_mouseData, buf, w * h * _screenFormat.bytesPerPixel); #else _mouseData = (byte *)malloc(w * h); memcpy(_mouseData, buf, w * h); @@ -1533,7 +1480,12 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, void OSystem_SDL::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; +#ifdef ENABLE_16BIT + uint32 color; + uint32 colormask = (1 << (_screenFormat.bytesPerPixel << 3)) - 1; +#else byte color; +#endif int w, h, i, j; if (!_mouseOrigSurface || !_mouseData) @@ -1567,20 +1519,20 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { - color = *srcPtr; #ifdef ENABLE_16BIT - if (_cursorBitDepth == 16) { + if (_screenFormat.bytesPerPixel > 1) { + color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw - int8 r = ((*(uint16 *)srcPtr >> 10) & 0x1F) << 3; - int8 g = ((*(uint16 *)srcPtr >> 5) & 0x1F) << 3; - int8 b = (*(uint16 *)srcPtr & 0x1F) << 3; + uint8 r,g,b; + _screenFormat.colorToRGB(color,r,g,b); *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, r, g, b); } dstPtr += 2; - srcPtr += 2; + srcPtr += _screenFormat.bytesPerPixel; } else { #endif + color = *srcPtr; if (color != _mouseKeyColor) { // transparent, don't draw *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, palette[color].r, palette[color].g, palette[color].b); -- cgit v1.2.3 From 2ee51a8fa189fc7817fd6d78533664ec870fca48 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 12 Jun 2009 08:49:45 +0000 Subject: Unfinished proof of concept regarding my compromise with LordHoto in IRC. svn-id: r41464 --- backends/platform/sdl/graphics.cpp | 41 +++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 51f63a364a..e5d8ba4fbc 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -128,7 +128,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { errors |= kTransactionPixelFormatNotSupported; _videoMode.format = _oldVideoMode.format; - _screenFormat = getPixelFormat(_videoMode.format); + _screenFormat = _videoMode.format; #endif } else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) { errors |= kTransactionSizeChangeFailed; @@ -362,7 +362,7 @@ Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List 1) { + if (_cursorFormat.bytesPerPixel > 1) { color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw uint8 r,g,b; - _screenFormat.colorToRGB(color,r,g,b); + _cursorFormat.colorToRGB(color,r,g,b); *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format, r, g, b); } dstPtr += 2; - srcPtr += _screenFormat.bytesPerPixel; + srcPtr += _cursorFormat.bytesPerPixel; } else { #endif color = *srcPtr; -- cgit v1.2.3 From 8d306ebccfa7e88b2e4f4635bff3987e550f98d3 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Mon, 15 Jun 2009 09:45:19 +0000 Subject: Added kUnsupportedColorMode error code brought Scumm engine and SDL backend into compliance with API outlined in http://scummvmupthorn09.wordpress.com/2009/06/14/how-this-is-going-to-work/ Provided convenient Graphics::PixelFormat constructors for ColorMode enums, and bitformat integers. Removed last vestiges (I think) of initial cursor hack. svn-id: r41539 --- backends/platform/sdl/graphics.cpp | 88 -------------------------------------- 1 file changed, 88 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 0d1b3fb8aa..f550621a28 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -352,34 +352,6 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } #ifdef ENABLE_16BIT -Graphics::ColorMode OSystem_SDL::findCompatibleFormat(Common::List formatList) { - bool typeAccepted = false; - Graphics::ColorMode format; - - while (!formatList.empty()) { - typeAccepted = false; - format = formatList.front(); - - //no need to keep searching if the screen - //is already in one of the desired formats - if (getPixelFormat(format) == _videoMode.format) - return format; - - formatList.pop_front(); - switch (format) { - case Graphics::kFormatCLUT8: - if (format == Graphics::kFormatCLUT8) - return format; - break; - case Graphics::kFormatRGB555: - case Graphics::kFormatRGB565: - return format; - break; - } - } - return Graphics::kFormatCLUT8; -} - void OSystem_SDL::initFormat(Graphics::PixelFormat format) { assert(_transactionMode == kTransactionActive); @@ -391,66 +363,6 @@ void OSystem_SDL::initFormat(Graphics::PixelFormat format) { _transactionDetails.formatChanged = true; _screenFormat = format; } - -//TODO: Move this out of OSystem and into Graphics, where engine can access it. -//TODO: ABGR support -Graphics::PixelFormat OSystem_SDL::getPixelFormat(Graphics::ColorMode format) { - Graphics::PixelFormat result; - switch (format) { - case Graphics::kFormatRGB555: - result.aLoss = 8; - result.bytesPerPixel = 2; - result.rLoss = result.gLoss = result.bLoss = 3; - break; - case Graphics::kFormatRGB565: - result.bytesPerPixel = 2; - result.aLoss = 8; - result.gLoss = 2; - result.rLoss = result.bLoss = 3; - break; - case Graphics::kFormatXRGB1555: - //Special case, alpha bit is always high in this mode. - result.aLoss = 7; - result.bytesPerPixel = 2; - result.rLoss = result.gLoss = result.bLoss = 3; - result.bShift = 0; - result.gShift = result.bShift + result.bBits(); - result.rShift = result.gShift + result.gBits(); - result.aShift = result.rShift + result.rBits(); - //HACK: there should be a clean way to handle setting - //up the color order without prematurely returning - return result; - case Graphics::kFormatRGBA4444: - result.bytesPerPixel = 2; - result.aLoss = result.gLoss = result.rLoss = result.bLoss = 4; - break; - case Graphics::kFormatRGB888: - result.bytesPerPixel = 3; - result.aLoss = 8; - result.gLoss = result.rLoss = result.bLoss = 0; - break; - case Graphics::kFormatRGBA6666: - result.bytesPerPixel = 3; - result.aLoss = result.gLoss = result.rLoss = result.bLoss = 2; - break; - case Graphics::kFormatRGBA8888: - result.bytesPerPixel = 4; - result.aLoss = result.gLoss = result.rLoss = result.bLoss = 0; - break; - case Graphics::kFormatCLUT8: - default: - result.bytesPerPixel = 1; - result.rShift = result.gShift = result.bShift = result.aShift = 0; - result.rLoss = result.gLoss = result.bLoss = result.aLoss = 8; - return result; - } - - result.aShift = 0; - result.bShift = result.aBits(); - result.gShift = result.bShift + result.bBits(); - result.rShift = result.gShift + result.gBits(); - return result; -} #endif void OSystem_SDL::initSize(uint w, uint h) { -- cgit v1.2.3 From 0ca17a7f8c79940873a4dc82537310584f03e439 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 15 Jun 2009 11:46:28 +0000 Subject: Fix compilation when 16BIT code is disabled. svn-id: r41543 --- backends/platform/sdl/graphics.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f550621a28..2cee0ea83d 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -155,6 +155,8 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { #ifdef ENABLE_16BIT if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) { +#else + if (_transactionDetails.sizeChanged) { #endif unloadGFXMode(); if (!loadGFXMode()) { -- cgit v1.2.3 From fb96e826f27b071d6696731f43cb5fa0d8760205 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 16 Jun 2009 05:33:11 +0000 Subject: Simplified cursor related 16-bit code. svn-id: r41577 --- backends/platform/sdl/graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 2cee0ea83d..f4269b55b2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1379,11 +1379,11 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -#ifdef ENABLE_16BIT void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { +#ifdef ENABLE_16BIT keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) { + keycolor &= 0xFF; #endif if (w == 0 || h == 0) -- cgit v1.2.3 From f7dd1c15ed38418a0371032966144eb6c2e004cb Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 20 Jun 2009 05:23:09 +0000 Subject: renamed ENABLE_16BIT define to more accurate ENABLE_RGB_COLOR svn-id: r41696 --- backends/platform/sdl/graphics.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f4269b55b2..a08239d472 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -97,7 +97,7 @@ void OSystem_SDL::beginGFXTransaction(void) { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _transactionDetails.formatChanged = false; #endif @@ -123,7 +123,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.mode = _oldVideoMode.mode; _videoMode.scaleFactor = _oldVideoMode.scaleFactor; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { errors |= kTransactionPixelFormatNotSupported; @@ -153,7 +153,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } } -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) { #else if (_transactionDetails.sizeChanged) { @@ -353,7 +353,7 @@ int OSystem_SDL::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR void OSystem_SDL::initFormat(Graphics::PixelFormat format) { assert(_transactionMode == kTransactionActive); @@ -411,7 +411,7 @@ bool OSystem_SDL::loadGFXMode() { // // Create the surface that contains the 8 bit game data // -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, _screenFormat.bytesPerPixel << 3, ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift , @@ -871,7 +871,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int if (SDL_LockSurface(_screen) == -1) error("SDL_LockSurface failed: %s", SDL_GetError()); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); @@ -917,7 +917,7 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel; #else _framebuffer.bytesPerPixel = 1; @@ -1105,7 +1105,7 @@ int16 OSystem_SDL::getWidth() { void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { assert(colors); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR if (_screenFormat.bytesPerPixel > 1) return; //not using a paletted pixel format #endif @@ -1163,7 +1163,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { } _cursorPaletteDisabled = false; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR } void OSystem_SDL::setCursorFormat(Graphics::PixelFormat format) { @@ -1380,7 +1380,7 @@ void OSystem_SDL::warpMouse(int x, int y) { } void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else keycolor &= 0xFF; @@ -1419,7 +1419,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, } free(_mouseData); -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR _mouseData = (byte *)malloc(w * h * _cursorFormat.bytesPerPixel); memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel); #else @@ -1433,7 +1433,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, void OSystem_SDL::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR uint32 color; uint32 colormask = (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else @@ -1472,7 +1472,7 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR if (_cursorFormat.bytesPerPixel > 1) { color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw @@ -1492,7 +1492,7 @@ void OSystem_SDL::blitCursor() { } dstPtr += 2; srcPtr++; -#ifdef ENABLE_16BIT +#ifdef ENABLE_RGB_COLOR } #endif } -- cgit v1.2.3 From 7c622423157e29b7206ba0c39a7756443ed1e70d Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 23 Jun 2009 02:02:51 +0000 Subject: Merged format initialization into InitSize to allow for backends not supporting gfx transactions. svn-id: r41801 --- backends/platform/sdl/graphics.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a08239d472..b5ec9b9db8 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -353,23 +353,22 @@ int OSystem_SDL::getGraphicsMode() const { assert (_transactionMode == kTransactionNone); return _videoMode.mode; } -#ifdef ENABLE_RGB_COLOR -void OSystem_SDL::initFormat(Graphics::PixelFormat format) { + +void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat format) { assert(_transactionMode == kTransactionActive); +#ifdef ENABLE_RGB_COLOR //avoid redundant format changes - if (format == _videoMode.format) - return; + assert(format.bytesPerPixel > 0); - _videoMode.format = format; - _transactionDetails.formatChanged = true; - _screenFormat = format; -} + if (format != _videoMode.format) + { + _videoMode.format = format; + _transactionDetails.formatChanged = true; + _screenFormat = format; + } #endif -void OSystem_SDL::initSize(uint w, uint h) { - assert(_transactionMode == kTransactionActive); - // Avoid redundant res changes if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight) return; -- cgit v1.2.3 From 865129a5630017f05d08e778ba1ef430c23cd55a Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 24 Jun 2009 06:44:30 +0000 Subject: made the cursor's pixel format a member of the cursor object, merged ____CursorFormat functions into equivalent ____Cursor functions. svn-id: r41825 --- backends/platform/sdl/graphics.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index b5ec9b9db8..d7cabd00cc 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1378,8 +1378,10 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat format) { #ifdef ENABLE_RGB_COLOR + if (format.bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else keycolor &= 0xFF; -- cgit v1.2.3 From 27e50db5d7cdbed498d6a61b1ee1ad5405ce33a2 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 26 Jun 2009 10:37:00 +0000 Subject: Converted OSystem::SetMouseCursor to take pointer to PixelFormat, instead of full PixelFormat. Removed OSystem::setCursorFormat (since I forgot to do so several commits ago) svn-id: r41901 --- backends/platform/sdl/graphics.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index d7cabd00cc..f6b4d76418 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1162,15 +1162,7 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) { } _cursorPaletteDisabled = false; -#ifdef ENABLE_RGB_COLOR -} - -void OSystem_SDL::setCursorFormat(Graphics::PixelFormat format) { - assert(format.bytesPerPixel); - _cursorFormat = format; - -#endif -// blitCursor(); + blitCursor(); } @@ -1378,10 +1370,12 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat format) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR - if (format.bytesPerPixel <= _screenFormat.bytesPerPixel) - _cursorFormat = format; + if (!format) + format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else keycolor &= 0xFF; -- cgit v1.2.3 From 853aec05ba4485f0bfc90e7515322dfd56a8d4af Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Sat, 27 Jun 2009 05:58:44 +0000 Subject: changed initGraphics, and OSystem::initSize to take Graphics::PixelFormat * parameters instead of Graphics::PixelFormat parameters, to save unnecessary pixelformat initialization if ENABLE_RGB_COLOR is not set. svn-id: r41909 --- backends/platform/sdl/graphics.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index f6b4d76418..a45f31108b 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -354,18 +354,21 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } -void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat format) { +void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); #ifdef ENABLE_RGB_COLOR //avoid redundant format changes - assert(format.bytesPerPixel > 0); + if (!format) + format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + + assert(format->bytesPerPixel > 0); - if (format != _videoMode.format) + if (*format != _videoMode.format) { - _videoMode.format = format; + _videoMode.format = *format; _transactionDetails.formatChanged = true; - _screenFormat = format; + _screenFormat = *format; } #endif -- cgit v1.2.3 From 9e1916bcad3cc33a870bdbff5bd01b39e523492d Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 30 Jun 2009 07:30:57 +0000 Subject: renamed kTransactionPixelFormatNotSupported to kTransactionFormatNotSupported, retyped all Graphics::PixelFormat * parameters to const Graphics::PixelFormat *, (hopefully) repaired all memory leaks on screen and cursor format changes, provided OSystem::getScreenFormat and OSystem::getSupportedFormats methods for when ENABLE_RGB_COLOR is not set, completely forgot the "commit early, commit often" mantra. svn-id: r41972 --- backends/platform/sdl/graphics.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a45f31108b..27f32ee8d2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -125,7 +125,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.scaleFactor = _oldVideoMode.scaleFactor; #ifdef ENABLE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { - errors |= kTransactionPixelFormatNotSupported; + errors |= kTransactionFormatNotSupported; _videoMode.format = _oldVideoMode.format; _screenFormat = _videoMode.format; @@ -354,21 +354,24 @@ int OSystem_SDL::getGraphicsMode() const { return _videoMode.mode; } -void OSystem_SDL::initSize(uint w, uint h, Graphics::PixelFormat *format) { +void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); #ifdef ENABLE_RGB_COLOR //avoid redundant format changes + Graphics::PixelFormat newFormat; if (!format) - format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + newFormat = Graphics::PixelFormat::createFormatCLUT8(); + else + newFormat = *format; - assert(format->bytesPerPixel > 0); + assert(newFormat.bytesPerPixel > 0); - if (*format != _videoMode.format) + if (newFormat != _videoMode.format) { - _videoMode.format = *format; + _videoMode.format = newFormat; _transactionDetails.formatChanged = true; - _screenFormat = *format; + _screenFormat = newFormat; } #endif @@ -1373,11 +1376,11 @@ void OSystem_SDL::warpMouse(int x, int y) { } } -void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, Graphics::PixelFormat *format) { +void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR if (!format) - format = new Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); - if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) + _cursorFormat = Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else -- cgit v1.2.3 From 2c5d11b67b35f93b2292c1ca56d0c9fc89608921 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 7 Jul 2009 07:50:40 +0000 Subject: Removed PixelFormat convenience constructors at behest of Max and Eugene. svn-id: r42207 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 27f32ee8d2..95a3276fa5 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -361,7 +361,7 @@ void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) //avoid redundant format changes Graphics::PixelFormat newFormat; if (!format) - newFormat = Graphics::PixelFormat::createFormatCLUT8(); + newFormat = Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0); else newFormat = *format; -- cgit v1.2.3 From 828ed66555b99363fed62b4cbb83c36de68c3024 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Wed, 8 Jul 2009 16:07:58 +0000 Subject: Reinstated static inline Graphics::PixelFormat::createFormatCLUT8(), which I am told was not supposed to be removed with the others. svn-id: r42268 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 95a3276fa5..27f32ee8d2 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -361,7 +361,7 @@ void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) //avoid redundant format changes Graphics::PixelFormat newFormat; if (!format) - newFormat = Graphics::PixelFormat(1, 8, 8, 8, 8, 0, 0, 0, 0); + newFormat = Graphics::PixelFormat::createFormatCLUT8(); else newFormat = *format; -- cgit v1.2.3 From a4f3a8390068fc372a96d4473b91eb09158353ef Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Thu, 9 Jul 2009 09:10:05 +0000 Subject: corrected creation of one Graphics::PixelFormat to reflect the resurrection of Graphics::PixelFormat::createFormatCLUT8 svn-id: r42282 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 27f32ee8d2..3029f43d87 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1379,7 +1379,7 @@ void OSystem_SDL::warpMouse(int x, int y) { void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR if (!format) - _cursorFormat = Graphics::PixelFormat(1,8,8,8,8,0,0,0,0); + _cursorFormat = Graphics::PixelFormat::createFormatCLUT8; else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; -- cgit v1.2.3 From ff208c5387a8566546a384afa9ab48c0a1f356a0 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 9 Jul 2009 17:25:06 +0000 Subject: fix compile svn-id: r42308 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 3029f43d87..fa162a6348 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -1379,7 +1379,7 @@ void OSystem_SDL::warpMouse(int x, int y) { void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { #ifdef ENABLE_RGB_COLOR if (!format) - _cursorFormat = Graphics::PixelFormat::createFormatCLUT8; + _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) _cursorFormat = *format; keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; -- cgit v1.2.3 From a5d374bded6204c9250155d572d23b0caef636a5 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 10 Jul 2009 06:46:50 +0000 Subject: Moved OSystem_SDL::getSupportedFormats function body from platforms/sdl/sdl.h to platforms/sdl/graphics.cpp, Improved and simplified list-generation method for OSystem_SDL::getSupportedFormats. svn-id: r42325 --- backends/platform/sdl/graphics.cpp | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index fa162a6348..61f33569af 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -26,6 +26,9 @@ #include "backends/platform/sdl/sdl.h" #include "common/mutex.h" #include "common/util.h" +#ifdef ENABLE_RGB_COLOR +#include "common/list.h" +#endif #include "graphics/font.h" #include "graphics/fontman.h" #include "graphics/scaler.h" @@ -206,6 +209,73 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { return (TransactionError)errors; } +#ifdef ENABLE_RGB_COLOR +const Graphics::PixelFormat RGBList[] = { +#ifdef ENABLE_32BIT + // RGBA8888, ARGB8888, RGB888 + Graphics::PixelFormat(4, 0, 0, 0, 0, 24, 16, 8, 0), + Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24), + Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0), +#endif + // RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444 + Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0), + Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15), + Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) +}; +const Graphics::PixelFormat BGRList[] = { +#ifdef ENABLE_32BIT + // ABGR8888, BGRA8888, BGR888 + Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24), + Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0), + Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0), +#endif + // BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444 + Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0), + Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15), + Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0), + Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12), + Graphics::PixelFormat(2, 3, 3, 3, 8, 4, 8, 12, 0) +}; + +// TODO: prioritize matching alpha masks +Common::List OSystem_SDL::getSupportedFormats() { + static Common::List list; + if (!list.empty()) + return list; + bool BGR = false; + int listLength = ARRAYSIZE(RGBList); + + // Get our currently set format + Graphics::PixelFormat format(_hwscreen->format->BytesPerPixel, + _hwscreen->format->Rloss, _hwscreen->format->Gloss, + _hwscreen->format->Bloss, _hwscreen->format->Aloss, + _hwscreen->format->Rshift, _hwscreen->format->Gshift, + _hwscreen->format->Bshift, _hwscreen->format->Ashift); + + // Push it first, as the prefered format. + list.push_back(format); + if (format.bShift > format.rShift) + BGR = true; + for (int i = 0; i < listLength; i++) { + if (RGBList[i].bytesPerPixel > format.bytesPerPixel) + continue; + if (BGR) { + if (BGRList[i] != format) + list.push_back(BGRList[i]); + list.push_back(RGBList[i]); + } else { + if (RGBList[i] != format) + list.push_back(RGBList[i]); + list.push_back(BGRList[i]); + } + } + list.push_back(Graphics::PixelFormat::createFormatCLUT8()); + return list; +} +#endif + bool OSystem_SDL::setGraphicsMode(int mode) { Common::StackLock lock(_graphicsMutex); -- cgit v1.2.3 From 02e639ea0ceaa4b6a530847dbb043a5c2352e4a2 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 10 Jul 2009 19:55:06 +0000 Subject: Fixed a couple of errors in the new getSupportedFormats implementation. svn-id: r42350 --- backends/platform/sdl/graphics.cpp | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 61f33569af..ea9c285a44 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -242,22 +242,37 @@ const Graphics::PixelFormat BGRList[] = { // TODO: prioritize matching alpha masks Common::List OSystem_SDL::getSupportedFormats() { static Common::List list; - if (!list.empty()) + static bool inited = false; + + if (inited) return list; + bool BGR = false; int listLength = ARRAYSIZE(RGBList); - // Get our currently set format - Graphics::PixelFormat format(_hwscreen->format->BytesPerPixel, - _hwscreen->format->Rloss, _hwscreen->format->Gloss, - _hwscreen->format->Bloss, _hwscreen->format->Aloss, - _hwscreen->format->Rshift, _hwscreen->format->Gshift, - _hwscreen->format->Bshift, _hwscreen->format->Ashift); - - // Push it first, as the prefered format. - list.push_back(format); - if (format.bShift > format.rShift) - BGR = true; + Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8(); + if (_hwscreen) { + // Get our currently set hardware format + format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel, + _hwscreen->format->Rloss, _hwscreen->format->Gloss, + _hwscreen->format->Bloss, _hwscreen->format->Aloss, + _hwscreen->format->Rshift, _hwscreen->format->Gshift, + _hwscreen->format->Bshift, _hwscreen->format->Ashift); + + // Workaround to MacOSX SDL not providing an accurate Aloss value. + if (_hwscreen->format->Amask == 0) + format.aLoss = 8; + + // Push it first, as the prefered format. + list.push_back(format); + + if (format.bShift > format.rShift) + BGR = true; + + // Mark that we don't need to do this any more. + inited = true; + } + for (int i = 0; i < listLength; i++) { if (RGBList[i].bytesPerPixel > format.bytesPerPixel) continue; -- cgit v1.2.3 From 70c138651dc71f886a4314943c4e9a753dc44607 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Fri, 10 Jul 2009 19:56:40 +0000 Subject: Whoops, and one more. svn-id: r42351 --- backends/platform/sdl/graphics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index ea9c285a44..a090db01b6 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -274,7 +274,7 @@ Common::List OSystem_SDL::getSupportedFormats() { } for (int i = 0; i < listLength; i++) { - if (RGBList[i].bytesPerPixel > format.bytesPerPixel) + if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel)) continue; if (BGR) { if (BGRList[i] != format) -- cgit v1.2.3 From cdf751accda346f5d96e3fdfa2fd4a1b92ed4d19 Mon Sep 17 00:00:00 2001 From: Jody Northup Date: Tue, 14 Jul 2009 08:27:36 +0000 Subject: changed generic Graphics::PixelFormat constructor to take xBits instead of xLoss. Modified OSystem_SDL::getSupportedFormats and ScummEngine::init to account for this change. svn-id: r42467 --- backends/platform/sdl/graphics.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index a090db01b6..4e47db0827 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -213,30 +213,30 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { const Graphics::PixelFormat RGBList[] = { #ifdef ENABLE_32BIT // RGBA8888, ARGB8888, RGB888 - Graphics::PixelFormat(4, 0, 0, 0, 0, 24, 16, 8, 0), - Graphics::PixelFormat(4, 0, 0, 0, 0, 16, 8, 0, 24), - Graphics::PixelFormat(3, 0, 0, 0, 8, 16, 8, 0, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24), + Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0), #endif // RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444 - Graphics::PixelFormat(2, 3, 2, 3, 8, 11, 5, 0, 0), - Graphics::PixelFormat(2, 3, 3, 3, 7, 10, 5, 0, 15), - Graphics::PixelFormat(2, 3, 3, 3, 8, 10, 5, 0, 0), + Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0), + Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15), + Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0), Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0), Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12) }; const Graphics::PixelFormat BGRList[] = { #ifdef ENABLE_32BIT // ABGR8888, BGRA8888, BGR888 - Graphics::PixelFormat(4, 0, 0, 0, 0, 0, 8, 16, 24), - Graphics::PixelFormat(4, 0, 0, 0, 0, 8, 16, 24, 0), - Graphics::PixelFormat(3, 0, 0, 0, 8, 0, 8, 16, 0), + Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24), + Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0), + Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0), #endif // BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444 - Graphics::PixelFormat(2, 3, 2, 3, 8, 0, 5, 11, 0), - Graphics::PixelFormat(2, 3, 3, 3, 7, 0, 5, 10, 15), - Graphics::PixelFormat(2, 3, 3, 3, 8, 0, 5, 10, 0), + Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0), + Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15), + Graphics::PixelFormat(2, 5, 5, 5, 0, 0, 5, 10, 0), Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12), - Graphics::PixelFormat(2, 3, 3, 3, 8, 4, 8, 12, 0) + Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0) }; // TODO: prioritize matching alpha masks -- cgit v1.2.3 From 52a160657f4db676e30b6d52abbf513154aad662 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sun, 19 Jul 2009 15:00:39 +0000 Subject: Fix 16bit color when using the hardware screen's pixel format. The call was never updated after r42467. svn-id: r42617 --- backends/platform/sdl/graphics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 4e47db0827..6d9f3fc6eb 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -254,8 +254,8 @@ Common::List OSystem_SDL::getSupportedFormats() { if (_hwscreen) { // Get our currently set hardware format format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel, - _hwscreen->format->Rloss, _hwscreen->format->Gloss, - _hwscreen->format->Bloss, _hwscreen->format->Aloss, + 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); -- cgit v1.2.3 From 007f68366fd55a519753bf533c7c3a80db3754f0 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Fri, 21 Aug 2009 18:16:37 +0000 Subject: Renamed ENABLE_RGB_COLOR to USE_RGB_COLOR, and added it to config.h to guarantee a consistent build. svn-id: r43604 --- backends/platform/sdl/graphics.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index 3bfe8f5c98..d3a37f4de7 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -26,7 +26,7 @@ #include "backends/platform/sdl/sdl.h" #include "common/mutex.h" #include "common/util.h" -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR #include "common/list.h" #endif #include "graphics/font.h" @@ -100,7 +100,7 @@ void OSystem_SDL::beginGFXTransaction(void) { _transactionDetails.needUpdatescreen = false; _transactionDetails.normal1xScaler = false; -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR _transactionDetails.formatChanged = false; #endif @@ -126,7 +126,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { _videoMode.mode = _oldVideoMode.mode; _videoMode.scaleFactor = _oldVideoMode.scaleFactor; -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR } else if (_videoMode.format != _oldVideoMode.format) { errors |= kTransactionFormatNotSupported; @@ -156,7 +156,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { } } -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) { #else if (_transactionDetails.sizeChanged) { @@ -209,7 +209,7 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) { return (TransactionError)errors; } -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR const Graphics::PixelFormat RGBList[] = { #ifdef ENABLE_32BIT // RGBA8888, ARGB8888, RGB888 @@ -442,7 +442,7 @@ int OSystem_SDL::getGraphicsMode() const { void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) { assert(_transactionMode == kTransactionActive); -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR //avoid redundant format changes Graphics::PixelFormat newFormat; if (!format) @@ -543,7 +543,7 @@ bool OSystem_SDL::loadGFXMode() { // // Create the surface that contains the 8 bit game data // -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, _screenFormat.bytesPerPixel << 3, ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift , @@ -1007,7 +1007,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int if (SDL_LockSurface(_screen) == -1) error("SDL_LockSurface failed: %s", SDL_GetError()); -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel; if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) { memcpy(dst, src, h*w*_screenFormat.bytesPerPixel); @@ -1053,7 +1053,7 @@ Graphics::Surface *OSystem_SDL::lockScreen() { _framebuffer.w = _screen->w; _framebuffer.h = _screen->h; _framebuffer.pitch = _screen->pitch; -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel; #else _framebuffer.bytesPerPixel = 1; @@ -1241,7 +1241,7 @@ int16 OSystem_SDL::getWidth() { void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) { assert(colors); -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR if (_screenFormat.bytesPerPixel > 1) return; //not using a paletted pixel format #endif @@ -1508,7 +1508,7 @@ void OSystem_SDL::warpMouse(int x, int y) { } void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) { -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR if (!format) _cursorFormat = Graphics::PixelFormat::createFormatCLUT8(); else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel) @@ -1551,7 +1551,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, } free(_mouseData); -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR _mouseData = (byte *)malloc(w * h * _cursorFormat.bytesPerPixel); memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel); #else @@ -1565,7 +1565,7 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, void OSystem_SDL::blitCursor() { byte *dstPtr; const byte *srcPtr = _mouseData; -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR uint32 color; uint32 colormask = (1 << (_cursorFormat.bytesPerPixel << 3)) - 1; #else @@ -1604,7 +1604,7 @@ void OSystem_SDL::blitCursor() { for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR if (_cursorFormat.bytesPerPixel > 1) { color = (*(uint32 *) srcPtr) & colormask; if (color != _mouseKeyColor) { // transparent, don't draw @@ -1624,7 +1624,7 @@ void OSystem_SDL::blitCursor() { } dstPtr += 2; srcPtr++; -#ifdef ENABLE_RGB_COLOR +#ifdef USE_RGB_COLOR } #endif } -- cgit v1.2.3 From 70ccc47accf0563ca793f9d0d03fa6908afbfd99 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Fri, 21 Aug 2009 23:04:06 +0000 Subject: Removed redundant checks, the asserts() earlier do exactly the same. svn-id: r43622 --- backends/platform/sdl/graphics.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'backends/platform/sdl/graphics.cpp') diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp index d3a37f4de7..a67e35cf73 100644 --- a/backends/platform/sdl/graphics.cpp +++ b/backends/platform/sdl/graphics.cpp @@ -975,30 +975,6 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int * and just updates those, on the actual display. */ addDirtyRgnAuto(src); } else { - /* Clip the coordinates */ - if (x < 0) { - w += x; - src -= x; - x = 0; - } - - if (y < 0) { - h += y; - src -= y * pitch; - y = 0; - } - - if (w > _videoMode.screenWidth - x) { - w = _videoMode.screenWidth - x; - } - - if (h > _videoMode.screenHeight - y) { - h = _videoMode.screenHeight - y; - } - - if (w <= 0 || h <= 0) - return; - _cksumValid = false; addDirtyRect(x, y, w, h); } -- cgit v1.2.3