Skip to content

Commit

Permalink
Reverted 3d2e5a0
Browse files Browse the repository at this point in the history
Applying these changes to external code doesn't actually improve anything, and within the context of the other Get* functions for renderers and surfaces, these stand out as outliers, so I'm going to back this change out.
  • Loading branch information
slouken committed Jul 17, 2024
1 parent b3df46e commit 75be2c1
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 79 deletions.
4 changes: 0 additions & 4 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,6 @@ Textures are created with SDL_SCALEMODE_LINEAR by default, and use SDL_BLENDMODE
SDL_QueryTexture() has been removed. The properties of the texture can be queried using SDL_PROP_TEXTURE_FORMAT_NUMBER, SDL_PROP_TEXTURE_ACCESS_NUMBER, SDL_PROP_TEXTURE_WIDTH_NUMBER, and SDL_PROP_TEXTURE_HEIGHT_NUMBER. A function SDL_GetTextureSize() has been added to get the size of the texture as floating point values.
SDL_GetRenderDrawBlendMode(), SDL_GetTextureBlendMode(), and SDL_GetTextureScaleMode() have been changed to return the values directly instead of an int error code.
Mouse and touch events are no longer filtered to change their coordinates, instead you
can call SDL_ConvertEventToRenderCoordinates() to explicitly map event coordinates into
the rendering viewport.
Expand Down Expand Up @@ -1714,8 +1712,6 @@ SDL_SetSurfaceColorKey() takes an SDL_bool to enable and disable colorkey. RLE a

SDL_SetSurfaceRLE() takes an SDL_bool to enable and disable RLE acceleration.

SDL_GetSurfaceBlendMode() and SDL_GetSurfaceColorKey() have been changed to return the values directly instead of an int error code.

The following functions have been renamed:
* SDL_BlitScaled() => SDL_BlitSurfaceScaled()
* SDL_ConvertSurfaceFormat() => SDL_ConvertSurface()
Expand Down
24 changes: 16 additions & 8 deletions include/SDL3/SDL_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SD
* Get the blend mode used for texture copy operations.
*
* \param texture the texture to query.
* \returns the current SDL_BlendMode.
* \param blendMode a pointer filled in with the current SDL_BlendMode.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetTextureBlendMode
*/
extern SDL_DECLSPEC SDL_BlendMode SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture);
extern SDL_DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode);

/**
* Set the scale mode used for texture scale operations.
Expand All @@ -1036,13 +1038,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SD
* Get the scale mode used for texture scale operations.
*
* \param texture the texture to query.
* \returns the current scale mode.
* \param scaleMode a pointer filled in with the current scale mode.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetTextureScaleMode
*/
extern SDL_DECLSPEC SDL_ScaleMode SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture);
extern SDL_DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode);

/**
* Update the given texture rectangle with new pixel data.
Expand Down Expand Up @@ -1637,13 +1641,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderColorScale(SDL_Renderer *renderer,
* Get the color scale used for render operations.
*
* \param renderer the rendering context.
* \returns the current color scale value.
* \param scale a pointer filled in with the current color scale value.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetRenderColorScale
*/
extern SDL_DECLSPEC float SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer);
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale);

/**
* Set the blend mode used for drawing operations (Fill and Line).
Expand All @@ -1665,13 +1671,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *rendere
* Get the blend mode used for drawing operations.
*
* \param renderer the rendering context.
* \returns the current SDL_BlendMode.
* \param blendMode a pointer filled in with the current SDL_BlendMode.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetRenderDrawBlendMode
*/
extern SDL_DECLSPEC SDL_BlendMode SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer);
extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode);

/**
* Clear the current rendering target with the drawing color.
Expand Down
12 changes: 8 additions & 4 deletions include/SDL3/SDL_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,16 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface
* If the surface doesn't have color key enabled this function returns -1.
*
* \param surface the SDL_Surface structure to query.
* \returns the transparent pixel.
* \param key a pointer filled in with the transparent pixel.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetSurfaceColorKey
* \sa SDL_SurfaceHasColorKey
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface);
extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key);

/**
* Set an additional color value multiplied into blit operations.
Expand Down Expand Up @@ -618,13 +620,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SD
* Get the blend mode used for blit operations.
*
* \param surface the SDL_Surface structure to query.
* \returns the current SDL_BlendMode.
* \param blendMode a pointer filled in with the current SDL_BlendMode.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_SetSurfaceBlendMode
*/
extern SDL_DECLSPEC SDL_BlendMode SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface);
extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode);

