Merged Ryan's SDL-gui-backend branch.

Adds three APIs, and implements them on X11, Cocoa, and Windows:

- SDL_CaptureMouse()
- SDL_GetGlobalMouseState()
- SDL_SetWindowHitTest()
This commit is contained in:
Ryan C. Gordon 2014-06-25 17:06:12 -04:00
commit b29740b88f
282 changed files with 30394 additions and 26689 deletions

View file

@ -421,6 +421,8 @@ SDL_GetPlatform()
return "MacOS Classic";
#elif __MACOSX__
return "Mac OS X";
#elif __NACL__
return "NaCl";
#elif __NETBSD__
return "NetBSD";
#elif __OPENBSD__

View file

@ -50,7 +50,7 @@ SDL_LookupString(const char *key)
/* Public functions */
int
SDL_SetError(const char *fmt, ...)
SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
SDL_error *error;

View file

@ -26,6 +26,7 @@
/* Simple log messages in SDL */
#include "SDL_error.h"
#include "SDL_log.h"
#if HAVE_STDIO_H
@ -41,9 +42,6 @@
#define DEFAULT_APPLICATION_PRIORITY SDL_LOG_PRIORITY_INFO
#define DEFAULT_TEST_PRIORITY SDL_LOG_PRIORITY_VERBOSE
/* Forward definition of error function */
extern int SDL_SetError(const char *fmt, ...);
typedef struct SDL_LogLevel
{
int category;
@ -172,7 +170,7 @@ SDL_LogResetPriorities(void)
}
void
SDL_Log(const char *fmt, ...)
SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -182,7 +180,7 @@ SDL_Log(const char *fmt, ...)
}
void
SDL_LogVerbose(int category, const char *fmt, ...)
SDL_LogVerbose(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -192,7 +190,7 @@ SDL_LogVerbose(int category, const char *fmt, ...)
}
void
SDL_LogDebug(int category, const char *fmt, ...)
SDL_LogDebug(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -202,7 +200,7 @@ SDL_LogDebug(int category, const char *fmt, ...)
}
void
SDL_LogInfo(int category, const char *fmt, ...)
SDL_LogInfo(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -212,7 +210,7 @@ SDL_LogInfo(int category, const char *fmt, ...)
}
void
SDL_LogWarn(int category, const char *fmt, ...)
SDL_LogWarn(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -222,7 +220,7 @@ SDL_LogWarn(int category, const char *fmt, ...)
}
void
SDL_LogError(int category, const char *fmt, ...)
SDL_LogError(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -232,7 +230,7 @@ SDL_LogError(int category, const char *fmt, ...)
}
void
SDL_LogCritical(int category, const char *fmt, ...)
SDL_LogCritical(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -242,7 +240,7 @@ SDL_LogCritical(int category, const char *fmt, ...)
}
void
SDL_LogMessage(int category, SDL_LogPriority priority, const char *fmt, ...)
SDL_LogMessage(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
@ -415,6 +413,9 @@ SDL_LogOutput(void *userdata, int category, SDL_LogPriority priority,
#endif
#if HAVE_STDIO_H
fprintf(stderr, "%s: %s\n", SDL_priority_prefixes[priority], message);
#if __NACL__
fflush(stderr);
#endif
#endif
}

View file

@ -51,6 +51,9 @@ extern AudioBootStrap QSAAUDIO_bootstrap;
extern AudioBootStrap SUNAUDIO_bootstrap;
extern AudioBootStrap ARTS_bootstrap;
extern AudioBootStrap ESD_bootstrap;
#if SDL_AUDIO_DRIVER_NACL
extern AudioBootStrap NACLAUD_bootstrap;
#endif
extern AudioBootStrap NAS_bootstrap;
extern AudioBootStrap XAUDIO2_bootstrap;
extern AudioBootStrap DSOUND_bootstrap;
@ -69,6 +72,7 @@ extern AudioBootStrap ANDROIDAUD_bootstrap;
extern AudioBootStrap PSPAUD_bootstrap;
extern AudioBootStrap SNDIO_bootstrap;
/* Available audio drivers */
static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_PULSEAUDIO
@ -98,6 +102,9 @@ static const AudioBootStrap *const bootstrap[] = {
#if SDL_AUDIO_DRIVER_ESD
&ESD_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_NACL
&NACLAUD_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_NAS
&NAS_bootstrap,
#endif
@ -1087,7 +1094,7 @@ SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)
id = open_audio_device(NULL, 0, desired, obtained,
SDL_AUDIO_ALLOW_ANY_CHANGE, 1);
} else {
id = open_audio_device(NULL, 0, desired, desired, 0, 1);
id = open_audio_device(NULL, 0, desired, NULL, 0, 1);
}
SDL_assert((id == 0) || (id == 1));

View file

@ -2300,7 +2300,7 @@ SDL_Upsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 16;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
register int eps = 0;
Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 1;
const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -2332,7 +2332,7 @@ SDL_Downsample_U8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 16;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
register int eps = 0;
Uint8 *dst = (Uint8 *) cvt->buf;
const Uint8 *src = (Uint8 *) cvt->buf;
@ -2364,7 +2364,7 @@ SDL_Upsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 2;
const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -2401,7 +2401,7 @@ SDL_Downsample_U8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Uint8 *dst = (Uint8 *) cvt->buf;
const Uint8 *src = (Uint8 *) cvt->buf;
@ -2438,7 +2438,7 @@ SDL_Upsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 4;
const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -2485,7 +2485,7 @@ SDL_Downsample_U8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Uint8 *dst = (Uint8 *) cvt->buf;
const Uint8 *src = (Uint8 *) cvt->buf;
@ -2532,7 +2532,7 @@ SDL_Upsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 96;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
register int eps = 0;
Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 6;
const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -2589,7 +2589,7 @@ SDL_Downsample_U8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 96;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
register int eps = 0;
Uint8 *dst = (Uint8 *) cvt->buf;
const Uint8 *src = (Uint8 *) cvt->buf;
@ -2646,7 +2646,7 @@ SDL_Upsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Uint8 *dst = ((Uint8 *) (cvt->buf + dstsize)) - 8;
const Uint8 *src = ((Uint8 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -2713,7 +2713,7 @@ SDL_Downsample_U8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Uint8 *dst = (Uint8 *) cvt->buf;
const Uint8 *src = (Uint8 *) cvt->buf;
@ -2780,7 +2780,7 @@ SDL_Upsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 16;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
register int eps = 0;
Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 1;
const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -2812,7 +2812,7 @@ SDL_Downsample_S8_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 16;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/1)) * cvt->rate_incr) * 1;
register int eps = 0;
Sint8 *dst = (Sint8 *) cvt->buf;
const Sint8 *src = (Sint8 *) cvt->buf;
@ -2844,7 +2844,7 @@ SDL_Upsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 2;
const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -2881,7 +2881,7 @@ SDL_Downsample_S8_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Sint8 *dst = (Sint8 *) cvt->buf;
const Sint8 *src = (Sint8 *) cvt->buf;
@ -2918,7 +2918,7 @@ SDL_Upsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 4;
const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -2965,7 +2965,7 @@ SDL_Downsample_S8_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint8 *dst = (Sint8 *) cvt->buf;
const Sint8 *src = (Sint8 *) cvt->buf;
@ -3012,7 +3012,7 @@ SDL_Upsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 96;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
register int eps = 0;
Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 6;
const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -3069,7 +3069,7 @@ SDL_Downsample_S8_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 96;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/6)) * cvt->rate_incr) * 6;
register int eps = 0;
Sint8 *dst = (Sint8 *) cvt->buf;
const Sint8 *src = (Sint8 *) cvt->buf;
@ -3126,7 +3126,7 @@ SDL_Upsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint8 *dst = ((Sint8 *) (cvt->buf + dstsize)) - 8;
const Sint8 *src = ((Sint8 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -3193,7 +3193,7 @@ SDL_Downsample_S8_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint8 *dst = (Sint8 *) cvt->buf;
const Sint8 *src = (Sint8 *) cvt->buf;
@ -3260,7 +3260,7 @@ SDL_Upsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -3292,7 +3292,7 @@ SDL_Downsample_U16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -3324,7 +3324,7 @@ SDL_Upsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -3361,7 +3361,7 @@ SDL_Downsample_U16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -3398,7 +3398,7 @@ SDL_Upsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -3445,7 +3445,7 @@ SDL_Downsample_U16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -3492,7 +3492,7 @@ SDL_Upsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -3549,7 +3549,7 @@ SDL_Downsample_U16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -3606,7 +3606,7 @@ SDL_Upsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -3673,7 +3673,7 @@ SDL_Downsample_U16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -3740,7 +3740,7 @@ SDL_Upsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -3772,7 +3772,7 @@ SDL_Downsample_S16LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -3804,7 +3804,7 @@ SDL_Upsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -3841,7 +3841,7 @@ SDL_Downsample_S16LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -3878,7 +3878,7 @@ SDL_Upsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -3925,7 +3925,7 @@ SDL_Downsample_S16LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -3972,7 +3972,7 @@ SDL_Upsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -4029,7 +4029,7 @@ SDL_Downsample_S16LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -4086,7 +4086,7 @@ SDL_Upsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -4153,7 +4153,7 @@ SDL_Downsample_S16LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -4220,7 +4220,7 @@ SDL_Upsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 1;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -4252,7 +4252,7 @@ SDL_Downsample_U16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -4284,7 +4284,7 @@ SDL_Upsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 2;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -4321,7 +4321,7 @@ SDL_Downsample_U16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -4358,7 +4358,7 @@ SDL_Upsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 4;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -4405,7 +4405,7 @@ SDL_Downsample_U16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -4452,7 +4452,7 @@ SDL_Upsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 6;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -4509,7 +4509,7 @@ SDL_Downsample_U16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -4566,7 +4566,7 @@ SDL_Upsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Uint16 *dst = ((Uint16 *) (cvt->buf + dstsize)) - 8;
const Uint16 *src = ((Uint16 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -4633,7 +4633,7 @@ SDL_Downsample_U16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Uint16 *dst = (Uint16 *) cvt->buf;
const Uint16 *src = (Uint16 *) cvt->buf;
@ -4700,7 +4700,7 @@ SDL_Upsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 1;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -4732,7 +4732,7 @@ SDL_Downsample_S16MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 32;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/2)) * cvt->rate_incr) * 2;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -4764,7 +4764,7 @@ SDL_Upsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 2;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -4801,7 +4801,7 @@ SDL_Downsample_S16MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -4838,7 +4838,7 @@ SDL_Upsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 4;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -4885,7 +4885,7 @@ SDL_Downsample_S16MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -4932,7 +4932,7 @@ SDL_Upsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 6;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -4989,7 +4989,7 @@ SDL_Downsample_S16MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 192;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/12)) * cvt->rate_incr) * 12;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -5046,7 +5046,7 @@ SDL_Upsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint16 *dst = ((Sint16 *) (cvt->buf + dstsize)) - 8;
const Sint16 *src = ((Sint16 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -5113,7 +5113,7 @@ SDL_Downsample_S16MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint16 *dst = (Sint16 *) cvt->buf;
const Sint16 *src = (Sint16 *) cvt->buf;
@ -5180,7 +5180,7 @@ SDL_Upsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -5212,7 +5212,7 @@ SDL_Downsample_S32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5244,7 +5244,7 @@ SDL_Upsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -5281,7 +5281,7 @@ SDL_Downsample_S32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5318,7 +5318,7 @@ SDL_Upsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -5365,7 +5365,7 @@ SDL_Downsample_S32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5412,7 +5412,7 @@ SDL_Upsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -5469,7 +5469,7 @@ SDL_Downsample_S32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5526,7 +5526,7 @@ SDL_Upsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -5593,7 +5593,7 @@ SDL_Downsample_S32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5660,7 +5660,7 @@ SDL_Upsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 1;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 1;
@ -5692,7 +5692,7 @@ SDL_Downsample_S32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5724,7 +5724,7 @@ SDL_Upsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 2;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 2;
@ -5761,7 +5761,7 @@ SDL_Downsample_S32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5798,7 +5798,7 @@ SDL_Upsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 4;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 4;
@ -5845,7 +5845,7 @@ SDL_Downsample_S32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -5892,7 +5892,7 @@ SDL_Upsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 6;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 6;
@ -5949,7 +5949,7 @@ SDL_Downsample_S32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -6006,7 +6006,7 @@ SDL_Upsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
Sint32 *dst = ((Sint32 *) (cvt->buf + dstsize)) - 8;
const Sint32 *src = ((Sint32 *) (cvt->buf + cvt->len_cvt)) - 8;
@ -6073,7 +6073,7 @@ SDL_Downsample_S32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
Sint32 *dst = (Sint32 *) cvt->buf;
const Sint32 *src = (Sint32 *) cvt->buf;
@ -6140,7 +6140,7 @@ SDL_Upsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 1;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
@ -6172,7 +6172,7 @@ SDL_Downsample_F32LSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6204,7 +6204,7 @@ SDL_Upsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 2;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
@ -6241,7 +6241,7 @@ SDL_Downsample_F32LSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6278,7 +6278,7 @@ SDL_Upsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 4;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
@ -6325,7 +6325,7 @@ SDL_Downsample_F32LSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6372,7 +6372,7 @@ SDL_Upsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 6;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
@ -6429,7 +6429,7 @@ SDL_Downsample_F32LSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6486,7 +6486,7 @@ SDL_Upsample_F32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 8;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
@ -6553,7 +6553,7 @@ SDL_Downsample_F32LSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6620,7 +6620,7 @@ SDL_Upsample_F32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 1;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 1;
@ -6652,7 +6652,7 @@ SDL_Downsample_F32MSB_1c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 64;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/4)) * cvt->rate_incr) * 4;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6684,7 +6684,7 @@ SDL_Upsample_F32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 2;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 2;
@ -6721,7 +6721,7 @@ SDL_Downsample_F32MSB_2c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 128;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/8)) * cvt->rate_incr) * 8;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6758,7 +6758,7 @@ SDL_Upsample_F32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 4;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 4;
@ -6805,7 +6805,7 @@ SDL_Downsample_F32MSB_4c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 256;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/16)) * cvt->rate_incr) * 16;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6852,7 +6852,7 @@ SDL_Upsample_F32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 6;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 6;
@ -6909,7 +6909,7 @@ SDL_Downsample_F32MSB_6c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 384;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/24)) * cvt->rate_incr) * 24;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;
@ -6966,7 +6966,7 @@ SDL_Upsample_F32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
float *dst = ((float *) (cvt->buf + dstsize)) - 8;
const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
@ -7033,7 +7033,7 @@ SDL_Downsample_F32MSB_8c(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - 512;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/32)) * cvt->rate_incr) * 32;
register int eps = 0;
float *dst = (float *) cvt->buf;
const float *src = (float *) cvt->buf;

View file

@ -121,7 +121,8 @@ MS_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
struct MS_ADPCM_decodestate *state[2];
Uint8 *freeable, *encoded, *decoded;
Sint32 encoded_len, samplesleft;
Sint8 nybble, stereo;
Sint8 nybble;
Uint8 stereo;
Sint16 *coeff[2];
Sint32 new_sample;
@ -278,7 +279,8 @@ IMA_ADPCM_nibble(struct IMA_ADPCM_decodestate *state, Uint8 nybble)
} else if (state->index < 0) {
state->index = 0;
}
step = step_table[state->index];
/* explicit cast to avoid gcc warning about using 'char' as array index */
step = step_table[(int)state->index];
delta = step >> 3;
if (nybble & 0x04)
delta += step;
@ -343,7 +345,7 @@ IMA_ADPCM_decode(Uint8 ** audio_buf, Uint32 * audio_len)
/* Check to make sure we have enough variables in the state array */
channels = IMA_ADPCM_state.wavefmt.channels;
if (channels > SDL_arraysize(IMA_ADPCM_state.state)) {
SDL_SetError("IMA ADPCM decoder can only handle %d channels",
SDL_SetError("IMA ADPCM decoder can only handle %zu channels",
SDL_arraysize(IMA_ADPCM_state.state));
return (-1);
}
@ -458,7 +460,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
}
/* 2 Uint32's for chunk header+len, plus the lenread */
headerDiff += lenread + 2 * sizeof(Uint32);
} while ((chunk.magic == FACT) || (chunk.magic == LIST));
} while ((chunk.magic == FACT) || (chunk.magic == LIST) || (chunk.magic == BEXT));
/* Decode the audio data format */
format = (WaveFMT *) chunk.data;
@ -493,8 +495,7 @@ SDL_LoadWAV_RW(SDL_RWops * src, int freesrc,
IMA_ADPCM_encoded = 1;
break;
case MP3_CODE:
SDL_SetError("MPEG Layer 3 data not supported",
SDL_SwapLE16(format->encoding));
SDL_SetError("MPEG Layer 3 data not supported");
was_error = 1;
goto done;
default:

View file

@ -29,6 +29,7 @@
#define WAVE 0x45564157 /* "WAVE" */
#define FACT 0x74636166 /* "fact" */
#define LIST 0x5453494c /* "LIST" */
#define BEXT 0x74786562 /* "bext" */
#define FMT 0x20746D66 /* "fmt " */
#define DATA 0x61746164 /* "data" */
#define PCM_CODE 0x0001

View file

@ -0,0 +1,147 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_naclaudio.h"
#include "SDL_audio.h"
#include "SDL_mutex.h"
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
#include "../SDL_audiodev_c.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi_simple/ps.h"
#include "ppapi_simple/ps_interface.h"
#include "ppapi_simple/ps_event.h"
/* The tag name used by NACL audio */
#define NACLAUD_DRIVER_NAME "nacl"
#define SAMPLE_FRAME_COUNT 4096
/* Audio driver functions */
static int NACLAUD_OpenDevice(_THIS, const char *devname, int iscapture);
static void NACLAUD_CloseDevice(_THIS);
static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data);
/* FIXME: Make use of latency if needed */
static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data) {
SDL_AudioDevice* _this = (SDL_AudioDevice*) data;
SDL_LockMutex(private->mutex);
if (_this->enabled && !_this->paused) {
if (_this->convert.needed) {
SDL_LockMutex(_this->mixer_lock);
(*_this->spec.callback) (_this->spec.userdata,
(Uint8 *) _this->convert.buf,
_this->convert.len);
SDL_UnlockMutex(_this->mixer_lock);
SDL_ConvertAudio(&_this->convert);
SDL_memcpy(samples, _this->convert.buf, _this->convert.len_cvt);
} else {
SDL_LockMutex(_this->mixer_lock);
(*_this->spec.callback) (_this->spec.userdata, (Uint8 *) samples, buffer_size);
SDL_UnlockMutex(_this->mixer_lock);
}
} else {
SDL_memset(samples, 0, buffer_size);
}
return;
}
static void NACLAUD_CloseDevice(SDL_AudioDevice *device) {
const PPB_Core *core = PSInterfaceCore();
const PPB_Audio *ppb_audio = PSInterfaceAudio();
SDL_PrivateAudioData *hidden = (SDL_PrivateAudioData *) device->hidden;
ppb_audio->StopPlayback(hidden->audio);
SDL_DestroyMutex(hidden->mutex);
core->ReleaseResource(hidden->audio);
}
static int
NACLAUD_OpenDevice(_THIS, const char *devname, int iscapture) {
PP_Instance instance = PSGetInstanceId();
const PPB_Audio *ppb_audio = PSInterfaceAudio();
const PPB_AudioConfig *ppb_audiocfg = PSInterfaceAudioConfig();
private = (SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *private));
if (private == NULL) {
SDL_OutOfMemory();
return 0;
}
private->mutex = SDL_CreateMutex();
_this->spec.freq = 44100;
_this->spec.format = AUDIO_S16LSB;
_this->spec.channels = 2;
_this->spec.samples = ppb_audiocfg->RecommendSampleFrameCount(
instance,
PP_AUDIOSAMPLERATE_44100,
SAMPLE_FRAME_COUNT);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(&_this->spec);
private->audio = ppb_audio->Create(
instance,
ppb_audiocfg->CreateStereo16Bit(instance, PP_AUDIOSAMPLERATE_44100, _this->spec.samples),
nacl_audio_callback,
_this);
/* Start audio playback while we are still on the main thread. */
ppb_audio->StartPlayback(private->audio);
return 1;
}
static int
NACLAUD_Init(SDL_AudioDriverImpl * impl)
{
if (PSGetInstanceId() == 0) {
return 0;
}
/* Set the function pointers */
impl->OpenDevice = NACLAUD_OpenDevice;
impl->CloseDevice = NACLAUD_CloseDevice;
impl->HasCaptureSupport = 0;
impl->OnlyHasDefaultOutputDevice = 1;
impl->OnlyHasDefaultInputDevice = 1;
impl->ProvidesOwnCallbackThread = 1;
/*
* impl->WaitDevice = NACLAUD_WaitDevice;
* impl->GetDeviceBuf = NACLAUD_GetDeviceBuf;
* impl->PlayDevice = NACLAUD_PlayDevice;
* impl->Deinitialize = NACLAUD_Deinitialize;
*/
return 1;
}
AudioBootStrap NACLAUD_bootstrap = {
NACLAUD_DRIVER_NAME, "SDL NaCl Audio Driver",
NACLAUD_Init, 0
};

View file

@ -0,0 +1,41 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclaudio_h
#define _SDL_naclaudio_h
#include "SDL_audio.h"
#include "../SDL_sysaudio.h"
#include "SDL_mutex.h"
#include "ppapi/c/ppb_audio.h"
#define _THIS SDL_AudioDevice *_this
#define private _this->hidden
typedef struct SDL_PrivateAudioData {
SDL_mutex* mutex;
PP_Resource audio;
} SDL_PrivateAudioData;
#endif /* _SDL_naclaudio_h */

View file

@ -383,6 +383,7 @@ sub buildArbitraryResampleFunc {
my $eps_adjust = ($upsample) ? 'dstsize' : 'srcsize';
my $incr = '';
my $incr2 = '';
my $block_align = $channels * $fsize/8;
# !!! FIXME: DEBUG_CONVERT should report frequencies.
@ -395,7 +396,7 @@ ${sym}(SDL_AudioCVT * cvt, SDL_AudioFormat format)
#endif
const int srcsize = cvt->len_cvt - $fudge;
const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
const int dstsize = (int) (((double)(cvt->len_cvt/${block_align})) * cvt->rate_incr) * ${block_align};
register int eps = 0;
EOF

View file

@ -209,7 +209,7 @@ SNDIO_OpenDevice(_THIS, const char *devname, int iscapture)
this->hidden->mixlen = this->spec.size;
/* !!! FIXME: SIO_DEVANY can be a specific device... */
if ((this->hidden->dev = SNDIO_sio_open(NULL, SIO_PLAY, 0)) == NULL) {
if ((this->hidden->dev = SNDIO_sio_open(SIO_DEVANY, SIO_PLAY, 0)) == NULL) {
SNDIO_CloseDevice(this);
return SDL_SetError("sio_open() failed");
}
@ -229,7 +229,17 @@ SNDIO_OpenDevice(_THIS, const char *devname, int iscapture)
par.sig = SDL_AUDIO_ISSIGNED(test_format) ? 1 : 0;
par.bits = SDL_AUDIO_BITSIZE(test_format);
if (SNDIO_sio_setpar(this->hidden->dev, &par) == 1) {
if (SNDIO_sio_setpar(this->hidden->dev, &par) == 0) {
continue;
}
if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
SNDIO_CloseDevice(this);
return SDL_SetError("sio_getpar() failed");
}
if (par.bps != SIO_BPS(par.bits)) {
continue;
}
if ((par.bits == 8 * par.bps) || (par.msb)) {
status = 0;
break;
}
@ -242,26 +252,21 @@ SNDIO_OpenDevice(_THIS, const char *devname, int iscapture)
return SDL_SetError("sndio: Couldn't find any hardware audio formats");
}
if (SNDIO_sio_getpar(this->hidden->dev, &par) == 0) {
SNDIO_CloseDevice(this);
return SDL_SetError("sio_getpar() failed");
}
if ((par.bits == 32) && (par.sig) && (par.le))
if ((par.bps == 4) && (par.sig) && (par.le))
this->spec.format = AUDIO_S32LSB;
else if ((par.bits == 32) && (par.sig) && (!par.le))
else if ((par.bps == 4) && (par.sig) && (!par.le))
this->spec.format = AUDIO_S32MSB;
else if ((par.bits == 16) && (par.sig) && (par.le))
else if ((par.bps == 2) && (par.sig) && (par.le))
this->spec.format = AUDIO_S16LSB;
else if ((par.bits == 16) && (par.sig) && (!par.le))
else if ((par.bps == 2) && (par.sig) && (!par.le))
this->spec.format = AUDIO_S16MSB;
else if ((par.bits == 16) && (!par.sig) && (par.le))
else if ((par.bps == 2) && (!par.sig) && (par.le))
this->spec.format = AUDIO_U16LSB;
else if ((par.bits == 16) && (!par.sig) && (!par.le))
else if ((par.bps == 2) && (!par.sig) && (!par.le))
this->spec.format = AUDIO_U16MSB;
else if ((par.bits == 8) && (par.sig))
else if ((par.bps == 1) && (par.sig))
this->spec.format = AUDIO_S8;
else if ((par.bits == 8) && (!par.sig))
else if ((par.bps == 1) && (!par.sig))
this->spec.format = AUDIO_U8;
else {
SNDIO_CloseDevice(this);

View file

@ -385,7 +385,15 @@ JNIEXPORT void JNICALL Java_org_libsdl_app_SDLInputConnection_nativeSetComposing
(*env)->ReleaseStringUTFChars(env, text, utftext);
}
jstring Java_org_libsdl_app_SDLActivity_nativeGetHint(JNIEnv* env, jclass cls, jstring name) {
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
const char *hint = SDL_GetHint(utfname);
jstring result = (*env)->NewStringUTF(env, hint);
(*env)->ReleaseStringUTFChars(env, name, utfname);
return result;
}
/*******************************************************************************
Functions called by SDL into Java
@ -758,7 +766,14 @@ fallback:
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
if (Android_JNI_ExceptionOccurred(false)) {
goto failure;
// Try fallback to APK Extension files
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
"openAPKExtensionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);
if (Android_JNI_ExceptionOccurred(false)) {
goto failure;
}
}
ctx->hidden.androidio.inputStreamRef = (*mEnv)->NewGlobalRef(mEnv, inputStream);

236
src/core/linux/SDL_dbus.c Normal file
View file

@ -0,0 +1,236 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_dbus.h"
#if SDL_USE_LIBDBUS
/* we never link directly to libdbus. */
#include "SDL_loadso.h"
static const char *dbus_library = "libdbus-1.so.3";
static void *dbus_handle = NULL;
static unsigned int screensaver_cookie = 0;
static SDL_DBusContext dbus = {0};
static int
load_dbus_syms(void)
{
#define SDL_DBUS_SYM2(x, y) \
if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) return -1
#define SDL_DBUS_SYM(x) \
SDL_DBUS_SYM2(x, dbus_##x)
SDL_DBUS_SYM(bus_get_private);
SDL_DBUS_SYM(bus_register);
SDL_DBUS_SYM(bus_add_match);
SDL_DBUS_SYM(connection_open_private);
SDL_DBUS_SYM(connection_set_exit_on_disconnect);
SDL_DBUS_SYM(connection_get_is_connected);
SDL_DBUS_SYM(connection_add_filter);
SDL_DBUS_SYM(connection_send);
SDL_DBUS_SYM(connection_send_with_reply_and_block);
SDL_DBUS_SYM(connection_close);
SDL_DBUS_SYM(connection_unref);
SDL_DBUS_SYM(connection_flush);
SDL_DBUS_SYM(connection_read_write);
SDL_DBUS_SYM(connection_dispatch);
SDL_DBUS_SYM(message_is_signal);
SDL_DBUS_SYM(message_new_method_call);
SDL_DBUS_SYM(message_append_args);
SDL_DBUS_SYM(message_get_args);
SDL_DBUS_SYM(message_iter_init);
SDL_DBUS_SYM(message_iter_next);
SDL_DBUS_SYM(message_iter_get_basic);
SDL_DBUS_SYM(message_iter_get_arg_type);
SDL_DBUS_SYM(message_iter_recurse);
SDL_DBUS_SYM(message_unref);
SDL_DBUS_SYM(error_init);
SDL_DBUS_SYM(error_is_set);
SDL_DBUS_SYM(error_free);
SDL_DBUS_SYM(get_local_machine_id);
SDL_DBUS_SYM(free);
#undef SDL_DBUS_SYM
#undef SDL_DBUS_SYM2
return 0;
}
static void
UnloadDBUSLibrary(void)
{
if (dbus_handle != NULL) {
SDL_UnloadObject(dbus_handle);
dbus_handle = NULL;
}
}
static int
LoadDBUSLibrary(void)
{
int retval = 0;
if (dbus_handle == NULL) {
dbus_handle = SDL_LoadObject(dbus_library);
if (dbus_handle == NULL) {
retval = -1;
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
} else {
retval = load_dbus_syms();
if (retval < 0) {
UnloadDBUSLibrary();
}
}
}
return retval;
}
void
SDL_DBus_Init(void)
{
if (LoadDBUSLibrary() != -1) {
DBusError err;
dbus.error_init(&err);
dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
if (dbus.error_is_set(&err)) {
dbus.error_free(&err);
if (dbus.session_conn) {
dbus.connection_unref(dbus.session_conn);
dbus.session_conn = NULL;
}
return; /* oh well */
}
dbus.connection_set_exit_on_disconnect(dbus.session_conn, 0);
}
}
void
SDL_DBus_Quit(void)
{
if (dbus.session_conn) {
dbus.connection_close(dbus.session_conn);
dbus.connection_unref(dbus.session_conn);
SDL_memset(&dbus, 0, sizeof(dbus));
}
UnloadDBUSLibrary();
}
SDL_DBusContext *
SDL_DBus_GetContext(void)
{
if(!dbus_handle || !dbus.session_conn){
SDL_DBus_Init();
}
if(dbus_handle && dbus.session_conn){
return &dbus;
} else {
return NULL;
}
}
void
SDL_DBus_ScreensaverTickle(void)
{
DBusConnection *conn = dbus.session_conn;
if (conn != NULL) {
DBusMessage *msg = dbus.message_new_method_call("org.gnome.ScreenSaver",
"/org/gnome/ScreenSaver",
"org.gnome.ScreenSaver",
"SimulateUserActivity");
if (msg != NULL) {
if (dbus.connection_send(conn, msg, NULL)) {
dbus.connection_flush(conn);
}
dbus.message_unref(msg);
}
}
}
SDL_bool
SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
{
DBusConnection *conn = dbus.session_conn;
if (conn == NULL)
return SDL_FALSE;
if (inhibit &&
screensaver_cookie != 0)
return SDL_TRUE;
if (!inhibit &&
screensaver_cookie == 0)
return SDL_TRUE;
if (inhibit) {
const char *app = "My SDL application";
const char *reason = "Playing a game";
DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
"/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver",
"Inhibit");
if (msg != NULL) {
dbus.message_append_args (msg,
DBUS_TYPE_STRING, &app,
DBUS_TYPE_STRING, &reason,
DBUS_TYPE_INVALID);
}
if (msg != NULL) {
DBusMessage *reply;
reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
if (reply) {
if (!dbus.message_get_args(reply, NULL,
DBUS_TYPE_UINT32, &screensaver_cookie,
DBUS_TYPE_INVALID))
screensaver_cookie = 0;
dbus.message_unref(reply);
}
dbus.message_unref(msg);
}
if (screensaver_cookie == 0) {
return SDL_FALSE;
}
return SDL_TRUE;
} else {
DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
"/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver",
"UnInhibit");
dbus.message_append_args (msg,
DBUS_TYPE_UINT32, &screensaver_cookie,
DBUS_TYPE_INVALID);
if (msg != NULL) {
if (dbus.connection_send(conn, msg, NULL)) {
dbus.connection_flush(conn);
}
dbus.message_unref(msg);
}
screensaver_cookie = 0;
return SDL_TRUE;
}
}
#endif

