Browse Source

Removed SDL_PROP_SURFACE_COLORSPACE_NUMBER

Now that we have surface internal data, we can store it there. This slightly improves performance in the surface blitting paths.
Sam Lantinga 1 year ago
parent
commit
c040a02d6c

+ 0 - 6
include/SDL3/SDL_surface.h

@@ -186,11 +186,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
  *
  *
  * The following properties are understood by SDL:
  * The following properties are understood by SDL:
  *
  *
- * - `SDL_PROP_SURFACE_COLORSPACE_NUMBER`: an SDL_ColorSpace value describing
- *   the surface colorspace, defaults to SDL_COLORSPACE_SRGB_LINEAR for
- *   floating point formats, SDL_COLORSPACE_HDR10 for 10-bit formats,
- *   SDL_COLORSPACE_SRGB for other RGB surfaces and SDL_COLORSPACE_BT709_FULL
- *   for YUV surfaces.
  * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  * - `SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT`: for HDR10 and floating point
  *   surfaces, this defines the value of 100% diffuse white, with higher
  *   surfaces, this defines the value of 100% diffuse white, with higher
  *   values being displayed in the High Dynamic Range headroom. This defaults
  *   values being displayed in the High Dynamic Range headroom. This defaults
@@ -214,7 +209,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySurface(SDL_Surface *surface);
  */
  */
 extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
 extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surface *surface);
 
 
-#define SDL_PROP_SURFACE_COLORSPACE_NUMBER                  "SDL.surface.colorspace"
 #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT              "SDL.surface.SDR_white_point"
 #define SDL_PROP_SURFACE_SDR_WHITE_POINT_FLOAT              "SDL.surface.SDR_white_point"
 #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT                 "SDL.surface.HDR_headroom"
 #define SDL_PROP_SURFACE_HDR_HEADROOM_FLOAT                 "SDL.surface.HDR_headroom"
 #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING            "SDL.surface.tonemap"
 #define SDL_PROP_SURFACE_TONEMAP_OPERATOR_STRING            "SDL.surface.tonemap"

+ 2 - 9
src/video/SDL_blit.c

@@ -181,15 +181,8 @@ int SDL_CalculateBlit(SDL_Surface *surface)
     SDL_BlitFunc blit = NULL;
     SDL_BlitFunc blit = NULL;
     SDL_BlitMap *map = &surface->internal->map;
     SDL_BlitMap *map = &surface->internal->map;
     SDL_Surface *dst = map->dst;
     SDL_Surface *dst = map->dst;
