Skip to content

Commit 2a3fa66

Browse files
authored
Merge pull request #3544 from Starbuck5/more-simple-sdl3-patches-2
Fix some Surface and Window tests on SDL3
2 parents 11868c4 + 370fe4e commit 2a3fa66

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

src_c/_pygame.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
8888
SDL_StretchSurface(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST)
8989

90+
#define PG_UpdateWindowSurface SDL_UpdateWindowSurface
91+
9092
/* Emulating SDL2 SDL_LockMutex API. In SDL3, it returns void. */
9193
static inline int
9294
PG_LockMutex(SDL_mutex *mutex)
@@ -198,6 +200,12 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
198200
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
199201
SDL_SoftStretch(src, srcrect, dst, dstrect)
200202

203+
static inline bool
204+
PG_UpdateWindowSurface(SDL_Window *window)
205+
{
206+
return SDL_UpdateWindowSurface(window) == 0;
207+
}
208+
201209
static inline int
202210
PG_LockMutex(SDL_mutex *mutex)
203211
{

src_c/display.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ static int
16911691
pg_flip_internal(_DisplayState *state)
16921692
{
16931693
SDL_Window *win = pg_GetDefaultWindow();
1694-
int status = 0;
1694+
bool success = true;
16951695

16961696
/* Same check as VIDEO_INIT_CHECK() but returns -1 instead of NULL on
16971697
* fail. */
@@ -1729,12 +1729,12 @@ pg_flip_internal(_DisplayState *state)
17291729
if (new_surface != ((pgSurfaceObject *)screen)->surf) {
17301730
screen->surf = new_surface;
17311731
}
1732-
status = SDL_UpdateWindowSurface(win);
1732+
success = PG_UpdateWindowSurface(win);
17331733
}
17341734
}
17351735
Py_END_ALLOW_THREADS;
17361736

1737-
if (status < 0) {
1737+
if (!success) {
17381738
PyErr_SetString(pgExc_SDLError, SDL_GetError());
17391739
return -1;
17401740
}

src_c/surface.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,7 +4564,11 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
45644564
newfmt.Bloss = fmt->Bloss;
45654565
src = PG_ConvertSurface(src, &newfmt);
45664566
if (src) {
4567+
#if SDL_VERSION_ATLEAST(3, 0, 0)
4568+
result = SDL_BlitSurface(src, srcrect, dst, dstrect) ? 0 : -1;
4569+
#else
45674570
result = SDL_BlitSurface(src, srcrect, dst, dstrect);
4571+
#endif
45684572
SDL_FreeSurface(src);
45694573
}
45704574
else {
@@ -4594,7 +4598,11 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
45944598
}
45954599
else {
45964600
/* Py_BEGIN_ALLOW_THREADS */
4601+
#if SDL_VERSION_ATLEAST(3, 0, 0)
4602+
result = SDL_BlitSurface(src, srcrect, dst, dstrect) ? 0 : -1;
4603+
#else
45974604
result = SDL_BlitSurface(src, srcrect, dst, dstrect);
4605+
#endif
45984606
/* Py_END_ALLOW_THREADS */
45994607
}
46004608

src_c/window.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ window_get_surface(pgWindowObject *self, PyObject *_null)
201201
static PyObject *
202202
window_flip(pgWindowObject *self, PyObject *_null)
203203
{
204-
int result;
204+
bool success;
205205

206206
if (self->context == NULL) {
207207
if (!self->surf) {
@@ -211,9 +211,9 @@ window_flip(pgWindowObject *self, PyObject *_null)
211211
}
212212

213213
Py_BEGIN_ALLOW_THREADS;
214-
result = SDL_UpdateWindowSurface(self->_win);
214+
success = PG_UpdateWindowSurface(self->_win);
215215
Py_END_ALLOW_THREADS;
216-
if (result) {
216+
if (!success) {
217217
return RAISE(pgExc_SDLError, SDL_GetError());
218218
}
219219
}
@@ -879,7 +879,12 @@ window_set_opacity(pgWindowObject *self, PyObject *arg, void *v)
879879
if (PyErr_Occurred()) {
880880
return -1;
881881
}
882-
if (SDL_SetWindowOpacity(self->_win, opacity)) {
882+
#if SDL_VERSION_ATLEAST(3, 0, 0)
883+
if (!SDL_SetWindowOpacity(self->_win, opacity))
884+
#else
885+
if (SDL_SetWindowOpacity(self->_win, opacity))
886+
#endif
887+
{
883888
PyErr_SetString(pgExc_SDLError, SDL_GetError());
884889
return -1;
885890
}

0 commit comments

Comments
 (0)