79
src/core/linux/SDL_dbus.h Normal file
View file

@ -0,0 +1,79 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_dbus_h
#define _SDL_dbus_h
#ifdef HAVE_DBUS_DBUS_H
#define SDL_USE_LIBDBUS 1
#include "SDL_stdinc.h"
#include <dbus/dbus.h>
typedef struct SDL_DBusContext {
DBusConnection *session_conn;
DBusConnection *(*bus_get_private)(DBusBusType, DBusError *);
dbus_bool_t (*bus_register)(DBusConnection *, DBusError *);
void (*bus_add_match)(DBusConnection *, const char *, DBusError *);
DBusConnection * (*connection_open_private)(const char *, DBusError *);
void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
dbus_bool_t (*connection_get_is_connected)(DBusConnection *);
dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction,
void *, DBusFreeFunction);
dbus_bool_t (*connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *);
DBusMessage *(*connection_send_with_reply_and_block)(DBusConnection *, DBusMessage *, int, DBusError *);
void (*connection_close)(DBusConnection *);
void (*connection_unref)(DBusConnection *);
void (*connection_flush)(DBusConnection *);
dbus_bool_t (*connection_read_write)(DBusConnection *, int);
DBusDispatchStatus (*connection_dispatch)(DBusConnection *);
dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *);
dbus_bool_t (*message_append_args)(DBusMessage *, int, ...);
dbus_bool_t (*message_get_args)(DBusMessage *, DBusError *, int, ...);
dbus_bool_t (*message_iter_init)(DBusMessage *, DBusMessageIter *);
dbus_bool_t (*message_iter_next)(DBusMessageIter *);
void (*message_iter_get_basic)(DBusMessageIter *, void *);
int (*message_iter_get_arg_type)(DBusMessageIter *);
void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
void (*message_unref)(DBusMessage *);
void (*error_init)(DBusError *);
dbus_bool_t (*error_is_set)(const DBusError *);
void (*error_free)(DBusError *);
char *(*get_local_machine_id)(void);
void (*free)(void *);
} SDL_DBusContext;
extern void SDL_DBus_Init(void);
extern void SDL_DBus_Quit(void);
extern SDL_DBusContext * SDL_DBus_GetContext(void);
extern void SDL_DBus_ScreensaverTickle(void);
extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit);
#endif /* HAVE_DBUS_DBUS_H */
#endif /* _SDL_dbus_h */
/* vi: set ts=4 sw=4 expandtab: */

593
src/core/linux/SDL_ibus.c Normal file
View file

@ -0,0 +1,593 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifdef HAVE_IBUS_IBUS_H
#include "SDL.h"
#include "SDL_ibus.h"
#include "SDL_dbus.h"
#include "../../video/SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include <sys/inotify.h>
#include <unistd.h>
#include <fcntl.h>
static const char IBUS_SERVICE[] = "org.freedesktop.IBus";
static const char IBUS_PATH[] = "/org/freedesktop/IBus";
static const char IBUS_INTERFACE[] = "org.freedesktop.IBus";
static const char IBUS_INPUT_INTERFACE[] = "org.freedesktop.IBus.InputContext";
static char *input_ctx_path = NULL;
static SDL_Rect ibus_cursor_rect = {0};
static DBusConnection *ibus_conn = NULL;
static char *ibus_addr_file = NULL;
int inotify_fd = -1;
static Uint32
IBus_ModState(void)
{
Uint32 ibus_mods = 0;
SDL_Keymod sdl_mods = SDL_GetModState();
/* Not sure about MOD3, MOD4 and HYPER mappings */
if(sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
if(sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK;
if(sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK;
if(sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK;
if(sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK;
if(sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK;
if(sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK;
if(sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK;
return ibus_mods;
}
static const char *
IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus)
{
/* The text we need is nested weirdly, use dbus-monitor to see the structure better */
const char *text = NULL;
DBusMessageIter sub1, sub2;
if(dbus->message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT){
return NULL;
}
dbus->message_iter_recurse(iter, &sub1);
if(dbus->message_iter_get_arg_type(&sub1) != DBUS_TYPE_STRUCT){
return NULL;
}
dbus->message_iter_recurse(&sub1, &sub2);
if(dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING){
return NULL;
}
const char *struct_id = NULL;
dbus->message_iter_get_basic(&sub2, &struct_id);
if(!struct_id || SDL_strncmp(struct_id, "IBusText", sizeof("IBusText")) != 0){
return NULL;
}
dbus->message_iter_next(&sub2);
dbus->message_iter_next(&sub2);
if(dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING){
return NULL;
}
dbus->message_iter_get_basic(&sub2, &text);
return text;
}
static size_t
IBus_utf8_strlen(const char *str)
{
size_t utf8_len = 0;
const char *p;
for(p = str; *p; ++p){
if(!((*p & 0x80) && !(*p & 0x40))){
++utf8_len;
}
}
return utf8_len;
}
static DBusHandlerResult
IBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
SDL_DBusContext *dbus = (SDL_DBusContext *)user_data;
if(dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "CommitText")){
DBusMessageIter iter;
dbus->message_iter_init(msg, &iter);
const char *text = IBus_GetVariantText(conn, &iter, dbus);
if(text && *text){
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
size_t text_bytes = SDL_strlen(text), i = 0;
while(i < text_bytes){
size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
SDL_SendKeyboardText(buf);
i += sz;
}
}
return DBUS_HANDLER_RESULT_HANDLED;
}
if(dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "UpdatePreeditText")){
DBusMessageIter iter;
dbus->message_iter_init(msg, &iter);
const char *text = IBus_GetVariantText(conn, &iter, dbus);
if(text && *text){
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
size_t text_bytes = SDL_strlen(text), i = 0;
size_t cursor = 0;
while(i < text_bytes){
size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
size_t chars = IBus_utf8_strlen(buf);
SDL_SendEditingText(buf, cursor, chars);
i += sz;
cursor += chars;
}
} else {
SDL_SendEditingText("", 0, 0);
}
SDL_IBus_UpdateTextRect(NULL);
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static char *
IBus_ReadAddressFromFile(const char *file_path)
{
FILE *addr_file = fopen(file_path, "r");
if(!addr_file){
return NULL;
}
char addr_buf[1024];
SDL_bool success = SDL_FALSE;
while(fgets(addr_buf, sizeof(addr_buf), addr_file)){
if(SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0){
size_t sz = SDL_strlen(addr_buf);
if(addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
if(addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
success = SDL_TRUE;
break;
}
}
fclose(addr_file);
if(success){
return SDL_strdup(addr_buf + (sizeof("IBUS_ADDRESS=") - 1));
} else {
return NULL;
}
}
static char *
IBus_GetDBusAddressFilename(void)
{
if(ibus_addr_file){
return SDL_strdup(ibus_addr_file);
}
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(!dbus){
return NULL;
}
/* Use this environment variable if it exists. */
const char *addr = SDL_getenv("IBUS_ADDRESS");
if(addr && *addr){
return SDL_strdup(addr);
}
/* Otherwise, we have to get the hostname, display, machine id, config dir
and look up the address from a filepath using all those bits, eek. */
const char *disp_env = SDL_getenv("DISPLAY");
char *display = NULL;
if(!disp_env || !*disp_env){
display = SDL_strdup(":0.0");
} else {
display = SDL_strdup(disp_env);
}
const char *host = display;
char *disp_num = SDL_strrchr(display, ':'),
*screen_num = SDL_strrchr(display, '.');
if(!disp_num){
SDL_free(display);
return NULL;
}
*disp_num = 0;
disp_num++;
if(screen_num){
*screen_num = 0;
}
if(!*host){
host = "unix";
}
char config_dir[PATH_MAX];
SDL_memset(config_dir, 0, sizeof(config_dir));
const char *conf_env = SDL_getenv("XDG_CONFIG_HOME");
if(conf_env && *conf_env){
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
} else {
const char *home_env = SDL_getenv("HOME");
if(!home_env || !*home_env){
SDL_free(display);
return NULL;
}
SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
}
char *key = dbus->get_local_machine_id();
char file_path[PATH_MAX];
SDL_memset(file_path, 0, sizeof(file_path));
SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
config_dir, key, host, disp_num);
dbus->free(key);
SDL_free(display);
return SDL_strdup(file_path);
}
static SDL_bool
IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
{
const char *path = NULL;
SDL_bool result = SDL_FALSE;
ibus_conn = dbus->connection_open_private(addr, NULL);
if(!ibus_conn){
return SDL_FALSE;
}
dbus->connection_flush(ibus_conn);
if(!dbus->bus_register(ibus_conn, NULL)){
ibus_conn = NULL;
return SDL_FALSE;
}
dbus->connection_flush(ibus_conn);
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
IBUS_PATH,
IBUS_INTERFACE,
"CreateInputContext");
if(msg){
const char *client_name = "SDL2_Application";
dbus->message_append_args(msg,
DBUS_TYPE_STRING, &client_name,
DBUS_TYPE_INVALID);
}
if(msg){
DBusMessage *reply;
reply = dbus->connection_send_with_reply_and_block(ibus_conn, msg, 1000, NULL);
if(reply){
if(dbus->message_get_args(reply, NULL,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID)){
if(input_ctx_path){
SDL_free(input_ctx_path);
}
input_ctx_path = SDL_strdup(path);
result = SDL_TRUE;
}
dbus->message_unref(reply);
}
dbus->message_unref(msg);
}
if(result){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
"SetCapabilities");
if(msg){
Uint32 caps = IBUS_CAP_FOCUS | IBUS_CAP_PREEDIT_TEXT;
dbus->message_append_args(msg,
DBUS_TYPE_UINT32, &caps,
DBUS_TYPE_INVALID);
}
if(msg){
if(dbus->connection_send(ibus_conn, msg, NULL)){
dbus->connection_flush(ibus_conn);
}
dbus->message_unref(msg);
}
dbus->bus_add_match(ibus_conn, "type='signal',interface='org.freedesktop.IBus.InputContext'", NULL);
dbus->connection_add_filter(ibus_conn, &IBus_MessageFilter, dbus, NULL);
dbus->connection_flush(ibus_conn);
}
SDL_IBus_SetFocus(SDL_GetFocusWindow() != NULL);
SDL_IBus_UpdateTextRect(NULL);
return result;
}
static SDL_bool
IBus_CheckConnection(SDL_DBusContext *dbus)
{
if(!dbus) return SDL_FALSE;
if(ibus_conn && dbus->connection_get_is_connected(ibus_conn)){
return SDL_TRUE;
}
if(inotify_fd != -1){
char buf[1024];
ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
if(readsize > 0){
char *p;
SDL_bool file_updated = SDL_FALSE;
for(p = buf; p < buf + readsize; /**/){
struct inotify_event *event = (struct inotify_event*) p;
if(event->len > 0){
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
if(!addr_file_no_path) return SDL_FALSE;
if(SDL_strcmp(addr_file_no_path + 1, event->name) == 0){
file_updated = SDL_TRUE;
break;
}
}
p += sizeof(struct inotify_event) + event->len;
}
if(file_updated){
char *addr = IBus_ReadAddressFromFile(ibus_addr_file);
if(addr){
SDL_bool result = IBus_SetupConnection(dbus, addr);
SDL_free(addr);
return result;
}
}
}
}
return SDL_FALSE;
}
SDL_bool
SDL_IBus_Init(void)
{
SDL_bool result = SDL_FALSE;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(dbus){
char *addr_file = IBus_GetDBusAddressFilename();
if(!addr_file){
return SDL_FALSE;
}
ibus_addr_file = SDL_strdup(addr_file);
char *addr = IBus_ReadAddressFromFile(addr_file);
inotify_fd = inotify_init();
fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
char *addr_file_dir = SDL_strrchr(addr_file, '/');
if(addr_file_dir){
*addr_file_dir = 0;
}
inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
SDL_free(addr_file);
result = IBus_SetupConnection(dbus, addr);
SDL_free(addr);
}
return result;
}
void
SDL_IBus_Quit(void)
{
if(input_ctx_path){
SDL_free(input_ctx_path);
input_ctx_path = NULL;
}
if(ibus_addr_file){
SDL_free(ibus_addr_file);
ibus_addr_file = NULL;
}
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(dbus && ibus_conn){
dbus->connection_close(ibus_conn);
dbus->connection_unref(ibus_conn);
}
SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
}
static void
IBus_SimpleMessage(const char *method)
{
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
method);
if(msg){
if(dbus->connection_send(ibus_conn, msg, NULL)){
dbus->connection_flush(ibus_conn);
}
dbus->message_unref(msg);
}
}
}
void
SDL_IBus_SetFocus(SDL_bool focused)
{
const char *method = focused ? "FocusIn" : "FocusOut";
IBus_SimpleMessage(method);
}
void
SDL_IBus_Reset(void)
{
IBus_SimpleMessage("Reset");
}
SDL_bool
SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
{
SDL_bool result = SDL_FALSE;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
"ProcessKeyEvent");
if(msg){
Uint32 mods = IBus_ModState();
dbus->message_append_args(msg,
DBUS_TYPE_UINT32, &keysym,
DBUS_TYPE_UINT32, &keycode,
DBUS_TYPE_UINT32, &mods,
DBUS_TYPE_INVALID);
}
if(msg){
DBusMessage *reply;
reply = dbus->connection_send_with_reply_and_block(ibus_conn, msg, 300, NULL);
if(reply){
if(!dbus->message_get_args(reply, NULL,
DBUS_TYPE_BOOLEAN, &result,
DBUS_TYPE_INVALID)){
result = SDL_FALSE;
}
dbus->message_unref(reply);
}
dbus->message_unref(msg);
}
}
return result;
}
void
SDL_IBus_UpdateTextRect(SDL_Rect *rect)
{
if(rect){
SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
}
SDL_Window *focused_win = SDL_GetFocusWindow();
if(!focused_win) return;
int x = 0, y = 0;
SDL_GetWindowPosition(focused_win, &x, &y);
x += ibus_cursor_rect.x;
y += ibus_cursor_rect.y;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
"SetCursorLocation");
if(msg){
dbus->message_append_args(msg,
DBUS_TYPE_INT32, &x,
DBUS_TYPE_INT32, &y,
DBUS_TYPE_INT32, &ibus_cursor_rect.w,
DBUS_TYPE_INT32, &ibus_cursor_rect.h,
DBUS_TYPE_INVALID);
}
if(msg){
if(dbus->connection_send(ibus_conn, msg, NULL)){
dbus->connection_flush(ibus_conn);
}
dbus->message_unref(msg);
}
}
}
void
SDL_IBus_PumpEvents(void)
{
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
dbus->connection_read_write(ibus_conn, 0);
while(dbus->connection_dispatch(ibus_conn) == DBUS_DISPATCH_DATA_REMAINS){
/* Do nothing, actual work happens in IBus_MessageFilter */
}
}
}
#endif

58
src/core/linux/SDL_ibus.h Normal file
View file

@ -0,0 +1,58 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_ibus_h
#define _SDL_ibus_h
#ifdef HAVE_IBUS_IBUS_H
#define SDL_USE_IBUS 1
#include "SDL_stdinc.h"
#include <ibus-1.0/ibus.h>
extern SDL_bool SDL_IBus_Init(void);
extern void SDL_IBus_Quit(void);
/* Lets the IBus server know about changes in window focus */
extern void SDL_IBus_SetFocus(SDL_bool focused);
/* Closes the candidate list and resets any text currently being edited */
extern void SDL_IBus_Reset(void);
/* Sends a keypress event to IBus, returns SDL_TRUE if IBus used this event to
update its candidate list or change input methods. PumpEvents should be
called some time after this, to recieve the TextInput / TextEditing event back. */
extern SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
/* Update the position of IBus' candidate list. If rect is NULL then this will
just reposition it relative to the focused window's new position. */
extern void SDL_IBus_UpdateTextRect(SDL_Rect *window_relative_rect);
/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
SDL_SendEditingText for each event it finds */
extern void SDL_IBus_PumpEvents();
#endif /* HAVE_IBUS_IBUS_H */
#endif /* _SDL_ibus_h */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -56,38 +56,38 @@ static void SDL_InitDynamicAPI(void);
#if DISABLE_JUMP_MAGIC
/* Can't use the macro for varargs nonsense. This is atrocious. */
#define SDL_DYNAPI_VARARGS_LOGFN(_static, name, initcall, logname, prio) \
_static void SDL_Log##logname##name(int category, const char *fmt, ...) { \
_static void SDL_Log##logname##name(int category, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(category, SDL_LOG_PRIORITY_##prio, fmt, ap); \
va_end(ap); \
}
#define SDL_DYNAPI_VARARGS(_static, name, initcall) \
_static int SDL_SetError##name(const char *fmt, ...) { \
_static int SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
char buf[512]; /* !!! FIXME: dynamic allocation */ \
va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_vsnprintf(buf, sizeof (buf), fmt, ap); \
va_end(ap); \
return jump_table.SDL_SetError("%s", buf); \
} \
_static int SDL_sscanf##name(const char *buf, const char *fmt, ...) { \
_static int SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { \
int retval; va_list ap; initcall; va_start(ap, fmt); \
retval = jump_table.SDL_vsscanf(buf, fmt, ap); \
va_end(ap); \
return retval; \
} \
_static int SDL_snprintf##name(char *buf, size_t buflen, const char *fmt, ...) { \
_static int SDL_snprintf##name(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
int retval; va_list ap; initcall; va_start(ap, fmt); \
retval = jump_table.SDL_vsnprintf(buf, buflen, fmt, ap); \
retval = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \
va_end(ap); \
return retval; \
} \
_static void SDL_Log##name(const char *fmt, ...) { \
_static void SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, fmt, ap); \
va_end(ap); \
} \
_static void SDL_LogMessage##name(int category, SDL_LogPriority priority, const char *fmt, ...) { \
_static void SDL_LogMessage##name(int category, SDL_LogPriority priority, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { \
va_list ap; initcall; va_start(ap, fmt); \
jump_table.SDL_LogMessageV(category, priority, fmt, ap); \
va_end(ap); \

View file

@ -43,7 +43,7 @@
#include "TargetConditionals.h"
#endif
#if TARGET_OS_IPHONE /* probably not useful on iOS. */
#if TARGET_OS_IPHONE || __native_client__ /* probably not useful on iOS or NACL. */
#define SDL_DYNAMIC_API 0
#elif SDL_BUILDING_WINRT /* probaly not useful on WinRT, given current .dll loading restrictions */
#define SDL_DYNAMIC_API 0

View file

@ -576,9 +576,14 @@
#define SDL_GetAssertionHandler SDL_GetAssertionHandler_REAL
#define SDL_DXGIGetOutputInfo SDL_DXGIGetOutputInfo_REAL
#define SDL_RenderIsClipEnabled SDL_RenderIsClipEnabled_REAL
#define SDL_WinRTRunApp SDL_WinRTRunApp_REAL
#define SDL_WarpMouseGlobal SDL_WarpMouseGlobal_REAL
#define SDL_WinRTGetFSPathUNICODE SDL_WinRTGetFSPathUNICODE_REAL
#define SDL_WinRTGetFSPathUTF8 SDL_WinRTGetFSPathUTF8_REAL
#define SDL_WinRTRunApp SDL_WinRTRunApp_REAL
#define SDL_sqrtf SDL_sqrtf_REAL
#define SDL_tan SDL_tan_REAL
#define SDL_tanf SDL_tanf_REAL
#define SDL_CaptureMouse SDL_CaptureMouse_REAL
#define SDL_SetWindowHitTest SDL_SetWindowHitTest_REAL
#define SDL_GetGlobalMouseState SDL_GetGlobalMouseState_REAL

View file

