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

@@ -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, const SDL_Rect *srcrect,
SDL_Surface *surf_dst, const SDL_Rect *dstrect)
static bool SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
SDL_Surface *surf_dst, const SDL_Rect *dstrect)
{
Uint8 *dstbuf;
Uint8 *srcbuf;
@@ -453,8 +453,8 @@ static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect,
// Lock the destination if necessary
if (SDL_MUSTLOCK(surf_dst)) {
if (SDL_LockSurface(surf_dst) < 0) {
return -1;
if (!SDL_LockSurface(surf_dst)) {
return false;
}
}
@@ -548,7 +548,7 @@ done:
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return 0;
return true;
}
#undef OPAQUE_BLIT
@@ -697,8 +697,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, const SDL_Rect *srcrect,
SDL_Surface *surf_dst, const SDL_Rect *dstrect)
static bool 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;
@@ -707,8 +707,8 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcre
// Lock the destination if necessary
if (SDL_MUSTLOCK(surf_dst)) {
if (SDL_LockSurface(surf_dst) < 0) {
return -1;
if (!SDL_LockSurface(surf_dst)) {
return false;
}
}
@@ -849,7 +849,7 @@ done:
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return 0;
return true;
}
/*
@@ -988,7 +988,7 @@ static int uncopy_32(Uint32 *dst, const void *src, int n,
((unsigned)((((pixel)&fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
// convert surface to be quickly alpha-blittable onto dest, if possible
static int RLEAlphaSurface(SDL_Surface *surface)
static bool RLEAlphaSurface(SDL_Surface *surface)
{
SDL_Surface *dest;
const SDL_PixelFormatDetails *df;
@@ -1004,11 +1004,11 @@ static int RLEAlphaSurface(SDL_Surface *surface)
dest = surface->internal->map.info.dst_surface;
if (!dest) {
return -1;
return false;
}
df = dest->internal->format;
if (surface->internal->format->bits_per_pixel != 32) {
return -1; // only 32bpp source supported
return false; // only 32bpp source supported
}
/* find out whether the destination is one we support,
@@ -1023,7 +1023,7 @@ static int RLEAlphaSurface(SDL_Surface *surface)
copy_opaque = copy_opaque_16;
copy_transl = copy_transl_565;
} else {
return -1;
return false;
}
break;
case 0x7fff:
@@ -1031,11 +1031,11 @@ static int RLEAlphaSurface(SDL_Surface *surface)
copy_opaque = copy_opaque_16;
copy_transl = copy_transl_555;
} else {
return -1;
return false;
}
break;
default:
return -1;
return false;
}
max_opaque_run = 255; // runs stored as bytes
@@ -1045,7 +1045,7 @@ static int RLEAlphaSurface(SDL_Surface *surface)
break;
case 4:
if (masksum != 0x00ffffff) {
return -1; // requires unused high byte
return false; // requires unused high byte
}
copy_opaque = copy_32;
copy_transl = copy_32;
@@ -1055,13 +1055,13 @@ static int RLEAlphaSurface(SDL_Surface *surface)
maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4;
break;
default:
return -1; // anything else unsupported right now
return false; // anything else unsupported right now
}
maxsize += sizeof(SDL_PixelFormat);
rlebuf = (Uint8 *)SDL_malloc(maxsize);
if (!rlebuf) {
return -1;
return false;
}
// save the destination format so we can undo the encoding later
*(SDL_PixelFormat *)rlebuf = df->format;
@@ -1197,7 +1197,7 @@ static int RLEAlphaSurface(SDL_Surface *surface)
surface->internal->map.data = p;
}
return 0;
return true;
}
static Uint32 getpix_8(const Uint8 *srcbuf)
@@ -1230,7 +1230,7 @@ static const getpix_func getpixes[4] = {
getpix_8, getpix_16, getpix_24, getpix_32
};
static int RLEColorkeySurface(SDL_Surface *surface)
static bool RLEColorkeySurface(SDL_Surface *surface)
{
Uint8 *rlebuf, *dst;
int maxn;
@@ -1260,12 +1260,12 @@ static int RLEColorkeySurface(SDL_Surface *surface)
break;
default:
return -1;
return false;
}
rlebuf = (Uint8 *)SDL_malloc(maxsize);
if (!rlebuf) {
return -1;
return false;
}
// Set up the conversion
@@ -1365,10 +1365,10 @@ static int RLEColorkeySurface(SDL_Surface *surface)
surface->internal->map.data = p;
}
return 0;
return true;
}
int SDL_RLESurface(SDL_Surface *surface)
bool SDL_RLESurface(SDL_Surface *surface)
{
int flags;
@@ -1379,12 +1379,12 @@ int SDL_RLESurface(SDL_Surface *surface)
// We don't support RLE encoding of bitmaps
if (SDL_BITSPERPIXEL(surface->format) < 8) {
return -1;
return false;
}
// Make sure the pixels are available
if (!surface->pixels) {
return -1;
return false;
}
flags = surface->internal->map.info.flags;
@@ -1394,7 +1394,7 @@ int SDL_RLESurface(SDL_Surface *surface)
// ok
} else {
// If we don't have colorkey or blending, nothing to do...
return -1;
return false;
}
// Pass on combinations not supported
@@ -1402,22 +1402,22 @@ int SDL_RLESurface(SDL_Surface *surface)
((flags & SDL_COPY_MODULATE_ALPHA) && SDL_ISPIXELFORMAT_ALPHA(surface->format)) ||
(flags & (SDL_COPY_BLEND_PREMULTIPLIED | SDL_COPY_ADD | SDL_COPY_ADD_PREMULTIPLIED | SDL_COPY_MOD | SDL_COPY_MUL)) ||
(flags & SDL_COPY_NEAREST)) {
return -1;
return false;
}
// Encode and set up the blit
if (!SDL_ISPIXELFORMAT_ALPHA(surface->format) || !(flags & SDL_COPY_BLEND)) {
if (!surface->internal->map.identity) {
return -1;
return false;
}
if (RLEColorkeySurface(surface) < 0) {
return -1;
if (!RLEColorkeySurface(surface)) {
return false;
}
surface->internal->map.blit = SDL_RLEBlit;
surface->internal->map.info.flags |= SDL_COPY_RLE_COLORKEY;
} else {
if (RLEAlphaSurface(surface) < 0) {
return -1;
if (!RLEAlphaSurface(surface)) {
return false;
}
surface->internal->map.blit = SDL_RLEAlphaBlit;
surface->internal->map.info.flags |= SDL_COPY_RLE_ALPHAKEY;
@@ -1426,7 +1426,7 @@ int SDL_RLESurface(SDL_Surface *surface)
// The surface is now accelerated
surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL;
return 0;
return true;
}
/*

View File

@@ -26,7 +26,7 @@
// Useful functions and variables from SDL_RLEaccel.c
extern int SDL_RLESurface(SDL_Surface *surface);
extern bool SDL_RLESurface(SDL_Surface *surface);
extern void SDL_UnRLESurface(SDL_Surface *surface, bool recode);
#endif // SDL_RLEaccel_c_h_

View File

@@ -29,21 +29,21 @@
#include "SDL_pixels_c.h"
// The general purpose software blit routine
static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
static bool SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect)
{
int okay;
bool okay;
int src_locked;
int dst_locked;
// Everything is okay at the beginning...
okay = 1;
okay = true;
// Lock the destination if it's in hardware
dst_locked = 0;
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
okay = 0;
if (!SDL_LockSurface(dst)) {
okay = false;
} else {
dst_locked = 1;
}
@@ -51,8 +51,8 @@ static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
// Lock the source if it's in hardware
src_locked = 0;
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
okay = 0;
if (!SDL_LockSurface(src)) {
okay = false;
} else {
src_locked = 1;
}
@@ -94,7 +94,7 @@ static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_UnlockSurface(src);
}
// Blit is done!
return okay ? 0 : -1;
return okay;
}
#if SDL_HAVE_BLIT_AUTO
@@ -176,7 +176,7 @@ static SDL_BlitFunc SDL_ChooseBlitFunc(SDL_PixelFormat src_format, SDL_PixelForm
#endif // SDL_HAVE_BLIT_AUTO
// Figure out which of many blit routines to set up on a surface
int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst)
bool SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst)
{
SDL_BlitFunc blit = NULL;
SDL_BlitMap *map = &surface->internal->map;
@@ -207,8 +207,8 @@ int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst)
#if SDL_HAVE_RLE
// See if we can do RLE acceleration
if (map->info.flags & SDL_COPY_RLE_DESIRED) {
if (SDL_RLESurface(surface) == 0) {
return 0;
if (SDL_RLESurface(surface)) {
return true;
}
}
#endif
@@ -286,5 +286,5 @@ int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst)
return SDL_SetError("Blit combination not supported");
}
return 0;
return true;
}

View File

@@ -89,7 +89,7 @@ typedef struct
SDL_BlitFunc func;
} SDL_BlitFuncEntry;
typedef int (SDLCALL *SDL_Blit) (struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect);
typedef bool (SDLCALL *SDL_Blit) (struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect);
// Blit mapping definition
typedef struct SDL_BlitMap
@@ -106,7 +106,7 @@ typedef struct SDL_BlitMap
} SDL_BlitMap;
// Functions found in SDL_blit.c
extern int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst);
extern bool SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst);
/* Functions found in SDL_blit_*.c */
extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface);

View File

@@ -591,7 +591,7 @@ SDL_Surface *SDL_LoadBMP(const char *file)
return SDL_LoadBMP_IO(SDL_IOFromFile(file, "rb"), 1);
}
int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
SDL_bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
{
bool was_error = true;
Sint64 fp_offset, new_offset;
@@ -696,7 +696,7 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio)
saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, false);
}
if (SDL_LockSurface(intermediate_surface) == 0) {
if (SDL_LockSurface(intermediate_surface)) {
const size_t bw = intermediate_surface->w * intermediate_surface->internal->format->bytes_per_pixel;
// Set the BMP file header values
@@ -860,17 +860,17 @@ done:
SDL_DestroySurface(intermediate_surface);
}
if (closeio && dst) {
if (SDL_CloseIO(dst) < 0) {
if (!SDL_CloseIO(dst)) {
was_error = true;
}
}
if (was_error) {
return -1;
return false;
}
return 0;
return true;
}
int SDL_SaveBMP(SDL_Surface *surface, const char *file)
SDL_bool SDL_SaveBMP(SDL_Surface *surface, const char *file)
{
return SDL_SaveBMP_IO(surface, SDL_IOFromFile(file, "wb"), 1);
return SDL_SaveBMP_IO(surface, SDL_IOFromFile(file, "wb"), true);
}

View File

@@ -53,7 +53,7 @@ void SDL_CancelClipboardData(Uint32 sequence)
_this->clipboard_userdata = NULL;
}
int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types)
SDL_bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
size_t i;
@@ -70,7 +70,7 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu
if (!callback && !_this->clipboard_callback) {
// Nothing to do, don't modify the system clipboard
return 0;
return true;
}
SDL_CancelClipboardData(_this->clipboard_sequence);
@@ -97,14 +97,14 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu
}
if (num_allocated < num_mime_types) {
SDL_ClearClipboardData();
return -1;
return false;
}
_this->num_clipboard_mime_types = num_mime_types;
}
if (_this->SetClipboardData) {
if (_this->SetClipboardData(_this) < 0) {
return -1;
if (!_this->SetClipboardData(_this)) {
return false;
}
} else if (_this->SetClipboardText) {
char *text = NULL;
@@ -118,9 +118,9 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu
text = (char *)SDL_malloc(size + 1);
SDL_memcpy(text, data, size);
text[size] = '\0';
if (_this->SetClipboardText(_this, text) < 0) {
if (!_this->SetClipboardText(_this, text)) {
SDL_free(text);
return -1;
return false;
}
break;
}
@@ -129,17 +129,17 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu
if (text) {
SDL_free(text);
} else {
if (_this->SetClipboardText(_this, "") < 0) {
return -1;
if (!_this->SetClipboardText(_this, "")) {
return false;
}
}
}
SDL_SendClipboardUpdate();
return 0;
return true;
}
int SDL_ClearClipboardData(void)
SDL_bool SDL_ClearClipboardData(void)
{
return SDL_SetClipboardData(NULL, NULL, NULL, NULL, 0);
}
@@ -264,7 +264,7 @@ const void * SDLCALL SDL_ClipboardTextCallback(void *userdata, const char *mime_
return text;
}
int SDL_SetClipboardText(const char *text)
SDL_bool SDL_SetClipboardText(const char *text)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
size_t num_mime_types;
@@ -332,7 +332,7 @@ SDL_bool SDL_HasClipboardText(void)
// Primary selection text
int SDL_SetPrimarySelectionText(const char *text)
SDL_bool SDL_SetPrimarySelectionText(const char *text)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@@ -344,8 +344,8 @@ int SDL_SetPrimarySelectionText(const char *text)
text = "";
}
if (_this->SetPrimarySelectionText) {
if (_this->SetPrimarySelectionText(_this, text) < 0) {
return -1;
if (!_this->SetPrimarySelectionText(_this, text)) {
return false;
}
} else {
SDL_free(_this->primary_selection_text);
@@ -353,7 +353,7 @@ int SDL_SetPrimarySelectionText(const char *text)
}
SDL_SendClipboardUpdate();
return 0;
return true;
}
char *SDL_GetPrimarySelectionText(void)

View File

@@ -162,7 +162,7 @@ static const char *SDL_EGL_GetErrorName(EGLint eglErrorCode)
return "";
}
int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode)
bool SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode)
{
const char *errorText = SDL_EGL_GetErrorName(eglErrorCode);
char altErrorText[32];
@@ -250,29 +250,29 @@ bool SDL_EGL_HasExtension(SDL_VideoDevice *_this, SDL_EGL_ExtensionType type, co
SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(SDL_VideoDevice *_this, const char *proc)
{
SDL_FunctionPointer retval = NULL;
SDL_FunctionPointer result = NULL;
if (_this->egl_data) {
const Uint32 eglver = (((Uint32)_this->egl_data->egl_version_major) << 16) | ((Uint32)_this->egl_data->egl_version_minor);
const bool is_egl_15_or_later = eglver >= ((((Uint32)1) << 16) | 5);
// EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points.
if (!retval && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
if (!result && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
result = _this->egl_data->eglGetProcAddress(proc);
}
#if !defined(SDL_PLATFORM_EMSCRIPTEN) && !defined(SDL_VIDEO_DRIVER_VITA) // LoadFunction isn't needed on Emscripten and will call dlsym(), causing other problems.
// Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5.
if (!retval) {
retval = SDL_LoadFunction(_this->egl_data->opengl_dll_handle, proc);
if (!result) {
result = SDL_LoadFunction(_this->egl_data->opengl_dll_handle, proc);
}
#endif
// Try eglGetProcAddress if we're on <= 1.4 and still searching...
if (!retval && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
retval = _this->egl_data->eglGetProcAddress(proc);
if (!result && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) {
result = _this->egl_data->eglGetProcAddress(proc);
}
}
return retval;
return result;
}
void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this)
@@ -297,7 +297,7 @@ void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this)
}
}
static int SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_path)
static bool SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_path)
{
void *egl_dll_handle = NULL, *opengl_dll_handle = NULL;
const char *path = NULL;
@@ -465,10 +465,10 @@ static int SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_p
*_this->gl_config.driver_path = '\0';
}
return 0;
return true;
}
int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path)
bool SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path)
{
if (_this->egl_data) {
return SDL_SetError("EGL context already created");
@@ -476,15 +476,15 @@ int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path)
_this->egl_data = (struct SDL_EGL_VideoData *)SDL_calloc(1, sizeof(SDL_EGL_VideoData));
if (!_this->egl_data) {
return -1;
return false;
}
if (SDL_EGL_LoadLibraryInternal(_this, egl_path) < 0) {
if (!SDL_EGL_LoadLibraryInternal(_this, egl_path)) {
SDL_free(_this->egl_data);
_this->egl_data = NULL;
return -1;
return false;
}
return 0;
return true;
}
static void SDL_EGL_GetVersion(SDL_VideoDevice *_this)
@@ -503,7 +503,7 @@ static void SDL_EGL_GetVersion(SDL_VideoDevice *_this)
}
}
int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
bool SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisplayType native_display, EGLenum platform)
{
int library_load_retcode = SDL_EGL_LoadLibraryOnly(_this, egl_path);
if (library_load_retcode != 0) {
@@ -572,7 +572,7 @@ int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisp
_this->egl_data->is_offscreen = false;
return 0;
return true;
}
/**
@@ -583,7 +583,7 @@ int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisp
valid available GPU for EGL to use.
*/
int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device)
bool SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device)
{
void *egl_devices[SDL_EGL_MAX_DEVICES];
EGLint num_egl_devices = 0;
@@ -658,7 +658,7 @@ int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device)
_this->egl_data->is_offscreen = true;
return 0;
return true;
}
void SDL_EGL_SetRequiredVisualId(SDL_VideoDevice *_this, int visual_id)
@@ -727,7 +727,7 @@ static void dumpconfig(SDL_VideoDevice *_this, EGLConfig config)
#endif // DUMP_EGL_CONFIG
static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_caveat_none)
static bool SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_caveat_none)
{
// 64 seems nice.
EGLint attribs[64];
@@ -825,7 +825,7 @@ static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_c
configs, SDL_arraysize(configs),
&found_configs) == EGL_FALSE ||
found_configs == 0) {
return -1;
return false;
}
// first ensure that a found config has a matching format, or the function will fall through.
@@ -922,10 +922,10 @@ static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_c
dumpconfig(_this, _this->egl_data->egl_config);
#endif
return 0;
return true;
}
int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this)
bool SDL_EGL_ChooseConfig(SDL_VideoDevice *_this)
{
int ret;
@@ -936,14 +936,14 @@ int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this)
// Try with EGL_CONFIG_CAVEAT set to EGL_NONE, to avoid any EGL_SLOW_CONFIG or EGL_NON_CONFORMANT_CONFIG
ret = SDL_EGL_PrivateChooseConfig(_this, true);
if (ret == 0) {
return 0;
return true;
}
// Fallback with all configs
ret = SDL_EGL_PrivateChooseConfig(_this, false);
if (ret == 0) {
SDL_Log("SDL_EGL_ChooseConfig: found a slow EGL config");
return 0;
return true;
}
return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig");
@@ -1085,9 +1085,9 @@ SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surfa
_this->egl_data->egl_swapinterval = 0;
if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) {
if (!SDL_EGL_MakeCurrent(_this, egl_surface, egl_context)) {
// Delete the context
SDL_EGL_DeleteContext(_this, egl_context);
SDL_EGL_DestroyContext(_this, egl_context);
return NULL;
}
@@ -1122,7 +1122,7 @@ SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surfa
return (SDL_GLContext)egl_context;
}
int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context)
bool SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context)
{
EGLContext egl_context = (EGLContext)context;
@@ -1133,7 +1133,7 @@ int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLCo
if (!_this->egl_data->eglMakeCurrent) {
if (!egl_surface && !context) {
// Can't do the nothing there is to do? Probably trying to cleanup a failed startup, just return.
return 0;
return true;
} else {
return SDL_SetError("EGL not initialized"); // something clearly went wrong somewhere.
}
@@ -1156,10 +1156,10 @@ int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLCo
}
}
return 0;
return true;
}
int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
bool SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{
EGLBoolean status;
@@ -1177,43 +1177,43 @@ int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval);
if (status == EGL_TRUE) {
_this->egl_data->egl_swapinterval = interval;
return 0;
return true;
}
return SDL_EGL_SetError("Unable to set the EGL swap interval", "eglSwapInterval");
}
int SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
bool SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
{
if (!_this->egl_data) {
return SDL_SetError("EGL not initialized");
}
*interval = _this->egl_data->egl_swapinterval;
return 0;
return true;
}
int SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface)
bool SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface)
{
if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) {
return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers");
}
return 0;
return true;
}
int SDL_EGL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
bool SDL_EGL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
EGLContext egl_context = (EGLContext)context;
// Clean up GLES and EGL
if (!_this->egl_data) {
return 0;
return true;
}
if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
_this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
}
return 0;
return true;
}
EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, NativeWindowType nw)
@@ -1228,7 +1228,7 @@ EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, Nat
EGLSurface surface;
if (SDL_EGL_ChooseConfig(_this) < 0) {
if (!SDL_EGL_ChooseConfig(_this)) {
return EGL_NO_SURFACE;
}
@@ -1319,7 +1319,7 @@ SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height)
attributes[1] = width;
attributes[3] = height;
if (SDL_EGL_ChooseConfig(_this) < 0) {
if (!SDL_EGL_ChooseConfig(_this)) {
return EGL_NO_SURFACE;
}

View File

@@ -116,53 +116,53 @@ typedef enum SDL_EGL_ExtensionType
extern bool SDL_EGL_HasExtension(SDL_VideoDevice *_this, SDL_EGL_ExtensionType type, const char *ext);
extern int SDL_EGL_GetAttribute(SDL_VideoDevice *_this, SDL_GLattr attrib, int *value);
extern bool SDL_EGL_GetAttribute(SDL_VideoDevice *_this, SDL_GLattr attrib, int *value);
/* SDL_EGL_LoadLibrary can get a display for a specific platform (EGL_PLATFORM_*)
* or, if 0 is passed, let the implementation decide.
*/
extern int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *path);
extern int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *path, NativeDisplayType native_display, EGLenum platform);
extern bool SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *path);
extern bool SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *path, NativeDisplayType native_display, EGLenum platform);
extern SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(SDL_VideoDevice *_this, const char *proc);
extern void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this);
extern void SDL_EGL_SetRequiredVisualId(SDL_VideoDevice *_this, int visual_id);
extern int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this);
extern int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern int SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
extern int SDL_EGL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern bool SDL_EGL_ChooseConfig(SDL_VideoDevice *_this);
extern bool SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern bool SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
extern bool SDL_EGL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, NativeWindowType nw);
extern void SDL_EGL_DestroySurface(SDL_VideoDevice *_this, EGLSurface egl_surface);
extern EGLSurface SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height);
// Assumes that LoadLibraryOnly() has succeeded
extern int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device);
extern bool SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device);
// These need to be wrapped to get the surface for the window by the platform GLES implementation
extern SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surface);
extern int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context);
extern int SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface);
extern bool SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context);
extern bool SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface);
// SDL Error-reporting
extern int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode);
extern bool SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode);
#define SDL_EGL_SetError(message, eglFunctionName) SDL_EGL_SetErrorEx(message, eglFunctionName, _this->egl_data->eglGetError())
// A few of useful macros
#define SDL_EGL_SwapWindow_impl(BACKEND) \
int BACKEND##_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) \
bool BACKEND##_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) \
{ \
return SDL_EGL_SwapBuffers(_this, window->internal->egl_surface); \
return SDL_EGL_SwapBuffers(_this, window->internal->egl_surface); \
}
#define SDL_EGL_MakeCurrent_impl(BACKEND) \
int BACKEND##_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) \
{ \
#define SDL_EGL_MakeCurrent_impl(BACKEND) \
bool BACKEND##_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) \
{ \
return SDL_EGL_MakeCurrent(_this, window ? window->internal->egl_surface : EGL_NO_SURFACE, context); \
}
#define SDL_EGL_CreateContext_impl(BACKEND) \
SDL_GLContext BACKEND##_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) \
SDL_GLContext BACKEND##_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) \
{ \
return SDL_EGL_CreateContext(_this, window->internal->egl_surface); \
return SDL_EGL_CreateContext(_this, window->internal->egl_surface); \
}
#endif // SDL_VIDEO_OPENGL_EGL

View File

@@ -229,7 +229,7 @@ static void SDL_FillSurfaceRect4(Uint8 *pixels, int pitch, Uint32 color, int w,
/*
* This function performs a fast fill of the given rectangle with 'color'
*/
int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
SDL_bool SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
{
if (!SDL_SurfaceValid(dst)) {
return SDL_InvalidParamError("SDL_FillSurfaceRect(): dst");
@@ -240,15 +240,14 @@ int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
rect = &dst->internal->clip_rect;
// Don't attempt to fill if the surface's clip_rect is empty
if (SDL_RectEmpty(rect)) {
return 0;
return true;
}
}
return SDL_FillSurfaceRects(dst, rect, 1, color);
}
int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
Uint32 color)
SDL_bool SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
{
SDL_Rect clipped;
Uint8 *pixels;
@@ -262,7 +261,7 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
// Nothing to do
if (dst->w == 0 || dst->h == 0) {
return 0;
return true;
}
// Perform software fill
@@ -284,7 +283,7 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
if (SDL_BITSPERPIXEL(dst->format) == 4) {
Uint8 b = (((Uint8)color << 4) | (Uint8)color);
SDL_memset(dst->pixels, b, (size_t)dst->h * dst->pitch);
return 1;
return true;
}
}
}
@@ -359,5 +358,5 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count,
}
// We're done!
return 0;
return true;
}

