A few #defines to reduce SDL2 footprint.

Only applied when library is statically linked
This commit is contained in:
Sylvain Becker 2020-01-21 21:33:40 +01:00
parent 25c88ea903
commit 7df22cf2c2
7 changed files with 75 additions and 13 deletions

View File

@ -51,6 +51,17 @@
#include "SDL_config.h" #include "SDL_config.h"
/* A few #defines to reduce SDL2 footprint.
Only applied when library is statically linked */
#define SDL_HAVE_BLIT_0 1
#define SDL_HAVE_BLIT_1 1
#define SDL_HAVE_BLIT_A 1
#define SDL_HAVE_BLIT_N 1
#define SDL_HAVE_BLIT_AUTO 1
#define SDL_HAVE_RLE 1
#define SDL_VIDEO_RENDER_SW 1
#define SDL_HAVE_YUV 1
#endif /* SDL_internal_h_ */ #endif /* SDL_internal_h_ */
/* vi: set ts=4 sw=4 expandtab: */ /* vi: set ts=4 sw=4 expandtab: */

View File

@ -105,7 +105,9 @@ static const SDL_RenderDriver *render_drivers[] = {
#if SDL_VIDEO_RENDER_PSP #if SDL_VIDEO_RENDER_PSP
&PSP_RenderDriver, &PSP_RenderDriver,
#endif #endif
#if SDL_VIDEO_RENDER_SW
&SW_RenderDriver &SW_RenderDriver
#endif
}; };
#endif /* !SDL_RENDER_DISABLED */ #endif /* !SDL_RENDER_DISABLED */
@ -907,7 +909,7 @@ error:
SDL_Renderer * SDL_Renderer *
SDL_CreateSoftwareRenderer(SDL_Surface * surface) SDL_CreateSoftwareRenderer(SDL_Surface * surface)
{ {
#if !SDL_RENDER_DISABLED #if !SDL_RENDER_DISABLED && SDL_VIDEO_RENDER_SW
SDL_Renderer *renderer; SDL_Renderer *renderer;
renderer = SW_CreateRendererForSurface(surface); renderer = SW_CreateRendererForSurface(surface);
@ -1114,7 +1116,11 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
renderer->textures = texture; renderer->textures = texture;
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
#if SDL_HAVE_YUV
texture->yuv = SDL_SW_CreateYUVTexture(format, w, h); texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
#else
SDL_SetError("SDL not built with YUV support");
#endif
if (!texture->yuv) { if (!texture->yuv) {
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
return NULL; return NULL;
@ -1532,8 +1538,10 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
if ((rect->w == 0) || (rect->h == 0)) { if ((rect->w == 0) || (rect->h == 0)) {
return 0; /* nothing to do. */ return 0; /* nothing to do. */
#if SDL_HAVE_YUV
} else if (texture->yuv) { } else if (texture->yuv) {
return SDL_UpdateTextureYUV(texture, rect, pixels, pitch); return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
#endif
} else if (texture->native) { } else if (texture->native) {
return SDL_UpdateTextureNative(texture, rect, pixels, pitch); return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
} else { } else {
@ -1602,6 +1610,7 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
const Uint8 *Uplane, int Upitch, const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch) const Uint8 *Vplane, int Vpitch)
{ {
#if SDL_HAVE_YUV
SDL_Renderer *renderer; SDL_Renderer *renderer;
SDL_Rect full_rect; SDL_Rect full_rect;
@ -1658,6 +1667,9 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
return SDL_Unsupported(); return SDL_Unsupported();
} }
} }
#else
return -1;
#endif
} }
static int static int
@ -1699,12 +1711,15 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect,
rect = &full_rect; rect = &full_rect;
} }
#if SDL_HAVE_YUV
if (texture->yuv) { if (texture->yuv) {
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
return -1; return -1;
} }
return SDL_LockTextureYUV(texture, rect, pixels, pitch); return SDL_LockTextureYUV(texture, rect, pixels, pitch);
} else if (texture->native) { } else
#endif
if (texture->native) {
/* Calls a real SDL_LockTexture/SDL_UnlockTexture on unlock, flushing then. */ /* Calls a real SDL_LockTexture/SDL_UnlockTexture on unlock, flushing then. */
return SDL_LockTextureNative(texture, rect, pixels, pitch); return SDL_LockTextureNative(texture, rect, pixels, pitch);
} else { } else {
@ -1802,9 +1817,12 @@ SDL_UnlockTexture(SDL_Texture * texture)
if (texture->access != SDL_TEXTUREACCESS_STREAMING) { if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
return; return;
} }
#if SDL_HAVE_YUV
if (texture->yuv) { if (texture->yuv) {
SDL_UnlockTextureYUV(texture); SDL_UnlockTextureYUV(texture);
} else if (texture->native) { } else
#endif
if (texture->native) {
SDL_UnlockTextureNative(texture); SDL_UnlockTextureNative(texture);
} else { } else {
SDL_Renderer *renderer = texture->renderer; SDL_Renderer *renderer = texture->renderer;
@ -3159,9 +3177,11 @@ SDL_DestroyTexture(SDL_Texture * texture)
if (texture->native) { if (texture->native) {
SDL_DestroyTexture(texture->native); SDL_DestroyTexture(texture->native);
} }
#if SDL_HAVE_YUV
if (texture->yuv) { if (texture->yuv) {
SDL_SW_DestroyYUVTexture(texture->yuv); SDL_SW_DestroyYUVTexture(texture->yuv);
} }
#endif
SDL_free(texture->pixels); SDL_free(texture->pixels);
renderer->DestroyTexture(renderer, texture); renderer->DestroyTexture(renderer, texture);

View File

@ -445,7 +445,7 @@ RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
/* blit a colorkeyed RLE surface */ /* blit a colorkeyed RLE surface */
int SDLCALL static int SDLCALL
SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
SDL_Surface * surf_dst, SDL_Rect * dstrect) SDL_Surface * surf_dst, SDL_Rect * dstrect)
{ {
@ -723,7 +723,7 @@ RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
} }
/* blit a pixel-alpha RLE surface */ /* blit a pixel-alpha RLE surface */
int SDLCALL static int SDLCALL
SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect, SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
SDL_Surface * surf_dst, SDL_Rect * dstrect) SDL_Surface * surf_dst, SDL_Rect * dstrect)
{ {

View File

@ -27,10 +27,6 @@
/* Useful functions and variables from SDL_RLEaccel.c */ /* Useful functions and variables from SDL_RLEaccel.c */
extern int SDL_RLESurface(SDL_Surface * surface); extern int SDL_RLESurface(SDL_Surface * surface);
extern int SDLCALL SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
extern int SDLCALL SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect);
extern void SDL_UnRLESurface(SDL_Surface * surface, int recode); extern void SDL_UnRLESurface(SDL_Surface * surface, int recode);
#endif /* SDL_RLEaccel_c_h_ */ #endif /* SDL_RLEaccel_c_h_ */

View File

@ -202,22 +202,27 @@ SDL_CalculateBlit(SDL_Surface * surface)
return SDL_SetError("Blit combination not supported"); return SDL_SetError("Blit combination not supported");
} }
#if SDL_HAVE_RLE
/* Clean everything out to start */ /* Clean everything out to start */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1); SDL_UnRLESurface(surface, 1);
} }
#endif
map->blit = SDL_SoftBlit; map->blit = SDL_SoftBlit;
map->info.src_fmt = surface->format; map->info.src_fmt = surface->format;
map->info.src_pitch = surface->pitch; map->info.src_pitch = surface->pitch;
map->info.dst_fmt = dst->format; map->info.dst_fmt = dst->format;
map->info.dst_pitch = dst->pitch; map->info.dst_pitch = dst->pitch;
#if SDL_HAVE_RLE
/* See if we can do RLE acceleration */ /* See if we can do RLE acceleration */
if (map->info.flags & SDL_COPY_RLE_DESIRED) { if (map->info.flags & SDL_COPY_RLE_DESIRED) {
if (SDL_RLESurface(surface) == 0) { if (SDL_RLESurface(surface) == 0) {
return 0; return 0;
} }
} }
#endif
/* Choose a standard blit function */ /* Choose a standard blit function */
if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) { if (map->identity && !(map->info.flags & ~SDL_COPY_RLE_DESIRED)) {
@ -226,17 +231,30 @@ SDL_CalculateBlit(SDL_Surface * surface)
/* Greater than 8 bits per channel not supported yet */ /* Greater than 8 bits per channel not supported yet */
SDL_InvalidateMap(map); SDL_InvalidateMap(map);
return SDL_SetError("Blit combination not supported"); return SDL_SetError("Blit combination not supported");
} else if (surface->format->BitsPerPixel < 8 && }
#if SDL_HAVE_BLIT_0
else if (surface->format->BitsPerPixel < 8 &&
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) { SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
blit = SDL_CalculateBlit0(surface); blit = SDL_CalculateBlit0(surface);
} else if (surface->format->BytesPerPixel == 1 && }
#endif
#if SDL_HAVE_BLIT_1
else if (surface->format->BytesPerPixel == 1 &&
SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) { SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
blit = SDL_CalculateBlit1(surface); blit = SDL_CalculateBlit1(surface);
} else if (map->info.flags & SDL_COPY_BLEND) { }
#endif
#if SDL_HAVE_BLIT_A
else if (map->info.flags & SDL_COPY_BLEND) {
blit = SDL_CalculateBlitA(surface); blit = SDL_CalculateBlitA(surface);
} else { }
#endif
#if SDL_HAVE_BLIT_N
else {
blit = SDL_CalculateBlitN(surface); blit = SDL_CalculateBlitN(surface);
} }
#endif
#if SDL_HAVE_BLIT_AUTO
if (blit == NULL) { if (blit == NULL) {
Uint32 src_format = surface->format->format; Uint32 src_format = surface->format->format;
Uint32 dst_format = dst->format->format; Uint32 dst_format = dst->format->format;
@ -245,6 +263,8 @@ SDL_CalculateBlit(SDL_Surface * surface)
SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags, SDL_ChooseBlitFunc(src_format, dst_format, map->info.flags,
SDL_GeneratedBlitFuncTable); SDL_GeneratedBlitFuncTable);
} }
#endif
#ifndef TEST_SLOW_BLIT #ifndef TEST_SLOW_BLIT
if (blit == NULL) if (blit == NULL)
#endif #endif

