Use SDL_bool instead an int return code in the SDL API

Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool.

Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test:
@ bool_return_type  @
identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat)$";
@@
(
  func(
  ...
  )
- == 0
|
- func(
+ !func(
  ...
  )
- < 0
|
- func(
+ !func(
  ...
  )
- != 0
|
- func(
+ !func(
  ...
  )
- == -1
)
This commit is contained in:
Sam Lantinga
2024-08-22 17:33:49 -07:00
parent d9a5ed75b9
commit 9ff3446f03
726 changed files with 11062 additions and 11472 deletions

View File

@@ -25,7 +25,7 @@
#include "SDL_draw.h"
#include "SDL_blendfillrect.h"
static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect,
static bool SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -51,10 +51,10 @@ static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
break;
}
return 0;
return true;
}
static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect,
static bool SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -80,10 +80,10 @@ static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
break;
}
return 0;
return true;
}
static int SDL_BlendFillRect_XRGB8888(SDL_Surface *dst, const SDL_Rect *rect,
static bool SDL_BlendFillRect_XRGB8888(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -109,10 +109,10 @@ static int SDL_BlendFillRect_XRGB8888(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint32, DRAW_SETPIXEL_XRGB8888);
break;
}
return 0;
return true;
}
static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
static bool SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -138,10 +138,10 @@ static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
break;
}
return 0;
return true;
}
static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
static bool SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
const SDL_PixelFormatDetails *fmt = dst->internal->format;
@@ -170,7 +170,7 @@ static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
break;
}
return 0;
return true;
case 4:
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
@@ -193,13 +193,13 @@ static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
break;
}
return 0;
return true;
default:
return SDL_Unsupported();
}
}
static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
static bool SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
const SDL_PixelFormatDetails *fmt = dst->internal->format;
@@ -228,14 +228,13 @@ static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect,
FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
break;
}
return 0;
return true;
default:
return SDL_Unsupported();
}
}
int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Rect clipped;
@@ -252,7 +251,7 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
if (rect) {
// Perform clipping
if (!SDL_GetRectIntersection(rect, &dst->internal->clip_rect, &clipped)) {
return 0;
return true;
}
rect = &clipped;
} else {
@@ -300,14 +299,12 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect,
}
}
int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Rect rect;
int i;
int (*func)(SDL_Surface * dst, const SDL_Rect *rect,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
bool (*func)(SDL_Surface * dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
bool result = true;
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
@@ -366,9 +363,9 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
if (!SDL_GetRectIntersection(&rects[i], &dst->internal->clip_rect, &rect)) {
continue;
}
status = func(dst, &rect, blendMode, r, g, b, a);
result = func(dst, &rect, blendMode, r, g, b, a);
}
return status;
return result;
}
#endif // SDL_VIDEO_RENDER_SW

View File

@@ -24,7 +24,7 @@
#include "SDL_internal.h"
extern int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif // SDL_blendfillrect_h_

View File

@@ -919,8 +919,7 @@ static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormatDetails *fm
return NULL;
}
int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
bool SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
BlendLineFunc func;
@@ -936,15 +935,14 @@ int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2,
// Perform clipping
// FIXME: We don't actually want to clip, as it may change line slope
if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
return true;
}
func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, true);
return 0;
return true;
}
int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
bool SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int i;
int x1, y1;
@@ -982,7 +980,7 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_BlendPoint(dst, points[count - 1].x, points[count - 1].y,
blendMode, r, g, b, a);
}
return 0;
return true;
}
#endif // SDL_VIDEO_RENDER_SW

View File

@@ -24,7 +24,7 @@
#include "SDL_internal.h"
extern int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern bool SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern bool SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif // SDL_blendline_h_

View File