View File

@@ -165,7 +165,7 @@ const char *SDL_GetPixelFormatName(SDL_PixelFormat format)
}
#undef CASE
int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
SDL_bool SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask)
{
Uint32 masks[4];
@@ -184,7 +184,7 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask,
default:
*bpp = 0; // oh well.
}
return 0;
return true;
}
#else
if (SDL_ISPIXELFORMAT_FOURCC(format)) {
@@ -210,7 +210,7 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask,
*Gmask = 0x0000FF00;
*Bmask = 0x00FF0000;
#endif
return 0;
return true;
}
if (format == SDL_PIXELFORMAT_BGR24) {
@@ -223,14 +223,14 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask,
*Gmask = 0x0000FF00;
*Bmask = 0x000000FF;
#endif
return 0;
return true;
}
if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 &&
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 &&
SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) {
// Not a format that uses masks
return 0;
return true;
}
switch (SDL_PIXELLAYOUT(format)) {
@@ -334,7 +334,7 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask,
default:
return SDL_SetError("Unknown pixel format");
}
return 0;
return true;
}
SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
@@ -578,14 +578,14 @@ SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask,
static SDL_HashTable *SDL_format_details;
static SDL_Mutex *SDL_format_details_lock;
static int SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_PixelFormat format)
static SDL_bool SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_PixelFormat format)
{
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Uint32 mask;
if (SDL_GetMasksForPixelFormat(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) < 0) {
return -1;
if (!SDL_GetMasksForPixelFormat(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
return false;
}
// Set up the format
@@ -642,7 +642,7 @@ static int SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_Pixel
}
}
return 0;
return true;
}
const SDL_PixelFormatDetails *SDL_GetPixelFormatDetails(SDL_PixelFormat format)
@@ -669,7 +669,7 @@ const SDL_PixelFormatDetails *SDL_GetPixelFormatDetails(SDL_PixelFormat format)
goto done;
}
if (SDL_InitPixelFormatDetails(details, format) < 0) {
if (!SDL_InitPixelFormatDetails(details, format)) {
SDL_free(details);
details = NULL;
goto done;
@@ -1035,18 +1035,17 @@ SDL_Palette *SDL_CreatePalette(int ncolors)
return palette;
}
int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
int firstcolor, int ncolors)
SDL_bool SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors)
{
int status = 0;
bool result = true;
// Verify the parameters
if (!palette) {
return -1;
return false;
}
if (ncolors > (palette->ncolors - firstcolor)) {
ncolors = (palette->ncolors - firstcolor);
status = -1;
result = false;
}
if (colors != (palette->colors + firstcolor)) {
@@ -1058,7 +1057,7 @@ int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors,
palette->version = 1;
}
return status;
return result;
}
void SDL_DestroyPalette(SDL_Palette *palette)
@@ -1418,7 +1417,7 @@ static Uint8 *Map1toN(const SDL_Palette *pal, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod
return map;
}
int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst)
bool SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst)
{
SDL_BlitMap *map = &src->internal->map;
@@ -1428,8 +1427,8 @@ int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst)
map->dst_palette_version != dst->internal->palette->version) ||
(src->internal->palette &&
map->src_palette_version != src->internal->palette->version)) {
if (SDL_MapSurface(src, dst) < 0) {
return -1;
if (!SDL_MapSurface(src, dst)) {
return false;
}
// just here for debugging
// printf
@@ -1439,7 +1438,7 @@ int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst)
} else {
map->info.dst_surface = dst;
}
return 0;
return true;
}
void SDL_InvalidateMap(SDL_BlitMap *map)
@@ -1458,7 +1457,7 @@ void SDL_InvalidateMap(SDL_BlitMap *map)
}
}
int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
bool SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
{
const SDL_PixelFormatDetails *srcfmt;
const SDL_Palette *srcpal;
@@ -1491,7 +1490,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
}
if (!map->identity) {
if (!map->info.table) {
return -1;
return false;
}
}
if (srcfmt->bits_per_pixel != dstfmt->bits_per_pixel) {
@@ -1503,7 +1502,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst)
Map1toN(srcpal, src->internal->map.info.r, src->internal->map.info.g,
src->internal->map.info.b, src->internal->map.info.a, dstfmt);
if (!map->info.table) {
return -1;
return false;
}
}
} else {

View File

@@ -29,7 +29,7 @@
// Pixel format functions
extern int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, bool minimalPitch);
extern bool SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, bool minimalPitch);
extern SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormat pixel_format);
extern void SDL_QuitPixelFormatDetails(void);
@@ -43,9 +43,9 @@ extern const float *SDL_GetColorPrimariesConversionMatrix(SDL_ColorPrimaries src
extern void SDL_ConvertColorPrimaries(float *fR, float *fG, float *fB, const float *matrix);
// Blit mapping functions
extern int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst);
extern bool SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst);
extern void SDL_InvalidateMap(SDL_BlitMap *map);
extern int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst);
extern bool SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst);
// Miscellaneous functions
extern void SDL_DitherPalette(SDL_Palette *palette);

View File

@@ -137,7 +137,7 @@ SDL_bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *resul
return !SDL_RECTEMPTY(result);
}
int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
SDL_bool SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
{
SCALARTYPE Amin, Amax, Bmin, Bmax;
@@ -156,10 +156,10 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
} else { // A empty, B not empty
*result = *B;
}
return 0;
return true;
} else if (SDL_RECTEMPTY(B)) { // A not empty, B empty
*result = *A;
return 0;
return true;
}
// Horizontal union
@@ -189,7 +189,7 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result)
Amax = Bmax;
}
result->h = Amax - Amin;
return 0;
return true;
}
SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip, RECTTYPE *result)

View File

