Commit 5095592c authored by Sam Lantinga's avatar Sam Lantinga

A few fixes:

Fixed creating render texture framebuffer.
Removed the need for palette watch, added surface format caching.
Added an SDL_DONTFREE flag so you can't free the window and 1.2 shadow surfaces.
parent 13ba84bf
...@@ -253,24 +253,20 @@ typedef struct SDL_Color ...@@ -253,24 +253,20 @@ typedef struct SDL_Color
} SDL_Color; } SDL_Color;
#define SDL_Colour SDL_Color #define SDL_Colour SDL_Color
typedef struct SDL_Palette SDL_Palette; typedef struct SDL_Palette
typedef int (*SDL_PaletteChangedFunc) (void *userdata, SDL_Palette * palette);
typedef struct SDL_PaletteWatch SDL_PaletteWatch;
struct SDL_Palette
{ {
int ncolors; int ncolors;
SDL_Color *colors; SDL_Color *colors;
Uint32 version;
int refcount; int refcount;
SDL_PaletteWatch *watch; } SDL_Palette;
};
/** /**
* \note Everything in the pixel format structure is read-only. * \note Everything in the pixel format structure is read-only.
*/ */
typedef struct SDL_PixelFormat typedef struct SDL_PixelFormat
{ {
Uint32 format;
SDL_Palette *palette; SDL_Palette *palette;
Uint8 BitsPerPixel; Uint8 BitsPerPixel;
Uint8 BytesPerPixel; Uint8 BytesPerPixel;
...@@ -286,6 +282,8 @@ typedef struct SDL_PixelFormat ...@@ -286,6 +282,8 @@ typedef struct SDL_PixelFormat
Uint32 Gmask; Uint32 Gmask;
Uint32 Bmask; Uint32 Bmask;
Uint32 Amask; Uint32 Amask;
int refcount;
struct SDL_PixelFormat *next;
} SDL_PixelFormat; } SDL_PixelFormat;
/** /**
...@@ -321,6 +319,16 @@ extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp, ...@@ -321,6 +319,16 @@ extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
Uint32 Bmask, Uint32 Bmask,
Uint32 Amask); Uint32 Amask);
/**
* \brief Create an SDL_PixelFormat structure from a pixel format enum.
*/
extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(Uint32 pixel_format);
/**
* \brief Free an SDL_PixelFormat structure.
*/
extern DECLSPEC void SDLCALL SDL_FreeFormat(SDL_PixelFormat *format);
/** /**
* \brief Create a palette structure with the specified number of color * \brief Create a palette structure with the specified number of color
* entries. * entries.
...@@ -334,23 +342,10 @@ extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp, ...@@ -334,23 +342,10 @@ extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp,
extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors); extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors);
/** /**
* \brief Add a callback function which is called when the palette changes. * \brief Set the palette for a pixel format structure.
*
* \sa SDL_DelPaletteWatch()
*/
extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette,
SDL_PaletteChangedFunc
callback, void *userdata);
/**
* \brief Remove a callback function previously added with
* SDL_AddPaletteWatch().
*
* \sa SDL_AddPaletteWatch()
*/ */
extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette, extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format,
SDL_PaletteChangedFunc SDL_Palette *palette);
callback, void *userdata);
/** /**
* \brief Set a range of colors in a palette. * \brief Set a range of colors in a palette.
......
...@@ -54,6 +54,7 @@ extern "C" { ...@@ -54,6 +54,7 @@ extern "C" {
/*@{*/ /*@{*/
#define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */ #define SDL_PREALLOC 0x00000001 /**< Surface uses preallocated memory */
#define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */ #define SDL_RLEACCEL 0x00000002 /**< Surface is RLE encoded */
#define SDL_DONTFREE 0x00000004 /**< Surface is referenced internally */
/*@}*//*Surface flags*/ /*@}*//*Surface flags*/
/** /**
......
...@@ -93,12 +93,7 @@ SDL_GetVideoInfo(void) ...@@ -93,12 +93,7 @@ SDL_GetVideoInfo(void)
/* Memory leak, compatibility code, who cares? */ /* Memory leak, compatibility code, who cares? */
if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) { if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
int bpp; info.vfmt = SDL_AllocFormat(mode.format);
Uint32 Rmask, Gmask, Bmask, Amask;
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask,
&Amask);
info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
info.current_w = mode.w; info.current_w = mode.w;
info.current_h = mode.h; info.current_h = mode.h;
} }
...@@ -383,7 +378,7 @@ SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags) ...@@ -383,7 +378,7 @@ SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
int w, h; int w, h;
/* We can't resize something we don't have... */ /* We can't resize something we don't have... */
if (!SDL_VideoWindow) { if (!SDL_VideoSurface) {
return -1; return -1;
} }
...@@ -396,6 +391,9 @@ SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags) ...@@ -396,6 +391,9 @@ SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
if (flags != SDL_VideoFlags) { if (flags != SDL_VideoFlags) {
return -1; return -1;
} }
if (bpp != SDL_VideoSurface->format->BitsPerPixel) {
return -1;
}
/* Resize the window */ /* Resize the window */
SDL_GetWindowSize(SDL_VideoWindow, &w, &h); SDL_GetWindowSize(SDL_VideoWindow, &w, &h);
...@@ -469,6 +467,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) ...@@ -469,6 +467,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
/* Destroy existing window */ /* Destroy existing window */
SDL_PublicSurface = NULL; SDL_PublicSurface = NULL;
if (SDL_ShadowSurface) { if (SDL_ShadowSurface) {
SDL_ShadowSurface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(SDL_ShadowSurface); SDL_FreeSurface(SDL_ShadowSurface);
SDL_ShadowSurface = NULL; SDL_ShadowSurface = NULL;
} }
...@@ -564,6 +563,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) ...@@ -564,6 +563,7 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
return NULL; return NULL;
} }
SDL_ShadowSurface->flags |= surface_flags; SDL_ShadowSurface->flags |= surface_flags;
SDL_ShadowSurface->flags |= SDL_DONTFREE;
/* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */ /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
if (SDL_ShadowSurface->format->palette) { if (SDL_ShadowSurface->format->palette) {
...@@ -670,7 +670,13 @@ SDL_DisplayFormatAlpha(SDL_Surface * surface) ...@@ -670,7 +670,13 @@ SDL_DisplayFormatAlpha(SDL_Surface * surface)
optimised alpha format is written, add the converter here */ optimised alpha format is written, add the converter here */
break; break;
} }
format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); format = SDL_AllocFormat(SDL_MasksToPixelFormatEnum(32, rmask,
gmask,
bmask,
amask));
if (!format) {
return NULL;
}
converted = SDL_ConvertSurface(surface, format, SDL_RLEACCEL); converted = SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
SDL_FreeFormat(format); SDL_FreeFormat(format);
return converted; return converted;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "SDL_log.h" #include "SDL_log.h"
#include "SDL_render.h" #include "SDL_render.h"
#include "SDL_sysrender.h" #include "SDL_sysrender.h"
#include "../video/SDL_pixels_c.h"
#include "software/SDL_render_sw_c.h" #include "software/SDL_render_sw_c.h"
...@@ -306,8 +305,6 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) ...@@ -306,8 +305,6 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
SDL_bool needAlpha; SDL_bool needAlpha;
Uint32 i; Uint32 i;
Uint32 format; Uint32 format;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
SDL_Texture *texture; SDL_Texture *texture;
CHECK_RENDERER_MAGIC(renderer, NULL); CHECK_RENDERER_MAGIC(renderer, NULL);
...@@ -333,20 +330,13 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) ...@@ -333,20 +330,13 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
} }
} }
if (!SDL_PixelFormatEnumToMasks(format, &bpp,
&Rmask, &Gmask, &Bmask, &Amask)) {
SDL_SetError("Unknown pixel format");
return NULL;
}
texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC, texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
surface->w, surface->h); surface->w, surface->h);
if (!texture) { if (!texture) {
return NULL; return NULL;
} }
if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask if (format == surface->format->format) {
&& Bmask == fmt->Bmask && Amask == fmt->Amask) {
if (SDL_MUSTLOCK(surface)) { if (SDL_MUSTLOCK(surface)) {
SDL_LockSurface(surface); SDL_LockSurface(surface);
SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch); SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
...@@ -359,7 +349,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) ...@@ -359,7 +349,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
SDL_Surface *temp = NULL; SDL_Surface *temp = NULL;
/* Set up a destination surface for the texture update */ /* Set up a destination surface for the texture update */
SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask); SDL_InitFormat(&dst_fmt, format);
temp = SDL_ConvertSurface(surface, &dst_fmt, 0); temp = SDL_ConvertSurface(surface, &dst_fmt, 0);
if (temp) { if (temp) {
SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch); SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#if !SDL_RENDER_DISABLED #if !SDL_RENDER_DISABLED
#include "../SDL_sysrender.h" #include "../SDL_sysrender.h"
#include "../../video/SDL_pixels_c.h"
#include "SDL_draw.h" #include "SDL_draw.h"
#include "SDL_blendfillrect.h" #include "SDL_blendfillrect.h"
......
...@@ -221,18 +221,8 @@ SDL_CalculateBlit(SDL_Surface * surface) ...@@ -221,18 +221,8 @@ SDL_CalculateBlit(SDL_Surface * surface)
blit = SDL_CalculateBlitN(surface); blit = SDL_CalculateBlitN(surface);
} }
if (blit == NULL) { if (blit == NULL) {
Uint32 src_format = Uint32 src_format = surface->format->format;
SDL_MasksToPixelFormatEnum(surface->format->BitsPerPixel, Uint32 dst_format = dst->format->format;
surface->format->Rmask,
surface->format->Gmask,
surface->format->Bmask,
surface->format->Amask);
Uint32 dst_format =
SDL_MasksToPixelFormatEnum(dst->format->BitsPerPixel,
dst->format->Rmask,
dst->format->Gmask,
dst->format->Bmask,
dst->format->Amask);
blit = blit =
SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags,
......
...@@ -105,7 +105,7 @@ typedef struct SDL_BlitMap ...@@ -105,7 +105,7 @@ typedef struct SDL_BlitMap
/* the version count matches the destination; mismatch indicates /* the version count matches the destination; mismatch indicates
an invalid mapping */ an invalid mapping */
unsigned int format_version; Uint32 palette_version;
} SDL_BlitMap; } SDL_BlitMap;
/* Functions found in SDL_blit.c */ /* Functions found in SDL_blit.c */
...@@ -129,10 +129,6 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface); ...@@ -129,10 +129,6 @@ extern SDL_BlitFunc SDL_CalculateBlitA(SDL_Surface * surface);
#define DECLARE_ALIGNED(t,v,a) t v #define DECLARE_ALIGNED(t,v,a) t v
#endif #endif
#define FORMAT_EQUAL(A, B) \
((A)->BitsPerPixel == (B)->BitsPerPixel \
&& ((A)->Rmask == (B)->Rmask) && ((A)->Amask == (B)->Amask))
/* Load pixel of the specified format from a buffer and get its R-G-B values */ /* Load pixel of the specified format from a buffer and get its R-G-B values */
/* FIXME: rescale values to 0..255 here? */ /* FIXME: rescale values to 0..255 here? */
#define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \ #define RGB_FROM_PIXEL(Pixel, fmt, r, g, b) \
......
...@@ -437,17 +437,15 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst) ...@@ -437,17 +437,15 @@ SDL_SaveBMP_RW(SDL_Surface * saveme, SDL_RWops * dst, int freedst)
/* If the surface has a colorkey or alpha channel we'll save a /* If the surface has a colorkey or alpha channel we'll save a
32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */ 32-bit BMP with alpha channel, otherwise save a 24-bit BMP. */
if (save32bit) { if (save32bit) {
SDL_InitFormat(&format, 32, SDL_InitFormat(&format,
0x00FF0000, 0x0000FF00, 0x000000FF,
0xFF000000);
} else {
SDL_InitFormat(&format, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN #if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x00FF0000, 0x0000FF00, 0x000000FF, SDL_PIXELFORMAT_ARGB8888
#else #else
0x000000FF, 0x0000FF00, 0x00FF0000, SDL_PIXELFORMAT_BGRA8888
#endif #endif
0); );
} else {
SDL_InitFormat(&format, SDL_PIXELFORMAT_BGR24);
} }
surface = SDL_ConvertSurface(saveme, &format, 0); surface = SDL_ConvertSurface(saveme, &format, 0);
if (!surface) { if (!surface) {
......
This diff is collapsed.
...@@ -26,14 +26,7 @@ ...@@ -26,14 +26,7 @@
#include "SDL_blit.h" #include "SDL_blit.h"
/* Pixel format functions */ /* Pixel format functions */
extern SDL_PixelFormat *SDL_AllocFormat(int bpp, extern int SDL_InitFormat(SDL_PixelFormat * format, Uint32 pixel_format);
Uint32 Rmask, Uint32 Gmask,
Uint32 Bmask, Uint32 Amask);
extern SDL_PixelFormat *SDL_InitFormat(SDL_PixelFormat * format, int bpp,
Uint32 Rmask, Uint32 Gmask,
Uint32 Bmask, Uint32 Amask);
extern void SDL_FormatChanged(SDL_Surface * surface);
extern void SDL_FreeFormat(SDL_PixelFormat * format);
/* Blit mapping functions */ /* Blit mapping functions */
extern SDL_BlitMap *SDL_AllocBlitMap(void); extern SDL_BlitMap *SDL_AllocBlitMap(void);
......
...@@ -39,10 +39,18 @@ SDL_CreateRGBSurface(Uint32 flags, ...@@ -39,10 +39,18 @@ SDL_CreateRGBSurface(Uint32 flags,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{ {
SDL_Surface *surface; SDL_Surface *surface;
Uint32 format;
/* The flags are no longer used, make the compiler happy */ /* The flags are no longer used, make the compiler happy */
(void)flags; (void)flags;
/* Get the pixel format */
format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
if (format == SDL_PIXELFORMAT_UNKNOWN) {
SDL_SetError("Unknown pixel format");
return NULL;
}
/* Allocate the surface */ /* Allocate the surface */
surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface)); surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
if (surface == NULL) { if (surface == NULL) {
...@@ -50,7 +58,7 @@ SDL_CreateRGBSurface(Uint32 flags, ...@@ -50,7 +58,7 @@ SDL_CreateRGBSurface(Uint32 flags,
return NULL; return NULL;
} }
surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask); surface->format = SDL_AllocFormat(format);
if (!surface->format) { if (!surface->format) {
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
return NULL; return NULL;
...@@ -60,7 +68,7 @@ SDL_CreateRGBSurface(Uint32 flags, ...@@ -60,7 +68,7 @@ SDL_CreateRGBSurface(Uint32 flags,
surface->pitch = SDL_CalculatePitch(surface); surface->pitch = SDL_CalculatePitch(surface);
SDL_SetClipRect(surface, NULL); SDL_SetClipRect(surface, NULL);
if (surface->format->BitsPerPixel <= 8) { if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
SDL_Palette *palette = SDL_Palette *palette =
SDL_AllocPalette((1 << surface->format->BitsPerPixel)); SDL_AllocPalette((1 << surface->format->BitsPerPixel));
if (!palette) { if (!palette) {
...@@ -135,7 +143,6 @@ SDL_CreateRGBSurface(Uint32 flags, ...@@ -135,7 +143,6 @@ SDL_CreateRGBSurface(Uint32 flags,
SDL_FreeSurface(surface); SDL_FreeSurface(surface);
return NULL; return NULL;
} }
SDL_FormatChanged(surface);
/* By default surface with an alpha mask are set up for blending */ /* By default surface with an alpha mask are set up for blending */
if (Amask) { if (Amask) {
...@@ -171,46 +178,14 @@ SDL_CreateRGBSurfaceFrom(void *pixels, ...@@ -171,46 +178,14 @@ SDL_CreateRGBSurfaceFrom(void *pixels,
return surface; return surface;
} }
static int
SDL_SurfacePaletteChanged(void *userdata, SDL_Palette * palette)
{
SDL_Surface *surface = (SDL_Surface *) userdata;
SDL_FormatChanged(surface);
return 0;
}
int int
SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette) SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette)
{ {
if (!surface || !surface->format) { if (!surface) {
SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface"); SDL_SetError("SDL_SetSurfacePalette() passed a NULL surface");
return -1; return -1;
} }
return SDL_SetPixelFormatPalette(surface->format, palette);
if (palette && palette->ncolors != (1 << surface->format->BitsPerPixel)) {
SDL_SetError
("SDL_SetSurfacePalette() passed a palette that doesn't match the surface format");
return -1;
}
if (surface->format->palette == palette) {
return 0;
}
if (surface->format->palette) {
SDL_DelPaletteWatch(surface->format->palette,
SDL_SurfacePaletteChanged, surface);
}
surface->format->palette = palette;
if (surface->format->palette) {
SDL_AddPaletteWatch(surface->format->palette,
SDL_SurfacePaletteChanged, surface);
}
return 0;
} }
int int
...@@ -556,7 +531,8 @@ SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect, ...@@ -556,7 +531,8 @@ SDL_LowerBlit(SDL_Surface * src, SDL_Rect * srcrect,
{ {
/* Check to make sure the blit mapping is valid */ /* Check to make sure the blit mapping is valid */
if ((src->map->dst != dst) || if ((src->map->dst != dst) ||
(src->map->dst->format_version != src->map->format_version)) { (dst->format->palette &&
src->map->palette_version != dst->format->palette->version)) {
if (SDL_MapSurface(src, dst) < 0) { if (SDL_MapSurface(src, dst) < 0) {
return (-1); return (-1);
} }
...@@ -801,21 +777,17 @@ SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, ...@@ -801,21 +777,17 @@ SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
void * pixels, int pitch, SDL_Surface * surface, void * pixels, int pitch, SDL_Surface * surface,
SDL_PixelFormat * format, SDL_BlitMap * blitmap) SDL_PixelFormat * format, SDL_BlitMap * blitmap)
{ {
int bpp; if (SDL_ISPIXELFORMAT_INDEXED(pixel_format)) {
Uint32 Rmask, Gmask, Bmask, Amask; SDL_SetError("Indexed pixel formats not supported");
if (!SDL_PixelFormatEnumToMasks(pixel_format,
&bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return SDL_FALSE; return SDL_FALSE;
} }
if (bpp <= 8) { if (SDL_InitFormat(format, pixel_format) < 0) {
SDL_SetError("Indexed pixel formats not supported");
return SDL_FALSE; return SDL_FALSE;
} }
SDL_zerop(surface); SDL_zerop(surface);
surface->flags = SDL_PREALLOC; surface->flags = SDL_PREALLOC;
surface->format = SDL_InitFormat(format, bpp, Rmask, Gmask, Bmask, Amask); surface->format = format;
surface->pixels = pixels; surface->pixels = pixels;
surface->w = width; surface->w = width;
surface->h = height; surface->h = height;
...@@ -830,7 +802,6 @@ SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format, ...@@ -830,7 +802,6 @@ SDL_CreateSurfaceOnStack(int width, int height, Uint32 pixel_format,
blitmap->info.b = 0xFF; blitmap->info.b = 0xFF;
blitmap->info.a = 0xFF; blitmap->info.a = 0xFF;
surface->map = blitmap; surface->map = blitmap;
SDL_FormatChanged(surface);
/* The surface is ready to go */ /* The surface is ready to go */
surface->refcount = 1; surface->refcount = 1;
...@@ -905,6 +876,9 @@ SDL_FreeSurface(SDL_Surface * surface) ...@@ -905,6 +876,9 @@ SDL_FreeSurface(SDL_Surface * surface)
if (surface == NULL) { if (surface == NULL) {
return; return;
} }
if (surface->flags & SDL_DONTFREE) {
return;
}
if (--surface->refcount > 0) { if (--surface->refcount > 0) {
return; return;
} }
......
...@@ -208,7 +208,7 @@ static int ...@@ -208,7 +208,7 @@ static int
SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch) SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{ {
SDL_WindowTextureData *data; SDL_WindowTextureData *data;
SDL_Renderer *renderer; SDL_Renderer *renderer = NULL;
SDL_RendererInfo info; SDL_RendererInfo info;
Uint32 i; Uint32 i;
...@@ -1204,7 +1204,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) ...@@ -1204,7 +1204,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
/* Tear down the old native window */ /* Tear down the old native window */
if (window->surface) { if (window->surface) {
window->surface->refcount = 0; window->surface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(window->surface); SDL_FreeSurface(window->surface);
} }
if (_this->DestroyWindowFramebuffer) { if (_this->DestroyWindowFramebuffer) {
...@@ -1622,13 +1622,13 @@ SDL_GetWindowSurface(SDL_Window * window) ...@@ -1622,13 +1622,13 @@ SDL_GetWindowSurface(SDL_Window * window)
if (!window->surface_valid) { if (!window->surface_valid) {
if (window->surface) { if (window->surface) {
window->surface->refcount = 0; window->surface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(window->surface); SDL_FreeSurface(window->surface);
} }
window->surface = SDL_CreateWindowFramebuffer(window); window->surface = SDL_CreateWindowFramebuffer(window);
if (window->surface) { if (window->surface) {
window->surface_valid = SDL_TRUE; window->surface_valid = SDL_TRUE;
window->surface->refcount = 0x7FFFFFF; window->surface->flags |= SDL_DONTFREE;
} }
} }
return window->surface; return window->surface;
...@@ -1778,7 +1778,7 @@ SDL_DestroyWindow(SDL_Window * window) ...@@ -1778,7 +1778,7 @@ SDL_DestroyWindow(SDL_Window * window)
SDL_UpdateFullscreenMode(window, SDL_FALSE); SDL_UpdateFullscreenMode(window, SDL_FALSE);
if (window->surface) { if (window->surface) {
window->surface->refcount = 0; window->surface->flags &= ~SDL_DONTFREE;
SDL_FreeSurface(window->surface); SDL_FreeSurface(window->surface);
} }
if (_this->DestroyWindowFramebuffer) { if (_this->DestroyWindowFramebuffer) {
......
...@@ -220,8 +220,7 @@ DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) ...@@ -220,8 +220,7 @@ DirectFB_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
int pitch, i; int pitch, i;
/* Convert the icon to ARGB for modern window managers */ /* Convert the icon to ARGB for modern window managers */
SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
0xFF000000);
surface = SDL_ConvertSurface(icon, &format, 0); surface = SDL_ConvertSurface(icon, &format, 0);
if (!surface) { if (!surface) {
return; return;
......
...@@ -332,8 +332,7 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) ...@@ -332,8 +332,7 @@ WIN_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
SDL_WriteLE32(dst, 0); SDL_WriteLE32(dst, 0);
/* Convert the icon to a 32-bit surface with alpha channel */ /* Convert the icon to a 32-bit surface with alpha channel */
SDL_InitFormat(&format, 32, SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
surface = SDL_ConvertSurface(icon, &format, 0); surface = SDL_ConvertSurface(icon, &format, 0);
if (surface) { if (surface) {
/* Write the pixels upside down into the bitmap buffer */ /* Write the pixels upside down into the bitmap buffer */
......
...@@ -666,8 +666,7 @@ X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) ...@@ -666,8 +666,7 @@ X11_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
long *propdata; long *propdata;
/* Convert the icon to ARGB for modern window managers */ /* Convert the icon to ARGB for modern window managers */
SDL_InitFormat(&format, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, SDL_InitFormat(&format, SDL_PIXELFORMAT_ARGB8888);
0xFF000000);
surface = SDL_ConvertSurface(icon, &format, 0); surface = SDL_ConvertSurface(icon, &format, 0);
if (!surface) { if (!surface) {
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment