Skip to content

Commit 1ff8759

Browse files
committed
Port SDL_LockSurface SDL3
1 parent 881a962 commit 1ff8759

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

src_c/_pygame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
137137
#define PG_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod
138138
#define PG_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod
139139
#define PG_FillSurfaceRect SDL_FillSurfaceRect
140+
#define PG_LockSurface SDL_LockSurface
140141

141142
#define PG_GetRGBA SDL_GetRGBA
142143
#define PG_GetRGB SDL_GetRGB
@@ -276,6 +277,12 @@ PG_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
276277
return SDL_FillRect(dst, rect, color) == 0;
277278
}
278279

280+
static inline bool
281+
PG_LockSurface(SDL_Surface *surface)
282+
{
283+
return SDL_LockSurface(surface) == 0;
284+
}
285+
279286
// NOTE:
280287
// palette is part of the format in SDL2, so these functions below have it
281288
// 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/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_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)