-    SDL_Colorspace src_colorspace = SDL_GetSurfaceColorspace(surface);
-    SDL_Colorspace dst_colorspace = SDL_GetSurfaceColorspace(dst);
-
-    if (src_colorspace == SDL_COLORSPACE_UNKNOWN) {
-        return -1;
-    }
-    if (dst_colorspace == SDL_COLORSPACE_UNKNOWN) {
-        return -1;
-    }
+    SDL_Colorspace src_colorspace = surface->internal->colorspace;
+    SDL_Colorspace dst_colorspace = dst->internal->colorspace;
 
 
     /* We don't currently support blitting to < 8 bpp surfaces */
     /* We don't currently support blitting to < 8 bpp surfaces */
     if (SDL_BITSPERPIXEL(dst->format) < 8) {
     if (SDL_BITSPERPIXEL(dst->format) < 8) {

+ 2 - 6
src/video/SDL_blit_slow.c

@@ -837,12 +837,8 @@ void SDL_Blit_Slow_Float(SDL_BlitInfo *info)
     float src_headroom;
     float src_headroom;
     SDL_TonemapContext tonemap;
     SDL_TonemapContext tonemap;
 
 
-    src_colorspace = SDL_GetSurfaceColorspace(info->src_surface);
-    dst_colorspace = SDL_GetSurfaceColorspace(info->dst_surface);
-    if (src_colorspace == SDL_COLORSPACE_UNKNOWN ||
-        dst_colorspace == SDL_COLORSPACE_UNKNOWN) {
-        return;
-    }
+    src_colorspace = info->src_surface->internal->colorspace;
+    dst_colorspace = info->dst_surface->internal->colorspace;
     src_primaries = SDL_COLORSPACEPRIMARIES(src_colorspace);
     src_primaries = SDL_COLORSPACEPRIMARIES(src_colorspace);
     dst_primaries = SDL_COLORSPACEPRIMARIES(dst_colorspace);
     dst_primaries = SDL_COLORSPACEPRIMARIES(dst_colorspace);
 
 

+ 2 - 3
src/video/SDL_stretch.c

@@ -44,7 +44,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
 
 
     if (src->format != dst->format) {
     if (src->format != dst->format) {
         // Slow!
         // Slow!
-        SDL_Surface *src_tmp = SDL_ConvertSurfaceAndColorspace(src, dst->format, dst->internal->palette, SDL_GetSurfaceColorspace(dst), dst->internal->props);
+        SDL_Surface *src_tmp = SDL_ConvertSurfaceAndColorspace(src, dst->format, dst->internal->palette, dst->internal->colorspace, dst->internal->props);
         if (!src_tmp) {
         if (!src_tmp) {
             return -1;
             return -1;
         }
         }
@@ -68,11 +68,10 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
         if (src_tmp && dst_tmp) {
         if (src_tmp && dst_tmp) {
             ret = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode);
             ret = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode);
             if (ret == 0) {
             if (ret == 0) {
-                SDL_Colorspace dst_colorspace = SDL_GetSurfaceColorspace(dst);
                 SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h,
                 SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h,
                     dst_tmp->format, SDL_COLORSPACE_SRGB, 0,
                     dst_tmp->format, SDL_COLORSPACE_SRGB, 0,
                     dst_tmp->pixels, dst_tmp->pitch,
                     dst_tmp->pixels, dst_tmp->pitch,
-                    dst->format, dst_colorspace, SDL_GetSurfaceProperties(dst),
+                    dst->format, dst->internal->colorspace, SDL_GetSurfaceProperties(dst),
                     (Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch);
                     (Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch);
             }
             }
         } else {
         } else {

+ 16 - 25
src/video/SDL_surface.c

@@ -158,9 +158,10 @@ static SDL_Surface *SDL_InitializeSurface(SDL_InternalSurface *mem, int width, i
     surface->internal->map.info.b = 0xFF;
     surface->internal->map.info.b = 0xFF;
     surface->internal->map.info.a = 0xFF;
     surface->internal->map.info.a = 0xFF;
 
 
-    if (colorspace != SDL_COLORSPACE_UNKNOWN &&
-        colorspace != SDL_GetDefaultColorspaceForFormat(format)) {
-        SDL_SetSurfaceColorspace(surface, colorspace);
+    if (colorspace == SDL_COLORSPACE_UNKNOWN) {
+        surface->internal->colorspace = SDL_GetDefaultColorspaceForFormat(format);
+    } else {
+        surface->internal->colorspace = colorspace;
     }
     }
 
 
     if (props) {
     if (props) {
@@ -289,25 +290,17 @@ int SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace)
         return SDL_InvalidParamError("surface");
         return SDL_InvalidParamError("surface");
     }
     }
 
 
-    if (colorspace == SDL_GetDefaultColorspaceForFormat(surface->format)) {
-        return 0;
-    }
-    return SDL_SetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROP_SURFACE_COLORSPACE_NUMBER, colorspace);
+    surface->internal->colorspace = colorspace;
+    return 0;
 }
 }
 
 
 SDL_Colorspace SDL_GetSurfaceColorspace(SDL_Surface *surface)
 SDL_Colorspace SDL_GetSurfaceColorspace(SDL_Surface *surface)
 {
 {
-    SDL_Colorspace colorspace;
-
     if (!SDL_SurfaceValid(surface)) {
     if (!SDL_SurfaceValid(surface)) {
         return SDL_COLORSPACE_UNKNOWN;
         return SDL_COLORSPACE_UNKNOWN;
     }
     }
 
 
-    colorspace = (SDL_Colorspace)SDL_GetNumberProperty(surface->internal->props, SDL_PROP_SURFACE_COLORSPACE_NUMBER, SDL_COLORSPACE_UNKNOWN);
-    if (colorspace == SDL_COLORSPACE_UNKNOWN) {
-        colorspace = SDL_GetDefaultColorspaceForFormat(surface->format);
-    }
-    return colorspace;
+    return surface->internal->colorspace;
 }
 }
 
 
 float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace)
 float SDL_GetDefaultSDRWhitePoint(SDL_Colorspace colorspace)
