Add SDL_MEMALIGNED flag for SDL_Surface using aligned memory.
authorSylvain Becker <sylvain.becker@gmail.com>
Thu, 31 Jan 2019 11:45:31 +0100
changeset 12587b2d4dcb4ba33
parent 12586 eb449394ec0e
child 12588 1fc2169984ad
Add SDL_MEMALIGNED flag for SDL_Surface using aligned memory.

If an SDL_Surface has an aligned memory pointers, it should be freed
using SDL_SIMDFree() (will be used by SDL_ttf).
include/SDL_surface.h
src/video/SDL_surface.c
     1.1 --- a/include/SDL_surface.h	Wed Jan 30 22:50:20 2019 +0100
     1.2 +++ b/include/SDL_surface.h	Thu Jan 31 11:45:31 2019 +0100
     1.3 @@ -53,6 +53,7 @@
     1.4  #define SDL_PREALLOC        0x00000001  /**< Surface uses preallocated memory */
     1.5  #define SDL_RLEACCEL        0x00000002  /**< Surface is RLE encoded */
     1.6  #define SDL_DONTFREE        0x00000004  /**< Surface is referenced internally */
     1.7 +#define SDL_MEMALIGNED      0x00000008  /**< Surface uses aligned memory */
     1.8  /* @} *//* Surface flags */
     1.9  
    1.10  /**
     2.1 --- a/src/video/SDL_surface.c	Wed Jan 30 22:50:20 2019 +0100
     2.2 +++ b/src/video/SDL_surface.c	Thu Jan 31 11:45:31 2019 +0100
     2.3 @@ -26,6 +26,7 @@
     2.4  #include "SDL_RLEaccel_c.h"
     2.5  #include "SDL_pixels_c.h"
     2.6  #include "SDL_yuv_c.h"
     2.7 +#include "../../cpuinfo/SDL_simd.h"
     2.8  
     2.9  
    2.10  /* Check to make sure we can safely check multiplication of surface w and pitch and it won't overflow size_t */
    2.11 @@ -289,7 +290,7 @@
    2.12          return SDL_FALSE;
    2.13      }
    2.14  
    2.15 -	return SDL_TRUE;
    2.16 +    return SDL_TRUE;
    2.17  }
    2.18  
    2.19  int
    2.20 @@ -1258,7 +1259,13 @@
    2.21          SDL_FreeFormat(surface->format);
    2.22          surface->format = NULL;
    2.23      }
    2.24 -    if (!(surface->flags & SDL_PREALLOC)) {
    2.25 +    if (surface->flags & SDL_PREALLOC) {
    2.26 +        /* Don't free */
    2.27 +    } else if (surface->flags & SDL_MEMALIGNED) {
    2.28 +        /* Free aligned */
    2.29 +        SDL_SIMDFree(surface->pixels);
    2.30 +    } else {
    2.31 +        /* Normal */
    2.32          SDL_free(surface->pixels);
    2.33      }
    2.34      if (surface->map) {