@ -31,17 +31,17 @@
/* direct jump magic can use these, the rest needs special code. */
#if !SDL_DYNAPI_PROC_NO_VARARGS
SDL_DYNAPI_PROC(int,SDL_SetError,(const char *a, ...),(a),return)
SDL_DYNAPI_PROC(void,SDL_Log,(const char *a, ...),(a),)
SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogError,(int a, const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, const char *c, ...),(a,b,c),)
SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, const char *b, ...),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_snprintf,(char *a, size_t b, const char *c, ...),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),return)
SDL_DYNAPI_PROC(void,SDL_Log,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),)
SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogDebug,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogError,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogCritical,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),)
SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),)
SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const char *b, ...),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_snprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),return)
#endif
#ifdef SDL_CreateThread
@ -418,17 +418,17 @@ SDL_DYNAPI_PROC(int,SDL_isdigit,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_isspace,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_toupper,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_tolower,(int a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_memset,(void *a, int b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_memcpy,(void *a, const void *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_memmove,(void *a, const void *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_memset,(SDL_OUT_BYTECAP(c) void *a, int b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_memcpy,(SDL_OUT_BYTECAP(c) void *a, SDL_IN_BYTECAP(c) const void *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(void*,SDL_memmove,(SDL_OUT_BYTECAP(c) void *a, SDL_IN_BYTECAP(c) const void *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_memcmp,(const void *a, const void *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslen,(const wchar_t *a),(a),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslcpy,(wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslcat,(wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslcpy,(SDL_OUT_Z_CAP(c) wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_wcslcat,(SDL_INOUT_Z_CAP(c) wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_strlen,(const char *a),(a),return)
SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_strlcat,(char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_utf8strlcpy,(SDL_OUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(size_t,SDL_strlcat,(SDL_INOUT_Z_CAP(c) char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(char*,SDL_strdup,(const char *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_strrev,(char *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_strupr,(char *a),(a),return)
@ -453,7 +453,7 @@ SDL_DYNAPI_PROC(int,SDL_strcmp,(const char *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_strncmp,(const char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_strcasecmp,(const char *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_strncasecmp,(const char *a, const char *b, size_t c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_vsnprintf,(char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
SDL_DYNAPI_PROC(int,SDL_vsnprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, const char *c, va_list d),(a,b,c,d),return)
SDL_DYNAPI_PROC(double,SDL_acos,(double a),(a),return)
SDL_DYNAPI_PROC(double,SDL_asin,(double a),(a),return)
SDL_DYNAPI_PROC(double,SDL_atan,(double a),(a),return)
@ -608,10 +608,14 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_DXGIGetOutputInfo,(int a,int *b, int *c),(a,b,c),re
#endif
SDL_DYNAPI_PROC(SDL_bool,SDL_RenderIsClipEnabled,(SDL_Renderer *a),(a),return)
#ifdef __WINRT__
SDL_DYNAPI_PROC(int,SDL_WinRTRunApp,(int a, char **b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(const wchar_t*,SDL_WinRTGetFSPathUNICODE,(SDL_WinRT_Path a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_WinRTGetFSPathUTF8,(SDL_WinRT_Path a),(a),return)
SDL_DYNAPI_PROC(int,SDL_WinRTRunApp,(int a, char **b, void *c),(a,b,c),return)
#endif
SDL_DYNAPI_PROC(void,SDL_WarpMouseGlobal,(int a, int b),(a,b),)
SDL_DYNAPI_PROC(float,SDL_sqrtf,(float a),(a),return)
SDL_DYNAPI_PROC(double,SDL_tan,(double a),(a),return)
SDL_DYNAPI_PROC(float,SDL_tanf,(float a),(a),return)
SDL_DYNAPI_PROC(int,SDL_CaptureMouse,(SDL_bool a),(a),return)
SDL_DYNAPI_PROC(int,SDL_SetWindowHitTest,(SDL_Window *a, SDL_HitTest b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(Uint32,SDL_GetGlobalMouseState,(int *a, int *b),(a,b),return)

View file

@ -83,19 +83,6 @@ static struct
} SDL_EventQ = { NULL, SDL_TRUE };
static SDL_INLINE SDL_bool
SDL_ShouldPollJoystick()
{
#if !SDL_JOYSTICK_DISABLED
if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
SDL_JoystickEventState(SDL_QUERY)) &&
SDL_PrivateJoystickNeedsPolling()) {
return SDL_TRUE;
}
#endif
return SDL_FALSE;
}
/* Public functions */
void
@ -315,7 +302,6 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
For now we'll guarantee it's valid at least until
the next call to SDL_PeepEvents()
*/
SDL_SysWMEntry *wmmsg;
if (SDL_EventQ.wmmsg_free) {
wmmsg = SDL_EventQ.wmmsg_free;
SDL_EventQ.wmmsg_free = wmmsg->next;
@ -403,7 +389,7 @@ SDL_PumpEvents(void)
}
#if !SDL_JOYSTICK_DISABLED
/* Check for joystick state change */
if (SDL_ShouldPollJoystick()) {
if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
SDL_JoystickUpdate();
}
#endif
@ -550,7 +536,7 @@ SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
void
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
{
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
if (SDL_EventQ.lock && SDL_LockMutex(SDL_EventQ.lock) == 0) {
SDL_EventEntry *entry, *next;
for (entry = SDL_EventQ.head; entry; entry = next) {
next = entry->next;

View file

@ -473,7 +473,6 @@ static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
void SDL_GestureProcessEvent(SDL_Event* event)
{
float x,y;
SDL_FloatPoint path[DOLLARNPOINTS];
int index;
int i;
float pathDx, pathDy;
@ -497,6 +496,8 @@ void SDL_GestureProcessEvent(SDL_Event* event)
/* Finger Up */
if (event->type == SDL_FINGERUP) {
SDL_FloatPoint path[DOLLARNPOINTS];
inTouch->numDownFingers--;
#ifdef ENABLE_DOLLAR

View file

@ -150,7 +150,20 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
}
}
/* Linux doesn't give you mouse events outside your window unless you grab
the pointer.
Windows doesn't give you mouse events outside your window unless you call
SetCapture().
Both of these are slightly scary changes, so for now we'll punt and if the
mouse leaves the window you'll lose mouse focus and reset button state.
*/
#ifdef SUPPORT_DRAG_OUTSIDE_WINDOW
if (!inWindow && !buttonstate) {
#else
if (!inWindow) {
#endif
if (window == mouse->focus) {
#ifdef DEBUG_MOUSE
printf("Mouse left window, synthesizing move & focus lost event\n");
@ -191,6 +204,7 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
int posted;
int xrel;
int yrel;
int x_max = 0, y_max = 0;
if (mouse->relative_mode_warp) {
int center_x = 0, center_y = 0;
@ -498,11 +512,11 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
if ( window == NULL ) {
if (window == NULL) {
window = mouse->focus;
}
if ( window == NULL ) {
if (window == NULL) {
return;
}
@ -513,6 +527,16 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
}
}
void
SDL_WarpMouseGlobal(int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
if (mouse->WarpMouseGlobal) {
mouse->WarpMouseGlobal(x, y);
}
}
static SDL_bool
ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
{
@ -590,42 +614,6 @@ SDL_GetRelativeMouseMode()
return mouse->relative_mode;
}
int
SDL_CaptureMouse(SDL_bool enabled)
{
SDL_Mouse *mouse = SDL_GetMouse();
SDL_Window *focusWindow;
SDL_bool isCaptured;
if (!mouse->CaptureMouse) {
return SDL_Unsupported();
}
focusWindow = SDL_GetKeyboardFocus();
isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
if (isCaptured == enabled) {
return 0; /* already done! */
}
if (enabled) {
if (!focusWindow) {
return SDL_SetError("No window has focus");
} else if (mouse->CaptureMouse(focusWindow) == -1) {
return -1; /* CaptureMouse() should call SetError */
}
focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
} else {
if (mouse->CaptureMouse(NULL) == -1) {
return -1; /* CaptureMouse() should call SetError */
}
focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
}
return 0;
}
SDL_Cursor *
SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
int w, int h, int hot_x, int hot_y)

View file

@ -57,9 +57,12 @@ typedef struct
/* Free a window manager cursor */
void (*FreeCursor) (SDL_Cursor * cursor);
/* Warp the mouse to (x,y) */
/* Warp the mouse to (x,y) within a window */
void (*WarpMouse) (SDL_Window * window, int x, int y);
/* Warp the mouse to (x,y) in screen space */
void (*WarpMouseGlobal) (int x, int y);
/* Set relative mode */
int (*SetRelativeMouseMode) (SDL_bool enabled);

View file

@ -43,6 +43,10 @@
#include "SDL_system.h"
#endif
#if __NACL__
#include "nacl_io/nacl_io.h"
#endif
#ifdef __WIN32__
/* Functions to read/write Win32 API file pointers */

View file

@ -18,27 +18,24 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_error.h"
#include "SDL_filesystem.h"
#import <UIKit/UIKit.h>
#import <SDL_types.h>
#ifdef SDL_FILESYSTEM_NACL
/* *INDENT-OFF* */
@interface SDLUIAccelerationDelegate: NSObject <UIAccelerometerDelegate> {
UIAccelerationValue x, y, z;
BOOL isRunning;
BOOL hasNewData;
char *
SDL_GetBasePath(void)
{
SDL_Unsupported();
return NULL;
}
+(SDLUIAccelerationDelegate *)sharedDelegate;
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
-(void)getLastOrientation:(Sint16 *)data;
-(void)startup;
-(void)shutdown;
-(BOOL)isRunning;
-(BOOL)hasNewData;
-(void)setHasNewData:(BOOL)value;
char *
SDL_GetPrefPath(const char *org, const char *app)
{
SDL_Unsupported();
return NULL;
}
@end
/* *INDENT-ON* */
#endif /* __NACL__ */

View file

@ -197,7 +197,7 @@ SDL_GetPrefPath(const char *org, const char *app)
}
if (mkdir(retval, 0700) != 0 && errno != EEXIST) {
error:
SDL_SetError("Couldn't create directory '%s': ", retval, strerror(errno));
SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno));
SDL_free(retval);
return NULL;
}

View file

@ -91,14 +91,14 @@ static int numhaptics = -1;
* Like strerror but for force feedback errors.
*/
static const char *
FFStrError(HRESULT err)
FFStrError(unsigned int err)
{
switch (err) {
case FFERR_DEVICEFULL:
return "device full";
/* This should be valid, but for some reason isn't defined... */
/* case FFERR_DEVICENOTREG:
return "device not registered"; */
/* This should be valid, but for some reason isn't defined... */
/* case FFERR_DEVICENOTREG:
return "device not registered"; */
case FFERR_DEVICEPAUSED:
return "device paused";
case FFERR_DEVICERELEASED:

View file

@ -624,6 +624,8 @@ SDL_SYS_HapticQuit(void)
#endif /* SDL_USE_LIBUDEV */
numhaptics = 0;
SDL_hapticlist = NULL;
SDL_hapticlist_tail = NULL;
}

View file

@ -261,7 +261,7 @@ ControllerMapping_t *SDL_PrivateGetControllerMappingForGUID(SDL_JoystickGUID *gu
ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
{
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
if (SDL_SYS_IsXInputDeviceIndex(device_index) && s_pXInputMapping) {
if (SDL_SYS_IsXInputGamepad_DeviceIndex(device_index) && s_pXInputMapping) {
return s_pXInputMapping;
}
else

View file

@ -41,9 +41,9 @@ static const char *s_ControllerMappings [] =
"4c056802000000000000504944564944,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
"25090500000000000000504944564944,PS3 DualShock,a:b2,b:b1,back:b9,dpdown:h0.8,dpleft:h0.4,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a2,righty:a3,start:b8,x:b0,y:b3,",
"4c05c405000000000000504944564944,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"xinput,X360 Controller,a:b10,b:b11,back:b5,dpdown:b1,dpleft:b2,dpright:b3,dpup:b0,guide:b14,leftshoulder:b8,leftstick:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b7,righttrigger:a5,rightx:a2,righty:a3,start:b4,x:b12,y:b13,",
"xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
#elif defined(SDL_JOYSTICK_XINPUT)
"xinput,X360 Controller,a:b10,b:b11,back:b5,dpdown:b1,dpleft:b2,dpright:b3,dpup:b0,guide:b14,leftshoulder:b8,leftstick:b6,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b9,rightstick:b7,righttrigger:a5,rightx:a2,righty:a3,start:b4,x:b12,y:b13,",
"xinput,XInput Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b10,leftshoulder:b4,leftstick:b8,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b9,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
#elif defined(__MACOSX__)
"0500000047532047616d657061640000,GameStop Gamepad,a:b0,b:b1,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b2,y:b3,",
"6d0400000000000016c2000000000000,Logitech F310 Gamepad (DInput),a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a3,start:b9,x:b0,y:b3,", /* Guide button doesn't seem to be sent in DInput mode. */
@ -64,6 +64,7 @@ static const char *s_ControllerMappings [] =
"050000003620000100000002010000,OUYA Game Controller,a:b0,b:b3,dpdown:b9,dpleft:b10,dpright:b11,dpup:b8,guide:b14,leftshoulder:b4,leftstick:b6,lefttrigger:a2,leftx:a0,lefty:a1,platform:Linux,rightshoulder:b5,rightstick:b7,righttrigger:a5,rightx:a3,righty:a4,x:b1,y:b2,",
"030000004c0500006802000011010000,PS3 Controller,a:b14,b:b13,back:b0,dpdown:b6,dpleft:b7,dpright:b5,dpup:b4,guide:b16,leftshoulder:b10,leftstick:b1,lefttrigger:b8,leftx:a0,lefty:a1,rightshoulder:b11,rightstick:b2,righttrigger:b9,rightx:a2,righty:a3,start:b3,x:b15,y:b12,",
"030000004c050000c405000011010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"050000004c050000c405000000010000,PS4 Controller,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:a3,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:a4,rightx:a2,righty:a5,start:b9,x:b0,y:b3,",
"03000000de280000ff11000001000000,Valve Streaming Gamepad,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400008e02000014010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",
"030000005e0400008e02000010010000,X360 Controller,a:b0,b:b1,back:b6,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b8,leftshoulder:b4,leftstick:b9,lefttrigger:a2,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b10,righttrigger:a5,rightx:a3,righty:a4,start:b7,x:b2,y:b3,",

View file

@ -113,9 +113,8 @@ SDL_JoystickOpen(int device_index)
/* If the joystick is already open, return it
* it is important that we have a single joystick * for each instance id
*/
while ( joysticklist )
{
if ( SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id ) {
while (joysticklist) {
if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id) {
joystick = joysticklist;
++joystick->ref_count;
return (joystick);
@ -136,9 +135,9 @@ SDL_JoystickOpen(int device_index)
return NULL;
}
joystickname = SDL_SYS_JoystickNameForDeviceIndex( device_index );
if ( joystickname )
joystick->name = SDL_strdup( joystickname );
joystickname = SDL_SYS_JoystickNameForDeviceIndex(device_index);
if (joystickname)
joystick->name = SDL_strdup(joystickname);
else
joystick->name = NULL;
@ -186,7 +185,7 @@ SDL_JoystickOpen(int device_index)
joystick->next = SDL_joysticks;
SDL_joysticks = joystick;
SDL_SYS_JoystickUpdate( joystick );
SDL_SYS_JoystickUpdate(joystick);
return (joystick);
}
@ -200,15 +199,14 @@ SDL_PrivateJoystickValid(SDL_Joystick * joystick)
{
int valid;
if ( joystick == NULL ) {
if (joystick == NULL) {
SDL_SetError("Joystick hasn't been opened yet");
valid = 0;
} else {
valid = 1;
}
if ( joystick && joystick->closed )
{
if (joystick && joystick->closed) {
valid = 0;
}
@ -417,20 +415,14 @@ SDL_JoystickClose(SDL_Joystick * joystick)
joysticklist = SDL_joysticks;
joysticklistprev = NULL;
while ( joysticklist )
{
if (joystick == joysticklist)
{
if ( joysticklistprev )
{
while (joysticklist) {
if (joystick == joysticklist) {
if (joysticklistprev) {
/* unlink this entry */
joysticklistprev->next = joysticklist->next;
}
else
{
} else {
SDL_joysticks = joystick->next;
}
break;
}
joysticklistprev = joysticklist;
@ -454,8 +446,7 @@ SDL_JoystickQuit(void)
SDL_assert(!SDL_updating_joystick);
/* Stop the event polling */
while ( SDL_joysticks )
{
while (SDL_joysticks) {
SDL_joysticks->ref_count = 1;
SDL_JoystickClose(SDL_joysticks);
}
@ -472,8 +463,7 @@ SDL_JoystickQuit(void)
static SDL_bool
SDL_PrivateJoystickShouldIgnoreEvent()
{
if (SDL_joystick_allows_background_events)
{
if (SDL_joystick_allows_background_events) {
return SDL_FALSE;
}
@ -497,26 +487,27 @@ SDL_PrivateJoystickAxis(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
{
int posted;
/* Make sure we're not getting garbage events */
/* Make sure we're not getting garbage or duplicate events */
if (axis >= joystick->naxes) {
return 0;
}
/* Update internal joystick state */
if (value == joystick->axes[axis]) {
return 0;
}
joystick->axes[axis] = value;
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (!(joystick->closed && joystick->uncentered)) {
if ((value > 0 && value >= joystick->axes[axis]) ||
(value < 0 && value <= joystick->axes[axis])) {
return 0;
}
}
/* Update internal joystick state */
joystick->axes[axis] = value;
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
@ -537,23 +528,25 @@ SDL_PrivateJoystickHat(SDL_Joystick * joystick, Uint8 hat, Uint8 value)
{
int posted;
/* Make sure we're not getting garbage events */
/* Make sure we're not getting garbage or duplicate events */
if (hat >= joystick->nhats) {
return 0;
}
/* Update internal joystick state */
joystick->hats[hat] = value;
if (value == joystick->hats[hat]) {
return 0;
}
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (!(joystick->closed && joystick->uncentered)) {
if (value != SDL_HAT_CENTERED) {
return 0;
}
}
/* Update internal joystick state */
joystick->hats[hat] = value;
/* Post the event, if desired */
posted = 0;
@ -626,15 +619,20 @@ SDL_PrivateJoystickButton(SDL_Joystick * joystick, Uint8 button, Uint8 state)
}
#endif /* !SDL_EVENTS_DISABLED */
/* Make sure we're not getting garbage events */
/* Make sure we're not getting garbage or duplicate events */
if (button >= joystick->nbuttons) {
return 0;
}
}
if (state == joystick->buttons[button]) {
return 0;
}
/* We ignore events if we don't have keyboard focus, except for button
* release. */
if (state == SDL_PRESSED && SDL_PrivateJoystickShouldIgnoreEvent()) {
return 0;
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (state == SDL_PRESSED) {
return 0;
}
}
/* Update internal joystick state */
@ -659,8 +657,7 @@ SDL_JoystickUpdate(void)
SDL_Joystick *joystick;
joystick = SDL_joysticks;
while ( joystick )
{
while (joystick) {
SDL_Joystick *joysticknext;
/* save off the next pointer, the Update call may cause a joystick removed event
* and cause our joystick pointer to be freed
@ -669,10 +666,9 @@ SDL_JoystickUpdate(void)
SDL_updating_joystick = joystick;
SDL_SYS_JoystickUpdate( joystick );
SDL_SYS_JoystickUpdate(joystick);
if ( joystick->closed && joystick->uncentered )
{
if (joystick->closed && joystick->uncentered) {
int i;
/* Tell the app that everything is centered/unpressed... */
@ -685,13 +681,13 @@ SDL_JoystickUpdate(void)
for (i = 0; i < joystick->nhats; i++)
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
joystick->uncentered = 0;
joystick->uncentered = SDL_FALSE;
}
SDL_updating_joystick = NULL;
/* If the joystick was closed while updating, free it here */
if ( joystick->ref_count <= 0 ) {
if (joystick->ref_count <= 0) {
SDL_JoystickClose(joystick);
}
@ -736,28 +732,16 @@ SDL_JoystickEventState(int state)
#endif /* SDL_EVENTS_DISABLED */
}
/* return 1 if you want to run the joystick update loop this frame, used by hotplug support */
SDL_bool
SDL_PrivateJoystickNeedsPolling()
{
if (SDL_joysticks != NULL) {
return SDL_TRUE;
} else {
return SDL_SYS_JoystickNeedsPolling();
}
}
/* return the guid for this index */
SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
{
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_JoystickGUID emptyGUID;
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
SDL_zero( emptyGUID );
SDL_zero(emptyGUID);
return emptyGUID;
}
return SDL_SYS_JoystickGetDeviceGUID( device_index );
return SDL_SYS_JoystickGetDeviceGUID(device_index);
}
/* return the guid for this opened device */
@ -765,14 +749,14 @@ SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick * joystick)
{
if (!SDL_PrivateJoystickValid(joystick)) {
SDL_JoystickGUID emptyGUID;
SDL_zero( emptyGUID );
SDL_zero(emptyGUID);
return emptyGUID;
}
return SDL_SYS_JoystickGetGUID( joystick );
return SDL_SYS_JoystickGetGUID(joystick);
}
/* convert the guid to a printable string */
void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID )
void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
@ -781,14 +765,13 @@ void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID
return;
}
for ( i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++ )
{
for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) {
/* each input byte writes 2 ascii chars, and might write a null byte. */
/* If we don't have room for next input byte, stop */
unsigned char c = guid.data[i];
*pszGUID++ = k_rgchHexToASCII[ c >> 4 ];
*pszGUID++ = k_rgchHexToASCII[ c & 0x0F ];
*pszGUID++ = k_rgchHexToASCII[c >> 4];
*pszGUID++ = k_rgchHexToASCII[c & 0x0F];
}
*pszGUID = '\0';
}
@ -799,28 +782,22 @@ void SDL_JoystickGetGUIDString( SDL_JoystickGUID guid, char *pszGUID, int cbGUID
* Input : c -
* Output : unsigned char
*-----------------------------------------------------------------------------*/
static unsigned char nibble( char c )
static unsigned char nibble(char c)
{
if ( ( c >= '0' ) &&
( c <= '9' ) )
{
if ((c >= '0') && (c <= '9')) {
return (unsigned char)(c - '0');
}
if ( ( c >= 'A' ) &&
( c <= 'F' ) )
{
if ((c >= 'A') && (c <= 'F')) {
return (unsigned char)(c - 'A' + 0x0a);
}
if ( ( c >= 'a' ) &&
( c <= 'f' ) )
{
if ((c >= 'a') && (c <= 'f')) {
return (unsigned char)(c - 'a' + 0x0a);
}
/* received an invalid character, and no real way to return an error */
/* AssertMsg1( false, "Q_nibble invalid hex character '%c' ", c ); */
/* AssertMsg1(false, "Q_nibble invalid hex character '%c' ", c); */
return 0;
}
@ -830,21 +807,18 @@ SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
{
SDL_JoystickGUID guid;
int maxoutputbytes= sizeof(guid);
size_t len = SDL_strlen( pchGUID );
size_t len = SDL_strlen(pchGUID);
Uint8 *p;
size_t i;
/* Make sure it's even */
len = ( len ) & ~0x1;
len = (len) & ~0x1;
SDL_memset( &guid, 0x00, sizeof(guid) );
SDL_memset(&guid, 0x00, sizeof(guid));
p = (Uint8 *)&guid;
for ( i = 0;
( i < len ) && ( ( p - (Uint8 *)&guid ) < maxoutputbytes );
i+=2, p++ )
{
*p = ( nibble( pchGUID[i] ) << 4 ) | nibble( pchGUID[i+1] );
for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
*p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]);
}
return guid;

View file

@ -42,9 +42,6 @@ extern int SDL_PrivateJoystickHat(SDL_Joystick * joystick,
extern int SDL_PrivateJoystickButton(SDL_Joystick * joystick,
Uint8 button, Uint8 state);
/* Helper function to let lower sys layer tell the event system if the joystick code needs to think */
extern SDL_bool SDL_PrivateJoystickNeedsPolling();
/* Internal sanity checking functions */
extern int SDL_PrivateJoystickValid(SDL_Joystick * joystick);

View file

@ -50,8 +50,8 @@ struct _SDL_Joystick
int ref_count; /* Reference count for multiple opens */
Uint8 closed; /* 1 if this device is no longer valid */
Uint8 uncentered; /* 1 if this device needs to have its state reset to 0 */
SDL_bool closed; /* SDL_TRUE if this device is no longer valid */
SDL_bool uncentered; /* SDL_TRUE if this device needs to have its state reset to 0 */
struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
};
@ -68,9 +68,6 @@ extern int SDL_SYS_NumJoysticks();
/* Function to cause any queued joystick insertions to be processed */
extern void SDL_SYS_JoystickDetect();
/* Function to determine if the joystick loop needs to run right now */
extern SDL_bool SDL_SYS_JoystickNeedsPolling();
/* Function to get the device-dependent name of a joystick */
extern const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index);
@ -109,9 +106,8 @@ extern SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index);
extern SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick);
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
/* Function to get the current instance id of the joystick located at device_index */
extern SDL_bool SDL_SYS_IsXInputDeviceIndex( int device_index );
extern SDL_bool SDL_SYS_IsXInputJoystick(SDL_Joystick * joystick);
/* Function returns SDL_TRUE if this device is an XInput gamepad */
extern SDL_bool SDL_SYS_IsXInputGamepad_DeviceIndex( int device_index );
#endif
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -410,11 +410,6 @@ void SDL_SYS_JoystickDetect()
}
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_TRUE;
}
static SDL_joylist_item *
JoystickByDevIndex(int device_index)
{

View file

@ -213,11 +213,6 @@ void SDL_SYS_JoystickDetect()
{
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
}
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
{

View file

@ -139,6 +139,7 @@ JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender)
{
recDevice *device = (recDevice *) ctx;
device->removed = 1;
device->deviceRef = NULL; // deviceRef was invalidated due to the remove
#if SDL_HAPTIC_IOKIT
MacHaptic_MaybeRemoveDevice(device->ffservice);
#endif
@ -600,12 +601,6 @@ SDL_SYS_JoystickDetect()
}
}
SDL_bool
SDL_SYS_JoystickNeedsPolling()
{
return s_bDeviceAdded || s_bDeviceRemoved;
}
/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)

View file

@ -46,11 +46,6 @@ void SDL_SYS_JoystickDetect()
{
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
}
/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)

View file

@ -94,11 +94,6 @@ extern "C"
{
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
}
/* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickNameForDeviceIndex(int device_index)
{

View file

@ -1,141 +0,0 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#import "SDLUIAccelerationDelegate.h"
/* needed for SDL_IPHONE_MAX_GFORCE macro */
#import "../../../include/SDL_config_iphoneos.h"
static SDLUIAccelerationDelegate *sharedDelegate=nil;
@implementation SDLUIAccelerationDelegate
/*
Returns a shared instance of the SDLUIAccelerationDelegate, creating the shared delegate if it doesn't exist yet.
*/
+(SDLUIAccelerationDelegate *)sharedDelegate {
if (sharedDelegate == nil) {
sharedDelegate = [[SDLUIAccelerationDelegate alloc] init];
}
return sharedDelegate;
}
/*
UIAccelerometerDelegate delegate method. Invoked by the UIAccelerometer instance when it has new data for us.
We just take the data and mark that we have new data available so that the joystick system will pump it to the
events system when SDL_SYS_JoystickUpdate is called.
*/
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
hasNewData = YES;
}
/*
getLastOrientation -- put last obtained accelerometer data into Sint16 array
Called from the joystick system when it needs the accelerometer data.
Function grabs the last data sent to the accelerometer and converts it
from floating point to Sint16, which is what the joystick system expects.
To do the conversion, the data is first clamped onto the interval
[-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
by MAX_SINT16 so that it is mapped to the full range of an Sint16.
You can customize the clamped range of this function by modifying the
SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
Once converted to Sint16, the accelerometer data no longer has coherent units.
You can convert the data back to units of g-force by multiplying it
in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
*/
-(void)getLastOrientation:(Sint16 *)data {
#define MAX_SINT16 0x7FFF
/* clamp the data */
if (x > SDL_IPHONE_MAX_GFORCE) x = SDL_IPHONE_MAX_GFORCE;
else if (x < -SDL_IPHONE_MAX_GFORCE) x = -SDL_IPHONE_MAX_GFORCE;
if (y > SDL_IPHONE_MAX_GFORCE) y = SDL_IPHONE_MAX_GFORCE;
else if (y < -SDL_IPHONE_MAX_GFORCE) y = -SDL_IPHONE_MAX_GFORCE;
if (z > SDL_IPHONE_MAX_GFORCE) z = SDL_IPHONE_MAX_GFORCE;
else if (z < -SDL_IPHONE_MAX_GFORCE) z = -SDL_IPHONE_MAX_GFORCE;
/* pass in data mapped to range of SInt16 */
data[0] = (x / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[1] = (y / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
data[2] = (z / SDL_IPHONE_MAX_GFORCE) * MAX_SINT16;
}
/*
Initialize SDLUIAccelerationDelegate. Since we don't have any data yet,
just set our last received data to zero, and indicate we don't have any;
*/
-(id)init {
self = [super init];
x = y = z = 0.0;
hasNewData = NO;
return self;
}
-(void)dealloc {
sharedDelegate = nil;
[self shutdown];
[super dealloc];
}
/*
Lets our delegate start receiving accelerometer updates.
*/
-(void)startup {
[UIAccelerometer sharedAccelerometer].delegate = self;
isRunning = YES;
}
/*
Stops our delegate from receiving accelerometer updates.
*/
-(void)shutdown {
if ([UIAccelerometer sharedAccelerometer].delegate == self) {
[UIAccelerometer sharedAccelerometer].delegate = nil;
}
isRunning = NO;
}
/*
Our we currently receiving accelerometer updates?
*/
-(BOOL)isRunning {
return isRunning;
}
/*
Do we have any data that hasn't been pumped into SDL's event system?
*/
-(BOOL)hasNewData {
return hasNewData;
}
/*
When the joystick system grabs the new data, it sets this to NO.
*/
-(void)setHasNewData:(BOOL)value {
hasNewData = value;
}
@end

View file

@ -23,11 +23,18 @@
/* This is the iOS implementation of the SDL joystick API */
#include "SDL_joystick.h"
#include "SDL_stdinc.h"
#include "../SDL_sysjoystick.h"
#include "../SDL_joystick_c.h"
#import "SDLUIAccelerationDelegate.h"
const char *accelerometerName = "iPhone accelerometer";
#import <CoreMotion/CoreMotion.h>
/* needed for SDL_IPHONE_MAX_GFORCE macro */
#import "SDL_config_iphoneos.h"
const char *accelerometerName = "iOS accelerometer";
static CMMotionManager *motionManager = nil;
/* Function to scan the system for joysticks.
* This function should set SDL_numjoysticks to the number of available
@ -49,11 +56,6 @@ void SDL_SYS_JoystickDetect()
{
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
}
/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
@ -79,7 +81,15 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
joystick->nhats = 0;
joystick->nballs = 0;
joystick->nbuttons = 0;
[[SDLUIAccelerationDelegate sharedDelegate] startup];
if (motionManager == nil) {
motionManager = [[CMMotionManager alloc] init];
}
/* Shorter times between updates can significantly increase CPU usage. */
motionManager.accelerometerUpdateInterval = 0.1;
[motionManager startAccelerometerUpdates];
return 0;
}
@ -89,6 +99,45 @@ SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
return SDL_TRUE;
}
static void SDL_SYS_AccelerometerUpdate(SDL_Joystick * joystick)
{
const float maxgforce = SDL_IPHONE_MAX_GFORCE;
const SInt16 maxsint16 = 0x7FFF;
CMAcceleration accel;
if (!motionManager.accelerometerActive) {
return;
}
accel = [[motionManager accelerometerData] acceleration];
/*
Convert accelerometer data from floating point to Sint16, which is what
the joystick system expects.
To do the conversion, the data is first clamped onto the interval
[-SDL_IPHONE_MAX_G_FORCE, SDL_IPHONE_MAX_G_FORCE], then the data is multiplied
by MAX_SINT16 so that it is mapped to the full range of an Sint16.
You can customize the clamped range of this function by modifying the
SDL_IPHONE_MAX_GFORCE macro in SDL_config_iphoneos.h.
Once converted to Sint16, the accelerometer data no longer has coherent
units. You can convert the data back to units of g-force by multiplying
it in your application's code by SDL_IPHONE_MAX_GFORCE / 0x7FFF.
*/
/* clamp the data */
accel.x = SDL_min(SDL_max(accel.x, -maxgforce), maxgforce);
accel.y = SDL_min(SDL_max(accel.y, -maxgforce), maxgforce);
accel.z = SDL_min(SDL_max(accel.z, -maxgforce), maxgforce);
/* pass in data mapped to range of SInt16 */
SDL_PrivateJoystickAxis(joystick, 0, (accel.x / maxgforce) * maxsint16);
SDL_PrivateJoystickAxis(joystick, 1, -(accel.y / maxgforce) * maxsint16);
SDL_PrivateJoystickAxis(joystick, 2, (accel.z / maxgforce) * maxsint16);
}
/* Function to update the state of a joystick - called as a device poll.
* This function shouldn't update the joystick structure directly,
* but instead should call SDL_PrivateJoystick*() to deliver events
@ -97,37 +146,25 @@ SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
{
Sint16 orientation[3];
if ([[SDLUIAccelerationDelegate sharedDelegate] hasNewData]) {
[[SDLUIAccelerationDelegate sharedDelegate] getLastOrientation: orientation];
[[SDLUIAccelerationDelegate sharedDelegate] setHasNewData: NO];
SDL_PrivateJoystickAxis(joystick, 0, orientation[0]);
SDL_PrivateJoystickAxis(joystick, 1, -orientation[1]);
SDL_PrivateJoystickAxis(joystick, 2, orientation[2]);
}
return;
SDL_SYS_AccelerometerUpdate(joystick);
}
/* Function to close a joystick after use */
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
{
if ([[SDLUIAccelerationDelegate sharedDelegate] isRunning]) {
[[SDLUIAccelerationDelegate sharedDelegate] shutdown];
}
SDL_SetError("No joystick open with that index");
[motionManager stopAccelerometerUpdates];
joystick->closed = 1;
}
/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
{
if (motionManager != nil) {
[motionManager release];
motionManager = nil;
}
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )

View file

@ -392,15 +392,6 @@ void SDL_SYS_JoystickDetect()
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
#if SDL_USE_LIBUDEV
return SDL_TRUE;
#endif
return SDL_FALSE;
}
static SDL_joylist_item *
JoystickByDevIndex(int device_index)
{

View file

@ -141,11 +141,6 @@ void SDL_SYS_JoystickDetect()
{
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
}
/* Function to get the device-dependent name of a joystick */
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
{

File diff suppressed because it is too large Load diff

View file

@ -54,6 +54,43 @@
#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
#endif
#ifndef XINPUT_DEVSUBTYPE_UNKNOWN
#define XINPUT_DEVSUBTYPE_UNKNOWN 0x00
#endif
#ifndef XINPUT_DEVSUBTYPE_GAMEPAD
#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01
#endif
#ifndef XINPUT_DEVSUBTYPE_WHEEL
#define XINPUT_DEVSUBTYPE_WHEEL 0x02
#endif
#ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
#endif
#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
#define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
#endif
#ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
#endif
#ifndef XINPUT_DEVSUBTYPE_GUITAR
#define XINPUT_DEVSUBTYPE_GUITAR 0x06
#endif
#ifndef XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE
#define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x07
#endif
#ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
#endif
#ifndef XINPUT_DEVSUBTYPE_GUITAR_BASS
#define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0B
#endif
#ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
#define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
#endif
#ifndef XINPUT_GAMEPAD_GUIDE
#define XINPUT_GAMEPAD_GUIDE 0x0400
#endif
/* typedef's for XInput structs we use */
typedef struct
@ -138,13 +175,12 @@ struct joystick_hwdata
input_t Inputs[MAX_INPUTS];
int NumInputs;
int NumSliders;
Uint8 removed;
Uint8 send_remove_event;
Uint8 bXInputDevice; /* 1 if this device supports using the xinput API rather than DirectInput */
Uint8 bXInputHaptic; /* Supports force feedback via XInput. */
SDL_bool removed;
SDL_bool send_remove_event;
SDL_bool bXInputDevice; /* SDL_TRUE if this device supports using the xinput API rather than DirectInput */
SDL_bool bXInputHaptic; /* Supports force feedback via XInput. */
Uint8 userid; /* XInput userid index for this joystick */
Uint8 currentXInputSlot; /* the current position to write to in XInputState below, used so we can compare old and new values */
XINPUT_STATE_EX XInputState[2];
DWORD dwPacketNumber;
};
#endif /* SDL_JOYSTICK_DINPUT_H */

View file

@ -193,11 +193,6 @@ void SDL_SYS_JoystickDetect()
{
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
return SDL_FALSE;
}
/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)

View file

@ -230,14 +230,6 @@ void SDL_SYS_JoystickDetect()
SDL_UnlockMutex(g_DeviceInfoLock);
}
SDL_bool SDL_SYS_JoystickNeedsPolling()
{
/* Since XInput, or WinRT, provides any events to indicate when a game
controller gets connected, and instead indicates device availability
solely through polling, we'll poll (for new devices).
*/
return SDL_TRUE;
}
/* Internal function to retreive device capabilities.
This function will return an SDL-standard value of 0 on success

118
src/libm/k_tan.c Normal file
View file

@ -0,0 +1,118 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/* __kernel_tan( x, y, k )
* kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input k indicates whether tan (if k=1) or
* -1/tan (if k= -1) is returned.
*
* Algorithm
* 1. Since tan(-x) = -tan(x), we need only to consider positive x.
* 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
* 3. tan(x) is approximated by a odd polynomial of degree 27 on
* [0,0.67434]
* 3 27
* tan(x) ~ x + T1*x + ... + T13*x
* where
*
* |tan(x) 2 4 26 | -59.2
* |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
* | x |
*
* Note: tan(x+y) = tan(x) + tan'(x)*y
* ~ tan(x) + (1+x*x)*y
* Therefore, for better accuracy in computing tan(x+y), let
* 3 2 2 2 2
* r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
* then
* 3 2
* tan(x+y) = x + (T1*x + (x *(r+y)+y))
*
* 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
* tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
* = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
*/
#include "math_libm.h"
#include "math_private.h"
static const double
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
T[] = {
3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
-1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
};
double __kernel_tan(double x, double y, int iy)
{
double z,r,v,w,s;
int32_t ix,hx;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x3e300000) /* x < 2**-28 */
{if((int)x==0) { /* generate inexact */
u_int32_t low;
GET_LOW_WORD(low,x);
if(((ix|low)|(iy+1))==0) return one/fabs(x);
else return (iy==1)? x: -one/x;
}
}
if(ix>=0x3FE59428) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
/* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3FE59428) {
v = (double)iy;
return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
/* compute -1.0/(x+r) accurately */
double a,t;
z = w;
SET_LOW_WORD(z,0);
v = r-(z - x); /* z+v = r+x */
t = a = -1.0/w; /* a = -1.0/w */
SET_LOW_WORD(t,0);
s = 1.0+t*z;
return t+a*(s+t*v);
}
}

View file

@ -33,5 +33,6 @@ double SDL_uclibc_pow(double x, double y);
double SDL_uclibc_scalbn(double x, int n);
double SDL_uclibc_sin(double x);
double SDL_uclibc_sqrt(double x);
double SDL_uclibc_tan(double x);
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -40,6 +40,7 @@ typedef unsigned int u_int32_t;
#define scalbn SDL_uclibc_scalbn
#define sin SDL_uclibc_sin
#define __ieee754_sqrt SDL_uclibc_sqrt
#define tan SDL_uclibc_tan
/* The original fdlibm code used statements like:
n0 = ((*(int*)&one)>>29)^1; * index of high word *

67
src/libm/s_tan.c Normal file
View file

@ -0,0 +1,67 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/* tan(x)
* Return tangent function of x.
*
* kernel function:
* __kernel_tan ... tangent function on [-pi/4,pi/4]
* __ieee754_rem_pio2 ... argument reduction routine
*
* Method.
* Let S,C and T denote the sin, cos and tan respectively on
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
* in [-pi/4 , +pi/4], and let n = k mod 4.
* We have
*
* n sin(x) cos(x) tan(x)
* ----------------------------------------------------------
* 0 S C T
* 1 C -S -1/T
* 2 -S -C T
* 3 -C S -1/T
* ----------------------------------------------------------
*
* Special cases:
* Let trig be any of sin, cos, or tan.
* trig(+-INF) is NaN, with signals;
* trig(NaN) is that NaN;
*
* Accuracy:
* TRIG(x) returns trig(x) nearly rounded
*/
#include "math_libm.h"
#include "math_private.h"
double tan(double x)
{
double y[2],z=0.0;
int32_t n, ix;
/* High word of x. */
GET_HIGH_WORD(ix,x);
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
/* tan(Inf or NaN) is NaN */
else if (ix>=0x7ff00000) return x-x; /* NaN */
/* argument reduction needed */
else {
n = __ieee754_rem_pio2(x,y);
return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
-1 -- n odd */
}
}
libm_hidden_def(tan)

View file

@ -0,0 +1,93 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
/* Include the SDL main definition header */
#include "SDL_main.h"
#include "ppapi_simple/ps_main.h"
#include "ppapi_simple/ps_event.h"
#include "ppapi_simple/ps_interface.h"
#include "nacl_io/nacl_io.h"
#include "sys/mount.h"
extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
int
nacl_main(int argc, char *argv[])
{
int status;
PSEvent* ps_event;
PP_Resource event;
struct PP_Rect rect;
int ready = 0;
const PPB_View *ppb_view = PSInterfaceView();
/* This is started in a worker thread by ppapi_simple! */
/* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
while (!ready) {
/* Process all waiting events without blocking */
while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
event = ps_event->as_resource;
switch(ps_event->type) {
/* From DidChangeView, contains a view resource */
case PSE_INSTANCE_DIDCHANGEVIEW:
ppb_view->GetRect(event, &rect);
NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
ready = 1;
break;
default:
break;
}
PSEventRelease(ps_event);
}
}
/* Do a default httpfs mount on /,
* apps can override this by unmounting /
* and remounting with the desired configuration
*/
nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
umount("/");
mount(
"", /* source */
"/", /* target */
"httpfs", /* filesystemtype */
0, /* mountflags */
""); /* data specific to the html5fs type */
/* Everything is ready, start the user main function */
SDL_SetMainReady();
status = SDL_main(argc, argv);
return 0;
}
/* ppapi_simple will start nacl_main in a worker thread */
PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);
#endif /* SDL_VIDEO_DRIVER_NACL */

View file

@ -93,7 +93,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
{
const int total = sizeof(implementations) / sizeof(implementations[0]);
int _seconds, _percent;
SDL_PowerState retval;
SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
int i;
/* Make these never NULL for platform-specific implementations. */
@ -106,7 +106,7 @@ SDL_GetPowerInfo(int *seconds, int *percent)
}
for (i = 0; i < total; i++) {
if (implementations[i] (&retval, seconds, percent)) {
if (implementations[i](&retval, seconds, percent)) {
return retval;
}
}

View file

@ -124,6 +124,7 @@ static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
static void D3D_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
@ -189,13 +190,20 @@ typedef struct
typedef struct
{
SDL_bool dirty;
IDirect3DTexture9 *texture;
IDirect3DTexture9 *staging;
} D3D_TextureRep;
typedef struct
{
D3D_TextureRep texture;
D3DTEXTUREFILTERTYPE scaleMode;
/* YV12 texture support */
SDL_bool yuv;
IDirect3DTexture9 *utexture;
IDirect3DTexture9 *vtexture;
D3D_TextureRep utexture;
D3D_TextureRep vtexture;
Uint8 *pixels;
int pitch;
SDL_Rect locked_rect;
@ -408,6 +416,8 @@ D3D_Reset(SDL_Renderer * renderer)
for (texture = renderer->textures; texture; texture = texture->next) {
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
D3D_DestroyTexture(renderer, texture);
} else {
D3D_RecreateTexture(renderer, texture);
}
}
@ -452,15 +462,21 @@ D3D_ActivateRenderer(SDL_Renderer * renderer)
if (data->updateSize) {
SDL_Window *window = renderer->window;
int w, h;
Uint32 window_flags = SDL_GetWindowFlags(window);
SDL_GetWindowSize(window, &w, &h);
data->pparams.BackBufferWidth = w;
data->pparams.BackBufferHeight = h;
if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
data->pparams.BackBufferFormat =
PixelFormatToD3DFMT(SDL_GetWindowPixelFormat(window));
if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
SDL_DisplayMode fullscreen_mode;
SDL_GetWindowDisplayMode(window, &fullscreen_mode);
data->pparams.Windowed = FALSE;
data->pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format);
data->pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
} else {
data->pparams.Windowed = TRUE;
data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
data->pparams.FullScreen_RefreshRateInHz = 0;
}
if (D3D_Reset(renderer) < 0) {
return -1;
@ -555,25 +571,16 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
pparams.hDeviceWindow = windowinfo.info.win.window;
pparams.BackBufferWidth = w;
pparams.BackBufferHeight = h;
if (window_flags & SDL_WINDOW_FULLSCREEN) {
pparams.BackBufferFormat =
PixelFormatToD3DFMT(fullscreen_mode.format);
} else {
pparams.BackBufferFormat = D3DFMT_UNKNOWN;
}
pparams.BackBufferCount = 1;
pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
if (window_flags & SDL_WINDOW_FULLSCREEN) {
if ((window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
pparams.Windowed = TRUE;
pparams.FullScreen_RefreshRateInHz = 0;
} else {
pparams.Windowed = FALSE;
pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
}
if (window_flags & SDL_WINDOW_FULLSCREEN && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
pparams.Windowed = FALSE;
pparams.BackBufferFormat = PixelFormatToD3DFMT(fullscreen_mode.format);
pparams.FullScreen_RefreshRateInHz = fullscreen_mode.refresh_rate;
} else {
pparams.Windowed = TRUE;
pparams.BackBufferFormat = D3DFMT_UNKNOWN;
pparams.FullScreen_RefreshRateInHz = 0;
}
if (flags & SDL_RENDERER_PRESENTVSYNC) {
@ -643,7 +650,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
}
/* Store the default render target */
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
data->currentRenderTarget = NULL;
/* Set up parameters for rendering */
@ -805,74 +812,77 @@ GetScaleQuality(void)
}
static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, int w, int h)
{
D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
D3D_TextureData *data;
D3DPOOL pool;
DWORD usage;
HRESULT result;
data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
if (!data) {
return SDL_OutOfMemory();
}
data->scaleMode = GetScaleQuality();
texture->dirty = SDL_FALSE;
texture->driverdata = data;
#ifdef USE_DYNAMIC_TEXTURE
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
pool = D3DPOOL_DEFAULT;
usage = D3DUSAGE_DYNAMIC;
} else
#endif
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
/* D3DPOOL_MANAGED does not work with D3DUSAGE_RENDERTARGET */
pool = D3DPOOL_DEFAULT;
usage = D3DUSAGE_RENDERTARGET;
} else {
pool = D3DPOOL_MANAGED;
usage = 0;
}
result =
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
texture->h, 1, usage,
PixelFormatToD3DFMT(texture->format),
pool, &data->texture, NULL);
result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
PixelFormatToD3DFMT(format),
D3DPOOL_DEFAULT, &texture->texture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture()", result);
return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
}
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
data->yuv = SDL_TRUE;
result =
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w / 2,
texture->h / 2, 1, usage,
PixelFormatToD3DFMT(texture->format),
pool, &data->utexture, NULL);
if (usage != D3DUSAGE_RENDERTARGET) {
result = IDirect3DDevice9_CreateTexture(device, w, h, 1, usage,
PixelFormatToD3DFMT(format),
D3DPOOL_SYSTEMMEM, &texture->staging, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture()", result);
}
result =
IDirect3DDevice9_CreateTexture(renderdata->device, texture->w / 2,
texture->h / 2, 1, usage,
PixelFormatToD3DFMT(texture->format),
pool, &data->vtexture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture()", result);
return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result);
}
}
return 0;
}
static int
D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool full_texture, int x, int y, int w, int h, const void *pixels, int pitch)
D3D_BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler)
{
HRESULT result;
if (texture->dirty && texture->staging) {
if (!texture->texture) {
D3DSURFACE_DESC desc;
result = IDirect3DTexture9_GetLevelDesc(texture->staging, 0, &desc);
if (FAILED(result)) {
return D3D_SetError("GetLevelDesc", result);
}
result = IDirect3DDevice9_CreateTexture(device, desc.Width, desc.Height, 1, 0,
desc.Format, D3DPOOL_DEFAULT, &texture->texture, NULL);
if (FAILED(result)) {
return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result);
}
}
result = IDirect3DDevice9_UpdateTexture(device, (IDirect3DBaseTexture9 *)texture->staging, (IDirect3DBaseTexture9 *)texture->texture);
if (FAILED(result)) {
return D3D_SetError("UpdateTexture()", result);
}
texture->dirty = SDL_FALSE;
}
result = IDirect3DDevice9_SetTexture(device, sampler, (IDirect3DBaseTexture9 *)texture->texture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
}
return 0;
}
static int
D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int w, int h)
{
if (texture->texture) {
IDirect3DTexture9_Release(texture->texture);
texture->texture = NULL;
}
IDirect3DTexture9_AddDirtyRect(texture->staging, NULL);
texture->dirty = SDL_TRUE;
return 0;
}
static int
D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, Uint32 format, int x, int y, int w, int h, const void *pixels, int pitch)
{
RECT d3drect;
D3DLOCKED_RECT locked;
@ -881,16 +891,11 @@ D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool fu
int row, length;
HRESULT result;
if (full_texture) {
result = IDirect3DTexture9_LockRect(texture, 0, &locked, NULL, D3DLOCK_DISCARD);
} else {
d3drect.left = x;
d3drect.right = x + w;
d3drect.top = y;
d3drect.bottom = y + h;
result = IDirect3DTexture9_LockRect(texture, 0, &locked, &d3drect, 0);
}
d3drect.left = x;
d3drect.right = x + w;
d3drect.top = y;
d3drect.bottom = y + h;
result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
if (FAILED(result)) {
return D3D_SetError("LockRect()", result);
}
@ -913,46 +918,117 @@ D3D_UpdateTextureInternal(IDirect3DTexture9 *texture, Uint32 format, SDL_bool fu
dst += locked.Pitch;
}
}
IDirect3DTexture9_UnlockRect(texture, 0);
result = IDirect3DTexture9_UnlockRect(texture->staging, 0);
if (FAILED(result)) {
return D3D_SetError("UnlockRect()", result);
}
texture->dirty = SDL_TRUE;
return 0;
}
static void
D3D_DestroyTextureRep(D3D_TextureRep *texture)
{
if (texture->texture) {
IDirect3DTexture9_Release(texture->texture);
texture->texture = NULL;
}
if (texture->staging) {
IDirect3DTexture9_Release(texture->staging);
texture->staging = NULL;
}
}
static int
D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
D3D_TextureData *texturedata;
DWORD usage;
texturedata = (D3D_TextureData *) SDL_calloc(1, sizeof(*texturedata));
if (!texturedata) {
return SDL_OutOfMemory();
}
texturedata->scaleMode = GetScaleQuality();
texture->driverdata = texturedata;
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
usage = D3DUSAGE_RENDERTARGET;
} else {
usage = 0;
}
if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, texture->w, texture->h) < 0) {
return -1;
}
if (texture->format == SDL_PIXELFORMAT_YV12 ||
texture->format == SDL_PIXELFORMAT_IYUV) {
texturedata->yuv = SDL_TRUE;
if (D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
if (D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
}
return 0;
}
static int
D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (D3D_RecreateTextureRep(data->device, &texturedata->texture, texture->format, texture->w, texture->h) < 0) {
return -1;
}
if (texturedata->yuv) {
if (D3D_RecreateTextureRep(data->device, &texturedata->utexture, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
if (D3D_RecreateTextureRep(data->device, &texturedata->vtexture, texture->format, texture->w / 2, texture->h / 2) < 0) {
return -1;
}
}
return 0;
}
static int
D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
SDL_bool full_texture = SDL_FALSE;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
#ifdef USE_DYNAMIC_TEXTURE
if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
rect->x == 0 && rect->y == 0 &&
rect->w == texture->w && rect->h == texture->h) {
full_texture = SDL_TRUE;
}
#endif
if (!data) {
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
}
if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, texture->format, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
return -1;
}
if (data->yuv) {
if (texturedata->yuv) {
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
if (D3D_UpdateTextureInternal(texture->format == SDL_PIXELFORMAT_YV12 ? data->vtexture : data->utexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) {
if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) {
return -1;
}
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4);
if (D3D_UpdateTextureInternal(texture->format == SDL_PIXELFORMAT_YV12 ? data->utexture : data->vtexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) {
if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, pixels, pitch / 2) < 0) {
return -1;
}
}
@ -966,29 +1042,21 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
SDL_bool full_texture = SDL_FALSE;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
#ifdef USE_DYNAMIC_TEXTURE
if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
rect->x == 0 && rect->y == 0 &&
rect->w == texture->w && rect->h == texture->h) {
full_texture = SDL_TRUE;
}
#endif
if (!data) {
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
}
if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, texture->format, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
return -1;
}
if (D3D_UpdateTextureInternal(data->utexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
if (D3D_UpdateTextureRep(data->device, &texturedata->utexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
return -1;
}
if (D3D_UpdateTextureInternal(data->vtexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
if (D3D_UpdateTextureRep(data->device, &texturedata->vtexture, texture->format, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
return -1;
}
return 0;
@ -998,37 +1066,39 @@ static int
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
{
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
RECT d3drect;
D3DLOCKED_RECT locked;
HRESULT result;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (!data) {
if (!texturedata) {
SDL_SetError("Texture is not currently available");
return -1;
}
if (data->yuv) {
texturedata->locked_rect = *rect;
if (texturedata->yuv) {
/* It's more efficient to upload directly... */
if (!data->pixels) {
data->pitch = texture->w;
data->pixels = (Uint8 *)SDL_malloc((texture->h * data->pitch * 3) / 2);
if (!data->pixels) {
if (!texturedata->pixels) {
texturedata->pitch = texture->w;
texturedata->pixels = (Uint8 *)SDL_malloc((texture->h * texturedata->pitch * 3) / 2);
if (!texturedata->pixels) {
return SDL_OutOfMemory();
}
}
data->locked_rect = *rect;
*pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
(void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch;
*pitch = texturedata->pitch;
} else {
RECT d3drect;
D3DLOCKED_RECT locked;
HRESULT result;
d3drect.left = rect->x;
d3drect.right = rect->x + rect->w;
d3drect.top = rect->y;
d3drect.bottom = rect->y + rect->h;
result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
if (FAILED(result)) {
return D3D_SetError("LockRect()", result);
}
@ -1041,21 +1111,23 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
static void
D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
D3D_RenderData *data = (D3D_RenderData *)renderer->driverdata;
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
if (!data) {
if (!texturedata) {
return;
}
if (data->yuv) {
const SDL_Rect *rect = &data->locked_rect;
if (texturedata->yuv) {
const SDL_Rect *rect = &texturedata->locked_rect;
void *pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
(void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
D3D_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
} else {
IDirect3DTexture9_UnlockRect(data->texture, 0);
}
IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
texturedata->texture.dirty = SDL_TRUE;
}
}
static int
@ -1082,7 +1154,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
return -1;
}
result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture, 0, &data->currentRenderTarget);
result = IDirect3DTexture9_GetSurfaceLevel(texturedata->texture.texture, 0, &data->currentRenderTarget);
if(FAILED(result)) {
return D3D_SetError("GetSurfaceLevel()", result);
}
@ -1528,11 +1600,8 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
D3D_UpdateTextureScaleMode(data, texturedata, 0);
result =
IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
texturedata->texture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
if (D3D_BindTextureRep(data->device, &texturedata->texture, 0) < 0) {
return -1;
}
if (texturedata->yuv) {
@ -1541,18 +1610,11 @@ D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
D3D_UpdateTextureScaleMode(data, texturedata, 1);
D3D_UpdateTextureScaleMode(data, texturedata, 2);
result =
IDirect3DDevice9_SetTexture(data->device, 1, (IDirect3DBaseTexture9 *)
texturedata->utexture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
if (D3D_BindTextureRep(data->device, &texturedata->utexture, 1) < 0) {
return -1;
}
result =
IDirect3DDevice9_SetTexture(data->device, 2, (IDirect3DBaseTexture9 *)
texturedata->vtexture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
if (D3D_BindTextureRep(data->device, &texturedata->vtexture, 2) < 0) {
return -1;
}
}
@ -1666,16 +1728,13 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
modelMatrix = MatrixMultiply(
MatrixRotationZ((float)(M_PI * (float) angle / 180.0f)),
MatrixTranslation(dstrect->x + center->x, dstrect->y + center->y, 0)
);
);
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&modelMatrix);
D3D_UpdateTextureScaleMode(data, texturedata, 0);
result =
IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
texturedata->texture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
if (D3D_BindTextureRep(data->device, &texturedata->texture, 0) < 0) {
return -1;
}
if (texturedata->yuv) {
@ -1683,19 +1742,12 @@ D3D_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
D3D_UpdateTextureScaleMode(data, texturedata, 1);
D3D_UpdateTextureScaleMode(data, texturedata, 2);
result =
IDirect3DDevice9_SetTexture(data->device, 1, (IDirect3DBaseTexture9 *)
texturedata->utexture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
if (D3D_BindTextureRep(data->device, &texturedata->utexture, 1) < 0) {
return -1;
}
result =
IDirect3DDevice9_SetTexture(data->device, 2, (IDirect3DBaseTexture9 *)
texturedata->vtexture);
if (FAILED(result)) {
return D3D_SetError("SetTexture()", result);
if (D3D_BindTextureRep(data->device, &texturedata->vtexture, 2) < 0) {
return -1;
}
}
@ -1816,15 +1868,9 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (!data) {
return;
}
if (data->texture) {
IDirect3DTexture9_Release(data->texture);
}
if (data->utexture) {
IDirect3DTexture9_Release(data->utexture);
}
if (data->vtexture) {
IDirect3DTexture9_Release(data->vtexture);
}
D3D_DestroyTextureRep(&data->texture);
D3D_DestroyTextureRep(&data->utexture);
D3D_DestroyTextureRep(&data->vtexture);
SDL_free(data->pixels);
SDL_free(data);
texture->driverdata = NULL;

View file

@ -290,7 +290,8 @@ GL_ActivateRenderer(SDL_Renderer * renderer)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
if (SDL_CurrentContext != data->context) {
if (SDL_CurrentContext != data->context ||
SDL_GL_GetCurrentContext() != data->context) {
if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
return -1;
}
@ -310,7 +311,7 @@ GL_ResetState(SDL_Renderer *renderer)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
if (SDL_CurrentContext == data->context) {
if (SDL_GL_GetCurrentContext() == data->context) {
GL_UpdateViewport(renderer);
} else {
GL_ActivateRenderer(renderer);
@ -332,7 +333,7 @@ GL_ResetState(SDL_Renderer *renderer)
}
static void APIENTRY
GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, void *userParam)
GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam)
{
SDL_Renderer *renderer = (SDL_Renderer *) userParam;
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
@ -389,6 +390,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
GLint value;
Uint32 window_flags;
int profile_mask, major, minor;
SDL_bool changed_window = SDL_FALSE;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
@ -397,32 +399,28 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
changed_window = SDL_TRUE;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, window_flags);
return NULL;
goto error;
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
goto error;
}
data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
GL_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
goto error;
}
renderer->WindowEvent = GL_WindowEvent;
@ -455,16 +453,16 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
GL_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
GL_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (GL_LoadFunctions(data) < 0) {
GL_DestroyRenderer(renderer);
return NULL;
goto error;
}
#ifdef __MACOSX__
@ -559,6 +557,16 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
GL_ResetState(renderer);
return renderer;
error:
if (changed_window) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, window_flags);
}
return NULL;
}
static void

View file

@ -285,42 +285,39 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
SDL_Renderer *renderer;
GLES_RenderData *data;
GLint value;
Uint32 windowFlags;
Uint32 window_flags;
int profile_mask, major, minor;
SDL_bool changed_window = SDL_FALSE;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
windowFlags = SDL_GetWindowFlags(window);
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
changed_window = SDL_TRUE;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, windowFlags);
return NULL;
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
goto error;
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
goto error;
}
data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
GLES_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
goto error;
}
renderer->WindowEvent = GLES_WindowEvent;
@ -351,16 +348,16 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
GLES_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
GLES_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (GLES_LoadFunctions(data) < 0) {
GLES_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (flags & SDL_RENDERER_PRESENTVSYNC) {
@ -411,6 +408,16 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
GLES_ResetState(renderer);
return renderer;
error:
if (changed_window) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, window_flags);
}
return NULL;
}
static void

View file

@ -53,7 +53,7 @@ SDL_PROC(void, glPixelStorei, (GLenum, GLint))
SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei))
SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const char **, const GLint *))
SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar* const*, const GLint *))
SDL_PROC(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const void *))
SDL_PROC(void, glTexParameteri, (GLenum, GLenum, GLint))
SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
@ -68,4 +68,4 @@ SDL_PROC(void, glFramebufferTexture2D, (GLenum, GLenum, GLenum, GLuint, GLint))
SDL_PROC(GLenum, glCheckFramebufferStatus, (GLenum))
SDL_PROC(void, glDeleteFramebuffers, (GLsizei, const GLuint *))
SDL_PROC(GLint, glGetAttribLocation, (GLuint, const GLchar *))
SDL_PROC(void, glGetProgramInfoLog, (GLuint, GLsizei, GLsizei*, GLchar*))

View file

@ -49,10 +49,12 @@ SDL_RenderDriver GLES2_RenderDriver = {
"opengles2",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
4,
{SDL_PIXELFORMAT_ABGR8888,
{
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888},
SDL_PIXELFORMAT_BGR888
},
0,
0
}
@ -79,6 +81,10 @@ typedef struct GLES2_TextureData
GLenum pixel_type;
void *pixel_data;
size_t pitch;
/* YV12 texture support */
SDL_bool yuv;
GLenum texture_v;
GLenum texture_u;
GLES2_FBOList *fbo;
} GLES2_TextureData;
@ -133,7 +139,9 @@ typedef enum
GLES2_UNIFORM_PROJECTION,
GLES2_UNIFORM_TEXTURE,
GLES2_UNIFORM_MODULATION,
GLES2_UNIFORM_COLOR
GLES2_UNIFORM_COLOR,
GLES2_UNIFORM_TEXTURE_U,
GLES2_UNIFORM_TEXTURE_V
} GLES2_Uniform;
typedef enum
@ -142,7 +150,8 @@ typedef enum
GLES2_IMAGESOURCE_TEXTURE_ABGR,
GLES2_IMAGESOURCE_TEXTURE_ARGB,
GLES2_IMAGESOURCE_TEXTURE_RGB,
GLES2_IMAGESOURCE_TEXTURE_BGR
GLES2_IMAGESOURCE_TEXTURE_BGR,
GLES2_IMAGESOURCE_TEXTURE_YUV
} GLES2_ImageSource;
typedef struct GLES2_DriverContext
@ -433,6 +442,11 @@ GLES2_DestroyRenderer(SDL_Renderer *renderer)
static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture);
static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
const void *pixels, int pitch);
static int GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
void **pixels, int *pitch);
static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture);
@ -465,13 +479,18 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
/* Determine the corresponding GLES texture format params */
switch (texture->format)
{
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_BGR888:
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_RGB888:
case SDL_PIXELFORMAT_BGR888:
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
break;
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_YV12:
format = GL_LUMINANCE;
type = GL_UNSIGNED_BYTE;
break;
default:
return SDL_SetError("Texture format not supported");
}
@ -485,12 +504,21 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
data->texture_type = GL_TEXTURE_2D;
data->pixel_format = format;
data->pixel_type = type;
data->yuv = ((texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12));
data->texture_u = 0;
data->texture_v = 0;
scaleMode = GetScaleQuality();
/* Allocate a blob for image renderdata */
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
size_t size;
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
data->pixel_data = SDL_calloc(1, data->pitch * texture->h);
size = texture->h * data->pitch;
if (data->yuv) {
/* Need to add size for the U and V planes */
size += (2 * (texture->h * data->pitch) / 4);
}
data->pixel_data = SDL_calloc(1, size);
if (!data->pixel_data) {
SDL_free(data);
return SDL_OutOfMemory();
@ -499,11 +527,42 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
/* Allocate the texture */
GL_CheckError("", renderer);
if (data->yuv) {
renderdata->glGenTextures(1, &data->texture_v);
if (GL_CheckError("glGenTexures()", renderer) < 0) {
return -1;
}
renderdata->glActiveTexture(GL_TEXTURE2);
renderdata->glBindTexture(data->texture_type, data->texture_v);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
renderdata->glTexImage2D(data->texture_type, 0, format, texture->w / 2, texture->h / 2, 0, format, type, NULL);
renderdata->glGenTextures(1, &data->texture_u);
if (GL_CheckError("glGenTexures()", renderer) < 0) {
return -1;
}
renderdata->glActiveTexture(GL_TEXTURE1);
renderdata->glBindTexture(data->texture_type, data->texture_u);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
renderdata->glTexImage2D(data->texture_type, 0, format, texture->w / 2, texture->h / 2, 0, format, type, NULL);
if (GL_CheckError("glTexImage2D()", renderer) < 0) {
return -1;
}
}
renderdata->glGenTextures(1, &data->texture);
if (GL_CheckError("glGenTexures()", renderer) < 0) {
return -1;
}
texture->driverdata = data;
renderdata->glActiveTexture(GL_TEXTURE0);
renderdata->glBindTexture(data->texture_type, data->texture);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode);
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode);
@ -523,16 +582,45 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
return GL_CheckError("", renderer);
}
static int
GLES2_TexSubImage2D(GLES2_DriverContext *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp)
{
Uint8 *blob = NULL;
Uint8 *src;
int src_pitch;
int y;
/* Reformat the texture data into a tightly packed array */
src_pitch = width * bpp;
src = (Uint8 *)pixels;
if (pitch != src_pitch) {
blob = (Uint8 *)SDL_malloc(src_pitch * height);
if (!blob) {
return SDL_OutOfMemory();
}
src = blob;
for (y = 0; y < height; ++y)
{
SDL_memcpy(src, pixels, src_pitch);
src += src_pitch;
pixels = (Uint8 *)pixels + pitch;
}
src = blob;
}
data->glTexSubImage2D(target, 0, xoffset, yoffset, width, height, format, type, src);
if (blob) {
SDL_free(blob);
}
return 0;
}
static int
GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
const void *pixels, int pitch)
{
GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
Uint8 *blob = NULL;
Uint8 *src;
int srcPitch;
int y;
GLES2_ActivateRenderer(renderer);
@ -540,36 +628,99 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
if (rect->w <= 0 || rect->h <= 0)
return 0;
/* Reformat the texture data into a tightly packed array */
srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
src = (Uint8 *)pixels;
if (pitch != srcPitch) {
blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
if (!blob) {
return SDL_OutOfMemory();
}
src = blob;
for (y = 0; y < rect->h; ++y)
{
SDL_memcpy(src, pixels, srcPitch);
src += srcPitch;
pixels = (Uint8 *)pixels + pitch;
}
src = blob;
}
/* Create a texture subimage with the supplied data */
data->glBindTexture(tdata->texture_type, tdata->texture);
data->glTexSubImage2D(tdata->texture_type,
0,
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w,
rect->h,
tdata->pixel_format,
tdata->pixel_type,
src);
SDL_free(blob);
pixels, pitch, SDL_BYTESPERPIXEL(texture->format));
if (tdata->yuv) {
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
if (texture->format == SDL_PIXELFORMAT_YV12) {
data->glBindTexture(tdata->texture_type, tdata->texture_v);
} else {
data->glBindTexture(tdata->texture_type, tdata->texture_u);
}
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x / 2,
rect->y / 2,
rect->w / 2,
rect->h / 2,
tdata->pixel_format,
tdata->pixel_type,
pixels, pitch / 2, 1);
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)pixels + (rect->h * pitch)/4);
if (texture->format == SDL_PIXELFORMAT_YV12) {
data->glBindTexture(tdata->texture_type, tdata->texture_u);
} else {
data->glBindTexture(tdata->texture_type, tdata->texture_v);
}
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x / 2,
rect->y / 2,
rect->w / 2,
rect->h / 2,
tdata->pixel_format,
tdata->pixel_type,
pixels, pitch / 2, 1);
}
return GL_CheckError("glTexSubImage2D()", renderer);
}
static int
GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata;
GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
GLES2_ActivateRenderer(renderer);
/* Bail out if we're supposed to update an empty rectangle */
if (rect->w <= 0 || rect->h <= 0)
return 0;
data->glBindTexture(tdata->texture_type, tdata->texture_v);
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w / 2,
rect->h / 2,
tdata->pixel_format,
tdata->pixel_type,
Vplane, Vpitch, 1);
data->glBindTexture(tdata->texture_type, tdata->texture_u);
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w / 2,
rect->h / 2,
tdata->pixel_format,
tdata->pixel_type,
Uplane, Upitch, 1);
data->glBindTexture(tdata->texture_type, tdata->texture);
GLES2_TexSubImage2D(data, tdata->texture_type,
rect->x,
rect->y,
rect->w,
rect->h,
tdata->pixel_format,
tdata->pixel_type,
Yplane, Ypitch, 1);
return GL_CheckError("glTexSubImage2D()", renderer);
}
@ -638,6 +789,12 @@ GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
if (tdata)
{
data->glDeleteTextures(1, &tdata->texture);
if (tdata->texture_v) {
data->glDeleteTextures(1, &tdata->texture_v);
}
if (tdata->texture_u) {
data->glDeleteTextures(1, &tdata->texture_u);
}
SDL_free(tdata->pixel_data);
SDL_free(tdata);
texture->driverdata = NULL;
@ -723,6 +880,10 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
/* Predetermine locations of uniform variables */
entry->uniform_locations[GLES2_UNIFORM_PROJECTION] =
data->glGetUniformLocation(entry->id, "u_projection");
entry->uniform_locations[GLES2_UNIFORM_TEXTURE_V] =
data->glGetUniformLocation(entry->id, "u_texture_v");
entry->uniform_locations[GLES2_UNIFORM_TEXTURE_U] =
data->glGetUniformLocation(entry->id, "u_texture_u");
entry->uniform_locations[GLES2_UNIFORM_TEXTURE] =
data->glGetUniformLocation(entry->id, "u_texture");
entry->uniform_locations[GLES2_UNIFORM_MODULATION] =
@ -734,8 +895,10 @@ GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
entry->color_r = entry->color_g = entry->color_b = entry->color_a = 255;
data->glUseProgram(entry->id);
data->glUniformMatrix4fv(entry->uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (GLfloat *)entry->projection);
data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE_V], 2); /* always texture unit 2. */
data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE_U], 1); /* always texture unit 1. */
data->glUniform1i(entry->uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
data->glUniformMatrix4fv(entry->uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (GLfloat *)entry->projection);
data->glUniform4f(entry->uniform_locations[GLES2_UNIFORM_MODULATION], 1.0f, 1.0f, 1.0f, 1.0f);
data->glUniform4f(entry->uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f);
@ -927,6 +1090,9 @@ GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendM
case GLES2_IMAGESOURCE_TEXTURE_BGR:
ftype = GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC;
break;
case GLES2_IMAGESOURCE_TEXTURE_YUV:
ftype = GLES2_SHADER_FRAGMENT_TEXTURE_YUV_SRC;
break;
default:
goto fault;
}
@ -1287,6 +1453,18 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
if (renderer->target->format != texture->format) {
switch (texture->format)
{
case SDL_PIXELFORMAT_ARGB8888:
switch (renderer->target->format)
{
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
}
break;
case SDL_PIXELFORMAT_ABGR8888:
switch (renderer->target->format)
{
@ -1299,15 +1477,17 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
break;
}
break;
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_RGB888:
switch (renderer->target->format)
{
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
}
break;
@ -1325,20 +1505,6 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
break;
}
break;
case SDL_PIXELFORMAT_RGB888:
switch (renderer->target->format)
{
case SDL_PIXELFORMAT_ABGR8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
}
break;
}
}
else sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; /* Texture formats match, use the non color mapping shader (even if the formats are not ABGR) */
@ -1346,17 +1512,22 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
else {
switch (texture->format)
{
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_ABGR8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
break;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
// TODO: new shader to change yv planes YV12 format
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_YV12:
sourceType = GLES2_IMAGESOURCE_TEXTURE_YUV;
break;
default:
return -1;
@ -1368,6 +1539,15 @@ GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *s
}
/* Select the target texture */
if (tdata->yuv) {
data->glActiveTexture(GL_TEXTURE2);
data->glBindTexture(tdata->texture_type, tdata->texture_v);
data->glActiveTexture(GL_TEXTURE1);
data->glBindTexture(tdata->texture_type, tdata->texture_u);
data->glActiveTexture(GL_TEXTURE0);
}
data->glBindTexture(tdata->texture_type, tdata->texture);
/* Configure color modulation */
@ -1455,6 +1635,18 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
if (renderer->target->format != texture->format) {
switch (texture->format)
{
case SDL_PIXELFORMAT_ARGB8888:
switch (renderer->target->format)
{
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
}
break;
case SDL_PIXELFORMAT_ABGR8888:
switch (renderer->target->format)
{
@ -1467,15 +1659,17 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
break;
}
break;
case SDL_PIXELFORMAT_ARGB8888:
case SDL_PIXELFORMAT_RGB888:
switch (renderer->target->format)
{
case SDL_PIXELFORMAT_ABGR8888:
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
}
break;
@ -1493,20 +1687,6 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
break;
}
break;
case SDL_PIXELFORMAT_RGB888:
switch (renderer->target->format)
{
case SDL_PIXELFORMAT_ABGR8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
}
break;
}
}
else sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; /* Texture formats match, use the non color mapping shader (even if the formats are not ABGR) */
@ -1514,18 +1694,18 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
else {
switch (texture->format)
{
case SDL_PIXELFORMAT_ABGR8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
case SDL_PIXELFORMAT_ARGB8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ARGB;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
case SDL_PIXELFORMAT_ABGR8888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR;
break;
case SDL_PIXELFORMAT_RGB888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_RGB;
break;
case SDL_PIXELFORMAT_BGR888:
sourceType = GLES2_IMAGESOURCE_TEXTURE_BGR;
break;
default:
return -1;
}
@ -1743,30 +1923,27 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
#ifndef ZUNE_HD
GLboolean hasCompiler;
#endif
Uint32 windowFlags;
Uint32 window_flags;
GLint window_framebuffer;
GLint value;
int profile_mask, major, minor;
SDL_bool changed_window = SDL_FALSE;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
windowFlags = SDL_GetWindowFlags(window);
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL) ||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
changed_window = SDL_TRUE;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, windowFlags);
return NULL;
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
goto error;
}
}
@ -1774,14 +1951,14 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
goto error;
}
data = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext));
if (!data) {
GLES2_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
goto error;
}
renderer->info = GLES2_RenderDriver.info;
renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
@ -1790,19 +1967,18 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
/* Create an OpenGL ES 2.0 context */
data->context = SDL_GL_CreateContext(window);
if (!data->context)
{
if (!data->context) {
GLES2_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
GLES2_DestroyRenderer(renderer);
return NULL;
goto error;
}
if (GLES2_LoadFunctions(data) < 0) {
GLES2_DestroyRenderer(renderer);
return NULL;
goto error;
}
#if __WINRT__
@ -1850,7 +2026,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
{
GLES2_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
goto error;
}
data->shader_format_count = nFormats;
#ifdef ZUNE_HD
@ -1869,6 +2045,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->WindowEvent = &GLES2_WindowEvent;
renderer->CreateTexture = &GLES2_CreateTexture;
renderer->UpdateTexture = &GLES2_UpdateTexture;
renderer->UpdateTextureYUV = &GLES2_UpdateTextureYUV;
renderer->LockTexture = &GLES2_LockTexture;
renderer->UnlockTexture = &GLES2_UnlockTexture;
renderer->SetRenderTarget = &GLES2_SetRenderTarget;
@ -1887,9 +2064,22 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
renderer->GL_BindTexture = &GLES2_BindTexture;
renderer->GL_UnbindTexture = &GLES2_UnbindTexture;
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_YV12;
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
GLES2_ResetState(renderer);
return renderer;
error:
if (changed_window) {
/* Uh oh, better try to put it back... */
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
SDL_RecreateWindow(window, window_flags);
}
return NULL;
}
#endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */

View file

@ -126,6 +126,30 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
} \
";
/* YUV to ABGR conversion */
static const Uint8 GLES2_FragmentSrc_TextureYUVSrc_[] = " \
precision mediump float; \
uniform sampler2D u_texture; \
uniform sampler2D u_texture_u; \
uniform sampler2D u_texture_v; \
uniform vec4 u_modulation; \
varying vec2 v_texCoord; \
\
void main() \
{ \
mediump vec3 yuv; \
lowp vec3 rgb; \
yuv.x = texture2D(u_texture, v_texCoord).r; \
yuv.y = texture2D(u_texture_u, v_texCoord).r - 0.5; \
yuv.z = texture2D(u_texture_v, v_texCoord).r - 0.5; \
rgb = mat3( 1, 1, 1, \
0, -0.39465, 2.03211, \
1.13983, -0.58060, 0) * yuv; \
gl_FragColor = vec4(rgb, 1); \
gl_FragColor *= u_modulation; \
} \
";
static const GLES2_ShaderInstance GLES2_VertexSrc_Default = {
GL_VERTEX_SHADER,
GLES2_SOURCE_SHADER,
@ -168,6 +192,14 @@ static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureBGRSrc = {
GLES2_FragmentSrc_TextureBGRSrc_
};
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVSrc = {
GL_FRAGMENT_SHADER,
GLES2_SOURCE_SHADER,
sizeof(GLES2_FragmentSrc_TextureYUVSrc_),
GLES2_FragmentSrc_TextureYUVSrc_
};
/*************************************************************************************************
* Vertex/fragment shader binaries (NVIDIA Tegra 1/2) *
*************************************************************************************************/
@ -692,6 +724,14 @@ static GLES2_Shader GLES2_FragmentShader_Modulated_TextureBGRSrc = {
}
};
static GLES2_Shader GLES2_FragmentShader_TextureYUVSrc = {
1,
{
&GLES2_FragmentSrc_TextureYUVSrc
}
};
/*************************************************************************************************
* Shader selector *
*************************************************************************************************/
@ -774,6 +814,11 @@ const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMo
default:
return NULL;
}
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_SRC:
{
return &GLES2_FragmentShader_TextureYUVSrc;
}
default:
return NULL;

