From d690eee7c5eeb68456c21f146b1749c2e2de652f Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Sat, 12 Oct 2024 10:59:12 +0100 Subject: [PATCH] SDL1: Avoid redundant palette update When the display surface is 8-bit, skips a redundant call to `SDL_SetPalette`. --- Source/utils/sdl_compat.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/utils/sdl_compat.h b/Source/utils/sdl_compat.h index bf1d79d4ff5..d70bbee5a72 100644 --- a/Source/utils/sdl_compat.h +++ b/Source/utils/sdl_compat.h @@ -75,7 +75,9 @@ inline int SDLC_SetSurfaceAndPaletteColors(SDL_Surface *surface, SDL_Palette *pa #if SDL1_VIDEO_MODE_BPP == 8 // When the video surface is 8bit, we need to set the output palette as well. - SDL_SetColors(SDL_GetVideoSurface(), colors, firstcolor, ncolors); + const Surface *videoSurface = SDL_GetVideoSurface(); + SDL_SetColors(videoSurface, colors, firstcolor, ncolors); + if (videoSurface == surface) return 0; #endif // In SDL1, the surface always has its own distinct palette, so we need to // update it as well.