Skip to content

Commit

Permalink
Porting surface.c SDL3 - second step
Browse files Browse the repository at this point in the history
  • Loading branch information
gresm committed Nov 6, 2024
1 parent 6c54b49 commit 5d79edd
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 104 deletions.
21 changes: 18 additions & 3 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@
#define PG_ConvertSurfaceFormat SDL_ConvertSurface

#define PG_PixelFormatEnum SDL_PixelFormat
#define PG_PixelFormat SDL_PixelFormatDetails
#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_GetSurfaceClipRect(surf, rect) SDL_GetSurfaceClipRect(surf, rect)

#define PG_SurfaceHasRLE SDL_SurfaceHasRLE

Expand All @@ -108,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 @@ -158,14 +166,15 @@ PG_UnlockMutex(SDL_mutex *mutex)

#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; \
rect = &surf->clip_rect; \
}

#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
Expand All @@ -183,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

0 comments on commit 5d79edd

Please sign in to comment.