From 73b66c60f873e80f327ddafb052d07bc8da79615 Mon Sep 17 00:00:00 2001 From: Kaloyan Chehlarski Date: Mon, 2 Oct 2023 12:19:09 +0300 Subject: [PATCH] BACKENDS: WII: Always retain cursor palette Calling setMouseCursor with a non-palette cursor no longer clears the cursor palette, allowing a subsequent call with a paletted cursor to re-use it. This fixes Trac defect #13895. The approach taken was to just copy what the OpenGL backend was doing in the same situation. --- backends/platform/wii/osystem_gfx.cpp | 40 ++++++++++----------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/backends/platform/wii/osystem_gfx.cpp b/backends/platform/wii/osystem_gfx.cpp index 4c32bf7d000..bc5c10b1688 100644 --- a/backends/platform/wii/osystem_gfx.cpp +++ b/backends/platform/wii/osystem_gfx.cpp @@ -334,8 +334,13 @@ void OSystem_Wii::updateMousePalette() { printf("%s() _cursorPaletteDisabled:%d\n", __func__, _cursorPaletteDisabled); #endif - if (_texMouse.palette && _cursorPaletteDisabled) { - memcpy(_texMouse.palette, _cursorPalette, 256 * 2); + if (_texMouse.palette) { + if (!_cursorPaletteDisabled) { + memcpy(_texMouse.palette, _cursorPalette, 256 * 2); + } else { + memcpy(_texMouse.palette, _texGame.palette, 256 * 2); + } + _cursorPaletteDirty = true; } } @@ -357,20 +362,7 @@ void OSystem_Wii::setPalette(const byte *colors, uint start, uint num) { gfx_tex_flush_palette(&_texGame); - s = colors; - d = _cursorPalette; - - for (uint i = 0; i < num; ++i, s += 3) { - d[start + i] = _pfRGB3444.ARGBToColor(0xff, s[0], s[1], s[2]); - } - - if (_cursorPaletteDisabled) { - assert(_texMouse.palette); - - memcpy((u8 *)_texMouse.palette + start * 2, (u8 *)_cursorPalette + start * 2, num * 2); - - _cursorPaletteDirty = true; - } + updateMousePalette(); } void OSystem_Wii::grabPalette(byte *colors, uint start, uint num) const { @@ -407,18 +399,16 @@ void OSystem_Wii::setCursorPalette(const byte *colors, uint start, uint num) { gfx_tex_set_bilinear_filter(&_texMouse, _bilinearFilter); } - if (_cursorPaletteDisabled) { - memcpy(_cursorPalette, _texMouse.palette, 256 * 2); - _cursorPaletteDisabled = false; - } + _cursorPaletteDisabled = false; const byte *s = colors; - u16 *d = _texMouse.palette; + u16 *d = _cursorPalette; - for (uint i = 0; i < num; ++i, s += 3) + for (uint i = 0; i < num; ++i, s += 3) { d[start + i] = _pfRGB3444.ARGBToColor(0xff, s[0], s[1], s[2]); + } - _cursorPaletteDirty = true; + updateMousePalette(); } void OSystem_Wii::copyRectToScreen(const void *buf, int pitch, int x, int y, @@ -788,6 +778,6 @@ void OSystem_Wii::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, _mouseHotspotY = hotspotY; _cursorDontScale = dontScale; - if ((_texMouse.palette) && (oldKeycolor != _mouseKeyColor)) - _cursorPaletteDirty = true; + if (_pfCursor.bytesPerPixel == 1 && oldKeycolor != _mouseKeyColor) + updateMousePalette(); }