@@ -22,14 +22,12 @@
#include "SDL_blit.h"
static int SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
static int SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
static bool SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
static bool SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect);
int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *dst, const SDL_Rect *dstrect,
SDL_ScaleMode scaleMode)
bool SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode)
{
int ret;
bool result;
int src_locked;
int dst_locked;
SDL_Rect full_src;
@@ -46,11 +44,11 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
// Slow!
SDL_Surface *src_tmp = SDL_ConvertSurfaceAndColorspace(src, dst->format, dst->internal->palette, dst->internal->colorspace, dst->internal->props);
if (!src_tmp) {
return -1;
return false;
}
ret = SDL_SoftStretch(src_tmp, srcrect, dst, dstrect, scaleMode);
result = SDL_SoftStretch(src_tmp, srcrect, dst, dstrect, scaleMode);
SDL_DestroySurface(src_tmp);
return ret;
return result;
}
if (SDL_ISPIXELFORMAT_FOURCC(src->format)) {
@@ -66,20 +64,20 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_Surface *src_tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_XRGB8888);
SDL_Surface *dst_tmp = SDL_CreateSurface(dstrect->w, dstrect->h, SDL_PIXELFORMAT_XRGB8888);
if (src_tmp && dst_tmp) {
ret = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode);
if (ret == 0) {
SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h,
dst_tmp->format, SDL_COLORSPACE_SRGB, 0,
dst_tmp->pixels, dst_tmp->pitch,
dst->format, dst->internal->colorspace, SDL_GetSurfaceProperties(dst),
(Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch);
result = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode);
if (result) {
result = SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h,
dst_tmp->format, SDL_COLORSPACE_SRGB, 0,
dst_tmp->pixels, dst_tmp->pitch,
dst->format, dst->internal->colorspace, SDL_GetSurfaceProperties(dst),
(Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch);
}
} else {
ret = -1;
result = false;
}
SDL_DestroySurface(src_tmp);
SDL_DestroySurface(dst_tmp);
return ret;
return result;
}
if (scaleMode != SDL_SCALEMODE_NEAREST && scaleMode != SDL_SCALEMODE_LINEAR && scaleMode != SDL_SCALEMODE_BEST) {
@@ -125,7 +123,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
}
if (dstrect->w <= 0 || dstrect->h <= 0) {
return 0;
return true;
}
if (srcrect->w > SDL_MAX_UINT16 || srcrect->h > SDL_MAX_UINT16 ||
@@ -136,7 +134,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
// Lock the destination if it's in hardware
dst_locked = 0;
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
if (!SDL_LockSurface(dst)) {
return SDL_SetError("Unable to lock destination surface");
}
dst_locked = 1;
@@ -144,7 +142,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
// Lock the source if it's in hardware
src_locked = 0;
if (SDL_MUSTLOCK(src)) {
if (SDL_LockSurface(src) < 0) {
if (!SDL_LockSurface(src)) {
if (dst_locked) {
SDL_UnlockSurface(dst);
}
@@ -154,9 +152,9 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
}
if (scaleMode == SDL_SCALEMODE_NEAREST) {
ret = SDL_LowerSoftStretchNearest(src, srcrect, dst, dstrect);
result = SDL_LowerSoftStretchNearest(src, srcrect, dst, dstrect);
} else {
ret = SDL_LowerSoftStretchLinear(src, srcrect, dst, dstrect);
result = SDL_LowerSoftStretchLinear(src, srcrect, dst, dstrect);
}
// We need to unlock the surfaces if they're locked
@@ -167,7 +165,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect,
SDL_UnlockSurface(src);
}
return ret;
return result;
}
/* bilinear interpolation precision must be < 8
@@ -325,8 +323,7 @@ static SDL_INLINE void INTERPOL_BILINEAR(const Uint32 *s0, const Uint32 *s1, int
INTERPOL(tmp, tmp + 1, frac_w0, frac_w1, dst);
}
static int scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
BILINEAR___START
@@ -371,7 +368,7 @@ static int scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch,
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
#ifdef SDL_NEON_INTRINSICS
@@ -446,7 +443,7 @@ static SDL_INLINE void SDL_TARGETING("sse2") INTERPOL_BILINEAR_SSE(const Uint32
*dst = _mm_cvtsi128_si32(e0);
}
static int SDL_TARGETING("sse2") scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool SDL_TARGETING("sse2") scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
BILINEAR___START
@@ -562,7 +559,7 @@ static int SDL_TARGETING("sse2") scale_mat_SSE(const Uint32 *src, int src_w, int
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
#endif
@@ -610,7 +607,7 @@ static SDL_INLINE void INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1
*dst = vget_lane_u32(CAST_uint32x2_t e0, 0);
}
static int scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
BILINEAR___START
@@ -824,14 +821,13 @@ static int scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
#endif
int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
bool SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect, SDL_Surface *d, const SDL_Rect *dstrect)
{
int ret = -1;
bool result = false;
int src_w = srcrect->w;
int src_h = srcrect->h;
int dst_w = dstrect->w;
@@ -842,22 +838,22 @@ int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
Uint32 *dst = (Uint32 *)((Uint8 *)d->pixels + dstrect->x * 4 + dstrect->y * dst_pitch);
#ifdef SDL_NEON_INTRINSICS
if (ret == -1 && hasNEON()) {
ret = scale_mat_NEON(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
if (!result && hasNEON()) {
result = scale_mat_NEON(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
}
#endif
#ifdef SDL_SSE2_INTRINSICS
if (ret == -1 && hasSSE2()) {
ret = scale_mat_SSE(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
if (!result && hasSSE2()) {
result = scale_mat_SSE(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
}
#endif
if (ret == -1) {
ret = scale_mat(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
if (!result) {
result = scale_mat(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch);
}
return ret;
return result;
}
#define SDL_SCALE_NEAREST__START \
@@ -879,8 +875,7 @@ int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect,
posx = incx / 2; \
n = dst_w;
static int scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 1;
SDL_SCALE_NEAREST__START
@@ -896,11 +891,10 @@ static int scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
static int scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 2;
SDL_SCALE_NEAREST__START
@@ -916,11 +910,10 @@ static int scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
static int scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 3;
SDL_SCALE_NEAREST__START
@@ -938,11 +931,10 @@ static int scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
static int scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch,
Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
static bool scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch)
{
Uint32 bpp = 4;
SDL_SCALE_NEAREST__START
@@ -958,11 +950,10 @@ static int scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int
}
dst = (Uint32 *)((Uint8 *)dst + dst_gap);
}
return 0;
return true;
}
int SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect,
SDL_Surface *d, const SDL_Rect *dstrect)
bool SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect, SDL_Surface *d, const SDL_Rect *dstrect)
{
int src_w = srcrect->w;
int src_h = srcrect->h;

File diff suppressed because it is too large Load Diff

View File

@@ -81,6 +81,6 @@ extern float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace co
extern float SDL_GetDefaultHDRHeadroom(SDL_Colorspace colorspace);
extern float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace);
extern SDL_Surface *SDL_GetSurfaceImage(SDL_Surface *surface, float display_scale);
extern int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
extern bool SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode);
#endif // SDL_surface_c_h_

View File

@@ -183,6 +183,13 @@ typedef enum
SDL_FULLSCREEN_OP_UPDATE
} SDL_FullscreenOp;
typedef enum
{
SDL_FULLSCREEN_FAILED,
SDL_FULLSCREEN_SUCCEEDED,
SDL_FULLSCREEN_PENDING
} SDL_FullscreenResult;
struct SDL_VideoDevice
{
/* * * */
@@ -196,7 +203,7 @@ struct SDL_VideoDevice
* Initialize the native video subsystem, filling in the list of
* displays for this driver, returning 0 or -1 if there's an error.
*/
int (*VideoInit)(SDL_VideoDevice *_this);
bool (*VideoInit)(SDL_VideoDevice *_this);
/*
* Reverse the effects VideoInit() -- called if VideoInit() fails or
@@ -222,17 +229,17 @@ struct SDL_VideoDevice
/*
* Get the bounds of a display
*/
int (*GetDisplayBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
bool (*GetDisplayBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
/*
* Get the usable bounds of a display (bounds minus menubar or whatever)
*/
int (*GetDisplayUsableBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
bool (*GetDisplayUsableBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
/*
* Get a list of the available display modes for a display.
*/
int (*GetDisplayModes)(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
bool (*GetDisplayModes)(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
/*
* Setting the display mode is independent of creating windows, so
@@ -240,24 +247,24 @@ struct SDL_VideoDevice
* their data updated accordingly, including the display surfaces
* associated with them.
*/
int (*SetDisplayMode)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
bool (*SetDisplayMode)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
/* * * */
/*
* Window functions
*/
int (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
bool (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void (*SetWindowTitle)(SDL_VideoDevice *_this, SDL_Window *window);
int (*SetWindowIcon)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
int (*SetWindowPosition)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*SetWindowIcon)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
bool (*SetWindowPosition)(SDL_VideoDevice *_this, SDL_Window *window);
void (*SetWindowSize)(SDL_VideoDevice *_this, SDL_Window *window);
void (*SetWindowMinimumSize)(SDL_VideoDevice *_this, SDL_Window *window);
void (*SetWindowMaximumSize)(SDL_VideoDevice *_this, SDL_Window *window);
void (*SetWindowAspectRatio)(SDL_VideoDevice *_this, SDL_Window *window);
int (*GetWindowBordersSize)(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right);
bool (*GetWindowBordersSize)(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right);
void (*GetWindowSizeInPixels)(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h);
int (*SetWindowOpacity)(SDL_VideoDevice *_this, SDL_Window *window, float opacity);
int (*SetWindowModalFor)(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window);
bool (*SetWindowOpacity)(SDL_VideoDevice *_this, SDL_Window *window, float opacity);
bool (*SetWindowModalFor)(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window);
void (*ShowWindow)(SDL_VideoDevice *_this, SDL_Window *window);
void (*HideWindow)(SDL_VideoDevice *_this, SDL_Window *window);
void (*RaiseWindow)(SDL_VideoDevice *_this, SDL_Window *window);
@@ -267,48 +274,48 @@ struct SDL_VideoDevice
void (*SetWindowBordered)(SDL_VideoDevice *_this, SDL_Window *window, bool bordered);
void (*SetWindowResizable)(SDL_VideoDevice *_this, SDL_Window *window, bool resizable);
void (*SetWindowAlwaysOnTop)(SDL_VideoDevice *_this, SDL_Window *window, bool on_top);
int (*SetWindowFullscreen)(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
SDL_FullscreenResult (*SetWindowFullscreen)(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
void *(*GetWindowICCProfile)(SDL_VideoDevice *_this, SDL_Window *window, size_t *size);
SDL_DisplayID (*GetDisplayForWindow)(SDL_VideoDevice *_this, SDL_Window *window);
int (*SetWindowMouseRect)(SDL_VideoDevice *_this, SDL_Window *window);
int (*SetWindowMouseGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
int (*SetWindowKeyboardGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
bool (*SetWindowMouseRect)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*SetWindowMouseGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
bool (*SetWindowKeyboardGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
void (*DestroyWindow)(SDL_VideoDevice *_this, SDL_Window *window);
int (*CreateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
int (*SetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int vsync);
int (*GetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int *vsync);
int (*UpdateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
bool (*CreateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
bool (*SetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int vsync);
bool (*GetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int *vsync);
bool (*UpdateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
void (*DestroyWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window);
void (*OnWindowEnter)(SDL_VideoDevice *_this, SDL_Window *window);
int (*UpdateWindowShape)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape);
int (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
int (*SetWindowFocusable)(SDL_VideoDevice *_this, SDL_Window *window, bool focusable);
int (*SyncWindow)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*UpdateWindowShape)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape);
bool (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
bool (*SetWindowFocusable)(SDL_VideoDevice *_this, SDL_Window *window, bool focusable);
bool (*SyncWindow)(SDL_VideoDevice *_this, SDL_Window *window);
/* * * */
/*
* OpenGL support
*/
int (*GL_LoadLibrary)(SDL_VideoDevice *_this, const char *path);
bool (*GL_LoadLibrary)(SDL_VideoDevice *_this, const char *path);
SDL_FunctionPointer (*GL_GetProcAddress)(SDL_VideoDevice *_this, const char *proc);
void (*GL_UnloadLibrary)(SDL_VideoDevice *_this);
SDL_GLContext (*GL_CreateContext)(SDL_VideoDevice *_this, SDL_Window *window);
int (*GL_MakeCurrent)(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
bool (*GL_MakeCurrent)(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
SDL_EGLSurface (*GL_GetEGLSurface)(SDL_VideoDevice *_this, SDL_Window *window);
int (*GL_SetSwapInterval)(SDL_VideoDevice *_this, int interval);
int (*GL_GetSwapInterval)(SDL_VideoDevice *_this, int *interval);
int (*GL_SwapWindow)(SDL_VideoDevice *_this, SDL_Window *window);
int (*GL_DeleteContext)(SDL_VideoDevice *_this, SDL_GLContext context);
bool (*GL_SetSwapInterval)(SDL_VideoDevice *_this, int interval);
bool (*GL_GetSwapInterval)(SDL_VideoDevice *_this, int *interval);
bool (*GL_SwapWindow)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*GL_DestroyContext)(SDL_VideoDevice *_this, SDL_GLContext context);
void (*GL_DefaultProfileConfig)(SDL_VideoDevice *_this, int *mask, int *major, int *minor);
/* * * */
/*
* Vulkan support
*/
int (*Vulkan_LoadLibrary)(SDL_VideoDevice *_this, const char *path);
bool (*Vulkan_LoadLibrary)(SDL_VideoDevice *_this, const char *path);
void (*Vulkan_UnloadLibrary)(SDL_VideoDevice *_this);
char const* const* (*Vulkan_GetInstanceExtensions)(SDL_VideoDevice *_this, Uint32 *count);
int (*Vulkan_CreateSurface)(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface);
bool (*Vulkan_CreateSurface)(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface);
void (*Vulkan_DestroySurface)(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator);
bool (*Vulkan_GetPresentationSupport)(SDL_VideoDevice *_this, VkInstance instance, VkPhysicalDevice physicalDevice, Uint32 queueFamilyIndex);
@@ -328,14 +335,14 @@ struct SDL_VideoDevice
void (*SendWakeupEvent)(SDL_VideoDevice *_this, SDL_Window *window);
void (*PumpEvents)(SDL_VideoDevice *_this);
// Suspend the screensaver
int (*SuspendScreenSaver)(SDL_VideoDevice *_this);
// Suspend/resume the screensaver
bool (*SuspendScreenSaver)(SDL_VideoDevice *_this);
// Text input
int (*StartTextInput)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
int (*StopTextInput)(SDL_VideoDevice *_this, SDL_Window *window);
int (*UpdateTextInputArea)(SDL_VideoDevice *_this, SDL_Window *window);
int (*ClearComposition)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*StartTextInput)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
bool (*StopTextInput)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*UpdateTextInputArea)(SDL_VideoDevice *_this, SDL_Window *window);
bool (*ClearComposition)(SDL_VideoDevice *_this, SDL_Window *window);
// Screen keyboard
bool (*HasScreenKeyboardSupport)(SDL_VideoDevice *_this);
@@ -345,23 +352,23 @@ struct SDL_VideoDevice
// Clipboard
const char **(*GetTextMimeTypes)(SDL_VideoDevice *_this, size_t *num_mime_types);
int (*SetClipboardData)(SDL_VideoDevice *_this);
bool (*SetClipboardData)(SDL_VideoDevice *_this);
void *(*GetClipboardData)(SDL_VideoDevice *_this, const char *mime_type, size_t *size);
bool (*HasClipboardData)(SDL_VideoDevice *_this, const char *mime_type);
/* If you implement *ClipboardData, you don't need to implement *ClipboardText */
int (*SetClipboardText)(SDL_VideoDevice *_this, const char *text);
bool (*SetClipboardText)(SDL_VideoDevice *_this, const char *text);
char *(*GetClipboardText)(SDL_VideoDevice *_this);
bool (*HasClipboardText)(SDL_VideoDevice *_this);
// These functions are only needed if the platform has a separate primary selection buffer
int (*SetPrimarySelectionText)(SDL_VideoDevice *_this, const char *text);
bool (*SetPrimarySelectionText)(SDL_VideoDevice *_this, const char *text);
char *(*GetPrimarySelectionText)(SDL_VideoDevice *_this);
bool (*HasPrimarySelectionText)(SDL_VideoDevice *_this);
// MessageBox
int (*ShowMessageBox)(SDL_VideoDevice *_this, const SDL_MessageBoxData *messageboxdata, int *buttonID);
bool (*ShowMessageBox)(SDL_VideoDevice *_this, const SDL_MessageBoxData *messageboxdata, int *buttonID);
// Hit-testing
int (*SetWindowHitTest)(SDL_Window *window, bool enabled);
bool (*SetWindowHitTest)(SDL_Window *window, bool enabled);
// Tell window that app enabled drag'n'drop events
void (*AcceptDragAndDrop)(SDL_Window *window, bool accept);
@@ -483,7 +490,7 @@ typedef struct VideoBootStrap
const char *name;
const char *desc;
SDL_VideoDevice *(*create)(void);
int (*ShowMessageBox)(const SDL_MessageBoxData *messageboxdata, int *buttonID); // can be done without initializing backend!
bool (*ShowMessageBox)(const SDL_MessageBoxData *messageboxdata, int *buttonID); // can be done without initializing backend!
} VideoBootStrap;
// Not all of these are available in a given build. Use #ifdefs, etc.
@@ -524,7 +531,7 @@ extern void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_Displ
extern void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode);
extern void SDL_SetDisplayContentScale(SDL_VideoDisplay *display, float scale);
extern void SDL_SetDisplayHDRProperties(SDL_VideoDisplay *display, const SDL_HDROutputProperties *HDR);
extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode);
extern bool SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode);
extern SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID display);
extern SDL_DisplayID SDL_GetDisplayForWindowPosition(SDL_Window *window);
extern SDL_VideoDisplay *SDL_GetVideoDisplayForWindow(SDL_Window *window);
@@ -538,7 +545,7 @@ extern void SDL_SetWindowSafeAreaInsets(SDL_Window *window, int left, int right,
extern void SDL_GL_DeduceMaxSupportedESProfile(int *major, int *minor);
extern int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags);
extern bool SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags);
extern bool SDL_HasWindows(void);
extern void SDL_RelativeToGlobalForWindow(SDL_Window *window, int rel_x, int rel_y, int *abs_x, int *abs_y);
extern void SDL_GlobalToRelativeForWindow(SDL_Window *window, int abs_x, int abs_y, int *rel_x, int *rel_y);
@@ -560,7 +567,7 @@ extern void SDL_OnWindowFocusGained(SDL_Window *window);
extern void SDL_OnWindowFocusLost(SDL_Window *window);
extern void SDL_OnWindowDisplayChanged(SDL_Window *window);
extern void SDL_UpdateWindowGrab(SDL_Window *window);
extern int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bool commit);
extern bool SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bool commit);
extern SDL_Window *SDL_GetToplevelForKeyboardFocus(void);
extern bool SDL_ShouldAllowTopmost(void);

File diff suppressed because it is too large Load Diff

View File

@@ -45,10 +45,10 @@ struct SDL_VideoDevice;
*
* \param driver_name the name of a video driver to initialize, or NULL for
* the default driver
* \returns 0 on success or a negative error code on failure; call
* \returns true on success or false on failure; call
* SDL_GetError() for more information.
*/
extern int SDL_VideoInit(const char *driver_name);
extern bool SDL_VideoInit(const char *driver_name);
/**
* Shut down the video subsystem, if initialized with SDL_VideoInit().
@@ -57,9 +57,7 @@ extern int SDL_VideoInit(const char *driver_name);
*/
extern void SDL_VideoQuit(void);
extern int SDL_SetWindowTextureVSync(struct SDL_VideoDevice *_this, SDL_Window *window, int vsync);
extern int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
extern bool SDL_SetWindowTextureVSync(struct SDL_VideoDevice *_this, SDL_Window *window, int vsync);
#if defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_EMSCRIPTEN)
const char *SDL_GetCSSCursorName(SDL_SystemCursor id, const char **fallback_name);

View File

@@ -24,12 +24,12 @@
#if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK)
int SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
SDL_bool SDL_RegisterApp(const char *name, Uint32 style, void *hInst)
{
(void)name;
(void)style;
(void)hInst;
return 0;
return true;
}
void SDL_UnregisterApp(void)
@@ -42,8 +42,8 @@ void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata)
#endif // SDL_PLATFORM_WIN32 || SDL_PLATFORM_GDK
SDL_DECLSPEC int SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex);
int SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex)
SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex);
SDL_bool SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex)
{
(void)displayID;
(void)adapterIndex;
@@ -55,7 +55,8 @@ SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID);
int SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID)
{
(void)displayID;
return SDL_Unsupported();
SDL_Unsupported();
return -1;
}
#elif defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
@@ -64,15 +65,16 @@ SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID);
int SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID)
{
(void)displayID;
return SDL_Unsupported();
SDL_Unsupported();
return -1;
}
#endif // !SDL_VIDEO_DRIVER_WINDOWS
#ifndef SDL_PLATFORM_GDK
SDL_DECLSPEC int SDLCALL SDL_GetGDKTaskQueue(void *outTaskQueue);
int SDL_GetGDKTaskQueue(void *outTaskQueue)
SDL_DECLSPEC bool SDLCALL SDL_GetGDKTaskQueue(void *outTaskQueue);
bool SDL_GetGDKTaskQueue(void *outTaskQueue)
{
(void)outTaskQueue;
return SDL_Unsupported();
@@ -93,8 +95,8 @@ void SDL_OnApplicationDidChangeStatusBarOrientation(void)
#ifndef SDL_VIDEO_DRIVER_UIKIT
typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata);
SDL_DECLSPEC int SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
int SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam)
SDL_DECLSPEC SDL_bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam);
SDL_bool SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam)
{
(void)window;
(void)interval;

View File

@@ -63,10 +63,10 @@ extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
* using the DisplayKHR extension.
* This needs to be passed an instance that was created with the VK_KHR_DISPLAY_EXTENSION_NAME
* extension. */
extern int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
extern bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
/* Platform independent base function for destroying the Vulkan surface. Unlike surface
* creation, surface destruction doesn't require platform specific extensions like

View File

@@ -121,49 +121,49 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList(
Uint32 *extensionCount)
{
Uint32 count = 0;
VkResult result = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL);
VkExtensionProperties *retval;
VkResult rc = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL);
VkExtensionProperties *result;
if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
if (rc == VK_ERROR_INCOMPATIBLE_DRIVER) {
// Avoid the ERR_MAX_STRLEN limit by passing part of the message as a string argument.
SDL_SetError(
"You probably don't have a working Vulkan driver installed. %s %s %s(%d)",
"Getting Vulkan extensions failed:",
"vkEnumerateInstanceExtensionProperties returned",
SDL_Vulkan_GetResultString(result),
(int)result);
SDL_Vulkan_GetResultString(rc),
(int)rc);
return NULL;
} else if (result != VK_SUCCESS) {
} else if (rc != VK_SUCCESS) {
SDL_SetError(
"Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
"%s(%d)",
SDL_Vulkan_GetResultString(result),
(int)result);
SDL_Vulkan_GetResultString(rc),
(int)rc);
return NULL;
}
if (count == 0) {
retval = (VkExtensionProperties *)SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
result = (VkExtensionProperties *)SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null
} else {
retval = (VkExtensionProperties *)SDL_calloc(count, sizeof(VkExtensionProperties));
result = (VkExtensionProperties *)SDL_calloc(count, sizeof(VkExtensionProperties));
}
if (!retval) {
if (!result) {
return NULL;
}
result = vkEnumerateInstanceExtensionProperties(NULL, &count, retval);
if (result != VK_SUCCESS) {
rc = vkEnumerateInstanceExtensionProperties(NULL, &count, result);
if (rc != VK_SUCCESS) {
SDL_SetError(
"Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned "
"%s(%d)",
SDL_Vulkan_GetResultString(result),
(int)result);
SDL_free(retval);
SDL_Vulkan_GetResultString(rc),
(int)rc);
SDL_free(result);
return NULL;
}
*extensionCount = count;
return retval;
return result;
}
// Alpha modes, in order of preference
@@ -174,10 +174,10 @@ static const VkDisplayPlaneAlphaFlagBitsKHR alphaModes[4] = {
VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR,
};
int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface)
bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface)
{
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr =
(PFN_vkGetInstanceProcAddr)vkGetInstanceProcAddr_;
@@ -192,7 +192,7 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
VULKAN_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR);
#undef VULKAN_INSTANCE_FUNCTION
VkDisplaySurfaceCreateInfoKHR createInfo;
VkResult result;
VkResult rc;
uint32_t physicalDeviceCount = 0;
VkPhysicalDevice *physicalDevices = NULL;
uint32_t physicalDeviceIndex;
@@ -215,8 +215,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
}
// Enumerate physical devices
result = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, NULL);
if (result != VK_SUCCESS) {
rc = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, NULL);
if (rc != VK_SUCCESS) {
SDL_SetError("Could not enumerate Vulkan physical devices");
goto error;
}
@@ -231,8 +231,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
goto error;
}
result = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices);
if (result != VK_SUCCESS) {
rc = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices);
if (rc != VK_SUCCESS) {
SDL_SetError("Error enumerating physical devices");
goto error;
}
@@ -254,8 +254,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
VkDisplayPlaneCapabilitiesKHR planeCaps = { 0 };
// Get information about the physical displays
result = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, NULL);
if (result != VK_SUCCESS || displayPropertiesCount == 0) {
rc = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, NULL);
if (rc != VK_SUCCESS || displayPropertiesCount == 0) {
// This device has no physical device display properties, move on to next.
continue;
}
@@ -273,8 +273,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
goto error;
}
result = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, displayProperties);
if (result != VK_SUCCESS || displayPropertiesCount == 0) {
rc = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, displayProperties);
if (rc != VK_SUCCESS || displayPropertiesCount == 0) {
SDL_free(displayProperties);
SDL_SetError("Error enumerating physical device displays");
goto error;
@@ -289,8 +289,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
displayProperties = NULL;
// Get display mode properties for the chosen display
result = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, NULL);
if (result != VK_SUCCESS || displayModePropertiesCount == 0) {
rc = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, NULL);
if (rc != VK_SUCCESS || displayModePropertiesCount == 0) {
SDL_SetError("Error enumerating display modes");
goto error;
}
@@ -301,8 +301,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
goto error;
}
result = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, displayModeProperties);
if (result != VK_SUCCESS || displayModePropertiesCount == 0) {
rc = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, displayModeProperties);
if (rc != VK_SUCCESS || displayModePropertiesCount == 0) {
SDL_SetError("Error enumerating display modes");
SDL_free(displayModeProperties);
goto error;
@@ -335,8 +335,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
displayModeProperties = NULL;
// Try to find a plane index that supports our display
result = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, NULL);
if (result != VK_SUCCESS || displayPlanePropertiesCount == 0) {
rc = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, NULL);
if (rc != VK_SUCCESS || displayPlanePropertiesCount == 0) {
SDL_SetError("Error enumerating display planes");
goto error;
}
@@ -347,8 +347,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
goto error;
}
result = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, displayPlaneProperties);
if (result != VK_SUCCESS || displayPlanePropertiesCount == 0) {
rc = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, displayPlaneProperties);
if (rc != VK_SUCCESS || displayPlanePropertiesCount == 0) {
SDL_SetError("Error enumerating display plane properties");
SDL_free(displayPlaneProperties);
goto error;
@@ -365,8 +365,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
}
// Check supported displays for this plane.
result = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, NULL);
if (result != VK_SUCCESS || planeSupportedDisplaysCount == 0) {
rc = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, NULL);
if (rc != VK_SUCCESS || planeSupportedDisplaysCount == 0) {
continue; // No supported displays, on to next plane.
}
@@ -378,8 +378,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
goto error;
}
result = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, planeSupportedDisplays);
if (result != VK_SUCCESS || planeSupportedDisplaysCount == 0) {
rc = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, planeSupportedDisplays);
if (rc != VK_SUCCESS || planeSupportedDisplaysCount == 0) {
SDL_SetError("Error enumerating supported displays, or no supported displays");
SDL_free(planeSupportedDisplays);
SDL_free(displayPlaneProperties);
@@ -397,8 +397,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
continue;
}
result = vkGetDisplayPlaneCapabilitiesKHR(physicalDevice, createInfo.displayMode, i, &planeCaps);
if (result != VK_SUCCESS) {
rc = vkGetDisplayPlaneCapabilitiesKHR(physicalDevice, createInfo.displayMode, i, &planeCaps);
if (rc != VK_SUCCESS) {
SDL_SetError("Error getting display plane capabilities");
SDL_free(displayPlaneProperties);
goto error;
@@ -454,17 +454,17 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_,
createInfo.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
createInfo.globalAlpha = 1.0f;
result = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo, allocator, surface);
if (result != VK_SUCCESS) {
SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
rc = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo, allocator, surface);
if (rc != VK_SUCCESS) {
SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(rc));
goto error;
}
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Created surface");
return 0;
return true;
error:
SDL_free(physicalDevices);
return -1;
return false;
}
void SDL_Vulkan_DestroySurface_Internal(void *vkGetInstanceProcAddr_,

View File

@@ -33,10 +33,8 @@ static bool IsPlanar2x2Format(SDL_PixelFormat format);
/*
* Calculate YUV size and pitch. Check for overflow.
* Output 'pitch' that can be used with SDL_ConvertPixels()
*
* return 0 on success, -1 on error
*/
int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch)
bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch)
{
#if SDL_HAVE_YUV
int sz_plane = 0, sz_plane_chroma = 0, sz_plane_packed = 0;
@@ -151,7 +149,7 @@ int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, siz
return SDL_Unsupported();
}
return 0;
return true;
#else
return SDL_Unsupported();
#endif
@@ -159,7 +157,7 @@ int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, siz
#if SDL_HAVE_YUV
static int GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type)
static bool GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type)
{
if (SDL_ISCOLORSPACE_MATRIX_BT601(colorspace)) {
if (SDL_ISCOLORSPACE_LIMITED_RANGE(colorspace)) {
@@ -167,20 +165,20 @@ static int GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type)
} else {
*yuv_type = YCBCR_601_FULL;
}
return 0;
return true;
}
if (SDL_ISCOLORSPACE_MATRIX_BT709(colorspace)) {
if (SDL_ISCOLORSPACE_LIMITED_RANGE(colorspace)) {
*yuv_type = YCBCR_709_LIMITED;
return 0;
return true;
}
}
if (SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(colorspace)) {
if (SDL_ISCOLORSPACE_FULL_RANGE(colorspace)) {
*yuv_type = YCBCR_2020_NCL_FULL;
return 0;
return true;
}
}
@@ -197,8 +195,8 @@ static bool IsPacked4Format(Uint32 format)
return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU;
}
static int GetYUVPlanes(int width, int height, SDL_PixelFormat format, const void *yuv, int yuv_pitch,
const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
static bool GetYUVPlanes(int width, int height, SDL_PixelFormat format, const void *yuv, int yuv_pitch,
const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride)
{
const Uint8 *planes[3] = { NULL, NULL, NULL };
int pitches[3] = { 0, 0, 0 };
@@ -299,7 +297,7 @@ static int GetYUVPlanes(int width, int height, SDL_PixelFormat format, const voi
// Should have caught this above
return SDL_SetError("GetYUVPlanes[2]: Unsupported YUV format: %s", SDL_GetPixelFormatName(format));
}
return 0;
return true;
}
#ifdef SDL_SSE2_INTRINSICS
@@ -586,9 +584,9 @@ static bool yuv_rgb_std(
return false;
}
int SDL_ConvertPixels_YUV_to_RGB(int width, int height,
SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
bool SDL_ConvertPixels_YUV_to_RGB(int width, int height,
SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
const Uint8 *y = NULL;
const Uint8 *u = NULL;
@@ -596,75 +594,75 @@ int SDL_ConvertPixels_YUV_to_RGB(int width, int height,
Uint32 y_stride = 0;
Uint32 uv_stride = 0;
if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) {
return -1;
if (!GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride)) {
return false;
}
if (SDL_COLORSPACEPRIMARIES(src_colorspace) == SDL_COLORSPACEPRIMARIES(dst_colorspace)) {
YCbCrType yuv_type = YCBCR_601_LIMITED;
if (GetYUVConversionType(src_colorspace, &yuv_type) < 0) {
return -1;
if (!GetYUVConversionType(src_colorspace, &yuv_type)) {
return false;
}
if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
return true;
}
if (yuv_rgb_lsx(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
return true;
}
if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) {
return 0;
return true;
}
}
// No fast path for the RGB format, instead convert using an intermediate buffer
if (src_format == SDL_PIXELFORMAT_P010 && dst_format != SDL_PIXELFORMAT_XBGR2101010) {
int ret;
bool result;
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc((size_t)tmp_pitch * height);
if (!tmp) {
return -1;
return false;
}
// convert src/src_format to tmp/XBGR2101010
ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch);
if (ret < 0) {
result = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch);
if (!result) {
SDL_free(tmp);
return ret;
return false;
}
// convert tmp/XBGR2101010 to dst/RGB
ret = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch);
result = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch);
SDL_free(tmp);
return ret;
return result;
}
if (dst_format != SDL_PIXELFORMAT_ARGB8888) {
int ret;
bool result;
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc((size_t)tmp_pitch * height);
if (!tmp) {
return -1;
return false;
}
// convert src/src_format to tmp/ARGB8888
ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch);
if (ret < 0) {
result = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch);
if (!result) {
SDL_free(tmp);
return ret;
return false;
}
// convert tmp/ARGB8888 to dst/RGB
ret = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch);
result = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch);
SDL_free(tmp);
return ret;
return result;
}
return SDL_SetError("Unsupported YUV conversion");
@@ -709,7 +707,7 @@ static struct RGB2YUVFactors RGB2YUVFactorTables[] = {
},
};
static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
static bool SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
{
const int src_pitch_x_2 = src_pitch * 2;
const int height_half = height / 2;
@@ -782,10 +780,10 @@ static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *
Uint8 *plane_interleaved_uv;
Uint32 y_stride, uv_stride, y_skip, uv_skip;
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
&y_stride, &uv_stride) != 0) {
return -1;
if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
&y_stride, &uv_stride)) {
return false;
}
plane_interleaved_uv = (plane_y + height * y_stride);
@@ -997,10 +995,10 @@ static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *
#undef READ_1x1_PIXEL
#undef READ_TWO_RGB_PIXELS
#undef READ_ONE_RGB_PIXEL
return 0;
return true;
}
static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
static bool SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type)
{
const int src_pitch_x_2 = src_pitch * 2;
const int height_half = height / 2;
@@ -1052,10 +1050,10 @@ static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const vo
Uint16 *plane_interleaved_uv;
Uint32 y_stride, uv_stride, y_skip, uv_skip;
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
&y_stride, &uv_stride) != 0) {
return -1;
if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v,
&y_stride, &uv_stride)) {
return false;
}
y_stride /= sizeof(Uint16);
@@ -1119,17 +1117,17 @@ static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const vo
#undef READ_2x1_PIXELS
#undef READ_1x2_PIXELS
#undef READ_1x1_PIXEL
return 0;
return true;
}
int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
bool SDL_ConvertPixels_RGB_to_YUV(int width, int height,
SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
YCbCrType yuv_type = YCBCR_601_LIMITED;
if (GetYUVConversionType(dst_colorspace, &yuv_type) < 0) {
return -1;
if (!GetYUVConversionType(dst_colorspace, &yuv_type)) {
return false;
}
#if 0 // Doesn't handle odd widths
@@ -1142,11 +1140,11 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
Uint32 uv_stride;
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) {
return -1;
return false;
}
rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type);
return 0;
return true;
}
#endif
@@ -1163,55 +1161,54 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height,
}
// We currently only support converting from XBGR2101010 to P010
int ret;
bool result;
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc((size_t)tmp_pitch * height);
if (!tmp) {
return -1;
return false;
}
// convert src/src_format to tmp/XBGR2101010
ret = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, dst_colorspace, dst_properties, tmp, tmp_pitch);
if (ret < 0) {
result = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, dst_colorspace, dst_properties, tmp, tmp_pitch);
if (!result) {
SDL_free(tmp);
return ret;
return false;
}
// convert tmp/XBGR2101010 to dst/P010
ret = SDL_ConvertPixels_XBGR2101010_to_P010(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type);
result = SDL_ConvertPixels_XBGR2101010_to_P010(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type);
SDL_free(tmp);
return ret;
return result;
}
// not ARGB8888 to FOURCC : need an intermediate conversion
{
int ret;
bool result;
void *tmp;
int tmp_pitch = (width * sizeof(Uint32));
tmp = SDL_malloc((size_t)tmp_pitch * height);
if (!tmp) {
return -1;
return false;
}
// convert src/src_format to tmp/ARGB8888
ret = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, dst_colorspace, dst_properties, tmp, tmp_pitch);
if (ret < 0) {
result = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, dst_colorspace, dst_properties, tmp, tmp_pitch);
if (!result) {
SDL_free(tmp);
return ret;
return false;
}
// convert tmp/ARGB8888 to dst/FOURCC
ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type);
result = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type);
SDL_free(tmp);
return ret;
return result;
}
}
static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFormat format,
const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFormat format, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int i;
@@ -1257,7 +1254,7 @@ static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFor
dst = (Uint8 *)dst + dst_pitch;
}
}
return 0;
return true;
}
if (IsPacked4Format(format)) {
@@ -1268,13 +1265,13 @@ static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFor
src = (const Uint8 *)src + src_pitch;
dst = (Uint8 *)dst + dst_pitch;
}
return 0;
return true;
}
return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV_Copy: Unsupported YUV format: %s", SDL_GetPixelFormatName(format));
}
static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int y;
const int UVwidth = (width + 1) / 2;
@@ -1293,7 +1290,7 @@ static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src
// Allocate a temporary row for the swap
tmp = (Uint8 *)SDL_malloc(UVwidth);
if (!tmp) {
return -1;
return false;
}
for (y = 0; y < UVheight; ++y) {
SDL_memcpy(tmp, row1, UVwidth);
@@ -1326,11 +1323,11 @@ static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src
dstUV += dstUVPitch;
}
}
return 0;
return true;
}
#ifdef SDL_SSE2_INTRINSICS
static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
{
int x, y;
const int UVwidth = (width + 1) / 2;
@@ -1351,7 +1348,7 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int w
// Need to make a copy of the buffer so we don't clobber it while converting
tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch);
if (tmp == NULL) {
return -1;
return false;
}
SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch);
src = tmp;
@@ -1393,10 +1390,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int w
if (tmp) {
SDL_free(tmp);
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
{
int x, y;
const int UVwidth = (width + 1) / 2;
@@ -1417,7 +1414,7 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int
// Need to make a copy of the buffer so we don't clobber it while converting
tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch);
if (tmp == NULL) {
return -1;
return false;
}
SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch);
src = tmp;
@@ -1464,10 +1461,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int
if (tmp) {
SDL_free(tmp);
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int UVwidth = (width + 1) / 2;
@@ -1504,11 +1501,11 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int he
srcUV += srcUVPitchLeft;
dstUV += dstUVPitchLeft;
}
return 0;
return true;
}
#endif
static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
static bool SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
{
int x, y;
const int UVwidth = (width + 1) / 2;
@@ -1529,7 +1526,7 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const
// Need to make a copy of the buffer so we don't clobber it while converting
tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch);
if (!tmp) {
return -1;
return false;
}
SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch);
src = tmp;
@@ -1559,10 +1556,10 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const
if (tmp) {
SDL_free(tmp);
}
return 0;
return true;
}
static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
static bool SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
{
int x, y;
const int UVwidth = (width + 1) / 2;
@@ -1583,7 +1580,7 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, cons
// Need to make a copy of the buffer so we don't clobber it while converting
tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch);
if (!tmp) {
return -1;
return false;
}
SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch);
src = tmp;
@@ -1613,10 +1610,10 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, cons
if (tmp) {
SDL_free(tmp);
}
return 0;
return true;
}
static int SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int UVwidth = (width + 1) / 2;
@@ -1643,10 +1640,10 @@ static int SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src,
srcUV += srcUVPitchLeft;
dstUV += dstUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
static bool SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -1656,7 +1653,7 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const voi
return SDL_ConvertPixels_PackUVPlanes_to_NV_std(width, height, src, src_pitch, dst, dst_pitch, reverseUV);
}
static int SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
static bool SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -1666,7 +1663,7 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const vo
return SDL_ConvertPixels_SplitNV_to_UVPlanes_std(width, height, src, src_pitch, dst, dst_pitch, reverseUV);
}
static int SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -1676,9 +1673,9 @@ static int SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int
return SDL_ConvertPixels_SwapNV_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
if (src != dst) {
// Copy Y plane
@@ -1765,7 +1762,7 @@ static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height,
x -= 4; \
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -1797,10 +1794,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_UYVY_SSE2(int width,
dstYUV += dstYUVPitchLeft;
x = YUVwidth;
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -1832,10 +1829,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_YVYU_SSE2(int width,
dstYUV += dstYUVPitchLeft;
x = YUVwidth;
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -1867,10 +1864,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YUY2_SSE2(int width,
dstYUV += dstYUVPitchLeft;
x = YUVwidth;
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -1902,10 +1899,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YVYU_SSE2(int width,
dstYUV += dstYUVPitchLeft;
x = YUVwidth;
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -1937,10 +1934,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_YUY2_SSE2(int width,
dstYUV += dstYUVPitchLeft;
x = YUVwidth;
}
return 0;
return true;
}
static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -1972,11 +1969,11 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_UYVY_SSE2(int width,
dstYUV += dstYUVPitchLeft;
x = YUVwidth;
}
return 0;
return true;
}
#endif
static int SDL_ConvertPixels_YUY2_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YUY2_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -2006,10 +2003,10 @@ static int SDL_ConvertPixels_YUY2_to_UYVY_std(int width, int height, const void
srcYUV += srcYUVPitchLeft;
dstYUV += dstYUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_YUY2_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YUY2_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -2039,10 +2036,10 @@ static int SDL_ConvertPixels_YUY2_to_YVYU_std(int width, int height, const void
srcYUV += srcYUVPitchLeft;
dstYUV += dstYUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_UYVY_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_UYVY_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -2072,10 +2069,10 @@ static int SDL_ConvertPixels_UYVY_to_YUY2_std(int width, int height, const void
srcYUV += srcYUVPitchLeft;
dstYUV += dstYUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_UYVY_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_UYVY_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -2105,10 +2102,10 @@ static int SDL_ConvertPixels_UYVY_to_YVYU_std(int width, int height, const void
srcYUV += srcYUVPitchLeft;
dstYUV += dstYUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_YVYU_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YVYU_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -2138,10 +2135,10 @@ static int SDL_ConvertPixels_YVYU_to_YUY2_std(int width, int height, const void
srcYUV += srcYUVPitchLeft;
dstYUV += dstYUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_YVYU_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YVYU_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
int x, y;
const int YUVwidth = (width + 1) / 2;
@@ -2171,10 +2168,10 @@ static int SDL_ConvertPixels_YVYU_to_UYVY_std(int width, int height, const void
srcYUV += srcYUVPitchLeft;
dstYUV += dstYUVPitchLeft;
}
return 0;
return true;
}
static int SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -2184,7 +2181,7 @@ static int SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src
return SDL_ConvertPixels_YUY2_to_UYVY_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -2194,7 +2191,7 @@ static int SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src
return SDL_ConvertPixels_YUY2_to_YVYU_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -2204,7 +2201,7 @@ static int SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src
return SDL_ConvertPixels_UYVY_to_YUY2_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -2214,7 +2211,7 @@ static int SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src
return SDL_ConvertPixels_UYVY_to_YVYU_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -2224,7 +2221,7 @@ static int SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src
return SDL_ConvertPixels_YVYU_to_YUY2_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch)
{
#ifdef SDL_SSE2_INTRINSICS
if (SDL_HasSSE2()) {
@@ -2234,7 +2231,7 @@ static int SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src
return SDL_ConvertPixels_YVYU_to_UYVY_std(width, height, src, src_pitch, dst, dst_pitch);
}
static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height,
static bool SDL_ConvertPixels_Packed4_to_Packed4(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
@@ -2276,9 +2273,9 @@ static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height,
SDL_GetPixelFormatName(dst_format));
}
static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
int x, y;
const Uint8 *srcY1, *srcY2, *srcU, *srcV;
@@ -2292,9 +2289,9 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
return SDL_SetError("Can't change YUV plane types in-place");
}
if (GetYUVPlanes(width, height, src_format, src, src_pitch,
&srcY1, &srcU, &srcV, &srcY_pitch, &srcUV_pitch) < 0) {
return -1;
if (!GetYUVPlanes(width, height, src_format, src, src_pitch,
&srcY1, &srcU, &srcV, &srcY_pitch, &srcUV_pitch)) {
return false;
}
srcY2 = srcY1 + srcY_pitch;
srcY_pitch_left = (srcY_pitch - width);
@@ -2307,10 +2304,10 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
srcUV_pitch_left = (srcUV_pitch - ((width + 1) / 2));
}
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&dstY1, (const Uint8 **)&dstU1, (const Uint8 **)&dstV1,
&dstY_pitch, &dstUV_pitch) < 0) {
return -1;
if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&dstY1, (const Uint8 **)&dstU1, (const Uint8 **)&dstV1,
&dstY_pitch, &dstUV_pitch)) {
return false;
}
dstY2 = dstY1 + dstY_pitch;
dstU2 = dstU1 + dstUV_pitch;
@@ -2415,12 +2412,12 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height,
dstV1 += 4;
}
}
return 0;
return true;
}
static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
static bool SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
SDL_PixelFormat src_format, const void *src, int src_pitch,
SDL_PixelFormat dst_format, void *dst, int dst_pitch)
{
int x, y;
const Uint8 *srcY1, *srcY2, *srcU1, *srcU2, *srcV1, *srcV2;
@@ -2434,19 +2431,19 @@ static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
return SDL_SetError("Can't change YUV plane types in-place");
}
if (GetYUVPlanes(width, height, src_format, src, src_pitch,
&srcY1, &srcU1, &srcV1, &srcY_pitch, &srcUV_pitch) < 0) {
return -1;
if (!GetYUVPlanes(width, height, src_format, src, src_pitch,
&srcY1, &srcU1, &srcV1, &srcY_pitch, &srcUV_pitch)) {
return false;
}
srcY2 = srcY1 + srcY_pitch;
srcU2 = srcU1 + srcUV_pitch;
srcV2 = srcV1 + srcUV_pitch;
src_pitch_left = (srcY_pitch - 4 * ((width + 1) / 2));
if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&dstY1, (const Uint8 **)&dstU, (const Uint8 **)&dstV,
&dstY_pitch, &dstUV_pitch) < 0) {
return -1;
if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch,
(const Uint8 **)&dstY1, (const Uint8 **)&dstU, (const Uint8 **)&dstV,
&dstY_pitch, &dstUV_pitch)) {
return false;
}
dstY2 = dstY1 + dstY_pitch;
dstY_pitch_left = (dstY_pitch - width);
@@ -2546,14 +2543,14 @@ static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height,
*dstV = *srcV1;
}
}
return 0;
return true;
}
#endif // SDL_HAVE_YUV
int SDL_ConvertPixels_YUV_to_YUV(int width, int height,
SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
bool SDL_ConvertPixels_YUV_to_YUV(int width, int height,
SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch,
SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch)
{
#if SDL_HAVE_YUV
if (src_colorspace != dst_colorspace) {
@@ -2563,7 +2560,7 @@ int SDL_ConvertPixels_YUV_to_YUV(int width, int height,
if (src_format == dst_format) {
if (src == dst) {
// Nothing to do
return 0;
return true;
}
return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch);
}

View File

@@ -26,11 +26,11 @@
// YUV conversion functions
extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
extern bool SDL_ConvertPixels_YUV_to_RGB(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
extern bool SDL_ConvertPixels_RGB_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
extern bool SDL_ConvertPixels_YUV_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch);
extern int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch);
extern bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch);
#endif // SDL_yuv_c_h_

View File

@@ -26,7 +26,7 @@
#include "SDL_androidclipboard.h"
#include "../../core/android/SDL_android.h"
int Android_SetClipboardText(SDL_VideoDevice *_this, const char *text)
bool Android_SetClipboardText(SDL_VideoDevice *_this, const char *text)
{
return Android_JNI_SetClipboardText(text);
}

View File

@@ -23,7 +23,7 @@
#ifndef SDL_androidclipboard_h_
#define SDL_androidclipboard_h_
extern int Android_SetClipboardText(SDL_VideoDevice *_this, const char *text);
extern bool Android_SetClipboardText(SDL_VideoDevice *_this, const char *text);
extern char *Android_GetClipboardText(SDL_VideoDevice *_this);
extern bool Android_HasClipboardText(SDL_VideoDevice *_this);

View File

@@ -39,7 +39,7 @@ static void android_egl_context_restore(SDL_Window *window)
SDL_Event event;
SDL_WindowData *data = window->internal;
SDL_GL_MakeCurrent(window, NULL);
if (SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context) < 0) {
if (!SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context)) {
// The context is no longer valid, create a new one
data->egl_context = (EGLContext)SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context);
@@ -65,7 +65,7 @@ static void android_egl_context_backup(SDL_Window *window)
data->egl_context = SDL_GL_GetCurrentContext();
// Save/Restore the swap interval / vsync
if (SDL_GL_GetSwapInterval(&interval) == 0) {
if (SDL_GL_GetSwapInterval(&interval)) {
data->has_swap_interval = 1;
data->swap_interval = interval;
}
@@ -245,7 +245,7 @@ void Android_PumpEvents(Sint64 timeoutNS)
}
}
int Android_WaitActiveAndLockActivity(void)
bool Android_WaitActiveAndLockActivity(void)
{
while (Android_Paused && !Android_Destroyed) {
Android_PumpEvents(-1);
@@ -253,11 +253,11 @@ int Android_WaitActiveAndLockActivity(void)
if (Android_Destroyed) {
SDL_SetError("Android activity has been destroyed");
return -1;
return false;
}
Android_LockActivityMutex();
return 0;
return true;
}
void Android_QuitEvents(void)

View File

@@ -22,5 +22,5 @@
extern void Android_InitEvents(void);
extern void Android_PumpEvents(Sint64 timeoutNS);
extern int Android_WaitActiveAndLockActivity(void);
extern bool Android_WaitActiveAndLockActivity(void);
extern void Android_QuitEvents(void);

View File

@@ -36,7 +36,7 @@
#include <dlfcn.h>
int Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
bool Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
{
if (window && context) {
return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context);
@@ -47,22 +47,22 @@ int Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLC
SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_GLContext ret;
SDL_GLContext result;
if (Android_WaitActiveAndLockActivity() < 0) {
if (!Android_WaitActiveAndLockActivity()) {
return NULL;
}
ret = SDL_EGL_CreateContext(_this, window->internal->egl_surface);
result = SDL_EGL_CreateContext(_this, window->internal->egl_surface);
Android_UnlockActivityMutex();
return ret;
return result;
}
int Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
int retval;
bool result;
Android_LockActivityMutex();
@@ -73,14 +73,14 @@ int Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
/*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE);
_this->egl_data->eglWaitGL();*/
retval = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface);
result = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface);
Android_UnlockActivityMutex();
return retval;
return result;
}
int Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0);
}

