Sam Lantinga 2024-07-20 11:53:36 -07:00
parent 71d2662a39
commit f47ddbf1ac
8 changed files with 1145 additions and 471 deletions

View File

@ -982,7 +982,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect
*
* \param src the SDL_Surface structure to be copied from.
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied, or NULL to copy the entire surface.
* copied, may not be NULL.
* \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.
@ -1007,10 +1007,10 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const
*
* \param src the SDL_Surface structure to be copied from.
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied.
* copied, may not be NULL.
* \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.
* the destination surface, may not be NULL.
* \param scaleMode scale algorithm to be used.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
@ -1027,7 +1027,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SoftStretch(SDL_Surface *src, const SDL_Rect
*
* \param src the SDL_Surface structure to be copied from.
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied.
* 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 target rectangle in
* the destination surface, filled with the actual rectangle
@ -1054,10 +1054,10 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SD
*
* \param src the SDL_Surface structure to be copied from.
* \param srcrect the SDL_Rect structure representing the rectangle to be
* copied.
* copied, may not be NULL.
* \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.
* the destination surface, may not be NULL.
* \param scaleMode scale algorithm to be used.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
@ -1072,6 +1072,31 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SD
*/
extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
/**
* Perform a tiled blit to a destination surface, which may be of a different
* format.
*
* The pixels in `srcrect` will be repeated as many times as needed to completely fill `dstrect`.
*
* \param src the SDL_Surface structure to be copied from.
* \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 target rectangle in
* the destination surface, or NULL to fill the entire surface.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \threadsafety The same destination surface should not be used from two
* threads at once. It is safe to use the same source surface
* from multiple threads.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_BlitSurface
*/
extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
/**
* Map an RGB triple to an opaque pixel value for a surface.
*

View File

@ -25,6 +25,7 @@ SDL3_0.0.0 {
SDL_BindAudioStreams;
SDL_BlitSurface;
SDL_BlitSurfaceScaled;
SDL_BlitSurfaceTiled;
SDL_BlitSurfaceUnchecked;
SDL_BlitSurfaceUncheckedScaled;
SDL_BroadcastCondition;

View File

@ -50,6 +50,7 @@
#define SDL_BindAudioStreams SDL_BindAudioStreams_REAL
#define SDL_BlitSurface SDL_BlitSurface_REAL
#define SDL_BlitSurfaceScaled SDL_BlitSurfaceScaled_REAL
#define SDL_BlitSurfaceTiled SDL_BlitSurfaceTiled_REAL
#define SDL_BlitSurfaceUnchecked SDL_BlitSurfaceUnchecked_REAL
#define SDL_BlitSurfaceUncheckedScaled SDL_BlitSurfaceUncheckedScaled_REAL
#define SDL_BroadcastCondition SDL_BroadcastCondition_REAL

View File

@ -70,6 +70,7 @@ SDL_DYNAPI_PROC(int,SDL_BindAudioStream,(SDL_AudioDeviceID a, SDL_AudioStream *b
SDL_DYNAPI_PROC(int,SDL_BindAudioStreams,(SDL_AudioDeviceID a, SDL_AudioStream **b, int c),(a,b,c),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, SDL_ScaleMode e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_BlitSurfaceTiled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const 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, SDL_ScaleMode e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(int,SDL_BroadcastCondition,(SDL_Condition *a),(a),return)

View File

@ -1236,6 +1236,111 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
}
}
int SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect)
{
SDL_Rect r_src, r_dst;
/* Make sure the surfaces aren't locked */
if (!SDL_SurfaceValid(src)) {
return SDL_InvalidParamError("src");
} else if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("dst");
} else if ((src->flags & SDL_SURFACE_LOCKED) || (dst->flags & SDL_SURFACE_LOCKED)) {
return SDL_SetError("Surfaces must not be locked during blit");
}
/* Full src surface */
r_src.x = 0;
r_src.y = 0;
r_src.w = src->w;
r_src.h = src->h;
if (dstrect) {
r_dst.x = dstrect->x;
r_dst.y = dstrect->y;
r_dst.w = dstrect->w;
r_dst.h = dstrect->h;
} else {
r_dst.x = 0;
r_dst.y = 0;
r_dst.w = dst->w;
r_dst.h = dst->h;
}
/* clip the source rectangle to the source surface */
if (srcrect) {
if (SDL_GetRectIntersection(srcrect, &r_src, &r_src) == SDL_FALSE) {
return 0;
}
/* For tiling we don't adjust the destination rectangle */
}
/* clip the destination rectangle against the clip rectangle */
{
if (SDL_GetRectIntersection(&r_dst, &dst->internal->clip_rect, &r_dst) == SDL_FALSE) {
return 0;
}
/* For tiling we don't adjust the source rectangle */
}
/* Switch back to a fast blit if we were previously stretching */
if (src->internal->map.info.flags & SDL_COPY_NEAREST) {
src->internal->map.info.flags &= ~SDL_COPY_NEAREST;
SDL_InvalidateMap(&src->internal->map);
}
int rows = r_dst.h / r_src.h;
int cols = r_dst.w / r_src.w;
int remaining_w = r_dst.w % r_src.w;
int remaining_h = r_dst.h % r_src.h;
SDL_Rect curr_src, curr_dst;
SDL_copyp(&curr_src, &r_src);
curr_dst.y = r_dst.y;
curr_dst.w = r_src.w;
curr_dst.h = r_src.h;
for (int y = 0; y < rows; ++y) {
curr_dst.x = r_dst.x;
for (int x = 0; x < cols; ++x) {
if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) {
return -1;
}
curr_dst.x += curr_dst.w;
}
if (remaining_w) {
curr_src.w = remaining_w;
curr_dst.w = remaining_w;
if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) {
return -1;
}
curr_src.w = r_src.w;
curr_dst.w = r_src.w;
}
curr_dst.y += curr_dst.h;
}
if (remaining_h) {
curr_src.h = remaining_h;
curr_dst.h = remaining_h;
curr_dst.x = r_dst.x;
for (int x = 0; x < cols; ++x) {
if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) {
return -1;
}
curr_dst.x += curr_dst.w;
}
if (remaining_w) {
curr_src.w = remaining_w;
curr_dst.w = remaining_w;
if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) {
return -1;
}
}
}
return 0;
}
/*
* Lock a surface to directly access the pixels
*/

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@ typedef struct SDLTest_SurfaceImage_s {
/* Test images */
extern SDL_Surface *SDLTest_ImageBlit(void);
extern SDL_Surface *SDLTest_ImageBlitTiled(void);
extern SDL_Surface *SDLTest_ImageBlitColor(void);
extern SDL_Surface *SDLTest_ImageFace(void);
extern SDL_Surface *SDLTest_ImagePrimitives(void);

View File

@ -57,6 +57,10 @@ static void surfaceSetUp(void *arg)
result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, blendMode, currentBlendMode);
/* Clear the target surface */
result = SDL_FillSurfaceRect(testSurface, NULL, SDL_MapSurfaceRGBA(testSurface, 0, 0, 0, 255));
SDLTest_AssertCheck(result == 0, "Validate result from SDL_FillSurfaceRect, expected: 0, got: %i", result);
}
}
@ -356,6 +360,36 @@ static int surface_testSaveLoadBitmap(void *arg)
return TEST_COMPLETED;
}
/**
* Tests tiled blitting.
*/
static int surface_testBlitTiled(void *arg)
{
SDL_Surface *face = NULL;
int ret = 0;
/* Create sample surface */
face = SDLTest_ImageFace();
SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
if (face == NULL) {
return TEST_ABORTED;
}
ret = SDL_BlitSurfaceTiled(face, NULL, testSurface, NULL);
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_BlitSurfaceTiled expected: 0, got: %i", ret);
/* See if it's the same */
SDL_DestroySurface(referenceSurface);
referenceSurface = SDLTest_ImageBlitTiled();
ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
SDL_DestroySurface(face);
return TEST_COMPLETED;
}
/**
* Tests surface conversion.
*/
@ -1028,55 +1062,59 @@ static int surface_testPremultiplyAlpha(void *arg)
/* ================= Test References ================== */
/* Surface test cases */
static const SDLTest_TestCaseReference surfaceTest1 = {
static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
(SDLTest_TestCaseFp)surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest2 = {
static const SDLTest_TestCaseReference surfaceTestBlit = {
(SDLTest_TestCaseFp)surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest3 = {
static const SDLTest_TestCaseReference surfaceTestBlitTiled = {
(SDLTest_TestCaseFp)surface_testBlitTiled, "surface_testBlitTiled", "Tests tiled blitting.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTestLoadFailure = {
(SDLTest_TestCaseFp)surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest4 = {
static const SDLTest_TestCaseReference surfaceTestSurfaceConversion = {
(SDLTest_TestCaseFp)surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest5 = {
static const SDLTest_TestCaseReference surfaceTestCompleteSurfaceConversion = {
(SDLTest_TestCaseFp)surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest6 = {
static const SDLTest_TestCaseReference surfaceTestBlitColorMod = {
(SDLTest_TestCaseFp)surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest7 = {
static const SDLTest_TestCaseReference surfaceTestBlitAlphaMod = {
(SDLTest_TestCaseFp)surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest8 = {
static const SDLTest_TestCaseReference surfaceTestBlitBlendBlend = {
(SDLTest_TestCaseFp)surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest9 = {
static const SDLTest_TestCaseReference surfaceTestBlitBlendPremultiplied = {
(SDLTest_TestCaseFp)surface_testBlitBlendPremultiplied, "surface_testBlitBlendPremultiplied", "Tests blitting routines with premultiplied blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest10 = {
static const SDLTest_TestCaseReference surfaceTestBlitBlendAdd = {
(SDLTest_TestCaseFp)surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest11 = {
static const SDLTest_TestCaseReference surfaceTestBlitBlendAddPremultiplied = {
(SDLTest_TestCaseFp)surface_testBlitBlendAddPremultiplied, "surface_testBlitBlendAddPremultiplied", "Tests blitting routines with premultiplied add blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest12 = {
static const SDLTest_TestCaseReference surfaceTestBlitBlendMod = {
(SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
};
static const SDLTest_TestCaseReference surfaceTest13 = {
static const SDLTest_TestCaseReference surfaceTestBlitBlendMul = {
(SDLTest_TestCaseFp)surface_testBlitBlendMul, "surface_testBlitBlendMul", "Tests blitting routines with mul blending mode.", TEST_ENABLED
};
@ -1102,11 +1140,26 @@ static const SDLTest_TestCaseReference surfaceTestPremultiplyAlpha = {
/* Sequence of Surface test cases */
static const SDLTest_TestCaseReference *surfaceTests[] = {
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
&surfaceTest11, &surfaceTest12, &surfaceTest13,
&surfaceTestOverflow, &surfaceTestFlip, &surfaceTestPalette,
&surfaceTestClearSurface, &surfaceTestPremultiplyAlpha, NULL
&surfaceTestSaveLoadBitmap,
&surfaceTestBlit,
&surfaceTestBlitTiled,
&surfaceTestLoadFailure,
&surfaceTestSurfaceConversion,
&surfaceTestCompleteSurfaceConversion,
&surfaceTestBlitColorMod,
&surfaceTestBlitAlphaMod,
&surfaceTestBlitBlendBlend,
&surfaceTestBlitBlendPremultiplied,
&surfaceTestBlitBlendAdd,
&surfaceTestBlitBlendAddPremultiplied,
&surfaceTestBlitBlendMod,
&surfaceTestBlitBlendMul,
&surfaceTestOverflow,
&surfaceTestFlip,
&surfaceTestPalette,
&surfaceTestClearSurface,
&surfaceTestPremultiplyAlpha,
NULL
};
/* Surface test suite (global) */