Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SDL_LEAN_AND_MEAN logic #11400

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions src/SDL_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,68 +127,64 @@
#endif

/* A few #defines to reduce SDL footprint.
Only effective when library is statically linked.
You have to manually edit this file. */
#ifndef SDL_LEAN_AND_MEAN
#define SDL_LEAN_AND_MEAN 0
#endif
Only effective when library is statically linked. */

/* Optimized functions from 'SDL_blit_0.c'
- blit with source bits_per_pixel < 8, palette */
#ifndef SDL_HAVE_BLIT_0
#define SDL_HAVE_BLIT_0 !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_BLIT_0) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_BLIT_0 1
#endif

/* Optimized functions from 'SDL_blit_1.c'
- blit with source bytes_per_pixel == 1, palette */
#ifndef SDL_HAVE_BLIT_1
#define SDL_HAVE_BLIT_1 !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_BLIT_1) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_BLIT_1 1
#endif

/* Optimized functions from 'SDL_blit_A.c'
- blit with 'SDL_BLENDMODE_BLEND' blending mode */
#ifndef SDL_HAVE_BLIT_A
#define SDL_HAVE_BLIT_A !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_BLIT_A) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_BLIT_A 1
#endif

/* Optimized functions from 'SDL_blit_N.c'
- blit with COLORKEY mode, or nothing */
#ifndef SDL_HAVE_BLIT_N
#define SDL_HAVE_BLIT_N !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_BLIT_N) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_BLIT_N 1
#endif

/* Optimized functions from 'SDL_blit_N.c'
- RGB565 conversion with Lookup tables */
#ifndef SDL_HAVE_BLIT_N_RGB565
#define SDL_HAVE_BLIT_N_RGB565 !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_BLIT_N_RGB565) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_BLIT_N_RGB565 1
#endif

/* Optimized functions from 'SDL_blit_AUTO.c'
- blit with modulate color, modulate alpha, any blending mode
- scaling or not */
#ifndef SDL_HAVE_BLIT_AUTO
#define SDL_HAVE_BLIT_AUTO !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_BLIT_AUTO) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_BLIT_AUTO 1
#endif

/* Run-Length-Encoding
- SDL_SetSurfaceColorKey() called with SDL_RLEACCEL flag */
#ifndef SDL_HAVE_RLE
#define SDL_HAVE_RLE !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_RLE) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_RLE 1
#endif

/* Software SDL_Renderer
- creation of software renderer
- *not* general blitting functions
- {blend,draw}{fillrect,line,point} internal functions */
#ifndef SDL_VIDEO_RENDER_SW
#define SDL_VIDEO_RENDER_SW !SDL_LEAN_AND_MEAN
#if !defined(SDL_VIDEO_RENDER_SW) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_VIDEO_RENDER_SW 1
#endif

/* YUV formats
- handling of YUV surfaces
- blitting and conversion functions */
#ifndef SDL_HAVE_YUV
#define SDL_HAVE_YUV !SDL_LEAN_AND_MEAN
#if !defined(SDL_HAVE_YUV) && !defined(SDL_LEAN_AND_MEAN)
#define SDL_HAVE_YUV 1
#endif

#ifdef SDL_RENDER_DISABLED
Expand Down
22 changes: 11 additions & 11 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert
renderer->textures = texture;

