Skip to content

Commit 20440c3

Browse files
committed
Fix incorrect clip rect port, add TODO SDL3 comment
Update surface.c
1 parent 2901dfa commit 20440c3

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src_c/surface.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args)
15441544
bool success =
15451545
PG_SetSurfaceRLE(surf, (flags & PGS_RLEACCEL) ? SDL_TRUE : SDL_FALSE);
15461546
/* HACK HACK HACK */
1547-
// TODO: SDL3: figure out how to port this or if it's relevant to SDL3.
1547+
// TODO SDL3: figure out how to port this or if it's relevant to SDL3.
15481548
#if !SDL_VERSION_ATLEAST(3, 0, 0)
15491549
if ((surf->flags & SDL_RLEACCEL) && (!(flags & PGS_RLEACCEL))) {
15501550
/* hack to strip SDL_RLEACCEL flag off surface immediately when
@@ -3019,6 +3019,8 @@ surf_get_flags(PyObject *self, PyObject *_null)
30193019
if (PG_SurfaceHasRLE(surf)) {
30203020
flags |= PGS_RLEACCELOK;
30213021
}
3022+
// TODO SDL3: figure out how to properly emulate SDL2 check/relevance
3023+
// Current implementation is just a placeholder.
30223024
#if SDL_VERSION_ATLEAST(3, 0, 0)
30233025
if (SDL_SurfaceHasRLE(surf)) {
30243026
flags |= PGS_RLEACCEL;
@@ -4379,8 +4381,8 @@ surf_get_pixels_address(PyObject *self, PyObject *closure)
43794381
}
43804382

43814383
static int
4382-
surface_do_overlap(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *srcclip,
4383-
SDL_Surface *dst, SDL_Rect *dstrect)
4384+
surface_do_overlap(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
4385+
SDL_Rect *dstrect, SDL_Rect *clip)
43844386
{
43854387
Uint8 *srcpixels;
43864388
Uint8 *dstpixels;
@@ -4414,23 +4416,23 @@ surface_do_overlap(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *srcclip,
44144416
}
44154417

44164418
/* clip the destination rectangle against the clip rectangle */
4417-
x = srcclip->x - dstx;
4419+
x = clip->x - dstx;
44184420
if (x > 0) {
44194421
w -= x;
44204422
dstx += x;
44214423
srcx += x;
44224424
}
4423-
x = dstx + w - srcclip->x - srcclip->w;
4425+
x = dstx + w - clip->x - clip->w;
44244426
if (x > 0) {
44254427
w -= x;
44264428
}
4427-
y = srcclip->y - dsty;
4429+
y = clip->y - dsty;
44284430
if (y > 0) {
44294431
h -= y;
44304432
dsty += y;
44314433
srcy += y;
44324434
}
4433-
y = dsty + h - srcclip->y - srcclip->h;
4435+
y = dsty + h - clip->y - clip->h;
44344436
if (y > 0) {
44354437
h -= y;
44364438
}
@@ -4468,12 +4470,12 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
44684470
SDL_Surface *dst = pgSurface_AsSurface(dstobj);
44694471
SDL_Surface *subsurface = NULL;
44704472
int result, suboffsetx = 0, suboffsety = 0;
4471-
SDL_Rect orig_clip, sub_clip, srcclip;
4473+
SDL_Rect orig_clip, sub_clip, dstclip;
44724474
#if !SDL_VERSION_ATLEAST(3, 0, 0)
44734475
Uint8 alpha;
44744476
#endif
44754477

4476-
if (!PG_GetSurfaceClipRect(src, &srcclip)) {
4478+
if (!PG_GetSurfaceClipRect(dst, &dstclip)) {
44774479
PyErr_SetString(pgExc_SDLError, SDL_GetError());
44784480
return 0;
44794481
}
@@ -4521,7 +4523,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
45214523
owner is locked.
45224524
*/
45234525
dst->pixels == src->pixels && srcrect != NULL &&
4524-
surface_do_overlap(src, srcrect, &srcclip, dst, dstrect))) {
4526+
surface_do_overlap(src, srcrect, dst, dstrect, &dstclip))) {
45254527
/* Py_BEGIN_ALLOW_THREADS */
45264528
result = pygame_Blit(src, srcrect, dst, dstrect, blend_flags);
45274529
/* Py_END_ALLOW_THREADS */

0 commit comments

Comments
 (0)