View File

@@ -23,9 +23,9 @@
#ifndef SDL_androidgl_h_
#define SDL_androidgl_h_
SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
int Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
int Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
int Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern bool Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
#endif // SDL_androidgl_h_

View File

@@ -368,14 +368,14 @@ static SDL_Scancode TranslateKeycode(int keycode)
return scancode;
}
int Android_OnKeyDown(int keycode)
void Android_OnKeyDown(int keycode)
{
return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_PRESSED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_PRESSED);
}
int Android_OnKeyUp(int keycode)
void Android_OnKeyUp(int keycode)
{
return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_RELEASED);
SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_RELEASED);
}
bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this)

View File

@@ -22,8 +22,8 @@
#include "SDL_androidvideo.h"
extern int Android_OnKeyDown(int keycode);
extern int Android_OnKeyUp(int keycode);
extern void Android_OnKeyDown(int keycode);
extern void Android_OnKeyUp(int keycode);
extern bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
extern void Android_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);

View File

@@ -25,7 +25,7 @@
#include "SDL_androidmessagebox.h"
#include "../../core/android/SDL_android.h"
int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
bool Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
{
return Android_JNI_ShowMessageBox(messageboxdata, buttonID);
}

View File

@@ -22,6 +22,6 @@
#ifdef SDL_VIDEO_DRIVER_ANDROID
extern int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
extern bool Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
#endif // SDL_VIDEO_DRIVER_ANDROID

View File

@@ -132,7 +132,7 @@ static void Android_DestroyEmptyCursor(void)
}
}
static int Android_ShowCursor(SDL_Cursor *cursor)
static bool Android_ShowCursor(SDL_Cursor *cursor)
{
if (!cursor) {
cursor = Android_CreateEmptyCursor();
@@ -148,14 +148,14 @@ static int Android_ShowCursor(SDL_Cursor *cursor)
return SDL_Unsupported();
}
}
return 0;
return true;
} else {
// SDL error set inside Android_CreateEmptyCursor()
return -1;
return false;
}
}
static int Android_SetRelativeMouseMode(bool enabled)
static bool Android_SetRelativeMouseMode(bool enabled)
{
if (!Android_JNI_SupportsRelativeMouse()) {
return SDL_Unsupported();
@@ -165,7 +165,7 @@ static int Android_SetRelativeMouseMode(bool enabled)
return SDL_Unsupported();
}
return 0;
return true;
}
void Android_InitMouse(void)

View File

@@ -43,7 +43,7 @@
#define ANDROID_VID_DRIVER_NAME "android"
// Initialization/Query functions
static int Android_VideoInit(SDL_VideoDevice *_this);
static bool Android_VideoInit(SDL_VideoDevice *_this);
static void Android_VideoQuit(SDL_VideoDevice *_this);
#include "../SDL_egl_c.h"
@@ -51,7 +51,7 @@ static void Android_VideoQuit(SDL_VideoDevice *_this);
#define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
#define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
#define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define Android_GLES_DeleteContext SDL_EGL_DeleteContext
#define Android_GLES_DestroyContext SDL_EGL_DestroyContext
// Android driver bootstrap functions
@@ -65,7 +65,7 @@ float Android_ScreenDensity = 1.0f;
static float Android_ScreenRate = 0.0f;
static SDL_SystemTheme Android_SystemTheme;
static int Android_SuspendScreenSaver(SDL_VideoDevice *_this)
static bool Android_SuspendScreenSaver(SDL_VideoDevice *_this)
{
return Android_JNI_SuspendScreenSaver(_this->suspend_screensaver);
}
@@ -119,7 +119,7 @@ static SDL_VideoDevice *Android_CreateDevice(void)
device->GL_SetSwapInterval = Android_GLES_SetSwapInterval;
device->GL_GetSwapInterval = Android_GLES_GetSwapInterval;
device->GL_SwapWindow = Android_GLES_SwapWindow;
device->GL_DeleteContext = Android_GLES_DeleteContext;
device->GL_DestroyContext = Android_GLES_DestroyContext;
#endif
#ifdef SDL_VIDEO_VULKAN
@@ -155,7 +155,7 @@ VideoBootStrap Android_bootstrap = {
Android_ShowMessageBox
};
int Android_VideoInit(SDL_VideoDevice *_this)
bool Android_VideoInit(SDL_VideoDevice *_this)
{
SDL_VideoData *videodata = _this->internal;
SDL_DisplayID displayID;
@@ -173,7 +173,7 @@ int Android_VideoInit(SDL_VideoDevice *_this)
displayID = SDL_AddBasicVideoDisplay(&mode);
if (displayID == 0) {
return -1;
return false;
}
display = SDL_GetVideoDisplay(displayID);
display->natural_orientation = Android_JNI_GetDisplayNaturalOrientation();
@@ -185,7 +185,7 @@ int Android_VideoInit(SDL_VideoDevice *_this)
Android_InitMouse();
// We're done!
return 0;
return true;
}
void Android_VideoQuit(SDL_VideoDevice *_this)

View File

@@ -36,7 +36,7 @@
#include "SDL_androidvulkan.h"
int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
VkExtensionProperties *extensions = NULL;
Uint32 i, extensionCount = 0;
@@ -56,7 +56,7 @@ int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
}
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
if (!_this->vulkan_config.loader_handle) {
return -1;
return false;
}
SDL_strlcpy(_this->vulkan_config.loader_path, path,
SDL_arraysize(_this->vulkan_config.loader_path));
@@ -94,12 +94,12 @@ int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "extension");
goto fail;
}
return 0;
return true;
fail:
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
return -1;
return false;
}
void Android_Vulkan_UnloadLibrary(SDL_VideoDevice *_this)
@@ -116,13 +116,13 @@ char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
static const char *const extensionsForAndroid[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
};
if(count) {
if (count) {
*count = SDL_arraysize(extensionsForAndroid);
}
return extensionsForAndroid;
}
int Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
@@ -155,7 +155,7 @@ int Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
if (result != VK_SUCCESS) {
return SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result));
}
return 0;
return true;
}
void Android_Vulkan_DestroySurface(SDL_VideoDevice *_this,

View File

@@ -34,19 +34,18 @@
#if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_ANDROID)
int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
void Android_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
Uint32 *count);
int Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
void Android_Vulkan_DestroySurface(SDL_VideoDevice *_this,
VkInstance instance,
VkSurfaceKHR surface,
const struct VkAllocationCallbacks *allocator);
extern bool Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern void Android_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
extern char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count);
extern bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
extern void Android_Vulkan_DestroySurface(SDL_VideoDevice *_this,
VkInstance instance,
VkSurfaceKHR surface,
const struct VkAllocationCallbacks *allocator);
#endif

View File

@@ -36,17 +36,17 @@
// Currently only one window
SDL_Window *Android_Window = NULL;
int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
bool Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *data;
int retval = 0;
bool result = true;
if (Android_WaitActiveAndLockActivity() < 0) {
return -1;
if (!Android_WaitActiveAndLockActivity()) {
return false;
}
if (Android_Window) {
retval = SDL_SetError("Android only supports one window");
result = SDL_SetError("Android only supports one window");
goto endfunction;
}
@@ -65,14 +65,14 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data));
if (!data) {
retval = -1;
result = SDL_FALSE;
goto endfunction;
}
data->native_window = Android_JNI_GetNativeWindow();
if (!data->native_window) {
SDL_free(data);
retval = SDL_SetError("Could not fetch native window");
result = SDL_SetError("Could not fetch native window");
goto endfunction;
}
SDL_SetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_ANDROID_WINDOW_POINTER, data->native_window);
@@ -86,7 +86,7 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
if (data->egl_surface == EGL_NO_SURFACE) {
ANativeWindow_release(data->native_window);
SDL_free(data);
retval = -1;
result = SDL_FALSE;
goto endfunction;
}
}
@@ -100,7 +100,7 @@ endfunction:
Android_UnlockActivityMutex();
return retval;
return result;
}
void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
@@ -108,7 +108,7 @@ void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
Android_JNI_SetActivityTitle(window->title);
}
int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
SDL_FullscreenResult Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
{
Android_LockActivityMutex();
@@ -157,7 +157,8 @@ int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_
endfunction:
Android_UnlockActivityMutex();
return 0;
return SDL_FULLSCREEN_SUCCEEDED;
}
void Android_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window)

