A few #defines to reduce SDL2 footprint. Only applied when library is statically linked
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index 9cb1d87..3ced9bc 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -51,6 +51,17 @@
#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_ */
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 0f7ec28..6a03cc5 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -105,7 +105,9 @@ static const SDL_RenderDriver *render_drivers[] = {
#if SDL_VIDEO_RENDER_PSP
&PSP_RenderDriver,
#endif
+#if SDL_VIDEO_RENDER_SW
&SW_RenderDriver
+#endif
};
#endif /* !SDL_RENDER_DISABLED */
@@ -907,7 +909,7 @@ error:
SDL_Renderer *
SDL_CreateSoftwareRenderer(SDL_Surface * surface)
{
-#if !SDL_RENDER_DISABLED
+#if !SDL_RENDER_DISABLED && SDL_VIDEO_RENDER_SW
SDL_Renderer *renderer;
renderer = SW_CreateRendererForSurface(surface);
@@ -1114,7 +1116,11 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
renderer->textures = texture;
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
+#if SDL_HAVE_YUV
texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
+#else
+ SDL_SetError("SDL not built with YUV support");
+#endif
if (!texture->yuv) {
SDL_DestroyTexture(texture);
return NULL;
@@ -1532,8 +1538,10 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
if ((rect->w == 0) || (rect->h == 0)) {
return 0; /* nothing to do. */
+#if SDL_HAVE_YUV
} else if (texture->yuv) {
return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
+#endif
} else if (texture->native) {
return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
} else {
@@ -1602,6 +1610,7 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
+#if SDL_HAVE_YUV
SDL_Renderer *renderer;
SDL_Rect full_rect;
@@ -1658,6 +1667,9 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
return SDL_Unsupported();
}
}
+#else
+ return -1;
+#endif
}
static int
@@ -1699,12 +1711,15 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect,
rect = &full_rect;
}
+#if SDL_HAVE_YUV
if (texture->yuv) {
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
return -1;
}
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. */
return SDL_LockTextureNative(texture, rect, pixels, pitch);
} else {
@@ -1802,9 +1817,12 @@ SDL_UnlockTexture(SDL_Texture * texture)
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
return;
}
+#if SDL_HAVE_YUV
if (texture->yuv) {
SDL_UnlockTextureYUV(texture);
- } else if (texture->native) {
+ } else
+#endif
+ if (texture->native) {
SDL_UnlockTextureNative(texture);
} else {
SDL_Renderer *renderer = texture->renderer;
@@ -3159,9 +3177,11 @@ SDL_DestroyTexture(SDL_Texture * texture)
if (texture->native) {
SDL_DestroyTexture(texture->native);
}
+#if SDL_HAVE_YUV
if (texture->yuv) {
SDL_SW_DestroyYUVTexture(texture->yuv);
}
+#endif
SDL_free(texture->pixels);
renderer->DestroyTexture(renderer, texture);
diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c
index 05114c4..9807694 100644
--- a/src/video/SDL_RLEaccel.c
+++ b/src/video/SDL_RLEaccel.c
@@ -445,7 +445,7 @@ RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
/* blit a colorkeyed RLE surface */
-int SDLCALL
+static int SDLCALL
SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
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 */
-int SDLCALL
+static int SDLCALL
SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
SDL_Surface * surf_dst, SDL_Rect * dstrect)
{
diff --git a/src/video/SDL_RLEaccel_c.h b/src/video/SDL_RLEaccel_c.h
index 7601fa4..3dcc6c0 100644
--- a/src/video/SDL_RLEaccel_c.h
+++ b/src/video/SDL_RLEaccel_c.h
@@ -27,10 +27,6 @@
/* Useful functions and variables from SDL_RLEaccel.c */
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);
#endif /* SDL_RLEaccel_c_h_ */
diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c
index 6ee0a63..dc0d4df 100644
--- a/src/video/SDL_blit.c
+++ b/src/video/SDL_blit.c
@@ -202,22 +202,27 @@ SDL_CalculateBlit(SDL_Surface * surface)
return SDL_SetError("Blit combination not supported");
}
+#if SDL_HAVE_RLE
/* Clean everything out to start */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1);
}
+#endif
+
map->blit = SDL_SoftBlit;
map->info.src_fmt = surface->format;
map->info.src_pitch = surface->pitch;
map->info.dst_fmt = dst->format;
map->info.dst_pitch = dst->pitch;
+#if SDL_HAVE_RLE
/* See if we can do RLE acceleration */
if (map->info.flags & SDL_COPY_RLE_DESIRED) {
if (SDL_RLESurface(surface) == 0) {
return 0;
}
}
+#endif
/* Choose a standard blit function */
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 */
SDL_InvalidateMap(map);
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)) {
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)) {
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);
- } else {
+ }
+#endif
+#if SDL_HAVE_BLIT_N
+ else {
blit = SDL_CalculateBlitN(surface);
}
+#endif
+#if SDL_HAVE_BLIT_AUTO
if (blit == NULL) {
Uint32 src_format = surface->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_GeneratedBlitFuncTable);
}
+#endif
+
#ifndef TEST_SLOW_BLIT
if (blit == NULL)
#endif
diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c
index 09738bf..f02a2bd 100644
--- a/src/video/SDL_pixels.c
+++ b/src/video/SDL_pixels.c
@@ -1003,9 +1003,11 @@ SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst)
/* Clear out any previous mapping */
map = src->map;
+#if SDL_HAVE_RLE
if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
SDL_UnRLESurface(src, 1);
}
+#endif
SDL_InvalidateMap(map);
/* Figure out what kind of mapping we're doing */
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 1e294d9..c3b4d56 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -905,11 +905,13 @@ int
SDL_LockSurface(SDL_Surface * surface)
{
if (!surface->locked) {
+#if SDL_HAVE_RLE
/* Perform the lock */
if (surface->flags & SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 1);
surface->flags |= SDL_RLEACCEL; /* save accel'd state */
}
+#endif
}
/* Increment the surface lock count, for recursive locks */
@@ -930,11 +932,13 @@ SDL_UnlockSurface(SDL_Surface * surface)
return;
}
+#if SDL_HAVE_RLE
/* Update RLE encoded surface with new data */
if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
surface->flags &= ~SDL_RLEACCEL; /* stop lying */
SDL_RLESurface(surface);
}
+#endif
}
/*
@@ -1210,6 +1214,7 @@ int SDL_ConvertPixels(int width, int height,
return SDL_InvalidParamError("dst_pitch");
}
+#if SDL_HAVE_YUV
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);
} 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)) {
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 */
if (src_format == dst_format) {
@@ -1269,9 +1280,11 @@ SDL_FreeSurface(SDL_Surface * surface)
while (surface->locked > 0) {
SDL_UnlockSurface(surface);
}
+#if SDL_HAVE_RLE
if (surface->flags & SDL_RLEACCEL) {
SDL_UnRLESurface(surface, 0);
}
+#endif
if (surface->format) {
SDL_SetSurfacePalette(surface, NULL);
SDL_FreeFormat(surface->format);