View file

@ -46,7 +46,8 @@ typedef enum
GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC,
GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC,
GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC,
GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC
GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC,
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_SRC
} GLES2_ShaderType;
#define GLES2_SOURCE_SHADER (GLenum)-1

View file

@ -82,14 +82,14 @@ SDL_RenderDriver SW_RenderDriver = {
SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE,
8,
{
SDL_PIXELFORMAT_RGB555,
SDL_PIXELFORMAT_RGB565,
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_RGB888,
SDL_PIXELFORMAT_BGR888,
SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888
SDL_PIXELFORMAT_RGB565,
SDL_PIXELFORMAT_RGB555
},
0,
0}

View file

@ -32,7 +32,8 @@
If we get this wrong, it's just a warning, so no big deal.
*/
#if defined(_XGP6) || defined(__APPLE__) || \
(defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)))
(defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \
(defined(_NEWLIB_VERSION)))
#define ICONV_INBUF_NONCONST
#endif

View file

@ -211,6 +211,36 @@ SDL_sqrt(double x)
#endif
}
float
SDL_sqrtf(float x)
{
#if defined(HAVE_SQRTF)
return sqrtf(x);
#else
return (float)SDL_sqrt((double)x);
#endif
}
double
SDL_tan(double x)
{
#if defined(HAVE_TAN)
return tan(x);
#else
return SDL_uclibc_tan(x);
#endif
}
float
SDL_tanf(float x)
{
#if defined(HAVE_TANF)
return tanf(x);
#else
return (float)SDL_tan((double)x);
#endif
}
int SDL_abs(int x)
{
#ifdef HAVE_ABS

View file

@ -258,7 +258,7 @@ SDL_ScanFloat(const char *text, double *valuep)
#endif
void *
SDL_memset(void *dst, int c, size_t len)
SDL_memset(SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
{
#if defined(HAVE_MEMSET)
return memset(dst, c, len);
@ -302,7 +302,7 @@ SDL_memset(void *dst, int c, size_t len)
}
void *
SDL_memcpy(void *dst, const void *src, size_t len)
SDL_memcpy(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{
#ifdef __GNUC__
/* Presumably this is well tuned for speed.
@ -355,7 +355,7 @@ SDL_memcpy(void *dst, const void *src, size_t len)
}
void *
SDL_memmove(void *dst, const void *src, size_t len)
SDL_memmove(SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
{
#if defined(HAVE_MEMMOVE)
return memmove(dst, src, len);
@ -426,7 +426,7 @@ SDL_wcslen(const wchar_t * string)
}
size_t
SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
SDL_wcslcpy(SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
{
#if defined(HAVE_WCSLCPY)
return wcslcpy(dst, src, maxlen);
@ -442,7 +442,7 @@ SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen)
}
size_t
SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
SDL_wcslcat(SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
{
#if defined(HAVE_WCSLCAT)
return wcslcat(dst, src, maxlen);
@ -457,7 +457,7 @@ SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen)
}
size_t
SDL_strlcpy(char *dst, const char *src, size_t maxlen)
SDL_strlcpy(SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
#if defined(HAVE_STRLCPY)
return strlcpy(dst, src, maxlen);
@ -472,7 +472,7 @@ SDL_strlcpy(char *dst, const char *src, size_t maxlen)
#endif /* HAVE_STRLCPY */
}
size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
{
size_t src_bytes = SDL_strlen(src);
size_t bytes = SDL_min(src_bytes, dst_bytes - 1);
@ -505,7 +505,7 @@ size_t SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes)
}
size_t
SDL_strlcat(char *dst, const char *src, size_t maxlen)
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
{
#if defined(HAVE_STRLCAT)
return strlcat(dst, src, maxlen);
@ -980,7 +980,7 @@ SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen)
}
int
SDL_sscanf(const char *text, const char *fmt, ...)
SDL_sscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, ...)
{
int rc;
va_list ap;
@ -1261,7 +1261,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
#endif /* HAVE_VSSCANF */
int
SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list ap;
int retval;
@ -1274,8 +1274,11 @@ SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...)
}
#ifdef HAVE_VSNPRINTF
int SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
if (!fmt) {
fmt = "";
}
return vsnprintf(text, maxlen, fmt, ap);
}
#else
@ -1463,11 +1466,14 @@ SDL_PrintFloat(char *text, size_t maxlen, SDL_FormatInfo *info, double arg)
}
int
SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap)
SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap)
{
size_t left = maxlen;
char *textstart = text;
if (!fmt) {
fmt = "";
}
while (*fmt) {
if (*fmt == '%') {
SDL_bool done = SDL_FALSE;

View file

@ -44,9 +44,9 @@ static Uint32 SDLTest_AssertsPassed = 0;
/*
* Assert that logs and break execution flow on failures (i.e. for harness errors).
*/
void SDLTest_Assert(int assertCondition, const char *assertDescription, ...)
void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
{
va_list list;
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
/* Print assert description into a buffer */
@ -56,13 +56,13 @@ void SDLTest_Assert(int assertCondition, const char *assertDescription, ...)
va_end(list);
/* Log, then assert and break on failure */
SDL_assert((SDLTest_AssertCheck(assertCondition, logMessage)));
SDL_assert((SDLTest_AssertCheck(assertCondition, "%s", logMessage)));
}
/*
* Assert that logs but does not break execution flow on failures (i.e. for test cases).
*/
int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...)
int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
@ -91,7 +91,7 @@ int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...)
/*
* Explicitly passing Assert that logs (i.e. for test cases).
*/
void SDLTest_AssertPass(const char *assertDescription, ...)
void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

View file

@ -999,12 +999,10 @@ default: return "???";
static void
SDLTest_PrintEvent(SDL_Event * event)
{
#if 0
if ((event->type == SDL_MOUSEMOTION) || (event->type == SDL_FINGERMOTION)) {
/* Mouse and finger motion are really spammy */
return;
}
#endif
switch (event->type) {
case SDL_WINDOWEVENT:

View file

@ -564,7 +564,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
execKey = SDLTest_GenerateExecKey((char *)runSeed, testSuite->name, testCase->name, iterationCounter);
}
SDLTest_Log("Test Iteration %i: execKey %llu", iterationCounter, execKey);
SDLTest_Log("Test Iteration %i: execKey %" SDL_PRIu64, iterationCounter, execKey);
testResult = SDLTest_RunTest(testSuite, testCase, execKey);
if (testResult == TEST_RESULT_PASSED) {

View file

@ -68,7 +68,7 @@ char *SDLTest_TimestampToString(const time_t timestamp)
/*
* Prints given message with a timestamp in the TEST category and INFO priority.
*/
void SDLTest_Log(const char *fmt, ...)
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
@ -86,7 +86,7 @@ void SDLTest_Log(const char *fmt, ...)
/*
* Prints given message with a timestamp in the TEST category and the ERROR priority.
*/
void SDLTest_LogError(const char *fmt, ...)
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

View file

@ -442,10 +442,10 @@ SDL_DetachThread(SDL_Thread * thread)
SDL_SYS_DetachThread(thread);
} else {
/* all other states are pretty final, see where we landed. */
const int state = SDL_AtomicGet(&thread->state);
if ((state == SDL_THREAD_STATE_DETACHED) || (state == SDL_THREAD_STATE_CLEANED)) {
const int thread_state = SDL_AtomicGet(&thread->state);
if ((thread_state == SDL_THREAD_STATE_DETACHED) || (thread_state == SDL_THREAD_STATE_CLEANED)) {
return; /* already detached (you shouldn't call this twice!) */
} else if (state == SDL_THREAD_STATE_ZOMBIE) {
} else if (thread_state == SDL_THREAD_STATE_ZOMBIE) {
SDL_WaitThread(thread, NULL); /* already done, clean it up. */
} else {
SDL_assert(0 && "Unexpected thread state");

View file

@ -20,7 +20,9 @@
*/
#include "../../SDL_internal.h"
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <pthread.h>
#include <errno.h>

View file

@ -150,7 +150,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
if (errno == ETIMEDOUT) {
retval = SDL_MUTEX_TIMEDOUT;
} else {
SDL_SetError(strerror(errno));
SDL_SetError("sem_timedwait returned an error: %s", strerror(errno));
}
}
#else

View file

@ -57,11 +57,13 @@
#include "SDL_assert.h"
#ifndef __NACL__
/* List of signals to mask in the subthreads */
static const int sig_list[] = {
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
SIGVTALRM, SIGPROF, 0
};
#endif
static void *
RunThread(void *data)
@ -115,8 +117,10 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
void
SDL_SYS_SetupThread(const char *name)
{
#ifndef __NACL__
int i;
sigset_t mask;
#endif
if (name != NULL) {
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__LINUX__)
@ -141,12 +145,15 @@ SDL_SYS_SetupThread(const char *name)
#endif
}
/* NativeClient does not yet support signals.*/
#ifndef __NACL__
/* Mask asynchronous signals for this thread */
sigemptyset(&mask);
for (i = 0; sig_list[i]; ++i) {
sigaddset(&mask, sig_list[i]);
}
pthread_sigmask(SIG_BLOCK, &mask, 0);
#endif
#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
/* Allow ourselves to be asynchronously cancelled */
@ -166,7 +173,10 @@ SDL_ThreadID(void)
int
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
{
#ifdef __LINUX__
#if __NACL__
/* FIXME: Setting thread priority does not seem to be supported in NACL */
return 0;
#elif __LINUX__
int value;
if (priority == SDL_THREAD_PRIORITY_LOW) {

View file

@ -28,6 +28,7 @@
#include <errno.h>
#include "SDL_timer.h"
#include "SDL_assert.h"
/* The clock_gettime provides monotonous time, so we should use it if
it's available. The clock_gettime function is behind ifdef
@ -106,6 +107,9 @@ SDL_GetTicks(void)
#elif defined(__APPLE__)
uint64_t now = mach_absolute_time();
ticks = (((now - start_mach) * mach_base_info.numer) / mach_base_info.denom) / 1000000;
#else
SDL_assert(SDL_FALSE);
ticks = 0;
#endif
} else {
struct timeval now;
@ -136,6 +140,9 @@ SDL_GetPerformanceCounter(void)
ticks += now.tv_nsec;
#elif defined(__APPLE__)
ticks = mach_absolute_time();
#else
SDL_assert(SDL_FALSE);
ticks = 0;
#endif
} else {
struct timeval now;

View file

@ -115,22 +115,22 @@
* This can be used for any RGB permutation of course.
*/
#define ALPHA_BLIT32_888(to, from, length, bpp, alpha) \
do { \
int i; \
Uint32 *src = (Uint32 *)(from); \
Uint32 *dst = (Uint32 *)(to); \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
Uint32 s1 = s & 0xff00ff; \
Uint32 d1 = d & 0xff00ff; \
d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
s &= 0xff00; \
d &= 0xff00; \
d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
*dst++ = d1 | d; \
} \
} while(0)
do { \
int i; \
Uint32 *src = (Uint32 *)(from); \
Uint32 *dst = (Uint32 *)(to); \
for (i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
Uint32 s1 = s & 0xff00ff; \
Uint32 d1 = d & 0xff00ff; \
d1 = (d1 + ((s1 - d1) * alpha >> 8)) & 0xff00ff; \
s &= 0xff00; \
d &= 0xff00; \
d = (d + ((s - d) * alpha >> 8)) & 0xff00; \
*dst++ = d1 | d; \
} \
} while (0)
/*
* For 16bpp pixels we can go a step further: put the middle component
@ -139,97 +139,97 @@
* 5 bits, we have to scale alpha down to 5 bits as well.
*/
#define ALPHA_BLIT16_565(to, from, length, bpp, alpha) \
do { \
int i; \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
Uint32 ALPHA = alpha >> 3; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
s = (s | s << 16) & 0x07e0f81f; \
d = (d | d << 16) & 0x07e0f81f; \
d += (s - d) * ALPHA >> 5; \
d &= 0x07e0f81f; \
*dst++ = (Uint16)(d | d >> 16); \
} \
do { \
int i; \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
Uint32 ALPHA = alpha >> 3; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
s = (s | s << 16) & 0x07e0f81f; \
d = (d | d << 16) & 0x07e0f81f; \
d += (s - d) * ALPHA >> 5; \
d &= 0x07e0f81f; \
*dst++ = (Uint16)(d | d >> 16); \
} \
} while(0)
#define ALPHA_BLIT16_555(to, from, length, bpp, alpha) \
do { \
int i; \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
Uint32 ALPHA = alpha >> 3; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
s = (s | s << 16) & 0x03e07c1f; \
d = (d | d << 16) & 0x03e07c1f; \
d += (s - d) * ALPHA >> 5; \
d &= 0x03e07c1f; \
*dst++ = (Uint16)(d | d >> 16); \
} \
do { \
int i; \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
Uint32 ALPHA = alpha >> 3; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
s = (s | s << 16) & 0x03e07c1f; \
d = (d | d << 16) & 0x03e07c1f; \
d += (s - d) * ALPHA >> 5; \
d &= 0x03e07c1f; \
*dst++ = (Uint16)(d | d >> 16); \
} \
} while(0)
/*
* The general slow catch-all function, for remaining depths and formats
*/
#define ALPHA_BLIT_ANY(to, from, length, bpp, alpha) \
do { \
int i; \
Uint8 *src = from; \
Uint8 *dst = to; \
for(i = 0; i < (int)(length); i++) { \
Uint32 s, d; \
unsigned rs, gs, bs, rd, gd, bd; \
switch(bpp) { \
case 2: \
s = *(Uint16 *)src; \
d = *(Uint16 *)dst; \
break; \
case 3: \
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
s = (src[0] << 16) | (src[1] << 8) | src[2]; \
d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
} else { \
s = (src[2] << 16) | (src[1] << 8) | src[0]; \
d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
} \
break; \
case 4: \
s = *(Uint32 *)src; \
d = *(Uint32 *)dst; \
break; \
} \
RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \
RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \
rd += (rs - rd) * alpha >> 8; \
gd += (gs - gd) * alpha >> 8; \
bd += (bs - bd) * alpha >> 8; \
PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \
switch(bpp) { \
case 2: \
*(Uint16 *)dst = (Uint16)d; \
break; \
case 3: \
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
dst[0] = (Uint8)(d >> 16); \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d); \
} else { \
dst[0] = (Uint8)d; \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d >> 16); \
} \
break; \
case 4: \
*(Uint32 *)dst = d; \
break; \
} \
src += bpp; \
dst += bpp; \
} \
do { \
int i; \
Uint8 *src = from; \
Uint8 *dst = to; \
for (i = 0; i < (int)(length); i++) { \
Uint32 s, d; \
unsigned rs, gs, bs, rd, gd, bd; \
switch (bpp) { \
case 2: \
s = *(Uint16 *)src; \
d = *(Uint16 *)dst; \
break; \
case 3: \
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
s = (src[0] << 16) | (src[1] << 8) | src[2]; \
d = (dst[0] << 16) | (dst[1] << 8) | dst[2]; \
} else { \
s = (src[2] << 16) | (src[1] << 8) | src[0]; \
d = (dst[2] << 16) | (dst[1] << 8) | dst[0]; \
} \
break; \
case 4: \
s = *(Uint32 *)src; \
d = *(Uint32 *)dst; \
break; \
} \
RGB_FROM_PIXEL(s, fmt, rs, gs, bs); \
RGB_FROM_PIXEL(d, fmt, rd, gd, bd); \
rd += (rs - rd) * alpha >> 8; \
gd += (gs - gd) * alpha >> 8; \
bd += (bs - bd) * alpha >> 8; \
PIXEL_FROM_RGB(d, fmt, rd, gd, bd); \
switch (bpp) { \
case 2: \
*(Uint16 *)dst = (Uint16)d; \
break; \
case 3: \
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { \
dst[0] = (Uint8)(d >> 16); \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d); \
} else { \
dst[0] = (Uint8)d; \
dst[1] = (Uint8)(d >> 8); \
dst[2] = (Uint8)(d >> 16); \
} \
break; \
case 4: \
*(Uint32 *)dst = d; \
break; \
} \
src += bpp; \
dst += bpp; \
} \
} while(0)
/*
@ -241,16 +241,16 @@
* add them. Then shift right and add the sum of the lowest bits.
*/
#define ALPHA_BLIT32_888_50(to, from, length, bpp, alpha) \
do { \
int i; \
Uint32 *src = (Uint32 *)(from); \
Uint32 *dst = (Uint32 *)(to); \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
*dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
+ (s & d & 0x00010101); \
} \
do { \
int i; \
Uint32 *src = (Uint32 *)(from); \
Uint32 *dst = (Uint32 *)(to); \
for(i = 0; i < (int)(length); i++) { \
Uint32 s = *src++; \
Uint32 d = *dst; \
*dst++ = (((s & 0x00fefefe) + (d & 0x00fefefe)) >> 1) \
+ (s & d & 0x00010101); \
} \
} while(0)
/*
@ -259,116 +259,118 @@
*/
/* helper: blend a single 16 bit pixel at 50% */
#define BLEND16_50(dst, src, mask) \
do { \
Uint32 s = *src++; \
Uint32 d = *dst; \
*dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
(s & d & (~mask & 0xffff))); \
#define BLEND16_50(dst, src, mask) \
do { \
Uint32 s = *src++; \
Uint32 d = *dst; \
*dst++ = (Uint16)((((s & mask) + (d & mask)) >> 1) + \
(s & d & (~mask & 0xffff))); \
} while(0)
/* basic 16bpp blender. mask is the pixels to keep when adding. */
#define ALPHA_BLIT16_50(to, from, length, bpp, alpha, mask) \
do { \
unsigned n = (length); \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
if(((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
/* source and destination not in phase, blit one by one */ \
while(n--) \
BLEND16_50(dst, src, mask); \
} else { \
if((uintptr_t)src & 3) { \
/* first odd pixel */ \
BLEND16_50(dst, src, mask); \
n--; \
} \
for(; n > 1; n -= 2) { \
Uint32 s = *(Uint32 *)src; \
Uint32 d = *(Uint32 *)dst; \
*(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
+ ((d & (mask | mask << 16)) >> 1) \
+ (s & d & (~(mask | mask << 16))); \
src += 2; \
dst += 2; \
} \
if(n) \
BLEND16_50(dst, src, mask); /* last odd pixel */ \
} \
do { \
unsigned n = (length); \
Uint16 *src = (Uint16 *)(from); \
Uint16 *dst = (Uint16 *)(to); \
if (((uintptr_t)src ^ (uintptr_t)dst) & 3) { \
/* source and destination not in phase, blit one by one */ \
while (n--) \
BLEND16_50(dst, src, mask); \
} else { \
if ((uintptr_t)src & 3) { \
/* first odd pixel */ \
BLEND16_50(dst, src, mask); \
n--; \
} \
for (; n > 1; n -= 2) { \
Uint32 s = *(Uint32 *)src; \
Uint32 d = *(Uint32 *)dst; \
*(Uint32 *)dst = ((s & (mask | mask << 16)) >> 1) \
+ ((d & (mask | mask << 16)) >> 1) \
+ (s & d & (~(mask | mask << 16))); \
src += 2; \
dst += 2; \
} \
if (n) \
BLEND16_50(dst, src, mask); /* last odd pixel */ \
} \
} while(0)
#define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \
#define ALPHA_BLIT16_565_50(to, from, length, bpp, alpha) \
ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xf7de)
#define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \
#define ALPHA_BLIT16_555_50(to, from, length, bpp, alpha) \
ALPHA_BLIT16_50(to, from, length, bpp, alpha, 0xfbde)
#define CHOOSE_BLIT(blitter, alpha, fmt) \
do { \
if(alpha == 255) { \
switch(fmt->BytesPerPixel) { \
case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \
case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \
case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \
case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \
} \
} else { \
switch(fmt->BytesPerPixel) { \
case 1: \
/* No 8bpp alpha blitting */ \
break; \
\
case 2: \
switch(fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
case 0xffff: \
if(fmt->Gmask == 0x07e0 \
|| fmt->Rmask == 0x07e0 \
|| fmt->Bmask == 0x07e0) { \
if(alpha == 128) \
blitter(2, Uint8, ALPHA_BLIT16_565_50); \
else { \
blitter(2, Uint8, ALPHA_BLIT16_565); \
} \
} else \
goto general16; \
break; \
\
case 0x7fff: \
if(fmt->Gmask == 0x03e0 \
|| fmt->Rmask == 0x03e0 \
|| fmt->Bmask == 0x03e0) { \
if(alpha == 128) \
blitter(2, Uint8, ALPHA_BLIT16_555_50); \
else { \
blitter(2, Uint8, ALPHA_BLIT16_555); \
} \
break; \
} \
/* fallthrough */ \
\
default: \
general16: \
blitter(2, Uint8, ALPHA_BLIT_ANY); \
} \
break; \
\
case 3: \
blitter(3, Uint8, ALPHA_BLIT_ANY); \
break; \
\
case 4: \
if((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \
&& (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \
|| fmt->Bmask == 0xff00)) { \
if(alpha == 128) \
blitter(4, Uint16, ALPHA_BLIT32_888_50); \
else \
blitter(4, Uint16, ALPHA_BLIT32_888); \
} else \
blitter(4, Uint16, ALPHA_BLIT_ANY); \
break; \
} \
} \
#define CHOOSE_BLIT(blitter, alpha, fmt) \
do { \
if (alpha == 255) { \
switch (fmt->BytesPerPixel) { \
case 1: blitter(1, Uint8, OPAQUE_BLIT); break; \
case 2: blitter(2, Uint8, OPAQUE_BLIT); break; \
case 3: blitter(3, Uint8, OPAQUE_BLIT); break; \
case 4: blitter(4, Uint16, OPAQUE_BLIT); break; \
} \
} else { \
switch (fmt->BytesPerPixel) { \
case 1: \
/* No 8bpp alpha blitting */ \
break; \
\
case 2: \
switch (fmt->Rmask | fmt->Gmask | fmt->Bmask) { \
case 0xffff: \
if (fmt->Gmask == 0x07e0 \
|| fmt->Rmask == 0x07e0 \
|| fmt->Bmask == 0x07e0) { \
if (alpha == 128) { \
blitter(2, Uint8, ALPHA_BLIT16_565_50); \
} else { \
blitter(2, Uint8, ALPHA_BLIT16_565); \
} \
} else \
goto general16; \
break; \
\
case 0x7fff: \
if (fmt->Gmask == 0x03e0 \
|| fmt->Rmask == 0x03e0 \
|| fmt->Bmask == 0x03e0) { \
if (alpha == 128) { \
blitter(2, Uint8, ALPHA_BLIT16_555_50); \
} else { \
blitter(2, Uint8, ALPHA_BLIT16_555); \
} \
break; \
} else \
goto general16; \
break; \
\
default: \
general16: \
blitter(2, Uint8, ALPHA_BLIT_ANY); \
} \
break; \
\
case 3: \
blitter(3, Uint8, ALPHA_BLIT_ANY); \
break; \
\
case 4: \
if ((fmt->Rmask | fmt->Gmask | fmt->Bmask) == 0x00ffffff \
&& (fmt->Gmask == 0xff00 || fmt->Rmask == 0xff00 \
|| fmt->Bmask == 0xff00)) { \
if (alpha == 128) { \
blitter(4, Uint16, ALPHA_BLIT32_888_50); \
} else { \
blitter(4, Uint16, ALPHA_BLIT32_888); \
} \
} else \
blitter(4, Uint16, ALPHA_BLIT_ANY); \
break; \
} \
} \
} while(0)
/*
@ -376,53 +378,54 @@
* right. Top clipping has already been taken care of.
*/
static void
RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha)
{
SDL_PixelFormat *fmt = dst->format;
SDL_PixelFormat *fmt = surf_dst->format;
#define RLECLIPBLIT(bpp, Type, do_blit) \
do { \
int linecount = srcrect->h; \
int ofs = 0; \
int left = srcrect->x; \
int right = left + srcrect->w; \
dstbuf -= left * bpp; \
for(;;) { \
int run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Type); \
if(run) { \
/* clip to left and right borders */ \
if(ofs < right) { \
int start = 0; \
int len = run; \
int startcol; \
if(left - ofs > 0) { \
start = left - ofs; \
len -= start; \
if(len <= 0) \
goto nocopy ## bpp ## do_blit; \
} \
startcol = ofs + start; \
if(len > right - startcol) \
len = right - startcol; \
do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
len, bpp, alpha); \
} \
nocopy ## bpp ## do_blit: \
srcbuf += run * bpp; \
ofs += run; \
} else if(!ofs) \
break; \
if(ofs == w) { \
ofs = 0; \
dstbuf += dst->pitch; \
if(!--linecount) \
break; \
} \
} \
#define RLECLIPBLIT(bpp, Type, do_blit) \
do { \
int linecount = srcrect->h; \
int ofs = 0; \
int left = srcrect->x; \
int right = left + srcrect->w; \
dstbuf -= left * bpp; \
for (;;) { \
int run; \
ofs += *(Type *)srcbuf; \
run = ((Type *)srcbuf)[1]; \
srcbuf += 2 * sizeof(Type); \
if (run) { \
/* clip to left and right borders */ \
if (ofs < right) { \
int start = 0; \
int len = run; \
int startcol; \
if (left - ofs > 0) { \
start = left - ofs; \
len -= start; \
if (len <= 0) \
goto nocopy ## bpp ## do_blit; \
} \
startcol = ofs + start; \
if (len > right - startcol) \
len = right - startcol; \
do_blit(dstbuf + startcol * bpp, srcbuf + start * bpp, \
len, bpp, alpha); \
} \
nocopy ## bpp ## do_blit: \
srcbuf += run * bpp; \
ofs += run; \
} else if (!ofs) \
break; \
\
if (ofs == w) { \
ofs = 0; \
dstbuf += surf_dst->pitch; \
if (!--linecount) \
break; \
} \
} \
} while(0)
CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt);
@ -434,18 +437,18 @@ RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
/* blit a colorkeyed RLE surface */
int
SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
SDL_RLEBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
SDL_Surface * surf_dst, SDL_Rect * dstrect)
{
Uint8 *dstbuf;
Uint8 *srcbuf;
int x, y;
int w = src->w;
int w = surf_src->w;
unsigned alpha;
/* Lock the destination if necessary */
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
if (SDL_MUSTLOCK(surf_dst)) {
if (SDL_LockSurface(surf_dst) < 0) {
return (-1);
}
}
@ -453,9 +456,9 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
/* Set up the source and destination pointers */
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *) dst->pixels
+ y * dst->pitch + x * src->format->BytesPerPixel;
srcbuf = (Uint8 *) src->map->data;
dstbuf = (Uint8 *) surf_dst->pixels
+ y * surf_dst->pitch + x * surf_src->format->BytesPerPixel;
srcbuf = (Uint8 *) surf_src->map->data;
{
/* skip lines at the top if necessary */
@ -481,7 +484,7 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
} \
}
switch (src->format->BytesPerPixel) {
switch (surf_src->format->BytesPerPixel) {
case 1:
RLESKIP(1, Uint8);
break;
@ -501,12 +504,12 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
}
}
alpha = src->map->info.a;
alpha = surf_src->map->info.a;
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != src->w) {
RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
if (srcrect->x || srcrect->w != surf_src->w) {
RLEClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect, alpha);
} else {
SDL_PixelFormat *fmt = src->format;
SDL_PixelFormat *fmt = surf_src->format;
#define RLEBLIT(bpp, Type, do_blit) \
do { \
@ -525,7 +528,7 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
break; \
if(ofs == w) { \
ofs = 0; \
dstbuf += dst->pitch; \
dstbuf += surf_dst->pitch; \
if(!--linecount) \
break; \
} \
@ -539,8 +542,8 @@ SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
done:
/* Unlock the destination if necessary */
if (SDL_MUSTLOCK(dst)) {
SDL_UnlockSurface(dst);
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return (0);
}
@ -620,10 +623,10 @@ typedef struct
/* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
static void
RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * surf_dst,
Uint8 * dstbuf, SDL_Rect * srcrect)
{
SDL_PixelFormat *df = dst->format;
SDL_PixelFormat *df = surf_dst->format;
/*
* clipped blitter: Ptype is the destination pixel type,
* Ctype the translucent count type, and do_blend the macro
@ -693,7 +696,7 @@ RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
ofs += run; \
} \
} while(ofs < w); \
dstbuf += dst->pitch; \
dstbuf += surf_dst->pitch; \
} while(--linecount); \
} while(0)
@ -712,25 +715,25 @@ RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
/* blit a pixel-alpha RLE surface */
int
SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
SDL_Surface * dst, SDL_Rect * dstrect)
SDL_RLEAlphaBlit(SDL_Surface * surf_src, SDL_Rect * srcrect,
SDL_Surface * surf_dst, SDL_Rect * dstrect)
{
int x, y;
int w = src->w;
int w = surf_src->w;
Uint8 *srcbuf, *dstbuf;
SDL_PixelFormat *df = dst->format;
SDL_PixelFormat *df = surf_dst->format;
/* Lock the destination if necessary */
if (SDL_MUSTLOCK(dst)) {
if (SDL_LockSurface(dst) < 0) {
if (SDL_MUSTLOCK(surf_dst)) {
if (SDL_LockSurface(surf_dst) < 0) {
return -1;
}
}
x = dstrect->x;
y = dstrect->y;
dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel;
srcbuf = (Uint8 *) src->map->data + sizeof(RLEDestFormat);
dstbuf = (Uint8 *) surf_dst->pixels + y * surf_dst->pitch + x * df->BytesPerPixel;
srcbuf = (Uint8 *) surf_src->map->data + sizeof(RLEDestFormat);
{
/* skip lines at the top if necessary */
@ -789,8 +792,8 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
}
/* if left or right edge clipping needed, call clip blit */
if (srcrect->x || srcrect->w != src->w) {
RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect);
if (srcrect->x || srcrect->w != surf_src->w) {
RLEAlphaClipBlit(w, srcbuf, surf_dst, dstbuf, srcrect);
} else {
/*
@ -839,7 +842,7 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
ofs += run; \
} \
} while(ofs < w); \
dstbuf += dst->pitch; \
dstbuf += surf_dst->pitch; \
} while(--linecount); \
} while(0)
@ -859,8 +862,8 @@ SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
done:
/* Unlock the destination if necessary */
if (SDL_MUSTLOCK(dst)) {
SDL_UnlockSurface(dst);
if (SDL_MUSTLOCK(surf_dst)) {
SDL_UnlockSurface(surf_dst);
}
return 0;
}

View file

@ -402,18 +402,18 @@ do { \
{ \
switch (bpp) { \
case 1: { \
Uint8 Pixel; \
Uint8 _pixel; \
\
PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a); \
*((Uint8 *)(buf)) = Pixel; \
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint8 *)(buf)) = _pixel; \
} \
break; \
\
case 2: { \
Uint16 Pixel; \
Uint16 _pixel; \
\
PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a); \
*((Uint16 *)(buf)) = Pixel; \
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint16 *)(buf)) = _pixel; \
} \
break; \
\
@ -431,10 +431,10 @@ do { \
break; \
\
case 4: { \
Uint32 Pixel; \
Uint32 _pixel; \
\
PIXEL_FROM_RGBA(Pixel, fmt, r, g, b, a); \
*((Uint32 *)(buf)) = Pixel; \
PIXEL_FROM_RGBA(_pixel, fmt, r, g, b, a); \
*((Uint32 *)(buf)) = _pixel; \
} \
break; \
} \

View file

@ -343,7 +343,7 @@ BlitRGBtoRGBPixelAlphaMMX(SDL_BlitInfo * info)
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
multmask = 0x00FF;
multmask <<= (ashift * 2);
multmask2 = 0x00FF00FF00FF00FF;
multmask2 = 0x00FF00FF00FF00FFULL;
while (height--) {
/* *INDENT-OFF* */
@ -530,7 +530,7 @@ BlitRGBtoRGBPixelAlphaMMX3DNOW(SDL_BlitInfo * info)
mm_zero = _mm_setzero_si64(); /* 0 -> mm_zero */
multmask = 0x00FF;
multmask <<= (ashift * 2);
multmask2 = 0x00FF00FF00FF00FF;
multmask2 = 0x00FF00FF00FF00FFULL;
while (height--) {
/* *INDENT-OFF* */

View file

@ -189,7 +189,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
dll_handle = SDL_LoadObject(egl_path);
}
/* Try loading a EGL symbol, if it does not work try the default library paths */
if (SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
if (dll_handle != NULL) {
SDL_UnloadObject(dll_handle);
}
@ -198,7 +198,10 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
path = DEFAULT_EGL;
}
dll_handle = SDL_LoadObject(path);
if (dll_handle == NULL) {
if (dll_handle == NULL || SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) {
if (dll_handle != NULL) {
SDL_UnloadObject(dll_handle);
}
return SDL_SetError("Could not load EGL library");
}
SDL_ClearError();
@ -235,8 +238,6 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
}
#endif
_this->egl_data->dll_handle = dll_handle;
_this->egl_data->egl_dll_handle = egl_dll_handle;
_this->gl_config.driver_loaded = 1;
if (path) {

View file

@ -387,6 +387,9 @@ extern VideoBootStrap DUMMY_bootstrap;
#if SDL_VIDEO_DRIVER_WAYLAND
extern VideoBootStrap Wayland_bootstrap;
#endif
#if SDL_VIDEO_DRIVER_NACL
extern VideoBootStrap NACL_bootstrap;
#endif
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);

View file

@ -92,6 +92,9 @@ static VideoBootStrap *bootstrap[] = {
#if SDL_VIDEO_DRIVER_WAYLAND
&Wayland_bootstrap,
#endif
#if SDL_VIDEO_DRIVER_NACL
&NACL_bootstrap,
#endif
#if SDL_VIDEO_DRIVER_DUMMY
&DUMMY_bootstrap,
#endif
@ -122,7 +125,7 @@ static SDL_VideoDevice *_this = NULL;
return retval; \
}
#define FULLSCREEN_MASK ( SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN )
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
#ifdef __MACOSX__
/* Support for Mac OS X fullscreen spaces */
@ -229,16 +232,13 @@ ShouldUseTextureFramebuffer()
}
static int
SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
SDL_CreateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
{
SDL_WindowTextureData *data;
SDL_RendererInfo info;
Uint32 i;
data = SDL_GetWindowData(window, SDL_WINDOWTEXTUREDATA);
if (!data) {
SDL_Renderer *renderer = NULL;
SDL_RendererInfo info;
int i;
const char *hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
@ -246,6 +246,7 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix
if (hint && *hint != '0' && *hint != '1' &&
SDL_strcasecmp(hint, "software") != 0) {
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
if (SDL_strcasecmp(info.name, hint) == 0) {
renderer = SDL_CreateRenderer(window, i, 0);
@ -253,9 +254,10 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix
}
}
}
if (!renderer) {
for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
SDL_RendererInfo info;
SDL_GetRenderDriverInfo(i, &info);
if (SDL_strcmp(info.name, "software") != 0) {
renderer = SDL_CreateRenderer(window, i, 0);
@ -288,17 +290,23 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix
SDL_free(data->pixels);
data->pixels = NULL;
if (SDL_GetRendererInfo(data->renderer, &info) < 0) {
return -1;
}
{
SDL_RendererInfo info;
Uint32 i;
/* Find the first format without an alpha channel */
*format = info.texture_formats[0];
for (i = 0; i < info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
*format = info.texture_formats[i];
break;
if (SDL_GetRendererInfo(data->renderer, &info) < 0) {
return -1;
}
/* Find the first format without an alpha channel */
*format = info.texture_formats[0];
for (i = 0; i < info.num_texture_formats; ++i) {
if (!SDL_ISPIXELFORMAT_FOURCC(info.texture_formats[i]) &&
!SDL_ISPIXELFORMAT_ALPHA(info.texture_formats[i])) {
*format = info.texture_formats[i];
break;
}
}
}
@ -327,7 +335,7 @@ SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pix
}
static int
SDL_UpdateWindowTexture(_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects)
SDL_UpdateWindowTexture(SDL_VideoDevice *unused, SDL_Window * window, const SDL_Rect * rects, int numrects)
{
SDL_WindowTextureData *data;
SDL_Rect rect;
@ -357,7 +365,7 @@ SDL_UpdateWindowTexture(_THIS, SDL_Window * window, const SDL_Rect * rects, int
}
static void
SDL_DestroyWindowTexture(_THIS, SDL_Window * window)
SDL_DestroyWindowTexture(SDL_VideoDevice *unused, SDL_Window * window)
{
SDL_WindowTextureData *data;
@ -626,9 +634,9 @@ SDL_GetIndexOfDisplay(SDL_VideoDisplay *display)
}
void *
SDL_GetDisplayDriverData( int displayIndex )
SDL_GetDisplayDriverData(int displayIndex)
{
CHECK_DISPLAY_INDEX( displayIndex, NULL );
CHECK_DISPLAY_INDEX(displayIndex, NULL);
return _this->displays[displayIndex].driverdata;
}
@ -1020,6 +1028,13 @@ SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode)
} else {
SDL_zero(window->fullscreen_mode);
}
if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
SDL_DisplayMode fullscreen_mode;
if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) {
SDL_SetDisplayModeForDisplay(SDL_GetDisplayForWindow(window), &fullscreen_mode);
}
}
return 0;
}
@ -1029,28 +1044,26 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode)
SDL_DisplayMode fullscreen_mode;
SDL_VideoDisplay *display;
if (!mode) {
return SDL_InvalidParamError("mode");
}
CHECK_WINDOW_MAGIC(window, -1);
if (!mode) {
return SDL_InvalidParamError("mode");
}
fullscreen_mode = window->fullscreen_mode;
if (!fullscreen_mode.w) {
fullscreen_mode.w = window->w;
fullscreen_mode.w = window->windowed.w;
}
if (!fullscreen_mode.h) {
fullscreen_mode.h = window->h;
fullscreen_mode.h = window->windowed.h;
}
display = SDL_GetDisplayForWindow(window);
/* if in desktop size mode, just return the size of the desktop */
if ( ( window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP ) == SDL_WINDOW_FULLSCREEN_DESKTOP )
{
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
fullscreen_mode = display->desktop_mode;
}
else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
} else if (!SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window),
&fullscreen_mode,
&fullscreen_mode)) {
return SDL_SetError("Couldn't find display mode match");
@ -1090,6 +1103,8 @@ SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
SDL_VideoDisplay *display;
SDL_Window *other;
CHECK_WINDOW_MAGIC(window,);
#ifdef __MACOSX__
if (Cocoa_SetWindowFullscreenSpace(window, fullscreen)) {
window->last_fullscreen_flags = window->flags;
@ -1232,7 +1247,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
}
/* Some platforms have OpenGL enabled by default */
#if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__
#if (SDL_VIDEO_OPENGL && __MACOSX__) || __IPHONEOS__ || __ANDROID__ || __NACL__
flags |= SDL_WINDOW_OPENGL;
#endif
if (flags & SDL_WINDOW_OPENGL) {
@ -1347,6 +1362,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
{
char *title = window->title;
SDL_Surface *icon = window->icon;
SDL_bool loaded_opengl = SDL_FALSE;
if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) {
return SDL_SetError("No OpenGL support in video driver");
@ -1379,6 +1395,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
if (SDL_GL_LoadLibrary(NULL) < 0) {
return -1;
}
loaded_opengl = SDL_TRUE;
} else {
SDL_GL_UnloadLibrary();
}
@ -1392,8 +1409,9 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) {
if (_this->CreateWindow(_this, window) < 0) {
if (flags & SDL_WINDOW_OPENGL) {
if (loaded_opengl) {
SDL_GL_UnloadLibrary();
window->flags &= ~SDL_WINDOW_OPENGL;
}
return -1;
}
@ -1411,7 +1429,7 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags)
SDL_FreeSurface(icon);
}
if (window->hit_test > 0) {
if (window->hit_test) {
_this->SetWindowHitTest(window, SDL_TRUE);
}
@ -1455,7 +1473,7 @@ SDL_GetWindowFlags(SDL_Window * window)
void
SDL_SetWindowTitle(SDL_Window * window, const char *title)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (title == window->title) {
return;
@ -1483,7 +1501,7 @@ SDL_GetWindowTitle(SDL_Window * window)
void
SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!icon) {
return;
@ -1573,7 +1591,7 @@ SDL_GetWindowData(SDL_Window * window, const char *name)
void
SDL_SetWindowPosition(SDL_Window * window, int x, int y)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
@ -1617,7 +1635,7 @@ SDL_SetWindowPosition(SDL_Window * window, int x, int y)
void
SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
/* Fullscreen windows are always at their display's origin */
if (window->flags & SDL_WINDOW_FULLSCREEN) {
@ -1640,7 +1658,7 @@ SDL_GetWindowPosition(SDL_Window * window, int *x, int *y)
void
SDL_SetWindowBordered(SDL_Window * window, SDL_bool bordered)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
const int want = (bordered != SDL_FALSE); /* normalize the flag. */
const int have = ((window->flags & SDL_WINDOW_BORDERLESS) == 0);
@ -1658,7 +1676,7 @@ SDL_SetWindowBordered(SDL_Window * window, SDL_bool bordered)
void
SDL_SetWindowSize(SDL_Window * window, int w, int h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (w <= 0) {
SDL_InvalidParamError("w");
return;
@ -1686,10 +1704,14 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h)
h = window->max_h;
}
/* FIXME: Should this change fullscreen modes? */
window->windowed.w = w;
window->windowed.h = h;
if (window->flags & SDL_WINDOW_FULLSCREEN) {
window->windowed.w = w;
window->windowed.h = h;
if (FULLSCREEN_VISIBLE(window) && (window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP) {
window->last_fullscreen_flags = 0;
SDL_UpdateFullscreenMode(window, SDL_TRUE);
}
} else {
window->w = w;
window->h = h;
@ -1706,7 +1728,7 @@ SDL_SetWindowSize(SDL_Window * window, int w, int h)
void
SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (w) {
*w = window->w;
}
@ -1718,7 +1740,7 @@ SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
void
SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (min_w <= 0) {
SDL_InvalidParamError("min_w");
return;
@ -1742,7 +1764,7 @@ SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
void
SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (min_w) {
*min_w = window->min_w;
}
@ -1754,7 +1776,7 @@ SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
void
SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (max_w <= 0) {
SDL_InvalidParamError("max_w");
return;
@ -1778,7 +1800,7 @@ SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
void
SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (max_w) {
*max_w = window->max_w;
}
@ -1790,7 +1812,7 @@ SDL_GetWindowMaximumSize(SDL_Window * window, int *max_w, int *max_h)
void
SDL_ShowWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (window->flags & SDL_WINDOW_SHOWN) {
return;
@ -1805,7 +1827,7 @@ SDL_ShowWindow(SDL_Window * window)
void
SDL_HideWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & SDL_WINDOW_SHOWN)) {
return;
@ -1822,7 +1844,7 @@ SDL_HideWindow(SDL_Window * window)
void
SDL_RaiseWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & SDL_WINDOW_SHOWN)) {
return;
@ -1835,7 +1857,7 @@ SDL_RaiseWindow(SDL_Window * window)
void
SDL_MaximizeWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (window->flags & SDL_WINDOW_MAXIMIZED) {
return;
@ -1851,7 +1873,7 @@ SDL_MaximizeWindow(SDL_Window * window)
void
SDL_MinimizeWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (window->flags & SDL_WINDOW_MINIMIZED) {
return;
@ -1867,7 +1889,7 @@ SDL_MinimizeWindow(SDL_Window * window)
void
SDL_RestoreWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) {
return;
@ -1885,7 +1907,7 @@ SDL_SetWindowFullscreen(SDL_Window * window, Uint32 flags)
flags &= FULLSCREEN_MASK;
if ( flags == (window->flags & FULLSCREEN_MASK) ) {
if (flags == (window->flags & FULLSCREEN_MASK)) {
return 0;
}
@ -2088,7 +2110,7 @@ SDL_UpdateWindowGrab(SDL_Window * window)
void
SDL_SetWindowGrab(SDL_Window * window, SDL_bool grabbed)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
return;
@ -2244,7 +2266,7 @@ SDL_DestroyWindow(SDL_Window * window)
{
SDL_VideoDisplay *display;
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
window->is_destroying = SDL_TRUE;
@ -2473,7 +2495,7 @@ SDL_GL_UnloadLibrary(void)
static SDL_INLINE SDL_bool
isAtLeastGL3(const char *verstr)
{
return ( verstr && (SDL_atoi(verstr) >= 3) );
return (verstr && (SDL_atoi(verstr) >= 3));
}
SDL_bool
@ -2680,23 +2702,23 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value)
};
break;
case SDL_GL_CONTEXT_FLAGS:
if( value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG |
SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG |
SDL_GL_CONTEXT_RESET_ISOLATION_FLAG) ) {
retval = SDL_SetError("Unknown OpenGL context flag %d", value);
break;
}
if (value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG |
SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG |
SDL_GL_CONTEXT_RESET_ISOLATION_FLAG)) {
retval = SDL_SetError("Unknown OpenGL context flag %d", value);
break;
}
_this->gl_config.flags = value;
break;
case SDL_GL_CONTEXT_PROFILE_MASK:
if( value != 0 &&
value != SDL_GL_CONTEXT_PROFILE_CORE &&
value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY &&
value != SDL_GL_CONTEXT_PROFILE_ES ) {
retval = SDL_SetError("Unknown OpenGL context profile %d", value);
break;
}
if (value != 0 &&
value != SDL_GL_CONTEXT_PROFILE_CORE &&
value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY &&
value != SDL_GL_CONTEXT_PROFILE_ES) {
retval = SDL_SetError("Unknown OpenGL context profile %d", value);
break;
}
_this->gl_config.profile_mask = value;
break;
case SDL_GL_SHARE_WITH_CURRENT_CONTEXT:
@ -2976,7 +2998,7 @@ SDL_GL_GetCurrentContext(void)
void SDL_GL_GetDrawableSize(SDL_Window * window, int *w, int *h)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (_this->GL_GetDrawableSize) {
_this->GL_GetDrawableSize(_this, window, w, h);
@ -3016,7 +3038,7 @@ SDL_GL_GetSwapInterval(void)
void
SDL_GL_SwapWindow(SDL_Window * window)
{
CHECK_WINDOW_MAGIC(window, );
CHECK_WINDOW_MAGIC(window,);
if (!(window->flags & SDL_WINDOW_OPENGL)) {
SDL_SetError("The specified window isn't an OpenGL window");
@ -3250,7 +3272,8 @@ SDL_IsScreenKeyboardShown(SDL_Window *window)
#include "x11/SDL_x11messagebox.h"
#endif
static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
// This function will be unused if none of the above video drivers are present.
SDL_UNUSED static SDL_bool SDL_MessageboxValidForDriver(const SDL_MessageBoxData *messageboxdata, SDL_SYSWM_TYPE drivertype)
{
SDL_SysWMinfo info;
SDL_Window *window = messageboxdata->window;

View file

@ -111,6 +111,7 @@ Android_CreateDevice(int devindex)
device->CreateWindow = Android_CreateWindow;
device->SetWindowTitle = Android_SetWindowTitle;
device->DestroyWindow = Android_DestroyWindow;
device->GetWindowWMInfo = Android_GetWindowWMInfo;
device->free = Android_DeleteDevice;

View file

@ -22,6 +22,7 @@
#if SDL_VIDEO_DRIVER_ANDROID
#include "SDL_syswm.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include "../../events/SDL_mouse_c.h"
@ -106,7 +107,7 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
if (data->egl_surface != EGL_NO_SURFACE) {
SDL_EGL_DestroySurface(_this, data->egl_surface);
}
if(data->native_window) {
if (data->native_window) {
ANativeWindow_release(data->native_window);
}
SDL_free(window->driverdata);
@ -115,6 +116,24 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
}
}
SDL_bool
Android_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (info->version.major == SDL_MAJOR_VERSION &&
info->version.minor == SDL_MINOR_VERSION) {
info->subsystem = SDL_SYSWM_ANDROID;
info->info.android.window = data->native_window;
info->info.android.surface = data->egl_surface;
return SDL_TRUE;
} else {
SDL_SetError("Application not compiled with SDL %d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return SDL_FALSE;
}
}
#endif /* SDL_VIDEO_DRIVER_ANDROID */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -29,6 +29,7 @@
extern int Android_CreateWindow(_THIS, SDL_Window * window);
extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
extern void Android_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool Android_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo * info);
typedef struct
{

View file

@ -565,6 +565,10 @@ void
Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
if (!data) {
return; /* can happen when returning from fullscreen Space on shutdown */
}
unsigned short scancode = [event keyCode];
SDL_Scancode code;
#if 0

View file

@ -132,7 +132,7 @@ Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
}
else
{
returnValue = SDL_SetError("Did not get a valid `clicked button' id: %d", clicked);
returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked);
}
[pool release];

View file

@ -200,14 +200,14 @@ Cocoa_ReleaseDisplayModeList(_THIS, CFArrayRef modelist)
static const char *
Cocoa_GetDisplayName(CGDirectDisplayID displayID)
{
NSDictionary *deviceInfo = (NSDictionary *)IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
NSDictionary *localizedNames = [deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
CFDictionaryRef deviceInfo = IODisplayCreateInfoDictionary(CGDisplayIOServicePort(displayID), kIODisplayOnlyPreferredName);
NSDictionary *localizedNames = [(NSDictionary *)deviceInfo objectForKey:[NSString stringWithUTF8String:kDisplayProductName]];
const char* displayName = NULL;
if ([localizedNames count] > 0) {
displayName = SDL_strdup([[localizedNames objectForKey:[[localizedNames allKeys] objectAtIndex:0]] UTF8String]);
}
[deviceInfo release];
CFRelease(deviceInfo);
return displayName;
}

View file

@ -241,6 +241,30 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
}
}
static void
Cocoa_WarpMouseGlobal(int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
CGPoint point = CGPointMake((float)x, (float)y);
Cocoa_HandleMouseWarp(point.x, point.y);
/* According to the docs, this was deprecated in 10.6, but it's still
* around. The substitute requires a CGEventSource, but I'm not entirely
* sure how we'd procure the right one for this event.
*/
CGSetLocalEventsSuppressionInterval(0.0);
CGWarpMouseCursorPosition(point);
CGSetLocalEventsSuppressionInterval(0.25);
if (!mouse->relative_mode && mouse->focus) {
/* CGWarpMouseCursorPosition doesn't generate a window event, unlike our
* other implementations' APIs.
*/
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 0, x - mouse->focus->x, y - mouse->focus->y);
}
}
static int
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
{
@ -271,6 +295,15 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
if (result != kCGErrorSuccess) {
return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
}
/* The hide/unhide calls are redundant most of the time, but they fix
* https://bugzilla.libsdl.org/show_bug.cgi?id=2550
*/
if (enabled) {
[NSCursor hide];
} else {
[NSCursor unhide];
}
return 0;
}
@ -319,6 +352,7 @@ Cocoa_InitMouse(_THIS)
mouse->ShowCursor = Cocoa_ShowCursor;
mouse->FreeCursor = Cocoa_FreeCursor;
mouse->WarpMouse = Cocoa_WarpMouse;
mouse->WarpMouseGlobal = Cocoa_WarpMouseGlobal;
mouse->SetRelativeMouseMode = Cocoa_SetRelativeMouseMode;
mouse->CaptureMouse = Cocoa_CaptureMouse;
mouse->GetGlobalMouseState = Cocoa_GetGlobalMouseState;
@ -350,8 +384,11 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
}
SDL_Mouse *mouse = SDL_GetMouse();
SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
if (!driverdata) {
return; /* can happen when returning from fullscreen Space on shutdown */
}
const SDL_bool seenWarp = driverdata->seenWarp;
driverdata->seenWarp = NO;

View file

@ -49,11 +49,15 @@
#endif
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
@interface SDLWindow : NSWindow
/* These are needed for borderless/fullscreen windows */
- (BOOL)canBecomeKeyWindow;
- (BOOL)canBecomeMainWindow;
- (void)sendEvent:(NSEvent *)event;
- (void)doCommandBySelector:(SEL)aSelector;
@end
@implementation SDLWindow
@ -84,14 +88,22 @@
[delegate windowDidFinishMoving];
}
}
/* We'll respond to selectors by doing nothing so we don't beep.
* The escape key gets converted to a "cancel" selector, etc.
*/
- (void)doCommandBySelector:(SEL)aSelector
{
/*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
}
@end
static Uint32 s_moveHack;
static void ConvertNSRect(NSScreen *screen, NSRect *r)
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
{
NSRect visibleScreen = [screen visibleFrame];
NSRect visibleScreen = fullscreen ? [screen frame] : [screen visibleFrame];
r->origin.y = (visibleScreen.origin.y + visibleScreen.size.height) - r->origin.y - r->size.height;
}
@ -269,6 +281,8 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
return NO; /* Spaces are forcibly disabled. */
} else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
return NO; /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
} else if (!state && ((window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
return NO; /* we only handle leaving the Space on windows that were previously FULLSCREEN_DESKTOP. */
} else if (state == isFullscreenSpace) {
return YES; /* already there. */
}
@ -411,8 +425,9 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
int x, y;
SDL_Window *window = _data->window;
NSWindow *nswindow = _data->nswindow;
BOOL fullscreen = window->flags & FULLSCREEN_MASK;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], fullscreen, &rect);
if (s_moveHack) {
SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
@ -423,7 +438,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
/* Cocoa is adjusting the window in response to a mode change */
rect.origin.x = window->x;
rect.origin.y = window->y;
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], fullscreen, &rect);
[nswindow setFrameOrigin:rect.origin];
return;
}
@ -448,7 +463,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
NSWindow *nswindow = _data->nswindow;
int x, y, w, h;
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
x = (int)rect.origin.x;
y = (int)rect.origin.y;
w = (int)rect.size.width;
@ -962,7 +977,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
SDL_WindowData *data;
/* Allocate the window data */
data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
window->driverdata = data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
if (!data) {
return SDL_OutOfMemory();
}
@ -980,7 +995,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
/* Fill in the SDL window with the window data */
{
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
window->x = (int)rect.origin.x;
window->y = (int)rect.origin.y;
window->w = (int)rect.size.width;
@ -1056,7 +1071,7 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
ConvertNSRect([[NSScreen screens] objectAtIndex:0], &rect);
ConvertNSRect([[NSScreen screens] objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
style = GetWindowStyle(window);
@ -1184,7 +1199,7 @@ Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
rect.origin.y = window->y;
rect.size.width = window->w;
rect.size.height = window->h;
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
moveHack = s_moveHack;
s_moveHack = 0;
@ -1384,7 +1399,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
rect.origin.y = bounds.y;
rect.size.width = bounds.w;
rect.size.height = bounds.h;
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], fullscreen, &rect);
/* Hack to fix origin on Mac OS X 10.4 */
NSRect screenRect = [[nswindow screen] frame];
@ -1402,7 +1417,7 @@ Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display
rect.origin.y = window->windowed.y;
rect.size.width = window->windowed.w;
rect.size.height = window->windowed.h;
ConvertNSRect([nswindow screen], &rect);
ConvertNSRect([nswindow screen], fullscreen, &rect);
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
@ -1529,6 +1544,8 @@ Cocoa_DestroyWindow(_THIS, SDL_Window * window)
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
window->driverdata = NULL;
if (data) {
[data->listener close];
[data->listener release];
@ -1585,6 +1602,20 @@ Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
succeeded = SDL_TRUE;
/* Wait for the transition to complete, so application changes
take effect properly (e.g. setting the window size, etc.)
*/
const int limit = 10000;
int count = 0;
while ([data->listener isInFullscreenSpaceTransition]) {
if ( ++count == limit ) {
/* Uh oh, transition isn't completing. Should we assert? */
break;
}
SDL_Delay(1);
SDL_PumpEvents();
}
}
[pool release];

View file

@ -224,12 +224,12 @@ HandleMotionEvent(MirMotionEvent const motion, SDL_Window* sdl_window)
{
int cord_index;
for (cord_index = 0; cord_index < motion.pointer_count; cord_index++) {
if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_mouse) {
HandleMouseEvent(motion, cord_index, sdl_window);
}
else if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_finger) {
if (motion.pointer_coordinates[cord_index].tool_type == mir_motion_tool_type_finger) {
HandleTouchEvent(motion, cord_index, sdl_window);
}
else {
HandleMouseEvent(motion, cord_index, sdl_window);
}
}
}

