Skip to content

Commit 14908e1

Browse files
authored
Merge pull request #2922 from Starbuck5/surface-stuff-sdl3-compat
More SDL3 compat: Surface things
2 parents 0fded82 + 54b73a7 commit 14908e1

File tree

5 files changed

+18
-83
lines changed

5 files changed

+18
-83
lines changed

src_c/_pygame.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ struct SDL_BlitMap {
190190
};
191191
#define SDL_COPY_RLE_DESIRED 0x00001000
192192

193-
SDL_bool
194-
PG_SurfaceHasRLE(SDL_Surface *surface);
193+
#define PG_SurfaceHasRLE(surface) \
194+
(((surface) == NULL) \
195+
? 0 \
196+
: ((surface)->map->info.flags & SDL_COPY_RLE_DESIRED))
197+
195198
#endif
196199

197200
#endif

src_c/draw.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,10 @@ aacircle(PyObject *self, PyObject *args, PyObject *kwargs)
786786
surf = pgSurface_AsSurface(surfobj);
787787
SURF_INIT_CHECK(surf)
788788

789-
if (surf->format->BytesPerPixel <= 0 || surf->format->BytesPerPixel > 4) {
789+
if (PG_SURF_BytesPerPixel(surf) <= 0 || PG_SURF_BytesPerPixel(surf) > 4) {
790790
return PyErr_Format(PyExc_ValueError,
791791
"unsupported surface bit depth (%d) for drawing",
792-
surf->format->BytesPerPixel);
792+
PG_SURF_BytesPerPixel(surf));
793793
}
794794

795795
CHECK_LOAD_COLOR(colorobj)

src_c/rotozoom.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,6 @@ typedef struct tColorRGBA {
3232
#define M_PI 3.141592654
3333
#endif
3434

35-
#if !SDL_VERSION_ATLEAST(2, 0, 14)
36-
// Remove this when our minimum version is 2.0.14 or larger
37-
SDL_bool
38-
PG_SurfaceHasRLE(SDL_Surface *surface)
39-
{
40-
if (surface == NULL) {
41-
return SDL_FALSE;
42-
}
43-
44-
if (!(surface->map->info.flags & SDL_COPY_RLE_DESIRED)) {
45-
return SDL_FALSE;
46-
}
47-
48-
return SDL_TRUE;
49-
}
50-
#endif
51-
5235
/*
5336
5437
32bit Zoomer with optional anti-aliasing by bilinear interpolation.

src_c/surface.c

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,6 @@ typedef struct pg_bufferinternal_s {
6363
Py_ssize_t mem[6]; /* Enough memory for dim 3 shape and strides */
6464
} pg_bufferinternal;
6565

66-
/* copy of SDL Blit mapping definitions to enable pointer casting hack
67-
for checking state of the SDL_COPY_RLE_DESIRED flag */
68-
#define PGS_COPY_RLE_DESIRED 0x00001000
69-
70-
typedef struct {
71-
Uint8 *src;
72-
int src_w, src_h;
73-
int src_pitch;
74-
int src_skip;
75-
Uint8 *dst;
76-
int dst_w, dst_h;
77-
int dst_pitch;
78-
int dst_skip;
79-
SDL_PixelFormat *src_fmt;
80-
SDL_PixelFormat *dst_fmt;
81-
Uint8 *table;
82-
int flags;
83-
Uint32 colorkey;
84-
Uint8 r, g, b, a;
85-
} pg_BlitInfo;
86-
87-
typedef struct pg_BlitMap {
88-
SDL_Surface *dst;
89-
int identity;
90-
SDL_blit blit;
91-
void *data;
92-
pg_BlitInfo info;
93-
94-
/* the version count matches the destination; mismatch indicates
95-
an invalid mapping */
96-
Uint32 dst_palette_version;
97-
Uint32 src_palette_version;
98-
} pg_BlitMap;
99-
/* end PGS_COPY_RLE_DESIRED hack definitions */
100-
10166
int
10267
pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
10368
SDL_Rect *dstrect, SDL_Rect *srcrect, int blend_flags);
@@ -2383,25 +2348,6 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds)
23832348
Py_RETURN_NONE;
23842349
}
23852350