View File

@@ -26,9 +26,9 @@
#include "../../core/android/SDL_android.h"
#include "../SDL_egl_c.h"
extern int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern bool Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
extern SDL_FullscreenResult Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
extern void Android_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void Android_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable);

View File

@@ -26,11 +26,8 @@
// Forward declaration
@class SDL_CocoaVideoData;
extern int Cocoa_SetClipboardText(SDL_VideoDevice *_this, const char *text);
extern char *Cocoa_GetClipboardText(SDL_VideoDevice *_this);
extern bool Cocoa_HasClipboardText(SDL_VideoDevice *_this);
extern void Cocoa_CheckClipboardUpdate(SDL_CocoaVideoData *data);
extern int Cocoa_SetClipboardData(SDL_VideoDevice *_this);
extern bool Cocoa_SetClipboardData(SDL_VideoDevice *_this);
extern void *Cocoa_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *size);
extern bool Cocoa_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type);

View File

@@ -90,7 +90,7 @@ void Cocoa_CheckClipboardUpdate(SDL_CocoaVideoData *data)
}
}
int Cocoa_SetClipboardData(SDL_VideoDevice *_this)
bool Cocoa_SetClipboardData(SDL_VideoDevice *_this)
{
@autoreleasepool {
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
@@ -125,7 +125,7 @@ int Cocoa_SetClipboardData(SDL_VideoDevice *_this)
}
data.clipboard_count = [pasteboard changeCount];
}
return 0;
return true;
}
void *Cocoa_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *size)

View File

@@ -28,6 +28,6 @@ extern Uint64 Cocoa_GetEventTimestamp(NSTimeInterval nsTimestamp);
extern void Cocoa_PumpEvents(SDL_VideoDevice *_this);
extern int Cocoa_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS);
extern void Cocoa_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this);
extern bool Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this);
#endif // SDL_cocoaevents_h_

View File

@@ -641,7 +641,7 @@ void Cocoa_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window)
}
}
int Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this)
bool Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this)
{
@autoreleasepool {
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
@@ -666,7 +666,7 @@ int Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this)
data.screensaver_assertion = assertion;
}
}
return 0;
return true;
}
#endif // SDL_VIDEO_DRIVER_COCOA

View File

@@ -27,10 +27,10 @@ extern void Cocoa_InitKeyboard(SDL_VideoDevice *_this);
extern void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event);
extern void Cocoa_QuitKeyboard(SDL_VideoDevice *_this);
extern int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
extern int Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
extern bool Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
extern bool Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
#endif // SDL_cocoakeyboard_h_

View File

@@ -381,7 +381,7 @@ void Cocoa_InitKeyboard(SDL_VideoDevice *_this)
SDL_ToggleModState(SDL_KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) ? true : false);
}
int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
bool Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
@autoreleasepool {
NSView *parentView;
@@ -409,7 +409,7 @@ int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert
return Cocoa_UpdateTextInputArea(_this, window);
}
int Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
@@ -419,16 +419,16 @@ int Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
data.fieldEdit = nil;
}
}
return 0;
return true;
}
int Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
if (data.fieldEdit) {
[data.fieldEdit setInputRect:&window->text_input_rect];
}
return 0;
return true;
}
void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event)
@@ -509,12 +509,12 @@ typedef enum
extern CGSConnection _CGSDefaultConnection(void);
extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection, CGSGlobalHotKeyOperatingMode mode);
int Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed)
bool Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed)
{
#ifdef SDL_MAC_NO_SANDBOX
CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), grabbed ? CGSGlobalHotKeyDisable : CGSGlobalHotKeyEnable);
#endif
return 0;
return true;
}
#endif // SDL_VIDEO_DRIVER_COCOA

View File

@@ -22,6 +22,6 @@
#ifdef SDL_VIDEO_DRIVER_COCOA
extern int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
extern bool Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
#endif // SDL_VIDEO_DRIVER_COCOA

View File

@@ -66,7 +66,7 @@
}
@end
static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, int *returnValue)
static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, bool *result)
{
NSAlert *alert;
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
@@ -119,26 +119,26 @@ static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, i
clicked = messageboxdata->numbuttons - 1 - clicked;
}
*buttonID = buttons[clicked].buttonID;
*returnValue = 0;
*result = true;
} else {
*returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
*result = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
}
}
// Display a Cocoa message box
int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
bool Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
{
@autoreleasepool {
__block int returnValue = 0;
__block bool result = 0;
if ([NSThread isMainThread]) {
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &returnValue);
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
} else {
dispatch_sync(dispatch_get_main_queue(), ^{
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &returnValue);
Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &result);
});
}
return returnValue;
return result;
}
}

View File

@@ -35,10 +35,10 @@ struct SDL_DisplayModeData
extern void Cocoa_InitModes(SDL_VideoDevice *_this);
extern void Cocoa_UpdateDisplays(SDL_VideoDevice *_this);
extern int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
extern int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
extern int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
extern bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
extern bool Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
extern bool Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern bool Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
extern void Cocoa_QuitModes(SDL_VideoDevice *_this);
#endif // SDL_cocoamodes_h_

View File

@@ -41,7 +41,7 @@
#define kDisplayModeNativeFlag 0x02000000
#endif
static int CG_SetError(const char *prefix, CGDisplayErr result)
static bool CG_SetError(const char *prefix, CGDisplayErr result)
{
const char *error;
@@ -409,7 +409,7 @@ void Cocoa_UpdateDisplays(SDL_VideoDevice *_this)
}
}
int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
CGRect cgrect;
@@ -419,10 +419,10 @@ int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SD
rect->y = (int)cgrect.origin.y;
rect->w = (int)cgrect.size.width;
rect->h = (int)cgrect.size.height;
return 0;
return true;
}
int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
bool Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
NSScreen *screen = GetNSScreenForDisplayID(displaydata->display);
@@ -439,10 +439,10 @@ int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ
rect->h = (int)frame.size.height;
}
return 0;
return true;
}
int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
bool Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
SDL_DisplayData *data = (SDL_DisplayData *)display->internal;
CVDisplayLinkRef link = NULL;
@@ -498,7 +498,7 @@ int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
}
CVDisplayLinkRelease(link);
return 0;
return true;
}
static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data)
@@ -519,7 +519,7 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo
return result;
}
int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
bool Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal;
SDL_DisplayModeData *data = mode->internal;
@@ -550,10 +550,9 @@ int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_
b_inModeTransition = false;
if (result != kCGErrorSuccess) {
CG_SetError("CGDisplaySwitchToMode()", result);
return -1;
return CG_SetError("CGDisplaySwitchToMode()", result);
}
return 0;
return true;
}
void Cocoa_QuitModes(SDL_VideoDevice *_this)

View File

@@ -25,7 +25,7 @@
#include "SDL_cocoavideo.h"
extern int Cocoa_InitMouse(SDL_VideoDevice *_this);
extern bool Cocoa_InitMouse(SDL_VideoDevice *_this);
extern void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event);
extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event);
extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y);

View File

@@ -237,7 +237,7 @@ static void Cocoa_FreeCursor(SDL_Cursor *cursor)
}
}
static int Cocoa_ShowCursor(SDL_Cursor *cursor)
static bool Cocoa_ShowCursor(SDL_Cursor *cursor)
{
@autoreleasepool {
SDL_VideoDevice *device = SDL_GetVideoDevice();
@@ -250,7 +250,7 @@ static int Cocoa_ShowCursor(SDL_Cursor *cursor)
waitUntilDone:NO];
}
}
return 0;
return true;
}
}
@@ -268,7 +268,7 @@ static SDL_Window *SDL_FindWindowAtPoint(const float x, const float y)
return NULL;
}
static int Cocoa_WarpMouseGlobal(float x, float y)
static bool Cocoa_WarpMouseGlobal(float x, float y)
{
CGPoint point;
SDL_Mouse *mouse = SDL_GetMouse();
@@ -277,7 +277,7 @@ static int Cocoa_WarpMouseGlobal(float x, float y)
if ([data.listener isMovingOrFocusClickPending]) {
DLog("Postponing warp, window being moved or focused.");
[data.listener setPendingMoveX:x Y:y];
return 0;
return true;
}
}
point = CGPointMake(x, y);
@@ -306,15 +306,15 @@ static int Cocoa_WarpMouseGlobal(float x, float y)
}
}
return 0;
return true;
}
static int Cocoa_WarpMouse(SDL_Window *window, float x, float y)
static bool Cocoa_WarpMouse(SDL_Window *window, float x, float y)
{
return Cocoa_WarpMouseGlobal(window->x + x, window->y + y);
}
static int Cocoa_SetRelativeMouseMode(bool enabled)
static bool Cocoa_SetRelativeMouseMode(bool enabled)
{
CGError result;
@@ -326,7 +326,7 @@ static int Cocoa_SetRelativeMouseMode(bool enabled)
*/
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
if ([data.listener isMovingOrFocusClickPending]) {
return 0;
return true;
}
// make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click.
@@ -352,41 +352,41 @@ static int Cocoa_SetRelativeMouseMode(bool enabled)
} else {
[NSCursor unhide];
}
return 0;
return true;
}
static int Cocoa_CaptureMouse(SDL_Window *window)
static bool Cocoa_CaptureMouse(SDL_Window *window)
{
/* our Cocoa event code already tracks the mouse outside the window,
so all we have to do here is say "okay" and do what we always do. */
return 0;
return true;
}
static SDL_MouseButtonFlags Cocoa_GetGlobalMouseState(float *x, float *y)
{
const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
const NSPoint cocoaLocation = [NSEvent mouseLocation];
SDL_MouseButtonFlags retval = 0;
SDL_MouseButtonFlags result = 0;
*x = cocoaLocation.x;
*y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
result |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
result |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
result |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0;
result |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0;
result |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0;
return retval;
return result;
}
int Cocoa_InitMouse(SDL_VideoDevice *_this)
bool Cocoa_InitMouse(SDL_VideoDevice *_this)
{
NSPoint location;
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *internal = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData));
if (internal == NULL) {
return -1;
return false;
}
mouse->internal = internal;
@@ -405,7 +405,7 @@ int Cocoa_InitMouse(SDL_VideoDevice *_this)
location = [NSEvent mouseLocation];
internal->lastMoveX = location.x;
internal->lastMoveY = location.y;
return 0;
return true;
}
static void Cocoa_HandleTitleButtonEvent(SDL_VideoDevice *_this, NSEvent *event)

View File

@@ -69,16 +69,15 @@ struct SDL_GLDriverData
@end
// OpenGL functions
extern int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern bool Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern SDL_FunctionPointer Cocoa_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
extern void Cocoa_GL_UnloadLibrary(SDL_VideoDevice *_this);
extern SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window,
SDL_GLContext context);
extern int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
extern int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern bool Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern bool Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern bool Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
extern bool Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
#ifdef __clang__
#pragma clang diagnostic pop

View File

@@ -225,7 +225,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
@end
int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
// Load the OpenGL library
if (path == NULL) {
@@ -236,11 +236,11 @@ int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
}
_this->gl_config.dll_handle = SDL_LoadObject(path);
if (!_this->gl_config.dll_handle) {
return -1;
return false;
}
SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
return 0;
return true;
}
SDL_FunctionPointer Cocoa_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc)
@@ -284,7 +284,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
_this->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
_this->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
_this->GL_SwapWindow = Cocoa_GLES_SwapWindow;
_this->GL_DeleteContext = Cocoa_GLES_DeleteContext;
_this->GL_DestroyContext = Cocoa_GLES_DestroyContext;
if (Cocoa_GLES_LoadLibrary(_this, NULL) != 0) {
return NULL;
@@ -385,7 +385,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
opaque = (window->flags & SDL_WINDOW_TRANSPARENT) ? 0 : 1;
[context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
if (Cocoa_GL_MakeCurrent(_this, window, sdlcontext) < 0) {
if (!Cocoa_GL_MakeCurrent(_this, window, sdlcontext)) {
SDL_GL_DestroyContext(sdlcontext);
SDL_SetError("Failed making OpenGL context current");
return NULL;
@@ -435,7 +435,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
}
}
int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
bool Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
{
@autoreleasepool {
if (context) {
@@ -449,44 +449,44 @@ int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLConte
[NSOpenGLContext clearCurrentContext];
}
return 0;
return true;
}
}
int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
bool Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{
@autoreleasepool {
SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext();
int status;
bool result;
if (nscontext == nil) {
status = SDL_SetError("No current OpenGL context");
result = SDL_SetError("No current OpenGL context");
} else {
SDL_LockMutex(nscontext->swapIntervalMutex);
SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0);
SDL_AtomicSet(&nscontext->swapIntervalSetting, interval);
SDL_UnlockMutex(nscontext->swapIntervalMutex);
status = 0;
result = true;
}
return status;
return result;
}
}
int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
bool Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
{
@autoreleasepool {
SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext();
if (nscontext) {
*interval = SDL_AtomicGet(&nscontext->swapIntervalSetting);
return 0;
return true;
} else {
return SDL_SetError("no OpenGL context");
}
}
}
int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {
SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext();
@@ -519,18 +519,18 @@ int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
[nscontext flushBuffer];
[nscontext updateIfNeeded];
SDL_UnlockMutex(videodata.swaplock);
return 0;
return true;
}
}
int Cocoa_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
@autoreleasepool {
SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)context;
[nscontext cleanup];
CFRelease(context);
}
return 0;
return true;
}
// We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it.

View File

@@ -35,12 +35,12 @@
#define Cocoa_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define Cocoa_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
extern int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern bool Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern int Cocoa_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern int Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern bool Cocoa_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern bool Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern SDL_EGLSurface Cocoa_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window);
#endif // SDL_VIDEO_OPENGL_EGL

View File

@@ -28,7 +28,7 @@
// EGL implementation of SDL OpenGL support
int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
// If the profile requested is not GL ES, switch over to WIN_GL functions
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
@@ -42,7 +42,7 @@ int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
_this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
_this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
_this->GL_SwapWindow = Cocoa_GL_SwapWindow;
_this->GL_DeleteContext = Cocoa_GL_DeleteContext;
_this->GL_DestroyContext = Cocoa_GL_DestroyContext;
_this->GL_GetEGLSurface = NULL;
return Cocoa_GL_LoadLibrary(_this, path);
#else
@@ -54,7 +54,7 @@ int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform);
}
return 0;
return true;
}
SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window)
@@ -75,10 +75,10 @@ SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *windo
_this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
_this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
_this->GL_SwapWindow = Cocoa_GL_SwapWindow;
_this->GL_DeleteContext = Cocoa_GL_DeleteContext;
_this->GL_DestroyContext = Cocoa_GL_DestroyContext;
_this->GL_GetEGLSurface = NULL;
if (Cocoa_GL_LoadLibrary(_this, NULL) != 0) {
if (!Cocoa_GL_LoadLibrary(_this, NULL)) {
return NULL;
}
@@ -91,29 +91,29 @@ SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *windo
}
}
int Cocoa_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
bool Cocoa_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
@autoreleasepool {
SDL_EGL_DeleteContext(_this, context);
SDL_EGL_DestroyContext(_this, context);
}
return 0;
return true;
}
int Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {
return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface);
}
}
int Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
bool Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
{
@autoreleasepool {
return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface : EGL_NO_SURFACE, context);
}
}
int Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {
NSView *v;
@@ -127,9 +127,9 @@ int Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window)
#if 0 // When hint SDL_HINT_OPENGL_ES_DRIVER is set to "1" (e.g. for ANGLE support), _this->gl_config.driver_loaded can be 1, while the below lines function.
SDL_assert(!_this->gl_config.driver_loaded);
#endif
if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform) < 0) {
if (!SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform)) {
SDL_EGL_UnloadLibrary(_this);
return -1;
return false;
}
_this->gl_config.driver_loaded = 1;
}

View File

@@ -25,7 +25,7 @@
#include "SDL_cocoavideo.h"
extern int Cocoa_InitPen(SDL_VideoDevice *_this);
extern bool Cocoa_InitPen(SDL_VideoDevice *_this);
extern bool Cocoa_HandlePenEvent(SDL_CocoaWindowData *_data, NSEvent *event); // return false if we didn't handle this event.
extern void Cocoa_QuitPen(SDL_VideoDevice *_this);

View File

@@ -27,9 +27,9 @@
#include "../../events/SDL_pen_c.h"
int Cocoa_InitPen(SDL_VideoDevice *_this)
bool Cocoa_InitPen(SDL_VideoDevice *_this)
{
return 0;
return true;
}
typedef struct Cocoa_PenHandle

View File

@@ -23,6 +23,6 @@
#ifndef SDL_cocoashape_h_
#define SDL_cocoashape_h_
extern int Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape);
extern bool Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape);
#endif // SDL_cocoashape_h_

View File

@@ -26,7 +26,7 @@
#include "SDL_cocoashape.h"
int Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape)
bool Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape)
{
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
BOOL ignoresMouseEvents = NO;
@@ -42,13 +42,13 @@ int Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surf
int y = (int)SDL_roundf((point.y / (window->h - 1)) * (shape->h - 1));
Uint8 a;
if (SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) < 0 || a == SDL_ALPHA_TRANSPARENT) {
if (!SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) || a == SDL_ALPHA_TRANSPARENT) {
ignoresMouseEvents = YES;
}
}
}
data.nswindow.ignoresMouseEvents = ignoresMouseEvents;
return 0;
return true;
}
#endif // SDL_VIDEO_DRIVER_COCOA

View File

@@ -41,7 +41,7 @@
@end
// Initialization/Query functions
static int Cocoa_VideoInit(SDL_VideoDevice *_this);
static bool Cocoa_VideoInit(SDL_VideoDevice *_this);
static void Cocoa_VideoQuit(SDL_VideoDevice *_this);
// Cocoa driver bootstrap functions
@@ -134,7 +134,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
device->GL_SwapWindow = Cocoa_GL_SwapWindow;
device->GL_DeleteContext = Cocoa_GL_DeleteContext;
device->GL_DestroyContext = Cocoa_GL_DestroyContext;
device->GL_GetEGLSurface = NULL;
#endif
#ifdef SDL_VIDEO_OPENGL_EGL
@@ -149,7 +149,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void)
device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval;
device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval;
device->GL_SwapWindow = Cocoa_GLES_SwapWindow;
device->GL_DeleteContext = Cocoa_GLES_DeleteContext;
device->GL_DestroyContext = Cocoa_GLES_DestroyContext;
device->GL_GetEGLSurface = Cocoa_GLES_GetEGLSurface;
#ifdef SDL_VIDEO_OPENGL_CGL
}
@@ -192,17 +192,18 @@ VideoBootStrap COCOA_bootstrap = {
Cocoa_ShowMessageBox
};
int Cocoa_VideoInit(SDL_VideoDevice *_this)
static bool Cocoa_VideoInit(SDL_VideoDevice *_this)
{
@autoreleasepool {
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
Cocoa_InitModes(_this);
Cocoa_InitKeyboard(_this);
if (Cocoa_InitMouse(_this) < 0) {
return -1;
} else if (Cocoa_InitPen(_this) < 0) {
return -1;
if (!Cocoa_InitMouse(_this)) {
return false;
}
if (!Cocoa_InitPen(_this)) {
return false;
}
// Assume we have a mouse and keyboard
@@ -215,10 +216,10 @@ int Cocoa_VideoInit(SDL_VideoDevice *_this)
data.swaplock = SDL_CreateMutex();
if (!data.swaplock) {
return -1;
return false;
}
return 0;
return true;
}
}

View File

@@ -34,16 +34,15 @@
#if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_COCOA)
int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
void Cocoa_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
Uint32 *count);
int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
extern bool Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern void Cocoa_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
extern char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count);
extern bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
void Cocoa_Vulkan_DestroySurface(SDL_VideoDevice *_this,
extern void Cocoa_Vulkan_DestroySurface(SDL_VideoDevice *_this,
VkInstance instance,
VkSurfaceKHR surface,
const struct VkAllocationCallbacks *allocator);

View File

@@ -46,7 +46,7 @@ const char *defaultPaths[] = {
// Since libSDL is most likely a .dylib, need RTLD_DEFAULT not RTLD_SELF.
#define DEFAULT_HANDLE RTLD_DEFAULT
int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
VkExtensionProperties *extensions = NULL;
Uint32 extensionCount = 0;
@@ -143,12 +143,12 @@ int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
SDL_SetError("Installed Vulkan Portability library doesn't implement the " VK_EXT_METAL_SURFACE_EXTENSION_NAME " or " VK_MVK_MACOS_SURFACE_EXTENSION_NAME " extensions");
goto fail;
}
return 0;
return true;
fail:
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
return -1;
return false;
}
void Cocoa_Vulkan_UnloadLibrary(SDL_VideoDevice *_this)
@@ -173,18 +173,18 @@ char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
return extensionsForCocoa;
}
static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface,
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT,
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK)
static bool Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface,
PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT,
PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK)
{
VkResult result;
VkResult rc;
SDL_MetalView metalview = Cocoa_Metal_CreateView(_this, window);
if (metalview == NULL) {
return -1;
return false;
}
if (vkCreateMetalSurfaceEXT) {
@@ -194,10 +194,10 @@ static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
createInfo.flags = 0;
createInfo.pLayer = (__bridge const CAMetalLayer *)
Cocoa_Metal_GetLayer(_this, metalview);
result = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface);
if (result != VK_SUCCESS) {
rc = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface);
if (rc != VK_SUCCESS) {
Cocoa_Metal_DestroyView(_this, metalview);
return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(result));;
return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(rc));
}
} else {
VkMacOSSurfaceCreateInfoMVK createInfo = {};
@@ -205,11 +205,11 @@ static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = (const void *)metalview;
result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
rc = vkCreateMacOSSurfaceMVK(instance, &createInfo,
NULL, surface);
if (result != VK_SUCCESS) {
if (rc != VK_SUCCESS) {
Cocoa_Metal_DestroyView(_this, metalview);
return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(result));
return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(rc));
}
}
@@ -223,10 +223,10 @@ static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this,
* knowledge of Metal can proceed. */
CFBridgingRelease(metalview);
return 0; // success!
return true; // success!
}
int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
@@ -242,7 +242,7 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
(PFN_vkCreateMacOSSurfaceMVK)vkGetInstanceProcAddr(
instance,
"vkCreateMacOSSurfaceMVK");
VkResult result;
VkResult rc;
if (!_this->vulkan_config.loader_handle) {
return SDL_SetError("Vulkan is not loaded");
@@ -266,9 +266,9 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pLayer = (CAMetalLayer *)data.sdlContentView.layer;
result = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface);
if (result != VK_SUCCESS) {
return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(result));
rc = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface);
if (rc != VK_SUCCESS) {
return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(rc));
}
} else {
VkMacOSSurfaceCreateInfoMVK createInfo = {};
@@ -276,10 +276,10 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = (__bridge const void *)data.sdlContentView;
result = vkCreateMacOSSurfaceMVK(instance, &createInfo,
rc = vkCreateMacOSSurfaceMVK(instance, &createInfo,
allocator, surface);
if (result != VK_SUCCESS) {
return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(result));
if (rc != VK_SUCCESS) {
return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(rc));
}
}
}
@@ -287,7 +287,7 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this,
return Cocoa_Vulkan_CreateSurfaceViaMetalView(_this, window, instance, allocator, surface, vkCreateMetalSurfaceEXT, vkCreateMacOSSurfaceMVK);
}
return 0;
return true;
}
void Cocoa_Vulkan_DestroySurface(SDL_VideoDevice *_this,

View File

@@ -155,15 +155,15 @@ typedef enum
extern bool b_inModeTransition;
extern int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern bool Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
extern int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon);
extern bool Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_SetWindowMaximumSize(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h);
extern int Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity);
extern bool Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity);
extern void Cocoa_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window);
@@ -173,17 +173,17 @@ extern void Cocoa_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void Cocoa_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered);
extern void Cocoa_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable);
extern void Cocoa_SetWindowAlwaysOnTop(SDL_VideoDevice *_this, SDL_Window *window, bool on_top);
extern int Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
extern SDL_FullscreenResult Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
extern void *Cocoa_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size);
extern SDL_DisplayID Cocoa_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
extern bool Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
extern void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled);
extern bool Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled);
extern void Cocoa_AcceptDragAndDrop(SDL_Window *window, bool accept);
extern int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
extern int Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable);
extern int Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window);
extern int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
extern bool Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable);
extern bool Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window);
extern bool Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window);
#endif // SDL_cocoawindow_h_