View file

@ -110,6 +110,12 @@ MIR_WarpMouse(SDL_Window* window, int x, int y)
SDL_Unsupported();
}
static void
MIR_WarpMouseGlobal(int x, int y)
{
SDL_Unsupported();
}
static int
MIR_SetRelativeMouseMode(SDL_bool enabled)
{
@ -126,6 +132,7 @@ MIR_InitMouse()
mouse->ShowCursor = MIR_ShowCursor;
mouse->FreeCursor = MIR_FreeCursor;
mouse->WarpMouse = MIR_WarpMouse;
mouse->WarpMouseGlobal = MIR_WarpMouseGlobal;
mouse->CreateSystemCursor = MIR_CreateSystemCursor;
mouse->SetRelativeMouseMode = MIR_SetRelativeMouseMode;

View file

@ -0,0 +1,432 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_naclevents_c.h"
#include "SDL_naclvideo.h"
#include "ppapi_simple/ps_event.h"
/* Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent */
static SDL_Scancode NACL_Keycodes[] = {
SDL_SCANCODE_UNKNOWN, /* 0 */
SDL_SCANCODE_UNKNOWN, /* 1 */
SDL_SCANCODE_UNKNOWN, /* 2 */
SDL_SCANCODE_CANCEL, /* DOM_VK_CANCEL 3 */
SDL_SCANCODE_UNKNOWN, /* 4 */
SDL_SCANCODE_UNKNOWN, /* 5 */
SDL_SCANCODE_HELP, /* DOM_VK_HELP 6 */
SDL_SCANCODE_UNKNOWN, /* 7 */
SDL_SCANCODE_BACKSPACE, /* DOM_VK_BACK_SPACE 8 */
SDL_SCANCODE_TAB, /* DOM_VK_TAB 9 */
SDL_SCANCODE_UNKNOWN, /* 10 */
SDL_SCANCODE_UNKNOWN, /* 11 */
SDL_SCANCODE_CLEAR, /* DOM_VK_CLEAR 12 */
SDL_SCANCODE_RETURN, /* DOM_VK_RETURN 13 */
SDL_SCANCODE_RETURN, /* DOM_VK_ENTER 14 */
SDL_SCANCODE_UNKNOWN, /* 15 */
SDL_SCANCODE_LSHIFT, /* DOM_VK_SHIFT 16 */
SDL_SCANCODE_LCTRL, /* DOM_VK_CONTROL 17 */
SDL_SCANCODE_LALT, /* DOM_VK_ALT 18 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_PAUSE 19 */
SDL_SCANCODE_CAPSLOCK, /* DOM_VK_CAPS_LOCK 20 */
SDL_SCANCODE_LANG1, /* DOM_VK_KANA DOM_VK_HANGUL 21 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_EISU 22 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_JUNJA 23 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_FINAL 24 */
SDL_SCANCODE_LANG2, /* DOM_VK_HANJA DOM_VK_KANJI 25 */
SDL_SCANCODE_UNKNOWN, /* 26 */
SDL_SCANCODE_ESCAPE, /* DOM_VK_ESCAPE 27 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_CONVERT 28 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_NONCONVERT 29 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_ACCEPT 30 */
SDL_SCANCODE_MODE, /* DOM_VK_MODECHANGE 31 */
SDL_SCANCODE_SPACE, /* DOM_VK_SPACE 32 */
SDL_SCANCODE_PAGEUP, /* DOM_VK_PAGE_UP 33 */
SDL_SCANCODE_PAGEDOWN, /* DOM_VK_PAGE_DOWN 34 */
SDL_SCANCODE_END, /* DOM_VK_END 35 */
SDL_SCANCODE_HOME, /* DOM_VK_HOME 36 */
SDL_SCANCODE_LEFT, /* DOM_VK_LEFT 37 */
SDL_SCANCODE_UP, /* DOM_VK_UP 38 */
SDL_SCANCODE_RIGHT, /* DOM_VK_RIGHT 39 */
SDL_SCANCODE_DOWN, /* DOM_VK_DOWN 40 */
SDL_SCANCODE_SELECT, /* DOM_VK_SELECT 41 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_PRINT 42 */
SDL_SCANCODE_EXECUTE, /* DOM_VK_EXECUTE 43 */
SDL_SCANCODE_PRINTSCREEN, /* DOM_VK_PRINTSCREEN 44 */
SDL_SCANCODE_INSERT, /* DOM_VK_INSERT 45 */
SDL_SCANCODE_DELETE, /* DOM_VK_DELETE 46 */
SDL_SCANCODE_UNKNOWN, /* 47 */
SDL_SCANCODE_0, /* DOM_VK_0 48 */
SDL_SCANCODE_1, /* DOM_VK_1 49 */
SDL_SCANCODE_2, /* DOM_VK_2 50 */
SDL_SCANCODE_3, /* DOM_VK_3 51 */
SDL_SCANCODE_4, /* DOM_VK_4 52 */
SDL_SCANCODE_5, /* DOM_VK_5 53 */
SDL_SCANCODE_6, /* DOM_VK_6 54 */
SDL_SCANCODE_7, /* DOM_VK_7 55 */
SDL_SCANCODE_8, /* DOM_VK_8 56 */
SDL_SCANCODE_9, /* DOM_VK_9 57 */
SDL_SCANCODE_KP_COLON, /* DOM_VK_COLON 58 */
SDL_SCANCODE_SEMICOLON, /* DOM_VK_SEMICOLON 59 */
SDL_SCANCODE_KP_LESS, /* DOM_VK_LESS_THAN 60 */
SDL_SCANCODE_EQUALS, /* DOM_VK_EQUALS 61 */
SDL_SCANCODE_KP_GREATER, /* DOM_VK_GREATER_THAN 62 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_QUESTION_MARK 63 */
SDL_SCANCODE_KP_AT, /* DOM_VK_AT 64 */
SDL_SCANCODE_A, /* DOM_VK_A 65 */
SDL_SCANCODE_B, /* DOM_VK_B 66 */
SDL_SCANCODE_C, /* DOM_VK_C 67 */
SDL_SCANCODE_D, /* DOM_VK_D 68 */
SDL_SCANCODE_E, /* DOM_VK_E 69 */
SDL_SCANCODE_F, /* DOM_VK_F 70 */
SDL_SCANCODE_G, /* DOM_VK_G 71 */
SDL_SCANCODE_H, /* DOM_VK_H 72 */
SDL_SCANCODE_I, /* DOM_VK_I 73 */
SDL_SCANCODE_J, /* DOM_VK_J 74 */
SDL_SCANCODE_K, /* DOM_VK_K 75 */
SDL_SCANCODE_L, /* DOM_VK_L 76 */
SDL_SCANCODE_M, /* DOM_VK_M 77 */
SDL_SCANCODE_N, /* DOM_VK_N 78 */
SDL_SCANCODE_O, /* DOM_VK_O 79 */
SDL_SCANCODE_P, /* DOM_VK_P 80 */
SDL_SCANCODE_Q, /* DOM_VK_Q 81 */
SDL_SCANCODE_R, /* DOM_VK_R 82 */
SDL_SCANCODE_S, /* DOM_VK_S 83 */
SDL_SCANCODE_T, /* DOM_VK_T 84 */
SDL_SCANCODE_U, /* DOM_VK_U 85 */
SDL_SCANCODE_V, /* DOM_VK_V 86 */
SDL_SCANCODE_W, /* DOM_VK_W 87 */
SDL_SCANCODE_X, /* DOM_VK_X 88 */
SDL_SCANCODE_Y, /* DOM_VK_Y 89 */
SDL_SCANCODE_Z, /* DOM_VK_Z 90 */
SDL_SCANCODE_LGUI, /* DOM_VK_WIN 91 */
SDL_SCANCODE_UNKNOWN, /* 92 */
SDL_SCANCODE_APPLICATION, /* DOM_VK_CONTEXT_MENU 93 */
SDL_SCANCODE_UNKNOWN, /* 94 */
SDL_SCANCODE_SLEEP, /* DOM_VK_SLEEP 95 */
SDL_SCANCODE_KP_0, /* DOM_VK_NUMPAD0 96 */
SDL_SCANCODE_KP_1, /* DOM_VK_NUMPAD1 97 */
SDL_SCANCODE_KP_2, /* DOM_VK_NUMPAD2 98 */
SDL_SCANCODE_KP_3, /* DOM_VK_NUMPAD3 99 */
SDL_SCANCODE_KP_4, /* DOM_VK_NUMPAD4 100 */
SDL_SCANCODE_KP_5, /* DOM_VK_NUMPAD5 101 */
SDL_SCANCODE_KP_6, /* DOM_VK_NUMPAD6 102 */
SDL_SCANCODE_KP_7, /* DOM_VK_NUMPAD7 103 */
SDL_SCANCODE_KP_8, /* DOM_VK_NUMPAD8 104 */
SDL_SCANCODE_KP_9, /* DOM_VK_NUMPAD9 105 */
SDL_SCANCODE_KP_MULTIPLY, /* DOM_VK_MULTIPLY 106 */
SDL_SCANCODE_KP_PLUS, /* DOM_VK_ADD 107 */
SDL_SCANCODE_KP_COMMA, /* DOM_VK_SEPARATOR 108 */
SDL_SCANCODE_KP_MINUS, /* DOM_VK_SUBTRACT 109 */
SDL_SCANCODE_KP_PERIOD, /* DOM_VK_DECIMAL 110 */
SDL_SCANCODE_KP_DIVIDE, /* DOM_VK_DIVIDE 111 */
SDL_SCANCODE_F1, /* DOM_VK_F1 112 */
SDL_SCANCODE_F2, /* DOM_VK_F2 113 */
SDL_SCANCODE_F3, /* DOM_VK_F3 114 */
SDL_SCANCODE_F4, /* DOM_VK_F4 115 */
SDL_SCANCODE_F5, /* DOM_VK_F5 116 */
SDL_SCANCODE_F6, /* DOM_VK_F6 117 */
SDL_SCANCODE_F7, /* DOM_VK_F7 118 */
SDL_SCANCODE_F8, /* DOM_VK_F8 119 */
SDL_SCANCODE_F9, /* DOM_VK_F9 120 */
SDL_SCANCODE_F10, /* DOM_VK_F10 121 */
SDL_SCANCODE_F11, /* DOM_VK_F11 122 */
SDL_SCANCODE_F12, /* DOM_VK_F12 123 */
SDL_SCANCODE_F13, /* DOM_VK_F13 124 */
SDL_SCANCODE_F14, /* DOM_VK_F14 125 */
SDL_SCANCODE_F15, /* DOM_VK_F15 126 */
SDL_SCANCODE_F16, /* DOM_VK_F16 127 */
SDL_SCANCODE_F17, /* DOM_VK_F17 128 */
SDL_SCANCODE_F18, /* DOM_VK_F18 129 */
SDL_SCANCODE_F19, /* DOM_VK_F19 130 */
SDL_SCANCODE_F20, /* DOM_VK_F20 131 */
SDL_SCANCODE_F21, /* DOM_VK_F21 132 */
SDL_SCANCODE_F22, /* DOM_VK_F22 133 */
SDL_SCANCODE_F23, /* DOM_VK_F23 134 */
SDL_SCANCODE_F24, /* DOM_VK_F24 135 */
SDL_SCANCODE_UNKNOWN, /* 136 */
SDL_SCANCODE_UNKNOWN, /* 137 */
SDL_SCANCODE_UNKNOWN, /* 138 */
SDL_SCANCODE_UNKNOWN, /* 139 */
SDL_SCANCODE_UNKNOWN, /* 140 */
SDL_SCANCODE_UNKNOWN, /* 141 */
SDL_SCANCODE_UNKNOWN, /* 142 */
SDL_SCANCODE_UNKNOWN, /* 143 */
SDL_SCANCODE_NUMLOCKCLEAR, /* DOM_VK_NUM_LOCK 144 */
SDL_SCANCODE_SCROLLLOCK, /* DOM_VK_SCROLL_LOCK 145 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_JISHO 146 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_MASSHOU 147 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_TOUROKU 148 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_LOYA 149 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_ROYA 150 */
SDL_SCANCODE_UNKNOWN, /* 151 */
SDL_SCANCODE_UNKNOWN, /* 152 */
SDL_SCANCODE_UNKNOWN, /* 153 */
SDL_SCANCODE_UNKNOWN, /* 154 */
SDL_SCANCODE_UNKNOWN, /* 155 */
SDL_SCANCODE_UNKNOWN, /* 156 */
SDL_SCANCODE_UNKNOWN, /* 157 */
SDL_SCANCODE_UNKNOWN, /* 158 */
SDL_SCANCODE_UNKNOWN, /* 159 */
SDL_SCANCODE_GRAVE, /* DOM_VK_CIRCUMFLEX 160 */
SDL_SCANCODE_KP_EXCLAM, /* DOM_VK_EXCLAMATION 161 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_DOUBLE_QUOTE 162 */
SDL_SCANCODE_KP_HASH, /* DOM_VK_HASH 163 */
SDL_SCANCODE_CURRENCYUNIT, /* DOM_VK_DOLLAR 164 */
SDL_SCANCODE_KP_PERCENT, /* DOM_VK_PERCENT 165 */
SDL_SCANCODE_KP_AMPERSAND, /* DOM_VK_AMPERSAND 166 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_UNDERSCORE 167 */
SDL_SCANCODE_KP_LEFTPAREN, /* DOM_VK_OPEN_PAREN 168 */
SDL_SCANCODE_KP_RIGHTPAREN, /* DOM_VK_CLOSE_PAREN 169 */
SDL_SCANCODE_KP_MULTIPLY, /* DOM_VK_ASTERISK 170 */
SDL_SCANCODE_KP_PLUS, /* DOM_VK_PLUS 171 */
SDL_SCANCODE_KP_PLUS, /* DOM_VK_PIPE 172 */
SDL_SCANCODE_MINUS, /* DOM_VK_HYPHEN_MINUS 173 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_OPEN_CURLY_BRACKET 174 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_CLOSE_CURLY_BRACKET 175 */
SDL_SCANCODE_NONUSBACKSLASH, /* DOM_VK_TILDE 176 */
SDL_SCANCODE_UNKNOWN, /* 177 */
SDL_SCANCODE_UNKNOWN, /* 178 */
SDL_SCANCODE_UNKNOWN, /* 179 */
SDL_SCANCODE_UNKNOWN, /* 180 */
SDL_SCANCODE_MUTE, /* DOM_VK_VOLUME_MUTE 181 */
SDL_SCANCODE_VOLUMEDOWN, /* DOM_VK_VOLUME_DOWN 182 */
SDL_SCANCODE_VOLUMEUP, /* DOM_VK_VOLUME_UP 183 */
SDL_SCANCODE_UNKNOWN, /* 184 */
SDL_SCANCODE_UNKNOWN, /* 185 */
SDL_SCANCODE_UNKNOWN, /* 186 */
SDL_SCANCODE_UNKNOWN, /* 187 */
SDL_SCANCODE_COMMA, /* DOM_VK_COMMA 188 */
SDL_SCANCODE_UNKNOWN, /* 189 */
SDL_SCANCODE_PERIOD, /* DOM_VK_PERIOD 190 */
SDL_SCANCODE_SLASH, /* DOM_VK_SLASH 191 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_BACK_QUOTE 192 */
SDL_SCANCODE_UNKNOWN, /* 193 */
SDL_SCANCODE_UNKNOWN, /* 194 */
SDL_SCANCODE_UNKNOWN, /* 195 */
SDL_SCANCODE_UNKNOWN, /* 196 */
SDL_SCANCODE_UNKNOWN, /* 197 */
SDL_SCANCODE_UNKNOWN, /* 198 */
SDL_SCANCODE_UNKNOWN, /* 199 */
SDL_SCANCODE_UNKNOWN, /* 200 */
SDL_SCANCODE_UNKNOWN, /* 201 */
SDL_SCANCODE_UNKNOWN, /* 202 */
SDL_SCANCODE_UNKNOWN, /* 203 */
SDL_SCANCODE_UNKNOWN, /* 204 */
SDL_SCANCODE_UNKNOWN, /* 205 */
SDL_SCANCODE_UNKNOWN, /* 206 */
SDL_SCANCODE_UNKNOWN, /* 207 */
SDL_SCANCODE_UNKNOWN, /* 208 */
SDL_SCANCODE_UNKNOWN, /* 209 */
SDL_SCANCODE_UNKNOWN, /* 210 */
SDL_SCANCODE_UNKNOWN, /* 211 */
SDL_SCANCODE_UNKNOWN, /* 212 */
SDL_SCANCODE_UNKNOWN, /* 213 */
SDL_SCANCODE_UNKNOWN, /* 214 */
SDL_SCANCODE_UNKNOWN, /* 215 */
SDL_SCANCODE_UNKNOWN, /* 216 */
SDL_SCANCODE_UNKNOWN, /* 217 */
SDL_SCANCODE_UNKNOWN, /* 218 */
SDL_SCANCODE_LEFTBRACKET, /* DOM_VK_OPEN_BRACKET 219 */
SDL_SCANCODE_BACKSLASH, /* DOM_VK_BACK_SLASH 220 */
SDL_SCANCODE_RIGHTBRACKET, /* DOM_VK_CLOSE_BRACKET 221 */
SDL_SCANCODE_APOSTROPHE, /* DOM_VK_QUOTE 222 */
SDL_SCANCODE_UNKNOWN, /* 223 */
SDL_SCANCODE_RGUI, /* DOM_VK_META 224 */
SDL_SCANCODE_RALT, /* DOM_VK_ALTGR 225 */
SDL_SCANCODE_UNKNOWN, /* 226 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_HELP 227 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_00 228 */
SDL_SCANCODE_UNKNOWN, /* 229 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_CLEAR 230 */
SDL_SCANCODE_UNKNOWN, /* 231 */
SDL_SCANCODE_UNKNOWN, /* 232 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_RESET 233 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_JUMP 234 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA1 235 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA2 236 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA3 237 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_WSCTRL 238 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_CUSEL 239 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_ATTN 240 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FINISH 241 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_COPY 242 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_AUTO 243 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_ENLW 244 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_BACKTAB 245 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_ATTN 246 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_CRSEL 247 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_EXSEL 248 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_EREOF 249 */
SDL_SCANCODE_AUDIOPLAY, /* DOM_VK_PLAY 250 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_ZOOM 251 */
SDL_SCANCODE_UNKNOWN, /* 252 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_PA1 253 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_CLEAR 254 */
SDL_SCANCODE_UNKNOWN, /* 255 */
};
static Uint8 SDL_NACL_translate_mouse_button(int32_t button) {
switch (button) {
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
return SDL_BUTTON_LEFT;
case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
return SDL_BUTTON_MIDDLE;
case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
return SDL_BUTTON_RIGHT;
case PP_INPUTEVENT_MOUSEBUTTON_NONE:
default:
return 0;
}
}
static SDL_Scancode
SDL_NACL_translate_keycode(int keycode)
{
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
if (keycode < SDL_arraysize(NACL_Keycodes)) {
scancode = NACL_Keycodes[keycode];
}
if (scancode == SDL_SCANCODE_UNKNOWN) {
SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> NACL KeyCode %d \n", keycode);
}
return scancode;
}
void NACL_PumpEvents(_THIS) {
PSEvent* ps_event;
PP_Resource event;
PP_InputEvent_Type type;
PP_InputEvent_Modifier modifiers;
struct PP_Rect rect;
struct PP_FloatPoint fp;
struct PP_Point location;
struct PP_Var var;
const char *str;
char text[64];
Uint32 str_len;
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();
if (driverdata->window) {
while ((ps_event = PSEventTryAcquire()) != NULL) {
event = ps_event->as_resource;
switch(ps_event->type) {
/* From DidChangeView, contains a view resource */
case PSE_INSTANCE_DIDCHANGEVIEW:
driverdata->ppb_view->GetRect(event, &rect);
NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN);
// FIXME: Rebuild context? See life.c UpdateContext
break;
/* From HandleInputEvent, contains an input resource. */
case PSE_INSTANCE_HANDLEINPUT:
type = driverdata->ppb_input_event->GetType(event);
modifiers = driverdata->ppb_input_event->GetModifiers(event);
switch(type) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
break;
case PP_INPUTEVENT_TYPE_MOUSEUP:
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
break;
case PP_INPUTEVENT_TYPE_WHEEL:
/* FIXME: GetTicks provides high resolution scroll events */
fp = driverdata->ppb_wheel_input_event->GetDelta(event);
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y);
break;
case PP_INPUTEVENT_TYPE_MOUSEENTER:
case PP_INPUTEVENT_TYPE_MOUSELEAVE:
/* FIXME: Mouse Focus */
break;
case PP_INPUTEVENT_TYPE_MOUSEMOVE:
location = driverdata->ppb_mouse_input_event->GetPosition(event);
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y);
break;
case PP_INPUTEVENT_TYPE_TOUCHSTART:
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
case PP_INPUTEVENT_TYPE_TOUCHEND:
case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
/* FIXME: Touch events */
break;
case PP_INPUTEVENT_TYPE_KEYDOWN:
SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
break;
case PP_INPUTEVENT_TYPE_KEYUP:
SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
break;
case PP_INPUTEVENT_TYPE_CHAR:
var = driverdata->ppb_keyboard_input_event->GetCharacterText(event);
str = driverdata->ppb_var->VarToUtf8(var, &str_len);
/* str is not null terminated! */
if ( str_len >= SDL_arraysize(text) ) {
str_len = SDL_arraysize(text) - 1;
}
SDL_strlcpy(text, str, str_len );
text[str_len] = '\0';
SDL_SendKeyboardText(text);
/* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/
break;
default:
break;
}
break;
/* From HandleMessage, contains a PP_Var. */
case PSE_INSTANCE_HANDLEMESSAGE:
break;
/* From DidChangeFocus, contains a PP_Bool with the current focus state. */
case PSE_INSTANCE_DIDCHANGEFOCUS:
break;
/* When the 3D context is lost, no resource. */
case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST:
break;
/* When the mouse lock is lost. */
case PSE_MOUSELOCK_MOUSELOCKLOST:
break;
default:
break;
}
PSEventRelease(ps_event);
}
}
}

