Skip to content

Commit ac352fb

Browse files
committed
sdl3(display): handle SDL_RendererInfo changes
1 parent 6a389a0 commit ac352fb

File tree

1 file changed

+64
-7
lines changed

1 file changed

+64
-7
lines changed

src_c/display.c

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,6 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
12791279

12801280
if (flags & PGS_SCALED || state->unscaled_render) {
12811281
if (pg_renderer == NULL) {
1282-
SDL_RendererInfo info;
1283-
12841282
SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY,
12851283
"nearest", SDL_HINT_DEFAULT);
12861284

@@ -1319,6 +1317,26 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
13191317
SDL_SetWindowMinimumSize(win, w, h);
13201318
}
13211319

1320+
#if SDL_VERSION_ATLEAST(3, 0, 0)
1321+
int has_vsync = 0;
1322+
SDL_GetRenderVSync(pg_renderer, &has_vsync);
1323+
if (vsync && has_vsync) {
1324+
PyErr_SetString(pgExc_SDLError,
1325+
"could not enable vsync");
1326+
_display_state_cleanup(state);
1327+
goto DESTROY_WINDOW;
1328+
}
1329+
const char *name = SDL_GetRendererName(pg_renderer);
1330+
if (name && !strcmp(name, SDL_SOFTWARE_RENDERER)) {
1331+
if (PyErr_WarnEx(PyExc_Warning,
1332+
"no fast renderer available",
1333+
1) != 0) {
1334+
_display_state_cleanup(state);
1335+
goto DESTROY_WINDOW;
1336+
}
1337+
}
1338+
#else
1339+
SDL_RendererInfo info;
13221340
SDL_GetRendererInfo(pg_renderer, &info);
13231341
if (vsync && !(info.flags & SDL_RENDERER_PRESENTVSYNC)) {
13241342
PyErr_SetString(pgExc_SDLError,
@@ -1334,6 +1352,7 @@ pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds)
13341352
goto DESTROY_WINDOW;
13351353
}
13361354
}
1355+
#endif
13371356

13381357
pg_texture = SDL_CreateTexture(
13391358
pg_renderer, SDL_PIXELFORMAT_ARGB8888,
@@ -2272,6 +2291,21 @@ pg_iconify(PyObject *self, PyObject *_null)
22722291
static PyObject *
22732292
pg_get_scaled_renderer_info(PyObject *self, PyObject *_null)
22742293
{
2294+
#if SDL_VERSION_ATLEAST(3, 0, 0)
2295+
VIDEO_INIT_CHECK();
2296+
if (!pg_renderer) {
2297+
Py_RETURN_NONE;
2298+
}
2299+
2300+
const char *name = SDL_GetRendererName(pg_renderer);
2301+
if (!name) {
2302+
return RAISE(pgExc_SDLError, SDL_GetError());
2303+
}
2304+
2305+
/* flags are not being handled here but it shouldn't matter as this is
2306+
* undocumented API */
2307+
return Py_BuildValue("(si)", name, 0);
2308+
#else
22752309
SDL_RendererInfo r_info;
22762310

22772311
VIDEO_INIT_CHECK();
@@ -2284,6 +2318,7 @@ pg_get_scaled_renderer_info(PyObject *self, PyObject *_null)
22842318
}
22852319

22862320
return Py_BuildValue("(si)", r_info.name, r_info.flags);
2321+
#endif
22872322
}
22882323

22892324
static PyObject *
@@ -2355,6 +2390,19 @@ pg_is_vsync(PyObject *self, PyObject *_null)
23552390
}
23562391

23572392
if (pg_renderer != NULL) {
2393+
#if SDL_VERSION_ATLEAST(3, 0, 0)
2394+
int has_vsync = 0;
2395+
if (!SDL_GetRenderVSync(pg_renderer, &has_vsync)) {
2396+
return RAISE(pgExc_SDLError, SDL_GetError());
2397+
}
2398+
2399+
if (has_vsync) {
2400+
Py_RETURN_TRUE;
2401+
}
2402+
else {
2403+
Py_RETURN_FALSE;
2404+
}
2405+
#else
23582406
SDL_RendererInfo info;
23592407

23602408
if (SDL_GetRendererInfo(pg_renderer, &info) != 0) {
@@ -2367,6 +2415,7 @@ pg_is_vsync(PyObject *self, PyObject *_null)
23672415
else {
23682416
Py_RETURN_FALSE;
23692417
}
2418+
#endif
23702419
}
23712420

23722421
if (state->using_gl) {
@@ -2465,7 +2514,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
24652514
_DisplayState *state = DISPLAY_MOD_STATE(self);
24662515
GL_glViewport_Func p_glViewport = NULL;
24672516
SDL_SysWMinfo wm_info;
2468-
SDL_RendererInfo r_info;
2517+
int is_renderer_software = 0;
24692518

24702519
VIDEO_INIT_CHECK();
24712520
if (!win) {
@@ -2485,9 +2534,19 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
24852534
}
24862535

24872536
if (pg_renderer != NULL) {
2537+
#if SDL_VERSION_ATLEAST(3, 0, 0)
2538+
const char *r_name;
2539+
if (!(r_name = SDL_GetRendererName(pg_renderer))) {
2540+
return RAISE(pgExc_SDLError, SDL_GetError());
2541+
}
2542+
is_renderer_software = !strcmp(r_name, SDL_SOFTWARE_RENDERER);
2543+
#else
2544+
SDL_RendererInfo r_info;
24882545
if (SDL_GetRendererInfo(pg_renderer, &r_info) != 0) {
24892546
return RAISE(pgExc_SDLError, SDL_GetError());
24902547
}
2548+
is_renderer_software = r_info.flags & SDL_RENDERER_SOFTWARE;
2549+
#endif
24912550
}
24922551

24932552
switch (wm_info.subsystem) {
@@ -2583,8 +2642,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
25832642
}
25842643
SDL_SetWindowSize(win, w * scale, h * scale);
25852644

2586-
if (r_info.flags & SDL_RENDERER_SOFTWARE &&
2587-
wm_info.subsystem == SDL_SYSWM_X11) {
2645+
if (is_renderer_software && wm_info.subsystem == SDL_SYSWM_X11) {
25882646
/* display surface lost? */
25892647
SDL_DestroyTexture(pg_texture);
25902648
SDL_DestroyRenderer(pg_renderer);
@@ -2720,8 +2778,7 @@ pg_toggle_fullscreen(PyObject *self, PyObject *_null)
27202778
if (result != 0) {
27212779
return RAISE(pgExc_SDLError, SDL_GetError());
27222780
}
2723-
if (r_info.flags & SDL_RENDERER_SOFTWARE &&
2724-
wm_info.subsystem == SDL_SYSWM_X11) {
2781+
if (is_renderer_software && wm_info.subsystem == SDL_SYSWM_X11) {
27252782
if (PyErr_WarnEx(
27262783
PyExc_Warning,
27272784
"recreating software renderer in toggle_fullscreen",

0 commit comments

Comments
 (0)