Browse Source

Make Palette a unique ptr

pull/2867/head
Vladimir Olteanu 5 years ago committed by Anders Jenbo
parent
commit
aab7bf6e91
  1. 2
      Source/DiabloUI/diabloui.cpp
  2. 11
      Source/dx.cpp
  3. 2
      Source/hwcursor.cpp
  4. 2
      Source/palette.cpp
  5. 2
      Source/utils/display.h

2
Source/DiabloUI/diabloui.cpp

@ -626,7 +626,7 @@ void LoadBackgroundArt(const char *pszFile, int frames)
if (IsHardwareCursorEnabled() && ArtCursor.surface != nullptr && GetCurrentCursorInfo().type() != CursorType::UserInterface) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetSurfacePalette(ArtCursor.surface.get(), Palette);
SDL_SetSurfacePalette(ArtCursor.surface.get(), Palette.get());
SDL_SetColorKey(ArtCursor.surface.get(), 1, 0);
#endif
SetHardwareCursor(CursorInfo::UserInterfaceCursor());

11
Source/dx.cpp

@ -28,7 +28,7 @@ SDLTextureUniquePtr texture;
#endif
/** Currently active palette */
SDL_Palette *Palette;
SDLPaletteUniquePtr Palette;
unsigned int pal_surface_palette_version = 0;
/** 24-bit renderer texture surface */
@ -84,7 +84,7 @@ void CreateBackBuffer()
#ifndef USE_SDL1
// In SDL2, `pal_surface` points to the global `palette`.
if (SDL_SetSurfacePalette(pal_surface, Palette) < 0)
if (SDL_SetSurfacePalette(pal_surface, Palette.get()) < 0)
ErrSdl();
#else
// In SDL1, `pal_surface` owns its palette and we must update it every
@ -206,7 +206,7 @@ void dx_cleanup()
return;
SDL_FreeSurface(pal_surface);
pal_surface = nullptr;
SDL_FreePalette(Palette);
Palette = nullptr;
SDL_FreeSurface(renderer_texture_surface);
#ifndef USE_SDL1
texture = nullptr;
@ -240,10 +240,7 @@ void dx_reinit()
void InitPalette()
{
Palette = SDL_AllocPalette(256);
if (Palette == nullptr) {
ErrSdl();
}
Palette = SDLWrap::AllocPalette(256);
}
void BltFast(SDL_Rect *srcRect, SDL_Rect *dstRect)

2
Source/hwcursor.cpp

@ -112,7 +112,7 @@ bool SetHardwareCursorFromSprite(int pcurs)
return false;
OwnedSurface out { size };
SDL_SetSurfacePalette(out.surface, Palette);
SDL_SetSurfacePalette(out.surface, Palette.get());
// Transparent color must not be used in the sprite itself.
// Colors 1-127 are outside of the UI palette so are safe to use.

2
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, system_palette, first, ncolor) < 0) {
if (SDLC_SetSurfaceAndPaletteColors(pal_surface, Palette.get(), system_palette, first, ncolor) < 0) {
ErrSdl();
}
pal_surface_palette_version++;

2
Source/utils/display.h

@ -22,7 +22,7 @@ extern SDL_Renderer *renderer;
extern SDLTextureUniquePtr texture;
#endif
extern SDL_Palette *Palette;
extern SDLPaletteUniquePtr Palette;
extern SDL_Surface *pal_surface;
extern unsigned int pal_surface_palette_version;

Loading…
Cancel
Save