View file

@ -0,0 +1,30 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclevents_c_h
#define _SDL_naclevents_c_h
#include "SDL_naclvideo.h"
extern void NACL_PumpEvents(_THIS);
#endif /* _SDL_naclevents_c_h */

View file

@ -0,0 +1,24 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
#endif /* SDL_VIDEO_DRIVER_NACL */

View file

@ -0,0 +1,171 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
/* NaCl SDL video GLES 2 driver implementation */
#include "SDL_video.h"
#include "SDL_naclvideo.h"
#if SDL_LOADSO_DLOPEN
#include "dlfcn.h"
#endif
#include "ppapi/gles2/gl2ext_ppapi.h"
#include "ppapi_simple/ps.h"
/* GL functions */
int
NACL_GLES_LoadLibrary(_THIS, const char *path)
{
/* FIXME: Support dynamic linking when PNACL supports it */
return glInitializePPAPI(PSGetInterface) == 0;
}
void *
NACL_GLES_GetProcAddress(_THIS, const char *proc)
{
#if SDL_LOADSO_DLOPEN
return dlsym( 0 /* RTLD_DEFAULT */, proc);
#else
return NULL;
#endif
}
void
NACL_GLES_UnloadLibrary(_THIS)
{
/* FIXME: Support dynamic linking when PNACL supports it */
glTerminatePPAPI();
}
int
NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext sdl_context)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
/* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
driverdata->ppb_instance->BindGraphics(driverdata->instance, (PP_Resource) sdl_context);
glSetCurrentContextPPAPI((PP_Resource) sdl_context);
return 0;
}
SDL_GLContext
NACL_GLES_CreateContext(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
PP_Resource context, share_context = 0;
/* 64 seems nice. */
Sint32 attribs[64];
int i = 0;
if (_this->gl_config.share_with_current_context) {
share_context = (PP_Resource) SDL_GL_GetCurrentContext();
}
/* FIXME: Some ATTRIBS from PP_Graphics3DAttrib are not set here */
attribs[i++] = PP_GRAPHICS3DATTRIB_WIDTH;
attribs[i++] = window->w;
attribs[i++] = PP_GRAPHICS3DATTRIB_HEIGHT;
attribs[i++] = window->h;
attribs[i++] = PP_GRAPHICS3DATTRIB_RED_SIZE;
attribs[i++] = _this->gl_config.red_size;
attribs[i++] = PP_GRAPHICS3DATTRIB_GREEN_SIZE;
attribs[i++] = _this->gl_config.green_size;
attribs[i++] = PP_GRAPHICS3DATTRIB_BLUE_SIZE;
attribs[i++] = _this->gl_config.blue_size;
if (_this->gl_config.alpha_size) {
attribs[i++] = PP_GRAPHICS3DATTRIB_ALPHA_SIZE;
attribs[i++] = _this->gl_config.alpha_size;
}
/*if (_this->gl_config.buffer_size) {
attribs[i++] = EGL_BUFFER_SIZE;
attribs[i++] = _this->gl_config.buffer_size;
}*/
attribs[i++] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
attribs[i++] = _this->gl_config.depth_size;
if (_this->gl_config.stencil_size) {
attribs[i++] = PP_GRAPHICS3DATTRIB_STENCIL_SIZE;
attribs[i++] = _this->gl_config.stencil_size;
}
if (_this->gl_config.multisamplebuffers) {
attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS;
attribs[i++] = _this->gl_config.multisamplebuffers;
}
if (_this->gl_config.multisamplesamples) {
attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLES;
attribs[i++] = _this->gl_config.multisamplesamples;
}
attribs[i++] = PP_GRAPHICS3DATTRIB_NONE;
context = driverdata->ppb_graphics->Create(driverdata->instance, share_context, attribs);
if (context) {
/* We need to make the context current, otherwise nothing works */
SDL_GL_MakeCurrent(window, (SDL_GLContext) context);
}
return (SDL_GLContext) context;
}
int
NACL_GLES_SetSwapInterval(_THIS, int interval)
{
/* STUB */
return 0;
}
int
NACL_GLES_GetSwapInterval(_THIS)
{
/* STUB */
return 0;
}
void
NACL_GLES_SwapWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
struct PP_CompletionCallback callback = { NULL, 0, PP_COMPLETIONCALLBACK_FLAG_NONE };
driverdata->ppb_graphics->SwapBuffers((PP_Resource) SDL_GL_GetCurrentContext(), callback );
}
void
NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
driverdata->ppb_core->ReleaseResource((PP_Resource) context);
}
#endif /* SDL_VIDEO_DRIVER_NACL */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,38 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclgl_h
#define _SDL_naclgl_h
extern int NACL_GLES_LoadLibrary(_THIS, const char *path);
extern void *NACL_GLES_GetProcAddress(_THIS, const char *proc);
extern void NACL_GLES_UnloadLibrary(_THIS);
extern SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window * window);
extern int NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
extern int NACL_GLES_SetSwapInterval(_THIS, int interval);
extern int NACL_GLES_GetSwapInterval(_THIS);
extern void NACL_GLES_SwapWindow(_THIS, SDL_Window * window);
extern void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context);
#endif /* _SDL_naclgl_h */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,183 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi_simple/ps.h"
#include "ppapi_simple/ps_interface.h"
#include "ppapi_simple/ps_event.h"
#include "nacl_io/nacl_io.h"
#include "SDL_naclvideo.h"
#include "SDL_naclwindow.h"
#include "SDL_naclevents_c.h"
#include "SDL_naclopengles.h"
#include "SDL_video.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
#define NACLVID_DRIVER_NAME "nacl"
/* Static init required because NACL_SetScreenResolution
* may appear even before SDL starts and we want to remember
* the window width and height
*/
static SDL_VideoData nacl = {0};
void
NACL_SetScreenResolution(int width, int height, Uint32 format)
{
PP_Resource context;
nacl.w = width;
nacl.h = height;
nacl.format = format;
if (nacl.window) {
nacl.window->w = width;
nacl.window->h = height;
SDL_SendWindowEvent(nacl.window, SDL_WINDOWEVENT_RESIZED, width, height);
}
/* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
context = (PP_Resource) SDL_GL_GetCurrentContext();
if (context) {
PSInterfaceGraphics3D()->ResizeBuffers(context, width, height);
}
}
/* Initialization/Query functions */
static int NACL_VideoInit(_THIS);
static void NACL_VideoQuit(_THIS);
static int NACL_Available(void) {
return PSGetInstanceId() != 0;
}
static void NACL_DeleteDevice(SDL_VideoDevice *device) {
SDL_VideoData *driverdata = (SDL_VideoData*) device->driverdata;
driverdata->ppb_core->ReleaseResource((PP_Resource) driverdata->ppb_message_loop);
SDL_free(device->driverdata);
SDL_free(device);
}
static int
NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
return 0;
}
static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_OutOfMemory();
return NULL;
}
device->driverdata = &nacl;
/* Set the function pointers */
device->VideoInit = NACL_VideoInit;
device->VideoQuit = NACL_VideoQuit;
device->PumpEvents = NACL_PumpEvents;
device->CreateWindow = NACL_CreateWindow;
device->SetWindowTitle = NACL_SetWindowTitle;
device->DestroyWindow = NACL_DestroyWindow;
device->SetDisplayMode = NACL_SetDisplayMode;
device->free = NACL_DeleteDevice;
/* GL pointers */
device->GL_LoadLibrary = NACL_GLES_LoadLibrary;
device->GL_GetProcAddress = NACL_GLES_GetProcAddress;
device->GL_UnloadLibrary = NACL_GLES_UnloadLibrary;
device->GL_CreateContext = NACL_GLES_CreateContext;
device->GL_MakeCurrent = NACL_GLES_MakeCurrent;
device->GL_SetSwapInterval = NACL_GLES_SetSwapInterval;
device->GL_GetSwapInterval = NACL_GLES_GetSwapInterval;
device->GL_SwapWindow = NACL_GLES_SwapWindow;
device->GL_DeleteContext = NACL_GLES_DeleteContext;
return device;
}
VideoBootStrap NACL_bootstrap = {
NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
NACL_Available, NACL_CreateDevice
};
int NACL_VideoInit(_THIS) {
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayMode mode;
SDL_zero(mode);
mode.format = driverdata->format;
mode.w = driverdata->w;
mode.h = driverdata->h;
mode.refresh_rate = 0;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}
SDL_AddDisplayMode(&_this->displays[0], &mode);
PSInterfaceInit();
driverdata->instance = PSGetInstanceId();
driverdata->ppb_graphics = PSInterfaceGraphics3D();
driverdata->ppb_message_loop = PSInterfaceMessageLoop();
driverdata->ppb_core = PSInterfaceCore();
driverdata->ppb_fullscreen = PSInterfaceFullscreen();
driverdata->ppb_instance = PSInterfaceInstance();
driverdata->ppb_image_data = PSInterfaceImageData();
driverdata->ppb_view = PSInterfaceView();
driverdata->ppb_var = PSInterfaceVar();
driverdata->ppb_input_event = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE);
driverdata->ppb_keyboard_input_event = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
driverdata->ppb_mouse_input_event = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE);
driverdata->ppb_wheel_input_event = (PPB_WheelInputEvent*) PSGetInterface(PPB_WHEEL_INPUT_EVENT_INTERFACE);
driverdata->ppb_touch_input_event = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE);
driverdata->message_loop = driverdata->ppb_message_loop->Create(driverdata->instance);
PSEventSetFilter(PSE_ALL);
/* We're done! */
return 0;
}
void NACL_VideoQuit(_THIS) {
}
#endif /* SDL_VIDEO_DRIVER_NACL */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,67 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclvideo_h
#define _SDL_naclvideo_h
#include "../SDL_sysvideo.h"
#include "ppapi_simple/ps_interface.h"
#include "ppapi/c/pp_input_event.h"
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *_this
/* Private display data */
typedef struct SDL_VideoData {
Uint32 format;
int w, h;
SDL_Window *window;
const PPB_Graphics3D *ppb_graphics;
const PPB_MessageLoop *ppb_message_loop;
const PPB_Core *ppb_core;
const PPB_Fullscreen *ppb_fullscreen;
const PPB_Instance *ppb_instance;
const PPB_ImageData *ppb_image_data;
const PPB_View *ppb_view;
const PPB_Var *ppb_var;
const PPB_InputEvent *ppb_input_event;
const PPB_KeyboardInputEvent *ppb_keyboard_input_event;
const PPB_MouseInputEvent *ppb_mouse_input_event;
const PPB_WheelInputEvent *ppb_wheel_input_event;
const PPB_TouchInputEvent *ppb_touch_input_event;
PP_Resource message_loop;
PP_Instance instance;
/* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
/* PP_Resource context; */
} SDL_VideoData;
extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
#endif /* _SDL_naclvideo_h */

