Skip to content

Fix some Surface and Window tests on SDL3 #3544

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

Open
wants to merge 1 commit 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
8 changes: 8 additions & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
SDL_StretchSurface(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST)

#define PG_UpdateWindowSurface SDL_UpdateWindowSurface

/* Emulating SDL2 SDL_LockMutex API. In SDL3, it returns void. */
static inline int
PG_LockMutex(SDL_mutex *mutex)
Expand Down Expand Up @@ -198,6 +200,12 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
#define PG_SoftStretchNearest(src, srcrect, dst, dstrect) \
SDL_SoftStretch(src, srcrect, dst, dstrect)

static inline bool
PG_UpdateWindowSurface(SDL_Window *window)
{
return SDL_UpdateWindowSurface(window) == 0;
}

static inline int
PG_LockMutex(SDL_mutex *mutex)
{
Expand Down
6 changes: 3 additions & 3 deletions src_c/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -1691,7 +1691,7 @@ static int
pg_flip_internal(_DisplayState *state)
{
SDL_Window *win = pg_GetDefaultWindow();
int status = 0;
bool success = true;

/* Same check as VIDEO_INIT_CHECK() but returns -1 instead of NULL on
* fail. */
Expand Down Expand Up @@ -1729,12 +1729,12 @@ pg_flip_internal(_DisplayState *state)
if (new_surface != ((pgSurfaceObject *)screen)->surf) {
screen->surf = new_surface;
}
status = SDL_UpdateWindowSurface(win);
success = PG_UpdateWindowSurface(win);
}
}
Py_END_ALLOW_THREADS;

if (status < 0) {
if (!success) {
PyErr_SetString(pgExc_SDLError, SDL_GetError());
return -1;
}
Expand Down
8 changes: 8 additions & 0 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -4545,7 +4545,11 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
newfmt.Bloss = fmt->Bloss;
src = PG_ConvertSurface(src, &newfmt);
if (src) {
#if SDL_VERSION_ATLEAST(3, 0, 0)
result = SDL_BlitSurface(src, srcrect, dst, dstrect) ? 0 : -1;
#else
result = SDL_BlitSurface(src, srcrect, dst, dstrect);
#endif
SDL_FreeSurface(src);
}
else {
Expand All @@ -4569,7 +4573,11 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
}
else {
/* Py_BEGIN_ALLOW_THREADS */
#if SDL_VERSION_ATLEAST(3, 0, 0)
result = SDL_BlitSurface(src, srcrect, dst, dstrect) ? 0 : -1;
#else
result = SDL_BlitSurface(src, srcrect, dst, dstrect);
#endif
/* Py_END_ALLOW_THREADS */
}

Expand Down
13 changes: 9 additions & 4 deletions src_c/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ window_get_surface(pgWindowObject *self, PyObject *_null)
static PyObject *
window_flip(pgWindowObject *self, PyObject *_null)
{
int result;
bool success;

if (self->context == NULL) {
if (!self->surf) {
Expand All @@ -211,9 +211,9 @@ window_flip(pgWindowObject *self, PyObject *_null)
}

Py_BEGIN_ALLOW_THREADS;
result = SDL_UpdateWindowSurface(self->_win);
success = PG_UpdateWindowSurface(self->_win);
Py_END_ALLOW_THREADS;
if (result) {
if (!success) {
return RAISE(pgExc_SDLError, SDL_GetError());
}
}
Expand Down Expand Up @@ -879,7 +879,12 @@ window_set_opacity(pgWindowObject *self, PyObject *arg, void *v)
if (PyErr_Occurred()) {
return -1;
}
if (SDL_SetWindowOpacity(self->_win, opacity)) {
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (!SDL_SetWindowOpacity(self->_win, opacity))
#else
if (SDL_SetWindowOpacity(self->_win, opacity))
#endif
{
PyErr_SetString(pgExc_SDLError, SDL_GetError());
return -1;
}
Expand Down
Loading