2386-
int
2387-
pg_HasSurfaceRLE(SDL_Surface *surface)
2388-
{
2389-
pg_BlitMap *blit_map;
2390-
/* this is part of a hack to allow us to access
2391-
the COPY_RLE_DESIRED flag from pygame */
2392-
if (!surface) {
2393-
return SDL_FALSE;
2394-
}
2395-
2396-
blit_map = (pg_BlitMap *)surface->map;
2397-
2398-
if (!(blit_map->info.flags & PGS_COPY_RLE_DESIRED)) {
2399-
return SDL_FALSE;
2400-
}
2401-
2402-
return SDL_TRUE;
2403-
}
2404-
24052351
static int
24062352
_PgSurface_SrcAlpha(SDL_Surface *surf)
24072353
{
@@ -2443,7 +2389,7 @@ surf_get_flags(PyObject *self, PyObject *_null)
24432389
flags |= PGS_SRCCOLORKEY;
24442390
if (sdl_flags & SDL_PREALLOC)
24452391
flags |= PGS_PREALLOC;
2446-
if (pg_HasSurfaceRLE(surf))
2392+
if (PG_SurfaceHasRLE(surf))
24472393
flags |= PGS_RLEACCELOK;
24482394
if ((sdl_flags & SDL_RLEACCEL))
24492395
flags |= PGS_RLEACCEL;
@@ -3925,7 +3871,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
39253871
PG_SURF_BytesPerPixel(dst) == 2) &&
39263872
_PgSurface_SrcAlpha(src) &&
39273873
(SDL_ISPIXELFORMAT_ALPHA(src->format->format)) &&
3928-
!pg_HasSurfaceRLE(src) && !pg_HasSurfaceRLE(dst) &&
3874+
!PG_SurfaceHasRLE(src) && !PG_SurfaceHasRLE(dst) &&
39293875
!(src->flags & SDL_RLEACCEL) && !(dst->flags & SDL_RLEACCEL)) {
39303876
/* If we have a 32bit source surface with per pixel alpha
39313877
and no RLE we'll use pygame_Blit so we can mimic how SDL1

src_c/transform.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,9 +2309,12 @@ modify_hsl(SDL_Surface *surf, SDL_Surface *dst, float h, float s, float l)
23092309
}
23102310
}
23112311

2312-
if (fmt->BytesPerPixel == 4 || fmt->BytesPerPixel == 3) {
2313-
const int src_skip = surf->pitch - surf->w * fmt->BytesPerPixel;
2314-
const int dst_skip = dst->pitch - dst->w * fmt->BytesPerPixel;
2312+
if (PG_FORMAT_BytesPerPixel(fmt) == 4 ||
2313+
PG_FORMAT_BytesPerPixel(fmt) == 3) {
2314+
const int src_skip =
2315+
surf->pitch - surf->w * PG_FORMAT_BytesPerPixel(fmt);
2316+
const int dst_skip =
2317+
dst->pitch - dst->w * PG_FORMAT_BytesPerPixel(fmt);
23152318

23162319
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
23172320
const int Ridx = fmt->Rshift >> 3;
@@ -2351,8 +2354,8 @@ modify_hsl(SDL_Surface *surf, SDL_Surface *dst, float h, float s, float l)
23512354
dstp8[Gidx] = g;
23522355
dstp8[Bidx] = b;
23532356

2354-
srcp8 += fmt->BytesPerPixel;
2355-
dstp8 += fmt->BytesPerPixel;
2357+
srcp8 += PG_FORMAT_BytesPerPixel(fmt);
2358+
dstp8 += PG_FORMAT_BytesPerPixel(fmt);
23562359
}
23572360
srcp8 += src_skip;
23582361
dstp8 += dst_skip;
@@ -2459,7 +2462,7 @@ surf_hsl(PyObject *self, PyObject *args, PyObject *kwargs)
24592462
if (src->format->Rmask != dst->format->Rmask ||
24602463
src->format->Gmask != dst->format->Gmask ||
24612464
src->format->Bmask != dst->format->Bmask ||
2462-
src->format->BytesPerPixel != dst->format->BytesPerPixel) {
2465+
PG_SURF_BytesPerPixel(src) != PG_SURF_BytesPerPixel(dst)) {
24632466
return RAISE(PyExc_ValueError,
24642467
"Source and destination surfaces need the same format.");
24652468
}

0 commit comments

Comments
 (0)