View file

@ -0,0 +1,79 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
#include "../SDL_sysvideo.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "SDL_naclvideo.h"
#include "SDL_naclwindow.h"
int
NACL_CreateWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
if (driverdata->window) {
SDL_SetError("NaCl only supports one window");
return -1;
}
driverdata->window = window;
/* Adjust the window data to match the screen */
window->x = 0;
window->y = 0;
window->w = driverdata->w;
window->h = driverdata->h;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
window->flags &= ~SDL_WINDOW_HIDDEN;
window->flags |= SDL_WINDOW_SHOWN; /* only one window on NaCl */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
window->flags |= SDL_WINDOW_OPENGL;
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
return 0;
}
void
NACL_SetWindowTitle(_THIS, SDL_Window * window)
{
/* TODO */
}
void
NACL_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
if (window == driverdata->window) {
driverdata->window = NULL;
}
}
#endif /* SDL_VIDEO_DRIVER_NACL */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -0,0 +1,32 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclwindow_h
#define _SDL_naclwindow_h
extern int NACL_CreateWindow(_THIS, SDL_Window * window);
extern void NACL_SetWindowTitle(_THIS, SDL_Window * window);
extern void NACL_DestroyWindow(_THIS, SDL_Window * window);
#endif /* _SDL_naclwindow_h */
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -48,6 +48,7 @@ static int RPI_ShowCursor(SDL_Cursor * cursor);
static void RPI_MoveCursor(SDL_Cursor * cursor);
static void RPI_FreeCursor(SDL_Cursor * cursor);
static void RPI_WarpMouse(SDL_Window * window, int x, int y);
static void RPI_WarpMouseGlobal(int x, int y);
static SDL_Cursor *
RPI_CreateDefaultCursor(void)
@ -210,6 +211,13 @@ RPI_FreeCursor(SDL_Cursor * cursor)
/* Warp the mouse to (x,y) */
static void
RPI_WarpMouse(SDL_Window * window, int x, int y)
{
RPI_WarpMouseGlobal(x, y);
}
/* Warp the mouse to (x,y) */
static void
RPI_WarpMouseGlobal(int x, int y)
{
RPI_CursorData *curdata;
DISPMANX_UPDATE_HANDLE_T update;
@ -254,6 +262,7 @@ RPI_InitMouse(_THIS)
mouse->MoveCursor = RPI_MoveCursor;
mouse->FreeCursor = RPI_FreeCursor;
mouse->WarpMouse = RPI_WarpMouse;
mouse->WarpMouseGlobal = RPI_WarpMouseGlobal;
SDL_SetDefaultCursor(RPI_CreateDefaultCursor());
}

View file

@ -37,8 +37,6 @@ typedef struct
CGFloat scale;
} SDL_DisplayModeData;
extern BOOL SDL_UIKit_supports_multiple_displays;
extern SDL_bool UIKit_IsDisplayLandscape(UIScreen *uiscreen);
extern int UIKit_InitModes(_THIS);

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