if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
texture->yuv = SDL_SW_CreateYUVTexture(texture->format, texture->colorspace, w, h);
#else
SDL_SetError("SDL not built with YUV support");
Expand Down Expand Up @@ -1972,7 +1972,7 @@ bool SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode)
return true;
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
static bool SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
const void *pixels, int pitch)
{
Expand Down Expand Up @@ -2084,7 +2084,7 @@ bool SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *p

if (real_rect.w == 0 || real_rect.h == 0) {
return true; // nothing to do.
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
} else if (texture->yuv) {
return SDL_UpdateTextureYUV(texture, &real_rect, pixels, pitch);
#endif
Expand All @@ -2099,7 +2099,7 @@ bool SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *p
}
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
static bool SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
Expand Down Expand Up @@ -2208,7 +2208,7 @@ bool SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
SDL_Renderer *renderer;
SDL_Rect real_rect;

Expand Down Expand Up @@ -2274,7 +2274,7 @@ bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *UVplane, int UVpitch)
{
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
SDL_Renderer *renderer;
SDL_Rect real_rect;

Expand Down Expand Up @@ -2330,7 +2330,7 @@ bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect,
#endif
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
static bool SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
void **pixels, int *pitch)
{
Expand Down Expand Up @@ -2367,7 +2367,7 @@ bool SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels,
rect = &full_rect;
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texture->yuv) {
if (!FlushRenderCommandsIfTextureNeeded(texture)) {
return false;
Expand Down Expand Up @@ -2419,7 +2419,7 @@ bool SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Su
return true;
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
static void SDL_UnlockTextureYUV(SDL_Texture *texture)
{
SDL_Texture *native = texture->native;
Expand Down Expand Up @@ -2468,7 +2468,7 @@ void SDL_UnlockTexture(SDL_Texture *texture)
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
return;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texture->yuv) {
SDL_UnlockTextureYUV(texture);
} else
Expand Down Expand Up @@ -5032,7 +5032,7 @@ static void SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying)
if (texture->native) {
SDL_DestroyTextureInternal(texture->native, is_destroying);
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texture->yuv) {
SDL_SW_DestroyYUVTexture(texture->yuv);
}
Expand Down
2 changes: 1 addition & 1 deletion src/render/SDL_sysrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ struct SDL_Renderer
bool (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels,
int pitch);
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
bool (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
Expand Down
2 changes: 1 addition & 1 deletion src/render/SDL_yuv_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// This is the software implementation of the YUV texture support

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV

#include "SDL_yuv_sw_c.h"
#include "../video/SDL_surface_c.h"
Expand Down
36 changes: 18 additions & 18 deletions src/render/direct3d/SDL_render_d3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct
IDirect3DSurface9 *defaultRenderTarget;
IDirect3DSurface9 *currentRenderTarget;
void *d3dxDLL;
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
LPDIRECT3DPIXELSHADER9 shaders[NUM_SHADERS];
#endif
LPDIRECT3DVERTEXBUFFER9 vertexBuffers[8];
Expand Down Expand Up @@ -93,7 +93,7 @@ typedef struct
D3D9_Shader shader;
const float *shader_params;

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
// YV12 texture support
bool yuv;
D3D_TextureRep utexture;
Expand Down Expand Up @@ -546,7 +546,7 @@ static bool D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_
if (!D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, PixelFormatToD3DFMT(texture->format), texture->w, texture->h)) {
return false;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
texturedata->yuv = true;
Expand Down Expand Up @@ -581,7 +581,7 @@ static bool D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (!D3D_RecreateTextureRep(data->device, &texturedata->texture)) {
return false;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
if (!D3D_RecreateTextureRep(data->device, &texturedata->utexture)) {
return false;
Expand All @@ -608,7 +608,7 @@ static bool D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch)) {
return false;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
// Skip to the correct offset into the next texture
pixels = (const void *)((const Uint8 *)pixels + rect->h * pitch);
Expand All @@ -627,7 +627,7 @@ static bool D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
return true;
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
static bool D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect,
const Uint8 *Yplane, int Ypitch,
Expand Down Expand Up @@ -664,7 +664,7 @@ static bool D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (!texturedata) {
return SDL_SetError("Texture is not currently available");
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
texturedata->locked_rect = *rect;

if (texturedata->yuv) {
Expand Down Expand Up @@ -714,7 +714,7 @@ static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (!texturedata) {
return;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
const SDL_Rect *rect = &texturedata->locked_rect;
void *pixels =
Expand Down Expand Up @@ -971,7 +971,7 @@ static bool SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_Te
if (!BindTextureRep(data->device, &texturedata->texture, 0)) {
return false;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
UpdateTextureScaleMode(data, texturedata, 1);
UpdateTextureScaleMode(data, texturedata, 2);
Expand All @@ -995,7 +995,7 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
const SDL_BlendMode blend = cmd->data.draw.blend;

if (texture != data->drawstate.texture) {
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
D3D_TextureData *oldtexturedata = data->drawstate.texture ? (D3D_TextureData *)data->drawstate.texture->internal : NULL;
D3D_TextureData *newtexturedata = texture ? (D3D_TextureData *)texture->internal : NULL;
#endif
Expand All @@ -1006,7 +1006,7 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
if (!texture) {
IDirect3DDevice9_SetTexture(data->device, 0, NULL);
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if ((!newtexturedata || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) {
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
IDirect3DDevice9_SetTexture(data->device, 2, NULL);
Expand All @@ -1016,7 +1016,7 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
return false;
}

#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (shader != data->drawstate.shader) {
const HRESULT result = IDirect3DDevice9_SetPixelShader(data->device, data->shaders[shader]);
if (FAILED(result)) {
Expand All @@ -1041,7 +1041,7 @@ static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
} else if (texture) {
D3D_TextureData *texturedata = (D3D_TextureData *)texture->internal;
UpdateDirtyTexture(data->device, &texturedata->texture);
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (texturedata->yuv) {
UpdateDirtyTexture(data->device, &texturedata->utexture);
UpdateDirtyTexture(data->device, &texturedata->vtexture);
Expand Down Expand Up @@ -1424,7 +1424,7 @@ static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
renderdata->drawstate.shader_params = NULL;
IDirect3DDevice9_SetPixelShader(renderdata->device, NULL);
IDirect3DDevice9_SetTexture(renderdata->device, 0, NULL);
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (data->yuv) {
IDirect3DDevice9_SetTexture(renderdata->device, 1, NULL);
IDirect3DDevice9_SetTexture(renderdata->device, 2, NULL);
Expand All @@ -1437,7 +1437,7 @@ static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
}

D3D_DestroyTextureRep(&data->texture);
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
D3D_DestroyTextureRep(&data->utexture);
D3D_DestroyTextureRep(&data->vtexture);
SDL_free(data->pixels);
Expand All @@ -1462,7 +1462,7 @@ static void D3D_DestroyRenderer(SDL_Renderer *renderer)
IDirect3DSurface9_Release(data->currentRenderTarget);
data->currentRenderTarget = NULL;
}
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
if (data->shaders[i]) {
IDirect3DPixelShader9_Release(data->shaders[i]);
Expand Down Expand Up @@ -1647,7 +1647,7 @@ static bool D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
renderer->SupportsBlendMode = D3D_SupportsBlendMode;
renderer->CreateTexture = D3D_CreateTexture;
renderer->UpdateTexture = D3D_UpdateTexture;
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
#endif
renderer->LockTexture = D3D_LockTexture;
Expand Down Expand Up @@ -1750,7 +1750,7 @@ static bool D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P

// Set up parameters for rendering
D3D_InitRenderState(data);
#if SDL_HAVE_YUV
#ifdef SDL_HAVE_YUV
if (caps.MaxSimultaneousTextures >= 3) {
int i;
for (i = SHADER_NONE + 1; i < SDL_arraysize(data->shaders); ++i) {
Expand Down
Loading
Loading