View File

@@ -441,7 +441,7 @@ static void ScheduleContextUpdates(SDL_CocoaWindowData *data)
}
// !!! FIXME: this should use a hint callback.
static int GetHintCtrlClickEmulateRightClick(void)
static bool GetHintCtrlClickEmulateRightClick(void)
{
return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, false);
}
@@ -925,7 +925,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
int y = (int)SDL_roundf(((window->h - point.y) / (window->h - 1)) * (shape->h - 1));
Uint8 a;
if (SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) < 0 || a == SDL_ALPHA_TRANSPARENT) {
if (!SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) || a == SDL_ALPHA_TRANSPARENT) {
ignoresMouseEvents = YES;
}
}
@@ -1538,12 +1538,11 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
return NO; // not a special area, carry on.
}
static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button)
static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button)
{
SDL_MouseID mouseID = SDL_DEFAULT_MOUSE_ID;
const int clicks = (int)[theEvent clickCount];
SDL_Window *focus = SDL_GetKeyboardFocus();
int rc;
// macOS will send non-left clicks to background windows without raising them, so we need to
// temporarily adjust the mouse position when this happens, as `mouse` will be tracking
@@ -1551,19 +1550,17 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
// event for the background window, this just makes sure the button is reported at the
// correct position in its own event.
if (focus && ([theEvent window] == ((__bridge SDL_CocoaWindowData *)focus->internal).nswindow)) {
rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
} else {
const float orig_x = mouse->x;
const float orig_y = mouse->y;
const NSPoint point = [theEvent locationInWindow];
mouse->x = (int)point.x;
mouse->y = (int)(window->h - point.y);
rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks);
mouse->x = orig_x;
mouse->y = orig_y;
}
return rc;
}
- (void)mouseDown:(NSEvent *)theEvent
@@ -2005,7 +2002,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
@end
static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow *nswindow, NSView *nsview)
static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow *nswindow, NSView *nsview)
{
@autoreleasepool {
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->internal;
@@ -2137,11 +2134,11 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
// All done!
window->internal = (SDL_WindowData *)CFBridgingRetain(data);
return 0;
return true;
}
}
int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
bool Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
@autoreleasepool {
SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->internal;
@@ -2273,29 +2270,29 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
#endif // SDL_VIDEO_OPENGL_ES2
[nswindow setContentView:nsview];
if (SetupWindowData(_this, window, nswindow, nsview) < 0) {
return -1;
if (!SetupWindowData(_this, window, nswindow, nsview)) {
return false;
}
if (!(window->flags & SDL_WINDOW_OPENGL)) {
return 0;
return true;
}
// The rest of this macro mess is for OpenGL or OpenGL ES windows
#ifdef SDL_VIDEO_OPENGL_ES2
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
#ifdef SDL_VIDEO_OPENGL_EGL
if (Cocoa_GLES_SetupWindow(_this, window) < 0) {
if (!Cocoa_GLES_SetupWindow(_this, window)) {
Cocoa_DestroyWindow(_this, window);
return -1;
return false;
}
return 0;
return true;
#else
return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
#endif // SDL_VIDEO_OPENGL_EGL
}
#endif // SDL_VIDEO_OPENGL_ES2
return 0;
return true;
}
}
@@ -2309,7 +2306,7 @@ void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
}
}
int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon)
bool Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon)
{
@autoreleasepool {
NSImage *nsimage = Cocoa_CreateImage(icon);
@@ -2317,14 +2314,14 @@ int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface
if (nsimage) {
[NSApp setApplicationIconImage:nsimage];
return 0;
return true;
}
return SDL_SetError("Unable to set the window's icon");
}
}
int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
{
@autoreleasepool {
SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->internal;
@@ -2374,7 +2371,7 @@ int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
windata.send_floating_position = true;
}
}
return 0;
return true;
}
void Cocoa_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
@@ -2702,7 +2699,7 @@ void Cocoa_SetWindowAlwaysOnTop(SDL_VideoDevice *_this, SDL_Window *window, bool
}
}
int Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
SDL_FullscreenResult Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
{
@autoreleasepool {
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
@@ -2821,7 +2818,7 @@ int Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vi
ScheduleContextUpdates(data);
}
return 0;
return SDL_FULLSCREEN_SUCCEEDED;
}
void *Cocoa_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size)
@@ -2896,13 +2893,13 @@ SDL_DisplayID Cocoa_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *wind
}
}
int Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window)
{
Cocoa_UpdateClipCursor(window);
return 0;
return true;
}
int Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed)
bool Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed)
{
@autoreleasepool {
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
@@ -2922,7 +2919,7 @@ int Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool gr
}
}
return 0;
return true;
}
void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
@@ -3036,12 +3033,12 @@ bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, bool state, bool blockin
}
}
int Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled)
bool Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled)
{
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
[data.listener updateHitTest];
return 0;
return true;
}
void Cocoa_AcceptDragAndDrop(SDL_Window *window, bool accept)
@@ -3057,7 +3054,7 @@ void Cocoa_AcceptDragAndDrop(SDL_Window *window, bool accept)
}
}
int Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window)
bool Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window)
{
@autoreleasepool {
SDL_CocoaWindowData *modal_data = (__bridge SDL_CocoaWindowData *)modal_window->internal;
@@ -3072,10 +3069,10 @@ int Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SD
}
}
return 0;
return true;
}
int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation)
bool Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation)
{
@autoreleasepool {
// Note that this is app-wide and not window-specific!
@@ -3099,27 +3096,27 @@ int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOpera
default:
return SDL_Unsupported();
}
return 0;
return true;
}
}
int Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable)
bool Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable)
{
return 0; // just succeed, the real work is done elsewhere.
return true; // just succeed, the real work is done elsewhere.
}
int Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity)
bool Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity)
{
@autoreleasepool {
SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal;
[data.nswindow setAlphaValue:opacity];
return 0;
return true;
}
}
int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
int ret = 0;
bool result = true;
@autoreleasepool {
/* The timeout needs to be high enough that animated fullscreen
@@ -3131,7 +3128,7 @@ int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window)
SDL_PumpEvents();
if (SDL_GetTicksNS() >= timeout) {
ret = 1;
result = false;
break;
}
if (![data.listener hasPendingWindowOperation]) {
@@ -3142,7 +3139,7 @@ int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
return ret;
return result;
}
#endif // SDL_VIDEO_DRIVER_COCOA

View File

@@ -29,7 +29,7 @@
#define DUMMY_SURFACE "SDL.internal.window.surface"
int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
bool SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB8888;
@@ -39,7 +39,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
SDL_GetWindowSizeInPixels(window, &w, &h);
surface = SDL_CreateSurface(w, h, surface_format);
if (!surface) {
return -1;
return false;
}
// Save the info and return!
@@ -47,10 +47,10 @@ int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
return 0;
return true;
}
int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
bool SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
{
static int frame_number;
SDL_Surface *surface;
@@ -67,7 +67,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window
SDL_GetWindowID(window), ++frame_number);
SDL_SaveBMP(surface, file);
}
return 0;
return true;
}
void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)

View File

@@ -24,8 +24,8 @@
#include "SDL_internal.h"
extern int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern bool SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern bool SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
#endif // SDL_nullframebuffer_c_h_

View File

@@ -52,13 +52,13 @@
#define DUMMYVID_DRIVER_EVDEV_NAME "evdev"
// Initialization/Query functions
static int DUMMY_VideoInit(SDL_VideoDevice *_this);
static bool DUMMY_VideoInit(SDL_VideoDevice *_this);
static void DUMMY_VideoQuit(SDL_VideoDevice *_this);
static int DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
static bool DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, window->floating.x, window->floating.y);
return 0;
return true;
}
static void DUMMY_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
@@ -149,7 +149,7 @@ VideoBootStrap DUMMY_evdev_bootstrap = {
#endif // SDL_INPUT_LINUXEV
int DUMMY_VideoInit(SDL_VideoDevice *_this)
bool DUMMY_VideoInit(SDL_VideoDevice *_this)
{
SDL_DisplayMode mode;
@@ -159,7 +159,7 @@ int DUMMY_VideoInit(SDL_VideoDevice *_this)
mode.w = 1024;
mode.h = 768;
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
return -1;
return false;
}
#ifdef SDL_INPUT_LINUXEV
@@ -167,7 +167,7 @@ int DUMMY_VideoInit(SDL_VideoDevice *_this)
#endif
// We're done!
return 0;
return true;
}
void DUMMY_VideoQuit(SDL_VideoDevice *_this)

View File

@@ -27,7 +27,7 @@
#include <emscripten/threading.h>
int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
bool Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch)
{
SDL_Surface *surface;
const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XBGR8888;
@@ -43,7 +43,7 @@ int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo
surface = SDL_CreateSurface(w, h, surface_format);
if (!surface) {
return -1;
return false;
}
// Save the info and return!
@@ -51,10 +51,10 @@ int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo
*format = surface_format;
*pixels = surface->pixels;
*pitch = surface->pitch;
return 0;
return true;
}
int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
bool Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects)
{
SDL_Surface *surface;
@@ -147,7 +147,7 @@ int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo
emscripten_sleep(0);
}
return 0;
return true;
}
void Emscripten_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window)

View File

@@ -23,8 +23,8 @@
#ifndef SDL_emscriptenframebuffer_h_
#define SDL_emscriptenframebuffer_h_
extern int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern bool Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch);
extern bool Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects);
extern void Emscripten_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
#endif // SDL_emscriptenframebuffer_h_

View File

@@ -140,7 +140,7 @@ static void Emscripten_FreeCursor(SDL_Cursor *cursor)
}
}
static int Emscripten_ShowCursor(SDL_Cursor *cursor)
static bool Emscripten_ShowCursor(SDL_Cursor *cursor)
{
SDL_CursorData *curdata;
if (SDL_GetMouseFocus() != NULL) {
@@ -166,10 +166,10 @@ static int Emscripten_ShowCursor(SDL_Cursor *cursor)
/* *INDENT-ON* */ // clang-format on
}
}
return 0;
return true;
}
static int Emscripten_SetRelativeMouseMode(bool enabled)
static bool Emscripten_SetRelativeMouseMode(bool enabled)
{
SDL_Window *window;
SDL_WindowData *window_data;
@@ -178,20 +178,20 @@ static int Emscripten_SetRelativeMouseMode(bool enabled)
if (enabled) {
window = SDL_GetMouseFocus();
if (!window) {
return -1;
return false;
}
window_data = window->internal;
if (emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) {
return 0;
return true;
}
} else {
if (emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) {
return 0;
return true;
}
}
return -1;
return false;
}
void Emscripten_InitMouse(void)

View File

@@ -29,9 +29,9 @@
#include "SDL_emscriptenvideo.h"
#include "SDL_emscriptenopengles.h"
int Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
return 0;
return true;
}
void Emscripten_GLES_UnloadLibrary(SDL_VideoDevice *_this)
@@ -43,7 +43,7 @@ SDL_FunctionPointer Emscripten_GLES_GetProcAddress(SDL_VideoDevice *_this, const
return emscripten_webgl_get_proc_address(proc);
}
int Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval)
bool Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{
if (interval < 0) {
return SDL_SetError("Late swap tearing currently unsupported");
@@ -53,10 +53,10 @@ int Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval)
emscripten_set_main_loop_timing(EM_TIMING_RAF, interval);
}
return 0;
return true;
}
int Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
bool Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
{
int mode, value;
@@ -64,10 +64,10 @@ int Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
if (mode == EM_TIMING_RAF) {
*interval = value;
return 0;
return true;
} else {
*interval = 0;
return 0;
return true;
}
}
@@ -112,7 +112,7 @@ SDL_GLContext Emscripten_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *
return (SDL_GLContext)context;
}
int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
bool Emscripten_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
SDL_Window *window;
@@ -126,19 +126,19 @@ int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context)
}
emscripten_webgl_destroy_context((EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)context);
return 0;
return true;
}
int Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, true)) {
// give back control to browser for screen refresh
emscripten_sleep(0);
}
return 0;
return true;
}
int Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
bool Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context)
{
// it isn't possible to reuse contexts across canvases
if (window && context) {
@@ -152,7 +152,7 @@ int Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_
if (emscripten_webgl_make_context_current((EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)context) != EMSCRIPTEN_RESULT_SUCCESS) {
return SDL_SetError("Unable to make context current");
}
return 0;
return true;
}
#endif // SDL_VIDEO_DRIVER_EMSCRIPTEN

View File

@@ -28,15 +28,15 @@
#include "../SDL_sysvideo.h"
// OpenGLES functions
extern int Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern bool Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern void Emscripten_GLES_UnloadLibrary(SDL_VideoDevice *_this);
extern SDL_FunctionPointer Emscripten_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
extern int Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern int Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
extern bool Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern bool Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
extern SDL_GLContext Emscripten_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern int Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern bool Emscripten_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern bool Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
#endif // SDL_VIDEO_DRIVER_EMSCRIPTEN

View File

@@ -35,16 +35,16 @@
#define EMSCRIPTENVID_DRIVER_NAME "emscripten"
// Initialization/Query functions
static int Emscripten_VideoInit(SDL_VideoDevice *_this);
static int Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
static bool Emscripten_VideoInit(SDL_VideoDevice *_this);
static bool Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
static void Emscripten_VideoQuit(SDL_VideoDevice *_this);
static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
static bool Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
static bool Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
static void Emscripten_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h);
static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
static SDL_FullscreenResult Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
static void Emscripten_PumpEvents(SDL_VideoDevice *_this);
static void Emscripten_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
@@ -107,7 +107,7 @@ static SDL_VideoDevice *Emscripten_CreateDevice(void)
device->GL_SetSwapInterval = Emscripten_GLES_SetSwapInterval;
device->GL_GetSwapInterval = Emscripten_GLES_GetSwapInterval;
device->GL_SwapWindow = Emscripten_GLES_SwapWindow;
device->GL_DeleteContext = Emscripten_GLES_DeleteContext;
device->GL_DestroyContext = Emscripten_GLES_DestroyContext;
device->free = Emscripten_DeleteDevice;
@@ -120,7 +120,7 @@ VideoBootStrap Emscripten_bootstrap = {
NULL // no ShowMessageBox implementation
};
int Emscripten_VideoInit(SDL_VideoDevice *_this)
bool Emscripten_VideoInit(SDL_VideoDevice *_this)
{
SDL_DisplayMode mode;
@@ -131,7 +131,7 @@ int Emscripten_VideoInit(SDL_VideoDevice *_this)
mode.pixel_density = emscripten_get_device_pixel_ratio();
if (SDL_AddBasicVideoDisplay(&mode) == 0) {
return -1;
return false;
}
Emscripten_InitMouse();
@@ -141,13 +141,13 @@ int Emscripten_VideoInit(SDL_VideoDevice *_this)
SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false);
// We're done!
return 0;
return true;
}
static int Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
static bool Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
// can't do this
return 0;
return true;
}
static void Emscripten_VideoQuit(SDL_VideoDevice *_this)
@@ -155,7 +155,7 @@ static void Emscripten_VideoQuit(SDL_VideoDevice *_this)
Emscripten_QuitMouse();
}
static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
static bool Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
if (rect) {
rect->x = 0;
@@ -167,7 +167,7 @@ static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDi
return window.innerHeight;
});
}
return 0;
return true;
}
static void Emscripten_PumpEvents(SDL_VideoDevice *_this)
@@ -175,7 +175,7 @@ static void Emscripten_PumpEvents(SDL_VideoDevice *_this)
// do nothing.
}
static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
static bool Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
SDL_WindowData *wdata;
double scaled_w, scaled_h;
@@ -185,7 +185,7 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, S
// Allocate window internal data
wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
if (!wdata) {
return -1;
return false;
}
selector = SDL_GetHint(SDL_HINT_EMSCRIPTEN_CANVAS_SELECTOR);
@@ -239,7 +239,7 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, S
Emscripten_RegisterEventHandlers(wdata);
// Window has been successfully created
return 0;
return true;
}
static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
@@ -291,7 +291,7 @@ static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
}
}
static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
static SDL_FullscreenResult Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
{
SDL_WindowData *data;
int res = -1;
@@ -329,11 +329,11 @@ static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *wi
}
if (res == EMSCRIPTEN_RESULT_SUCCESS) {
return 0;
return SDL_FULLSCREEN_SUCCEEDED;
} else if (res == EMSCRIPTEN_RESULT_DEFERRED) {
return 1;
return SDL_FULLSCREEN_PENDING;
} else {
return -1;
return SDL_FULLSCREEN_FAILED;
}
}

View File

@@ -97,16 +97,15 @@ static void SDLCALL GDK_InternalHintCallback(
}
}
static int GDK_InternalEnsureTaskQueue(void)
static bool GDK_InternalEnsureTaskQueue(void)
{
if (!g_TextTaskQueue) {
if (SDL_GetGDKTaskQueue(&g_TextTaskQueue) < 0) {
if (!SDL_GetGDKTaskQueue(&g_TextTaskQueue)) {
// SetError will be done for us.
return -1;
return false;
}
}
return 0;
return true;
}
static void CALLBACK GDK_InternalTextEntryCallback(XAsyncBlock *asyncBlock)
@@ -178,7 +177,7 @@ void GDK_EnsureHints(void)
}
}
int GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
bool GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props)
{
/*
* Currently a stub, since all input is handled by the virtual keyboard,
@@ -191,16 +190,16 @@ int GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
* Right now this function isn't implemented on Desktop
* and seems to be present only in the docs? So I didn't bother.
*/
return 0;
return true;
}
int GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
bool GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window)
{
// See notice in GDK_StartTextInput
return 0;
return true;
}
int GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
bool GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
{
/*
* XGameUiShowTextEntryAsync does not allow you to set
@@ -211,13 +210,13 @@ int GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
*
* Right now it's a stub which may be useful later.
*/
return 0;
return true;
}
int GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window)
bool GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window)
{
// See notice in GDK_StartTextInput
return 0;
return true;
}
bool GDK_HasScreenKeyboardSupport(SDL_VideoDevice *_this)
@@ -243,7 +242,7 @@ void GDK_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_Prop
return;
}
if (GDK_InternalEnsureTaskQueue() < 0) {
if (!GDK_InternalEnsureTaskQueue()) {
// unable to obtain the SDL GDK queue
return;
}

View File

@@ -32,10 +32,10 @@ extern "C" {
void GDK_EnsureHints(void);
int GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
int GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window);
int GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window);
int GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window);
bool GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);
bool GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window);
bool GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window);
bool GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window);
bool GDK_HasScreenKeyboardSupport(SDL_VideoDevice *_this);
void GDK_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props);

View File

@@ -127,7 +127,7 @@ class SDL_BWin : public BWindow
if (_SDL_GLView == _cur_view)
RemoveChild(_SDL_GLView);
_SDL_GLView = NULL;
// _SDL_GLView deleted by HAIKU_GL_DeleteContext
// _SDL_GLView deleted by HAIKU_GL_DestroyContext
}
#endif
@@ -213,7 +213,7 @@ class SDL_BWin : public BWindow
SDL_Looper->SetCurrentContext(NULL);
_SDL_GLView = NULL;
UpdateCurrentView();
// _SDL_GLView deleted by HAIKU_GL_DeleteContext
// _SDL_GLView deleted by HAIKU_GL_DestroyContext
}
Unlock();
}

View File

@@ -34,7 +34,8 @@
extern "C" {
#endif
int HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text) {
bool HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text)
{
BMessage *clip = NULL;
if (be_clipboard->Lock()) {
be_clipboard->Clear();
@@ -47,7 +48,7 @@ int HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text) {
}
be_clipboard->Unlock();
}
return 0;
return true;
}
char *HAIKU_GetClipboardText(SDL_VideoDevice *_this) {

View File

@@ -24,7 +24,7 @@
#ifndef SDL_BCLIPBOARD_H
#define SDL_BCLIPBOARD_H
extern int HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text);
extern bool HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text);
extern char *HAIKU_GetClipboardText(SDL_VideoDevice *_this);
extern bool HAIKU_HasClipboardText(SDL_VideoDevice *_this);

View File