@@ -1740,7 +1733,7 @@ SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelForm
         }
         }
     }
     }
 
 
-    src_colorspace = SDL_GetSurfaceColorspace(surface);
+    src_colorspace = surface->internal->colorspace;
     src_properties = surface->internal->props;
     src_properties = surface->internal->props;
 
 
     /* Create a new surface with the desired format */
     /* Create a new surface with the desired format */
@@ -1968,7 +1961,7 @@ SDL_Surface *SDL_DuplicateSurface(SDL_Surface *surface)
         return NULL;
         return NULL;
     }
     }
 
 
-    return SDL_ConvertSurfaceAndColorspace(surface, surface->format, surface->internal->palette, SDL_GetSurfaceColorspace(surface), surface->internal->props);
+    return SDL_ConvertSurfaceAndColorspace(surface, surface->format, surface->internal->palette, surface->internal->colorspace, surface->internal->props);
 }
 }
 
 
 SDL_Surface *SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format)
 SDL_Surface *SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format)
@@ -2311,7 +2304,7 @@ int SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear)
         return SDL_InvalidParamError("surface");
         return SDL_InvalidParamError("surface");
     }
     }
 
 
-    colorspace = SDL_GetSurfaceColorspace(surface);
+    colorspace = surface->internal->colorspace;
 
 
     return SDL_PremultiplyAlphaPixelsAndColorspace(surface->w, surface->h, surface->format, colorspace, surface->internal->props, surface->pixels, surface->pitch, surface->format, colorspace, surface->internal->props, surface->pixels, surface->pitch, linear);
     return SDL_PremultiplyAlphaPixelsAndColorspace(surface->w, surface->h, surface->format, colorspace, surface->internal->props, surface->pixels, surface->pitch, surface->format, colorspace, surface->internal->props, surface->pixels, surface->pitch, linear);
 }
 }