@@ -25,7 +25,7 @@
#include "SDL_draw.h"
#include "SDL_blendpoint.h"
static int SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
static bool SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -51,10 +51,10 @@ static int SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode b
DRAW_SETPIXELXY_RGB555(x, y);
break;
}
return 0;
return true;
}
static int SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
static bool SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -80,10 +80,10 @@ static int SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode b
DRAW_SETPIXELXY_RGB565(x, y);
break;
}
return 0;
return true;
}
static int SDL_BlendPoint_XRGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
static bool SDL_BlendPoint_XRGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -109,10 +109,10 @@ static int SDL_BlendPoint_XRGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode
DRAW_SETPIXELXY_XRGB8888(x, y);
break;
}
return 0;
return true;
}
static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode,
static bool SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode,
Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
unsigned inva = 0xff - a;
@@ -138,10 +138,10 @@ static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode
DRAW_SETPIXELXY_ARGB8888(x, y);
break;
}
return 0;
return true;
}
static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
static bool SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
const SDL_PixelFormatDetails *fmt = dst->internal->format;
@@ -170,7 +170,7 @@ static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blen
DRAW_SETPIXELXY2_RGB(x, y);
break;
}
return 0;
return true;
case 4:
switch (blendMode) {
case SDL_BLENDMODE_BLEND:
@@ -193,13 +193,13 @@ static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blen
DRAW_SETPIXELXY4_RGB(x, y);
break;
}
return 0;
return true;
default:
return SDL_Unsupported();
}
}
static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
static bool SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
{
const SDL_PixelFormatDetails *fmt = dst->internal->format;
@@ -228,14 +228,13 @@ static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode ble
DRAW_SETPIXELXY4_RGBA(x, y);
break;
}
return 0;
return true;
default:
return SDL_Unsupported();
}
}
int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r,
Uint8 g, Uint8 b, Uint8 a)
bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
@@ -250,7 +249,7 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint
if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
return 0;
return true;
}
if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
@@ -294,16 +293,14 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint
}
}
int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int minx, miny;
int maxx, maxy;
int i;
int x, y;
int (*func)(SDL_Surface * dst, int x, int y,
SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
int status = 0;
bool (*func)(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
bool result = true;
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
@@ -371,9 +368,9 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count,
if (x < minx || x > maxx || y < miny || y > maxy) {
continue;
}
status = func(dst, x, y, blendMode, r, g, b, a);
result = func(dst, x, y, blendMode, r, g, b, a);
}
return status;
return result;
}
#endif // SDL_VIDEO_RENDER_SW

View File

@@ -24,7 +24,7 @@
#include "SDL_internal.h"
extern int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
extern bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
#endif // SDL_blendpoint_h_

View File

@@ -133,7 +133,7 @@ static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormatDetails *fmt)
return NULL;
}
int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
bool SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
{
DrawLineFunc func;
@@ -149,15 +149,14 @@ int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color)
// Perform clipping
// FIXME: We don't actually want to clip, as it may change line slope
if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) {
return 0;
return true;
}
func(dst, x1, y1, x2, y2, color, true);
return 0;
return true;
}
int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
Uint32 color)
bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)
{
int i;
int x1, y1;
@@ -194,7 +193,7 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count,
if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) {
SDL_DrawPoint(dst, points[count - 1].x, points[count - 1].y, color);
}
return 0;
return true;
}
#endif // SDL_VIDEO_RENDER_SW

View File

@@ -24,7 +24,7 @@
#include "SDL_internal.h"
extern int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color);
extern int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
extern bool SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color);
extern bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
#endif // SDL_drawline_h_

View File

@@ -25,7 +25,7 @@
#include "SDL_draw.h"
#include "SDL_drawpoint.h"
int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
bool SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
{
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
@@ -40,7 +40,7 @@ int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y ||
x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) ||
y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) {
return 0;
return true;
}
switch (dst->internal->format->bytes_per_pixel) {
@@ -56,11 +56,10 @@ int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color)
DRAW_FASTSETPIXELXY4(x, y);
break;
}
return 0;
return true;
}
int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
Uint32 color)
bool SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color)
{
int minx, miny;
int maxx, maxy;
@@ -103,7 +102,7 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count,
break;
}
}
return 0;
return true;
}
#endif // SDL_VIDEO_RENDER_SW

View File

@@ -24,7 +24,7 @@
#include "SDL_internal.h"
extern int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color);
extern int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
extern bool SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color);
extern bool SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color);
#endif // SDL_drawpoint_h_

View File