@@ -35,21 +35,22 @@
extern "C" {
#endif
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
{
return (SDL_BWin *)(window->internal);
}
static SDL_INLINE SDL_BLooper *_GetBeLooper() {
static SDL_INLINE SDL_BLooper *_GetBeLooper()
{
return SDL_Looper;
}
int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
SDL_PixelFormat * format,
void ** pixels, int *pitch) {
bool HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, void ** pixels, int *pitch)
{
SDL_BWin *bwin = _ToBeWin(window);
BScreen bscreen;
if (!bscreen.IsValid()) {
return -1;
return false;
}
// Make sure we have exclusive access to frame buffer data
@@ -87,22 +88,22 @@ int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
*pitch = bitmap->BytesPerRow();
bwin->UnlockBuffer();
return 0;
return true;
}
int HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
bool HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window,
const SDL_Rect * rects, int numrects) {
if (!window) {
return 0;
return true;
}
SDL_BWin *bwin = _ToBeWin(window);
bwin->PostMessage(BWIN_UPDATE_FRAMEBUFFER);
return 0;
return true;
}
void HAIKU_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window) {

View File

@@ -30,11 +30,11 @@ extern "C" {
#include "../SDL_sysvideo.h"
extern int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
SDL_PixelFormat *format,
void **pixels, int *pitch);
extern int HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
const SDL_Rect *rects, int numrects);
extern bool HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
SDL_PixelFormat *format,
void **pixels, int *pitch);
extern bool HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window,
const SDL_Rect *rects, int numrects);
extern void HAIKU_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window);
extern int32 HAIKU_DrawThread(void *data);

View File

@@ -335,7 +335,7 @@ protected:
extern "C" {
#endif
int HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
bool HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID)
{
// Initialize button by closed or error value first.
*buttonID = G_CLOSE_BUTTON_ID;
@@ -373,7 +373,7 @@ int HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID
// Initialize button by real pushed value then.
*buttonID = pushedButton;
return 0;
return true;
}
#ifdef __cplusplus

View File

@@ -31,8 +31,7 @@
extern "C" {
#endif
extern int
HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
extern bool HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID);
#ifdef __cplusplus
}

View File

@@ -48,15 +48,18 @@ struct SDL_DisplayModeData {
};
#endif
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
{
return (SDL_BWin *)(window->internal);
}
static SDL_INLINE SDL_BLooper *_GetBeLooper() {
static SDL_INLINE SDL_BLooper *_GetBeLooper()
{
return SDL_Looper;
}
static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) {
static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode)
{
#if WRAP_BMODE
return mode->internal->bmode;
#else
@@ -76,7 +79,8 @@ static void get_refresh_rate(display_mode &mode, int *numerator, int *denominato
/* TODO:
* This is a useful debugging tool. Uncomment and insert into code as needed.
*/
void _SpoutModeData(display_mode *bmode) {
void _SpoutModeData(display_mode *bmode)
{
printf("BMode:\n");
printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
printf("\th,v = (%i,%i)\n", bmode->h_display_start,
@@ -166,7 +170,8 @@ SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace)
return SDL_PIXELFORMAT_UNKNOWN;
}
static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) {
static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode)
{
SDL_zerop(mode);
mode->w = bmode->virtual_width;
mode->h = bmode->virtual_height;
@@ -186,7 +191,8 @@ static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *
}
// Later, there may be more than one monitor available
static void _AddDisplay(BScreen *screen) {
static void _AddDisplay(BScreen *screen)
{
SDL_DisplayMode mode;
display_mode bmode;
screen->GetMode(&bmode);
@@ -200,32 +206,35 @@ static void _AddDisplay(BScreen *screen) {
* Functions called by SDL
*/
int HAIKU_InitModes(SDL_VideoDevice *_this) {
bool HAIKU_InitModes(SDL_VideoDevice *_this)
{
BScreen screen;
/* TODO: When Haiku supports multiple display screens, call
_AddDisplayScreen() for each of them. */
_AddDisplay(&screen);
return 0;
return true;
}
int HAIKU_QuitModes(SDL_VideoDevice *_this) {
// FIXME: Nothing really needs to be done here at the moment?
return 0;
void HAIKU_QuitModes(SDL_VideoDevice *_this)
{
return;
}
int HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) {
bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect)
{
BScreen bscreen;
BRect rc = bscreen.Frame();
rect->x = (int)rc.left;
rect->y = (int)rc.top;
rect->w = (int)rc.Width() + 1;
rect->h = (int)rc.Height() + 1;
return 0;
return true;
}
int HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) {
bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
// Get the current screen
BScreen bscreen;
@@ -247,11 +256,12 @@ int HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) {
}
}
free(bmodes); // This should not be SDL_free()
return 0;
return true;
}
int HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) {
bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
// Get the current screen
BScreen bscreen;
if (!bscreen.IsValid()) {
@@ -287,7 +297,7 @@ int HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_
// HAIKU_GL_RebootContexts(_this);
#endif
return 0;
return true;
}
#ifdef __cplusplus

View File

@@ -30,13 +30,11 @@ extern "C" {
extern SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace);
extern int HAIKU_InitModes(SDL_VideoDevice *_this);
extern int HAIKU_QuitModes(SDL_VideoDevice *_this);
extern int HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display,
SDL_Rect *rect);
extern int HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern int HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display,
SDL_DisplayMode *mode);
extern bool HAIKU_InitModes(SDL_VideoDevice *_this);
extern void HAIKU_QuitModes(SDL_VideoDevice *_this);
extern bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect);
extern bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
#ifdef __cplusplus
}

View File

@@ -35,16 +35,18 @@ extern "C" {
#endif
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
{
return (SDL_BWin *)(window->internal);
}
static SDL_INLINE SDL_BLooper *_GetBeLooper() {
static SDL_INLINE SDL_BLooper *_GetBeLooper()
{
return SDL_Looper;
}
// Passing a NULL path means load pointers from the application
int HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
// FIXME: Is this working correctly?
image_info info;
@@ -60,7 +62,7 @@ int HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
SDL_arraysize(_this->gl_config.driver_path));
}
}
return 0;
return true;
}
SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc)
@@ -84,12 +86,14 @@ SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char *
}
int HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window * window) {
bool HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
_ToBeWin(window)->SwapBuffers();
return 0;
return true;
}
int HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context) {
bool HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context)
{
BGLView* glView = (BGLView*)context;
// printf("HAIKU_GL_MakeCurrent(%llx), win = %llx, thread = %d\n", (uint64)context, (uint64)window, find_thread(NULL));
if (glView) {
@@ -98,11 +102,12 @@ int HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLCont
}
}
_GetBeLooper()->SetCurrentContext(glView);
return 0;
return true;
}
SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window) {
SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window)
{
/* FIXME: Not sure what flags should be included here; may want to have
most of them */
SDL_BWin *bwin = _ToBeWin(window);
@@ -142,8 +147,9 @@ SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window
return (SDL_GLContext)(bwin->GetGLView());
}
int HAIKU_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) {
// printf("HAIKU_GL_DeleteContext(%llx), thread = %d\n", (uint64)context, find_thread(NULL));
bool HAIKU_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context)
{
// printf("HAIKU_GL_DestroyContext(%llx), thread = %d\n", (uint64)context, find_thread(NULL));
BGLView* glView = (BGLView*)context;
SDL_BWin *bwin = (SDL_BWin*)glView->Window();
if (!bwin) {
@@ -151,21 +157,24 @@ int HAIKU_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) {
} else {
bwin->RemoveGLView();
}
return 0;
return true;
}
int HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) {
bool HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{
// TODO: Implement this, if necessary?
return SDL_Unsupported();
}
int HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) {
bool HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval)
{
return SDL_Unsupported();
}
void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this) {
void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this)
{
// TODO: Implement this, if necessary?
}
@@ -173,7 +182,8 @@ void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this) {
/* FIXME: This function is meant to clear the OpenGL context when the video
mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not
currently in use. */
void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this) {
void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this)
{
SDL_Window *window = _this->windows;
while (window) {
SDL_BWin *bwin = _ToBeWin(window);

View File

@@ -30,16 +30,16 @@ extern "C" {
#include "../SDL_sysvideo.h"
extern int HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); // FIXME
extern bool HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); // FIXME
extern SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); // FIXME
extern void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this); // TODO
extern int HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window,
extern bool HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window,
SDL_GLContext context);
extern int HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); // TODO
extern int HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); // TODO
extern int HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); // TODO
extern bool HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); // TODO
extern bool HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern int HAIKU_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern bool HAIKU_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this);

View File

@@ -96,7 +96,7 @@ static SDL_VideoDevice * HAIKU_CreateDevice(void)
device->GL_SetSwapInterval = HAIKU_GL_SetSwapInterval;
device->GL_GetSwapInterval = HAIKU_GL_GetSwapInterval;
device->GL_SwapWindow = HAIKU_GL_SwapWindow;
device->GL_DeleteContext = HAIKU_GL_DeleteContext;
device->GL_DestroyContext = HAIKU_GL_DestroyContext;
#endif
device->SetClipboardText = HAIKU_SetClipboardText;
@@ -208,12 +208,12 @@ static SDL_Cursor * HAIKU_CreateCursor(SDL_Surface * surface, int hot_x, int hot
return HAIKU_CreateCursorAndData(new BCursor(cursorBitmap, BPoint(hot_x, hot_y)));
}
static int HAIKU_ShowCursor(SDL_Cursor *cursor)
static bool HAIKU_ShowCursor(SDL_Cursor *cursor)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (!mouse) {
return 0;
return true;
}
if (cursor) {
@@ -225,14 +225,14 @@ static int HAIKU_ShowCursor(SDL_Cursor *cursor)
delete hCursor;
}
return 0;
return true;
}
static int HAIKU_SetRelativeMouseMode(bool enabled)
static bool HAIKU_SetRelativeMouseMode(bool enabled)
{
SDL_Window *window = SDL_GetMouseFocus();
if (!window) {
return 0;
return true;
}
SDL_BWin *bewin = _ToBeWin(window);
@@ -245,7 +245,7 @@ static int HAIKU_SetRelativeMouseMode(bool enabled)
_SDL_GLView->SetEventMask(0, 0);
bewin->Unlock();
return 0;
return true;
}
static void HAIKU_MouseInit(SDL_VideoDevice *_this)
@@ -263,11 +263,11 @@ static void HAIKU_MouseInit(SDL_VideoDevice *_this)
SDL_SetDefaultCursor(HAIKU_CreateDefaultCursor());
}
int HAIKU_VideoInit(SDL_VideoDevice *_this)
bool HAIKU_VideoInit(SDL_VideoDevice *_this)
{
// Initialize the Be Application for appserver interaction
if (SDL_InitBeApp() < 0) {
return -1;
if (!SDL_InitBeApp()) {
return false;
}
// Initialize video modes
@@ -289,7 +289,7 @@ int HAIKU_VideoInit(SDL_VideoDevice *_this)
#endif
// We're done!
return 0;
return true;
}
void HAIKU_VideoQuit(SDL_VideoDevice *_this)
@@ -301,12 +301,15 @@ void HAIKU_VideoQuit(SDL_VideoDevice *_this)
}
// just sticking this function in here so it's in a C++ source file.
extern "C" { int HAIKU_OpenURL(const char *url); }
int HAIKU_OpenURL(const char *url)
extern "C"
bool HAIKU_OpenURL(const char *url)
{
BUrl burl(url);
const status_t rc = burl.OpenWithPreferredApplication(false);
return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int)rc);
if (rc != B_NO_ERROR) {
return SDL_SetError("URL open failed (err=%d)", (int)rc);
}
return true;
}
#ifdef __cplusplus

View File

@@ -30,7 +30,7 @@ extern "C" {
#include "../SDL_sysvideo.h"
extern void HAIKU_VideoQuit(SDL_VideoDevice *_this);
extern int HAIKU_VideoInit(SDL_VideoDevice *_this);
extern bool HAIKU_VideoInit(SDL_VideoDevice *_this);
extern void HAIKU_DeleteDevice(SDL_VideoDevice *_this);
#ifdef __cplusplus

View File

@@ -31,15 +31,18 @@
extern "C" {
#endif
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) {
static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window)
{
return (SDL_BWin *)(window->internal);
}
static SDL_INLINE SDL_BLooper *_GetBeLooper() {
static SDL_INLINE SDL_BLooper *_GetBeLooper()
{
return SDL_Looper;
}
static int _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) {
static bool _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
uint32 flags = 0;
window_look look = B_TITLED_WINDOW_LOOK;
@@ -66,112 +69,127 @@ static int _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags);
if (!bwin) {
return -1;
return false;
}
window->internal = (SDL_WindowData *)bwin;
int32 winID = _GetBeLooper()->GetID(window);
bwin->SetID(winID);
return 0;
return true;
}
int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) {
if (_InitWindow(_this, window, create_props) < 0) {
return -1;
bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
if (!_InitWindow(_this, window, create_props)) {
return false;
}
// Start window loop
_ToBeWin(window)->Show();
return 0;
return true;
}
void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_SET_TITLE);
msg.AddString("window-title", window->title);
_ToBeWin(window)->PostMessage(&msg);
}
int HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window) {
bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_MOVE_WINDOW);
msg.AddInt32("window-x", window->floating.x);
msg.AddInt32("window-y", window->floating.y);
_ToBeWin(window)->PostMessage(&msg);
return 0;
return true;
}
void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_RESIZE_WINDOW);
msg.AddInt32("window-w", window->floating.w - 1);
msg.AddInt32("window-h", window->floating.h - 1);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered) {
void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered)
{
BMessage msg(BWIN_SET_BORDERED);
msg.AddBool("window-border", bordered != false);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable) {
void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable)
{
BMessage msg(BWIN_SET_RESIZABLE);
msg.AddBool("window-resizable", resizable != false);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_SHOW_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_HIDE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_SHOW_WINDOW); // Activate this window and move to front
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_MAXIMIZE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_MINIMIZE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
}
void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_RESTORE_WINDOW);
_ToBeWin(window)->PostMessage(&msg);
}
int HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window * window,
SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen) {
SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen)
{
// Haiku tracks all video display information
BMessage msg(BWIN_FULLSCREEN);
msg.AddBool("fullscreen", !!fullscreen);
_ToBeWin(window)->PostMessage(&msg);
return 0;
return SDL_FULLSCREEN_SUCCEEDED;
}
void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window)
{
BMessage msg(BWIN_MINIMUM_SIZE_WINDOW);
msg.AddInt32("window-w", window->w -1);
msg.AddInt32("window-h", window->h -1);
_ToBeWin(window)->PostMessage(&msg);
}
int HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed) {
bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed)
{
// TODO: Implement this!
return SDL_Unsupported();
}
int HAIKU_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) {
bool HAIKU_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window)
{
if (modal_window->parent && modal_window->parent != parent_window) {
// Remove from the subset of a previous parent.
_ToBeWin(modal_window)->RemoveFromSubset(_ToBeWin(modal_window->parent));
@@ -187,10 +205,11 @@ int HAIKU_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SD
_ToBeWin(modal_window)->SetFeel(B_NORMAL_WINDOW_FEEL);
}
return 0;
return true;
}
void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window) {
void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window)
{
_ToBeWin(window)->LockLooper(); // This MUST be locked
_GetBeLooper()->ClearID(_ToBeWin(window));
_ToBeWin(window)->Quit();

View File

@@ -24,9 +24,9 @@
#include "../SDL_sysvideo.h"
extern int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern int HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
extern void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window);
extern void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
@@ -37,8 +37,8 @@ extern void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered);
extern void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable);
extern int HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
extern int HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
extern SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen);
extern bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed);
extern void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
#endif

View File

@@ -109,9 +109,9 @@ void SDL_KMSDRM_UnloadSymbols(void)
}
// returns non-zero if all needed symbols were loaded.
int SDL_KMSDRM_LoadSymbols(void)
bool SDL_KMSDRM_LoadSymbols(void)
{
int rc = 1; // always succeed if not using Dynamic KMSDRM stuff.
bool result = true; // always succeed if not using Dynamic KMSDRM stuff.
// deal with multiple modules needing these symbols...
if (kmsdrm_load_refcount++ == 0) {
@@ -138,7 +138,7 @@ int SDL_KMSDRM_LoadSymbols(void)
} else {
// in case something got loaded...
SDL_KMSDRM_UnloadSymbols();
rc = 0;
result = false;
}
#else // no dynamic KMSDRM
@@ -151,7 +151,7 @@ int SDL_KMSDRM_LoadSymbols(void)
#endif
}
return rc;
return result;
}
#endif // SDL_VIDEO_DRIVER_KMSDRM

View File

@@ -32,8 +32,8 @@
extern "C" {
#endif
int SDL_KMSDRM_LoadSymbols(void);
void SDL_KMSDRM_UnloadSymbols(void);
extern bool SDL_KMSDRM_LoadSymbols(void);
extern void SDL_KMSDRM_UnloadSymbols(void);
// Declare all the function pointers and wrappers...
#define SDL_KMSDRM_SYM(rc, fn, params) \

View File

@@ -34,8 +34,8 @@
static SDL_Cursor *KMSDRM_CreateDefaultCursor(void);
static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y);
static int KMSDRM_ShowCursor(SDL_Cursor *cursor);
static int KMSDRM_MoveCursor(SDL_Cursor *cursor);
static bool KMSDRM_ShowCursor(SDL_Cursor *cursor);
static bool KMSDRM_MoveCursor(SDL_Cursor *cursor);
static void KMSDRM_FreeCursor(SDL_Cursor *cursor);
/**************************************************************************************/
@@ -76,7 +76,7 @@ void KMSDRM_DestroyCursorBO(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
/* Given a display's internal, create the cursor BO for it.
To be called from KMSDRM_CreateWindow(), as that's where we
build a window and assign a display to it. */
int KMSDRM_CreateCursorBO(SDL_VideoDisplay *display)
bool KMSDRM_CreateCursorBO(SDL_VideoDisplay *display)
{
SDL_VideoDevice *dev = SDL_GetVideoDevice();
@@ -109,29 +109,27 @@ int KMSDRM_CreateCursorBO(SDL_VideoDisplay *display)
}
dispdata->cursor_bo_drm_fd = viddata->drm_fd;
return 0;
return true;
}
// Remove a cursor buffer from a display's DRM cursor BO.
static int KMSDRM_RemoveCursorFromBO(SDL_VideoDisplay *display)
static bool KMSDRM_RemoveCursorFromBO(SDL_VideoDisplay *display)
{
int ret = 0;
bool result = true;
SDL_DisplayData *dispdata = display->internal;
SDL_VideoDevice *video_device = SDL_GetVideoDevice();
SDL_VideoData *viddata = video_device->internal;
ret = KMSDRM_drmModeSetCursor(viddata->drm_fd,
dispdata->crtc->crtc_id, 0, 0, 0);
if (ret) {
ret = SDL_SetError("Could not hide current cursor with drmModeSetCursor().");
const int rc = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id, 0, 0, 0);
if (rc < 0) {
result = SDL_SetError("drmModeSetCursor() failed: %s", strerror(-rc));
}
return ret;
return result;
}
// Dump a cursor buffer to a display's DRM cursor BO.
static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor)
static bool KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor)
{
SDL_DisplayData *dispdata = display->internal;
SDL_CursorData *curdata = cursor->internal;
@@ -144,8 +142,8 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor)
uint8_t *ready_buffer = NULL;
uint8_t *src_row;
int i;
int ret;
int i, rc;
bool result = true;
if (!curdata || !dispdata->cursor_bo) {
return SDL_SetError("Cursor or display not initialized properly.");
@@ -159,7 +157,7 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor)
ready_buffer = (uint8_t *)SDL_calloc(1, bufsize);
if (!ready_buffer) {
ret = -1;
result = false;
goto cleanup;
}
@@ -171,27 +169,21 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor)
// Dump the cursor buffer to our GBM BO.
if (KMSDRM_gbm_bo_write(dispdata->cursor_bo, ready_buffer, bufsize)) {
ret = SDL_SetError("Could not write to GBM cursor BO");
result = SDL_SetError("Could not write to GBM cursor BO");
goto cleanup;
}
// Put the GBM BO buffer on screen using the DRM interface.
bo_handle = KMSDRM_gbm_bo_get_handle(dispdata->cursor_bo).u32;
if (curdata->hot_x == 0 && curdata->hot_y == 0) {
ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id,
rc = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id,
bo_handle, dispdata->cursor_w, dispdata->cursor_h);
} else {
ret = KMSDRM_drmModeSetCursor2(viddata->drm_fd, dispdata->crtc->crtc_id,
rc = KMSDRM_drmModeSetCursor2(viddata->drm_fd, dispdata->crtc->crtc_id,
bo_handle, dispdata->cursor_w, dispdata->cursor_h, curdata->hot_x, curdata->hot_y);
}
if (ret) {
ret = SDL_SetError("Failed to set DRM cursor.");
goto cleanup;
}
if (ret) {
ret = SDL_SetError("Failed to reset cursor position.");
if (rc < 0) {
result = SDL_SetError("Failed to set DRM cursor: %s", strerror(-rc));
goto cleanup;
}
@@ -200,7 +192,7 @@ cleanup:
if (ready_buffer) {
SDL_free(ready_buffer);
}
return ret;
return result;
}
// This is only for freeing the SDL_cursor.
@@ -230,10 +222,10 @@ static void KMSDRM_FreeCursor(SDL_Cursor *cursor)
static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
{
SDL_CursorData *curdata;
SDL_Cursor *cursor, *ret;
SDL_Cursor *cursor, *result;
curdata = NULL;
ret = NULL;
result = NULL;
cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor));
if (!cursor) {
@@ -271,10 +263,10 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_
cursor->internal = curdata;
ret = cursor;
result = cursor;
cleanup:
if (!ret) {
if (!result) {
if (curdata) {
if (curdata->buffer) {
SDL_free(curdata->buffer);
@@ -286,26 +278,20 @@ cleanup:
}
}
return ret;
return result;
}
// Show the specified cursor, or hide if cursor is NULL or has no focus.
static int KMSDRM_ShowCursor(SDL_Cursor *cursor)
static bool KMSDRM_ShowCursor(SDL_Cursor *cursor)
{
SDL_VideoDisplay *display;
SDL_Window *window;
SDL_Mouse *mouse;
SDL_Mouse *mouse = SDL_GetMouse();
int i;
int ret = 0;
bool result = true;
// Get the mouse focused window, if any.
mouse = SDL_GetMouse();
if (!mouse) {
return SDL_SetError("No mouse.");
}
window = mouse->focus;
if (!window || !cursor) {
@@ -320,7 +306,7 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor)
// Iterate on the displays, hiding the cursor.
for (i = 0; i < displays[i]; i++) {
display = SDL_GetVideoDisplay(displays[i]);
ret = KMSDRM_RemoveCursorFromBO(display);
result = KMSDRM_RemoveCursorFromBO(display);
}
SDL_free(displays);
}
@@ -330,23 +316,22 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor)
if (cursor) {
/* Dump the cursor to the display DRM cursor BO so it becomes visible
on that display. */
ret = KMSDRM_DumpCursorToBO(display, cursor);
result = KMSDRM_DumpCursorToBO(display, cursor);
} else {
// Hide the cursor on that display.
ret = KMSDRM_RemoveCursorFromBO(display);
result = KMSDRM_RemoveCursorFromBO(display);
}
}
}
return ret;
return result;
}
static int KMSDRM_WarpMouseGlobal(float x, float y)
static bool KMSDRM_WarpMouseGlobal(float x, float y)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse && mouse->cur_cursor && mouse->focus) {
SDL_Window *window = mouse->focus;
SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window);
@@ -355,26 +340,20 @@ static int KMSDRM_WarpMouseGlobal(float x, float y)
// And now update the cursor graphic position on screen.
if (dispdata->cursor_bo) {
int ret = 0;
ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)x, (int)y);
if (ret) {
SDL_SetError("drmModeMoveCursor() failed.");
const int rc = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)x, (int)y);
if (rc < 0) {
return SDL_SetError("drmModeMoveCursor() failed: %s", strerror(-rc));
}
return ret;
return true;
} else {
return SDL_SetError("Cursor not initialized properly.");
}
} else {
return SDL_SetError("No mouse or current cursor.");
}
}
static int KMSDRM_WarpMouse(SDL_Window *window, float x, float y)
static bool KMSDRM_WarpMouse(SDL_Window *window, float x, float y)
{
// Only one global/fullscreen window is supported
return KMSDRM_WarpMouseGlobal(x, y);
@@ -406,15 +385,13 @@ void KMSDRM_QuitMouse(SDL_VideoDevice *_this)
}
// This is called when a mouse motion event occurs
static int KMSDRM_MoveCursor(SDL_Cursor *cursor)
static bool KMSDRM_MoveCursor(SDL_Cursor *cursor)
{
SDL_Mouse *mouse = SDL_GetMouse();
int ret = 0;
/* We must NOT call SDL_SendMouseMotion() here or we will enter recursivity!
That's why we move the cursor graphic ONLY. */
if (mouse && mouse->cur_cursor && mouse->focus) {
SDL_Window *window = mouse->focus;
SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window);
@@ -422,13 +399,12 @@ static int KMSDRM_MoveCursor(SDL_Cursor *cursor)
return SDL_SetError("Cursor not initialized properly.");
}
ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)mouse->x, (int)mouse->y);
if (ret) {
return SDL_SetError("drmModeMoveCursor() failed.");
const int rc = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)mouse->x, (int)mouse->y);
if (rc < 0) {
return SDL_SetError("drmModeMoveCursor() failed: %s", strerror(-rc));
}
}
return 0;
return true;
}
#endif // SDL_VIDEO_DRIVER_KMSDRM

