diff --git a/src_c/alphablit.c b/src_c/alphablit.c index 52bd07ad32..b7333430e0 100644 --- a/src_c/alphablit.c +++ b/src_c/alphablit.c @@ -71,21 +71,16 @@ typedef struct int d_skip; SDL_PixelFormat *src; SDL_PixelFormat *dst; -#if IS_SDLv1 - Uint32 src_flags; - Uint32 dst_flags; -#else /* IS_SDLv2 */ Uint8 src_blanket_alpha; int src_has_colorkey; Uint32 src_colorkey; SDL_BlendMode src_blend; SDL_BlendMode dst_blend; -#endif /* IS_SDLv2 */ } SDL_BlitInfo; static void alphablit_alpha (SDL_BlitInfo * info); -#if IS_SDLv2 && (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON)) +#if (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON)) static void alphablit_alpha_sse2_argb_surf_alpha (SDL_BlitInfo * info); static void alphablit_alpha_sse2_argb_no_surf_alpha (SDL_BlitInfo * info); static void alphablit_alpha_sse2_argb_no_surf_alpha_opaque_dst (SDL_BlitInfo * info); @@ -160,16 +155,6 @@ SoftBlitPyGame (SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, /* Set up the blit information */ info.width = srcrect->w; info.height = srcrect->h; -#if IS_SDLv1 - info.s_pixels = (Uint8 *) src->pixels + src->offset + - (Uint16) srcrect->y * src->pitch + - (Uint16) srcrect->x * src->format->BytesPerPixel; - info.s_pxskip = src->format->BytesPerPixel; - info.s_skip = src->pitch - info.width * src->format->BytesPerPixel; - info.d_pixels = (Uint8 *) dst->pixels + dst->offset + - (Uint16) dstrect->y * dst->pitch + - (Uint16) dstrect->x * dst->format->BytesPerPixel; -#else /* IS_SDLv2 */ info.s_pixels = (Uint8 *) src->pixels + (Uint16) srcrect->y * src->pitch + (Uint16) srcrect->x * src->format->BytesPerPixel; @@ -178,22 +163,16 @@ SoftBlitPyGame (SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, info.d_pixels = (Uint8 *) dst->pixels + (Uint16) dstrect->y * dst->pitch + (Uint16) dstrect->x * dst->format->BytesPerPixel; -#endif /* IS_SDLv2 */ info.d_pxskip = dst->format->BytesPerPixel; info.d_skip = dst->pitch - info.width * dst->format->BytesPerPixel; info.src = src->format; info.dst = dst->format; -#if IS_SDLv1 - info.src_flags = src->flags; - info.dst_flags = dst->flags; -#else /* IS_SDLv2 */ SDL_GetSurfaceAlphaMod (src, &info.src_blanket_alpha); info.src_has_colorkey = SDL_GetColorKey (src, &info.src_colorkey) == 0; if (SDL_GetSurfaceBlendMode(src, &info.src_blend) || SDL_GetSurfaceBlendMode(dst, &info.dst_blend)) { okay = 0; } -#endif /* IS_SDLv2 */ if (okay){ if (info.d_pixels > info.s_pixels) { @@ -226,15 +205,6 @@ SoftBlitPyGame (SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, { case 0: { -#if IS_SDLv1 - if (src->flags & SDL_SRCALPHA && src->format->Amask) - alphablit_alpha (&info); - else if (src->flags & SDL_SRCCOLORKEY) - alphablit_colorkey (&info); - else - alphablit_solid (&info); - break; -#else /* IS_SDLv2 */ if (info.src_blend != SDL_BLENDMODE_NONE && src->format->Amask) { @@ -299,7 +269,6 @@ SoftBlitPyGame (SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, alphablit_solid (&info); } break; -#endif /* IS_SDLv2 */ } case PYGAME_BLEND_ADD: { @@ -443,13 +412,8 @@ blit_blend_rgba_add (SDL_BlitInfo * info) Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; Uint32 tmp; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ if (!dstppa) { @@ -457,21 +421,12 @@ blit_blend_rgba_add (SDL_BlitInfo * info) return; } -#if IS_SDLv1 - if (srcbpp == 4 && dstbpp == 4 && - srcfmt->Rmask == dstfmt->Rmask && - srcfmt->Gmask == dstfmt->Gmask && - srcfmt->Bmask == dstfmt->Bmask && - srcfmt->Amask == dstfmt->Amask && - info->src_flags & SDL_SRCALPHA) -#else /* IS_SDLv2 */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask && srcfmt->Amask == dstfmt->Amask && info->src_blend != SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { int incr = srcpxskip > 0 ? 1 : -1; if (incr < 0) @@ -597,13 +552,8 @@ blit_blend_rgba_sub (SDL_BlitInfo * info) Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; Sint32 tmp2; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ if (!dstppa) { @@ -611,21 +561,12 @@ blit_blend_rgba_sub (SDL_BlitInfo * info) return; } -#if IS_SDLv1 - if (srcbpp == 4 && dstbpp == 4 && - srcfmt->Rmask == dstfmt->Rmask && - srcfmt->Gmask == dstfmt->Gmask && - srcfmt->Bmask == dstfmt->Bmask && - srcfmt->Amask == dstfmt->Amask && - info->src_flags & SDL_SRCALPHA) -#else /* IS_SDLv2 */ if (srcbpp == 4 && dstbpp == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask && srcfmt->Amask == dstfmt->Amask && info->src_blend != SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { int incr = srcpxskip > 0 ? 1 : -1; if (incr < 0) @@ -751,13 +692,8 @@ blit_blend_rgba_mul (SDL_BlitInfo * info) Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; Uint32 tmp; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ if (!dstppa) { @@ -770,11 +706,7 @@ blit_blend_rgba_mul (SDL_BlitInfo * info) srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask && srcfmt->Amask == dstfmt->Amask && -#if IS_SDLv1 - info->src_flags & SDL_SRCALPHA) -#else /* IS_SDLv2 */ info->src_blend != SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { int incr = srcpxskip > 0 ? 1 : -1; if (incr < 0) @@ -899,13 +831,8 @@ blit_blend_rgba_min (SDL_BlitInfo * info) int dstbpp = dstfmt->BytesPerPixel; Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ if (!dstppa) { @@ -918,11 +845,7 @@ blit_blend_rgba_min (SDL_BlitInfo * info) srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask && srcfmt->Amask == dstfmt->Amask && -#if IS_SDLv1 - info->src_flags & SDL_SRCALPHA) -#else /* IS_SDLv2 */ info->src_blend != SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { int incr = srcpxskip > 0 ? 1 : -1; if (incr < 0) @@ -1047,13 +970,8 @@ blit_blend_rgba_max (SDL_BlitInfo * info) int dstbpp = dstfmt->BytesPerPixel; Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ if (!dstppa) { @@ -1066,11 +984,7 @@ blit_blend_rgba_max (SDL_BlitInfo * info) srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask && srcfmt->Amask == dstfmt->Amask && -#if IS_SDLv1 - info->src_flags & SDL_SRCALPHA) -#else /* IS_SDLv2 */ info->src_blend != SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { int incr = srcpxskip > 0 ? 1 : -1; if (incr < 0) @@ -1322,19 +1236,10 @@ blit_blend_premultiplied (SDL_BlitInfo * info) int dstbpp = dstfmt->BytesPerPixel; Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - if (srcbpp >= 3 && dstbpp >= 3 && !(info->src_flags & SDL_SRCALPHA)) -#else /* IS_SDLv2 */ if (srcbpp >= 3 && dstbpp >= 3 && info->src_blend == SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { size_t srcoffsetR, srcoffsetG, srcoffsetB; size_t dstoffsetR, dstoffsetG, dstoffsetB; @@ -1553,19 +1458,10 @@ blit_blend_add (SDL_BlitInfo * info) Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; Uint32 tmp; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - if (srcbpp >= 3 && dstbpp >= 3 && !(info->src_flags & SDL_SRCALPHA)) -#else /* IS_SDLv2 */ if (srcbpp >= 3 && dstbpp >= 3 && info->src_blend == SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { size_t srcoffsetR, srcoffsetG, srcoffsetB; size_t dstoffsetR, dstoffsetG, dstoffsetB; @@ -1749,19 +1645,10 @@ blit_blend_sub (SDL_BlitInfo * info) Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; Sint32 tmp2; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - if (srcbpp >= 3 && dstbpp >= 3 && !(info->src_flags & SDL_SRCALPHA)) -#else /* IS_SDLv2 */ if (srcbpp >= 3 && dstbpp >= 3 && info->src_blend == SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { size_t srcoffsetR, srcoffsetG, srcoffsetB; size_t dstoffsetR, dstoffsetG, dstoffsetB; @@ -1945,19 +1832,10 @@ blit_blend_mul (SDL_BlitInfo * info) Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; Uint32 tmp; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - if (srcbpp >= 3 && dstbpp >= 3 && !(info->src_flags & SDL_SRCALPHA)) -#else /* IS_SDLv2 */ if (srcbpp >= 3 && dstbpp >= 3 && info->src_blend == SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { size_t srcoffsetR, srcoffsetG, srcoffsetB; size_t dstoffsetR, dstoffsetG, dstoffsetB; @@ -2144,19 +2022,10 @@ blit_blend_min (SDL_BlitInfo * info) int dstbpp = dstfmt->BytesPerPixel; Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - if (srcbpp >= 3 && dstbpp >= 3 && !(info->src_flags & SDL_SRCALPHA)) -#else /* IS_SDLv2 */ if (srcbpp >= 3 && dstbpp >= 3 && info->src_blend == SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { size_t srcoffsetR, srcoffsetG, srcoffsetB; size_t dstoffsetR, dstoffsetG, dstoffsetB; @@ -2345,19 +2214,10 @@ blit_blend_max (SDL_BlitInfo * info) int dstbpp = dstfmt->BytesPerPixel; Uint8 dR, dG, dB, dA, sR, sG, sB, sA; Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#else /* IS_SDLv2 */ int srcppa = info->src_blend != SDL_BLENDMODE_NONE && srcfmt->Amask; int dstppa = info->dst_blend != SDL_BLENDMODE_NONE && dstfmt->Amask; -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - if (srcbpp >= 3 && dstbpp >= 3 && !(info->src_flags & SDL_SRCALPHA)) -#else /* IS_SDLv2 */ if (srcbpp >= 3 && dstbpp >= 3 && info->src_blend == SDL_BLENDMODE_NONE) -#endif /* IS_SDLv2 */ { size_t srcoffsetR, srcoffsetG, srcoffsetB; size_t dstoffsetR, dstoffsetG, dstoffsetB; @@ -2530,7 +2390,7 @@ blit_blend_max (SDL_BlitInfo * info) /* --------------------------------------------------------- */ -#if IS_SDLv2 && (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON)) +#if (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON)) static void alphablit_alpha_sse2_argb_surf_alpha (SDL_BlitInfo * info) { @@ -3279,18 +3139,10 @@ alphablit_alpha (SDL_BlitInfo * info) SDL_PixelFormat *dstfmt = info->dst; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; -#if IS_SDLv1 - int dR, dG, dB, dA, sR, sG, sB, sA; -#else /* IS_SDLv2 */ Uint8 dR, dG, dB, dA, sR, sG, sB, sA; int dRi, dGi, dBi, dAi, sRi, sGi, sBi, sAi; Uint32 modulateA = info->src_blanket_alpha; -#endif /* IS_SDLv2 */ Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#endif /* IS_SDLv1 */ @@ -3304,17 +3156,6 @@ alphablit_alpha (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt); - GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXELVALS_1(sRi, sGi, sBi, sAi, src, srcfmt); @@ -3324,7 +3165,6 @@ alphablit_alpha (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3333,18 +3173,6 @@ alphablit_alpha (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt); - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXELVALS_1(sRi, sGi, sBi, sAi, src, srcfmt); @@ -3359,7 +3187,6 @@ alphablit_alpha (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3371,18 +3198,6 @@ alphablit_alpha (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3393,7 +3208,6 @@ alphablit_alpha (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3403,19 +3217,6 @@ alphablit_alpha (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3434,7 +3235,6 @@ alphablit_alpha (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3458,47 +3258,23 @@ alphablit_colorkey (SDL_BlitInfo * info) SDL_PixelFormat *dstfmt = info->dst; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; -#if IS_SDLv1 - int dR, dG, dB, dA, sR, sG, sB, sA; - int alpha = srcfmt->alpha; - Uint32 colorkey = srcfmt->colorkey; -#else /* IS_SDLv2 */ Uint8 dR, dG, dB, dA, sR, sG, sB, sA; int dRi, dGi, dBi, dAi, sRi, sGi, sBi, sAi; int alpha = info->src_blanket_alpha; Uint32 colorkey = info->src_colorkey; -#endif /* IS_SDLv2 */ Uint32 pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#endif /* IS_SDLv1 */ /* printf ("Colorkey blit with %d and %d\n", srcbpp, dstbpp); */ -#if IS_SDLv2 assert (info->src_has_colorkey); -#endif /* IS_SDLv2 */ if (srcbpp == 1) { if (dstbpp == 1) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt); - sA = (*src == colorkey) ? 0 : alpha; - GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - *dst = (Uint8) SDL_MapRGB (dstfmt, dR, dG, dB); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXELVALS_1(sRi, sGi, sBi, sAi, src, srcfmt); @@ -3509,7 +3285,6 @@ alphablit_colorkey (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3518,19 +3293,6 @@ alphablit_colorkey (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt); - sA = (*src == colorkey) ? 0 : alpha; - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXELVALS_1(sRi, sGi, sBi, sAi, src, srcfmt); @@ -3546,7 +3308,6 @@ alphablit_colorkey (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3558,19 +3319,6 @@ alphablit_colorkey (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - sA = (pixel == colorkey) ? 0 : alpha; - GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - *dst = (Uint8) SDL_MapRGB (dstfmt, dR, dG, dB); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3582,7 +3330,6 @@ alphablit_colorkey (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3597,22 +3344,6 @@ alphablit_colorkey (SDL_BlitInfo * info) SET_OFFSETS_24 (offsetR, offsetG, offsetB, dstfmt); while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - sA = (pixel == colorkey) ? 0 : alpha; - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - dst[offsetR] = dR; - dst[offsetG] = dG; - dst[offsetB] = dB; - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3631,7 +3362,6 @@ alphablit_colorkey (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3640,20 +3370,6 @@ alphablit_colorkey (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - sA = (pixel == colorkey) ? 0 : alpha; - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, sA, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3670,7 +3386,6 @@ alphablit_colorkey (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3694,19 +3409,10 @@ alphablit_solid (SDL_BlitInfo * info) SDL_PixelFormat *dstfmt = info->dst; int srcbpp = srcfmt->BytesPerPixel; int dstbpp = dstfmt->BytesPerPixel; -#if IS_SDLv1 - int dR, dG, dB, dA, sR, sG, sB, sA; - int alpha = srcfmt->alpha; -#else /* IS_SDLv2 */ Uint8 dR, dG, dB, dA, sR, sG, sB, sA; int dRi, dGi, dBi, dAi, sRi, sGi, sBi; int alpha = info->src_blanket_alpha; -#endif /* IS_SDLv2 */ int pixel; -#if IS_SDLv1 - int srcppa = (info->src_flags & SDL_SRCALPHA && srcfmt->Amask); - int dstppa = (info->dst_flags & SDL_SRCALPHA && dstfmt->Amask); -#endif /* IS_SDLv1 */ /* printf ("Solid blit with %d and %d\n", srcbpp, dstbpp); @@ -3718,17 +3424,6 @@ alphablit_solid (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt); - GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt); - ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA); - *dst = (Uint8) SDL_MapRGB (dstfmt, dR, dG, dB); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXELVALS_1(sRi, sGi, sBi, dAi, src, srcfmt); @@ -3738,7 +3433,6 @@ alphablit_solid (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3747,18 +3441,6 @@ alphablit_solid (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXELVALS_1(sR, sG, sB, sA, src, srcfmt); - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXELVALS_1(sRi, sGi, sBi, dAi, src, srcfmt); @@ -3773,7 +3455,6 @@ alphablit_solid (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3785,18 +3466,6 @@ alphablit_solid (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - GET_PIXELVALS_1(dR, dG, dB, dA, dst, dstfmt); - ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA); - *dst = (Uint8) SDL_MapRGB (dstfmt, dR, dG, dB); - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3807,7 +3476,6 @@ alphablit_solid (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3822,21 +3490,6 @@ alphablit_solid (SDL_BlitInfo * info) SET_OFFSETS_24 (offsetR, offsetG, offsetB, dstfmt); while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA); - dst[offsetR] = dR; - dst[offsetG] = dG; - dst[offsetB] = dB; - src += srcpxskip; - dst += dstpxskip; - }, n, width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3854,7 +3507,6 @@ alphablit_solid (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n, width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } @@ -3863,19 +3515,6 @@ alphablit_solid (SDL_BlitInfo * info) { while (height--) { -#if IS_SDLv1 - LOOP_UNROLLED4( - { - GET_PIXEL(pixel, srcbpp, src); - GET_PIXELVALS (sR, sG, sB, sA, pixel, srcfmt, srcppa); - GET_PIXEL (pixel, dstbpp, dst); - GET_PIXELVALS (dR, dG, dB, dA, pixel, dstfmt, dstppa); - ALPHA_BLEND (sR, sG, sB, alpha, dR, dG, dB, dA); - CREATE_PIXEL(dst, dR, dG, dB, dA, dstbpp, dstfmt); - src += srcpxskip; - dst += dstpxskip; - }, n ,width); -#else /* IS_SDLv2 */ LOOP_UNROLLED4( { GET_PIXEL(pixel, srcbpp, src); @@ -3891,7 +3530,6 @@ alphablit_solid (SDL_BlitInfo * info) src += srcpxskip; dst += dstpxskip; }, n ,width); -#endif /* IS_SDLv2 */ src += srcskip; dst += dstskip; } diff --git a/src_c/base.c b/src_c/base.c index bbb6554628..50596b29ad 100644 --- a/src_c/base.c +++ b/src_c/base.c @@ -79,11 +79,9 @@ static PyObject *pgExc_BufferError = NULL; static PyObject *pg_quit_functions = NULL; static int pg_is_init = 0; static int pg_sdl_was_init = 0; -#if IS_SDLv2 SDL_Window *pg_default_window = NULL; pgSurfaceObject *pg_default_screen = NULL; static char * pg_env_blend_alpha_SDL2 = NULL; -#endif /* IS_SDLv2 */ static void pg_install_parachute(void); @@ -164,7 +162,6 @@ static void _pg_release_buffer_array(Py_buffer *); static void _pg_release_buffer_generic(Py_buffer *); -#if IS_SDLv2 static SDL_Window * pg_GetDefaultWindow(void); static void @@ -175,29 +172,10 @@ static void pg_SetDefaultWindowSurface(pgSurfaceObject *); static char * pg_EnvShouldBlendAlphaSDL2(void); -#endif /* IS_SDLv2 */ static int pg_CheckSDLVersions(void) /*compare compiled to linked*/ { -#if IS_SDLv1 - SDL_version compiled; - const SDL_version *linked; - - SDL_VERSION(&compiled); - linked = SDL_Linked_Version(); - - /*only check the major and minor version numbers. - we will relax any differences in 'patch' version.*/ - - if (compiled.major != linked->major || compiled.minor != linked->minor) { - PyErr_Format(PyExc_RuntimeError, - "SDL compiled with version %d.%d.%d, linked to %d.%d.%d", - compiled.major, compiled.minor, compiled.patch, - linked->major, linked->minor, linked->patch); - return 0; - } -#else /* IS_SDLv2 */ SDL_version compiled; SDL_version linked; @@ -214,7 +192,6 @@ pg_CheckSDLVersions(void) /*compare compiled to linked*/ linked.major, linked.minor, linked.patch); return 0; } -#endif /* IS_SDLv2 */ return 1; } @@ -335,11 +312,7 @@ pg_init(PyObject *self) IMPPREFIX "font", IMPPREFIX "freetype", IMPPREFIX "mixer", -#if IS_SDLv2 /* IMPPREFIX "_sdl2.controller", Is this required? Comment for now*/ -#else - IMPPREFIX "cdrom", -#endif NULL }; @@ -355,9 +328,7 @@ pg_init(PyObject *self) pg_sdl_was_init = SDL_Init(SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) == 0; #endif -#if IS_SDLv2 pg_env_blend_alpha_SDL2 = SDL_getenv("PYGAME_BLEND_ALPHA_SDL2"); -#endif /* IS_SDLv2 */ /* initialize all pygame modules */ for (i = 0; modnames[i]; i++) { @@ -391,17 +362,10 @@ pg_atexit_quit(void) static PyObject * pg_get_sdl_version(PyObject *self) { -#if IS_SDLv1 - const SDL_version *v; - - v = SDL_Linked_Version(); - return Py_BuildValue("iii", v->major, v->minor, v->patch); -#else /* IS_SDLv2 */ SDL_version v; SDL_GetVersion(&v); return Py_BuildValue("iii", v.major, v.minor, v.patch); -#endif /* IS_SDLv2 */ } static PyObject * @@ -418,11 +382,7 @@ _pg_quit(void) /* Put all the module names we want to quit in this array */ const char *modnames[] = { -#if IS_SDLv2 /* IMPPREFIX "_sdl2.controller", Is this required?, comment for now */ -#else - IMPPREFIX "cdrom" -#endif IMPPREFIX "mixer", IMPPREFIX "freetype", IMPPREFIX "font", @@ -656,17 +616,7 @@ pg_RGBAFromObj(PyObject *obj, Uint8 *RGBA) static PyObject * pg_get_error(PyObject *self) { -#if IS_SDLv1 && !defined(PYPY_VERSION) - /* SDL 1's encoding is ambiguous */ - PyObject *obj; - if ((obj = PyUnicode_DecodeUTF8(SDL_GetError(), - strlen(SDL_GetError()), "strict"))) - return obj; - PyErr_Clear(); - return PyUnicode_DecodeLocale(SDL_GetError(), "surrogateescape"); -#else /* IS_SDLv2 */ return Text_FromUTF8(SDL_GetError()); -#endif /* IS_SDLv2 */ } static PyObject * @@ -1921,7 +1871,6 @@ _pg_typestr_as_format(PyObject *sp, char *format, Py_ssize_t *itemsize_p) return 0; } -#if IS_SDLv2 /*Default window(display)*/ static SDL_Window * pg_GetDefaultWindow(void) @@ -1966,7 +1915,6 @@ pg_EnvShouldBlendAlphaSDL2(void) { return pg_env_blend_alpha_SDL2; } -#endif /* IS_SDLv2 */ /*error signal handlers(replacing SDL parachute)*/ static void @@ -2205,16 +2153,12 @@ MODINIT_DEFINE(base) c_api[16] = pgBuffer_Release; c_api[17] = pgDict_AsBuffer; c_api[18] = pgExc_BufferError; -#if IS_SDLv1 -#define FILLED_SLOTS 19 -#else /* IS_SDLv2 */ c_api[19] = pg_GetDefaultWindow; c_api[20] = pg_SetDefaultWindow; c_api[21] = pg_GetDefaultWindowSurface; c_api[22] = pg_SetDefaultWindowSurface; c_api[23] = pg_EnvShouldBlendAlphaSDL2; #define FILLED_SLOTS 24 -#endif /* IS_SDLv2 */ #if PYGAMEAPI_BASE_NUMSLOTS != FILLED_SLOTS #error export slot count mismatch diff --git a/src_c/constants.c b/src_c/constants.c index 790b4d6a03..d69c464d45 100644 --- a/src_c/constants.c +++ b/src_c/constants.c @@ -27,7 +27,6 @@ #include "scrap.h" /* macros used to create each constant */ -#if IS_SDLv2 #define ADD_ERROR(x) \ { \ DECREF_MOD(module); \ @@ -56,30 +55,6 @@ #define DEC_CONSTN(x) DEC_CONSTS_(#x, x) #define DEC_CONSTSF(x) DEC_CONSTS_(#x, PGS_##x) -#else /* IS_SDLv1 */ -#define ADD_ERROR(x) \ - { \ - DECREF_MOD(module); \ - MODINIT_ERROR; \ - } \ - else \ - { \ - PyList_Append(all_list, Text_FromUTF8(x)); \ - } -#define DEC_CONST(x) \ - if (PyModule_AddIntConstant(module, #x, (int)SDL_##x)) \ - ADD_ERROR(#x) -#define DEC_CONSTK(x) \ - if (PyModule_AddIntConstant(module, #x, (int)SDL##x)) \ - ADD_ERROR(#x) -#define DEC_CONSTN(x) \ - if (PyModule_AddIntConstant(module, #x, (int)x)) \ - ADD_ERROR(#x) -#define DEC_CONSTS(x, y) \ - if (PyModule_AddIntConstant(module, #x, (int)y)) \ - ADD_ERROR(#x) - -#endif /* IS_SDLv1 */ #define ADD_STRING_CONST(x) \ if (PyModule_AddStringConstant(module, #x, x)) \ @@ -116,34 +91,6 @@ MODINIT_DEFINE(constants) DEC_CONST(LIL_ENDIAN); DEC_CONST(BIG_ENDIAN); -#if IS_SDLv1 - DEC_CONST(YV12_OVERLAY); - DEC_CONST(IYUV_OVERLAY); - DEC_CONST(YUY2_OVERLAY); - DEC_CONST(UYVY_OVERLAY); - DEC_CONST(YVYU_OVERLAY); - - DEC_CONST(SWSURFACE); - DEC_CONST(HWSURFACE); - DEC_CONST(RESIZABLE); - DEC_CONST(ASYNCBLIT); - DEC_CONST(OPENGL); - DEC_CONST(OPENGLBLIT); - DEC_CONST(ANYFORMAT); - DEC_CONST(HWPALETTE); - DEC_CONST(DOUBLEBUF); - DEC_CONST(FULLSCREEN); - DEC_CONST(HWACCEL); - DEC_CONST(SRCCOLORKEY); - DEC_CONST(RLEACCELOK); - DEC_CONST(RLEACCEL); - DEC_CONST(SRCALPHA); - DEC_CONST(PREALLOC); - DEC_CONST(NOFRAME); - - DEC_CONSTS(SHOWN, -1); - DEC_CONSTS(HIDDEN, -1); -#else /* IS_SDLv2 */ DEC_CONSTSF(SWSURFACE); DEC_CONSTSF(HWSURFACE); DEC_CONSTSF(RESIZABLE); @@ -163,14 +110,9 @@ MODINIT_DEFINE(constants) DEC_CONSTSF(NOFRAME); DEC_CONSTSF(SHOWN); DEC_CONSTSF(HIDDEN); -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - DEC_CONSTS(SCALED, 0); -#else DEC_CONSTSF(SCALED); -#endif /* IS_SDLv2 */ DEC_CONST(GL_RED_SIZE); @@ -185,7 +127,6 @@ MODINIT_DEFINE(constants) DEC_CONST(GL_ACCUM_GREEN_SIZE); DEC_CONST(GL_ACCUM_BLUE_SIZE); DEC_CONST(GL_ACCUM_ALPHA_SIZE); -#if IS_SDLv2 DEC_CONST(GL_ACCELERATED_VISUAL); DEC_CONST(GL_CONTEXT_MAJOR_VERSION); DEC_CONST(GL_CONTEXT_MINOR_VERSION); @@ -212,38 +153,11 @@ MODINIT_DEFINE(constants) DEC_CONST(GL_CONTEXT_RELEASE_BEHAVIOR_NONE); DEC_CONST(GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH); #endif -#else /* IS_SDLv1 */ - DEC_CONSTS(GL_CONTEXT_MAJOR_VERSION, -1); - DEC_CONSTS(GL_CONTEXT_MINOR_VERSION, -1); - DEC_CONSTS(GL_SHARE_WITH_CURRENT_CONTEXT, -1); - - DEC_CONSTS(GL_CONTEXT_DEBUG_FLAG, -1); - DEC_CONSTS(GL_CONTEXT_FLAGS, -1); - DEC_CONSTS(GL_CONTEXT_FORWARD_COMPATIBLE_FLAG, -1); - DEC_CONSTS(GL_CONTEXT_ROBUST_ACCESS_FLAG, -1); - DEC_CONSTS(GL_CONTEXT_RESET_ISOLATION_FLAG, -1); - - DEC_CONSTS(GL_CONTEXT_PROFILE_MASK, -1); - DEC_CONSTS(GL_CONTEXT_PROFILE_CORE, -1); - DEC_CONSTS(GL_CONTEXT_PROFILE_COMPATIBILITY, -1); - DEC_CONSTS(GL_CONTEXT_PROFILE_ES, -1); - DEC_CONSTS(GL_FRAMEBUFFER_SRGB_CAPABLE, -1); - DEC_CONSTS(GL_CONTEXT_RELEASE_BEHAVIOR, -1); - DEC_CONSTS(GL_CONTEXT_RELEASE_BEHAVIOR_NONE, -1); - DEC_CONSTS(GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH, -1); -#endif /* IS_SDLv2 */ -#if IS_SDLv2 DEC_CONST(BLENDMODE_NONE); DEC_CONST(BLENDMODE_BLEND); DEC_CONST(BLENDMODE_ADD); DEC_CONST(BLENDMODE_MOD); -#else /* IS_SDLv1 */ - DEC_CONSTS(BLENDMODE_NONE, -1); - DEC_CONSTS(BLENDMODE_BLEND, -1); - DEC_CONSTS(BLENDMODE_ADD, -1); - DEC_CONSTS(BLENDMODE_MOD, -1); -#endif /* IS_SDLv2 */ #if SDL_VERSION_ATLEAST(1, 2, 5) DEC_CONST(GL_STEREO); #else @@ -371,7 +285,6 @@ MODINIT_DEFINE(constants) DEC_CONST(BUTTON_MIDDLE); DEC_CONST(BUTTON_RIGHT); -#if IS_SDLv2 DEC_CONST(FINGERMOTION); DEC_CONST(FINGERDOWN); DEC_CONST(FINGERUP); @@ -469,414 +382,7 @@ MODINIT_DEFINE(constants) DEC_CONST(CONTROLLER_BUTTON_DPAD_RIGHT); DEC_CONST(CONTROLLER_BUTTON_MAX); -#else - DEC_CONSTS(AUDIODEVICEADDED, -1); - DEC_CONSTS(AUDIODEVICEREMOVED, -1); - DEC_CONSTS(FINGERMOTION, -1); - DEC_CONSTS(FINGERDOWN, -1); - DEC_CONSTS(FINGERUP, -1); - DEC_CONSTS(MULTIGESTURE, -1); - DEC_CONSTS(MOUSEWHEEL, -1); - DEC_CONSTS(TEXTINPUT, -1); - DEC_CONSTS(TEXTEDITING, -1); - - DEC_CONSTS(WINDOWSHOWN, -1); - DEC_CONSTS(WINDOWHIDDEN, -1); - DEC_CONSTS(WINDOWEXPOSED, -1); - DEC_CONSTS(WINDOWMOVED, -1); - DEC_CONSTS(WINDOWRESIZED, -1); - DEC_CONSTS(WINDOWSIZECHANGED, -1); - DEC_CONSTS(WINDOWMINIMIZED, -1); - DEC_CONSTS(WINDOWMAXIMIZED, -1); - DEC_CONSTS(WINDOWRESTORED, -1); - DEC_CONSTS(WINDOWENTER, -1); - DEC_CONSTS(WINDOWLEAVE, -1); - DEC_CONSTS(WINDOWFOCUSGAINED, -1); - DEC_CONSTS(WINDOWFOCUSLOST, -1); - DEC_CONSTS(WINDOWCLOSE, -1); - DEC_CONSTS(WINDOWTAKEFOCUS, -1); - DEC_CONSTS(WINDOWHITTEST, -1); - DEC_CONSTS(CONTROLLERAXISMOTION, -1); - DEC_CONSTS(CONTROLLERBUTTONDOWN, -1); - DEC_CONSTS(CONTROLLERBUTTONUP, -1); - DEC_CONSTS(CONTROLLERDEVICEADDED, -1); - DEC_CONSTS(CONTROLLERDEVICEREMOVED, -1); - DEC_CONSTS(CONTROLLERDEVICEREMAPPED, -1); - DEC_CONSTS(CONTROLLERTOUCHPADDOWN, -1); - DEC_CONSTS(CONTROLLERTOUCHPADMOTION, 1); - DEC_CONSTS(CONTROLLERTOUCHPADUP, -1); - - DEC_CONSTS(JOYDEVICEADDED, -1); - DEC_CONSTS(JOYDEVICEREMOVED, -1); - - DEC_CONST(BUTTON_WHEELUP); - DEC_CONST(BUTTON_WHEELDOWN); - DEC_CONSTS(AUDIO_ALLOW_FREQUENCY_CHANGE, -1); - DEC_CONSTS(AUDIO_ALLOW_FORMAT_CHANGE, -1); - DEC_CONSTS(AUDIO_ALLOW_CHANNELS_CHANGE, -1); - DEC_CONSTS(AUDIO_ALLOW_ANY_CHANGE, -1); - DEC_CONSTS(DROPFILE, -1); - DEC_CONSTS(DROPTEXT, -1); - DEC_CONSTS(DROPBEGIN, -1); - DEC_CONSTS(DROPCOMPLETE, -1); - DEC_CONSTS(CONTROLLER_AXIS_INVALID, -1); - DEC_CONSTS(CONTROLLER_AXIS_LEFTX, -1); - DEC_CONSTS(CONTROLLER_AXIS_LEFTY, -1); - DEC_CONSTS(CONTROLLER_AXIS_RIGHTX, -1); - DEC_CONSTS(CONTROLLER_AXIS_RIGHTY, -1); - DEC_CONSTS(CONTROLLER_AXIS_TRIGGERLEFT, -1); - DEC_CONSTS(CONTROLLER_AXIS_TRIGGERRIGHT, -1); - DEC_CONSTS(CONTROLLER_AXIS_MAX, -1); - DEC_CONSTS(CONTROLLER_BUTTON_INVALID, -1); - DEC_CONSTS(CONTROLLER_BUTTON_A, -1); - DEC_CONSTS(CONTROLLER_BUTTON_B, -1); - DEC_CONSTS(CONTROLLER_BUTTON_X, -1); - DEC_CONSTS(CONTROLLER_BUTTON_Y, -1); - DEC_CONSTS(CONTROLLER_BUTTON_BACK, -1); - DEC_CONSTS(CONTROLLER_BUTTON_GUIDE, -1); - DEC_CONSTS(CONTROLLER_BUTTON_START, -1); - DEC_CONSTS(CONTROLLER_BUTTON_LEFTSTICK, -1); - DEC_CONSTS(CONTROLLER_BUTTON_RIGHTSTICK, -1); - DEC_CONSTS(CONTROLLER_BUTTON_LEFTSHOULDER, -1); - DEC_CONSTS(CONTROLLER_BUTTON_RIGHTSHOULDER, -1); - DEC_CONSTS(CONTROLLER_BUTTON_DPAD_UP, -1); - DEC_CONSTS(CONTROLLER_BUTTON_DPAD_DOWN, -1); - DEC_CONSTS(CONTROLLER_BUTTON_DPAD_LEFT, -1); - DEC_CONSTS(CONTROLLER_BUTTON_DPAD_RIGHT, -1); - DEC_CONSTS(CONTROLLER_BUTTON_MAX, -1); -#if SDL_VERSION_ATLEAST(1, 2, 13) - DEC_CONST(BUTTON_X1); - DEC_CONST(BUTTON_X2); -#else - DEC_CONSTS(BUTTON_X1, -1); - DEC_CONSTS(BUTTON_X2, -1); -#endif -#endif - -#if IS_SDLv1 - DEC_CONSTK(K_UNKNOWN); - DEC_CONSTK(K_FIRST); - DEC_CONSTK(K_BACKSPACE); - DEC_CONSTK(K_TAB); - DEC_CONSTK(K_CLEAR); - DEC_CONSTK(K_RETURN); - DEC_CONSTK(K_PAUSE); - DEC_CONSTK(K_ESCAPE); - DEC_CONSTK(K_SPACE); - DEC_CONSTK(K_EXCLAIM); - DEC_CONSTK(K_QUOTEDBL); - DEC_CONSTK(K_HASH); - DEC_CONSTK(K_DOLLAR); - DEC_CONSTK(K_AMPERSAND); - DEC_CONSTK(K_QUOTE); - DEC_CONSTK(K_LEFTPAREN); - DEC_CONSTK(K_RIGHTPAREN); - DEC_CONSTK(K_ASTERISK); - DEC_CONSTK(K_PLUS); - DEC_CONSTK(K_COMMA); - DEC_CONSTK(K_MINUS); - DEC_CONSTK(K_PERIOD); - DEC_CONSTK(K_SLASH); - DEC_CONSTK(K_0); - DEC_CONSTK(K_1); - DEC_CONSTK(K_2); - DEC_CONSTK(K_3); - DEC_CONSTK(K_4); - DEC_CONSTK(K_5); - DEC_CONSTK(K_6); - DEC_CONSTK(K_7); - DEC_CONSTK(K_8); - DEC_CONSTK(K_9); - DEC_CONSTK(K_COLON); - DEC_CONSTK(K_SEMICOLON); - DEC_CONSTK(K_LESS); - DEC_CONSTK(K_EQUALS); - DEC_CONSTK(K_GREATER); - DEC_CONSTK(K_QUESTION); - DEC_CONSTK(K_AT); - DEC_CONSTK(K_LEFTBRACKET); - DEC_CONSTK(K_BACKSLASH); - DEC_CONSTK(K_RIGHTBRACKET); - DEC_CONSTK(K_CARET); - DEC_CONSTK(K_UNDERSCORE); - DEC_CONSTK(K_BACKQUOTE); - DEC_CONSTK(K_a); - DEC_CONSTK(K_b); - DEC_CONSTK(K_c); - DEC_CONSTK(K_d); - DEC_CONSTK(K_e); - DEC_CONSTK(K_f); - DEC_CONSTK(K_g); - DEC_CONSTK(K_h); - DEC_CONSTK(K_i); - DEC_CONSTK(K_j); - DEC_CONSTK(K_k); - DEC_CONSTK(K_l); - DEC_CONSTK(K_m); - DEC_CONSTK(K_n); - DEC_CONSTK(K_o); - DEC_CONSTK(K_p); - DEC_CONSTK(K_q); - DEC_CONSTK(K_r); - DEC_CONSTK(K_s); - DEC_CONSTK(K_t); - DEC_CONSTK(K_u); - DEC_CONSTK(K_v); - DEC_CONSTK(K_w); - DEC_CONSTK(K_x); - DEC_CONSTK(K_y); - DEC_CONSTK(K_z); - DEC_CONSTK(K_DELETE); - - DEC_CONSTK(K_KP0); - DEC_CONSTK(K_KP1); - DEC_CONSTK(K_KP2); - DEC_CONSTK(K_KP3); - DEC_CONSTK(K_KP4); - DEC_CONSTK(K_KP5); - DEC_CONSTK(K_KP6); - DEC_CONSTK(K_KP7); - DEC_CONSTK(K_KP8); - DEC_CONSTK(K_KP9); - DEC_CONSTK(K_KP_PERIOD); - DEC_CONSTK(K_KP_DIVIDE); - DEC_CONSTK(K_KP_MULTIPLY); - DEC_CONSTK(K_KP_MINUS); - DEC_CONSTK(K_KP_PLUS); - DEC_CONSTK(K_KP_ENTER); - DEC_CONSTK(K_KP_EQUALS); - DEC_CONSTK(K_UP); - DEC_CONSTK(K_DOWN); - DEC_CONSTK(K_RIGHT); - DEC_CONSTK(K_LEFT); - DEC_CONSTK(K_INSERT); - DEC_CONSTK(K_HOME); - DEC_CONSTK(K_END); - DEC_CONSTK(K_PAGEUP); - DEC_CONSTK(K_PAGEDOWN); - DEC_CONSTK(K_F1); - DEC_CONSTK(K_F2); - DEC_CONSTK(K_F3); - DEC_CONSTK(K_F4); - DEC_CONSTK(K_F5); - DEC_CONSTK(K_F6); - DEC_CONSTK(K_F7); - DEC_CONSTK(K_F8); - DEC_CONSTK(K_F9); - DEC_CONSTK(K_F10); - DEC_CONSTK(K_F11); - DEC_CONSTK(K_F12); - DEC_CONSTK(K_F13); - DEC_CONSTK(K_F14); - DEC_CONSTK(K_F15); - - DEC_CONSTK(K_NUMLOCK); - DEC_CONSTK(K_CAPSLOCK); - DEC_CONSTK(K_SCROLLOCK); - DEC_CONSTK(K_RSHIFT); - DEC_CONSTK(K_LSHIFT); - DEC_CONSTK(K_RCTRL); - DEC_CONSTK(K_LCTRL); - DEC_CONSTK(K_RALT); - DEC_CONSTK(K_LALT); - DEC_CONSTK(K_RMETA); - DEC_CONSTK(K_LMETA); - DEC_CONSTK(K_LSUPER); - DEC_CONSTK(K_RSUPER); - DEC_CONSTK(K_MODE); - - DEC_CONSTK(K_HELP); - DEC_CONSTK(K_PRINT); - DEC_CONSTK(K_SYSREQ); - DEC_CONSTK(K_BREAK); - DEC_CONSTK(K_MENU); - DEC_CONSTK(K_POWER); - DEC_CONSTK(K_EURO); - DEC_CONSTK(K_LAST); - - // Key codes not supported in SDL1 - DEC_CONSTS(K_CURRENCYSUBUNIT, -1); - DEC_CONSTS(K_CURRENCYUNIT, -1); - - DEC_CONSTS(K_KP_0, -1); - DEC_CONSTS(K_KP_1, -1); - DEC_CONSTS(K_KP_2, -1); - DEC_CONSTS(K_KP_3, -1); - DEC_CONSTS(K_KP_4, -1); - DEC_CONSTS(K_KP_5, -1); - DEC_CONSTS(K_KP_6, -1); - DEC_CONSTS(K_KP_7, -1); - DEC_CONSTS(K_KP_8, -1); - DEC_CONSTS(K_KP_9, -1); - - DEC_CONSTS(K_LGUI, -1); - DEC_CONSTS(K_RGUI, -1); - - DEC_CONSTS(K_NUMLOCKCLEAR, -1); - DEC_CONSTS(K_PERCENT, -1); - DEC_CONSTS(K_PRINTSCREEN, -1); - DEC_CONSTS(K_SCROLLLOCK, -1); - DEC_CONSTS(K_AC_BACK, -1); - - // scan code key codes (also not supported in SDL1) - DEC_CONSTS(KSCAN_0, -1); - DEC_CONSTS(KSCAN_1, -1); - DEC_CONSTS(KSCAN_2, -1); - DEC_CONSTS(KSCAN_3, -1); - DEC_CONSTS(KSCAN_4, -1); - DEC_CONSTS(KSCAN_5, -1); - DEC_CONSTS(KSCAN_6, -1); - DEC_CONSTS(KSCAN_7, -1); - DEC_CONSTS(KSCAN_8, -1); - DEC_CONSTS(KSCAN_9, -1); - DEC_CONSTS(KSCAN_A, -1); - DEC_CONSTS(KSCAN_APOSTROPHE, -1); - DEC_CONSTS(KSCAN_B, -1); - DEC_CONSTS(KSCAN_BACKSLASH, -1); - DEC_CONSTS(KSCAN_BACKSPACE, -1); - DEC_CONSTS(KSCAN_BREAK, -1); - DEC_CONSTS(KSCAN_C, -1); - DEC_CONSTS(KSCAN_CAPSLOCK, -1); - DEC_CONSTS(KSCAN_CLEAR, -1); - DEC_CONSTS(KSCAN_COMMA, -1); - DEC_CONSTS(KSCAN_CURRENCYSUBUNIT, -1); - DEC_CONSTS(KSCAN_CURRENCYUNIT, -1); - DEC_CONSTS(KSCAN_D, -1); - DEC_CONSTS(KSCAN_DELETE, -1); - DEC_CONSTS(KSCAN_DOWN, -1); - DEC_CONSTS(KSCAN_E, -1); - DEC_CONSTS(KSCAN_END, -1); - DEC_CONSTS(KSCAN_EQUALS, -1); - DEC_CONSTS(KSCAN_ESCAPE, -1); - DEC_CONSTS(KSCAN_EURO, -1); - DEC_CONSTS(KSCAN_F, -1); - DEC_CONSTS(KSCAN_F1, -1); - DEC_CONSTS(KSCAN_F10, -1); - DEC_CONSTS(KSCAN_F11, -1); - DEC_CONSTS(KSCAN_F12, -1); - DEC_CONSTS(KSCAN_F13, -1); - DEC_CONSTS(KSCAN_F14, -1); - DEC_CONSTS(KSCAN_F15, -1); - DEC_CONSTS(KSCAN_F2, -1); - DEC_CONSTS(KSCAN_F3, -1); - DEC_CONSTS(KSCAN_F4, -1); - DEC_CONSTS(KSCAN_F5, -1); - DEC_CONSTS(KSCAN_F6, -1); - DEC_CONSTS(KSCAN_F7, -1); - DEC_CONSTS(KSCAN_F8, -1); - DEC_CONSTS(KSCAN_F9, -1); - DEC_CONSTS(KSCAN_G, -1); - DEC_CONSTS(KSCAN_GRAVE, -1); - DEC_CONSTS(KSCAN_H, -1); - DEC_CONSTS(KSCAN_HELP, -1); - DEC_CONSTS(KSCAN_HOME, -1); - DEC_CONSTS(KSCAN_I, -1); - DEC_CONSTS(KSCAN_INSERT, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL1, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL2, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL3, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL4, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL5, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL6, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL7, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL8, -1); - DEC_CONSTS(KSCAN_INTERNATIONAL9, -1); - DEC_CONSTS(KSCAN_J, -1); - DEC_CONSTS(KSCAN_K, -1); - DEC_CONSTS(KSCAN_KP0, -1); - DEC_CONSTS(KSCAN_KP1, -1); - DEC_CONSTS(KSCAN_KP2, -1); - DEC_CONSTS(KSCAN_KP3, -1); - DEC_CONSTS(KSCAN_KP4, -1); - DEC_CONSTS(KSCAN_KP5, -1); - DEC_CONSTS(KSCAN_KP6, -1); - DEC_CONSTS(KSCAN_KP7, -1); - DEC_CONSTS(KSCAN_KP8, -1); - DEC_CONSTS(KSCAN_KP9, -1); - DEC_CONSTS(KSCAN_KP_0, -1); - DEC_CONSTS(KSCAN_KP_1, -1); - DEC_CONSTS(KSCAN_KP_2, -1); - DEC_CONSTS(KSCAN_KP_3, -1); - DEC_CONSTS(KSCAN_KP_4, -1); - DEC_CONSTS(KSCAN_KP_5, -1); - DEC_CONSTS(KSCAN_KP_6, -1); - DEC_CONSTS(KSCAN_KP_7, -1); - DEC_CONSTS(KSCAN_KP_8, -1); - DEC_CONSTS(KSCAN_KP_9, -1); - DEC_CONSTS(KSCAN_KP_DIVIDE, -1); - DEC_CONSTS(KSCAN_KP_ENTER, -1); - DEC_CONSTS(KSCAN_KP_EQUALS, -1); - DEC_CONSTS(KSCAN_KP_MINUS, -1); - DEC_CONSTS(KSCAN_KP_MULTIPLY, -1); - DEC_CONSTS(KSCAN_KP_PERIOD, -1); - DEC_CONSTS(KSCAN_KP_PLUS, -1); - DEC_CONSTS(KSCAN_L, -1); - DEC_CONSTS(KSCAN_LALT, -1); - DEC_CONSTS(KSCAN_LANG1, -1); - DEC_CONSTS(KSCAN_LANG2, -1); - DEC_CONSTS(KSCAN_LANG3, -1); - DEC_CONSTS(KSCAN_LANG4, -1); - DEC_CONSTS(KSCAN_LANG5, -1); - DEC_CONSTS(KSCAN_LANG6, -1); - DEC_CONSTS(KSCAN_LANG7, -1); - DEC_CONSTS(KSCAN_LANG8, -1); - DEC_CONSTS(KSCAN_LANG9, -1); - DEC_CONSTS(KSCAN_LCTRL, -1); - DEC_CONSTS(KSCAN_LEFT, -1); - DEC_CONSTS(KSCAN_LEFTBRACKET, -1); - DEC_CONSTS(KSCAN_LGUI, -1); - DEC_CONSTS(KSCAN_LMETA, -1); - DEC_CONSTS(KSCAN_LSHIFT, -1); - DEC_CONSTS(KSCAN_LSUPER, -1); - DEC_CONSTS(KSCAN_M, -1); - DEC_CONSTS(KSCAN_MENU, -1); - DEC_CONSTS(KSCAN_MINUS, -1); - DEC_CONSTS(KSCAN_MODE, -1); - DEC_CONSTS(KSCAN_N, -1); - DEC_CONSTS(KSCAN_NONUSBACKSLASH, -1); - DEC_CONSTS(KSCAN_NONUSHASH, -1); - DEC_CONSTS(KSCAN_NUMLOCK, -1); - DEC_CONSTS(KSCAN_NUMLOCKCLEAR, -1); - DEC_CONSTS(KSCAN_O, -1); - DEC_CONSTS(KSCAN_P, -1); - DEC_CONSTS(KSCAN_PAGEDOWN, -1); - DEC_CONSTS(KSCAN_PAGEUP, -1); - DEC_CONSTS(KSCAN_PAUSE, -1); - DEC_CONSTS(KSCAN_PERIOD, -1); - DEC_CONSTS(KSCAN_POWER, -1); - DEC_CONSTS(KSCAN_PRINT, -1); - DEC_CONSTS(KSCAN_PRINTSCREEN, -1); - DEC_CONSTS(KSCAN_Q, -1); - DEC_CONSTS(KSCAN_R, -1); - DEC_CONSTS(KSCAN_RALT, -1); - DEC_CONSTS(KSCAN_RCTRL, -1); - DEC_CONSTS(KSCAN_RETURN, -1); - DEC_CONSTS(KSCAN_RGUI, -1); - DEC_CONSTS(KSCAN_RIGHT, -1); - DEC_CONSTS(KSCAN_RIGHTBRACKET, -1); - DEC_CONSTS(KSCAN_RMETA, -1); - DEC_CONSTS(KSCAN_RSHIFT, -1); - DEC_CONSTS(KSCAN_RSUPER, -1); - DEC_CONSTS(KSCAN_S, -1); - DEC_CONSTS(KSCAN_SCROLLLOCK, -1); - DEC_CONSTS(KSCAN_SCROLLOCK, -1); - DEC_CONSTS(KSCAN_SEMICOLON, -1); - DEC_CONSTS(KSCAN_SLASH, -1); - DEC_CONSTS(KSCAN_SPACE, -1); - DEC_CONSTS(KSCAN_SYSREQ, -1); - DEC_CONSTS(KSCAN_T, -1); - DEC_CONSTS(KSCAN_TAB, -1); - DEC_CONSTS(KSCAN_U, -1); - DEC_CONSTS(KSCAN_UNKNOWN, -1); - DEC_CONSTS(KSCAN_UP, -1); - DEC_CONSTS(KSCAN_V, -1); - DEC_CONSTS(KSCAN_W, -1); - DEC_CONSTS(KSCAN_X, -1); - DEC_CONSTS(KSCAN_Y, -1); - DEC_CONSTS(KSCAN_Z, -1); - -#else /* IS_SDLv2 */ /* Keyboard key codes: Pygame K_ constants. Scan codes: KSCAN_ constants. */ DEC_CONSTK_AND_SC(AC_BACK); @@ -1057,7 +563,6 @@ MODINIT_DEFINE(constants) DEC_CONSTK(AT); DEC_CONSTK(CARET); DEC_CONSTK(UNDERSCORE); -#endif /* IS_SDLv2 */ /* Keyboard key modifiers: Pygame KMOD_ constants. */ @@ -1068,17 +573,10 @@ MODINIT_DEFINE(constants) DEC_CONSTN(KMOD_RCTRL); DEC_CONSTN(KMOD_LALT); DEC_CONSTN(KMOD_RALT); -#if IS_SDLv1 - DEC_CONSTN(KMOD_LMETA); - DEC_CONSTN(KMOD_RMETA); - DEC_CONSTS(KMOD_LGUI, -1); - DEC_CONSTS(KMOD_RGUI, -1); -#else /* IS_SDLv2 */ DEC_CONSTN(KMOD_LGUI); DEC_CONSTS(KMOD_LMETA, KMOD_LGUI); DEC_CONSTN(KMOD_RGUI); DEC_CONSTS(KMOD_RMETA, KMOD_RGUI); -#endif /* IS_SDLv2 */ DEC_CONSTN(KMOD_NUM); DEC_CONSTN(KMOD_CAPS); DEC_CONSTN(KMOD_MODE); @@ -1086,23 +584,14 @@ MODINIT_DEFINE(constants) DEC_CONSTN(KMOD_CTRL); DEC_CONSTN(KMOD_SHIFT); DEC_CONSTN(KMOD_ALT); -#if IS_SDLv1 - DEC_CONSTN(KMOD_META); - DEC_CONSTS(KMOD_GUI, -1); - DEC_CONSTS(APPFOCUSMOUSE, -1); - DEC_CONSTS(APPINPUTFOCUS, -1); - DEC_CONSTS(APPACTIVE, -1); -#else /* IS_SDLv2 */ DEC_CONSTN(KMOD_GUI); DEC_CONSTS(KMOD_META, KMOD_GUI); DEC_CONST(APPFOCUSMOUSE); DEC_CONST(APPINPUTFOCUS); DEC_CONST(APPACTIVE); -#endif /* IS_SDLv2 */ /* cursor constants */ -#if IS_SDLv2 DEC_CONST(SYSTEM_CURSOR_ARROW); DEC_CONST(SYSTEM_CURSOR_IBEAM); DEC_CONST(SYSTEM_CURSOR_WAIT); @@ -1115,20 +604,6 @@ MODINIT_DEFINE(constants) DEC_CONST(SYSTEM_CURSOR_SIZEALL); DEC_CONST(SYSTEM_CURSOR_NO); DEC_CONST(SYSTEM_CURSOR_HAND); -#else - DEC_CONSTS(SYSTEM_CURSOR_ARROW, -1); - DEC_CONSTS(SYSTEM_CURSOR_IBEAM, -1); - DEC_CONSTS(SYSTEM_CURSOR_WAIT, -1); - DEC_CONSTS(SYSTEM_CURSOR_CROSSHAIR, -1); - DEC_CONSTS(SYSTEM_CURSOR_WAITARROW, -1); - DEC_CONSTS(SYSTEM_CURSOR_SIZENWSE, -1); - DEC_CONSTS(SYSTEM_CURSOR_SIZENESW, -1); - DEC_CONSTS(SYSTEM_CURSOR_SIZEWE, -1); - DEC_CONSTS(SYSTEM_CURSOR_SIZENS, -1); - DEC_CONSTS(SYSTEM_CURSOR_SIZEALL, -1); - DEC_CONSTS(SYSTEM_CURSOR_NO, -1); - DEC_CONSTS(SYSTEM_CURSOR_HAND, -1); -#endif #define PYGAME_USEREVENT_DROPFILE 0x1000 DEC_CONSTS(USEREVENT_DROPFILE, PYGAME_USEREVENT_DROPFILE); diff --git a/src_c/display.c b/src_c/display.c index 44bcb9730a..e3d84ba3b4 100644 --- a/src_c/display.c +++ b/src_c/display.c @@ -35,18 +35,6 @@ static PyTypeObject pgVidInfo_Type; -#if IS_SDLv1 - -static PyObject * -pgVidInfo_New(const SDL_VideoInfo *info); - -static void -pg_do_set_icon(PyObject *surface); -static pgSurfaceObject *pgDisplaySurfaceObject = NULL; -static int icon_was_set = 0; -static int _allow_screensaver = 0; - -#else /* IS_SDLv2 */ static PyObject * pgVidInfo_New(const pg_VideoInfo *info); @@ -105,7 +93,6 @@ _display_state_cleanup(_DisplayState *state) } } -#endif /* IS_SDLv2 */ static char *icon_defaultname = "pygame_icon.bmp"; static char *pkgdatamodule_name = "pygame.pkgdata"; @@ -187,7 +174,6 @@ pg_display_resource(char *filename) static PyObject * pg_display_quit(PyObject *self) { -#if IS_SDLv2 _DisplayState *state = DISPLAY_STATE; _display_state_cleanup(state); if (pg_GetDefaultWindowSurface()) { @@ -195,14 +181,6 @@ pg_display_quit(PyObject *self) pg_SetDefaultWindowSurface(NULL); pg_SetDefaultWindow(NULL); } -#else /* IS_SDLv1 */ - if (pgDisplaySurfaceObject) { - pgSurface_AsSurface(pgDisplaySurfaceObject) = NULL; - Py_DECREF((PyObject *)pgDisplaySurfaceObject); - pgDisplaySurfaceObject = NULL; - icon_was_set = 0; - } -#endif /* IS_SDLv1 */ pg_mod_autoquit(IMPPREFIX "event"); pg_mod_autoquit(IMPPREFIX "time"); @@ -241,7 +219,6 @@ static PyObject * pg_display_init(PyObject *self) { -#if IS_SDLv2 const char *drivername; /* Compatibility: * windib video driver was renamed in SDL2, and we don't want it to fail. @@ -250,7 +227,6 @@ pg_display_init(PyObject *self) if (drivername && !SDL_strncasecmp("windib", drivername, SDL_strlen(drivername))) { SDL_setenv("SDL_VIDEODRIVER", "windows", 1); } -#endif if (!SDL_WasInit(SDL_INIT_VIDEO)) { if (!_pg_mac_display_init()) return NULL; @@ -258,9 +234,6 @@ pg_display_init(PyObject *self) if (SDL_InitSubSystem(SDL_INIT_VIDEO)) return RAISE(pgExc_SDLError, SDL_GetError()); -#if IS_SDLv1 - SDL_EnableUNICODE(1); -#endif /* IS_SDLv1 */ } if (!pg_mod_autoinit(IMPPREFIX "time")) @@ -277,7 +250,6 @@ pg_get_init(PyObject *self) return PyBool_FromLong(SDL_WasInit(SDL_INIT_VIDEO) != 0); } -#if IS_SDLv2 static PyObject * pg_get_active(PyObject *self) { @@ -285,15 +257,6 @@ pg_get_active(PyObject *self) return PyBool_FromLong((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)); } -#else /* IS_SDLv1 */ -static PyObject * -pg_get_active(PyObject *self) -{ - if (!pgDisplaySurfaceObject) - Py_RETURN_FALSE; - return PyBool_FromLong((SDL_GetAppState() & SDL_APPACTIVE) != 0); -} -#endif /* IS_SDLv1 */ /* vidinfo object */ static void @@ -305,11 +268,7 @@ pg_vidinfo_dealloc(PyObject *self) static PyObject * pg_vidinfo_getattr(PyObject *self, char *name) { -#if IS_SDLv1 - SDL_VideoInfo *info = &((pgVidInfoObject *)self)->info; -#else pg_VideoInfo *info = &((pgVidInfoObject *)self)->info; -#endif int current_w = -1; int current_h = -1; @@ -370,11 +329,7 @@ pg_vidinfo_str(PyObject *self) char str[1024]; int current_w = -1; int current_h = -1; -#if IS_SDLv1 - SDL_VideoInfo *info = &((pgVidInfoObject *)self)->info; -#else pg_VideoInfo *info = &((pgVidInfoObject *)self)->info; -#endif SDL_version versioninfo; SDL_VERSION(&versioninfo); @@ -425,13 +380,8 @@ static PyTypeObject pgVidInfo_Type = { (reprfunc)NULL, /*str*/ }; -#if IS_SDLv1 -static PyObject * -pgVidInfo_New(const SDL_VideoInfo *i) -#else static PyObject * pgVidInfo_New(const pg_VideoInfo *i) -#endif { pgVidInfoObject *info; if (!i) @@ -439,16 +389,11 @@ pgVidInfo_New(const pg_VideoInfo *i) info = PyObject_NEW(pgVidInfoObject, &pgVidInfo_Type); if (!info) return NULL; -#if IS_SDLv1 - memcpy(&info->info, i, sizeof(SDL_VideoInfo)); -#else info->info = *i; info->info.vfmt = &info->info.vfmt_data; -#endif return (PyObject *)info; } -#if IS_SDLv2 static pg_VideoInfo * pg_GetVideoInfo(pg_VideoInfo *info) { @@ -497,21 +442,13 @@ pg_GetVideoInfo(pg_VideoInfo *info) return info; } -#endif /* IS_SDLv2 */ static PyObject * pgInfo(PyObject *self) { -#if IS_SDLv1 - const SDL_VideoInfo *info; - VIDEO_INIT_CHECK(); - info = SDL_GetVideoInfo(); - return pgVidInfo_New(info); -#else /* IS_SDLv2 */ pg_VideoInfo info; VIDEO_INIT_CHECK(); return pgVidInfo_New(pg_GetVideoInfo(&info)); -#endif /* IS_SDLv2 */ } static PyObject * @@ -520,9 +457,7 @@ pg_get_wm_info(PyObject *self) PyObject *dict; PyObject *tmp; SDL_SysWMinfo info; -#if IS_SDLv2 SDL_Window *win; -#endif VIDEO_INIT_CHECK(); @@ -531,73 +466,6 @@ pg_get_wm_info(PyObject *self) if (!dict) return NULL; -#if IS_SDLv1 - if (!SDL_GetWMInfo(&info)) - return dict; - -/*scary #ifdef's match SDL_syswm.h*/ -#if (defined(unix) || defined(__unix__) || defined(_AIX) || \ - defined(__OpenBSD__)) && \ - (defined(SDL_VIDEO_DRIVER_X11) && !defined(__CYGWIN32__) && \ - !defined(ENABLE_NANOX) && !defined(__QNXNTO__)) - - tmp = PyInt_FromLong(info.info.x11.window); - PyDict_SetItemString(dict, "window", tmp); - Py_DECREF(tmp); - - tmp = PyCapsule_New(info.info.x11.display, "display", NULL); - PyDict_SetItemString(dict, "display", tmp); - Py_DECREF(tmp); - - tmp = PyCapsule_New(info.info.x11.lock_func, "lock_func", NULL); - PyDict_SetItemString(dict, "lock_func", tmp); - Py_DECREF(tmp); - - tmp = PyCapsule_New(info.info.x11.unlock_func, "unlock_func", NULL); - PyDict_SetItemString(dict, "unlock_func", tmp); - Py_DECREF(tmp); - - tmp = PyInt_FromLong(info.info.x11.fswindow); - PyDict_SetItemString(dict, "fswindow", tmp); - Py_DECREF(tmp); - - tmp = PyInt_FromLong(info.info.x11.wmwindow); - PyDict_SetItemString(dict, "wmwindow", tmp); - Py_DECREF(tmp); - -#elif defined(ENABLE_NANOX) - tmp = PyInt_FromLong(info.window); - PyDict_SetItemString(dict, "window", tmp); - Py_DECREF(tmp); -#elif defined(WIN32) - tmp = PyInt_FromLong((long)info.window); - PyDict_SetItemString(dict, "window", tmp); - Py_DECREF(tmp); - - tmp = PyInt_FromLong((long)info.hglrc); - PyDict_SetItemString(dict, "hglrc", tmp); - Py_DECREF(tmp); -#elif defined(__riscos__) - tmp = PyInt_FromLong(info.window); - PyDict_SetItemString(dict, "window", tmp); - Py_DECREF(tmp); - - tmp = PyInt_FromLong(info.wimpVersion); - PyDict_SetItemString(dict, "wimpVersion", tmp); - Py_DECREF(tmp); - - tmp = PyInt_FromLong(info.taskHandle); - PyDict_SetItemString(dict, "taskHandle", tmp); - Py_DECREF(tmp); -#elif (defined(__APPLE__) && defined(__MACH__)) - /* do nothing. */ -#else - tmp = PyInt_FromLong(info.data); - PyDict_SetItemString(dict, "data", tmp); - Py_DECREF(tmp); -#endif - -#else /* IS_SDLv2 */ win = pg_GetDefaultWindow(); if (!win) @@ -709,13 +577,11 @@ pg_get_wm_info(PyObject *self) Py_DECREF(tmp); #endif -#endif /* IS_SDLv2 */ return dict; } /* display functions */ -#if IS_SDLv2 static PyObject * pg_get_driver(PyObject *self) { @@ -759,26 +625,6 @@ pg_get_surface(PyObject *self) } return NULL; } -#else /* IS_SDLv1 */ -static PyObject * -pg_get_driver(PyObject *self) -{ - char buf[256]; - VIDEO_INIT_CHECK(); - if (!SDL_VideoDriverName(buf, sizeof(buf))) - Py_RETURN_NONE; - return Text_FromUTF8(buf); -} - -static PyObject * -pg_get_surface(PyObject *self) -{ - if (!pgDisplaySurfaceObject) - Py_RETURN_NONE; - Py_INCREF((PyObject *)pgDisplaySurfaceObject); - return (PyObject *)pgDisplaySurfaceObject; -} -#endif /* IS_SDLv1 */ static PyObject * pg_gl_set_attribute(PyObject *self, PyObject *arg) @@ -808,7 +654,6 @@ pg_gl_get_attribute(PyObject *self, PyObject *arg) return PyInt_FromLong(value); } -#if IS_SDLv2 /* ** Looks at the SDL1 environment variables: @@ -1736,218 +1581,6 @@ pg_num_displays(PyObject *self) return PyInt_FromLong(ret); } -#else /* IS_SDLv1 */ -static PyObject * -pg_set_mode(PyObject *self, PyObject *arg, PyObject *kwds) -{ - SDL_Surface *surf; - int depth = 0; - int flags = SDL_SWSURFACE; - int w, h; - PyObject *size = NULL; - int display = 0; - int hasbuf; - char *title, *icontitle; - - char *keywords[] = {"size", "flags", "depth", "display", NULL}; - - if (!PyArg_ParseTupleAndKeywords(arg, kwds, "|Oiii", keywords, &size, - &flags, &depth, &display)) - return NULL; - - if (size != NULL) { - if (!pg_TwoIntsFromObj(size, &w, &h)) - return RAISE(PyExc_TypeError, "size must be two numbers"); - if (w < 0 || h < 0) - return RAISE(pgExc_SDLError, "Cannot set negative sized display mode"); - } - else { - w = 0; - h = 0; - } - - if (w == 0 || h == 0) { - SDL_version versioninfo; - SDL_VERSION(&versioninfo); - if (!(versioninfo.major > 1 || - (versioninfo.major == 1 && versioninfo.minor > 2) || - (versioninfo.major == 1 && versioninfo.minor == 2 && - versioninfo.patch >= 10))) { - return RAISE(pgExc_SDLError, "Cannot set 0 sized display mode"); - } - } - - if (!SDL_WasInit(SDL_INIT_VIDEO)) { - /*note SDL works special like this too*/ - if (!pg_display_init(NULL)) - return NULL; - } - - if (flags & SDL_OPENGL) { - if (flags & SDL_DOUBLEBUF) { - flags &= ~SDL_DOUBLEBUF; - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - } - else - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); - if (depth) - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depth); - surf = SDL_SetVideoMode(w, h, depth, flags); - if (!surf) - return RAISE(pgExc_SDLError, SDL_GetError()); - - SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &hasbuf); - if (hasbuf) - surf->flags |= SDL_DOUBLEBUF; - } - else { - if (!depth) - flags |= SDL_ANYFORMAT; - Py_BEGIN_ALLOW_THREADS; - surf = SDL_SetVideoMode(w, h, depth, flags); - Py_END_ALLOW_THREADS; - if (!surf) - return RAISE(pgExc_SDLError, SDL_GetError()); - } - SDL_WM_GetCaption(&title, &icontitle); - if (!title || !*title) - SDL_WM_SetCaption("pygame window", "pygame"); - - /*probably won't do much, but can't hurt, and might help*/ - SDL_PumpEvents(); - - if (pgDisplaySurfaceObject) - pgDisplaySurfaceObject->surf = surf; - else - pgDisplaySurfaceObject = pgSurface_New(surf); - -#if !defined(darwin) - if (!icon_was_set) { - PyObject *iconsurf = pg_display_resource(icon_defaultname); - if (!iconsurf) - PyErr_Clear(); - else { - SDL_SetColorKey(pgSurface_AsSurface(iconsurf), SDL_SRCCOLORKEY, 0); - pg_do_set_icon(iconsurf); - Py_DECREF(iconsurf); - } - } -#endif - Py_INCREF((PyObject *)pgDisplaySurfaceObject); - return (PyObject *)pgDisplaySurfaceObject; -} - -static PyObject * -pg_window_size(PyObject *self) -{ - if (!pgDisplaySurfaceObject) { - return RAISE(pgExc_SDLError, "No open window"); - } - return Py_BuildValue("(ii)", - pgSurface_AsSurface(pgDisplaySurfaceObject)->w, - pgSurface_AsSurface(pgDisplaySurfaceObject)->h); -} - -/* SDL1 mode_ok. Note, there is a separate SDL2 version of this. */ -static PyObject * -pg_mode_ok(PyObject *self, PyObject *args, PyObject *kwds) -{ - int depth = 0; - int w, h; - int flags = SDL_SWSURFACE; - int display = 0; - char *keywords[] = {"size", "flags", "depth", "display", NULL}; - - VIDEO_INIT_CHECK(); - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "(ii)|iii", keywords, &w, &h, - &flags, &depth, &display)) - return NULL; - if (!depth) - depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; - - return PyInt_FromLong(SDL_VideoModeOK(w, h, depth, flags)); -} - -static PyObject * -pg_list_modes(PyObject *self, PyObject *args, PyObject *kwds) -{ - SDL_PixelFormat format; - SDL_Rect **rects; - int flags = SDL_FULLSCREEN; - int display_index = 0; /* SDL1 does not use a display_index. */ - PyObject *list, *size; - char *keywords[] = {"depth", "flags", "display", NULL}; - - format.BitsPerPixel = 0; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|bii", keywords, - &format.BitsPerPixel, &flags, - &display_index)) { - return NULL; - } - - VIDEO_INIT_CHECK(); - - if (!format.BitsPerPixel) - format.BitsPerPixel = SDL_GetVideoInfo()->vfmt->BitsPerPixel; - - rects = SDL_ListModes(&format, flags); - - if (rects == (SDL_Rect **)-1) - return PyInt_FromLong(-1); - - if (!(list = PyList_New(0))) - return NULL; - if (!rects) - return list; - - for (; *rects; ++rects) { - if (!(size = Py_BuildValue("(ii)", (*rects)->w, (*rects)->h))) { - Py_DECREF(list); - return NULL; - } - if (0 != PyList_Append(list, size)) { - Py_DECREF(list); - Py_DECREF(size); - return NULL; /* Exception already set. */ - } - Py_DECREF(size); - } - return list; -} - -static PyObject * -pg_flip(PyObject *self) -{ - SDL_Surface *screen; - int status = 0; - - VIDEO_INIT_CHECK(); - - screen = SDL_GetVideoSurface(); - if (!screen) - return RAISE(pgExc_SDLError, "Display mode not set"); - - Py_BEGIN_ALLOW_THREADS; - if (screen->flags & SDL_OPENGL) - SDL_GL_SwapBuffers(); - else - status = SDL_Flip(screen); - Py_END_ALLOW_THREADS; - - if (status < 0) - return RAISE(pgExc_SDLError, SDL_GetError()); - Py_RETURN_NONE; -} - -static PyObject * -pg_num_displays(PyObject *self) -{ - return PyInt_FromLong(1); -} - -#endif /* IS_SDLv1 */ /*BAD things happen when out-of-bound rects go to updaterect*/ static SDL_Rect * @@ -1969,19 +1602,14 @@ pg_screencroprect(GAME_Rect *r, int w, int h, SDL_Rect *cur) static PyObject * pg_update(PyObject *self, PyObject *arg) { -#if IS_SDLv2 SDL_Window *win = pg_GetDefaultWindow(); _DisplayState *state = DISPLAY_MOD_STATE(self); -#else /* IS_SDLv1 */ - SDL_Surface *screen; -#endif /* IS_SDLv1 */ GAME_Rect *gr, temp = {0}; int wide, high; PyObject *obj; VIDEO_INIT_CHECK(); -#if IS_SDLv2 if (!win) return RAISE(pgExc_SDLError, "Display mode not set"); if (pg_renderer != NULL) { @@ -1991,25 +1619,10 @@ pg_update(PyObject *self, PyObject *arg) if (state->using_gl) return RAISE(pgExc_SDLError, "Cannot update an OPENGL display"); -#else /* IS_SDLv1 */ - screen = SDL_GetVideoSurface(); - if (!screen) - return RAISE(pgExc_SDLError, SDL_GetError()); - wide = screen->w; - high = screen->h; - if (screen->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot update an OPENGL display"); -#endif /* IS_SDLv1 */ /*determine type of argument we got*/ if (PyTuple_Size(arg) == 0) { -#if IS_SDLv2 return pg_flip(self); -#else /* IS_SDLv1 */ - SDL_UpdateRect(screen, 0, 0, 0, 0); - - Py_RETURN_NONE; -#endif /* IS_SDLv1 */ } else { obj = PyTuple_GET_ITEM(arg, 0); @@ -2027,17 +1640,10 @@ pg_update(PyObject *self, PyObject *arg) } if (gr) { -#if IS_SDLv2 SDL_Rect sdlr; if (pg_screencroprect(gr, wide, high, &sdlr)) SDL_UpdateWindowSurfaceRects(win, &sdlr, 1); -#else /* IS_SDLv1 */ - SDL_Rect sdlr; - - if (pg_screencroprect(gr, wide, high, &sdlr)) - SDL_UpdateRect(screen, sdlr.x, sdlr.y, sdlr.w, sdlr.h); -#endif /* IS_SDLv1 */ } else { PyObject *seq; @@ -2088,15 +1694,9 @@ pg_update(PyObject *self, PyObject *arg) } if (count) { -#if IS_SDLv1 - Py_BEGIN_ALLOW_THREADS; - SDL_UpdateRects(screen, count, rects); - Py_END_ALLOW_THREADS; -#else /* IS_SDLv2 */ Py_BEGIN_ALLOW_THREADS; SDL_UpdateWindowSurfaceRects(win, rects, count); Py_END_ALLOW_THREADS; -#endif /* IS_SDLv2 */ } PyMem_Free((char *)rects); @@ -2104,7 +1704,6 @@ pg_update(PyObject *self, PyObject *arg) Py_RETURN_NONE; } -#if IS_SDLv2 static PyObject * pg_set_palette(PyObject *self, PyObject *args) { @@ -2232,87 +1831,6 @@ pg_set_gamma(PyObject *self, PyObject *arg) return PyBool_FromLong(result == 0); } -#else /* IS_SDLv1 */ -static PyObject * -pg_set_palette(PyObject *self, PyObject *args) -{ - SDL_Surface *surf; - SDL_Palette *pal; - SDL_Color *colors; - PyObject *list, *item = NULL; - int i, len; - int r, g, b; - - VIDEO_INIT_CHECK(); - if (!PyArg_ParseTuple(args, "|O", &list)) - return NULL; - surf = SDL_GetVideoSurface(); - if (!surf) - return RAISE(pgExc_SDLError, "No display mode is set"); - pal = surf->format->palette; - if (surf->format->BytesPerPixel != 1 || !pal) - return RAISE(pgExc_SDLError, "Display mode is not colormapped"); - - if (!list) { - colors = pal->colors; - len = pal->ncolors; - SDL_SetPalette(surf, SDL_PHYSPAL, colors, 0, len); - Py_RETURN_NONE; - } - - if (!PySequence_Check(list)) - return RAISE(PyExc_ValueError, "Argument must be a sequence type"); - - len = MIN(pal->ncolors, PySequence_Length(list)); - - colors = (SDL_Color *)malloc(len * sizeof(SDL_Color)); - if (!colors) - return NULL; - - for (i = 0; i < len; i++) { - item = PySequence_GetItem(list, i); - if (!PySequence_Check(item) || PySequence_Length(item) != 3) { - Py_DECREF(item); - free((char *)colors); - return RAISE(PyExc_TypeError, - "takes a sequence of sequence of RGB"); - } - if (!pg_IntFromObjIndex(item, 0, &r) || - !pg_IntFromObjIndex(item, 1, &g) || - !pg_IntFromObjIndex(item, 2, &b)) { - Py_DECREF(item); - free((char *)colors); - return RAISE(PyExc_TypeError, - "RGB sequence must contain numeric values"); - } - - colors[i].r = (unsigned char)r; - colors[i].g = (unsigned char)g; - colors[i].b = (unsigned char)b; - - Py_DECREF(item); - } - - SDL_SetPalette(surf, SDL_PHYSPAL, colors, 0, len); - - free((char *)colors); - Py_RETURN_NONE; -} - -static PyObject * -pg_set_gamma(PyObject *self, PyObject *arg) -{ - float r, g, b; - int result = 0; - if (!PyArg_ParseTuple(arg, "f|ff", &r, &g, &b)) - return NULL; - if (PyTuple_Size(arg) == 1) - g = b = r; - VIDEO_INIT_CHECK(); - result = SDL_SetGamma(r, g, b); - return PyBool_FromLong(result == 0); -} -#endif /* IS_SDLv1 */ static int pg_convert_to_uint16(PyObject *python_array, Uint16 *c_uint16_array) @@ -2347,7 +1865,6 @@ pg_convert_to_uint16(PyObject *python_array, Uint16 *c_uint16_array) return 1; } -#if IS_SDLv2 static PyObject * pg_set_gamma_ramp(PyObject *self, PyObject *arg) { @@ -2938,122 +2455,6 @@ pg_display_resize_event(PyObject *self, PyObject *event) Py_RETURN_FALSE; } -#else /* IS_SDLv1 */ -static PyObject * -pg_set_gamma_ramp(PyObject *self, PyObject *arg) -{ - Uint16 *r, *g, *b; - int result; - r = (Uint16 *)malloc(256 * sizeof(Uint16)); - if (!r) - return NULL; - g = (Uint16 *)malloc(256 * sizeof(Uint16)); - if (!g) { - free(r); - return NULL; - } - b = (Uint16 *)malloc(256 * sizeof(Uint16)); - if (!b) { - free(r); - free(g); - return NULL; - } - if (!PyArg_ParseTuple(arg, "O&O&O&", pg_convert_to_uint16, r, - pg_convert_to_uint16, g, pg_convert_to_uint16, b)) { - free(r); - free(g); - free(b); - return NULL; - } - VIDEO_INIT_CHECK(); - result = SDL_SetGammaRamp(r, g, b); - free((char *)r); - free((char *)g); - free((char *)b); - return PyBool_FromLong(result == 0); -} - -static PyObject * -pg_set_caption(PyObject *self, PyObject *arg) -{ - char *title, *icontitle = NULL; - if (!PyArg_ParseTuple(arg, "es|es", "UTF-8", &title, "UTF-8", &icontitle)) - return NULL; - SDL_WM_SetCaption(title, icontitle ? icontitle : title); - PyMem_Free(title); - PyMem_Free(icontitle); - Py_RETURN_NONE; -} - -static PyObject * -pg_get_caption(PyObject *self) -{ - char *title, *icontitle; - SDL_WM_GetCaption(&title, &icontitle); - if (title && *title) { - PyObject *titleObj = Text_FromUTF8(title); - PyObject *iconObj = Text_FromUTF8(icontitle); - PyObject *ret = PyTuple_Pack(2, titleObj, iconObj); - Py_DECREF(titleObj); - Py_DECREF(iconObj); - return ret; - } - return PyTuple_New(0); -} - -static void -pg_do_set_icon(PyObject *surface) -{ - SDL_Surface *surf = pgSurface_AsSurface(surface); - SDL_WM_SetIcon(surf, NULL); - icon_was_set = 1; -} - -static PyObject * -pg_set_icon(PyObject *self, PyObject *arg) -{ - PyObject *surface; - if (!PyArg_ParseTuple(arg, "O!", &pgSurface_Type, &surface)) - return NULL; - - if (!SDL_WasInit(SDL_INIT_VIDEO)) { - if (!pg_display_init(NULL)) - return NULL; - } - pg_do_set_icon(surface); - Py_RETURN_NONE; -} - -static PyObject * -pg_iconify(PyObject *self) -{ - int result; - VIDEO_INIT_CHECK(); - result = SDL_WM_IconifyWindow(); - - /* If the application is running in a window managed environment SDL - attempts to iconify/minimise it. If SDL_WM_IconifyWindow is successful, - the application will receive a SDL_APPACTIVE loss event (see - SDL_ActiveEvent). - */ - return PyBool_FromLong(result != 0); -} - -static PyObject * -pg_toggle_fullscreen(PyObject *self) -{ - //https://sdl.beuc.net/sdl.wiki/SDL_WM_ToggleFullScreen - SDL_Surface *screen; - int result; - VIDEO_INIT_CHECK(); - screen = SDL_GetVideoSurface(); - if (!screen) - return RAISE(pgExc_SDLError, SDL_GetError()); - - result = SDL_WM_ToggleFullScreen(screen); - return PyInt_FromLong(result != 0); -} -#endif /* IS_SDLv1 */ static PyObject * @@ -3063,11 +2464,7 @@ pg_get_allow_screensaver(PyObject *self) { * the video being initialized before calling it. */ VIDEO_INIT_CHECK(); -#if IS_SDLv2 return PyBool_FromLong(SDL_IsScreenSaverEnabled() == SDL_TRUE); -#else /* IS_SDLv1*/ - return PyBool_FromLong(_allow_screensaver); -#endif /* IS_SDLv1*/ } static PyObject * @@ -3081,17 +2478,9 @@ pg_set_allow_screensaver(PyObject *self, PyObject *arg, PyObject *kwargs) { VIDEO_INIT_CHECK(); if (val) { -#if IS_SDLv2 SDL_EnableScreenSaver(); -#else - _allow_screensaver = 1; -#endif } else { -#if IS_SDLv2 SDL_DisableScreenSaver(); -#else - _allow_screensaver = 0; -#endif } Py_RETURN_NONE; @@ -3138,7 +2527,6 @@ static PyMethodDef _pg_display_methods[] = { {"toggle_fullscreen", (PyCFunction)pg_toggle_fullscreen, METH_NOARGS, DOC_PYGAMEDISPLAYTOGGLEFULLSCREEN}, -#if IS_SDLv2 {"_set_autoresize", (PyCFunction)pg_display_set_autoresize , METH_VARARGS, "provisional API, subject to change"}, {"_resize_event", (PyCFunction)pg_display_resize_event, METH_O, @@ -3149,7 +2537,6 @@ static PyMethodDef _pg_display_methods[] = { METH_NOARGS, DOC_PYGAMEDISPLAYGETDESKTOPSIZES}, {"is_fullscreen", (PyCFunction)pg_is_fullscreen, METH_NOARGS, "provisional API, subject to change"}, -#endif {"gl_set_attribute", pg_gl_set_attribute, METH_VARARGS, DOC_PYGAMEDISPLAYGLSETATTRIBUTE}, @@ -3163,7 +2550,6 @@ static PyMethodDef _pg_display_methods[] = { {NULL, NULL, 0, NULL}}; -#if IS_SDLv2 #ifndef PYPY_VERSION static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, "display", @@ -3228,65 +2614,3 @@ MODINIT_DEFINE(display) MODINIT_RETURN(module); } -#else /* IF_SDLv1 */ - -MODINIT_DEFINE(display) -{ - PyObject *module, *dict, *apiobj; - int ecode; - static void *c_api[PYGAMEAPI_DISPLAY_NUMSLOTS]; - static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT, - "display", - DOC_PYGAMEDISPLAY, - -1, - _pg_display_methods, - NULL, - NULL, - NULL, - NULL}; - - /* imported needed apis; Do this first so if there is an error - the module is not loaded. - */ - import_pygame_base(); - if (PyErr_Occurred()) { - MODINIT_ERROR; - } - import_pygame_rect(); - if (PyErr_Occurred()) { - MODINIT_ERROR; - } - import_pygame_surface(); - if (PyErr_Occurred()) { - MODINIT_ERROR; - } - - /* type preparation */ - if (PyType_Ready(&pgVidInfo_Type) < 0) { - MODINIT_ERROR; - } - - /* create the module */ - module = PyModule_Create(&_module); - if (module == NULL) { - MODINIT_ERROR; - } - dict = PyModule_GetDict(module); - - /* export the c api */ - c_api[0] = &pgVidInfo_Type; - c_api[1] = pgVidInfo_New; - apiobj = encapsulate_api(c_api, "display"); - if (apiobj == NULL) { - DECREF_MOD(module); - MODINIT_ERROR; - } - ecode = PyDict_SetItemString(dict, PYGAMEAPI_LOCAL_ENTRY, apiobj); - Py_DECREF(apiobj); - if (ecode) { - DECREF_MOD(module); - MODINIT_ERROR; - } - MODINIT_RETURN(module); -} -#endif /* IF_SDLv1 */ diff --git a/src_c/draw.c b/src_c/draw.c index d80ad9e871..950c6d3b97 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -865,12 +865,10 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs) int x, y, w, h; /* Fields for the rounded rect draw to "normalize" into */ int top_left_radius = -1, top_right_radius = -1, bottom_left_radius = -1, bottom_right_radius = -1; -#if IS_SDLv2 SDL_Rect sdlrect; SDL_Rect cliprect; int result; SDL_Rect clipped; -#endif /* IS_SDLv2 */ int drawn_area[4] = {INT_MAX, INT_MAX, INT_MIN, INT_MIN}; /* Used to store bounding box values */ static char *keywords[] = {"surface", @@ -913,7 +911,6 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs) if ((radius <= 0 && top_left_radius <= 0 && top_right_radius <= 0 && bottom_left_radius <= 0 && bottom_right_radius <= 0) || abs(rect->w) < 2 || abs(rect->h) < 2) { -#if IS_SDLv2 if(width > 0){ l = rect->x; r = rect->x + rect->w - 1; @@ -954,21 +951,6 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs) return RAISE(pgExc_SDLError, SDL_GetError()); return pgRect_New(&clipped); } -#else - l = rect->x; - r = rect->x + rect->w - 1; - t = rect->y; - b = rect->y + rect->h - 1; - points = Py_BuildValue("((ii)(ii)(ii)(ii))", l, t, r, t, r, b, l, b); - poly_args = Py_BuildValue("(OONi)", surfobj, colorobj, points, width); - if (NULL == poly_args) { - return NULL; /* Exception already set. */ - } - - ret = polygon(NULL, poly_args, NULL); - Py_DECREF(poly_args); - return ret; -#endif } else { if (!pgSurface_Lock(surfobj)) { diff --git a/src_c/event.c b/src_c/event.c index 4220060f9b..c8c8d719b3 100644 --- a/src_c/event.c +++ b/src_c/event.c @@ -37,7 +37,6 @@ // include it there for now. #include -#if IS_SDLv2 #define JOYEVENT_INSTANCE_ID "instance_id" #define JOYEVENT_DEVICE_INDEX "device_index" @@ -47,15 +46,6 @@ #define PG_PEEP_EVENT_ALL(x, y, z) \ SDL_PeepEvents(x, y, z, SDL_FIRSTEVENT, SDL_LASTEVENT) -#else /* IS_SLDv1 */ - -#define JOYEVENT_INSTANCE_ID "joy" -#define JOYEVENT_DEVICE_INDEX "joy" - -#define PG_PEEP_EVENT(a, b, c, d) SDL_PeepEvents(a, b, c, SDL_EVENTMASK(d)) -#define PG_PEEP_EVENT_ALL(x, y, z) SDL_PeepEvents(x, y, z, SDL_ALLEVENTS) - -#endif /* IS_SLDv1 */ /* These are used for checks. The checks are kinda redundant because we * have proxy events anyways, but this is needed for SDL1 */ @@ -80,7 +70,6 @@ static int _pg_event_is_init = 0; * at the end as well */ #define UNICODE_LEN 4 -#if IS_SDLv2 /* This defines the maximum values of key-press and unicode values we * can store at a time, it is used for determining the unicode attribute @@ -266,51 +255,6 @@ _pg_get_event_unicode(SDL_Event *event) return PyUnicode_FromString(""); } -#else /* IS_SDLv1 */ - -/* Convert a Uint16 unicode codepoint to Python Unicode Object - * This is the same as python 2 unichr() function and almost same as - * python 3 chr() function, except it does not support numbers larger - * than the limit of Uint16. */ -static PyObject * -_pg_chr(Uint16 uni) -{ - char ret[UNICODE_LEN] = { 0 }; - - if (uni < 0x80) { - /* We can UTF-8 encode it within a single byte */ - ret[0] = (uni & 0xFF); - } - else if (uni < 0x0800) { - /* We can UTF-8 encode it within 2 bytes */ - ret[0] = 0xC0; /* binary: 1100 0000 */ - ret[1] = 0x80; /* binary: 1000 0000 */ - - /* binary: 0000 0111 1100 0000 is 0x07C0 */ - /* binary: 0000 0000 0011 1111 is 0x3F */ - ret[0] |= ((uni & 0x07C0) >> 6); - ret[1] |= (uni & 0x3F); - } - else { - /* We can UTF-8 encode it within 3 bytes */ - ret[0] = 0xE0; /* binary: 1110 0000 */ - ret[1] = 0x80; /* binary: 1000 0000 */ - ret[2] = 0x80; /* binary: 1000 0000 */ - - /* binary: 1111 0000 0000 0000 is 0xF000 */ - /* binary: 0000 1111 1100 0000 is 0x0FC0 */ - /* binary: 0000 0000 0011 1111 is 0x003F */ - ret[0] |= ((uni & 0xF000) >> 12); - ret[1] |= ((uni & 0x0FC0) >> 6); - ret[2] |= (uni & 0x3F); - } - /* You may be thinking why we are not handling unicode that is - * represented in 4 bytes. Because our input is Uint16, there is - * no chance that our input needs 4 bytes for encoding */ - return PyUnicode_FromString(ret); /* Dont use Text_FromUTF8 here */ -} - -#endif /* IS_SDLv1 */ /* The next two functions are used for proxying SDL events to and from * PGPOST_* events. These functions do NOT proxy on SDL1. @@ -328,9 +272,6 @@ _pg_chr(Uint16 uni) static Uint32 _pg_pgevent_proxify(Uint32 type) { -#if IS_SDLv1 - return type; -#else /* IS_SDLv2 */ switch (type) { case SDL_ACTIVEEVENT: return PGPOST_ACTIVEEVENT; @@ -462,15 +403,11 @@ _pg_pgevent_proxify(Uint32 type) default: return type; } -#endif /* IS_SDLv2 */ } static Uint32 _pg_pgevent_deproxify(Uint32 type) { -#if IS_SDLv1 - return type; -#else /* IS_SDLv2 */ switch (type) { case PGPOST_ACTIVEEVENT: return SDL_ACTIVEEVENT; @@ -602,10 +539,8 @@ _pg_pgevent_deproxify(Uint32 type) default: return type; } -#endif /* IS_SDLv2 */ } -#if IS_SDLv2 static SDL_Event *_pg_last_keydown_event = NULL; static int @@ -793,18 +728,15 @@ pg_GetKeyRepeat(int *delay, int *interval) *delay = pg_key_repeat_delay; *interval = pg_key_repeat_interval; } -#endif /* IS_SDLv2 */ static PyObject * pgEvent_AutoQuit(PyObject *self) { if (_pg_event_is_init) { -#if IS_SDLv2 if (_pg_repeat_timer) { SDL_RemoveTimer(_pg_repeat_timer); _pg_repeat_timer = 0; } -#endif /* IS_SLDv2 */ /* The main reason for _custom_event to be reset here is so we * can have a unit test that checks if pygame.event.custom_type() * stops returning new types when they are finished, without that @@ -818,13 +750,11 @@ pgEvent_AutoQuit(PyObject *self) static PyObject * pgEvent_AutoInit(PyObject *self) { -#if IS_SDLv2 if (!_pg_event_is_init) { pg_key_repeat_delay = 0; pg_key_repeat_interval = 0; SDL_SetEventFilter(pg_event_filter, NULL); } -#endif /* IS_SDLv2 */ _pg_event_is_init = 1; Py_RETURN_NONE; } @@ -884,7 +814,6 @@ _pg_name_from_eventtype(int type) return "MidiOut"; case SDL_NOEVENT: return "NoEvent"; -#if IS_SDLv2 case SDL_FINGERMOTION: return "FingerMotion"; case SDL_FINGERDOWN: @@ -972,7 +901,6 @@ _pg_name_from_eventtype(int type) return "WindowTakeFocus"; case PGE_WINDOWHITTEST: return "WindowHitTest"; -#endif /* IS_SDLv2 */ } if (type >= PGE_USEREVENT && type < PG_NUMEVENTS) @@ -991,7 +919,6 @@ _pg_insobj(PyObject *dict, char *name, PyObject *v) } } -#if IS_SDLv2 static PyObject * get_joy_guid(int device_index) { char strguid[33]; @@ -1000,7 +927,6 @@ get_joy_guid(int device_index) { SDL_JoystickGetGUIDString(guid, strguid, 33); return Text_FromUTF8(strguid); } -#endif /** Try to insert the instance ID for a new device into the joystick mapping. */ void @@ -1052,10 +978,8 @@ dict_from_event(SDL_Event *event) { PyObject *dict = NULL, *tuple, *obj; int hx, hy; -#if IS_SDLv2 long gain; long state; -#endif /* IS_SDLv2 */ /* check if a proxy event or userevent was posted */ if (event->type >= PGPOST_EVENTBEGIN && event->user.code == USEROBJ_CHECK) @@ -1066,18 +990,6 @@ dict_from_event(SDL_Event *event) return NULL; switch (event->type) { -#if IS_SDLv1 - case SDL_VIDEORESIZE: - obj = Py_BuildValue("(ii)", event->resize.w, event->resize.h); - _pg_insobj(dict, "size", obj); - _pg_insobj(dict, "w", PyInt_FromLong(event->resize.w)); - _pg_insobj(dict, "h", PyInt_FromLong(event->resize.h)); - break; - case SDL_ACTIVEEVENT: - _pg_insobj(dict, "gain", PyInt_FromLong(event->active.gain)); - _pg_insobj(dict, "state", PyInt_FromLong(event->active.state)); - break; -#else /* IS_SDLv2 */ case SDL_VIDEORESIZE: obj = Py_BuildValue("(ii)", event->window.data1, event->window.data2); @@ -1115,15 +1027,9 @@ dict_from_event(SDL_Event *event) _pg_insobj(dict, "gain", PyInt_FromLong(gain)); _pg_insobj(dict, "state", PyInt_FromLong(state)); break; -#endif /* IS_SDLv2 */ case SDL_KEYDOWN: -#if IS_SDLv1 - _pg_insobj(dict, "unicode", _pg_chr(event->key.keysym.unicode)); - case SDL_KEYUP: -#else /* IS_SDLv2 */ case SDL_KEYUP: _pg_insobj(dict, "unicode", _pg_get_event_unicode(event)); -#endif /* IS_SDLv2 */ _pg_insobj(dict, "key", PyInt_FromLong(event->key.keysym.sym)); _pg_insobj(dict, "mod", PyInt_FromLong(event->key.keysym.mod)); _pg_insobj(dict, "scancode", PyInt_FromLong(event->key.keysym.scancode)); @@ -1198,7 +1104,6 @@ dict_from_event(SDL_Event *event) _pg_insobj(dict, "instance_id", PyInt_FromLong(event->jbutton.which)); _pg_insobj(dict, "button", PyInt_FromLong(event->jbutton.button)); break; -#if IS_SDLv2 case PGE_WINDOWMOVED: case PGE_WINDOWRESIZED: case PGE_WINDOWSIZECHANGED: @@ -1314,18 +1219,8 @@ dict_from_event(SDL_Event *event) _pg_insobj(dict, "pressure", PyFloat_FromDouble(event->ctouchpad.pressure)); break; #endif /*SDL_VERSION_ATLEAST(2, 0, 14)*/ -#endif #ifdef WIN32 -#if IS_SDLv1 - case SDL_SYSWMEVENT: - _pg_insobj(dict, "hwnd", - PyInt_FromLong((long)(event->syswm.msg->hwnd))); - _pg_insobj(dict, "msg", PyInt_FromLong(event->syswm.msg->msg)); - _pg_insobj(dict, "wparam", PyInt_FromLong(event->syswm.msg->wParam)); - _pg_insobj(dict, "lparam", PyInt_FromLong(event->syswm.msg->lParam)); - break; -#else /* IS_SDLv2 */ case SDL_SYSWMEVENT: _pg_insobj(dict, "hwnd", PyInt_FromLong((long)(event->syswm.msg->msg.win.hwnd))); @@ -1333,21 +1228,12 @@ dict_from_event(SDL_Event *event) _pg_insobj(dict, "wparam", PyInt_FromLong(event->syswm.msg->msg.win.wParam)); _pg_insobj(dict, "lparam", PyInt_FromLong(event->syswm.msg->msg.win.lParam)); break; -#endif /* IS_SDLv2 */ #endif /* WIN32 */ #if (defined(unix) || defined(__unix__) || defined(_AIX) || \ defined(__OpenBSD__)) && \ (defined(SDL_VIDEO_DRIVER_X11) && !defined(__CYGWIN32__) && \ !defined(ENABLE_NANOX) && !defined(__QNXNTO__)) -#if IS_SDLv1 - case SDL_SYSWMEVENT: - _pg_insobj(dict, "event", - Bytes_FromStringAndSize( - (char *)&(event->syswm.msg->event.xevent), - sizeof(XEvent))); - break; -#else /* IS_SDLv2 */ case SDL_SYSWMEVENT: if (event->syswm.msg->subsystem == SDL_SYSWM_X11) { XEvent *xevent = (XEvent *)&event->syswm.msg->msg.x11.event; @@ -1355,14 +1241,12 @@ dict_from_event(SDL_Event *event) _pg_insobj(dict, "event", obj); } break; -#endif /* IS_SDLv2 */ #endif /* (defined(unix) || ... */ } /* switch (event->type) */ /* Events that dont have any attributes are not handled in switch * statement */ switch (event->type) { -#if IS_SDLv2 case PGE_WINDOWSHOWN: case PGE_WINDOWHIDDEN: case PGE_WINDOWEXPOSED: @@ -1382,14 +1266,12 @@ dict_from_event(SDL_Event *event) case SDL_TEXTEDITING: case SDL_TEXTINPUT: case SDL_MOUSEWHEEL: -#endif /* IS_SDLv2 */ case SDL_KEYDOWN: case SDL_KEYUP: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { -#if IS_SDLv2 SDL_Window *window = SDL_GetWindowFromID(event->window.windowID); PyObject *pgWindow; if (!window || !(pgWindow=SDL_GetWindowData(window, "pg_window"))) { @@ -1397,10 +1279,6 @@ dict_from_event(SDL_Event *event) } Py_INCREF(pgWindow); _pg_insobj(dict, "window", pgWindow); -#else /* IS_SDLv1 */ - Py_INCREF(Py_None); - _pg_insobj(dict, "window", Py_None); -#endif /* IS_SDLv1 */ break; } } @@ -1733,20 +1611,12 @@ static PyObject * set_grab(PyObject *self, PyObject *arg) { int doit; -#if IS_SDLv2 SDL_Window *win = NULL; -#endif /* IS_SDLv2 */ if (!PyArg_ParseTuple(arg, "p", &doit)) return NULL; VIDEO_INIT_CHECK(); -#if IS_SDLv1 - if (doit) - SDL_WM_GrabInput(SDL_GRAB_ON); - else - SDL_WM_GrabInput(SDL_GRAB_OFF); -#else /* IS_SDLv2 */ win = pg_GetDefaultWindow(); if (win) { if (doit) { @@ -1761,7 +1631,6 @@ set_grab(PyObject *self, PyObject *arg) SDL_SetRelativeMouseMode(0); } } -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } @@ -1769,10 +1638,6 @@ set_grab(PyObject *self, PyObject *arg) static PyObject * get_grab(PyObject *self) { -#if IS_SDLv1 - VIDEO_INIT_CHECK(); - return PyBool_FromLong(SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON); -#else /* IS_SDLv2 */ SDL_Window *win; SDL_bool mode = SDL_FALSE; @@ -1781,7 +1646,6 @@ get_grab(PyObject *self) if (win) mode = SDL_GetWindowGrab(win); return PyBool_FromLong(mode); -#endif /* IS_SDLv2 */ } static void @@ -1790,13 +1654,11 @@ _pg_event_pump(int dopump) if (dopump) { SDL_PumpEvents(); } -#if IS_SDLv2 /* We need to translate WINDOWEVENTS. But if we do that from the * from event filter, internal SDL stuff that rely on WINDOWEVENT * might break. So after every event pump, we translate events from * here */ SDL_FilterEvents(_pg_translate_windowevent, NULL); -#endif } static int @@ -1912,20 +1774,12 @@ _pg_eventtype_as_seq(PyObject *obj, int *len) static void _pg_flush_events(Uint32 type) { -#if IS_SDLv1 - SDL_Event event; - if (type == MAX_UINT32) - while (PG_PEEP_EVENT_ALL(&event, 1, SDL_GETEVENT) == 1); - else - while (PG_PEEP_EVENT(&event, 1, SDL_GETEVENT, type) == 1); -#else /* IS_SDLv2 */ if (type == MAX_UINT32) SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT); else { SDL_FlushEvent(type); SDL_FlushEvent(_pg_pgevent_proxify(type)); } -#endif /* IS_SDLv2 */ } static PyObject * @@ -2036,7 +1890,6 @@ _pg_get_all_events_except(PyObject *obj) filtered_index++; } } while (ret); -#if IS_SDLv2 do { ret = PG_PEEP_EVENT(&event, 1, SDL_GETEVENT, _pg_pgevent_proxify(type)); @@ -2060,7 +1913,6 @@ _pg_get_all_events_except(PyObject *obj) filtered_index++; } } while (ret); -#endif } do { @@ -2152,7 +2004,6 @@ _pg_get_seq_events(PyObject *obj) goto error; } } while (ret); -#if IS_SDLv2 do { ret = PG_PEEP_EVENT(&event, 1, SDL_GETEVENT, _pg_pgevent_proxify(type)); @@ -2165,7 +2016,6 @@ _pg_get_seq_events(PyObject *obj) goto error; } } while (ret); -#endif /* IS_SDLv2 */ } Py_DECREF(seq); return list; @@ -2260,7 +2110,6 @@ pg_event_peek(PyObject *self, PyObject *args, PyObject *kwargs) return RAISE(pgExc_SDLError, SDL_GetError()); Py_RETURN_TRUE; } -#if IS_SDLv2 res = PG_PEEP_EVENT(&event, 1, SDL_PEEKEVENT, _pg_pgevent_proxify(type)); if (res) { @@ -2270,7 +2119,6 @@ pg_event_peek(PyObject *self, PyObject *args, PyObject *kwargs) return RAISE(pgExc_SDLError, SDL_GetError()); Py_RETURN_TRUE; } -#endif /* IS_SDLv2 */ } Py_DECREF(seq); Py_RETURN_FALSE; /* No event type match. */ @@ -2300,15 +2148,6 @@ pg_event_post(PyObject *self, PyObject *obj) pgEvent_FillUserEvent(e, &event); ret = SDL_PushEvent(&event); -#if IS_SDLv1 - if (ret == -1) { - Py_DECREF(e->dict); - return RAISE(pgExc_SDLError, SDL_GetError()); - } - else { - Py_RETURN_TRUE; - } -#else /* IS_SDLv2 */ if (ret == 1) Py_RETURN_TRUE; else { @@ -2318,7 +2157,6 @@ pg_event_post(PyObject *self, PyObject *obj) else return RAISE(pgExc_SDLError, SDL_GetError()); } -#endif /* IS_SDLv2 */ } static PyObject * @@ -2329,14 +2167,10 @@ pg_event_set_allowed(PyObject *self, PyObject *obj) VIDEO_INIT_CHECK(); if (obj == Py_None) { -#if IS_SDLv2 int i; for (i=SDL_FIRSTEVENT; irender_flags & FT_RFLAG_ANTIALIAS) ? 32 : 8; -#if IS_SDLv1 - FT_UInt32 surface_flags = SDL_SWSURFACE; -#endif /* IS_SDLv1 */ FontSurface font_surf; Layout *font_text; @@ -465,11 +448,6 @@ SDL_Surface *_PGFT_Render_NewSurface(FreeTypeInstance *ft, offset.y = -font_text->min_y; } -#if IS_SDLv1 - surface = SDL_CreateRGBSurface(surface_flags, width, height, - bits_per_pixel, rmask, gmask, bmask, - bits_per_pixel == 32 ? amask : 0); -#else /* IS_SDLv2 */ if (bits_per_pixel == 32) { #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; @@ -485,7 +463,6 @@ SDL_Surface *_PGFT_Render_NewSurface(FreeTypeInstance *ft, } surface = SDL_CreateRGBSurface(0, width, height, bits_per_pixel, rmask, gmask, bmask, amask); -#endif /* IS_SDLv2 */ if (!surface) { PyErr_SetString(pgExc_SDLError, SDL_GetError()); return 0; @@ -526,54 +503,33 @@ SDL_Surface *_PGFT_Render_NewSurface(FreeTypeInstance *ft, SDL_FillRect(surface, 0, fillcolor); } else { -#if IS_SDLv2 SDL_Palette* palette = surface->format->palette; -#endif /* IS_SDLv2 */ SDL_Color colors[2]; -#if IS_SDLv2 if (!palette) { SDL_FreeSurface(surface); PyErr_NoMemory(); return 0; } -#endif /* IS_SDLv2 */ colors[1].r = fgcolor->r; /* Foreground */ colors[1].g = fgcolor->g; colors[1].b = fgcolor->b; -#if IS_SDLv2 colors[1].a = SDL_ALPHA_OPAQUE; -#endif /* IS_SDLv2 */ colors[0].r = ~colors[1].r; /* Background */ colors[0].g = ~colors[1].g; colors[0].b = ~colors[1].b; -#if IS_SDLv1 - if (!SDL_SetColors(surface, colors, 0, 2)) { - PyErr_SetString(PyExc_SystemError, - "Pygame bug in _PGFT_Render_NewSurface: " - "SDL_SetColors failed"); -#else /* IS_SDLv2 */ colors[0].a = SDL_ALPHA_OPAQUE; if (SDL_SetPaletteColors(palette, colors, 0, 2)) { PyErr_Format(PyExc_SystemError, "Pygame bug in _PGFT_Render_NewSurface: %.200s", SDL_GetError()); -#endif /* IS_SDLv2 */ SDL_FreeSurface(surface); return 0; } -#if IS_SDLv1 - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, (FT_UInt32)0); -#else /* IS_SDLv2 */ SDL_SetColorKey(surface, SDL_TRUE, (FT_UInt32)0); -#endif /* IS_SDLv2 */ if (fgcolor->a != SDL_ALPHA_OPAQUE) { -#if IS_SDLv1 - SDL_SetAlpha(surface, SDL_SRCALPHA, fgcolor->a); -#else /* IS_SDLv2 */ SDL_SetSurfaceAlphaMod(surface, fgcolor->a); SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); -#endif /* IS_SDLv2 */ } fgcolor = &mono_fgcolor; bgcolor = &mono_bgcolor; diff --git a/src_c/freetype/ft_wrap.c b/src_c/freetype/ft_wrap.c index ee3ad19028..fea54fd957 100644 --- a/src_c/freetype/ft_wrap.c +++ b/src_c/freetype/ft_wrap.c @@ -483,13 +483,7 @@ _PGFT_TryLoadFont_RWops(FreeTypeInstance *ft, pgFontObject *fontobj, stream->read = RWops_read; stream->descriptor.pointer = src; stream->pos = (unsigned long)position; -#if IS_SDLv1 - SDL_RWseek(src, 0, SEEK_END); - stream->size = (unsigned long)(SDL_RWtell(src) - position); - SDL_RWseek(src, position, SEEK_SET); -#else /* IS_SDLv2 */ stream->size = (unsigned long)(SDL_RWsize(src)); -#endif /* IS_SDLv2 */ fontobj->id.font_index = (FT_Long) font_index; fontobj->id.open_args.flags = FT_OPEN_STREAM; diff --git a/src_c/image.c b/src_c/image.c index a011c23aaa..f47a30564a 100644 --- a/src_c/image.c +++ b/src_c/image.c @@ -36,18 +36,11 @@ #include #endif -#if IS_SDLv1 -#include "pgopengl.h" -#endif /* IS_SDLv1 */ static int SaveTGA(SDL_Surface *surface, const char *file, int rle); static int SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle); -#if IS_SDLv1 -static SDL_Surface * -opengltosdl(void); -#endif /* IS_SDLv1 */ #define DATAROW(data, row, width, height, flipped) \ ((flipped) ? (((char *)data) + (height - row - 1) * width) \ @@ -125,79 +118,6 @@ image_load(PyObject *self, PyObject *arg) return image_load_extended(self, arg); } -#if IS_SDLv1 -static SDL_Surface * -opengltosdl() -{ - /*we need to get ahold of the pyopengl glReadPixels function*/ - /*we use pyopengl's so we don't need to link with opengl at compiletime*/ - SDL_Surface *surf = NULL; - Uint32 rmask, gmask, bmask; - int i; - unsigned char *pixels = NULL; - - GL_glReadPixels_Func p_glReadPixels = NULL; - - p_glReadPixels = - (GL_glReadPixels_Func)SDL_GL_GetProcAddress("glReadPixels"); - - surf = SDL_GetVideoSurface(); - - if (!surf) { - return (SDL_Surface *)RAISE(PyExc_RuntimeError, - "Cannot get video surface."); - - } - - if (!p_glReadPixels) { - return (SDL_Surface *)RAISE(PyExc_RuntimeError, - "Cannot find glReadPixels function."); - - } - - /* - GL_UNSIGNED_BYTE = 5121 - GL_RGB = 6407 - */ - - pixels = (unsigned char *)malloc(surf->w * surf->h * 3); - - if (!pixels) { - return (SDL_Surface *)RAISE( - PyExc_MemoryError, - "Cannot allocate enough memory for pixels."); - - } - // p_glReadPixels(0, 0, surf->w, surf->h, 6407, 5121, pixels); - // glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels); - p_glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels); - - if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { - rmask = 0x000000FF; - gmask = 0x0000FF00; - bmask = 0x00FF0000; - } - else { - rmask = 0x00FF0000; - gmask = 0x0000FF00; - bmask = 0x000000FF; - } - surf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, rmask, - gmask, bmask, 0); - if (!surf) { - free(pixels); - return (SDL_Surface *)RAISE(pgExc_SDLError, SDL_GetError()); - } - - for (i = 0; i < surf->h; ++i) { - memcpy(((char *)surf->pixels) + surf->pitch * i, - pixels + 3 * surf->w * (surf->h - i - 1), surf->w * 3); - } - - free(pixels); - return surf; -} -#endif /* IS_SDLv1 */ #ifdef WIN32 #define strcasecmp _stricmp @@ -225,9 +145,6 @@ image_save(PyObject *self, PyObject *arg) PyObject *ret; SDL_Surface *surf; int result = 1; -#if IS_SDLv1 - SDL_Surface *temp = NULL; -#endif /* IS_SDLv1 */ if (!PyArg_ParseTuple(arg, "O!O|s", &pgSurface_Type, &surfobj, &obj, &namehint)) { @@ -235,19 +152,7 @@ image_save(PyObject *self, PyObject *arg) } surf = pgSurface_AsSurface(surfobj); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) { - temp = surf = opengltosdl(); - if (surf == NULL) { - return NULL; - } - } - else { - pgSurface_Prep(surfobj); - } -#else /* IS_SDLv2 */ pgSurface_Prep(surfobj); -#endif /* IS_SDLv2 */ oencoded = pg_EncodeString(obj, "UTF-8", NULL, pgExc_SDLError); if (oencoded == NULL) { @@ -307,16 +212,7 @@ image_save(PyObject *self, PyObject *arg) } Py_XDECREF(oencoded); -#if IS_SDLv1 - if (temp) { - SDL_FreeSurface(temp); - } - else { - pgSurface_Unprep(surfobj); - } -#else /* IS_SDLv2 */ pgSurface_Unprep(surfobj); -#endif /* IS_SDLv2 */ if (result == -2) { /* Python error raised elsewhere */ @@ -511,21 +407,12 @@ tostring_surf_32bpp_sse42(SDL_Surface *surf, int flipped, char *data, #endif /* PG_COMPILE_SSE4_2 && SDL_VERSION_ATLEAST(2, 0, 0) */ -#if IS_SDLv2 static void tostring_surf_32bpp(SDL_Surface *surf, int flipped, int hascolorkey, Uint32 colorkey, char *serialized_image, int color_offset, int alpha_offset ) -#else -static void -tostring_surf_32bpp(SDL_Surface *surf, int flipped, - int hascolorkey, int colorkey, - char *serialized_image, - int color_offset, int alpha_offset -) -#endif /* !IS_SDLv2*/ { int w, h; @@ -610,25 +497,13 @@ image_tostring(PyObject *self, PyObject *arg) Uint32 Rmask, Gmask, Bmask, Amask, Rshift, Gshift, Bshift, Ashift, Rloss, Gloss, Bloss, Aloss; int hascolorkey; -#if IS_SDLv1 - SDL_Surface *temp = NULL; - int color, colorkey; -#else /* IS_SDLv2 */ Uint32 color, colorkey; -#endif /* IS_SDLv2 */ Uint32 alpha; if (!PyArg_ParseTuple(arg, "O!s|i", &pgSurface_Type, &surfobj, &format, &flipped)) return NULL; surf = pgSurface_AsSurface(surfobj); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) { - temp = surf = opengltosdl(); - if (!surf) - return NULL; - } -#endif /* IS_SDLv1 */ Rmask = surf->format->Rmask; Gmask = surf->format->Gmask; @@ -642,12 +517,7 @@ image_tostring(PyObject *self, PyObject *arg) Gloss = surf->format->Gloss; Bloss = surf->format->Bloss; Aloss = surf->format->Aloss; -#if IS_SDLv1 - hascolorkey = (surf->flags & SDL_SRCCOLORKEY) && !Amask; - colorkey = surf->format->colorkey; -#else /* IS_SDLv2 */ hascolorkey = (SDL_GetColorKey(surf, &colorkey) == 0); -#endif /* IS_SDLv2 */ if (!strcmp(format, "P")) { if (surf->format->BytesPerPixel != 1) @@ -673,12 +543,7 @@ image_tostring(PyObject *self, PyObject *arg) return NULL; Bytes_AsStringAndSize(string, &data, &len); -#if IS_SDLv1 - if (!temp) - pgSurface_Lock(surfobj); -#else /* IS_SDLv2 */ pgSurface_Lock(surfobj); -#endif /* IS_SDLv2 */ pixels = (char *)surf->pixels; switch (surf->format->BytesPerPixel) { @@ -741,12 +606,7 @@ image_tostring(PyObject *self, PyObject *arg) break; } -#if IS_SDLv1 - if (!temp) - pgSurface_Unlock(surfobj); -#else /* IS_SDLv2 */ pgSurface_Unlock(surfobj); -#endif /* IS_SDLv2 */ } else if (!strcmp(format, "RGBX") || !strcmp(format, "RGBA")) { if (strcmp(format, "RGBA")) @@ -1083,18 +943,10 @@ image_tostring(PyObject *self, PyObject *arg) pgSurface_Unlock(surfobj); } else { -#if IS_SDLv1 - if (temp) - SDL_FreeSurface(temp); -#endif /* IS_SDLv1 */ return RAISE(PyExc_ValueError, "Unrecognized type of format"); } -#if IS_SDLv1 - if (temp) - SDL_FreeSurface(temp); -#endif /* IS_SDLv1 */ return string; } @@ -1443,19 +1295,11 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) { SDL_Surface *linebuf = NULL; int alpha = 0; -#if IS_SDLv1 - int ckey = -1; -#endif /* IS_SDLv1 */ struct TGAheader h; int srcbpp; -#if IS_SDLv1 - unsigned surf_flags; - unsigned surf_alpha; -#else /* IS_SDLv2 */ Uint8 surf_alpha; int have_surf_colorkey = 0; Uint32 surf_colorkey; -#endif /* IS_SDLv2 */ Uint32 rmask, gmask, bmask, amask; SDL_Rect r; int bpp; @@ -1470,23 +1314,14 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) return -1; } -#if IS_SDLv2 SDL_GetSurfaceAlphaMod(surface, &surf_alpha); have_surf_colorkey = (SDL_GetColorKey(surface, &surf_colorkey) == 0); -#endif /* IS_SDLv2 */ if (srcbpp == 8) { h.has_cmap = 1; h.type = TGA_TYPE_INDEXED; -#if IS_SDLv1 - if (surface->flags & SDL_SRCCOLORKEY) { - ckey = surface->format->colorkey; - h.cmap_bits = 32; - } -#else /* IS_SDLv2 */ if (have_surf_colorkey) h.cmap_bits = 32; -#endif /* IS_SDLv2 */ else h.cmap_bits = 24; SETLE16(h.cmap_len, surface->format->palette->ncolors); @@ -1539,11 +1374,7 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) entry[0] = pal->colors[i].b; entry[1] = pal->colors[i].g; entry[2] = pal->colors[i].r; -#if IS_SDLv1 - entry[3] = (i == ckey) ? 0 : 0xff; -#else /* IS_SDLv2 */ entry[3] = ((unsigned)i == surf_colorkey) ? 0 : 0xff; -#endif /* IS_SDLv2 */ if (!SDL_RWwrite(out, entry, h.cmap_bits >> 3, 1)) return -1; } @@ -1555,17 +1386,12 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) return -1; if (h.has_cmap) { -#if IS_SDLv1 - SDL_SetColors(linebuf, surface->format->palette->colors, 0, - surface->format->palette->ncolors); -#else /* IS_SDLv2 */ if (0 != SDL_SetPaletteColors(linebuf->format->palette, surface->format->palette->colors, 0, surface->format->palette->ncolors)) { /* SDL error already set. */ goto error; } -#endif /* IS_SDLv2 */ } if (rle) { @@ -1578,18 +1404,9 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) /* Temporarily remove colourkey and alpha from surface so copies are opaque */ -#if IS_SDLv1 - surf_flags = surface->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY); - surf_alpha = surface->format->alpha; - if (surf_flags & SDL_SRCALPHA) - SDL_SetAlpha(surface, 0, 255); - if (surf_flags & SDL_SRCCOLORKEY) - SDL_SetColorKey(surface, 0, surface->format->colorkey); -#else /* IS_SDLv2 */ SDL_SetSurfaceAlphaMod(surface, SDL_ALPHA_OPAQUE); if (have_surf_colorkey) SDL_SetColorKey(surface, SDL_FALSE, surf_colorkey); -#endif /* IS_SDLv2 */ r.x = 0; r.w = surface->w; @@ -1612,16 +1429,9 @@ SaveTGA_RW(SDL_Surface *surface, SDL_RWops *out, int rle) } /* restore flags */ -#if IS_SDLv1 - if (surf_flags & SDL_SRCALPHA) - SDL_SetAlpha(surface, SDL_SRCALPHA, (Uint8)surf_alpha); - if (surf_flags & SDL_SRCCOLORKEY) - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, surface->format->colorkey); -#else /* IS_SDLv2 */ SDL_SetSurfaceAlphaMod(surface, surf_alpha); if (have_surf_colorkey) SDL_SetColorKey(surface, SDL_TRUE, surf_colorkey); -#endif /* IS_SDLv2 */ free(rlebuf); SDL_FreeSurface(linebuf); diff --git a/src_c/imageext.c b/src_c/imageext.c index e892827bc0..536f48a575 100644 --- a/src_c/imageext.c +++ b/src_c/imageext.c @@ -72,19 +72,11 @@ static SDL_mutex *_pg_img_mutex = 0; #endif /* WITH_THREAD */ #ifdef WIN32 - #include - -#if IS_SDLv1 -#define pg_RWflush(rwops) (FlushFileBuffers((HANDLE)(rwops)->hidden.win32io.h) ? 0 : -1) -#else /* IS_SDLv2 */ #define pg_RWflush(rwops) (FlushFileBuffers((HANDLE)(rwops)->hidden.windowsio.h) ? 0 : -1) -#endif /* IS_SDLv2 */ #else /* ~WIN32 */ - #define pg_RWflush(rwops) (fflush((rwops)->hidden.stdio.fp) ? -1 : 0) - #endif /* ~WIN32 */ static const char * @@ -255,16 +247,10 @@ SavePNG(SDL_Surface *surface, const char *file, SDL_RWops *rw) int r, i; int alpha = 0; -#if IS_SDLv1 - unsigned surf_flags; - unsigned surf_alpha; - unsigned surf_colorkey; -#else /* IS_SDLv2 */ Uint8 surf_alpha = 255; Uint32 surf_colorkey; int has_colorkey = 0; SDL_BlendMode surf_mode; -#endif /* IS_SDLv2 */ ss_rows = 0; ss_size = 0; @@ -273,28 +259,6 @@ SavePNG(SDL_Surface *surface, const char *file, SDL_RWops *rw) ss_w = surface->w; ss_h = surface->h; -#if IS_SDLv1 - if (surface->format->Amask) { - alpha = 1; - ss_surface = - SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, ss_w, ss_h, 32, -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff000000, 0xff0000, 0xff00, 0xff -#else - 0xff, 0xff00, 0xff0000, 0xff000000 -#endif - ); - } - else { - ss_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, ss_w, ss_h, 24, -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - 0xff0000, 0xff00, 0xff, 0 -#else - 0xff, 0xff00, 0xff0000, 0 -#endif - ); - } -#else /* IS_SDLv2 */ if (surface->format->Amask) { alpha = 1; ss_surface = SDL_CreateRGBSurface(0, ss_w, ss_h, 32, @@ -314,21 +278,10 @@ SavePNG(SDL_Surface *surface, const char *file, SDL_RWops *rw) #endif ); } -#endif /* IS_SDLv2 */ if (ss_surface == NULL) return -1; -#if IS_SDLv1 - surf_flags = surface->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY); - surf_alpha = surface->format->alpha; - surf_colorkey = surface->format->colorkey; - - if (surf_flags & SDL_SRCALPHA) - SDL_SetAlpha(surface, 0, 255); - if (surf_flags & SDL_SRCCOLORKEY) - SDL_SetColorKey(surface, 0, surface->format->colorkey); -#else /* IS_SDLv2 */ SDL_GetSurfaceAlphaMod(surface, &surf_alpha); SDL_SetSurfaceAlphaMod(surface, 255); SDL_GetSurfaceBlendMode(surface, &surf_mode); @@ -338,7 +291,6 @@ SavePNG(SDL_Surface *surface, const char *file, SDL_RWops *rw) has_colorkey = 1; SDL_SetColorKey(surface, SDL_FALSE, surf_colorkey); } -#endif /* IS_SDLv2 */ ss_rect.x = 0; ss_rect.y = 0; @@ -352,17 +304,10 @@ SavePNG(SDL_Surface *surface, const char *file, SDL_RWops *rw) if (ss_rows == NULL) return -1; } -#if IS_SDLv1 - if (surf_flags & SDL_SRCALPHA) - SDL_SetAlpha(surface, SDL_SRCALPHA, (Uint8)surf_alpha); - if (surf_flags & SDL_SRCCOLORKEY) - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, surf_colorkey); -#else /* IS_SDLv2 */ if (has_colorkey) SDL_SetColorKey(surface, SDL_TRUE, surf_colorkey); SDL_SetSurfaceAlphaMod(surface, surf_alpha); SDL_SetSurfaceBlendMode(surface, surf_mode); -#endif /* IS_SDLv2 */ for (i = 0; i < ss_h; i++) { ss_rows[i] = @@ -570,18 +515,6 @@ SaveJPEG(SDL_Surface *surface, const char *file) So no conversion is needed. 24bit, RGB */ -#if IS_SDLv1 - if ((surface->format->BytesPerPixel == 3) && - !(surface->flags & SDL_SRCALPHA) && - (surface->format->Rmask == RED_MASK)) { - /* - printf("not creating...\n"); - */ - ss_surface = surface; - - free_ss_surface = 0; - } -#else /* IS_SDLv2 */ if (surface->format->format == SDL_PIXELFORMAT_RGB24) { /* printf("not creating...\n"); @@ -590,7 +523,6 @@ SaveJPEG(SDL_Surface *surface, const char *file) free_ss_surface = 0; } -#endif /* IS_SDLv2 */ else { /* printf("creating...\n"); @@ -599,14 +531,8 @@ SaveJPEG(SDL_Surface *surface, const char *file) /* If it is not, then we need to make a new surface. */ -#if IS_SDLv1 - ss_surface = - SDL_CreateRGBSurface(SDL_SWSURFACE, ss_w, ss_h, pixel_bits, - RED_MASK, GREEN_MASK, BLUE_MASK, 0); -#else /* IS_SDLv2 */ ss_surface = SDL_CreateRGBSurface(0, ss_w, ss_h, pixel_bits, RED_MASK, GREEN_MASK, BLUE_MASK, 0); -#endif /* IS_SDLv2 */ if (ss_surface == NULL) { return -1; } @@ -649,76 +575,6 @@ SaveJPEG(SDL_Surface *surface, const char *file) #endif /* end if JPEGLIB_H */ -#if IS_SDLv1 -/* NOTE XX HACK TODO FIXME: this opengltosdl is also in image.c - need to share it between both. -*/ - -static SDL_Surface * -opengltosdl(void) -{ - /*we need to get ahold of the pyopengl glReadPixels function*/ - /*we use pyopengl's so we don't need to link with opengl at compiletime*/ - SDL_Surface *surf = NULL; - Uint32 rmask, gmask, bmask; - int i; - unsigned char *pixels = NULL; - - GL_glReadPixels_Func p_glReadPixels = NULL; - - p_glReadPixels = - (GL_glReadPixels_Func)SDL_GL_GetProcAddress("glReadPixels"); - - surf = SDL_GetVideoSurface(); - - if (!surf) { - return (SDL_Surface *)RAISE(PyExc_RuntimeError, - "Cannot get video surface."); - } - if (!p_glReadPixels) { - return (SDL_Surface *)RAISE(PyExc_RuntimeError, - "Cannot find glReadPixels function."); - - } - - pixels = (unsigned char *)malloc(surf->w * surf->h * 3); - - if (!pixels) { - return (SDL_Surface *)RAISE( - PyExc_MemoryError, - "Cannot allocate enough memory for pixels."); - } - - /* GL_RGB, GL_UNSIGNED_BYTE */ - p_glReadPixels(0, 0, surf->w, surf->h, 0x1907, 0x1401, pixels); - - if (SDL_BYTEORDER == SDL_LIL_ENDIAN) { - rmask = 0x000000FF; - gmask = 0x0000FF00; - bmask = 0x00FF0000; - } - else { - rmask = 0x00FF0000; - gmask = 0x0000FF00; - bmask = 0x000000FF; - } - surf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, rmask, - gmask, bmask, 0); - if (!surf) { - free(pixels); - return (SDL_Surface *)RAISE(pgExc_SDLError, SDL_GetError()); - } - - for (i = 0; i < surf->h; ++i) { - memcpy(((char *)surf->pixels) + surf->pitch * i, - pixels + 3 * surf->w * (surf->h - i - 1), surf->w * 3); - } - - free(pixels); - return surf; -} - -#endif /* IS_SDLv1 */ static PyObject * image_save_ext(PyObject *self, PyObject *arg) @@ -731,9 +587,6 @@ image_save_ext(PyObject *self, PyObject *arg) int result = 1; const char *name = NULL; SDL_RWops *rw = NULL; -#if IS_SDLv1 - SDL_Surface *temp = NULL; -#endif /* IS_SDLv1 */ if (!PyArg_ParseTuple(arg, "O!O|s", &pgSurface_Type, &surfobj, &obj, &namehint)) { @@ -741,19 +594,7 @@ image_save_ext(PyObject *self, PyObject *arg) } surf = pgSurface_AsSurface(surfobj); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) { - temp = surf = opengltosdl(); - if (surf == NULL) { - return NULL; - } - } - else { - pgSurface_Prep(surfobj); - } -#else /* IS_SDLv2 */ pgSurface_Prep(surfobj); -#endif /* IS_SDLv2 */ oencoded = pg_EncodeString(obj, "UTF-8", NULL, pgExc_SDLError); if (oencoded == NULL) { @@ -845,16 +686,7 @@ image_save_ext(PyObject *self, PyObject *arg) } } -#if IS_SDLv1 - if (temp != NULL) { - SDL_FreeSurface(temp); - } - else { - pgSurface_Unprep(surfobj); - } -#else /* IS_SDLv2 */ pgSurface_Unprep(surfobj); -#endif /* IS_SDLv2 */ Py_XDECREF(oencoded); if (result == -2) { diff --git a/src_c/joystick.c b/src_c/joystick.c index c9b02aa3c4..8c430f8da9 100644 --- a/src_c/joystick.c +++ b/src_c/joystick.c @@ -135,7 +135,6 @@ joy_init(PyObject *self, PyObject *args) static int _joy_map_insert(pgJoystickObject *jstick) { -#if IS_SDLv2 SDL_JoystickID instance_id; PyObject *k, *v; @@ -155,7 +154,6 @@ _joy_map_insert(pgJoystickObject *jstick) { } Py_XDECREF(k); Py_XDECREF(v); -#endif return 0; } @@ -187,7 +185,6 @@ joy_get_id(PyObject *self, PyObject *args) return PyInt_FromLong(joy_id); } -#if IS_SDLv2 static PyObject * joy_get_instance_id(PyObject *self, PyObject *args) @@ -326,19 +323,12 @@ joy_stop_rumble(pgJoystickObject *self) Py_RETURN_NONE; } -#endif /*if IS_SDLv2*/ static PyObject * joy_get_name(PyObject *self, PyObject *args) { -#if IS_SDLv1 - int joy_id = pgJoystick_AsID(self); - JOYSTICK_INIT_CHECK(); - return Text_FromLocale(SDL_JoystickName(joy_id)); -#else /* IS_SDLv2 */ SDL_Joystick *joy = pgJoystick_AsSDL(self); return Text_FromUTF8(SDL_JoystickName(joy)); -#endif /* IS_SDLv2 */ } static PyObject * @@ -521,13 +511,11 @@ static PyMethodDef joy_methods[] = { {"get_init", joy_get_init, METH_NOARGS, DOC_JOYSTICKGETINIT}, {"get_id", joy_get_id, METH_NOARGS, DOC_JOYSTICKGETID}, -#if IS_SDLv2 {"get_instance_id", joy_get_instance_id, METH_NOARGS, DOC_JOYSTICKGETINSTANCEID}, {"get_guid", joy_get_guid, METH_NOARGS, DOC_JOYSTICKGETGUID}, {"get_power_level", joy_get_power_level, METH_NOARGS, DOC_JOYSTICKGETPOWERLEVEL}, {"rumble", (PyCFunction)joy_rumble, METH_VARARGS | METH_KEYWORDS, DOC_JOYSTICKRUMBLE}, {"stop_rumble", (PyCFunction)joy_stop_rumble, METH_NOARGS, DOC_JOYSTICKSTOPRUMBLE}, -#endif {"get_name", joy_get_name, METH_NOARGS, DOC_JOYSTICKGETNAME}, {"get_numaxes", joy_get_numaxes, METH_NOARGS, diff --git a/src_c/key.c b/src_c/key.c index 0486091b84..42a3d867e6 100644 --- a/src_c/key.c +++ b/src_c/key.c @@ -43,13 +43,8 @@ key_set_repeat(PyObject *self, PyObject *args) if (delay && !interval) interval = delay; -#if IS_SDLv1 - if (SDL_EnableKeyRepeat(delay, interval) == -1) - return RAISE(pgExc_SDLError, SDL_GetError()); -#else /* IS_SDLv2 */ if (pg_EnableKeyRepeat(delay, interval) == -1) return NULL; -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } @@ -61,11 +56,7 @@ key_get_repeat(PyObject *self, PyObject *args) int delay = 0, interval = 0; VIDEO_INIT_CHECK(); -#if IS_SDLv1 - SDL_GetKeyRepeat(&delay, &interval); -#else /* IS_SDLv2 */ pg_GetKeyRepeat(&delay, &interval); -#endif /* IS_SDLv2 */ return Py_BuildValue("(ii)", delay, interval); } #else /* not SDL_VERSION_ATLEAST(1, 2, 10) */ @@ -77,7 +68,6 @@ key_get_repeat(PyObject *self, PyObject *args) #endif /* not SDL_VERSION_ATLEAST(1, 2, 10) */ -#if IS_SDLv2 /* * pgScancodeWrapper is for key_get_pressed in SDL2. * It converts key symbol indices to scan codes, as suggested in @@ -162,28 +152,19 @@ static PyTypeObject pgScancodeWrapper_Type = { 0, /* tp_alloc */ 0 /* tp_new */ }; -#endif /* IS_SDLv2 */ static PyObject * key_get_pressed(PyObject *self, PyObject *args) { int num_keys; -#if IS_SDLv1 - Uint8 *key_state; -#else const Uint8 *key_state; PyObject *ret_obj = NULL; -#endif PyObject *key_tuple; int i; VIDEO_INIT_CHECK(); -#if IS_SDLv1 - key_state = SDL_GetKeyState(&num_keys); -#else /* IS_SDLv2 */ key_state = SDL_GetKeyboardState(&num_keys); -#endif /* IS_SDLv2 */ if (!key_state || !num_keys) Py_RETURN_NONE; @@ -201,17 +182,12 @@ key_get_pressed(PyObject *self, PyObject *args) PyTuple_SET_ITEM(key_tuple, i, key_elem); } -#if IS_SDLv1 - return key_tuple; -#else ret_obj = PyObject_CallFunctionObjArgs((PyObject *)&pgScancodeWrapper_Type, key_tuple, NULL); Py_DECREF(key_tuple); return ret_obj; -#endif } -#if IS_SDLv2 /* keep our own table for backward compatibility */ static const char *SDL1_scancode_names[SDL_NUM_SCANCODES] = { NULL, NULL, NULL, NULL, @@ -688,7 +664,6 @@ _get_keycode_name(SDL_Keycode key) } } -#endif /* IS_SDLv2 */ static PyObject * key_name(PyObject *self, PyObject *args) @@ -698,20 +673,14 @@ key_name(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "i", &key)) return NULL; -#if IS_SDLv2 return Text_FromUTF8(_get_keycode_name(key)); -#else - return Text_FromUTF8(SDL_GetKeyName(key)); -#endif } static PyObject * key_code(PyObject *self, PyObject *args, PyObject *kwargs) { const char * name; -#if IS_SDLv2 SDL_Keycode code; -#endif static char *kwids[] = { "name", @@ -721,10 +690,6 @@ key_code(PyObject *self, PyObject *args, PyObject *kwargs) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwids, &name)) return NULL; -#if IS_SDLv1 - PyErr_SetString(PyExc_NotImplementedError, "not supported with SDL 1"); - return 0; -#else code = SDL_GetKeyFromName(name); if (code != SDLK_UNKNOWN){ return PyInt_FromLong(code); @@ -735,7 +700,6 @@ key_code(PyObject *self, PyObject *args, PyObject *kwargs) return 0; } -#endif } @@ -766,30 +730,22 @@ key_get_focused(PyObject *self, PyObject *args) { VIDEO_INIT_CHECK(); -#if IS_SDLv1 - return PyBool_FromLong((SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0); -#else /* IS_SDLv2 */ return PyBool_FromLong(SDL_GetKeyboardFocus() != NULL); -#endif /* IS_SDLv2 */ } static PyObject * key_start_text_input(PyObject *self, PyObject *args) { -#if IS_SDLv2 /* https://wiki.libsdl.org/SDL_StartTextInput */ SDL_StartTextInput(); -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } static PyObject * key_stop_text_input(PyObject *self, PyObject *args) { -#if IS_SDLv2 /* https://wiki.libsdl.org/SDL_StopTextInput */ SDL_StopTextInput(); -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } @@ -797,7 +753,6 @@ static PyObject * key_set_text_input_rect(PyObject *self, PyObject *obj) { /* https://wiki.libsdl.org/SDL_SetTextInputRect */ -#if IS_SDLv2 SDL_Rect *rect, temp; SDL_Window *sdlWindow = pg_GetDefaultWindow(); SDL_Renderer *sdlRenderer = SDL_GetRenderer(sdlWindow); @@ -828,7 +783,6 @@ key_set_text_input_rect(PyObject *self, PyObject *obj) SDL_SetTextInputRect(rect); -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } @@ -874,7 +828,6 @@ MODINIT_DEFINE(key) if (PyErr_Occurred()) { MODINIT_ERROR; } -#if IS_SDLv2 import_pygame_rect(); if (PyErr_Occurred()) { MODINIT_ERROR; @@ -888,7 +841,6 @@ MODINIT_DEFINE(key) if (PyType_Ready(&pgScancodeWrapper_Type) < 0) { MODINIT_ERROR; } -#endif /* IS_SDLv2 */ /* create the module */ module = PyModule_Create(&_module); @@ -896,7 +848,6 @@ MODINIT_DEFINE(key) MODINIT_ERROR; } -#if IS_SDLv2 Py_INCREF((PyObject*)&pgScancodeWrapper_Type); if (PyModule_AddObject(module, _PG_SCANCODEWRAPPER_TYPE_NAME, (PyObject*)&pgScancodeWrapper_Type) == -1) { @@ -906,7 +857,6 @@ MODINIT_DEFINE(key) } _use_sdl1_key_names(); -#endif /* IS_SDLv2 */ MODINIT_RETURN(module); } diff --git a/src_c/mask.c b/src_c/mask.c index bd9ec7fbfe..75ea163466 100644 --- a/src_c/mask.c +++ b/src_c/mask.c @@ -859,14 +859,7 @@ mask_from_surface(PyObject *self, PyObject *args, PyObject *kwargs) Py_BEGIN_ALLOW_THREADS; /* Release the GIL. */ -#if IS_SDLv1 - if (surf->flags & SDL_SRCCOLORKEY) { - colorkey = surf->format->colorkey; - use_thresh = 0; - } -#else /* IS_SDLv2 */ use_thresh = (SDL_GetColorKey(surf, &colorkey) == -1); -#endif /* IS_SDLv2 */ if (use_thresh) { set_from_threshold(surf, maskobj->mask, threshold); @@ -2100,11 +2093,7 @@ check_surface_pixel_format(SDL_Surface *surf, SDL_Surface *check_surf) { if ((surf->format->BytesPerPixel != check_surf->format->BytesPerPixel) || (surf->format->BitsPerPixel != check_surf->format->BitsPerPixel) -#if IS_SDLv2 || (surf->format->format != check_surf->format->format) -#else - || ((surf->flags & SDL_SRCALPHA) != (check_surf->flags & SDL_SRCALPHA)) -#endif ) { return 0; } @@ -2146,11 +2135,7 @@ mask_to_surface(PyObject *self, PyObject *args, PyObject *kwargs) if (Py_None == surfobj) { surfobj = PyObject_CallFunction((PyObject *)&pgSurface_Type, "(ii)ii", bitmask->w, bitmask->h, -#if IS_SDLv1 - SDL_SRCALPHA, -#else PGS_SRCALPHA, -#endif 32); if (NULL == surfobj) { diff --git a/src_c/mixer.c b/src_c/mixer.c index f880929ec1..d94a7f5eb4 100644 --- a/src_c/mixer.c +++ b/src_c/mixer.c @@ -65,12 +65,8 @@ const PG_sample_format_t PG_SAMPLE_CHAR_SIGN = (char)0xff > 0 ? 0 : 0x10000u; #define PYGAME_MIXER_DEFAULT_SIZE -16 #define PYGAME_MIXER_DEFAULT_CHANNELS 2 #define PYGAME_MIXER_DEFAULT_CHUNKSIZE 512 -#if IS_SDLv2 #define PYGAME_MIXER_DEFAULT_ALLOWEDCHANGES SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | \ SDL_AUDIO_ALLOW_CHANNELS_CHANGE -#else -#define PYGAME_MIXER_DEFAULT_ALLOWEDCHANGES -1 -#endif static int sound_init(PyObject *, PyObject *, PyObject *); @@ -123,14 +119,12 @@ _format_itemsize(Uint16 format) case AUDIO_S16MSB: size = 2; break; -#if IS_SDLv2 case AUDIO_S32LSB: case AUDIO_S32MSB: case AUDIO_F32LSB: case AUDIO_F32MSB: size = 4; break; -#endif default: PyErr_Format(PyExc_SystemError, "Pygame bug (mixer.Sound): unknown mixer format %d", @@ -281,11 +275,7 @@ _pg_push_mixer_event(int type, int code) if (e) { pgEvent_FillUserEvent(e, &event); -#if IS_SDLv1 - if (SDL_PushEvent(&event) < 0) -#else if (SDL_PushEvent(&event) <= 0) -#endif Py_DECREF(dict); Py_DECREF(e); } @@ -355,9 +345,6 @@ _init(int freq, int size, int channels, int chunk, char *devicename, int allowed if (!channels) { channels = request_channels; } -#if IS_SDLv1 - channels = channels <= 1 ? 1 : 2; -#else /* IS_SDLv2 */ if (allowedchanges & SDL_AUDIO_ALLOW_CHANNELS_CHANGE) { if (channels <= 1) channels = 1; @@ -378,7 +365,6 @@ _init(int freq, int size, int channels, int chunk, char *devicename, int allowed return RAISE(PyExc_ValueError, "'channels' must be 1, 2, 4, or 6"); } } -#endif /* IS_SDLv2 */ if (!chunk) { chunk = request_chunksize; @@ -403,11 +389,9 @@ _init(int freq, int size, int channels, int chunk, char *devicename, int allowed case -16: fmt = AUDIO_S16SYS; break; -#if IS_SDLv2 case 32: fmt = AUDIO_F32SYS; break; -#endif default: PyErr_Format(PyExc_ValueError, "unsupported size %i", size); return NULL; @@ -435,7 +419,6 @@ _init(int freq, int size, int channels, int chunk, char *devicename, int allowed } } -#if IS_SDLv2 /* Compatibility: pulse and dsound audio drivers were renamed in SDL2, and we don't want it to fail. @@ -447,7 +430,6 @@ _init(int freq, int size, int channels, int chunk, char *devicename, int allowed else if (drivername && SDL_strncasecmp("dsound", drivername, SDL_strlen(drivername)) == 0) { SDL_setenv("SDL_AUDIODRIVER", "directsound", 1); } -#endif if (SDL_InitSubSystem(SDL_INIT_AUDIO)) return RAISE(pgExc_SDLError, SDL_GetError()); @@ -732,11 +714,9 @@ snd_get_length(PyObject *self, PyObject *args) Mix_QuerySpec(&freq, &format, &channels); if (format == AUDIO_S8 || format == AUDIO_U8) mixerbytes = 1; -#if IS_SDLv2 else if (format == AUDIO_F32 || format == AUDIO_F32LSB || format == AUDIO_F32MSB){ mixerbytes = 4; } -#endif else mixerbytes = 2; numsamples = chunk->alen / mixerbytes / channels; @@ -842,12 +822,10 @@ snd_buffer_iteminfo(char **format, Py_ssize_t *itemsize, int *channels) static char fmt_AUDIO_U16SYS[] = "=H"; static char fmt_AUDIO_S16SYS[] = "=h"; -#if IS_SDLv2 static char fmt_AUDIO_S32LSB[] = "dict); Py_DECREF(e); } diff --git a/src_c/pixelarray_methods.c b/src_c/pixelarray_methods.c index 0d02817092..10ec74cd7f 100644 --- a/src_c/pixelarray_methods.c +++ b/src_c/pixelarray_methods.c @@ -175,11 +175,7 @@ _make_surface(pgPixelArrayObject *array, PyObject *args) temp_surf = SDL_CreateRGBSurface(surf->flags, (int)dim0, (int)dim1, -#if IS_SDLv1 - bpp, -#else /* IS_SDLv2 */ surf->format->BitsPerPixel, -#endif /* IS_SDLv2 */ surf->format->Rmask, surf->format->Gmask, surf->format->Bmask, diff --git a/src_c/pixelcopy.c b/src_c/pixelcopy.c index 1521755ae2..9459c6eba1 100644 --- a/src_c/pixelcopy.c +++ b/src_c/pixelcopy.c @@ -23,19 +23,13 @@ #include #include "pygame.h" -#if IS_SDLv2 #include "palette.h" -#endif /* IS_SDLv2 */ #include "pgcompat.h" #include "doc/pixelcopy_doc.h" -#if IS_SDLv1 -#include -#else /* IS_SDLv2 */ #include -#endif /* IS_SDLv2 */ typedef enum { VIEWKIND_RED, @@ -259,11 +253,7 @@ _copy_colorplane(Py_buffer *view_p, SDL_Surface *surf, { SDL_PixelFormat *format = surf->format; int pixelsize = surf->format->BytesPerPixel; -#if IS_SDLv1 - Uint32 flags = surf->flags; -#else /* IS_SDLv2 */ SDL_BlendMode mode; -#endif /* IS_SDLv2 */ int intsize = (int)view_p->itemsize; char *src = (char *)surf->pixels; char *dst = (char *)view_p->buf; @@ -293,12 +283,10 @@ _copy_colorplane(Py_buffer *view_p, SDL_Surface *surf, intsize); return -1; } -#if IS_SDLv2 if (SDL_GetSurfaceBlendMode(surf, &mode) < 0) { PyErr_SetString(pgExc_SDLError, SDL_GetError()); return -1; } -#endif /* Select appropriate color plane element within the pixel */ switch (view_kind) { case VIEWKIND_RED: @@ -329,13 +317,8 @@ _copy_colorplane(Py_buffer *view_p, SDL_Surface *surf, dz_dst = -1; } #endif -#if IS_SDLv1 - if (view_kind == VIEWKIND_COLORKEY && flags & SDL_SRCCOLORKEY) { - colorkey = format->colorkey; -#else /* IS_SDLv2 */ if (view_kind == VIEWKIND_COLORKEY && SDL_GetColorKey(surf, &colorkey) == 0) { -#endif /* IS_SDLv2 */ for (x = 0; x < w; ++x) { for (y = 0; y < h; ++y) { for (z = 0; z < pixelsize; ++z) { @@ -349,13 +332,8 @@ _copy_colorplane(Py_buffer *view_p, SDL_Surface *surf, } } } -#if IS_SDLv1 - else if ((view_kind != VIEWKIND_COLORKEY) && - (view_kind != VIEWKIND_ALPHA || flags & SDL_SRCALPHA)) { -#else /* IS_SDLv2 */ else if ((view_kind != VIEWKIND_COLORKEY) && (view_kind != VIEWKIND_ALPHA || mode != SDL_BLENDMODE_NONE)) { -#endif /* IS_SDLv2 */ for (x = 0; x < w; ++x) { for (y = 0; y < h; ++y) { for (z = 0; z < pixelsize; ++z) { @@ -1164,15 +1142,9 @@ make_surface(PyObject *self, PyObject *arg) if (view_p->ndim == 2) { bitsperpixel = 8; -#if IS_SDLv1 - rmask = 0xFF >> 6 << 5; - gmask = 0xFF >> 5 << 2; - bmask = 0xFF >> 6; -#else /* IS_SDLv2 */ rmask = 0; gmask = 0; bmask = 0; -#endif /* IS_SDLv2 */ } else { bitsperpixel = 32; @@ -1189,7 +1161,6 @@ make_surface(PyObject *self, PyObject *arg) pgBuffer_Release(&pg_view); return RAISE(pgExc_SDLError, SDL_GetError()); } -#if IS_SDLv2 if (SDL_ISPIXELFORMAT_INDEXED(surf->format->format)) { /* Give the surface something other than an all white palette. * */ @@ -1200,7 +1171,6 @@ make_surface(PyObject *self, PyObject *arg) return 0; } } -#endif /* IS_SDLv2 */ surfobj = pgSurface_New(surf); if (!surfobj) { pgBuffer_Release(&pg_view); diff --git a/src_c/rect.c b/src_c/rect.c index b719b96ba1..4ac33d7702 100644 --- a/src_c/rect.c +++ b/src_c/rect.c @@ -50,7 +50,6 @@ static pgRectObject *pg_rect_freelist[PG_RECT_NUM]; int pg_rect_freelist_num = -1; #endif -#if IS_SDLv2 /* Helper method to extract 4 ints from an object. * * This sequence extraction supports the following formats: @@ -158,7 +157,6 @@ four_ints_from_obj(PyObject *obj, int *val1, int *val2, int *val3, int *val4) return 1; } -#endif /* IS_SDLv2 */ static PyObject * _pg_rect_subtype_new4(PyTypeObject *type, int x, int y, int w, int h) @@ -851,7 +849,6 @@ pg_rect_clip(pgRectObject *self, PyObject *args) return _pg_rect_subtype_new4(Py_TYPE(self), A->x, A->y, 0, 0); } -#if IS_SDLv2 /* clipline() - crops the given line within the rect * * Supported argument formats: @@ -958,7 +955,6 @@ pg_rect_clipline(pgRectObject *self, PyObject *args) Py_XDECREF(rect_copy); return Py_BuildValue("((ii)(ii))", x1, y1, x2, y2); } -#endif /* IS_SDLv2 */ static PyObject * pg_rect_contains(pgRectObject *self, PyObject *args) @@ -1091,10 +1087,8 @@ static struct PyMethodDef pg_rect_methods[] = { {"normalize", (PyCFunction)pg_rect_normalize, METH_NOARGS, DOC_RECTNORMALIZE}, {"clip", (PyCFunction)pg_rect_clip, METH_VARARGS, DOC_RECTCLIP}, -#if IS_SDLv2 {"clipline", (PyCFunction)pg_rect_clipline, METH_VARARGS, DOC_RECTCLIPLINE}, -#endif /* IS_SDLv2 */ {"clamp", (PyCFunction)pg_rect_clamp, METH_VARARGS, DOC_RECTCLAMP}, {"clamp_ip", (PyCFunction)pg_rect_clamp_ip, METH_VARARGS, DOC_RECTCLAMPIP}, {"copy", (PyCFunction)pg_rect_copy, METH_NOARGS, DOC_RECTCOPY}, diff --git a/src_c/rotozoom.c b/src_c/rotozoom.c index 52d116e30b..5f2030be47 100644 --- a/src_c/rotozoom.c +++ b/src_c/rotozoom.c @@ -606,11 +606,7 @@ rotozoomSurface(SDL_Surface *src, double angle, double zoom, int smooth) /* * Turn on source-alpha support */ -#if IS_SDLv1 - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); -#else /* IS_SDLv2 */ SDL_SetSurfaceAlphaMod(rz_dst, SDL_ALPHA_OPAQUE); -#endif /* IS_SDLv2 */ /* * Unlock source surface */ @@ -657,11 +653,7 @@ rotozoomSurface(SDL_Surface *src, double angle, double zoom, int smooth) /* * Turn on source-alpha support */ -#if IS_SDLv1 - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); -#else /* IS_SDLv2 */ SDL_SetSurfaceAlphaMod(rz_dst, SDL_ALPHA_OPAQUE); -#endif /* IS_SDLv2 */ /* * Unlock source surface */ diff --git a/src_c/rwobject.c b/src_c/rwobject.c index dea16d0214..6d0a0b4102 100644 --- a/src_c/rwobject.c +++ b/src_c/rwobject.c @@ -51,16 +51,6 @@ static PyObject* os_module = NULL; #define PATHLIB "pathlib" #define PUREPATH "PurePath" -#if IS_SDLv1 -static int -_pg_rw_seek(SDL_RWops *, int, int); -static int -_pg_rw_read(SDL_RWops *, void *, int, int); -static int -_pg_rw_write(SDL_RWops *, const void *, int, int); -static int -_pg_rw_close(SDL_RWops *); -#else /* IS_SDLv2 */ static Sint64 _pg_rw_size(SDL_RWops *); static Sint64 @@ -71,7 +61,6 @@ static size_t _pg_rw_write(SDL_RWops *, const void *, size_t, size_t); static int _pg_rw_close(SDL_RWops *); -#endif /* IS_SDLv2 */ /* Converter function used by PyArg_ParseTupleAndKeywords with the "O&" format. * @@ -323,7 +312,6 @@ pgRWops_GetFileExtension(SDL_RWops* rw) } } -#if IS_SDLv2 static Sint64 _pg_rw_size(SDL_RWops *context) { @@ -396,15 +384,9 @@ _pg_rw_size(SDL_RWops *context) #endif return retval; } -#endif /* IS_SDLv2 */ -#if IS_SDLv1 -static int -_pg_rw_write(SDL_RWops *context, const void *ptr, int size, int num) -#else /* IS_SDLv2 */ static size_t _pg_rw_write(SDL_RWops *context, const void *ptr, size_t size, size_t num) -#endif /* IS_SDLv2 */ { #ifndef WITH_THREAD pgRWHelper *helper = (pgRWHelper *)context->hidden.unknown.data1; @@ -517,9 +499,7 @@ pgRWops_FromFileObject(PyObject *obj) * RWops from actual files use this space to store the file extension * for later use */ rw->hidden.unknown.data1 = (void *)helper; -#if IS_SDLv2 rw->size = _pg_rw_size; -#endif /* IS_SDLv2 */ rw->seek = _pg_rw_seek; rw->read = _pg_rw_read; rw->write = _pg_rw_write; @@ -582,21 +562,12 @@ pgRWops_ReleaseObject(SDL_RWops *context) return ret; } -#if IS_SDLv1 -static int -_pg_rw_seek(SDL_RWops *context, int offset, int whence) -{ - pgRWHelper *helper = (pgRWHelper *)context->hidden.unknown.data1; - PyObject *result; - int retval; -#else /* IS_SDLv2 */ static Sint64 _pg_rw_seek(SDL_RWops *context, Sint64 offset, int whence) { pgRWHelper *helper = (pgRWHelper *)context->hidden.unknown.data1; PyObject *result; Sint64 retval; -#endif /* IS_SDLv2 */ #ifdef WITH_THREAD PyGILState_STATE state; @@ -670,21 +641,12 @@ _pg_rw_seek(SDL_RWops *context, Sint64 offset, int whence) #endif /* ~WITH_THREAD*/ } -#if IS_SDLv1 -static int -_pg_rw_read(SDL_RWops *context, void *ptr, int size, int maxnum) -{ - pgRWHelper *helper = (pgRWHelper *)context->hidden.unknown.data1; - PyObject *result; - int retval; -#else /* IS_SDLv2 */ static size_t _pg_rw_read(SDL_RWops *context, void *ptr, size_t size, size_t maxnum) { pgRWHelper *helper = (pgRWHelper *)context->hidden.unknown.data1; PyObject *result; Py_ssize_t retval; -#endif /* IS_SDLv2 */ #ifdef WITH_THREAD PyGILState_STATE state; #endif /* WITH_THREAD */ diff --git a/src_c/surface.c b/src_c/surface.c index fe1795e58c..ace27e462a 100644 --- a/src_c/surface.c +++ b/src_c/surface.c @@ -25,9 +25,7 @@ #include "surface.h" -#if IS_SDLv2 #include "palette.h" -#endif /* IS_SDLv2 */ #include "structmember.h" #include "pgcompat.h" @@ -107,17 +105,10 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj, SDL_Rect *dstrect, SDL_Rect *srcrect, int the_args); /* statics */ -#if IS_SDLv1 -static PyObject * -pgSurface_New(SDL_Surface *info); -static PyObject * -surf_subtype_new(PyTypeObject *type, SDL_Surface *s); -#else /* IS_SDLv2 */ static PyObject * pgSurface_New(SDL_Surface *info, int owner); static PyObject * surf_subtype_new(PyTypeObject *type, SDL_Surface *s, int owner); -#endif /* IS_SDLv2 */ static PyObject * surface_new(PyTypeObject *type, PyObject *args, PyObject *kwds); static intptr_t @@ -168,10 +159,8 @@ static PyObject * surf_set_alpha(pgSurfaceObject *self, PyObject *args); static PyObject * surf_get_alpha(pgSurfaceObject *self, PyObject *args); -#if IS_SDLv2 static PyObject * surf_get_blendmode(PyObject *self, PyObject *args); -#endif /* IS_SDLv2 */ static PyObject * surf_copy(pgSurfaceObject *self, PyObject *args); static PyObject * @@ -261,7 +250,6 @@ static void _release_buffer(Py_buffer *view_p); static PyObject * _raise_get_view_ndim_error(int bitsize, SurfViewKind kind); -#if IS_SDLv2 static PyObject * _raise_create_surface_error(void); static SDL_Surface * @@ -269,9 +257,8 @@ pg_DisplayFormatAlpha(SDL_Surface *surface); static SDL_Surface * pg_DisplayFormat(SDL_Surface *surface); static int _PgSurface_SrcAlpha(SDL_Surface *surf); -#endif /* IS_SDLv2 */ -#if IS_SDLv2 && !SDL_VERSION_ATLEAST(2, 0, 10) +#if !SDL_VERSION_ATLEAST(2, 0, 10) static Uint32 pg_map_rgb(SDL_Surface *surf, Uint8 r, Uint8 g, Uint8 b) { @@ -338,10 +325,8 @@ static struct PyMethodDef surface_methods[] = { DOC_SURFACESETALPHA}, {"get_alpha", (PyCFunction)surf_get_alpha, METH_NOARGS, DOC_SURFACEGETALPHA}, -#if IS_SDLv2 {"get_blendmode", surf_get_blendmode, METH_NOARGS, "Return the surface's SDL 2 blend mode"}, -#endif /* IS_SDLv2 */ {"copy", (PyCFunction)surf_copy, METH_NOARGS, DOC_SURFACECOPY}, {"__copy__", (PyCFunction)surf_copy, METH_NOARGS, DOC_SURFACECOPY}, @@ -436,15 +421,6 @@ static PyTypeObject pgSurface_Type = { #define pgSurface_Check(x) \ (PyObject_IsInstance((x), (PyObject *)&pgSurface_Type)) -#if IS_SDLv1 - -static PyObject * -pgSurface_New(SDL_Surface *s) -{ - return surf_subtype_new(&pgSurface_Type, s); -} - -#else /* IS_SDLv2 */ static PyObject * pgSurface_New(SDL_Surface *s, int owner) @@ -452,44 +428,28 @@ pgSurface_New(SDL_Surface *s, int owner) return surf_subtype_new(&pgSurface_Type, s, owner); } -#endif /* IS_SDLv2 */ -#if IS_SDLv1 -static int -pgSurface_SetSurface(pgSurfaceObject *self, SDL_Surface *s) -#else /* IS_SDLv2 */ static int pgSurface_SetSurface(pgSurfaceObject *self, SDL_Surface *s, int owner) -#endif /* IS_SDLv2 */ { if (!s) { PyErr_SetString(pgExc_SDLError, SDL_GetError()); return -1; } if (s == self->surf) { -#if IS_SDLv2 self->owner = owner; -#endif return 0; } surface_cleanup(self); self->surf = s; -#if IS_SDLv2 self->owner = owner; -#endif return 0; } -#if IS_SDLv1 - -static PyObject * -surf_subtype_new(PyTypeObject *type, SDL_Surface *s) -#else /* IS_SDLv2 */ static PyObject * surf_subtype_new(PyTypeObject *type, SDL_Surface *s, int owner) -#endif /* IS_SDLv2 */ { pgSurfaceObject *self; @@ -498,13 +458,8 @@ surf_subtype_new(PyTypeObject *type, SDL_Surface *s, int owner) self = (pgSurfaceObject *)pgSurface_Type.tp_new(type, NULL, NULL); -#if IS_SDLv2 if (pgSurface_SetSurface(self, s, owner)) return NULL; -#else /* IS_SDLv1 */ - if (pgSurface_SetSurface(self, s)) - return NULL; -#endif /* IS_SDLv1 */ return (PyObject *)self; } @@ -517,9 +472,7 @@ surface_new(PyTypeObject *type, PyObject *args, PyObject *kwds) self = (pgSurfaceObject *)type->tp_alloc(type, 0); if (self) { self->surf = NULL; -#if IS_SDLv2 self->owner = 0; -#endif /* IS_SDLv2 */ self->subsurface = NULL; self->weakreflist = NULL; self->dependency = NULL; @@ -532,22 +485,10 @@ surface_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static void surface_cleanup(pgSurfaceObject *self) { -#if IS_SDLv1 - if (self->surf) { - if (!(self->surf->flags & SDL_HWSURFACE) || - SDL_WasInit(SDL_INIT_VIDEO)) { - /* unsafe to free hardware surfaces without video init */ - /* i question SDL's ability to free a locked hardware surface */ - SDL_FreeSurface(self->surf); - } - self->surf = NULL; - } -#else /* IS_SDLv2 */ if (self->surf && self->owner) { SDL_FreeSurface(self->surf); self->surf = NULL; } -#endif /* IS_SDLv2 */ if (self->subsurface) { Py_XDECREF(self->subsurface->owner); PyMem_Del(self->subsurface); @@ -562,9 +503,7 @@ surface_cleanup(pgSurfaceObject *self) Py_DECREF(self->locklist); self->locklist = NULL; } -#if IS_SDLv2 self->owner = 0; -#endif /* IS_SDLv2 */ } static void @@ -585,14 +524,8 @@ surface_str(PyObject *self) return Text_FromUTF8(""); } -#if IS_SDLv1 - return Text_FromFormat("", surf->w, surf->h, - surf->format->BitsPerPixel, - (surf->flags & SDL_HWSURFACE) ? "HW" : "SW"); -#else /* IS_SDLv2 */ return Text_FromFormat("", surf->w, surf->h, surf->format->BitsPerPixel); -#endif /* IS_SDLv2 */ } static intptr_t @@ -631,9 +564,7 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) } -#if IS_SDLv2 default_format.palette = NULL; -#endif /* IS_SDLv2 */ surface_cleanup(self); @@ -669,11 +600,7 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) "invalid bits per pixel depth argument"); return -1; } -#if IS_SDLv1 - if (flags & SDL_SRCALPHA) { -#else /* IS_SDLv2 */ if (flags & PGS_SRCALPHA) { -#endif /* IS_SDLv2 */ switch (bpp) { case 16: Rmask = 0xF << 8; @@ -699,15 +626,9 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) Amask = 0; switch (bpp) { case 8: -#if IS_SDLv1 - Rmask = 0xFF >> 6 << 5; - Gmask = 0xFF >> 5 << 2; - Bmask = 0xFF >> 6; -#else /* IS_SDLv2 */ Rmask = 0; Gmask = 0; Bmask = 0; -#endif /* IS_SDLv2 */ break; case 12: Rmask = 0xFF >> 4 << 8; @@ -741,15 +662,8 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) SDL_PixelFormat *pix; if (depth && pgSurface_Check(depth)) pix = ((pgSurfaceObject *)depth)->surf->format; -#if IS_SDLv1 - else if (SDL_GetVideoSurface()) - pix = SDL_GetVideoSurface()->format; - else if (SDL_WasInit(SDL_INIT_VIDEO)) - pix = SDL_GetVideoInfo()->vfmt; -#else /* IS_SDLv2 */ else if (pg_GetDefaultWindowSurface()) pix = pgSurface_AsSurface(pg_GetDefaultWindowSurface())->format; -#endif /* IS_SDLv2 */ else { pix = &default_format; pix->BitsPerPixel = 32; @@ -760,11 +674,7 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) } bpp = pix->BitsPerPixel; -#if IS_SDLv1 - if (flags & SDL_SRCALPHA) { -#else /* IS_SDLv2 */ if (flags & PGS_SRCALPHA) { -#endif /* IS_SDLv2 */ switch (bpp) { case 16: Rmask = 0xF << 8; @@ -798,41 +708,6 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) } } -#if IS_SDLv1 - surface = SDL_CreateRGBSurface(flags, width, height, bpp, Rmask, Gmask, - Bmask, Amask); - if (!surface) { - PyErr_SetString(pgExc_SDLError, SDL_GetError()); - return -1; - } - - if (masks) { - /* Confirm the surface was created correctly (masks were valid). - Also ensure that 24 and 32 bit surfaces have 8 bit fields - (no losses). - */ - SDL_PixelFormat *format = surface->format; - Rmask = (0xFF >> format->Rloss) << format->Rshift; - Gmask = (0xFF >> format->Gloss) << format->Gshift; - Bmask = (0xFF >> format->Bloss) << format->Bshift; - Amask = (0xFF >> format->Aloss) << format->Ashift; - if (format->Rmask != Rmask || format->Gmask != Gmask || - format->Bmask != Bmask || format->Amask != Amask || - (format->BytesPerPixel >= 3 && - (format->Rloss || format->Gloss || format->Bloss || - ((surface->flags & SDL_SRCALPHA) ? format->Aloss - : format->Aloss != 8)))) { - SDL_FreeSurface(surface); - PyErr_SetString(PyExc_ValueError, "Invalid mask values"); - return -1; - } - } - - if (surface) { - self->surf = surface; - self->subsurface = NULL; - } -#else /* IS_SDLv2 */ surface = SDL_CreateRGBSurface(0, width, height, bpp, Rmask, Gmask, Bmask, Amask); if (!surface) { @@ -861,12 +736,10 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds) self->owner = 1; self->subsurface = NULL; } -#endif /* IS_SDLv2 */ return 0; } -#if IS_SDLv2 static PyObject * _raise_create_surface_error(void) { @@ -876,7 +749,6 @@ _raise_create_surface_error(void) return RAISE(PyExc_ValueError, "Invalid mask values"); return RAISE(pgExc_SDLError, msg); } -#endif /* IS_SDLv2 */ /* surface object methods */ static PyObject * @@ -888,21 +760,13 @@ surf_get_at(PyObject *self, PyObject *args) int x, y; Uint32 color; Uint8 *pix; -#if IS_SDLv1 - Uint8 rgba[4]; -#else /* IS_SDLv2 */ Uint8 rgba[4] = {0, 0, 0, 255}; -#endif /* IS_SDLv2 */ if (!PyArg_ParseTuple(args, "(ii)", &x, &y)) return NULL; if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ if (x < 0 || x >= surf->w || y < 0 || y >= surf->h) return RAISE(PyExc_IndexError, "pixel index out of range"); @@ -918,25 +782,6 @@ surf_get_at(PyObject *self, PyObject *args) pixels = (Uint8 *)surf->pixels; switch (format->BytesPerPixel) { -#if IS_SDLv1 - case 1: - color = (Uint32) * ((Uint8 *)pixels + y * surf->pitch + x); - break; - case 2: - color = (Uint32) * ((Uint16 *)(pixels + y * surf->pitch) + x); - break; - case 3: - pix = ((Uint8 *)(pixels + y * surf->pitch) + x * 3); -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - color = (pix[0]) + (pix[1] << 8) + (pix[2] << 16); -#else - color = (pix[2]) + (pix[1] << 8) + (pix[0] << 16); -#endif - break; - default: /* case 4: */ - color = *((Uint32 *)(pixels + y * surf->pitch) + x); - break; -#else /* IS_SDLv2 */ case 1: color = (Uint32) * ((Uint8 *)pixels + y * surf->pitch + x); SDL_GetRGB(color, format, rgba, rgba + 1, rgba + 2); @@ -959,14 +804,10 @@ surf_get_at(PyObject *self, PyObject *args) color = *((Uint32 *)(pixels + y * surf->pitch) + x); SDL_GetRGBA(color, format, rgba, rgba + 1, rgba + 2, rgba + 3); break; -#endif /* IS_SDLv2 */ } if (!pgSurface_Unlock((pgSurfaceObject *)self)) return NULL; -#if IS_SDLv1 - SDL_GetRGBA(color, format, rgba, rgba + 1, rgba + 2, rgba + 3); -#endif /* IS_SDLv1 */ return pgColor_New(rgba); } @@ -987,10 +828,6 @@ surf_set_at(PyObject *self, PyObject *args) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ format = surf->format; @@ -1072,10 +909,6 @@ surf_get_at_mapped(PyObject *self, PyObject *args) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ if (x < 0 || x >= surf->w || y < 0 || y >= surf->h) return RAISE(PyExc_IndexError, "pixel index out of range"); @@ -1146,16 +979,12 @@ surf_unmap_rgb(PyObject *self, PyObject *arg) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - SDL_GetRGBA(col, surf->format, rgba, rgba + 1, rgba + 2, rgba + 3); -#else /* IS_SDLv2 */ if (SDL_ISPIXELFORMAT_ALPHA(surf->format->format)) SDL_GetRGBA(col, surf->format, rgba, rgba + 1, rgba + 2, rgba + 3); else { SDL_GetRGB(col, surf->format, rgba, rgba + 1, rgba + 2); rgba[3] = 255; } -#endif /* IS_SDLv2 */ return pgColor_New(rgba); } @@ -1288,7 +1117,6 @@ surf_get_palette_at(PyObject *self, PyObject *args) static PyObject * surf_set_palette(PyObject *self, PyObject *args) { -#if IS_SDLv2 /* This method works differently from the SDL 1.2 equivalent. * It replaces colors in the surface's existing palette. So, if the * color list is shorter than the existing palette, only the first @@ -1297,9 +1125,6 @@ surf_set_palette(PyObject *self, PyObject *args) */ const SDL_Color *old_colors; SDL_Color colors[256]; -#else /* IS_SDLv1 */ - SDL_Color *colors; -#endif /* IS_SDLv1 */ SDL_Surface *surf = pgSurface_AsSurface(self); SDL_Palette *pal = NULL; PyObject *list, *item; @@ -1316,17 +1141,12 @@ surf_set_palette(PyObject *self, PyObject *args) pal = surf->format->palette; -#if IS_SDLv2 if (!SDL_ISPIXELFORMAT_INDEXED(surf->format->format)) return RAISE(pgExc_SDLError, "Surface colors are not indexed\n"); if (!pal) return RAISE(pgExc_SDLError, "Surface is not palettitized\n"); old_colors = pal->colors; -#else /* IS_SDLv1 */ - if (!pal) - return RAISE(pgExc_SDLError, "Surface has no palette\n"); -#endif /* IS_SDLv1 */ if (!SDL_WasInit(SDL_INIT_VIDEO)) return RAISE(pgExc_SDLError, @@ -1334,13 +1154,6 @@ surf_set_palette(PyObject *self, PyObject *args) len = MIN(pal->ncolors, PySequence_Length(list)); -#if IS_SDLv1 - colors = (SDL_Color *)malloc(len * sizeof(SDL_Color)); - if (!colors) { - PyErr_NoMemory(); - return NULL; - } -#endif /* IS_SDLv1 */ for (i = 0; i < len; i++) { item = PySequence_GetItem(list, i); @@ -1348,38 +1161,25 @@ surf_set_palette(PyObject *self, PyObject *args) ecode = pg_RGBAFromObj(item, rgba); Py_DECREF(item); if (!ecode) { -#if IS_SDLv1 - free(colors); -#endif /* IS_SDLv1 */ return RAISE(PyExc_ValueError, "takes a sequence of integers of RGB"); } if (rgba[3] != 255) { -#if IS_SDLv1 - free(colors); -#endif /* IS_SDLv1 */ return RAISE(PyExc_ValueError, "takes an alpha value of 255"); } colors[i].r = (unsigned char)rgba[0]; colors[i].g = (unsigned char)rgba[1]; colors[i].b = (unsigned char)rgba[2]; -#if IS_SDLv2 /* Preserve palette alphas. Normally, a palette entry has alpha 255. * If, however, colorkey is set, the corresponding palette entry has * 0 alpha. */ colors[i].a = (unsigned char)old_colors[i].a; -#endif /* IS_SDLv2 */ } -#if IS_SDLv1 - SDL_SetColors(surf, colors, 0, len); - free(colors); -#else /* IS_SDLv2 */ ecode = SDL_SetPaletteColors(pal, colors, 0, len); if (ecode != 0) return RAISE(pgExc_SDLError, SDL_GetError()); -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } @@ -1403,10 +1203,8 @@ surf_set_palette_at(PyObject *self, PyObject *args) "takes a sequence of integers of RGB for argument 2"); } -#if IS_SDLv2 if (!SDL_ISPIXELFORMAT_INDEXED(surf->format->format)) return RAISE(pgExc_SDLError, "Surface colors are not indexed\n"); -#endif /* IS_SDLv2 */ pal = surf->format->palette; @@ -1424,13 +1222,6 @@ surf_set_palette_at(PyObject *self, PyObject *args) return RAISE(pgExc_SDLError, "cannot set palette without pygame.display initialized"); -#if IS_SDLv1 - color.r = rgba[0]; - color.g = rgba[1]; - color.b = rgba[2]; - - SDL_SetColors(surf, &color, _index, 1); -#else /* IS_SDLv2 */ color.r = rgba[0]; color.g = rgba[1]; color.b = rgba[2]; @@ -1438,7 +1229,6 @@ surf_set_palette_at(PyObject *self, PyObject *args) if (SDL_SetPaletteColors(pal, &color, _index, 1) != 0) return RAISE(pgExc_SDLError, SDL_GetError()); -#endif /* IS_SDLv2 */ Py_RETURN_NONE; } @@ -1459,10 +1249,6 @@ surf_set_colorkey(pgSurfaceObject *self, PyObject *args) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ if (rgba_obj && rgba_obj != Py_None) { if (PyInt_Check(rgba_obj)) { @@ -1476,29 +1262,17 @@ surf_set_colorkey(pgSurfaceObject *self, PyObject *args) return RAISE(PyExc_TypeError, "invalid color argument"); } else if (pg_RGBAFromFuzzyColorObj(rgba_obj, rgba)) { -#if IS_SDLv1 - color = - SDL_MapRGBA(surf->format, rgba[0], rgba[1], rgba[2], rgba[3]); -#else /* IS_SDLv2 */ if (SDL_ISPIXELFORMAT_ALPHA(surf->format->format)) color = pg_map_rgba(surf, rgba[0], rgba[1], rgba[2], rgba[3]); else color = pg_map_rgb(surf, rgba[0], rgba[1], rgba[2]); -#endif /* IS_SDLv2 */ } else return NULL; /* pg_RGBAFromFuzzyColorObj set an exception for us */ hascolor = SDL_TRUE; } -#if IS_SDLv1 - if (hascolor) - flags |= SDL_SRCCOLORKEY; -#endif /* IS_SDLv1 */ pgSurface_Prep(self); -#if IS_SDLv1 - result = SDL_SetColorKey(surf, flags, color); -#else /* IS_SDLv2 */ result = 0; if (hascolor && bpp == 1) { @@ -1513,7 +1287,6 @@ surf_set_colorkey(pgSurfaceObject *self, PyObject *args) if (result == 0) { result = SDL_SetColorKey(surf, hascolor, color); } -#endif /* IS_SDLv2 */ pgSurface_Unprep(self); if (result == -1) @@ -1526,26 +1299,12 @@ static PyObject * surf_get_colorkey(pgSurfaceObject *self, PyObject *args) { SDL_Surface *surf = pgSurface_AsSurface(self); -#if IS_SDLv1 - Uint8 r, g, b, a; -#else /* IS_SDLv2 */ Uint32 mapped_color; Uint8 r, g, b, a = 255; -#endif /* IS_SDLv2 */ if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); - - if (!(surf->flags & SDL_SRCCOLORKEY)) { - Py_RETURN_NONE; - } - - SDL_GetRGBA(surf->format->colorkey, surf->format, &r, &g, &b, &a); -#else /* IS_SDLv2 */ if (SDL_GetColorKey(surf, &mapped_color) != 0) { SDL_ClearError(); Py_RETURN_NONE; @@ -1555,62 +1314,11 @@ surf_get_colorkey(pgSurfaceObject *self, PyObject *args) SDL_GetRGBA(mapped_color, surf->format, &r, &g, &b, &a); else SDL_GetRGB(mapped_color, surf->format, &r, &g, &b); -#endif /* IS_SDLv2 */ return Py_BuildValue("(bbbb)", r, g, b, a); } -#if IS_SDLv1 -static PyObject * -surf_set_alpha(pgSurfaceObject *self, PyObject *args) -{ - SDL_Surface *surf = pgSurface_AsSurface(self); - Uint32 flags = 0; - PyObject *alpha_obj = NULL, *intobj = NULL; - Uint8 alpha; - int result, alphaval = 255; - int hasalpha = 0; - - if (!PyArg_ParseTuple(args, "|Oi", &alpha_obj, &flags)) - return NULL; - if (!surf) - return RAISE(pgExc_SDLError, "display Surface quit"); - if (alpha_obj && alpha_obj != Py_None) { - if (PyNumber_Check(alpha_obj) && (intobj = PyNumber_Int(alpha_obj))) { - if (PyInt_Check(intobj)) { - alphaval = (int)PyInt_AsLong(intobj); - Py_DECREF(intobj); - } - else - return RAISE(PyExc_TypeError, "invalid alpha argument"); - } - else - return RAISE(PyExc_TypeError, "invalid alpha argument"); - hasalpha = 1; - } - if (hasalpha) - flags |= SDL_SRCALPHA; - - if (alphaval > 255) - alpha = 255; - else if (alphaval < 0) - alpha = 0; - else - alpha = (Uint8)alphaval; - - pgSurface_Prep(self); - result = SDL_SetAlpha(surf, flags, alpha); - pgSurface_Unprep(self); - - if (result == -1) - return RAISE(pgExc_SDLError, SDL_GetError()); - - Py_RETURN_NONE; -} -#endif /* IS_SDLv2 */ - -#if IS_SDLv2 static PyObject * surf_set_alpha(pgSurfaceObject *self, PyObject *args) { @@ -1692,31 +1400,18 @@ surf_set_alpha(pgSurfaceObject *self, PyObject *args) Py_RETURN_NONE; } -#endif /* IS_SDLv2 */ static PyObject * surf_get_alpha(pgSurfaceObject *self, PyObject *args) { SDL_Surface *surf = pgSurface_AsSurface(self); -#if IS_SDLv2 SDL_BlendMode mode; Uint8 alpha; -#endif /* IS_SDLv2 */ if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ - -#if IS_SDLv1 - if (surf->flags & SDL_SRCALPHA) - return PyInt_FromLong(surf->format->alpha); - Py_RETURN_NONE; -#else /* IS_SDLv2 */ if (SDL_GetSurfaceBlendMode(surf, &mode) != 0) return RAISE(pgExc_SDLError, SDL_GetError()); @@ -1727,10 +1422,8 @@ surf_get_alpha(pgSurfaceObject *self, PyObject *args) return RAISE(pgExc_SDLError, SDL_GetError()); return PyInt_FromLong(alpha); -#endif /* IS_SDLv2 */ } -#if IS_SDLv2 static PyObject * surf_get_blendmode(PyObject *self, PyObject *args) @@ -1742,7 +1435,6 @@ surf_get_blendmode(PyObject *self, PyObject *args) return RAISE(pgExc_SDLError, SDL_GetError()); return PyInt_FromLong((long)mode); } -#endif /* IS_SDLv2 */ static PyObject * surf_copy(pgSurfaceObject *self, PyObject *args) @@ -1754,26 +1446,12 @@ surf_copy(pgSurfaceObject *self, PyObject *args) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot copy opengl display"); -#endif /* IS_SDLv1 */ pgSurface_Prep(self); -#if IS_SDLv1 - newsurf = SDL_ConvertSurface(surf, surf->format, surf->flags); - if (surf->flags & SDL_SRCALPHA) - newsurf->format->alpha = surf->format->alpha; -#else newsurf = SDL_ConvertSurface(surf, surf->format, 0); -#endif pgSurface_Unprep(self); -#if IS_SDLv1 - final = surf_subtype_new(Py_TYPE(self), newsurf); -#else /* IS_SDLv2 */ final = surf_subtype_new(Py_TYPE(self), newsurf, 1); -#endif /* IS_SDLv2 */ if (!final) SDL_FreeSurface(newsurf); return final; @@ -1789,12 +1467,10 @@ surf_convert(pgSurfaceObject *self, PyObject *args) SDL_Surface *newsurf; Uint32 flags = UINT32_MAX; -#if IS_SDLv2 Uint32 colorkey; Uint8 key_r, key_g, key_b, key_a = 255; int has_colorkey = SDL_FALSE; -#endif /* IS_SDLv2 */ if (!SDL_WasInit(SDL_INIT_VIDEO)) return RAISE(pgExc_SDLError, @@ -1803,14 +1479,9 @@ surf_convert(pgSurfaceObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "|Oi", &argobject, &flags)) return NULL; -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot convert opengl display"); -#endif /* IS_SDLv1 */ pgSurface_Prep(self); -#if IS_SDLv2 if (SDL_GetColorKey(surf, &colorkey) == 0) { has_colorkey = SDL_TRUE; if (SDL_ISPIXELFORMAT_ALPHA(surf->format->format)) @@ -1819,18 +1490,11 @@ surf_convert(pgSurfaceObject *self, PyObject *args) else SDL_GetRGB(colorkey, surf->format, &key_r, &key_g, &key_b); } -#endif if (argobject) { if (pgSurface_Check(argobject)) { src = pgSurface_AsSurface(argobject); -#if IS_SDLv1 - flags = - src->flags | (surf->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA)); - newsurf = SDL_ConvertSurface(surf, src->format, flags); -#else /* IS_SDLv2 */ newsurf = SDL_ConvertSurface(surf, src->format, 0); -#endif /* IS_SDLv2 */ } else { int bpp; @@ -1840,11 +1504,7 @@ surf_convert(pgSurfaceObject *self, PyObject *args) if (pg_IntFromObj(argobject, &bpp)) { Uint32 Rmask, Gmask, Bmask, Amask; -#if IS_SDLv1 - if (flags != UINT32_MAX && flags & SDL_SRCALPHA) { -#else /* IS_SDLv2 */ if (flags != UINT32_MAX && flags & PGS_SRCALPHA) { -#endif /* IS_SDLv2 */ switch (bpp) { case 16: Rmask = 0xF << 8; @@ -1868,15 +1528,9 @@ surf_convert(pgSurfaceObject *self, PyObject *args) Amask = 0; switch (bpp) { case 8: -#if IS_SDLv1 - Rmask = 0xFF >> 6 << 5; - Gmask = 0xFF >> 5 << 2; - Bmask = 0xFF >> 6; -#else /* IS_SDLv2 */ Rmask = 0; Gmask = 0; Bmask = 0; -#endif /* IS_SDLv2 */ break; case 12: Rmask = 0xFF >> 4 << 8; @@ -1943,23 +1597,10 @@ surf_convert(pgSurfaceObject *self, PyObject *args) * that at least one entry is not black. */ format.palette = NULL; -#if IS_SDLv1 - if (flags == UINT32_MAX) - flags = surf->flags; - if (format.Amask) - flags |= SDL_SRCALPHA; - newsurf = SDL_ConvertSurface(surf, &format, flags); -#else /* IS_SDLv2 */ newsurf = SDL_ConvertSurface(surf, &format, 0); SDL_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ } } -#if IS_SDLv1 - else { - newsurf = SDL_DisplayFormat(surf); - } -#else /* IS_SDLv2 */ else { newsurf = pg_DisplayFormat(surf); SDL_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_NONE); @@ -1974,20 +1615,14 @@ surf_convert(pgSurfaceObject *self, PyObject *args) } } -#endif /* IS_SDLv2 */ pgSurface_Unprep(self); -#if IS_SDLv1 - final = surf_subtype_new(Py_TYPE(self), newsurf); -#else /* IS_SDLv2 */ final = surf_subtype_new(Py_TYPE(self), newsurf, 1); -#endif /* IS_SDLv2 */ if (!final) SDL_FreeSurface(newsurf); return final; } -#if IS_SDLv2 static SDL_Surface * pg_DisplayFormat(SDL_Surface *surface) { @@ -2052,7 +1687,6 @@ pg_DisplayFormatAlpha(SDL_Surface *surface) } return SDL_ConvertSurfaceFormat(surface, pfe, 0); } -#endif /* IS_SDLv2 */ static PyObject * surf_convert_alpha(pgSurfaceObject *self, PyObject *args) @@ -2061,9 +1695,6 @@ surf_convert_alpha(pgSurfaceObject *self, PyObject *args) PyObject *final; pgSurfaceObject *srcsurf = NULL; SDL_Surface *newsurf; -#if IS_SDLv1 - SDL_Surface *src; -#endif if (!SDL_WasInit(SDL_INIT_VIDEO)) return RAISE(pgExc_SDLError, @@ -2074,7 +1705,6 @@ surf_convert_alpha(pgSurfaceObject *self, PyObject *args) #pragma PG_WARN("srcsurf doesn't actually do anything?") -#if IS_SDLv2 /*if (!srcsurf) {}*/ /* * hmm, we have to figure this out, not all depths have good @@ -2083,22 +1713,6 @@ surf_convert_alpha(pgSurfaceObject *self, PyObject *args) newsurf = pg_DisplayFormatAlpha(surf); SDL_SetSurfaceBlendMode(newsurf, SDL_BLENDMODE_BLEND); final = surf_subtype_new(Py_TYPE(self), newsurf, 1); -#else /* IS_SDLv1 */ - pgSurface_Prep(self); - if (srcsurf) { - /* - * hmm, we have to figure this out, not all depths have good - * support for alpha - */ - src = pgSurface_AsSurface(srcsurf); - newsurf = SDL_DisplayFormatAlpha(surf); - } - else - newsurf = SDL_DisplayFormatAlpha(surf); - pgSurface_Unprep(self); - - final = surf_subtype_new(Py_TYPE(self), newsurf); -#endif /* IS_SDLv1 */ if (!final) SDL_FreeSurface(newsurf); @@ -2173,10 +1787,6 @@ surf_fill(pgSurfaceObject *self, PyObject *args, PyObject *keywds) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ if (PyInt_Check(rgba_obj)) color = (Uint32)PyInt_AsLong(rgba_obj); @@ -2261,9 +1871,6 @@ surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds) pgSurfaceObject *srcobject; int dx, dy, result; SDL_Rect dest_rect; -#if IS_SDLv1 - SDL_Rect sdlsrc_rect; -#endif /* IS_SDLv1 */ int sx, sy; int the_args = 0; @@ -2277,12 +1884,6 @@ surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds) if (!dest || !src) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (dest->flags & SDL_OPENGL && - !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) - return RAISE(pgExc_SDLError, - "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)"); -#endif /* IS_SDLv1 */ if ((src_rect = pgRect_FromObject(argpos, &temp))) { dx = src_rect->x; @@ -2306,31 +1907,15 @@ surf_blit(pgSurfaceObject *self, PyObject *args, PyObject *keywds) src_rect = &temp; } -#if IS_SDLv1 - dest_rect.x = (short)dx; - dest_rect.y = (short)dy; - dest_rect.w = (unsigned short)src_rect->w; - dest_rect.h = (unsigned short)src_rect->h; - sdlsrc_rect.x = (short)src_rect->x; - sdlsrc_rect.y = (short)src_rect->y; - sdlsrc_rect.w = (unsigned short)src_rect->w; - sdlsrc_rect.h = (unsigned short)src_rect->h; -#else /* IS_SDLv2 */ dest_rect.x = dx; dest_rect.y = dy; dest_rect.w = src_rect->w; dest_rect.h = src_rect->h; -#endif /* IS_SDLv2 */ if (!the_args) the_args = 0; -#if IS_SDLv1 - result = - pgSurface_Blit(self, srcobject, &dest_rect, &sdlsrc_rect, the_args); -#else /* IS_SDLv2 */ result = pgSurface_Blit(self, srcobject, &dest_rect, src_rect, the_args); -#endif /* IS_SDLv2 */ if (result != 0) return NULL; @@ -2357,9 +1942,6 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds) PyObject *srcobject = NULL, *argpos = NULL, *argrect = NULL; int dx, dy, result; SDL_Rect dest_rect; -#if IS_SDLv1 - SDL_Rect sdlsrc_rect; -#endif /* IS_SDLv1 */ int sx, sy; int the_args = 0; @@ -2444,13 +2026,6 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds) goto bliterror; } -#if IS_SDLv1 - if (dest->flags & SDL_OPENGL && - !(dest->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) { - bliterrornum = BLITS_ERR_NO_OPENGL_SURF; - goto bliterror; - } -#endif /* IS_SDLv1 */ if ((src_rect = pgRect_FromObject(argpos, &temp))) { dx = src_rect->x; @@ -2477,21 +2052,10 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds) src_rect = &temp; } -#if IS_SDLv1 - dest_rect.x = (short)dx; - dest_rect.y = (short)dy; - dest_rect.w = (unsigned short)src_rect->w; - dest_rect.h = (unsigned short)src_rect->h; - sdlsrc_rect.x = (short)src_rect->x; - sdlsrc_rect.y = (short)src_rect->y; - sdlsrc_rect.w = (unsigned short)src_rect->w; - sdlsrc_rect.h = (unsigned short)src_rect->h; -#else /* IS_SDLv2 */ dest_rect.x = dx; dest_rect.y = dy; dest_rect.w = src_rect->w; dest_rect.h = src_rect->h; -#endif /* IS_SDLv2 */ if (special_flags) { if (!pg_IntFromObj(special_flags, &the_args)) { @@ -2500,13 +2064,8 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds) } } -#if IS_SDLv1 - result = pgSurface_Blit(self, (pgSurfaceObject *)srcobject, &dest_rect, - &sdlsrc_rect, the_args); -#else /* IS_SDLv2 */ result = pgSurface_Blit(self, (pgSurfaceObject *)srcobject, &dest_rect, src_rect, the_args); -#endif /* IS_SDLv2 */ if (result != 0) { bliterrornum = BLITS_ERR_BLIT_FAIL; @@ -2567,11 +2126,6 @@ surf_blits(pgSurfaceObject *self, PyObject *args, PyObject *keywds) case BLITS_ERR_SEQUENCE_SURF: return RAISE(PyExc_TypeError, "First element of blit_list needs to be Surface."); -#if IS_SDLv1 - case BLITS_ERR_NO_OPENGL_SURF: - return RAISE(pgExc_SDLError, - "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)"); -#endif /* IS_SDLv1 */ case BLITS_ERR_INVALID_DESTINATION: return RAISE(PyExc_TypeError, "invalid destination position for blit"); @@ -2610,13 +2164,6 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds) return RAISE(pgExc_SDLError, "display Surface quit"); } -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL && - !(surf->flags & (SDL_OPENGLBLIT & ~SDL_OPENGL))) { - return RAISE(pgExc_SDLError, - "Cannot scroll an OPENGL Surfaces (OPENGLBLIT is ok)"); - } -#endif /* IS_SDLv1 */ if (dx == 0 && dy == 0) { Py_RETURN_NONE; @@ -2670,13 +2217,6 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds) Py_RETURN_NONE; } -#if IS_SDLv1 -int -pg_HasSurfaceRLE(SDL_Surface * surface) -{ - return SDL_FALSE; -} -#else /* IS_SDLv2 */ int pg_HasSurfaceRLE(SDL_Surface * surface) { @@ -2706,27 +2246,21 @@ _PgSurface_SrcAlpha(SDL_Surface *surf) } return (mode != SDL_BLENDMODE_NONE); } -#endif /* IS_SDLv2 */ static PyObject * surf_get_flags(PyObject *self, PyObject *args) { -#if IS_SDLv2 Uint32 sdl_flags = 0; Uint32 window_flags = 0; Uint32 flags = 0; int is_alpha; int is_window_surf = 0; SDL_Window *win = pg_GetDefaultWindow(); -#endif /* IS_SDLv2 */ SDL_Surface *surf = pgSurface_AsSurface(self); if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - return PyInt_FromLong((long)surf->flags); -#else /* IS_SDLv2 */ if (win && pg_GetDefaultWindowSurface()) { if (surf == pgSurface_AsSurface(pg_GetDefaultWindowSurface())) @@ -2763,7 +2297,6 @@ surf_get_flags(PyObject *self, PyObject *args) } return PyInt_FromLong((long)flags); -#endif /* IS_SDLv2 */ } static PyObject * @@ -2877,16 +2410,7 @@ surf_set_masks(PyObject *self, PyObject *args) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv2 return RAISE(PyExc_TypeError, "The surface masks are read-only in SDL2"); -#else /* IS_SDLv1 */ - surf->format->Rmask = (Uint32)r; - surf->format->Gmask = (Uint32)g; - surf->format->Bmask = (Uint32)b; - surf->format->Amask = (Uint32)a; - - Py_RETURN_NONE; -#endif /* IS_SDLv1 */ } static PyObject * @@ -2911,16 +2435,7 @@ surf_set_shifts(PyObject *self, PyObject *args) if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv2 return RAISE(PyExc_TypeError, "The surface shifts are read-only in SDL2"); -#else /* IS_SDLv1 */ - surf->format->Rshift = (Uint8)r; - surf->format->Gshift = (Uint8)g; - surf->format->Bshift = (Uint8)b; - surf->format->Ashift = (Uint8)a; - - Py_RETURN_NONE; -#endif /* IS_SDLv1 */ } static PyObject * @@ -2945,18 +2460,12 @@ surf_subsurface(PyObject *self, PyObject *args) int pixeloffset; char *startpixel; struct pgSubSurface_Data *data; -#if IS_SDLv2 Uint8 alpha; Uint32 colorkey; int ecode; -#endif /* IS_SDLv2 */ if (!surf) return RAISE(pgExc_SDLError, "display Surface quit"); -#if IS_SDLv1 - if (surf->flags & SDL_OPENGL) - return RAISE(pgExc_SDLError, "Cannot call on OPENGL Surfaces"); -#endif /* IS_SDLv1 */ format = surf->format; if (!(rect = pgRect_FromObject(args, &temp))) @@ -2977,20 +2486,6 @@ surf_subsurface(PyObject *self, PyObject *args) pgSurface_Unlock((pgSurfaceObject *)self); -#if IS_SDLv1 - if (!sub) - return RAISE(pgExc_SDLError, SDL_GetError()); - - /* copy the colormap if we need it */ - if (surf->format->BytesPerPixel == 1 && surf->format->palette) - SDL_SetPalette(sub, SDL_LOGPAL, surf->format->palette->colors, 0, - surf->format->palette->ncolors); - if (surf->flags & SDL_SRCALPHA) - SDL_SetAlpha(sub, surf->flags & SDL_SRCALPHA, format->alpha); - if (surf->flags & SDL_SRCCOLORKEY) - SDL_SetColorKey(sub, surf->flags & (SDL_SRCCOLORKEY | SDL_RLEACCEL), - format->colorkey); -#else /* IS_SDLv2 */ if (!sub) return _raise_create_surface_error(); @@ -3047,17 +2542,12 @@ surf_subsurface(PyObject *self, PyObject *args) SDL_FreeSurface(sub); return NULL; } -#endif /* IS_SDLv2 */ data = PyMem_New(struct pgSubSurface_Data, 1); if (!data) return NULL; -#if IS_SDLv1 - subobj = surf_subtype_new(Py_TYPE(self), sub); -#else /* IS_SDLv2 */ subobj = surf_subtype_new(Py_TYPE(self), sub, 1); -#endif /* IS_SDLv2 */ if (!subobj) { PyMem_Del(data); return NULL; @@ -3185,9 +2675,7 @@ surf_get_bounding_rect(PyObject *self, PyObject *args, PyObject *kwargs) Uint32 value; Uint8 r, g, b, a; int has_colorkey = 0; -#if IS_SDLv2 Uint32 colorkey; -#endif /* IS_SDLv2 */ Uint8 keyr, keyg, keyb; char *kwids[] = {"min_alpha", NULL}; @@ -3204,18 +2692,10 @@ surf_get_bounding_rect(PyObject *self, PyObject *args, PyObject *kwargs) format = surf->format; -#if IS_SDLv1 - if (surf->flags & SDL_SRCCOLORKEY) { - has_colorkey = 1; - SDL_GetRGBA(surf->format->colorkey, surf->format, &keyr, &keyg, &keyb, - &a); - } -#else /* IS_SDLv2 */ if (SDL_GetColorKey(surf, &colorkey) == 0) { has_colorkey = 1; SDL_GetRGBA(colorkey, surf->format, &keyr, &keyg, &keyb, &a); } -#endif /* IS_SDLv2 */ pixels = (Uint8 *)surf->pixels; min_y = 0; @@ -4110,17 +3590,10 @@ surface_do_overlap(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, return 0; } -#if IS_SDLv1 - srcpixels = ((Uint8 *)src->pixels + src->offset + srcy * src->pitch + - srcx * src->format->BytesPerPixel); - dstpixels = ((Uint8 *)dst->pixels + src->offset + dsty * dst->pitch + - dstx * dst->format->BytesPerPixel); -#else /* IS_SDLv2 */ srcpixels = ((Uint8 *)src->pixels + srcy * src->pitch + srcx * src->format->BytesPerPixel); dstpixels = ((Uint8 *)dst->pixels + dsty * dst->pitch + dstx * dst->format->BytesPerPixel); -#endif /* IS_SDLv2 */ if (dstpixels <= srcpixels) { return 0; @@ -4147,10 +3620,8 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj, SDL_Surface *subsurface = NULL; int result, suboffsetx = 0, suboffsety = 0; SDL_Rect orig_clip, sub_clip; -#if IS_SDLv2 Uint8 alpha; Uint32 key; -#endif /* IS_SDLv2 */ /* passthrough blits to the real surface */ if (((pgSurfaceObject *)dstobj)->subsurface) { @@ -4187,71 +3658,6 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj, pgSurface_Prep(srcobj); -#if IS_SDLv1 - /* This test fails if this first condition is not used. - File "test/surface_test.py", in test_pixel_alpha - */ - if (dst->format->Amask && (dst->flags & SDL_SRCALPHA) && - !(src->format->Amask && !(src->flags & SDL_SRCALPHA)) && - /* special case, SDL works */ - (dst->format->BytesPerPixel == 2 || dst->format->BytesPerPixel == 4)) { - /* Py_BEGIN_ALLOW_THREADS */ - result = pygame_AlphaBlit(src, srcrect, dst, dstrect, the_args); - /* Py_END_ALLOW_THREADS */ - } - else if (the_args != 0 || - (src->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY) && - /* This simplification is possible because a source subsurface - is converted to its owner with a clip rect and a dst - subsurface cannot be blitted to its owner because the - owner is locked. - */ - dst->pixels == src->pixels && - surface_do_overlap(src, srcrect, dst, dstrect))) { - /* Py_BEGIN_ALLOW_THREADS */ - result = pygame_Blit(src, srcrect, dst, dstrect, the_args); - /* Py_END_ALLOW_THREADS */ - } - /* can't blit alpha to 8bit, crashes SDL */ - else if (dst->format->BytesPerPixel == 1 && - (src->format->Amask || src->flags & SDL_SRCALPHA)) { - /* Py_BEGIN_ALLOW_THREADS */ - if (src->format->BytesPerPixel == 1) { - result = pygame_Blit(src, srcrect, dst, dstrect, 0); - } - else { - SDL_PixelFormat *fmt = src->format; - SDL_PixelFormat newfmt; - - newfmt.palette = 0; /* Set NULL (or SDL gets confused) */ - newfmt.BitsPerPixel = fmt->BitsPerPixel; - newfmt.BytesPerPixel = fmt->BytesPerPixel; - newfmt.Amask = 0; - newfmt.Rmask = fmt->Rmask; - newfmt.Gmask = fmt->Gmask; - newfmt.Bmask = fmt->Bmask; - newfmt.Ashift = 0; - newfmt.Rshift = fmt->Rshift; - newfmt.Gshift = fmt->Gshift; - newfmt.Bshift = fmt->Bshift; - newfmt.Aloss = 0; - newfmt.Rloss = fmt->Rloss; - newfmt.Gloss = fmt->Gloss; - newfmt.Bloss = fmt->Bloss; - newfmt.colorkey = 0; - newfmt.alpha = 0; - src = SDL_ConvertSurface(src, &newfmt, SDL_SWSURFACE); - if (src) { - result = SDL_BlitSurface(src, srcrect, dst, dstrect); - SDL_FreeSurface(src); - } - else { - result = -1; - } - } - /* Py_END_ALLOW_THREADS */ - } -#else /* IS_SDLv2 */ if ((the_args != 0 && the_args != PYGAME_BLEND_ALPHA_SDL2) || ((SDL_GetColorKey(src, &key) == 0 || _PgSurface_SrcAlpha(src) == 1) && /* This simplification is possible because a source subsurface @@ -4318,7 +3724,6 @@ pgSurface_Blit(pgSurfaceObject *dstobj, pgSurfaceObject *srcobj, behaved */ result = pygame_Blit(src, srcrect, dst, dstrect, the_args); } -#endif /* IS_SDLv2 */ else { /* Py_BEGIN_ALLOW_THREADS */ result = SDL_BlitSurface(src, srcrect, dst, dstrect); diff --git a/src_c/surface_fill.c b/src_c/surface_fill.c index e98a5f3e6d..e616b47030 100644 --- a/src_c/surface_fill.c +++ b/src_c/surface_fill.c @@ -90,20 +90,12 @@ surface_fill_blend_add(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint32 pixel; Uint32 tmp; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -184,20 +176,12 @@ surface_fill_blend_sub(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint32 pixel; Sint32 tmp2; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -277,20 +261,12 @@ surface_fill_blend_mult(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint8 sR, sG, sB, sA, cR, cG, cB, cA; Uint32 pixel; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -370,20 +346,12 @@ surface_fill_blend_min(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint8 sR, sG, sB, sA, cR, cG, cB, cA; Uint32 pixel; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -463,20 +431,12 @@ surface_fill_blend_max(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint8 sR, sG, sB, sA, cR, cG, cB, cA; Uint32 pixel; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -559,24 +519,16 @@ surface_fill_blend_rgba_add(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint32 pixel; Uint32 tmp; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ if (!ppa) { return surface_fill_blend_add(surface, rect, color); } -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -636,24 +588,16 @@ surface_fill_blend_rgba_sub(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint32 pixel; Sint32 tmp2; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ if (!ppa) { return surface_fill_blend_sub(surface, rect, color); } -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -713,24 +657,16 @@ surface_fill_blend_rgba_mult(SDL_Surface *surface, SDL_Rect *rect, Uint8 sR, sG, sB, sA, cR, cG, cB, cA; Uint32 pixel; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ if (!ppa) { return surface_fill_blend_mult(surface, rect, color); } -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -789,24 +725,16 @@ surface_fill_blend_rgba_min(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint8 sR, sG, sB, sA, cR, cG, cB, cA; Uint32 pixel; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ if (!ppa) { return surface_fill_blend_min(surface, rect, color); } -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; @@ -865,24 +793,16 @@ surface_fill_blend_rgba_max(SDL_Surface *surface, SDL_Rect *rect, Uint32 color) Uint8 sR, sG, sB, sA, cR, cG, cB, cA; Uint32 pixel; int result = -1; -#if IS_SDLv1 - int ppa = (surface->flags & SDL_SRCALPHA && fmt->Amask); -#else /* IS_SDLv2 */ int ppa; SDL_BlendMode mode; SDL_GetSurfaceBlendMode(surface, &mode); ppa = (fmt->Amask && mode != SDL_BLENDMODE_NONE); -#endif /* IS_SDLv2 */ if (!ppa) { return surface_fill_blend_max(surface, rect, color); } -#if IS_SDLv1 - pixels = (Uint8 *)surface->pixels + surface->offset + -#else /* IS_SDLv2 */ pixels = (Uint8 *)surface->pixels + -#endif /* IS_SDLv2 */ (Uint16)rect->y * surface->pitch + (Uint16)rect->x * bpp; skip = surface->pitch - width * bpp; diff --git a/src_c/time.c b/src_c/time.c index c554a93b2c..f3ca3031be 100644 --- a/src_c/time.c +++ b/src_c/time.c @@ -175,11 +175,7 @@ timer_callback(Uint32 interval, void *param) if (SDL_WasInit(SDL_INIT_VIDEO)) { pgEvent_FillUserEvent(evtimer->event, &event); -#if IS_SDLv1 - if (SDL_PushEvent(&event) < 0) -#else if (SDL_PushEvent(&event) <= 0) -#endif Py_DECREF(evtimer->event->dict); } else diff --git a/src_c/transform.c b/src_c/transform.c index 49453549a0..c250f9fe75 100644 --- a/src_c/transform.c +++ b/src_c/transform.c @@ -78,7 +78,6 @@ extern SDL_Surface * rotozoomSurface(SDL_Surface *src, double angle, double zoom, int smooth); -#if IS_SDLv2 static int _PgSurface_SrcAlpha(SDL_Surface *surf) { @@ -100,7 +99,6 @@ _PgSurface_SrcAlpha(SDL_Surface *surf) } return 0; } -#endif /* IS_SDLv2 */ @@ -108,11 +106,9 @@ static SDL_Surface * newsurf_fromsurf(SDL_Surface *surf, int width, int height) { SDL_Surface *newsurf; -#if IS_SDLv2 Uint32 colorkey; Uint8 alpha; int isalpha; -#endif /* IS_SDLv2 */ if (surf->format->BytesPerPixel == 0 || surf->format->BytesPerPixel > 4) return (SDL_Surface *)(RAISE( @@ -126,21 +122,6 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height) return (SDL_Surface *)(RAISE(pgExc_SDLError, SDL_GetError())); /* Copy palette, colorkey, etc info */ -#if IS_SDLv1 - if (surf->format->BytesPerPixel == 1 && surf->format->palette) - SDL_SetColors(newsurf, surf->format->palette->colors, 0, - surf->format->palette->ncolors); - if (surf->flags & SDL_SRCCOLORKEY) - SDL_SetColorKey(newsurf, - (surf->flags & SDL_RLEACCEL) | SDL_SRCCOLORKEY, - surf->format->colorkey); - - if (surf->flags & SDL_SRCALPHA) { - int result = SDL_SetAlpha(newsurf, surf->flags, surf->format->alpha); - if (result == -1) - return (SDL_Surface *)(RAISE(pgExc_SDLError, SDL_GetError())); - } -#else /* IS_SDLv2 */ if (SDL_ISPIXELFORMAT_INDEXED(surf->format->format)) { if (SDL_SetPaletteColors(newsurf->format->palette, surf->format->palette->colors, 0, @@ -192,7 +173,6 @@ newsurf_fromsurf(SDL_Surface *surf, int width, int height) } } -#endif /* IS_SDLv2 */ return newsurf; } @@ -703,13 +683,7 @@ surf_rotate(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; /* get the background color */ -#if IS_SDLv1 - if (surf->flags & SDL_SRCCOLORKEY) - bgcolor = surf->format->colorkey; - else -#else /* IS_SDLv2 */ if (SDL_GetColorKey(surf, &bgcolor) != 0) -#endif /* IS_SDLv2 */ { SDL_LockSurface(surf); switch (surf->format->BytesPerPixel) {