Skip to content

Commit 88834fa

Browse files
authored
Merge pull request #3451 from Starbuck5/sdl3-moar-functions
Port over more SDL functions to SDL3
2 parents ac09c5b + 1ff8759 commit 88834fa

File tree

8 files changed

+28
-30
lines changed

8 files changed

+28
-30
lines changed

src_c/_pygame.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
136136
#define PG_GetSurfaceBlendMode SDL_GetSurfaceBlendMode
137137
#define PG_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod
138138
#define PG_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod
139+
#define PG_FillSurfaceRect SDL_FillSurfaceRect
140+
#define PG_LockSurface SDL_LockSurface
139141

140142
#define PG_GetRGBA SDL_GetRGBA
141143
#define PG_GetRGB SDL_GetRGB
@@ -269,6 +271,18 @@ PG_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
269271
return SDL_SetSurfaceAlphaMod(surface, alpha) == 0;
270272
}
271273

274+
static inline bool
275+
PG_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
276+
{
277+
return SDL_FillRect(dst, rect, color) == 0;
278+
}
279+
280+
static inline bool
281+
PG_LockSurface(SDL_Surface *surface)
282+
{
283+
return SDL_LockSurface(surface) == 0;
284+
}
285+
272286
// NOTE:
273287
// palette is part of the format in SDL2, so these functions below have it
274288
// as a separate parameter to be consistent with the SDL3 signature.