@@ -77,7 +77,7 @@ static void SW_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event)
}
}
static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
static bool SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
{
SW_RenderData *data = (SW_RenderData *)renderer->internal;
@@ -88,18 +88,18 @@ static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h)
if (h) {
*h = data->surface->h;
}
return 0;
return true;
}
if (renderer->window) {
SDL_GetWindowSizeInPixels(renderer->window, w, h);
return 0;
return true;
}
return SDL_SetError("Software renderer doesn't have an output surface");
}
static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props)
static bool SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props)
{
SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format);
Uint8 r, g, b, a;
@@ -123,10 +123,10 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr
SDL_SetSurfaceRLE(surface, 1);
}
return 0;
return true;
}
static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
static bool SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, const void *pixels, int pitch)
{
SDL_Surface *surface = (SDL_Surface *)texture->internal;
@@ -135,8 +135,8 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
size_t length;
if (SDL_MUSTLOCK(surface)) {
if (SDL_LockSurface(surface) < 0) {
return -1;
if (!SDL_LockSurface(surface)) {
return false;
}
}
src = (Uint8 *)pixels;
@@ -152,10 +152,10 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
if (SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface);
}
return 0;
return true;
}
static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
static bool SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
const SDL_Rect *rect, void **pixels, int *pitch)
{
SDL_Surface *surface = (SDL_Surface *)texture->internal;
@@ -164,7 +164,7 @@ static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
(void *)((Uint8 *)surface->pixels + rect->y * surface->pitch +
rect->x * surface->internal->format->bytes_per_pixel);
*pitch = surface->pitch;
return 0;
return true;
}
static void SW_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
@@ -175,7 +175,7 @@ static void SW_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture,
{
}
static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
static bool SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
SW_RenderData *data = (SW_RenderData *)renderer->internal;
@@ -184,21 +184,21 @@ static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
} else {
data->surface = data->window;
}
return 0;
return true;
}
static int SW_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
static bool SW_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
{
return 0; // nothing to do in this backend.
return true; // nothing to do in this backend.
}
static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
static bool SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count)
{
SDL_Point *verts = (SDL_Point *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Point), 0, &cmd->data.draw.first);
int i;
if (!verts) {
return -1;
return false;
}
cmd->data.draw.count = count;
@@ -208,16 +208,16 @@ static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co
verts->y = (int)points->y;
}
return 0;
return true;
}
static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
static bool SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count)
{
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
int i;
if (!verts) {
return -1;
return false;
}
cmd->data.draw.count = count;
@@ -229,16 +229,16 @@ static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, con
verts->h = SDL_max((int)rects->h, 1);
}
return 0;
return true;
}
static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
static bool SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const SDL_FRect *srcrect, const SDL_FRect *dstrect)
{
SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(SDL_Rect), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
return false;
}
cmd->data.draw.count = 1;
@@ -254,7 +254,7 @@ static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Text
verts->w = (int)dstrect->w;
verts->h = (int)dstrect->h;
return 0;
return true;
}
typedef struct CopyExData
@@ -268,14 +268,14 @@ typedef struct CopyExData
float scale_y;
} CopyExData;
static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
static bool SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const SDL_FRect *srcrect, const SDL_FRect *dstrect,
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y)
{
CopyExData *verts = (CopyExData *)SDL_AllocateRenderVertices(renderer, sizeof(CopyExData), 0, &cmd->data.draw.first);
if (!verts) {
return -1;
return false;
}
cmd->data.draw.count = 1;
@@ -294,13 +294,13 @@ static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Te
verts->scale_x = scale_x;
verts->scale_y = scale_y;
return 0;
return true;
}
static int Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
static bool Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
float scale_x, float scale_y, SDL_ScaleMode scaleMode)
{
int retval;
bool result;
// Renderer scaling, if needed
if (scale_x != 1.0f || scale_y != 1.0f) {
SDL_Rect r;
@@ -308,22 +308,22 @@ 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_BlitSurfaceScaled(src, srcrect, surface, &r, scaleMode);
result = SDL_BlitSurfaceScaled(src, srcrect, surface, &r, scaleMode);
} else {
retval = SDL_BlitSurface(src, srcrect, surface, dstrect);
result = SDL_BlitSurface(src, srcrect, surface, dstrect);
}
return retval;
return result;
}
static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Texture *texture,
const SDL_Rect *srcrect, const SDL_Rect *final_rect,
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y)
static bool SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Texture *texture,
const SDL_Rect *srcrect, const SDL_Rect *final_rect,
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y)
{
SDL_Surface *src = (SDL_Surface *)texture->internal;
SDL_Rect tmp_rect;
SDL_Surface *src_clone, *src_rotated, *src_scaled;
SDL_Surface *mask = NULL, *mask_rotated = NULL;
int retval = 0;
bool result = true;
SDL_BlendMode blendmode;
Uint8 alphaMod, rMod, gMod, bMod;
int applyModulation = false;
@@ -331,7 +331,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
int isOpaque = false;
if (!SDL_SurfaceValid(surface)) {
return -1;
return false;
}
tmp_rect.x = 0;
@@ -343,8 +343,8 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
* necessary because this code is going to access the pixel buffer directly.
*/
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
return -1;
if (!SDL_LockSurface(src)) {
return false;
}
}
@@ -356,7 +356,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
if (SDL_MUSTLOCK(src)) {
SDL_UnlockSurface(src);
}
return -1;
return false;
}
SDL_GetSurfaceBlendMode(src, &blendmode);
@@ -396,7 +396,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) {
mask = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
if (!mask) {
retval = -1;
result = false;
} else {
SDL_SetSurfaceBlendMode(mask, SDL_BLENDMODE_MOD);
}
@@ -405,14 +405,14 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
/* Create a new surface should there be a format mismatch or if scaling, cropping,
* or modulation is required. It's possible to use the source surface directly otherwise.
*/
if (!retval && (blitRequired || applyModulation)) {
if (result && (blitRequired || applyModulation)) {
SDL_Rect scale_rect = tmp_rect;
src_scaled = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888);
if (!src_scaled) {
retval = -1;
result = false;
} else {
SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE);
retval = SDL_BlitSurfaceScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode);
result = SDL_BlitSurfaceScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode);
SDL_DestroySurface(src_clone);
src_clone = src_scaled;
src_scaled = NULL;
@@ -422,7 +422,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
// SDLgfx_rotateSurface is going to make decisions depending on the blend mode.
SDL_SetSurfaceBlendMode(src_clone, blendmode);
if (!retval) {
if (result) {
SDL_Rect rect_dest;
double cangle, sangle;
@@ -432,18 +432,18 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
(texture->scaleMode == SDL_SCALEMODE_NEAREST) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL,
&rect_dest, cangle, sangle, center);
if (!src_rotated) {
retval = -1;
result = false;
}
if (!retval && mask) {
if (result && mask) {
// The mask needed for the NONE blend mode gets rotated with the same parameters.
mask_rotated = SDLgfx_rotateSurface(mask, angle,
false, 0, 0,
&rect_dest, cangle, sangle, center);
if (!mask_rotated) {
retval = -1;
result = false;
}
}
if (!retval) {
if (result) {
tmp_rect.x = final_rect->x + rect_dest.x;
tmp_rect.y = final_rect->y + rect_dest.y;
@@ -460,7 +460,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
SDL_SetSurfaceColorMod(src_rotated, rMod, gMod, bMod);
}
// Renderer scaling, if needed
retval = Blit_to_Screen(src_rotated, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode);
result = Blit_to_Screen(src_rotated, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode);
} else {
/* The NONE blend mode requires three steps to get the pixels onto the destination surface.
* First, the area where the rotated pixels will be blitted to get set to zero.
@@ -470,8 +470,8 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
SDL_Rect mask_rect = tmp_rect;
SDL_SetSurfaceBlendMode(mask_rotated, SDL_BLENDMODE_NONE);
// Renderer scaling, if needed
retval = Blit_to_Screen(mask_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode);
if (!retval) {
result = Blit_to_Screen(mask_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode);
if (result) {
/* The next step copies the alpha value. This is done with the BLEND blend mode and
* by modulating the source colors with 0. Since the destination is all zeros, this
* will effectively set the destination alpha to the source alpha.
@@ -479,8 +479,8 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
SDL_SetSurfaceColorMod(src_rotated, 0, 0, 0);
mask_rect = tmp_rect;
// Renderer scaling, if needed
retval = Blit_to_Screen(src_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode);
if (!retval) {
result = Blit_to_Screen(src_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode);
if (result) {
/* The last step gets the color values in place. The ADD blend mode simply adds them to
* the destination (where the color values are all zero). However, because the ADD blend
* mode modulates the colors with the alpha channel, a surface without an alpha mask needs
@@ -488,11 +488,11 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
*/
SDL_Surface *src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->w, src_rotated->h, src_rotated->format, src_rotated->pixels, src_rotated->pitch);
if (!src_rotated_rgb) {
retval = -1;
result = false;
} else {
SDL_SetSurfaceBlendMode(src_rotated_rgb, SDL_BLENDMODE_ADD);
// Renderer scaling, if needed
retval = Blit_to_Screen(src_rotated_rgb, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode);
result = Blit_to_Screen(src_rotated_rgb, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode);
SDL_DestroySurface(src_rotated_rgb);
}
}
@@ -514,7 +514,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex
if (src_clone) {
SDL_DestroySurface(src_clone);
}
return retval;
return result;
}
typedef struct GeometryFillData
@@ -530,7 +530,7 @@ typedef struct GeometryCopyData
SDL_Color color;
} GeometryCopyData;
static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
static bool SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride,
int num_vertices, const void *indices, int num_indices, int size_indices,
float scale_x, float scale_y)
@@ -543,7 +543,7 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_
verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
if (!verts) {
return -1;
return false;
}
cmd->data.draw.count = count;
@@ -617,7 +617,7 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_
ptr++;
}
}
return 0;
return true;
}
static void PrepTextureForCopy(const SDL_RenderCommand *cmd, SW_DrawStateCache *drawstate)
@@ -671,13 +671,13 @@ static void SW_InvalidateCachedState(SDL_Renderer *renderer)
}
static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
static bool SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
{
SDL_Surface *surface = SW_ActivateRenderer(renderer);
SW_DrawStateCache drawstate;
if (!SDL_SurfaceValid(surface)) {
return -1;
return false;
}
drawstate.viewport = NULL;
@@ -960,7 +960,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo
cmd = cmd->next;
}
return 0;
return true;
}
static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
@@ -989,12 +989,12 @@ static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
return SDL_DuplicatePixels(rect->w, rect->h, surface->format, SDL_COLORSPACE_SRGB, pixels, surface->pitch);
}
static int SW_RenderPresent(SDL_Renderer *renderer)
static bool SW_RenderPresent(SDL_Renderer *renderer)
{
SDL_Window *window = renderer->window;
if (!window) {
return -1;
return false;
}
return SDL_UpdateWindowSurface(window);
}
@@ -1112,7 +1112,7 @@ static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormat format)
}
}
int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props)
bool SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props)
{
SW_RenderData *data;
@@ -1124,7 +1124,7 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD
data = (SW_RenderData *)SDL_calloc(1, sizeof(*data));
if (!data) {
return -1;
return false;
}
data->surface = surface;
data->window = surface;
@@ -1164,10 +1164,10 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD
return SDL_SetError("Unsupported output colorspace");
}
return 0;
return true;
}
static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props)
static bool SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props)
{
// Set the vsync hint based on our flags, if it's not already set
const char *hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
@@ -1189,7 +1189,7 @@ static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro
}
if (!SDL_SurfaceValid(surface)) {
return -1;
return false;
}
return SW_CreateRendererForSurface(renderer, surface, create_props);

