Skip to content

Commit f129dbb

Browse files
committed
Use HasColorKey instead of GetColorKey in pgSurface_Blit
This routine doesn't use the value of GetColorKey, it just wants to know whether the surface has one. Internally, this was setting a bunch of SDL errors ("surf doesn't have colorkey"-esque), which became much more expensive in SDL 2.29.3 because of a new logging feature. Therefore lets replace it with HasColorKey (a newer function, the code was originally written before this existed). This fixes the performance regression here and even makes the performance slightly better than it was before, at least in my test scenario. Credit to itzpr for narrowing this down to SDL_GetColorKey
1 parent 7d73fc8 commit f129dbb

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src_c/surface.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,7 +3822,6 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
38223822
int result, suboffsetx = 0, suboffsety = 0;
38233823
SDL_Rect orig_clip, sub_clip;
38243824
Uint8 alpha;
3825-
Uint32 key;
38263825

38273826
/* passthrough blits to the real surface */
38283827
if (((pgSurfaceObject *)dstobj)->subsurface) {
@@ -3860,7 +3859,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
38603859
pgSurface_Prep(srcobj);
38613860

38623861
if ((blend_flags != 0 && blend_flags != PYGAME_BLEND_ALPHA_SDL2) ||
3863-
((SDL_GetColorKey(src, &key) == 0 || _PgSurface_SrcAlpha(src) == 1) &&
3862+
((SDL_HasColorKey(src) || _PgSurface_SrcAlpha(src) == 1) &&
38643863
/* This simplification is possible because a source subsurface
38653864
is converted to its owner with a clip rect and a dst
38663865
subsurface cannot be blitted to its owner because the
@@ -3916,8 +3915,7 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj,
39163915
/* Py_END_ALLOW_THREADS */
39173916
}
39183917
else if (blend_flags != PYGAME_BLEND_ALPHA_SDL2 &&
3919-
!(pg_EnvShouldBlendAlphaSDL2()) &&
3920-
SDL_GetColorKey(src, &key) != 0 &&
3918+
!(pg_EnvShouldBlendAlphaSDL2()) && !SDL_HasColorKey(src) &&
39213919
(PG_SURF_BytesPerPixel(dst) == 4 ||
39223920
PG_SURF_BytesPerPixel(dst) == 2) &&
39233921
_PgSurface_SrcAlpha(src) &&

0 commit comments

Comments
 (0)