[Scummvm-git-logs] scummvm master -> 3454d4988ce104db5c1bb3a3404992bbd015ae62
bluegr
noreply at scummvm.org
Wed Jul 17 07:57:45 UTC 2024
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
3454d4988c GRAPHICS: Disable colorKey when applying a mask to a RGB cursor in SurfaceSdl
Commit: 3454d4988ce104db5c1bb3a3404992bbd015ae62
https://github.com/scummvm/scummvm/commit/3454d4988ce104db5c1bb3a3404992bbd015ae62
Author: Simon Delamarre (simon.delamarre14 at gmail.com)
Date: 2024-07-17T10:57:41+03:00
Commit Message:
GRAPHICS: Disable colorKey when applying a mask to a RGB cursor in SurfaceSdl
To apply a mask to a RGB (non-paletted) cursor in SurfaceSdl, we use an
intermediary masked_image, where the pixels made transparent by the mask
are replaced by an ARGB color with alpha = 0 (ARGB 0x00000000 in practice).
However the cursor surface still has a key color attached to it by
SDL_SetColorKey (set to 0 currently), which is not sensitive to the alpha
channel, wrongly making opaque black ARGB 0xFF000000 transparent as well.
So we provide an option to disable the key color in such a case.
Changed paths:
backends/graphics/surfacesdl/surfacesdl-graphics.cpp
backends/graphics/surfacesdl/surfacesdl-graphics.h
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
index 64361750cdd..87edfff96a2 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp
@@ -138,7 +138,7 @@ SurfaceSdlGraphicsManager::SurfaceSdlGraphicsManager(SdlEventSource *sdlEventSou
_scalerPlugins(ScalerMan.getPlugins()), _scalerPlugin(nullptr), _scaler(nullptr),
_needRestoreAfterOverlay(false), _isInOverlayPalette(false), _isDoubleBuf(false), _prevForceRedraw(false), _numPrevDirtyRects(0),
_prevCursorNeedsRedraw(false),
- _mouseKeyColor(0) {
+ _mouseKeyColor(0), _disableMouseKeyColor(false) {
// allocate palette storage
_currentPalette = (SDL_Color *)calloc(sizeof(SDL_Color), 256);
@@ -2028,7 +2028,7 @@ void SurfaceSdlGraphicsManager::copyRectToOverlay(const void *buf, int pitch, in
#pragma mark --- Mouse ---
#pragma mark -
-void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keyColor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
+void SurfaceSdlGraphicsManager::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) {
if (mask && (!format || format->bytesPerPixel == 1)) {
// 8-bit masked cursor, SurfaceSdl has no alpha mask support so we must convert this to color key
@@ -2068,7 +2068,7 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
maskedImage[i] = static_cast<byte>(bestKey);
}
- setMouseCursor(&maskedImage[0], w, h, hotspotX, hotspotY, bestKey, dontScale, format, nullptr);
+ setMouseCursor(&maskedImage[0], w, h, hotspotX, hotspotY, bestKey, dontScale, format, nullptr, disableKeyColor);
return;
}
@@ -2119,7 +2119,8 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
memcpy(&maskedImage[i * outBPP], outColorPtr, outBPP);
}
- setMouseCursor(&maskedImage[0], w, h, hotspotX, hotspotY, 0, dontScale, &formatWithAlpha, nullptr);
+ // Disable the key color because SDL_SetColorKey ignores the alpha channel, which would make 0xFF000000 transparent
+ setMouseCursor(&maskedImage[0], w, h, hotspotX, hotspotY, 0, dontScale, &formatWithAlpha, nullptr, true);
return;
}
#endif
@@ -2149,8 +2150,9 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
bool keycolorChanged = false;
- if (_mouseKeyColor != keyColor) {
+ if (_mouseKeyColor != keyColor || _disableMouseKeyColor != disableKeyColor) {
_mouseKeyColor = keyColor;
+ _disableMouseKeyColor = disableKeyColor;
keycolorChanged = true;
}
@@ -2210,7 +2212,8 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
}
if (keycolorChanged) {
- SDL_SetColorKey(_mouseOrigSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _mouseKeyColor);
+ uint32 flags = _disableMouseKeyColor ? 0 : SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA;
+ SDL_SetColorKey(_mouseOrigSurface, flags, _mouseKeyColor);
}
SDL_LockSurface(_mouseOrigSurface);
@@ -2236,6 +2239,10 @@ void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h,
blitCursor();
}
+void SurfaceSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keyColor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
+ setMouseCursor(buf, w, h, hotspotX, hotspotY, keyColor, dontScale, format, mask, false);
+}
+
void SurfaceSdlGraphicsManager::blitCursor() {
const int w = _mouseCurState.w;
const int h = _mouseCurState.h;
@@ -2303,7 +2310,8 @@ void SurfaceSdlGraphicsManager::blitCursor() {
}
SDL_SetColors(_mouseSurface, _cursorPaletteDisabled ? _currentPalette : _cursorPalette, 0, 256);
- SDL_SetColorKey(_mouseSurface, SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA, _mouseKeyColor);
+ uint32 flags = _disableMouseKeyColor ? 0 : SDL_RLEACCEL | SDL_SRCCOLORKEY | SDL_SRCALPHA;
+ SDL_SetColorKey(_mouseSurface, flags, _mouseKeyColor);
SDL_LockSurface(_mouseOrigSurface);
SDL_LockSurface(_mouseSurface);
@@ -2921,7 +2929,7 @@ int SurfaceSdlGraphicsManager::SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, U
}
int SurfaceSdlGraphicsManager::SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key) {
- return ::SDL_SetColorKey(surface, SDL_TRUE, key) ? -1 : 0;
+ return ::SDL_SetColorKey(surface, flag ? SDL_TRUE : SDL_FALSE, key) ? -1 : 0;
}
#endif // SDL_VERSION_ATLEAST(2, 0, 0)
diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.h b/backends/graphics/surfacesdl/surfacesdl-graphics.h
index 57afc8f0622..58cc9fda99a 100644
--- a/backends/graphics/surfacesdl/surfacesdl-graphics.h
+++ b/backends/graphics/surfacesdl/surfacesdl-graphics.h
@@ -114,6 +114,7 @@ public:
int16 getOverlayWidth() const override { return _videoMode.overlayWidth; }
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;
+ 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);
void setCursorPalette(const byte *colors, uint start, uint num) override;
#ifdef USE_OSD
@@ -384,6 +385,7 @@ protected:
#else
byte _mouseKeyColor;
#endif
+ bool _disableMouseKeyColor;
byte _mappedMouseKeyColor;
bool _cursorDontScale;
bool _cursorPaletteDisabled;
More information about the Scummvm-git-logs
mailing list