Skip to content
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

Simple SDL3 patches for freetype, surface, mouse #2838

Merged
Merged
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
4 changes: 2 additions & 2 deletions src_c/_freetype.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,10 @@ _ftfont_init(pgFontObject *self, PyObject *args, PyObject *kwds)
goto end;
}

if (source->size(source) <= 0) {
if (SDL_RWsize(source) <= 0) {
PyErr_Format(PyExc_ValueError,
"Font file object has an invalid file size: %lld",
source->size(source));
SDL_RWsize(source));
goto end;
}

Expand Down
8 changes: 8 additions & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ PG_UnlockMutex(SDL_mutex *mutex)
#define PG_FORMAT_BitsPerPixel(format) format->bits_per_pixel
#define PG_FORMAT_BytesPerPixel(format) format->bytes_per_pixel

/* Mask to test if surface flags are in a fullscreen window. */
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN

#else /* ~SDL_VERSION_ATLEAST(3, 0, 0)*/
#define PG_ShowCursor() SDL_ShowCursor(SDL_ENABLE)
#define PG_HideCursor() SDL_ShowCursor(SDL_DISABLE)
Expand Down Expand Up @@ -147,6 +150,11 @@ PG_UnlockMutex(SDL_mutex *mutex)
#define PG_FORMAT_BitsPerPixel(format) format->BitsPerPixel
#define PG_FORMAT_BytesPerPixel(format) format->BytesPerPixel

/* Mask to test if surface flags are in a fullscreen window.
* SDL_WINDOW_FULLSCREEN_DESKTOP works here because it also contains
* SDL_WINDOW_FULLSCREEN. */
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN_DESKTOP

#if SDL_VERSION_ATLEAST(2, 0, 14)
#define PG_SurfaceHasRLE SDL_HasSurfaceRLE
#else
Expand Down
4 changes: 4 additions & 0 deletions src_c/freetype/ft_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,11 @@ _PGFT_Render_Array(FreeTypeInstance *ft, pgFontObject *fontobj,
/*
* Setup target surface struct
*/
#if SDL_VERSION_ATLEAST(3, 0, 0)
format.bytes_per_pixel = itemsize;
#else
format.BytesPerPixel = itemsize;
#endif
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
format.Ashift = _is_swapped(view_p) ? (itemsize - 1) * 8 : 0;
#else
Expand Down
3 changes: 1 addition & 2 deletions src_c/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ mouse_set_visible(PyObject *self, PyObject *args)
SDL_SetRelativeMouseMode(0);
}
window_flags = SDL_GetWindowFlags(win);
if (!toggle && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP ||
window_flags & SDL_WINDOW_FULLSCREEN)) {
if (!toggle && (window_flags & PG_WINDOW_FULLSCREEN_INCLUSIVE)) {
SDL_SetHint(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, "0");
}
else {
Expand Down
18 changes: 13 additions & 5 deletions src_c/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,11 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds)
pix = pgSurface_AsSurface(pg_GetDefaultWindowSurface())->format;
else {
pix = &default_format;
#if SDL_VERSION_ATLEAST(3, 0, 0)
pix->bits_per_pixel = 32;
#else
pix->BitsPerPixel = 32;
#endif
pix->Amask = 0;
pix->Rmask = 0xFF0000;
pix->Gmask = 0xFF00;
Expand Down Expand Up @@ -1534,9 +1538,14 @@ surf_convert(pgSurfaceObject *self, PyObject *args)
PyExc_ValueError,
"invalid argument specifying new format to convert to");
}
#if SDL_VERSION_ATLEAST(3, 0, 0)
format.bits_per_pixel = (Uint8)bpp;
format.bytes_per_pixel = (bpp + 7) / 8;
#else
format.BitsPerPixel = (Uint8)bpp;
format.BytesPerPixel = (bpp + 7) / 8;
if (format.BitsPerPixel > 8)
#endif
if (PG_FORMAT_BitsPerPixel((&format)) > 8)
/* Allow a 8 bit source surface with an empty palette to be
* converted to a format without a palette (pygame-ce issue
* #146). If the target format has a non-NULL palette pointer
Expand All @@ -1545,8 +1554,8 @@ surf_convert(pgSurfaceObject *self, PyObject *args)
*/
format.palette = NULL;
if (SDL_ISPIXELFORMAT_INDEXED(SDL_MasksToPixelFormatEnum(
format.BitsPerPixel, format.Rmask, format.Gmask,
format.Bmask, format.Amask))) {
PG_FORMAT_BitsPerPixel((&format)), format.Rmask,
format.Gmask, format.Bmask, format.Amask))) {
if (SDL_ISPIXELFORMAT_INDEXED(surf->format->format)) {
SDL_SetPixelFormatPalette(&format, surf->format->palette);
}
Expand Down Expand Up @@ -2434,8 +2443,7 @@ surf_get_flags(PyObject *self, PyObject *_null)
if ((sdl_flags & SDL_RLEACCEL))
flags |= PGS_RLEACCEL;
if (is_window_surf) {
if (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP ||
window_flags & SDL_WINDOW_FULLSCREEN)
if (window_flags & PG_WINDOW_FULLSCREEN_INCLUSIVE)
flags |= PGS_FULLSCREEN;
if (window_flags & SDL_WINDOW_OPENGL)
flags |= PGS_OPENGL;
Expand Down
Loading