diff --git a/Source/DiabloUI/art_draw.cpp b/Source/DiabloUI/art_draw.cpp index fcc0913fb..06b74abc9 100644 --- a/Source/DiabloUI/art_draw.cpp +++ b/Source/DiabloUI/art_draw.cpp @@ -16,7 +16,7 @@ void UpdatePalette(Art *art, const SDL_Surface *output) return; if (output == nullptr || output->format->BitsPerPixel != 8) - output = pal_surface; + output = PalSurface; if (SDLC_SetSurfaceColors(art->surface.get(), output->format->palette) <= -1) ErrSdl(); diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 2d1e064e4..ff8a0c32a 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -635,7 +635,7 @@ void LoadBackgroundArt(const char *pszFile, int frames) BlackPalette(); SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000); - if (DiabloUiSurface() == pal_surface) + if (DiabloUiSurface() == PalSurface) BltFast(nullptr, nullptr); RenderPresent(); } @@ -672,7 +672,7 @@ void UiFadeIn() SetFadeLevel(fadeValue); } - if (DiabloUiSurface() == pal_surface) + if (DiabloUiSurface() == PalSurface) BltFast(nullptr, nullptr); RenderPresent(); } diff --git a/Source/DiabloUI/diabloui.h b/Source/DiabloUI/diabloui.h index 9b5a8ff60..29a8eaf2a 100644 --- a/Source/DiabloUI/diabloui.h +++ b/Source/DiabloUI/diabloui.h @@ -86,7 +86,7 @@ inline SDL_Surface *DiabloUiSurface() // to an off-screen surface first to avoid flickering / tearing. if ((output_surface->flags & SDL_HWSURFACE) != 0 && (output_surface->flags & SDL_DOUBLEBUF) == 0) { - return pal_surface; + return PalSurface; } #endif diff --git a/Source/dx.cpp b/Source/dx.cpp index dba3502dd..ccf63e3d7 100644 --- a/Source/dx.cpp +++ b/Source/dx.cpp @@ -35,9 +35,12 @@ unsigned int pal_surface_palette_version = 0; SDLSurfaceUniquePtr RendererTextureSurface; /** 8-bit surface that we render to */ -SDL_Surface *pal_surface; +SDL_Surface *PalSurface; +namespace { +SDLSurfaceUniquePtr PinnedPalSurface; +} // namespace -/** Whether we render directly to the screen surface, i.e. `pal_surface == GetOutputSurface()` */ +/** Whether we render directly to the screen surface, i.e. `PalSurface == GetOutputSurface()` */ bool RenderDirectlyToOutputSurface; namespace { @@ -68,26 +71,24 @@ void CreateBackBuffer() { if (CanRenderDirectlyToOutputSurface()) { Log("{}", "Will render directly to the SDL output surface"); - pal_surface = GetOutputSurface(); + PalSurface = GetOutputSurface(); RenderDirectlyToOutputSurface = true; } else { - pal_surface = SDL_CreateRGBSurfaceWithFormat( + PinnedPalSurface = SDLWrap::CreateRGBSurfaceWithFormat( /*flags=*/0, /*width=*/gnScreenWidth, /*height=*/gnScreenHeight, /*depth=*/8, SDL_PIXELFORMAT_INDEX8); - if (pal_surface == nullptr) { - ErrSdl(); - } + PalSurface = PinnedPalSurface.get(); } #ifndef USE_SDL1 - // In SDL2, `pal_surface` points to the global `palette`. - if (SDL_SetSurfacePalette(pal_surface, Palette.get()) < 0) + // In SDL2, `PalSurface` points to the global `palette`. + if (SDL_SetSurfacePalette(PalSurface, Palette.get()) < 0) ErrSdl(); #else - // In SDL1, `pal_surface` owns its palette and we must update it every + // In SDL1, `PalSurface` owns its palette and we must update it every // time the global `palette` is changed. No need to do anything here as // the global `palette` doesn't have any colors set yet. #endif @@ -189,7 +190,7 @@ Surface GlobalBackBuffer() return Surface(); } - return Surface(pal_surface, SDL_Rect { 0, 0, gnScreenWidth, gnScreenHeight }); + return Surface(PalSurface, SDL_Rect { 0, 0, gnScreenWidth, gnScreenHeight }); } void dx_cleanup() @@ -202,10 +203,10 @@ void dx_cleanup() sgdwLockCount = 0; MemCrit.unlock(); - if (pal_surface == nullptr) + if (PalSurface == nullptr) return; - SDL_FreeSurface(pal_surface); - pal_surface = nullptr; + PalSurface = nullptr; + PinnedPalSurface = nullptr; Palette = nullptr; RendererTextureSurface = nullptr; #ifndef USE_SDL1 @@ -247,7 +248,7 @@ void BltFast(SDL_Rect *srcRect, SDL_Rect *dstRect) { if (RenderDirectlyToOutputSurface) return; - Blit(pal_surface, srcRect, dstRect); + Blit(PalSurface, srcRect, dstRect); } void Blit(SDL_Surface *src, SDL_Rect *srcRect, SDL_Rect *dstRect) @@ -342,7 +343,7 @@ void RenderPresent() ErrSdl(); } if (RenderDirectlyToOutputSurface) - pal_surface = GetOutputSurface(); + PalSurface = GetOutputSurface(); LimitFrameRate(); #endif } diff --git a/Source/dx.h b/Source/dx.h index be3e8bc20..8b9bc8282 100644 --- a/Source/dx.h +++ b/Source/dx.h @@ -9,7 +9,7 @@ namespace devilution { -/** Whether we render directly to the screen surface, i.e. `pal_surface == GetOutputSurface()` */ +/** Whether we render directly to the screen surface, i.e. `PalSurface == GetOutputSurface()` */ extern bool RenderDirectlyToOutputSurface; Surface GlobalBackBuffer(); diff --git a/Source/palette.cpp b/Source/palette.cpp index 7b5a16892..6926979ff 100644 --- a/Source/palette.cpp +++ b/Source/palette.cpp @@ -163,7 +163,7 @@ void CycleColorsReverse(int from, int to) void palette_update(int first, int ncolor) { assert(Palette); - if (SDLC_SetSurfaceAndPaletteColors(pal_surface, Palette.get(), system_palette, first, ncolor) < 0) { + if (SDLC_SetSurfaceAndPaletteColors(PalSurface, Palette.get(), system_palette, first, ncolor) < 0) { ErrSdl(); } pal_surface_palette_version++; diff --git a/Source/scrollrt.cpp b/Source/scrollrt.cpp index a591b376d..cafcd0744 100644 --- a/Source/scrollrt.cpp +++ b/Source/scrollrt.cpp @@ -1552,14 +1552,14 @@ void CalcViewportGeometry() tileRows++; // Cover lower edge saw tooth, right edge accounted for in scrollrt_draw() } -extern SDL_Surface *pal_surface; +extern SDL_Surface *PalSurface; void ClearScreenBuffer() { lock_buf(3); - assert(pal_surface != nullptr); - SDL_FillRect(pal_surface, nullptr, 0); + assert(PalSurface != nullptr); + SDL_FillRect(PalSurface, nullptr, 0); unlock_buf(3); } diff --git a/Source/utils/display.h b/Source/utils/display.h index 58ee24ff2..7ccc46a8d 100644 --- a/Source/utils/display.h +++ b/Source/utils/display.h @@ -23,7 +23,7 @@ extern SDLTextureUniquePtr texture; #endif extern SDLPaletteUniquePtr Palette; -extern SDL_Surface *pal_surface; +extern SDL_Surface *PalSurface; extern unsigned int pal_surface_palette_version; #ifdef USE_SDL1