src_c/alphablit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
8080
/* Lock the destination if it's in hardware */
8181
dst_locked = 0;
8282
if (SDL_MUSTLOCK(dst)) {
83-
if (SDL_LockSurface(dst) < 0) {
83+
if (!PG_LockSurface(dst)) {
8484
okay = 0;
8585
}
8686
else {
@@ -90,7 +90,7 @@ SoftBlitPyGame(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
9090
/* Lock the source if it's in hardware */
9191
src_locked = 0;
9292
if (SDL_MUSTLOCK(src)) {
93-
if (SDL_LockSurface(src) < 0) {
93+
if (!PG_LockSurface(src)) {
9494
okay = 0;
9595
}
9696
else {

src_c/draw.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,6 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs)
11781178
int top_left_radius = -1, top_right_radius = -1, bottom_left_radius = -1,
11791179
bottom_right_radius = -1;
11801180
SDL_Rect sdlrect;
1181-
int result;
11821181
SDL_Rect clipped;
11831182
int drawn_area[4] = {INT_MAX, INT_MAX, INT_MIN,
11841183
INT_MIN}; /* Used to store bounding box values */
@@ -1248,10 +1247,10 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs)
12481247
else {
12491248
pgSurface_Prep(surfobj);
12501249
pgSurface_Lock(surfobj);
1251-
result = SDL_FillRect(surf, &clipped, color);
1250+
bool success = PG_FillSurfaceRect(surf, &clipped, color);
12521251
pgSurface_Unlock(surfobj);
12531252
pgSurface_Unprep(surfobj);
1254-
if (result != 0) {
1253+
if (!success) {
12551254
return RAISE(pgExc_SDLError, SDL_GetError());
12561255
}
12571256
}

src_c/freetype/ft_render.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ _PGFT_Render_ExistingSurface(FreeTypeInstance *ft, pgFontObject *fontobj,
286286
Layout *font_text;
287287

288288
if (SDL_MUSTLOCK(surface)) {
289-
if (SDL_LockSurface(surface) == -1) {
289+
if (!PG_LockSurface(surface)) {
290290
SDL_FreeSurface(surface);
291291
PyErr_SetString(pgExc_SDLError, SDL_GetError());
292292
return -1;
@@ -445,7 +445,7 @@ _PGFT_Render_NewSurface(FreeTypeInstance *ft, pgFontObject *fontobj,
445445
}
446446

447447
if (SDL_MUSTLOCK(surface)) {
448-
if (SDL_LockSurface(surface) == -1) {
448+
if (!PG_LockSurface(surface)) {
449449
PyErr_SetString(pgExc_SDLError, SDL_GetError());
450450
SDL_FreeSurface(surface);
451451
return 0;

src_c/surface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ surf_fill(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
21982198
else {
21992199
pgSurface_Prep(self);
22002200
pgSurface_Lock((pgSurfaceObject *)self);
2201-
result = SDL_FillRect(surf, &sdlrect, color);
2201+
result = PG_FillSurfaceRect(surf, &sdlrect, color) - 1;
22022202
pgSurface_Unlock((pgSurfaceObject *)self);
22032203
pgSurface_Unprep(self);
22042204
}
@@ -2938,7 +2938,7 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds)
29382938
if (!repeat) {
29392939
if (dx >= w || dx <= -w || dy >= h || dy <= -h) {
29402940
if (erase) {
2941-
if (SDL_FillRect(surf, NULL, 0) == -1) {
2941+
if (!PG_FillSurfaceRect(surf, NULL, 0)) {
29422942
PyErr_SetString(pgExc_SDLError, SDL_GetError());
29432943
return NULL;
29442944
}

src_c/surface_fill.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ surface_fill_blend(SDL_Surface *surface, SDL_Rect *rect, Uint32 color,
927927

928928
/* Lock the surface, if needed */
929929
if (SDL_MUSTLOCK(surface)) {
930-
if (SDL_LockSurface(surface) < 0) {
930+
if (!PG_LockSurface(surface)) {
931931
return -1;
932932
}
933933
locked = 1;

src_c/surflock.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ pgSurface_LockBy(pgSurfaceObject *surfobj, PyObject *lockobj)
9999
if (surf->subsurface != NULL) {
100100
pgSurface_Prep(surfobj);
101101
}
102-
#if SDL_VERSION_ATLEAST(3, 0, 0)
103-
if (!SDL_LockSurface(surf->surf))
104-
#else
105-
if (SDL_LockSurface(surf->surf) == -1)
106-
#endif
107-
{
102+
if (!PG_LockSurface(surf->surf)) {
108103
PyErr_SetString(PyExc_RuntimeError, "error locking surface");
109104
return 0;
110105
}

src_c/transform.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,20 +2420,10 @@ solid_overlay(pgSurfaceObject *srcobj, Uint32 color, pgSurfaceObject *dstobj,
24202420
int src_lock = SDL_MUSTLOCK(src);
24212421
int dst_lock = src != newsurf && SDL_MUSTLOCK(newsurf);
24222422

2423-
#if SDL_VERSION_ATLEAST(3, 0, 0)
2424-
if (src_lock && !SDL_LockSurface(src))
2425-
#else
2426-
if (src_lock && SDL_LockSurface(src) < 0)
2427-
#endif
2428-
{
2423+
if (src_lock && !PG_LockSurface(src)) {
24292424
return NULL;
24302425
}
2431-
#if SDL_VERSION_ATLEAST(3, 0, 0)
2432-
if (dst_lock && !SDL_LockSurface(newsurf))
2433-
#else
2434-
if (dst_lock && SDL_LockSurface(newsurf) < 0)
2435-
#endif
2436-
{
2426+
if (dst_lock && !PG_LockSurface(newsurf)) {
24372427
if (src_lock) {
24382428
SDL_UnlockSurface(src);
24392429
}
@@ -2696,13 +2686,13 @@ modify_hsl(SDL_Surface *surf, PG_PixelFormat *fmt, SDL_Surface *dst,
26962686
{
26972687
int surf_locked = 0;
26982688
if (SDL_MUSTLOCK(surf)) {
2699-
if (SDL_LockSurface(surf) == 0) {
2689+
if (PG_LockSurface(surf)) {
27002690
surf_locked = 1;
27012691
}
27022692
}
27032693
int dst_locked = 0;
27042694
if (SDL_MUSTLOCK(dst)) {
2705-
if (SDL_LockSurface(dst) == 0) {
2695+
if (PG_LockSurface(dst)) {
27062696
dst_locked = 1;
27072697
}
27082698
}

0 commit comments

Comments
 (0)