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

Reduce errors in src_c/surface.c when compiling with SDL3 #3215

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
33 changes: 33 additions & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
#define PG_ConvertSurfaceFormat SDL_ConvertSurface

#define PG_PixelFormatEnum SDL_PixelFormat
#define PG_PixelFormat const SDL_PixelFormatDetails
#define PG_PixelFormatMut SDL_PixelFormatDetails
#define PG_SurfaceFormatEnum(surf) (surf)->format
#define PG_GetSurfaceFormat(surf) \
SDL_GetPixelFormatDetails(PG_SurfaceFormatEnum(surf))
#define PG_GetSurfacePalette SDL_GetSurfacePalette
#define PG_SurfaceMapRGBA(surf, r, g, b, a) \
SDL_MapSurfaceRGBA(surface, r, g, b, a)
#define PG_GetSurfaceClipRect(surf, rect) SDL_GetSurfaceClipRect(surf, rect)

#define PG_SurfaceHasRLE SDL_SurfaceHasRLE

Expand All @@ -100,6 +109,13 @@ PG_UnlockMutex(SDL_mutex *mutex)
return 0;
}

/* Emulating SDL2 SDL_FillRect API. In SDL3, it returns -1 on failure. */
static inline int
PG_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
{
return SDL_FillSurfaceRect(dst, rect, color) ? 0 : -1;
}

#define PG_SURF_BitsPerPixel(surf) SDL_BITSPERPIXEL(surf->format)
#define PG_SURF_BytesPerPixel(surf) SDL_BYTESPERPIXEL(surf->format)
#define PG_FORMAT_BitsPerPixel(format) format->bits_per_pixel
Expand Down Expand Up @@ -149,6 +165,17 @@ PG_UnlockMutex(SDL_mutex *mutex)
SDL_ConvertSurfaceFormat(src, pixel_format, 0)

#define PG_PixelFormatEnum SDL_PixelFormatEnum
#define PG_PixelFormat SDL_PixelFormat
#define PG_PixelFormatMut SDL_PixelFormat
#define PG_SurfaceFormatEnum(surf) (surf)->format->format
#define PG_GetSurfaceFormat(surf) (surf)->format
#define PG_GetSurfacePalette(surf) (surf)->format->palette
#define PG_SurfaceMapRGBA(surf, r, g, b, a) \
SDL_MapRGBA(PG_GetSurfaceFormat(surface), r, g, b, a)
#define PG_GetSurfaceClipRect(surf, rect) \
{ \
rect = &surf->clip_rect; \
}

#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
SDL_SoftStretch(src, srcrect, dst, dstrect)
Expand All @@ -165,6 +192,12 @@ PG_UnlockMutex(SDL_mutex *mutex)
return SDL_UnlockMutex(mutex);
}

static inline int
PG_FillRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
{
return SDL_FillRect(dst, rect, color);
}

#define PG_SURF_BitsPerPixel(surf) surf->format->BitsPerPixel
#define PG_SURF_BytesPerPixel(surf) surf->format->BytesPerPixel
#define PG_FORMAT_BitsPerPixel(format) format->BitsPerPixel
Expand Down
Loading
Loading