View File

@@ -22,6 +22,6 @@
#ifndef SDL_render_sw_c_h_
#define SDL_render_sw_c_h_
extern int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props);
extern bool SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props);
#endif // SDL_render_sw_c_h_

View File

@@ -501,7 +501,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
}
if (SDL_SurfaceHasColorKey(src)) {
if (SDL_GetSurfaceColorKey(src, &colorkey) == 0) {
if (SDL_GetSurfaceColorKey(src, &colorkey)) {
colorKeyAvailable = true;
}
}
@@ -561,7 +561,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in
// Lock source surface
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
if (!SDL_LockSurface(src)) {
SDL_DestroySurface(rz_dst);
return NULL;
}

View File

@@ -45,13 +45,13 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
SDL_Color c0, SDL_Color c1, SDL_Color c2, bool is_uniform, SDL_TextureAddressMode texture_address_mode);
#if 0
int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3])
bool SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3])
{
int i;
SDL_Point points[6];
if (src == NULL || dst == NULL) {
return -1;
return false;
}
for (i = 0; i < 3; i++) {
@@ -72,12 +72,12 @@ int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface
return SDL_SW_BlitTriangle(src, dst, points);
}
int SDL_FillTriangle(SDL_Surface *dst, const SDL_Point points[3], Uint32 color)
bool SDL_FillTriangle(SDL_Surface *dst, const SDL_Point points[3], Uint32 color)
{
int i;
SDL_Point points_tmp[3];
if (dst == NULL) {
return -1;
return false;
}
for (i = 0; i < 3; i++) {
points_tmp[i] = points[i];
@@ -94,24 +94,24 @@ static Sint64 cross_product(const SDL_Point *a, const SDL_Point *b, int c_x, int
}
// check for top left rules
static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
static bool is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
{
if (is_clockwise) {
if (a->y == b->y && a->x < b->x) {
return 1;
return true;
}
if (b->y < a->y) {
return 1;
return true;
}
} else {
if (a->y == b->y && b->x < a->x) {
return 1;
return true;
}
if (a->y < b->y) {
return 1;
return true;
}
}
return 0;
return false;
}
// x = (y << FP_BITS)
@@ -223,9 +223,9 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin
} \
}
int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2)
bool SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2)
{
int ret = 0;
bool result = true;
int dst_locked = 0;
SDL_Rect dstrect;
@@ -246,7 +246,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
SDL_Surface *tmp = NULL;
if (!SDL_SurfaceValid(dst)) {
return -1;
return false;
}
area = cross_product(d0, d1, d2->x, d2->y);
@@ -255,13 +255,13 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
// Flat triangle
if (area == 0) {
return 0;
return true;
}
// Lock the destination, if needed
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
ret = -1;
if (!SDL_LockSurface(dst)) {
result = false;
goto end;
} else {
dst_locked = 1;
@@ -298,7 +298,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin
// Use an intermediate surface
tmp = SDL_CreateSurface(dstrect.w, dstrect.h, format);
if (!tmp) {
ret = -1;
result = false;
goto end;
}
@@ -456,10 +456,10 @@ end:
SDL_UnlockSurface(dst);
}
return ret;
return result;
}
int SDL_SW_BlitTriangle(
bool SDL_SW_BlitTriangle(
SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
@@ -467,8 +467,8 @@ int SDL_SW_BlitTriangle(
SDL_Color c0, SDL_Color c1, SDL_Color c2,
SDL_TextureAddressMode texture_address_mode)
{
bool result = true;
SDL_Surface *src_surface = src;
int ret = 0;
int src_locked = 0;
int dst_locked = 0;
@@ -509,13 +509,13 @@ int SDL_SW_BlitTriangle(
// Flat triangle
if (area == 0) {
return 0;
return true;
}
// Lock the destination, if needed
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
ret = -1;
if (!SDL_LockSurface(dst)) {
result = false;
goto end;
} else {
dst_locked = 1;
@@ -524,8 +524,8 @@ int SDL_SW_BlitTriangle(
// Lock the source, if needed
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
ret = -1;
if (!SDL_LockSurface(src)) {
result = false;
goto end;
} else {
src_locked = 1;
@@ -648,14 +648,14 @@ int SDL_SW_BlitTriangle(
if (tmp64 >= INT_MIN && tmp64 <= INT_MAX) {
s2_x_area.x = (int)tmp64;
} else {
ret = SDL_SetError("triangle area overflow");
result = SDL_SetError("triangle area overflow");
goto end;
}
tmp64 = s2->y * area;
if (tmp64 >= INT_MIN && tmp64 <= INT_MAX) {
s2_x_area.y = (int)tmp64;
} else {
ret = SDL_SetError("triangle area overflow");
result = SDL_SetError("triangle area overflow");
goto end;
}
@@ -706,7 +706,7 @@ int SDL_SW_BlitTriangle(
#define CHECK_INT_RANGE(X) \
if ((X) < INT_MIN || (X) > INT_MAX) { \
ret = SDL_SetError("integer overflow (%s = %" SDL_PRIs64 ")", #X, X); \
result = SDL_SetError("integer overflow (%s = %" SDL_PRIs64 ")", #X, X); \
goto end; \
}
CHECK_INT_RANGE(area);
@@ -765,7 +765,7 @@ end:
SDL_UnlockSurface(src);
}
return ret;
return result;
}
#define FORMAT_ALPHA 0

View File

@@ -26,17 +26,16 @@
#include "../SDL_sysrender.h" // For SDL_TextureAddressMode
extern int SDL_SW_FillTriangle(SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
extern bool SDL_SW_FillTriangle(SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
extern int SDL_SW_BlitTriangle(
SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_Color c0, SDL_Color c1, SDL_Color c2,
SDL_TextureAddressMode texture_address_mode);
extern bool SDL_SW_BlitTriangle(SDL_Surface *src,
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
SDL_Surface *dst,
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
SDL_Color c0, SDL_Color c1, SDL_Color c2,
SDL_TextureAddressMode texture_address_mode);
extern void trianglepoint_2_fixedpoint(SDL_Point *a);