The rectangles passed to SDL_BlitSurfaceUnchecked() and SDL_BlitSurfaceUncheckedScaled() are const.

The destination rectangle passed to SDL_BlitSurface() and SDL_BlitSurfaceScaled() is non-const and filled in with the final destination rectangle after clipping, and now documented as such.

Fixes https://github.com/libsdl-org/SDL/issues/7911
This commit is contained in:
Sam Lantinga 2023-07-02 18:45:11 -07:00
parent ced153a24a
commit 3c04be4486
6 changed files with 38 additions and 36 deletions

View File

@ -99,8 +99,8 @@ typedef struct SDL_Surface
/**
* \brief The type of function used for surface blitting functions.
*/
typedef int (SDLCALL *SDL_blit) (struct SDL_Surface *src, SDL_Rect *srcrect,
struct SDL_Surface *dst, SDL_Rect *dstrect);
typedef int (SDLCALL *SDL_blit) (struct SDL_Surface *src, const SDL_Rect *srcrect,
struct SDL_Surface *dst, const SDL_Rect *dstrect);
/**
* \brief The formula used for converting between YUV and RGB
@ -773,8 +773,9 @@ extern DECLSPEC int SDLCALL SDL_FillSurfaceRects
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied, or NULL to copy the entire surface
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the rectangle that is
* copied into
* \param dstrect the SDL_Rect structure representing the target rectangle
* in the destination surface, filled with the actual rectangle
* used after clipping
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -796,8 +797,8 @@ extern DECLSPEC int SDLCALL SDL_BlitSurface
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied, or NULL to copy the entire surface
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the rectangle that is
* copied into
* \param dstrect the SDL_Rect structure representing the target rectangle
* in the destination surface
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -806,8 +807,8 @@ extern DECLSPEC int SDLCALL SDL_BlitSurface
* \sa SDL_BlitSurface
*/
extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked
(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect);
/**
@ -820,8 +821,8 @@ extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the rectangle that is
* copied into
* \param dstrect the SDL_Rect structure representing the target rectangle
* in the destination surface
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -839,8 +840,8 @@ extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src,
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the rectangle that is
* copied into
* \param dstrect the SDL_Rect structure representing the target rectangle
* in the destination surface
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -859,8 +860,9 @@ extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src,
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the rectangle that is
* copied into
* \param dstrect the SDL_Rect structure representing the target rectangle
* in the destination surface, filled with the actual rectangle
* used after clipping
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -868,7 +870,7 @@ extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src,
*/
extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
SDL_Surface *dst, SDL_Rect *dstrect);
/**
* Perform low-level surface scaled blitting only.
@ -880,8 +882,8 @@ extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied
* \param dst the SDL_Surface structure that is the blit target
* \param dstrect the SDL_Rect structure representing the rectangle that is
* copied into
* \param dstrect the SDL_Rect structure representing the target rectangle
* in the destination surface
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
@ -890,8 +892,8 @@ extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled
* \sa SDL_BlitSurfaceScaled
*/
extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled
(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect);
/**
* Set the YUV conversion mode

View File

@ -136,8 +136,8 @@ SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystick,(SDL_JoystickType a, in
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystickEx,(const SDL_VirtualJoystickDesc *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurface,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurfaceScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurfaceUnchecked,(SDL_Surface *a, SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurfaceUncheckedScaled,(SDL_Surface *a, SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurfaceUnchecked,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurfaceUncheckedScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_BroadcastCondition,(SDL_Condition *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_CaptureMouse,(SDL_bool a),(a),return)
SDL_DYNAPI_PROC(void,SDL_CleanupTLS,(void),(),)

View File

@ -307,7 +307,7 @@ extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode
the next call, because it might be in an array that gets realloc()'d. */
extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset);
extern int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
extern int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
extern int SDL_PrivateBlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
/* Ends C function definitions when using C++ */

View File

@ -432,7 +432,7 @@
} while (0)
static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
Uint8 *dstbuf, SDL_Rect *srcrect, unsigned alpha)
Uint8 *dstbuf, const SDL_Rect *srcrect, unsigned alpha)
{
SDL_PixelFormat *fmt = surf_dst->format;
@ -442,8 +442,8 @@ static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
#undef RLECLIPBLIT
/* blit a colorkeyed RLE surface */
static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
SDL_Surface *surf_dst, SDL_Rect *dstrect)
static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
SDL_Surface *surf_dst, const SDL_Rect *dstrect)
{
Uint8 *dstbuf;
Uint8 *srcbuf;
@ -626,7 +626,7 @@ typedef struct
/* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
Uint8 *dstbuf, SDL_Rect *srcrect)
Uint8 *dstbuf, const SDL_Rect *srcrect)
{
SDL_PixelFormat *df = surf_dst->format;
/*
@ -717,8 +717,8 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst,
}
/* blit a pixel-alpha RLE surface */
static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, SDL_Rect *srcrect,
SDL_Surface *surf_dst, SDL_Rect *dstrect)
static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
SDL_Surface *surf_dst, const SDL_Rect *dstrect)
{
int x, y;
int w = surf_src->w;

View File

@ -29,8 +29,8 @@
#include "SDL_pixels_c.h"
/* The general purpose software blit routine */
static int SDLCALL SDL_SoftBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
int okay;
int src_locked;

View File

@ -636,8 +636,8 @@ int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect)
* you know exactly what you are doing, you can optimize your code
* by calling the one(s) you need.
*/
int SDL_BlitSurfaceUnchecked(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
/* Check to make sure the blit mapping is valid */
if ((src->map->dst != dst) ||
@ -927,14 +927,14 @@ int SDL_PrivateBlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect,
* This is a semi-private blit function and it performs low-level surface
* scaled blitting only.
*/
int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect)
int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
return SDL_PrivateBlitSurfaceUncheckedScaled(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST);
}
int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
{
static const Uint32 complex_copy_flags = (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA |
SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL |