SDL_blit: use a named enum for required hardware features bits in dispatch tables SDL-1.2
authorBen Avison <bavison@riscosopen.org>
Thu, 31 Oct 2019 14:00:28 +0300
branchSDL-1.2
changeset 1321584aa936d90e4
parent 13214 78d5c2b67346
child 13216 eb0ed9be8a68
SDL_blit: use a named enum for required hardware features bits in dispatch tables
---
src/video/SDL_blit_N.c | 47 ++++++++++++++++++++++++------------------
1 file changed, 27 insertions(+), 20 deletions(-)
src/video/SDL_blit_N.c
     1.1 --- a/src/video/SDL_blit_N.c	Thu Oct 31 14:00:28 2019 +0300
     1.2 +++ b/src/video/SDL_blit_N.c	Thu Oct 31 14:00:28 2019 +0300
     1.3 @@ -28,6 +28,12 @@
     1.4  
     1.5  /* Functions to blit from N-bit surfaces to other surfaces */
     1.6  
     1.7 +enum blit_features {
     1.8 +	BLIT_FEATURE_HAS_MMX = 1,
     1.9 +	BLIT_FEATURE_HAS_ALTIVEC = 2,
    1.10 +	BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH = 4
    1.11 +};
    1.12 +
    1.13  #if SDL_ALTIVEC_BLITTERS
    1.14  #if __MWERKS__
    1.15  #pragma altivec_model on
    1.16 @@ -858,24 +864,25 @@
    1.17      vec_dss(DST_CHAN_DEST);
    1.18  }
    1.19  
    1.20 -static Uint32 GetBlitFeatures( void )
    1.21 +static enum blit_features GetBlitFeatures( void )
    1.22  {
    1.23 -    static Uint32 features = 0xffffffff;
    1.24 -    if (features == 0xffffffff) {
    1.25 +    static enum blit_features features = -1;
    1.26 +    if (features == (enum blit_features) -1) {
    1.27          /* Provide an override for testing .. */
    1.28          char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
    1.29          if (override) {
    1.30 -            features = 0;
    1.31 -            SDL_sscanf(override, "%u", &features);
    1.32 +            unsigned int features_as_uint = 0;
    1.33 +            SDL_sscanf(override, "%u", &features_as_uint);
    1.34 +            features = (enum blit_features) features_as_uint;
    1.35          } else {
    1.36              features = ( 0
    1.37                  /* Feature 1 is has-MMX */
    1.38 -                | ((SDL_HasMMX()) ? 1 : 0)
    1.39 +                | ((SDL_HasMMX()) ? BLIT_FEATURE_HAS_MMX : 0)
    1.40                  /* Feature 2 is has-AltiVec */
    1.41 -                | ((SDL_HasAltiVec()) ? 2 : 0)
    1.42 +                | ((SDL_HasAltiVec()) ? BLIT_FEATURE_HAS_ALTIVEC : 0)
    1.43                  /* Feature 4 is dont-use-prefetch */
    1.44                  /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
    1.45 -                | ((GetL3CacheSize() == 0) ? 4 : 0)
    1.46 +                | ((GetL3CacheSize() == 0) ? BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH : 0)
    1.47              );
    1.48          }
    1.49      }
    1.50 @@ -886,7 +893,7 @@
    1.51  #endif
    1.52  #else
    1.53  /* Feature 1 is has-MMX */
    1.54 -#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
    1.55 +#define GetBlitFeatures() (SDL_HasMMX() ? BLIT_FEATURE_HAS_MMX : 0)
    1.56  #endif
    1.57  
    1.58  /* This is now endian dependent */
    1.59 @@ -2346,7 +2353,7 @@
    1.60  	Uint32 srcR, srcG, srcB;
    1.61  	int dstbpp;
    1.62  	Uint32 dstR, dstG, dstB;
    1.63 -	Uint32 blit_features;
    1.64 +	enum blit_features blit_features;
    1.65  	void *aux_data;
    1.66  	SDL_loblit blitfunc;
    1.67  	enum { NO_ALPHA=1, SET_ALPHA=2, COPY_ALPHA=4 } alpha;
    1.68 @@ -2366,9 +2373,9 @@
    1.69  #elif SDL_ALTIVEC_BLITTERS
    1.70      /* has-altivec */
    1.71      { 0x0000F800,0x000007E0,0x0000001F, 4, 0x00000000,0x00000000,0x00000000,
    1.72 -      2, NULL, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
    1.73 +      BLIT_FEATURE_HAS_ALTIVEC, NULL, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
    1.74      { 0x00007C00,0x000003E0,0x0000001F, 4, 0x00000000,0x00000000,0x00000000,
    1.75 -      2, NULL, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
    1.76 +      BLIT_FEATURE_HAS_ALTIVEC, NULL, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
    1.77  #endif
    1.78      { 0x0000F800,0x000007E0,0x0000001F, 4, 0x00FF0000,0x0000FF00,0x000000FF,
    1.79        0, NULL, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
    1.80 @@ -2389,23 +2396,23 @@
    1.81  static const struct blit_table normal_blit_4[] = {
    1.82  #if SDL_HERMES_BLITTERS
    1.83      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
    1.84 -      1, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA },
    1.85 +      BLIT_FEATURE_HAS_MMX, ConvertMMXpII32_16RGB565, ConvertMMX, NO_ALPHA },
    1.86      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
    1.87        0, ConvertX86p32_16RGB565, ConvertX86, NO_ALPHA },
    1.88      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000007E0,0x0000F800,
    1.89 -      1, ConvertMMXpII32_16BGR565, ConvertMMX, NO_ALPHA },
    1.90 +      BLIT_FEATURE_HAS_MMX, ConvertMMXpII32_16BGR565, ConvertMMX, NO_ALPHA },
    1.91      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000007E0,0x0000F800,
    1.92        0, ConvertX86p32_16BGR565, ConvertX86, NO_ALPHA },
    1.93      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x00007C00,0x000003E0,0x0000001F,
    1.94 -      1, ConvertMMXpII32_16RGB555, ConvertMMX, NO_ALPHA },
    1.95 +      BLIT_FEATURE_HAS_MMX, ConvertMMXpII32_16RGB555, ConvertMMX, NO_ALPHA },
    1.96      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x00007C00,0x000003E0,0x0000001F,
    1.97        0, ConvertX86p32_16RGB555, ConvertX86, NO_ALPHA },
    1.98      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000003E0,0x00007C00,
    1.99 -      1, ConvertMMXpII32_16BGR555, ConvertMMX, NO_ALPHA },
   1.100 +      BLIT_FEATURE_HAS_MMX, ConvertMMXpII32_16BGR555, ConvertMMX, NO_ALPHA },
   1.101      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000001F,0x000003E0,0x00007C00,
   1.102        0, ConvertX86p32_16BGR555, ConvertX86, NO_ALPHA },
   1.103      { 0x00FF0000,0x0000FF00,0x000000FF, 3, 0x00FF0000,0x0000FF00,0x000000FF,
   1.104 -      1, ConvertMMXpII32_24RGB888, ConvertMMX, NO_ALPHA },
   1.105 +      BLIT_FEATURE_HAS_MMX, ConvertMMXpII32_24RGB888, ConvertMMX, NO_ALPHA },
   1.106      { 0x00FF0000,0x0000FF00,0x000000FF, 3, 0x00FF0000,0x0000FF00,0x000000FF,
   1.107        0, ConvertX86p32_24RGB888, ConvertX86, NO_ALPHA },
   1.108      { 0x00FF0000,0x0000FF00,0x000000FF, 3, 0x000000FF,0x0000FF00,0x00FF0000,
   1.109 @@ -2420,13 +2427,13 @@
   1.110  #if SDL_ALTIVEC_BLITTERS
   1.111      /* has-altivec | dont-use-prefetch */
   1.112      { 0x00000000,0x00000000,0x00000000, 4, 0x00000000,0x00000000,0x00000000,
   1.113 -      6, NULL, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
   1.114 +      BLIT_FEATURE_HAS_ALTIVEC | BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH, NULL, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
   1.115      /* has-altivec */
   1.116      { 0x00000000,0x00000000,0x00000000, 4, 0x00000000,0x00000000,0x00000000,
   1.117 -      2, NULL, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
   1.118 +      BLIT_FEATURE_HAS_ALTIVEC, NULL, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
   1.119      /* has-altivec */
   1.120      { 0x00000000,0x00000000,0x00000000, 2, 0x0000F800,0x000007E0,0x0000001F,
   1.121 -      2, NULL, Blit_RGB888_RGB565Altivec, NO_ALPHA },
   1.122 +      BLIT_FEATURE_HAS_ALTIVEC, NULL, Blit_RGB888_RGB565Altivec, NO_ALPHA },
   1.123  #endif
   1.124      { 0x00FF0000,0x0000FF00,0x000000FF, 2, 0x0000F800,0x000007E0,0x0000001F,
   1.125        0, NULL, Blit_RGB888_RGB565, NO_ALPHA },