View File

@@ -46,7 +46,7 @@ struct SDL_CursorData
extern void KMSDRM_InitMouse(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern void KMSDRM_QuitMouse(SDL_VideoDevice *_this);
extern int KMSDRM_CreateCursorBO(SDL_VideoDisplay *display);
extern bool KMSDRM_CreateCursorBO(SDL_VideoDisplay *display);
extern void KMSDRM_DestroyCursorBO(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern void KMSDRM_InitCursor(void);

View File

@@ -46,7 +46,7 @@ void KMSDRM_GLES_DefaultProfileConfig(SDL_VideoDevice *_this, int *mask, int *ma
#endif
}
int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
/* Just pretend you do this here, but don't do it until KMSDRM_CreateWindow(),
where we do the same library load we would normally do here.
@@ -57,7 +57,7 @@ int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path)
NativeDisplayType display = (NativeDisplayType)_this->internal->gbm_dev;
return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA);
#endif
return 0;
return true;
}
void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this)
@@ -68,9 +68,8 @@ void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this)
SDL_EGL_CreateContext_impl(KMSDRM)
int KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval)
bool KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval)
{
if (!_this->egl_data) {
return SDL_SetError("EGL not initialized");
}
@@ -81,10 +80,10 @@ SDL_EGL_CreateContext_impl(KMSDRM)
return SDL_SetError("Only swap intervals of 0 or 1 are supported");
}
return 0;
return true;
}
int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
bool KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_WindowData *windata = window->internal;
SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window);
@@ -100,7 +99,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
if (windata->egl_surface == EGL_NO_SURFACE) {
// Wait a bit, throttling to ~100 FPS
SDL_Delay(10);
return 0;
return true;
}
// Recreate the GBM / EGL surfaces if the display mode has changed
@@ -111,8 +110,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
/* Wait for confirmation that the next front buffer has been flipped, at which
point the previous front buffer can be released */
if (!KMSDRM_WaitPageflip(_this, windata)) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Wait for previous pageflip failed");
return 0;
return SDL_SetError("Wait for previous pageflip failed");
}
// Release the previous front buffer
@@ -127,8 +125,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
This won't happen until pagelip completes. */
if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display,
windata->egl_surface))) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed");
return 0;
return SDL_SetError("eglSwapBuffers failed");
}
/* From the GBM surface, get the next BO to become the next front buffer,
@@ -136,15 +133,13 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
from drawing into it!) */
windata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(windata->gs);
if (!windata->next_bo) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock front buffer on GBM surface");
return 0;
return SDL_SetError("Could not lock front buffer on GBM surface");
}
// Get an actual usable fb for the next front buffer.
fb_info = KMSDRM_FBFromBO(_this, windata->next_bo);
if (!fb_info) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not get a framebuffer");
return 0;
return SDL_SetError("Could not get a framebuffer");
}
if (!windata->bo) {
@@ -156,8 +151,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
&dispdata->connector->connector_id, 1, &dispdata->mode);
if (ret) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set videomode on CRTC.");
return 0;
return SDL_SetError("Could not set videomode on CRTC.");
}
} else {
/* On subsequent swaps, queue the new front buffer to be flipped during
@@ -196,13 +190,12 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
to enable this. */
if (windata->double_buffer) {
if (!KMSDRM_WaitPageflip(_this, windata)) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Immediate wait for previous pageflip failed");
return 0;
return SDL_SetError("Immediate wait for previous pageflip failed");
}
}
}
return 1;
return true;
}
SDL_EGL_MakeCurrent_impl(KMSDRM)

View File

@@ -31,15 +31,15 @@
// OpenGLES functions
#define KMSDRM_GLES_GetAttribute SDL_EGL_GetAttribute
#define KMSDRM_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal
#define KMSDRM_GLES_DeleteContext SDL_EGL_DeleteContext
#define KMSDRM_GLES_DestroyContext SDL_EGL_DestroyContext
#define KMSDRM_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
extern void KMSDRM_GLES_DefaultProfileConfig(SDL_VideoDevice *_this, int *mask, int *major, int *minor);
extern int KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern bool KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern SDL_GLContext KMSDRM_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern int KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern bool KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
#endif // SDL_VIDEO_DRIVER_KMSDRM

View File

@@ -188,7 +188,7 @@ static void CalculateRefreshRate(drmModeModeInfo *mode, int *numerator, int *den
}
}
static int KMSDRM_Available(void)
static bool KMSDRM_Available(void)
{
#ifdef SDL_PLATFORM_OPENBSD
struct utsname nameofsystem;
@@ -220,10 +220,10 @@ static int KMSDRM_Available(void)
ret = get_driindex();
if (ret >= 0) {
return 1;
return true;
}
return ret;
return false;
}
static void KMSDRM_DeleteDevice(SDL_VideoDevice *device)
@@ -298,7 +298,7 @@ static SDL_VideoDevice *KMSDRM_CreateDevice(void)
device->GL_SetSwapInterval = KMSDRM_GLES_SetSwapInterval;
device->GL_GetSwapInterval = KMSDRM_GLES_GetSwapInterval;
device->GL_SwapWindow = KMSDRM_GLES_SwapWindow;
device->GL_DeleteContext = KMSDRM_GLES_DeleteContext;
device->GL_DestroyContext = KMSDRM_GLES_DestroyContext;
device->GL_DefaultProfileConfig = KMSDRM_GLES_DefaultProfileConfig;
#ifdef SDL_VIDEO_VULKAN
@@ -464,14 +464,14 @@ bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata)
} else {
// There was another error. Don't pull again or we could get into a busy loop.
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll error");
return false; // Return number 1.
return false;
}
}
if (pfd.revents & (POLLHUP | POLLERR)) {
// An event arrived on the FD in time, but it's an error.
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll hup or error");
return false; // Return number 2.
return false;
}
if (pfd.revents & POLLIN) {
@@ -511,7 +511,7 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
SDL_DisplayMode closest;
drmModeModeInfo *drm_mode;
if (SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, false, &closest) == 0) {
if (SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, false, &closest)) {
const SDL_DisplayModeData *modedata = closest.internal;
drm_mode = &connector->modes[modedata->mode_index];
return drm_mode;
@@ -994,15 +994,14 @@ cleanup:
closed when we get to the end of this function.
This is to be called early, in VideoInit(), because it gets us
the videomode information, which SDL needs immediately after VideoInit(). */
static int KMSDRM_InitDisplays(SDL_VideoDevice *_this)
static bool KMSDRM_InitDisplays(SDL_VideoDevice *_this)
{
SDL_VideoData *viddata = _this->internal;
drmModeRes *resources = NULL;
uint64_t async_pageflip = 0;
int ret = 0;
int i;
bool result = true;
// Open /dev/dri/cardNN (/dev/drmN if on OpenBSD version less than 6.9)
(void)SDL_snprintf(viddata->devpath, sizeof(viddata->devpath), "%s%d",
@@ -1012,7 +1011,7 @@ static int KMSDRM_InitDisplays(SDL_VideoDevice *_this)
viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC);
if (viddata->drm_fd < 0) {
ret = SDL_SetError("Could not open %s", viddata->devpath);
result = SDL_SetError("Could not open %s", viddata->devpath);
goto cleanup;
}
@@ -1021,7 +1020,7 @@ static int KMSDRM_InitDisplays(SDL_VideoDevice *_this)
// Get all of the available connectors / devices / crtcs
resources = KMSDRM_drmModeGetResources(viddata->drm_fd);
if (!resources) {
ret = SDL_SetError("drmModeGetResources(%d) failed", viddata->drm_fd);
result = SDL_SetError("drmModeGetResources(%d) failed", viddata->drm_fd);
goto cleanup;
}
@@ -1049,13 +1048,12 @@ static int KMSDRM_InitDisplays(SDL_VideoDevice *_this)
// Have we added any SDL displays?
if (SDL_GetPrimaryDisplay() == 0) {
ret = SDL_SetError("No connected displays found.");
result = SDL_SetError("No connected displays found.");
goto cleanup;
}
// Determine if video hardware supports async pageflips.
ret = KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_ASYNC_PAGE_FLIP, &async_pageflip);
if (ret) {
if (KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_ASYNC_PAGE_FLIP, &async_pageflip) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not determine async page flip capability.");
}
viddata->async_pageflip_support = async_pageflip ? true : false;
@@ -1073,13 +1071,13 @@ cleanup:
if (resources) {
KMSDRM_drmModeFreeResources(resources);
}
if (ret) {
if (!result) {
if (viddata->drm_fd >= 0) {
close(viddata->drm_fd);
viddata->drm_fd = -1;
}
}
return ret;
return result;
}
/* Init the Vulkan-INCOMPATIBLE stuff:
@@ -1090,10 +1088,10 @@ cleanup:
These things are incompatible with Vulkan, which accesses the same resources
internally so they must be free when trying to build a Vulkan surface.
*/
static int KMSDRM_GBMInit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata)
static bool KMSDRM_GBMInit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata)
{
SDL_VideoData *viddata = _this->internal;
int ret = 0;
bool result = true;
// Reopen the FD!
viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC);
@@ -1104,12 +1102,12 @@ static int KMSDRM_GBMInit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata)
// Create the GBM device.
viddata->gbm_dev = KMSDRM_gbm_create_device(viddata->drm_fd);
if (!viddata->gbm_dev) {
ret = SDL_SetError("Couldn't create gbm device.");
result = SDL_SetError("Couldn't create gbm device.");
}
viddata->gbm_init = true;
return ret;
return result;
}
// Deinit the Vulkan-incompatible KMSDRM stuff.
@@ -1235,7 +1233,7 @@ static void KMSDRM_DirtySurfaces(SDL_Window *window)
/* This determines the size of the fb, which comes from the GBM surface
that we create here. */
int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
bool KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
{
SDL_VideoData *viddata = _this->internal;
SDL_WindowData *windata = window->internal;
@@ -1247,7 +1245,7 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
EGLContext egl_context;
int ret = 0;
bool result = true;
// If the current window already has surfaces, destroy them before creating other.
if (windata->gs) {
@@ -1283,14 +1281,14 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
windata->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)windata->gs);
if (windata->egl_surface == EGL_NO_SURFACE) {
ret = SDL_SetError("Could not create EGL window surface");
result = SDL_SetError("Could not create EGL window surface");
goto cleanup;
}
/* Current context passing to EGL is now done here. If something fails,
go back to delayed SDL_EGL_MakeCurrent() call in SwapWindow. */
egl_context = (EGLContext)SDL_GL_GetCurrentContext();
ret = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context);
result = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context);
SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED,
dispdata->mode.hdisplay, dispdata->mode.vdisplay);
@@ -1299,7 +1297,7 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window)
cleanup:
if (ret) {
if (!result) {
// Error (complete) cleanup.
if (windata->gs) {
KMSDRM_gbm_surface_destroy(windata->gs);
@@ -1307,7 +1305,7 @@ cleanup:
}
}
return ret;
return result;
}
#ifdef SDL_INPUT_LINUXEV
@@ -1342,9 +1340,9 @@ static void KMSDRM_AcquireVT(void *userdata)
}
#endif // defined SDL_INPUT_LINUXEV
int KMSDRM_VideoInit(SDL_VideoDevice *_this)
bool KMSDRM_VideoInit(SDL_VideoDevice *_this)
{
int ret = 0;
bool result = true;
SDL_VideoData *viddata = _this->internal;
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()");
@@ -1356,8 +1354,8 @@ int KMSDRM_VideoInit(SDL_VideoDevice *_this)
this info isn't a problem for VK compatibility.
For VK-incompatible initializations we have KMSDRM_GBMInit(), which is
called on window creation, and only when we know it's not a VK window. */
if (KMSDRM_InitDisplays(_this)) {
ret = SDL_SetError("error getting KMSDRM displays information");
if (!KMSDRM_InitDisplays(_this)) {
result = SDL_SetError("error getting KMSDRM displays information");
}
#ifdef SDL_INPUT_LINUXEV
@@ -1369,7 +1367,7 @@ int KMSDRM_VideoInit(SDL_VideoDevice *_this)
viddata->video_init = true;
return ret;
return result;
}
/* The internal pointers, like dispdata, viddata, windata, etc...
@@ -1396,7 +1394,7 @@ void KMSDRM_VideoQuit(SDL_VideoDevice *_this)
}
// Read modes from the connector modes, and store them in display->display_modes.
int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
bool KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
{
SDL_DisplayData *dispdata = display->internal;
drmModeConnector *conn = dispdata->connector;
@@ -1421,10 +1419,10 @@ int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display)
SDL_free(modedata);
}
}
return 0;
return true;
}
int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
bool KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
{
/* Set the dispdata->mode to the new mode and leave actual modesetting
pending to be done on SwapWindow() via drmModeSetCrtc() */
@@ -1437,7 +1435,7 @@ int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL
// Don't do anything if we are in Vulkan mode.
if (viddata->vulkan_mode) {
return 0;
return true;
}
if (!modedata) {
@@ -1452,7 +1450,7 @@ int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL
KMSDRM_DirtySurfaces(viddata->windows[i]);
}
return 0;
return true;
}
void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
@@ -1533,7 +1531,7 @@ void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
// reflect it: if it's fullscreen, KMSDRM_SetWindwoFullscreen() will
// be called by SDL later, and we can manage it there.
/**********************************************************************/
int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props)
{
SDL_WindowData *windata = NULL;
SDL_VideoData *viddata = _this->internal;
@@ -1543,12 +1541,12 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
bool vulkan_mode = viddata->vulkan_mode; // Do we have any Vulkan windows?
NativeDisplayType egl_display;
drmModeModeInfo *mode;
int ret = 0;
bool result = true;
// Allocate window internal data
windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData));
if (!windata) {
return -1;
return false;
}
// Setup driver data for this window
@@ -1590,8 +1588,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
/* Reopen FD, create gbm dev, setup display plane, etc,.
but only when we come here for the first time,
and only if it's not a VK window. */
ret = KMSDRM_GBMInit(_this, dispdata);
if (ret != 0) {
if (!KMSDRM_GBMInit(_this, dispdata)) {
return SDL_SetError("Can't init GBM on window creation.");
}
}
@@ -1603,12 +1600,12 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
before we call KMSDRM_GBMInit(), causing all GLES programs to fail. */
if (!_this->egl_data) {
egl_display = (NativeDisplayType)_this->internal->gbm_dev;
if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA) < 0) {
if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) {
// Try again with OpenGL ES 2.0
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
_this->gl_config.major_version = 2;
_this->gl_config.minor_version = 0;
if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA) < 0) {
if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) {
return SDL_SetError("Can't load EGL/GL library on window creation.");
}
}
@@ -1639,8 +1636,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
/* Create the window surfaces with the size we have just chosen.
Needs the window diverdata in place. */
ret = KMSDRM_CreateSurfaces(_this, window);
if (ret != 0) {
if (!KMSDRM_CreateSurfaces(_this, window)) {
return SDL_SetError("Can't window GBM/EGL surfaces on window creation.");
}
} // NON-Vulkan block ends.
@@ -1653,7 +1649,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
SDL_Window **new_windows = (SDL_Window **)SDL_realloc(viddata->windows,
new_max_windows * sizeof(SDL_Window *));
if (!new_windows) {
return -1;
return false;
}
viddata->windows = new_windows;
viddata->max_windows = new_max_windows;
@@ -1678,13 +1674,13 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
/* Allocated windata will be freed in KMSDRM_DestroyWindow,
and KMSDRM_DestroyWindow() will be called by SDL_CreateWindow()
if we return error on any of the previous returns of the function. */
return ret;
return result;
}
void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window)
{
}
int KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
bool KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
{
return SDL_Unsupported();
}
@@ -1695,13 +1691,13 @@ void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window)
KMSDRM_DirtySurfaces(window);
}
}
int KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
SDL_FullscreenResult KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen)
{
SDL_VideoData *viddata = _this->internal;
if (!viddata->vulkan_mode) {
KMSDRM_DirtySurfaces(window);
}
return 0;
return SDL_FULLSCREEN_SUCCEEDED;
}
void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
{

View File

@@ -146,42 +146,42 @@ typedef struct KMSDRM_FBInfo
} KMSDRM_FBInfo;
// Helper functions
int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window);
KMSDRM_FBInfo *KMSDRM_FBFromBO(SDL_VideoDevice *_this, struct gbm_bo *bo);
KMSDRM_FBInfo *KMSDRM_FBFromBO2(SDL_VideoDevice *_this, struct gbm_bo *bo, int w, int h);
bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata);
extern bool KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window);
extern KMSDRM_FBInfo *KMSDRM_FBFromBO(SDL_VideoDevice *_this, struct gbm_bo *bo);
extern KMSDRM_FBInfo *KMSDRM_FBFromBO2(SDL_VideoDevice *_this, struct gbm_bo *bo, int w, int h);
extern bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata);
/****************************************************************************/
// SDL_VideoDevice functions declaration
/****************************************************************************/
// Display and window functions
int KMSDRM_VideoInit(SDL_VideoDevice *_this);
void KMSDRM_VideoQuit(SDL_VideoDevice *_this);
int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
int KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
int KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen);
void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool KMSDRM_VideoInit(SDL_VideoDevice *_this);
extern void KMSDRM_VideoQuit(SDL_VideoDevice *_this);
extern bool KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display);
extern bool KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
extern bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props);
extern void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window);
extern bool KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window);
extern SDL_FullscreenResult KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen);
extern void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_HideWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window);
// OpenGL/OpenGL ES functions
int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
SDL_FunctionPointer KMSDRM_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this);
SDL_GLContext KMSDRM_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
int KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
int KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
int KMSDRM_GLES_GetSwapInterval(SDL_VideoDevice *_this);
int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
int KMSDRM_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context);
extern bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern SDL_FunctionPointer KMSDRM_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
extern void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this);
extern SDL_GLContext KMSDRM_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
extern bool KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context);
extern bool KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval);
extern bool KMSDRM_GLES_GetSwapInterval(SDL_VideoDevice *_this);
extern bool KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
extern bool KMSDRM_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
#endif // SDL_kmsdrmvideo_h

View File

@@ -42,7 +42,7 @@
#define DEFAULT_VULKAN "libvulkan.so.1"
#endif
int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
bool KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
{
VkExtensionProperties *extensions = NULL;
Uint32 i, extensionCount = 0;
@@ -65,7 +65,7 @@ int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
_this->vulkan_config.loader_handle = SDL_LoadObject(path);
if (!_this->vulkan_config.loader_handle) {
return -1;
return false;
}
SDL_strlcpy(_this->vulkan_config.loader_path, path,
@@ -114,12 +114,12 @@ int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path)
goto fail;
}
return 0;
return true;
fail:
SDL_UnloadObject(_this->vulkan_config.loader_handle);
_this->vulkan_config.loader_handle = NULL;
return -1;
return false;
}
void KMSDRM_Vulkan_UnloadLibrary(SDL_VideoDevice *_this)
@@ -146,7 +146,9 @@ char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
static const char *const extensionsForKMSDRM[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME
};
if(count) { *count = SDL_arraysize(extensionsForKMSDRM); }
if (count) {
*count = SDL_arraysize(extensionsForKMSDRM);
}
return extensionsForKMSDRM;
}
@@ -158,7 +160,7 @@ char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
// KMSDRM_Vulkan_GetInstanceExtensions(), like we do with
// VK_KHR_DISPLAY_EXTENSION_NAME, which is what we need for x-less VK.
/***********************************************************************/
int KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,

View File

@@ -34,16 +34,15 @@
#if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_KMSDRM)
int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
void KMSDRM_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this,
Uint32 *count);
int KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
extern bool KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path);
extern void KMSDRM_Vulkan_UnloadLibrary(SDL_VideoDevice *_this);
extern char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count);
extern bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this,
SDL_Window *window,
VkInstance instance,
const struct VkAllocationCallbacks *allocator,
VkSurfaceKHR *surface);
void KMSDRM_Vulkan_DestroySurface(SDL_VideoDevice *_this,
extern void KMSDRM_Vulkan_DestroySurface(SDL_VideoDevice *_this,
VkInstance instance,
VkSurfaceKHR surface,
const struct VkAllocationCallbacks *allocator);

Some files were not shown because too many files have changed in this diff Show More