diff --git a/WhatsNew.txt b/WhatsNew.txt index 18dfd84cb..1b84c49b9 100644 --- a/WhatsNew.txt +++ b/WhatsNew.txt @@ -30,4 +30,3 @@ General: * Added SDL_PlayAudioDevice() to start audio playback * Added SDL_ConvertAudioSamples() to convert audio samples from one format to another * Added the hint SDL_HINT_ANDROID_ALLOW_RECREATE_ACTIVITY to control re-creation of Android SDL activity. -* Added SDL_SetSurfaceScaleMode() and SDL_GetSurfaceScaleMode() to control scale mode using SDL_BlitSurfaceScaled() diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci index 0455147f4..9220d4d31 100644 --- a/build-scripts/SDL_migration.cocci +++ b/build-scripts/SDL_migration.cocci @@ -1924,10 +1924,10 @@ expression e2; + SDL_BlitSurfaceUnchecked (...) @@ +expression e1, e2, e3, e4; @@ -- SDL_LowerBlitScaled -+ SDL_BlitSurfaceUncheckedScaled - (...) +- SDL_LowerBlitScaled(e1, e2, e3, e4) ++ SDL_BlitSurfaceUncheckedScaled(e1, e2, e3, e4, SDL_SCALEMODE_NEAREST) @@ @@ - SDL_SetClipRect @@ -1944,10 +1944,10 @@ expression e2; + SDL_BlitSurface (...) @@ +expression e1, e2, e3, e4; @@ -- SDL_UpperBlitScaled -+ SDL_BlitSurfaceScaled - (...) +- SDL_UpperBlitScaled(e1, e2, e3, e4) ++ SDL_BlitSurfaceScaled(e1, e2, e3, e4, SDL_SCALEMODE_NEAREST) @@ @@ - SDL_RenderGetD3D11Device diff --git a/docs/README-migration.md b/docs/README-migration.md index f3dfdacdd..a90e32511 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -1158,6 +1158,7 @@ But if you're migrating your code which uses masks, you probably have a format i 0x0000F800 0x000007E0 0x0000001F 0x00000000 => SDL_PIXELFORMAT_RGB565 ``` +SDL_BlitSurfaceScaled() and SDL_BlitSurfaceUncheckedScaled() now take a scale paramater. The following functions have been renamed: * SDL_FillRect() => SDL_FillSurfaceRect() diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h index c6a3459b9..423150735 100644 --- a/include/SDL3/SDL_surface.h +++ b/include/SDL3/SDL_surface.h @@ -876,7 +876,6 @@ extern DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked * \since This function is available since SDL 3.0.0. * * \sa SDL_BlitSurfaceScaled - * \sa SDL_SetSurfaceScaleMode */ extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, @@ -898,7 +897,6 @@ extern DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, * \since This function is available since SDL 3.0.0. * * \sa SDL_BlitSurfaceScaled - * \sa SDL_SetSurfaceScaleMode */ extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, @@ -916,17 +914,19 @@ extern DECLSPEC int SDLCALL SDL_SoftStretchLinear(SDL_Surface *src, * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface, filled with the actual rectangle * used after clipping + * \param scaleMode scale algorithm to be used * \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_BlitSurface - * \sa SDL_SetSurfaceScaleMode */ -extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled - (SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect); +extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, + const SDL_Rect *srcrect, + SDL_Surface *dst, + SDL_Rect *dstrect, + SDL_ScaleMode scaleMode); /** * Perform low-level surface scaled blitting only. @@ -940,47 +940,19 @@ extern DECLSPEC int SDLCALL SDL_BlitSurfaceScaled * \param dst the SDL_Surface structure that is the blit target * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface + * \param scaleMode scale algorithm to be used * \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_BlitSurfaceScaled - * \sa SDL_SetSurfaceScaleMode */ -extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled - (SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect); - -/** - * Set the scale mode used for surface scale operations. - * - * \param surface the surface to update. - * \param scaleMode the SDL_ScaleMode to use for scaling. - * \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_GetSurfaceScaleMode - * \sa SDL_BlitSurfaceScaled - */ -extern DECLSPEC int SDLCALL SDL_SetSurfaceScaleMode(SDL_Surface *surface, SDL_ScaleMode scaleMode); - -/** - * Get the scale mode used for surface scale operations. - * - * \param surface the surface to query. - * \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_SetSurfaceScaleMode - * \sa SDL_BlitSurfaceScaled - */ -extern DECLSPEC int SDLCALL SDL_GetSurfaceScaleMode(SDL_Surface *surface, SDL_ScaleMode *scaleMode); +extern DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, + const SDL_Rect *srcrect, + SDL_Surface *dst, + const SDL_Rect *dstrect, + SDL_ScaleMode scaleMode); /** * Set the YUV conversion mode diff --git a/src/dynapi/SDL_dynapi.sym b/src/dynapi/SDL_dynapi.sym index 9b22950ec..2392a31bb 100644 --- a/src/dynapi/SDL_dynapi.sym +++ b/src/dynapi/SDL_dynapi.sym @@ -963,8 +963,6 @@ SDL3_0.0.0 { SDL_strnstr; SDL_wcsnstr; SDL_SyncWindow; - SDL_SetSurfaceScaleMode; - SDL_GetSurfaceScaleMode; SDL_GetGamepadSteamHandle; # extra symbols go here (don't modify this line) local: *; diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 4c3007636..8482314dc 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -988,6 +988,4 @@ #define SDL_strnstr SDL_strnstr_REAL #define SDL_wcsnstr SDL_wcsnstr_REAL #define SDL_SyncWindow SDL_SyncWindow_REAL -#define SDL_SetSurfaceScaleMode SDL_SetSurfaceScaleMode_REAL -#define SDL_GetSurfaceScaleMode SDL_GetSurfaceScaleMode_REAL #define SDL_GetGamepadSteamHandle SDL_GetGamepadSteamHandle_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 7c7993c6f..9cb62f4ba 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -119,9 +119,9 @@ SDL_DYNAPI_PROC(void,SDL_AtomicUnlock,(SDL_SpinLock *a),(a),) SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystick,(SDL_JoystickType a, int b, int c, int d),(a,b,c,d),return) 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_BlitSurfaceScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d, SDL_ScaleMode e),(a,b,c,d,e),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_BlitSurfaceUncheckedScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d, SDL_ScaleMode e),(a,b,c,d,e),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),(),) @@ -1013,6 +1013,4 @@ SDL_DYNAPI_PROC(const char*,SDL_GetTouchDeviceName,(SDL_TouchID a),(a),return) SDL_DYNAPI_PROC(char*,SDL_strnstr,(const char *a, const char *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(wchar_t*,SDL_wcsnstr,(const wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_SyncWindow,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceScaleMode,(SDL_Surface *a, SDL_ScaleMode b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetSurfaceScaleMode,(SDL_Surface *a, SDL_ScaleMode *b),(a,b),return) SDL_DYNAPI_PROC(Uint64,SDL_GetGamepadSteamHandle,(SDL_Gamepad *a),(a),return) diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index 01bf8ec29..51d58c384 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -310,9 +310,6 @@ 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, 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++ */ #ifdef __cplusplus } diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 591bb89c2..bb2fe7558 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -302,7 +302,7 @@ static int Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surf r.y = (int)((float)dstrect->y * scale_y); r.w = (int)((float)dstrect->w * scale_x); r.h = (int)((float)dstrect->h * scale_y); - retval = SDL_PrivateBlitSurfaceScaled(src, srcrect, surface, &r, scaleMode); + retval = SDL_BlitSurfaceScaled(src, srcrect, surface, &r, scaleMode); } else { retval = SDL_BlitSurface(src, srcrect, surface, dstrect); } @@ -404,7 +404,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex retval = -1; } else { SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE); - retval = SDL_PrivateBlitSurfaceScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode); + retval = SDL_BlitSurfaceScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode); SDL_DestroySurface(src_clone); src_clone = src_scaled; src_scaled = NULL; @@ -843,7 +843,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo SDL_SetSurfaceColorMod(src, 255, 255, 255); SDL_SetSurfaceAlphaMod(src, 255); - SDL_PrivateBlitSurfaceScaled(src, srcrect, tmp, &r, texture->scaleMode); + SDL_BlitSurfaceScaled(src, srcrect, tmp, &r, texture->scaleMode); SDL_SetSurfaceColorMod(tmp, rMod, gMod, bMod); SDL_SetSurfaceAlphaMod(tmp, alphaMod); @@ -854,7 +854,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo /* No need to set back r/g/b/a/blendmode to 'src' since it's done in PrepTextureForCopy() */ } } else { - SDL_PrivateBlitSurfaceScaled(src, srcrect, surface, dstrect, texture->scaleMode); + SDL_BlitSurfaceScaled(src, srcrect, surface, dstrect, texture->scaleMode); } } break; diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 0e9cd40ec..f4f0dbaea 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -782,18 +782,8 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, } int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect) -{ - SDL_ScaleMode scale_mode = SDL_SCALEMODE_NEAREST; - - if (SDL_GetSurfaceScaleMode(src, &scale_mode) < 0) { - return -1; - } - return SDL_PrivateBlitSurfaceScaled(src, srcrect, dst, dstrect, scale_mode); -} - -int SDL_PrivateBlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, SDL_Rect *dstrect, SDL_ScaleMode scaleMode) + SDL_Surface *dst, SDL_Rect *dstrect, + SDL_ScaleMode scaleMode) { double src_x0, src_y0, src_x1, src_y1; double dst_x0, dst_y0, dst_x1, dst_y1; @@ -947,7 +937,7 @@ int SDL_PrivateBlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, return 0; } - return SDL_PrivateBlitSurfaceUncheckedScaled(src, &final_src, dst, &final_dst, scaleMode); + return SDL_BlitSurfaceUncheckedScaled(src, &final_src, dst, &final_dst, scaleMode); } /** @@ -955,23 +945,21 @@ int SDL_PrivateBlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, * scaled blitting only. */ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect) -{ - SDL_ScaleMode scale_mode = SDL_SCALEMODE_NEAREST; - - if (SDL_GetSurfaceScaleMode(src, &scale_mode) < 0) { - return -1; - } - return SDL_PrivateBlitSurfaceUncheckedScaled(src, srcrect, dst, dstrect, scale_mode); -} - -int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode) + 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 | SDL_COPY_COLORKEY); + if (scaleMode != SDL_SCALEMODE_NEAREST && scaleMode != SDL_SCALEMODE_LINEAR && scaleMode != SDL_SCALEMODE_BEST) { + return SDL_InvalidParamError("scaleMode"); + } + + if (scaleMode != SDL_SCALEMODE_NEAREST) { + scaleMode = SDL_SCALEMODE_LINEAR; + } + if (srcrect->w > SDL_MAX_UINT16 || srcrect->h > SDL_MAX_UINT16 || dstrect->w > SDL_MAX_UINT16 || dstrect->h > SDL_MAX_UINT16) { return SDL_SetError("Size too large for scaling"); @@ -1069,47 +1057,6 @@ int SDL_PrivateBlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcr } } -#define SDL_PROPERTY_SURFACE_SCALEMODE "SDL.internal.surface.scale_mode" - -int SDL_SetSurfaceScaleMode(SDL_Surface *surface, SDL_ScaleMode scaleMode) -{ - SDL_PropertiesID props; - - if (!surface) { - return SDL_InvalidParamError("surface"); - } - - if (scaleMode != SDL_SCALEMODE_NEAREST && scaleMode != SDL_SCALEMODE_LINEAR && scaleMode != SDL_SCALEMODE_BEST) { - return SDL_InvalidParamError("scaleMode"); - } - - props = SDL_GetSurfaceProperties(surface); - if (!props) { - return -1; - } - - if (scaleMode != SDL_SCALEMODE_NEAREST) { - scaleMode = SDL_SCALEMODE_LINEAR; - } - return SDL_SetNumberProperty(props, SDL_PROPERTY_SURFACE_SCALEMODE, scaleMode); -} - -int SDL_GetSurfaceScaleMode(SDL_Surface *surface, SDL_ScaleMode *scaleMode) -{ - if (!surface) { - return SDL_InvalidParamError("surface"); - } - - if (scaleMode) { - if (surface->flags & SDL_SURFACE_USES_PROPERTIES) { - *scaleMode = (SDL_ScaleMode)SDL_GetNumberProperty(SDL_GetSurfaceProperties(surface), SDL_PROPERTY_SURFACE_SCALEMODE, SDL_SCALEMODE_NEAREST); - } else { - *scaleMode = SDL_SCALEMODE_NEAREST; - } - } - return 0; -} - /* * Lock a surface to directly access the pixels */