/**
* Set the clipping rectangle for a surface.
Expand Down
12 changes: 6 additions & 6 deletions src/dynapi/SDL_dynapi_procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ SDL_DYNAPI_PROC(int,SDL_GetRectUnionFloat,(const SDL_FRect *a, const SDL_FRect *
SDL_DYNAPI_PROC(SDL_bool,SDL_GetRelativeMouseMode,(void),(),return)
SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetRelativeMouseState,(float *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(float,SDL_GetRenderColorScale,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(SDL_BlendMode,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColorFloat,(SDL_Renderer *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(const char*,SDL_GetRenderDriver,(int a),(a),return)
Expand Down Expand Up @@ -475,9 +475,9 @@ SDL_DYNAPI_PROC(int,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_P
SDL_DYNAPI_PROC(Uint64,SDL_GetStorageSpaceRemaining,(SDL_Storage *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceAlphaMod,(SDL_Surface *a, Uint8 *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_BlendMode,SDL_GetSurfaceBlendMode,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(Uint32,SDL_GetSurfaceColorKey,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorMod,(SDL_Surface *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_Colorspace,SDL_GetSurfaceColorspace,(SDL_Surface *a),(a),return)
SDL_DYNAPI_PROC(SDL_Palette*,SDL_GetSurfacePalette,(SDL_Surface *a),(a),return)
Expand All @@ -488,11 +488,11 @@ SDL_DYNAPI_PROC(void*,SDL_GetTLS,(SDL_TLSID *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetTextInputArea,(SDL_Window *a, SDL_Rect *b, int *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaMod,(SDL_Texture *a, Uint8 *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaModFloat,(SDL_Texture *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_BlendMode,SDL_GetTextureBlendMode,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureColorModFloat,(SDL_Texture *a, float *b, float *c, float *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetTextureProperties,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(SDL_ScaleMode,SDL_GetTextureScaleMode,(SDL_Texture *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetTextureSize,(SDL_Texture *a, float *b, float *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetThreadID,(SDL_Thread *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetThreadName,(SDL_Thread *a),(a),return)
Expand Down
53 changes: 29 additions & 24 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s

{
Uint8 r, g, b, a;
SDL_BlendMode blendMode;

SDL_GetSurfaceColorMod(surface, &r, &g, &b);
SDL_SetTextureColorMod(texture, r, g, b);
Expand All @@ -1652,7 +1653,8 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s
/* We converted to a texture with alpha format */
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
} else {
SDL_SetTextureBlendMode(texture, SDL_GetSurfaceBlendMode(surface));
SDL_GetSurfaceBlendMode(surface, &blendMode);
SDL_SetTextureBlendMode(texture, blendMode);
}
}
return texture;
Expand Down Expand Up @@ -1797,10 +1799,6 @@ int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)

CHECK_TEXTURE_MAGIC(texture, -1);

if (blendMode == SDL_BLENDMODE_INVALID) {
return SDL_InvalidParamError("blendMode");
}

renderer = texture->renderer;
if (!IsSupportedBlendMode(renderer, blendMode)) {
return SDL_Unsupported();
Expand All @@ -1812,11 +1810,14 @@ int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode)
return 0;
}

SDL_BlendMode SDL_GetTextureBlendMode(SDL_Texture *texture)
int SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode)
{
CHECK_TEXTURE_MAGIC(texture, SDL_BLENDMODE_INVALID);
CHECK_TEXTURE_MAGIC(texture, -1);

return texture->blendMode;
if (blendMode) {
*blendMode = texture->blendMode;
}
return 0;
}

int SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode)
Expand All @@ -1835,11 +1836,14 @@ int SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode)
return 0;
}

SDL_ScaleMode SDL_GetTextureScaleMode(SDL_Texture *texture)
int SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode)
{
CHECK_TEXTURE_MAGIC(texture, SDL_SCALEMODE_LINEAR);
CHECK_TEXTURE_MAGIC(texture, -1);

return texture->scaleMode;
if (scaleMode) {
*scaleMode = texture->scaleMode;
}
return 0;
}

#if SDL_HAVE_YUV
Expand Down Expand Up @@ -3065,40 +3069,41 @@ int SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale)
return 0;
}

float SDL_GetRenderColorScale(SDL_Renderer *renderer)
int SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale)
{
CHECK_RENDERER_MAGIC(renderer, 1.0f);
CHECK_RENDERER_MAGIC(renderer, -1);

return renderer->color_scale / renderer->SDR_white_point;
if (scale) {
*scale = renderer->color_scale / renderer->SDR_white_point;
}
return 0;
}

int SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode)
{
CHECK_RENDERER_MAGIC(renderer, -1);

if (blendMode == SDL_BLENDMODE_INVALID) {
return SDL_InvalidParamError("blendMode");
}

if (!IsSupportedBlendMode(renderer, blendMode)) {
return SDL_Unsupported();
}
renderer->blendMode = blendMode;
return 0;
}

SDL_BlendMode SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer)
int SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode)
{
CHECK_RENDERER_MAGIC(renderer, SDL_BLENDMODE_INVALID);
CHECK_RENDERER_MAGIC(renderer, -1);

return renderer->blendMode;
*blendMode = renderer->blendMode;
return 0;
}

int SDL_RenderClear(SDL_Renderer *renderer)
{
int retval;
CHECK_RENDERER_MAGIC(renderer, -1);

return QueueCmdClear(renderer);
retval = QueueCmdClear(renderer);
return retval;
}

int SDL_RenderPoint(SDL_Renderer *renderer, float x, float y)
Expand Down Expand Up @@ -3965,7 +3970,7 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer,
float r = 0, g = 0, b = 0, a = 0;

/* Save */
blendMode = SDL_GetRenderDrawBlendMode(renderer);
SDL_GetRenderDrawBlendMode(renderer, &blendMode);
SDL_GetRenderDrawColorFloat(renderer, &r, &g, &b, &a);

if (texture) {
Expand Down
4 changes: 2 additions & 2 deletions src/render/software/SDL_render_sw.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
return -1;
}

blendmode = SDL_GetSurfaceBlendMode(src);
SDL_GetSurfaceBlendMode(src, &blendmode);
SDL_GetSurfaceAlphaMod(src, &alphaMod);
SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);

Expand Down Expand Up @@ -841,7 +841,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
SDL_BlendMode blendmode;
Uint8 alphaMod, rMod, gMod, bMod;

blendmode = SDL_GetSurfaceBlendMode(src);
SDL_GetSurfaceBlendMode(src, &blendmode);
SDL_GetSurfaceAlphaMod(src, &alphaMod);
SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);

Expand Down
13 changes: 9 additions & 4 deletions src/render/software/SDL_rotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ Returns colorkey info for a surface
*/
static Uint32 get_colorkey(SDL_Surface *src)
{
return SDL_GetSurfaceColorKey(src);
Uint32 key = 0;
if (SDL_SurfaceHasColorKey(src)) {
SDL_GetSurfaceColorKey(src, &key);
}
return key;
}

/* rotate (sx, sy) by (angle, center) into (dx, dy) */
Expand Down Expand Up @@ -497,8 +501,9 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
}

if (SDL_SurfaceHasColorKey(src)) {
colorkey = SDL_GetSurfaceColorKey(src);
colorKeyAvailable = SDL_TRUE;
if (SDL_GetSurfaceColorKey(src, &colorkey) == 0) {
colorKeyAvailable = SDL_TRUE;
}
}
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
is8bit = src->internal->format->bits_per_pixel == 8 && colorKeyAvailable;
Expand Down Expand Up @@ -531,7 +536,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
/* Adjust for guard rows */
rz_dst->h = rect_dest->h;

blendmode = SDL_GetSurfaceBlendMode(src);
SDL_GetSurfaceBlendMode(src, &blendmode);

if (colorKeyAvailable == SDL_TRUE) {
/* If available, the colorkey will be used to discard the pixels that are outside of the rotated area. */
Expand Down
2 changes: 1 addition & 1 deletion src/render/software/SDL_triangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ int SDL_SW_BlitTriangle(

bounding_rect_fixedpoint(d0, d1, d2, &dstrect);

blend = SDL_GetSurfaceBlendMode(src);
SDL_GetSurfaceBlendMode(src, &blend);

/* TRIANGLE_GET_TEXTCOORD interpolates up to the max values included, so reduce by 1 */
{
Expand Down
Loading

0 comments on commit 75be2c1

Please sign in to comment.