@@ -2346,7 +2339,7 @@ int SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
         }
         }
 
 
         if (SDL_ClearSurface(tmp, r, g, b, a) == 0) {
         if (SDL_ClearSurface(tmp, r, g, b, a) == 0) {
-            result = SDL_ConvertPixelsAndColorspace(surface->w, surface->h, tmp->format, SDL_GetSurfaceColorspace(tmp), tmp->internal->props, tmp->pixels, tmp->pitch, surface->format, SDL_GetSurfaceColorspace(surface), surface->internal->props, surface->pixels, surface->pitch);
+            result = SDL_ConvertPixelsAndColorspace(surface->w, surface->h, tmp->format, tmp->internal->colorspace, tmp->internal->props, tmp->pixels, tmp->pitch, surface->format, surface->internal->colorspace, surface->internal->props, surface->pixels, surface->pitch);
         }
         }
         SDL_DestroySurface(tmp);
         SDL_DestroySurface(tmp);
     } else {
     } else {
@@ -2355,7 +2348,7 @@ int SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
         if (!tmp) {
         if (!tmp) {
             goto done;
             goto done;
         }
         }
-        SDL_SetSurfaceColorspace(tmp, SDL_GetSurfaceColorspace(surface));
+        SDL_SetSurfaceColorspace(tmp, surface->internal->colorspace);
 
 
         float *pixels = (float *)tmp->pixels;
         float *pixels = (float *)tmp->pixels;
         pixels[0] = r;
         pixels[0] = r;
@@ -2462,9 +2455,8 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g,
     } else {
     } else {
         /* This is really slow, but it gets the job done */
         /* This is really slow, but it gets the job done */
         Uint8 rgba[4];
         Uint8 rgba[4];
-        SDL_Colorspace colorspace = SDL_GetSurfaceColorspace(surface);
 
 
-        if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba)) == 0) {
+        if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, surface->internal->colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba)) == 0) {
             *r = rgba[0];
             *r = rgba[0];
             *g = rgba[1];
             *g = rgba[1];
             *b = rgba[2];
             *b = rgba[2];
@@ -2554,7 +2546,7 @@ int SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, floa
             SDL_memcpy(rgba, p, sizeof(rgba));
             SDL_memcpy(rgba, p, sizeof(rgba));
             result = 0;
             result = 0;
         } else {
         } else {
-            SDL_Colorspace src_colorspace = SDL_GetSurfaceColorspace(surface);
+            SDL_Colorspace src_colorspace = surface->internal->colorspace;
             SDL_Colorspace dst_colorspace = (src_colorspace == SDL_COLORSPACE_SRGB_LINEAR ? SDL_COLORSPACE_SRGB_LINEAR : SDL_COLORSPACE_SRGB);
             SDL_Colorspace dst_colorspace = (src_colorspace == SDL_COLORSPACE_SRGB_LINEAR ? SDL_COLORSPACE_SRGB_LINEAR : SDL_COLORSPACE_SRGB);
 
 
             if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, src_colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA128_FLOAT, dst_colorspace, 0, rgba, sizeof(rgba)) == 0) {
             if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, src_colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA128_FLOAT, dst_colorspace, 0, rgba, sizeof(rgba)) == 0) {
@@ -2618,13 +2610,12 @@ int SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g,
     } else {
     } else {
         /* This is really slow, but it gets the job done */
         /* This is really slow, but it gets the job done */
         Uint8 rgba[4];
         Uint8 rgba[4];
-        SDL_Colorspace colorspace = SDL_GetSurfaceColorspace(surface);
 
 
         rgba[0] = r;
         rgba[0] = r;
         rgba[1] = g;
         rgba[1] = g;
         rgba[2] = b;
         rgba[2] = b;
         rgba[3] = a;
         rgba[3] = a;
-        result = SDL_ConvertPixelsAndColorspace(1, 1, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba), surface->format, colorspace, surface->internal->props, p, surface->pitch);
+        result = SDL_ConvertPixelsAndColorspace(1, 1, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba), surface->format, surface->internal->colorspace, surface->internal->props, p, surface->pitch);
     }
     }
 
 
     if (SDL_MUSTLOCK(surface)) {
     if (SDL_MUSTLOCK(surface)) {
@@ -2683,7 +2674,7 @@ int SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, floa
             SDL_memcpy(p, rgba, sizeof(rgba));
             SDL_memcpy(p, rgba, sizeof(rgba));
             result = 0;
             result = 0;
         } else {
         } else {
-            SDL_Colorspace dst_colorspace = SDL_GetSurfaceColorspace(surface);
+            SDL_Colorspace dst_colorspace = surface->internal->colorspace;
             SDL_Colorspace src_colorspace = (dst_colorspace == SDL_COLORSPACE_SRGB_LINEAR ? SDL_COLORSPACE_SRGB_LINEAR : SDL_COLORSPACE_SRGB);
             SDL_Colorspace src_colorspace = (dst_colorspace == SDL_COLORSPACE_SRGB_LINEAR ? SDL_COLORSPACE_SRGB_LINEAR : SDL_COLORSPACE_SRGB);
 
 
             result = SDL_ConvertPixelsAndColorspace(1, 1, SDL_PIXELFORMAT_RGBA128_FLOAT, src_colorspace, 0, rgba, sizeof(rgba), surface->format, dst_colorspace, surface->internal->props, p, surface->pitch);
             result = SDL_ConvertPixelsAndColorspace(1, 1, SDL_PIXELFORMAT_RGBA128_FLOAT, src_colorspace, 0, rgba, sizeof(rgba), surface->format, dst_colorspace, surface->internal->props, p, surface->pitch);

+ 3 - 0
src/video/SDL_surface_c.h

@@ -46,6 +46,9 @@ struct SDL_SurfaceData
     /** detailed format for this surface */
     /** detailed format for this surface */
     const SDL_PixelFormatDetails *format;
     const SDL_PixelFormatDetails *format;
 
 
+    /** Pixel colorspace */
+    SDL_Colorspace colorspace;
+
     /** palette for indexed surfaces */
     /** palette for indexed surfaces */
     SDL_Palette *palette;
     SDL_Palette *palette;