View File

@ -1003,9 +1003,11 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
/* Clear out any previous mapping */ /* Clear out any previous mapping */
map = src->map; map = src->map;
#if SDL_HAVE_RLE
if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(src, 1); SDL_UnRLESurface(src, 1);
} }
#endif
SDL_InvalidateMap(map); SDL_InvalidateMap(map);
/* Figure out what kind of mapping we're doing */ /* Figure out what kind of mapping we're doing */

View File

@ -905,11 +905,13 @@ int
SDL_LockSurface(SDL_Surface * surface) SDL_LockSurface(SDL_Surface * surface)
{ {
if (!surface->locked) { if (!surface->locked) {
#if SDL_HAVE_RLE
/* Perform the lock */ /* Perform the lock */
if (surface->flags & SDL_RLEACCEL) { if (surface->flags & SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1); SDL_UnRLESurface(surface, 1);
surface->flags |= SDL_RLEACCEL; /* save accel'd state */ surface->flags |= SDL_RLEACCEL; /* save accel'd state */
} }
#endif
} }
/* Increment the surface lock count, for recursive locks */ /* Increment the surface lock count, for recursive locks */
@ -930,11 +932,13 @@ SDL_UnlockSurface(SDL_Surface * surface)
return; return;
} }
#if SDL_HAVE_RLE
/* Update RLE encoded surface with new data */ /* Update RLE encoded surface with new data */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
surface->flags &= ~SDL_RLEACCEL; /* stop lying */ surface->flags &= ~SDL_RLEACCEL; /* stop lying */
SDL_RLESurface(surface); SDL_RLESurface(surface);
} }
#endif
} }
/* /*
@ -1210,6 +1214,7 @@ int SDL_ConvertPixels(int width, int height,
return SDL_InvalidParamError("dst_pitch"); return SDL_InvalidParamError("dst_pitch");
} }
#if SDL_HAVE_YUV
if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) { if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch); return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) { } else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
@ -1217,6 +1222,12 @@ int SDL_ConvertPixels(int width, int height,
} else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) { } else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch); return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} }
#else
if (SDL_ISPIXELFORMAT_FOURCC(src_format) || SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
SDL_SetError("SDL not built with YUV support");
return -1;
}
#endif
/* Fast path for same format copy */ /* Fast path for same format copy */
if (src_format == dst_format) { if (src_format == dst_format) {
@ -1269,9 +1280,11 @@ SDL_FreeSurface(SDL_Surface * surface)
while (surface->locked > 0) { while (surface->locked > 0) {
SDL_UnlockSurface(surface); SDL_UnlockSurface(surface);
} }
#if SDL_HAVE_RLE
if (surface->flags & SDL_RLEACCEL) { if (surface->flags & SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 0); SDL_UnRLESurface(surface, 0);
} }
#endif
if (surface->format) { if (surface->format) {
SDL_SetSurfacePalette(surface, NULL); SDL_SetSurfacePalette(surface, NULL);
SDL_FreeFormat(surface->format); SDL_FreeFormat(surface->format);