mirror of
https://github.com/encounter/SDL.git
synced 2025-12-10 05:57:44 +00:00
WinRT: merged with latest SDL 2.x/HG code
SDL 2.x recently accepted patches to enable OpenGL ES 2 support via Google's ANGLE library. The thought is to try to eventually merge SDL/WinRT's OpenGL code with SDL-official's.
This commit is contained in:
10
src/SDL.c
10
src/SDL.c
@@ -115,9 +115,11 @@ SDL_InitSubSystem(Uint32 flags)
|
||||
SDL_ClearError();
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
if (SDL_HelperWindowCreate() < 0) {
|
||||
return -1;
|
||||
}
|
||||
if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
|
||||
if (SDL_HelperWindowCreate() < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !SDL_TIMERS_DISABLED
|
||||
@@ -394,8 +396,6 @@ SDL_GetPlatform()
|
||||
return "AIX";
|
||||
#elif __ANDROID__
|
||||
return "Android";
|
||||
#elif __BEOS__
|
||||
return "BeOS";
|
||||
#elif __BSDI__
|
||||
return "BSDI";
|
||||
#elif __DREAMCAST__
|
||||
|
||||
@@ -56,7 +56,7 @@ extern AudioBootStrap XAUDIO2_bootstrap;
|
||||
extern AudioBootStrap DSOUND_bootstrap;
|
||||
extern AudioBootStrap WINMM_bootstrap;
|
||||
extern AudioBootStrap PAUDIO_bootstrap;
|
||||
extern AudioBootStrap BEOSAUDIO_bootstrap;
|
||||
extern AudioBootStrap HAIKUAUDIO_bootstrap;
|
||||
extern AudioBootStrap COREAUDIO_bootstrap;
|
||||
extern AudioBootStrap SNDMGR_bootstrap;
|
||||
extern AudioBootStrap DISKAUD_bootstrap;
|
||||
@@ -113,8 +113,8 @@ static const AudioBootStrap *const bootstrap[] = {
|
||||
#if SDL_AUDIO_DRIVER_PAUDIO
|
||||
&PAUDIO_bootstrap,
|
||||
#endif
|
||||
#if SDL_AUDIO_DRIVER_BEOSAUDIO
|
||||
&BEOSAUDIO_bootstrap,
|
||||
#if SDL_AUDIO_DRIVER_HAIKU
|
||||
&HAIKUAUDIO_bootstrap,
|
||||
#endif
|
||||
#if SDL_AUDIO_DRIVER_COREAUDIO
|
||||
&COREAUDIO_bootstrap,
|
||||
@@ -722,10 +722,16 @@ SDL_GetAudioDeviceName(int index, int iscapture)
|
||||
}
|
||||
|
||||
if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
|
||||
if (index > 0) {
|
||||
goto no_such_device;
|
||||
}
|
||||
return DEFAULT_INPUT_DEVNAME;
|
||||
}
|
||||
|
||||
if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
|
||||
if (index > 0) {
|
||||
goto no_such_device;
|
||||
}
|
||||
return DEFAULT_OUTPUT_DEVNAME;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_AUDIO_DRIVER_BEOSAUDIO
|
||||
#if SDL_AUDIO_DRIVER_HAIKU
|
||||
|
||||
/* Allow access to the audio stream on BeOS */
|
||||
/* Allow access to the audio stream on Haiku */
|
||||
|
||||
#include <SoundPlayer.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "../../main/beos/SDL_BeApp.h"
|
||||
#include "../../main/haiku/SDL_BeApp.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -34,14 +35,13 @@ extern "C"
|
||||
#include "SDL_audio.h"
|
||||
#include "../SDL_audio_c.h"
|
||||
#include "../SDL_sysaudio.h"
|
||||
#include "../../thread/beos/SDL_systhread_c.h"
|
||||
#include "SDL_beaudio.h"
|
||||
#include "SDL_haikuaudio.h"
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* !!! FIXME: have the callback call the higher level to avoid code dupe. */
|
||||
/* The BeOS callback for handling the audio buffer */
|
||||
/* The Haiku callback for handling the audio buffer */
|
||||
static void
|
||||
FillSound(void *device, void *stream, size_t len,
|
||||
const media_raw_audio_format & format)
|
||||
@@ -71,7 +71,7 @@ FillSound(void *device, void *stream, size_t len,
|
||||
}
|
||||
|
||||
static void
|
||||
BEOSAUDIO_CloseDevice(_THIS)
|
||||
HAIKUAUDIO_CloseDevice(_THIS)
|
||||
{
|
||||
if (_this->hidden != NULL) {
|
||||
if (_this->hidden->audio_obj) {
|
||||
@@ -85,8 +85,33 @@ BEOSAUDIO_CloseDevice(_THIS)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const int sig_list[] = {
|
||||
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
|
||||
};
|
||||
|
||||
static inline void
|
||||
MaskSignals(sigset_t * omask)
|
||||
{
|
||||
sigset_t mask;
|
||||
int i;
|
||||
|
||||
sigemptyset(&mask);
|
||||
for (i = 0; sig_list[i]; ++i) {
|
||||
sigaddset(&mask, sig_list[i]);
|
||||
}
|
||||
sigprocmask(SIG_BLOCK, &mask, omask);
|
||||
}
|
||||
|
||||
static inline void
|
||||
UnmaskSignals(sigset_t * omask)
|
||||
{
|
||||
sigprocmask(SIG_SETMASK, omask, NULL);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
HAIKUAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
{
|
||||
int valid_datatype = 0;
|
||||
media_raw_audio_format format;
|
||||
@@ -151,7 +176,7 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
}
|
||||
|
||||
if (!valid_datatype) { /* shouldn't happen, but just in case... */
|
||||
BEOSAUDIO_CloseDevice(_this);
|
||||
HAIKUAUDIO_CloseDevice(_this);
|
||||
return SDL_SetError("Unsupported audio format");
|
||||
}
|
||||
|
||||
@@ -162,15 +187,15 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
|
||||
/* Subscribe to the audio stream (creates a new thread) */
|
||||
sigset_t omask;
|
||||
SDL_MaskSignals(&omask);
|
||||
MaskSignals(&omask);
|
||||
_this->hidden->audio_obj = new BSoundPlayer(&format, "SDL Audio",
|
||||
FillSound, NULL, _this);
|
||||
SDL_UnmaskSignals(&omask);
|
||||
UnmaskSignals(&omask);
|
||||
|
||||
if (_this->hidden->audio_obj->Start() == B_NO_ERROR) {
|
||||
_this->hidden->audio_obj->SetHasData(true);
|
||||
} else {
|
||||
BEOSAUDIO_CloseDevice(_this);
|
||||
HAIKUAUDIO_CloseDevice(_this);
|
||||
return SDL_SetError("Unable to start Be audio");
|
||||
}
|
||||
|
||||
@@ -179,13 +204,13 @@ BEOSAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
|
||||
}
|
||||
|
||||
static void
|
||||
BEOSAUDIO_Deinitialize(void)
|
||||
HAIKUAUDIO_Deinitialize(void)
|
||||
{
|
||||
SDL_QuitBeApp();
|
||||
}
|
||||
|
||||
static int
|
||||
BEOSAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
HAIKUAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
{
|
||||
/* Initialize the Be Application, if it's not already started */
|
||||
if (SDL_InitBeApp() < 0) {
|
||||
@@ -193,9 +218,9 @@ BEOSAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
}
|
||||
|
||||
/* Set the function pointers */
|
||||
impl->OpenDevice = BEOSAUDIO_OpenDevice;
|
||||
impl->CloseDevice = BEOSAUDIO_CloseDevice;
|
||||
impl->Deinitialize = BEOSAUDIO_Deinitialize;
|
||||
impl->OpenDevice = HAIKUAUDIO_OpenDevice;
|
||||
impl->CloseDevice = HAIKUAUDIO_CloseDevice;
|
||||
impl->Deinitialize = HAIKUAUDIO_Deinitialize;
|
||||
impl->ProvidesOwnCallbackThread = 1;
|
||||
impl->OnlyHasDefaultOutputDevice = 1;
|
||||
|
||||
@@ -204,12 +229,12 @@ BEOSAUDIO_Init(SDL_AudioDriverImpl * impl)
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern AudioBootStrap BEOSAUDIO_bootstrap;
|
||||
extern AudioBootStrap HAIKUAUDIO_bootstrap;
|
||||
}
|
||||
AudioBootStrap BEOSAUDIO_bootstrap = {
|
||||
"baudio", "BeOS BSoundPlayer", BEOSAUDIO_Init, 0
|
||||
AudioBootStrap HAIKUAUDIO_bootstrap = {
|
||||
"haiku", "Haiku BSoundPlayer", HAIKUAUDIO_Init, 0
|
||||
};
|
||||
|
||||
#endif /* SDL_AUDIO_DRIVER_BEOSAUDIO */
|
||||
#endif /* SDL_AUDIO_DRIVER_HAIKU */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -62,7 +62,11 @@
|
||||
/* WinRT always has access to the .the XAudio 2 SDK */
|
||||
# define SDL_XAUDIO2_HAS_SDK
|
||||
#else
|
||||
#include <dxsdkver.h> /* XAudio2 exists as of the March 2008 DirectX SDK */
|
||||
/* XAudio2 exists as of the March 2008 DirectX SDK
|
||||
The XAudio2 implementation available in the Windows 8 SDK targets Windows 8 and newer.
|
||||
If you want to build SDL with XAudio2 support you should install the DirectX SDK.
|
||||
*/
|
||||
#include <dxsdkver.h>
|
||||
#if (!defined(_DXSDK_BUILD_MAJOR) || (_DXSDK_BUILD_MAJOR < 1284))
|
||||
# pragma message("Your DirectX SDK is too old. Disabling XAudio2 support.")
|
||||
#else
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "../../video/android/SDL_androidtouch.h"
|
||||
#include "../../video/android/SDL_androidvideo.h"
|
||||
#include "../../video/android/SDL_androidwindow.h"
|
||||
#include "../../joystick/android/SDL_sysjoystick.h"
|
||||
|
||||
#include <android/log.h>
|
||||
#include <pthread.h>
|
||||
@@ -146,6 +147,30 @@ void Java_org_libsdl_app_SDLActivity_onNativeResize(
|
||||
Android_SetScreenResolution(width, height, format);
|
||||
}
|
||||
|
||||
// Paddown
|
||||
int Java_org_libsdl_app_SDLActivity_onNativePadDown(
|
||||
JNIEnv* env, jclass jcls,
|
||||
jint padId, jint keycode)
|
||||
{
|
||||
return Android_OnPadDown(padId, keycode);
|
||||
}
|
||||
|
||||
// Padup
|
||||
int Java_org_libsdl_app_SDLActivity_onNativePadUp(
|
||||
JNIEnv* env, jclass jcls,
|
||||
jint padId, jint keycode)
|
||||
{
|
||||
return Android_OnPadUp(padId, keycode);
|
||||
}
|
||||
|
||||
/* Joy */
|
||||
void Java_org_libsdl_app_SDLActivity_onNativeJoy(
|
||||
JNIEnv* env, jclass jcls,
|
||||
jint joyId, jint axis, jfloat value)
|
||||
{
|
||||
Android_OnJoy(joyId, axis, value);
|
||||
}
|
||||
|
||||
|
||||
/* Surface Created */
|
||||
void Java_org_libsdl_app_SDLActivity_onNativeSurfaceChanged(JNIEnv* env, jclass jcls)
|
||||
@@ -259,9 +284,16 @@ void Java_org_libsdl_app_SDLActivity_nativeLowMemory(
|
||||
void Java_org_libsdl_app_SDLActivity_nativeQuit(
|
||||
JNIEnv* env, jclass cls)
|
||||
{
|
||||
/* Discard previous events. The user should have handled state storage
|
||||
* in SDL_APP_WILLENTERBACKGROUND. After nativeQuit() is called, no
|
||||
* events other than SDL_QUIT and SDL_APP_TERMINATING should fire */
|
||||
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
|
||||
/* Inject a SDL_QUIT event */
|
||||
SDL_SendQuit();
|
||||
SDL_SendAppEvent(SDL_APP_TERMINATING);
|
||||
/* Resume the event loop so that the app can catch SDL_QUIT which
|
||||
* should now be the top event in the event queue. */
|
||||
if (!SDL_SemValue(Android_ResumeSem)) SDL_SemPost(Android_ResumeSem);
|
||||
}
|
||||
|
||||
/* Pause */
|
||||
@@ -1009,7 +1041,7 @@ static jobject Android_JNI_GetSystemServiceObject(const char* name)
|
||||
mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
|
||||
jobject context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
|
||||
|
||||
mid = (*env)->GetMethodID(env, mActivityClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
mid = (*env)->GetMethodID(env, mActivityClass, "getSystemServiceFromUiThread", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
jobject manager = (*env)->CallObjectMethod(env, context, mid, service);
|
||||
|
||||
(*env)->DeleteLocalRef(env, service);
|
||||
@@ -1212,6 +1244,62 @@ int Android_JNI_GetTouchDeviceIds(int **ids) {
|
||||
return number;
|
||||
}
|
||||
|
||||
/* return the total number of plugged in joysticks */
|
||||
int Android_JNI_GetNumJoysticks()
|
||||
{
|
||||
JNIEnv* env = Android_JNI_GetEnv();
|
||||
if (!env) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "getNumJoysticks", "()I");
|
||||
if (!mid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)(*env)->CallStaticIntMethod(env, mActivityClass, mid);
|
||||
}
|
||||
|
||||
/* Return the name of joystick number "i" */
|
||||
char* Android_JNI_GetJoystickName(int i)
|
||||
{
|
||||
JNIEnv* env = Android_JNI_GetEnv();
|
||||
if (!env) {
|
||||
return SDL_strdup("");
|
||||
}
|
||||
|
||||
jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "getJoystickName", "(I)Ljava/lang/String;");
|
||||
if (!mid) {
|
||||
return SDL_strdup("");
|
||||
}
|
||||
jstring string = (jstring)((*env)->CallStaticObjectMethod(env, mActivityClass, mid, i));
|
||||
const char* utf = (*env)->GetStringUTFChars(env, string, 0);
|
||||
if (!utf) {
|
||||
return SDL_strdup("");
|
||||
}
|
||||
|
||||
char* text = SDL_strdup(utf);
|
||||
(*env)->ReleaseStringUTFChars(env, string, utf);
|
||||
return text;
|
||||
}
|
||||
|
||||
/* return the number of axes in the given joystick */
|
||||
int Android_JNI_GetJoystickAxes(int joy)
|
||||
{
|
||||
JNIEnv* env = Android_JNI_GetEnv();
|
||||
if (!env) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
jmethodID mid = (*env)->GetStaticMethodID(env, mActivityClass, "getJoystickAxes", "(I)I");
|
||||
if (!mid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)(*env)->CallIntMethod(env, mActivityClass, mid, joy);
|
||||
}
|
||||
|
||||
|
||||
/* sends message to be handled on the UI event dispatch thread */
|
||||
int Android_JNI_SendMessage(int command, int param)
|
||||
{
|
||||
|
||||
@@ -64,6 +64,11 @@ SDL_bool Android_JNI_HasClipboardText();
|
||||
|
||||
/* Power support */
|
||||
int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent);
|
||||
|
||||
/* Joystick support */
|
||||
int Android_JNI_GetNumJoysticks();
|
||||
char* Android_JNI_GetJoystickName(int i);
|
||||
int Android_JNI_GetJoystickAxes(int joy);
|
||||
|
||||
/* Touch support */
|
||||
int Android_JNI_GetTouchDeviceIds(int **ids);
|
||||
|
||||
@@ -116,15 +116,14 @@ static unsigned long SDL_HashDollar(SDL_FloatPoint* points)
|
||||
}
|
||||
|
||||
|
||||
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
|
||||
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops *dst)
|
||||
{
|
||||
if (src == NULL) return 0;
|
||||
|
||||
if (dst == NULL) return 0;
|
||||
|
||||
/* No Longer storing the Hash, rehash on load */
|
||||
/* if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; */
|
||||
/* if (SDL_RWops.write(dst, &(templ->hash), sizeof(templ->hash), 1) != 1) return 0; */
|
||||
|
||||
if (SDL_RWwrite(src,templ->path,
|
||||
if (SDL_RWwrite(dst, templ->path,
|
||||
sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
|
||||
return 0;
|
||||
|
||||
@@ -132,26 +131,26 @@ static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
|
||||
}
|
||||
|
||||
|
||||
int SDL_SaveAllDollarTemplates(SDL_RWops *src)
|
||||
int SDL_SaveAllDollarTemplates(SDL_RWops *dst)
|
||||
{
|
||||
int i,j,rtrn = 0;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
SDL_GestureTouch* touch = &SDL_gestureTouch[i];
|
||||
for (j = 0; j < touch->numDollarTemplates; j++) {
|
||||
rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
|
||||
rtrn += SaveTemplate(&touch->dollarTemplate[i], dst);
|
||||
}
|
||||
}
|
||||
return rtrn;
|
||||
}
|
||||
|
||||
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src)
|
||||
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *dst)
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
SDL_GestureTouch* touch = &SDL_gestureTouch[i];
|
||||
for (j = 0; j < touch->numDollarTemplates; j++) {
|
||||
if (touch->dollarTemplate[i].hash == gestureId) {
|
||||
return SaveTemplate(&touch->dollarTemplate[i],src);
|
||||
return SaveTemplate(&touch->dollarTemplate[i], dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,10 +197,8 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
|
||||
}
|
||||
/* Use the index of the last one added. */
|
||||
return index;
|
||||
} else {
|
||||
return SDL_AddDollarGesture_one(inTouch, path);
|
||||
}
|
||||
return -1;
|
||||
return SDL_AddDollarGesture_one(inTouch, path);
|
||||
}
|
||||
|
||||
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
/* Useful functions and variables from SDL_sysevents.c */
|
||||
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
/* The Be and Haiku event loops run in a separate thread */
|
||||
#if defined(__HAIKU__)
|
||||
/* The Haiku event loops run in a separate thread */
|
||||
#define MUST_THREAD_EVENTS
|
||||
#endif
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_FILESYSTEM_BEOS
|
||||
#ifdef SDL_FILESYSTEM_HAIKU
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent filesystem routines */
|
||||
@@ -82,12 +82,12 @@ SDL_GetPrefPath(const char *org, const char *app)
|
||||
SDL_OutOfMemory();
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app);
|
||||
create_directory(retval, 0700); // BeOS api: creates missing dirs
|
||||
create_directory(retval, 0700); // Haiku api: creates missing dirs
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_BEOS */
|
||||
#endif /* SDL_FILESYSTEM_HAIKU */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -289,8 +289,6 @@ ControllerMapping_t *SDL_PrivateGetControllerMapping(int device_index)
|
||||
SDL_JoystickGUID jGUID = SDL_JoystickGetDeviceGUID( device_index );
|
||||
return SDL_PrivateGetControllerMappingForGUID(&jGUID);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* map_StringForControllerAxis[] = {
|
||||
|
||||
@@ -57,9 +57,11 @@ static const char *s_ControllerMappings [] =
|
||||
"030000006d04000019c2000011010000,Logitech F710 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. */
|
||||
"030000006d0400001fc2000005030000,Logitech F710 Gamepad (XInput),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,",
|
||||
"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,",
|
||||
"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,",
|
||||
"030000005e0400001907000000010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,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,",
|
||||
"030000005e0400009102000007010000,X360 Wireless Controller,a:b0,b:b1,back:b6,dpdown:b14,dpleft:b11,dpright:b12,dpup:b13,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,",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -832,7 +832,7 @@ SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
|
||||
int maxoutputbytes= sizeof(guid);
|
||||
size_t len = SDL_strlen( pchGUID );
|
||||
Uint8 *p;
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
/* Make sure it's even */
|
||||
len = ( len ) & ~0x1;
|
||||
|
||||
@@ -29,11 +29,115 @@
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_joystick.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "../SDL_joystick_c.h"
|
||||
#include "../../core/android/SDL_android.h"
|
||||
|
||||
static const char *accelerometerName = "Android accelerometer";
|
||||
#include "android/keycodes.h"
|
||||
|
||||
/* As of platform android-14, android/keycodes.h is missing these defines */
|
||||
#ifndef AKEYCODE_BUTTON_1
|
||||
#define AKEYCODE_BUTTON_1 188
|
||||
#define AKEYCODE_BUTTON_2 189
|
||||
#define AKEYCODE_BUTTON_3 190
|
||||
#define AKEYCODE_BUTTON_4 191
|
||||
#define AKEYCODE_BUTTON_5 192
|
||||
#define AKEYCODE_BUTTON_6 193
|
||||
#define AKEYCODE_BUTTON_7 194
|
||||
#define AKEYCODE_BUTTON_8 195
|
||||
#define AKEYCODE_BUTTON_9 196
|
||||
#define AKEYCODE_BUTTON_10 197
|
||||
#define AKEYCODE_BUTTON_11 198
|
||||
#define AKEYCODE_BUTTON_12 199
|
||||
#define AKEYCODE_BUTTON_13 200
|
||||
#define AKEYCODE_BUTTON_14 201
|
||||
#define AKEYCODE_BUTTON_15 202
|
||||
#define AKEYCODE_BUTTON_16 203
|
||||
#endif
|
||||
|
||||
#define ANDROID_ACCELEROMETER_INDEX (SYS_numjoysticks - 1)
|
||||
#define ANDROID_ACCELEROMETER_NAME "Android Accelerometer"
|
||||
#define ANDROID_MAX_NBUTTONS 36
|
||||
|
||||
static SDL_Joystick **SYS_Joysticks;
|
||||
static char **SYS_JoystickNames;
|
||||
static int SYS_numjoysticks;
|
||||
static SDL_bool SYS_accelAsJoy;
|
||||
|
||||
/* Function to convert Android keyCodes into SDL ones.
|
||||
* This code manipulation is done to get a sequential list of codes.
|
||||
* FIXME: This is only suited for the case where we use a fixed number of buttons determined by ANDROID_MAX_NBUTTONS
|
||||
*/
|
||||
static int
|
||||
keycode_to_SDL(int keycode)
|
||||
{
|
||||
/* FIXME: If this function gets too unwiedly in the future, replace with a lookup table */
|
||||
int button = 0;
|
||||
switch(keycode)
|
||||
{
|
||||
/* D-Pad key codes (API 1), these get mapped to 0...4 */
|
||||
case AKEYCODE_DPAD_UP:
|
||||
case AKEYCODE_DPAD_DOWN:
|
||||
case AKEYCODE_DPAD_LEFT:
|
||||
case AKEYCODE_DPAD_RIGHT:
|
||||
case AKEYCODE_DPAD_CENTER:
|
||||
button = keycode - AKEYCODE_DPAD_UP;
|
||||
break;
|
||||
|
||||
/* Some gamepad buttons (API 9), these get mapped to 5...19*/
|
||||
case AKEYCODE_BUTTON_A:
|
||||
case AKEYCODE_BUTTON_B:
|
||||
case AKEYCODE_BUTTON_C:
|
||||
case AKEYCODE_BUTTON_X:
|
||||
case AKEYCODE_BUTTON_Y:
|
||||
case AKEYCODE_BUTTON_Z:
|
||||
case AKEYCODE_BUTTON_L1:
|
||||
case AKEYCODE_BUTTON_L2:
|
||||
case AKEYCODE_BUTTON_R1:
|
||||
case AKEYCODE_BUTTON_R2:
|
||||
case AKEYCODE_BUTTON_THUMBL:
|
||||
case AKEYCODE_BUTTON_THUMBR:
|
||||
case AKEYCODE_BUTTON_START:
|
||||
case AKEYCODE_BUTTON_SELECT:
|
||||
case AKEYCODE_BUTTON_MODE:
|
||||
button = keycode - AKEYCODE_BUTTON_A + 5;
|
||||
break;
|
||||
|
||||
|
||||
/* More gamepad buttons (API 12), these get mapped to 20...35*/
|
||||
case AKEYCODE_BUTTON_1:
|
||||
case AKEYCODE_BUTTON_2:
|
||||
case AKEYCODE_BUTTON_3:
|
||||
case AKEYCODE_BUTTON_4:
|
||||
case AKEYCODE_BUTTON_5:
|
||||
case AKEYCODE_BUTTON_6:
|
||||
case AKEYCODE_BUTTON_7:
|
||||
case AKEYCODE_BUTTON_8:
|
||||
case AKEYCODE_BUTTON_9:
|
||||
case AKEYCODE_BUTTON_10:
|
||||
case AKEYCODE_BUTTON_11:
|
||||
case AKEYCODE_BUTTON_12:
|
||||
case AKEYCODE_BUTTON_13:
|
||||
case AKEYCODE_BUTTON_14:
|
||||
case AKEYCODE_BUTTON_15:
|
||||
case AKEYCODE_BUTTON_16:
|
||||
button = keycode - AKEYCODE_BUTTON_1 + 20;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* This is here in case future generations, probably with six fingers per hand,
|
||||
* happily add new cases up above and forget to update the max number of buttons.
|
||||
*/
|
||||
SDL_assert(button < ANDROID_MAX_NBUTTONS);
|
||||
return button;
|
||||
|
||||
}
|
||||
|
||||
/* Function to scan the system for joysticks.
|
||||
* This function should set SDL_numjoysticks to the number of available
|
||||
@@ -43,18 +147,54 @@ static const char *accelerometerName = "Android accelerometer";
|
||||
int
|
||||
SDL_SYS_JoystickInit(void)
|
||||
{
|
||||
return (1);
|
||||
int i = 0;
|
||||
const char *env;
|
||||
|
||||
env = SDL_GetHint(SDL_HINT_ACCEL_AS_JOY);
|
||||
if (env && !SDL_atoi(env))
|
||||
SYS_accelAsJoy = SDL_FALSE;
|
||||
else
|
||||
SYS_accelAsJoy = SDL_TRUE; /* Default behavior */
|
||||
|
||||
SYS_numjoysticks = Android_JNI_GetNumJoysticks();
|
||||
if (SYS_accelAsJoy) {
|
||||
SYS_numjoysticks++;
|
||||
}
|
||||
SYS_Joysticks = (SDL_Joystick **)SDL_calloc(1, SYS_numjoysticks*sizeof(SDL_Joystick *));
|
||||
if (SYS_Joysticks == NULL)
|
||||
{
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
SYS_JoystickNames = (char **)SDL_calloc(1, SYS_numjoysticks*sizeof(char *));
|
||||
if (SYS_JoystickNames == NULL)
|
||||
{
|
||||
SDL_free(SYS_Joysticks);
|
||||
SYS_Joysticks = NULL;
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
for (i = 0; i < SYS_numjoysticks; i++)
|
||||
{
|
||||
if ( SYS_accelAsJoy && i == ANDROID_ACCELEROMETER_INDEX ) {
|
||||
SYS_JoystickNames[i] = ANDROID_ACCELEROMETER_NAME;
|
||||
} else {
|
||||
SYS_JoystickNames[i] = Android_JNI_GetJoystickName(i);
|
||||
}
|
||||
}
|
||||
|
||||
return (SYS_numjoysticks);
|
||||
}
|
||||
|
||||
int SDL_SYS_NumJoysticks()
|
||||
{
|
||||
return 1;
|
||||
return SYS_numjoysticks;
|
||||
}
|
||||
|
||||
void SDL_SYS_JoystickDetect()
|
||||
{
|
||||
}
|
||||
|
||||
/* TODO: Hotplugging support */
|
||||
SDL_bool SDL_SYS_JoystickNeedsPolling()
|
||||
{
|
||||
return SDL_FALSE;
|
||||
@@ -64,7 +204,7 @@ SDL_bool SDL_SYS_JoystickNeedsPolling()
|
||||
const char *
|
||||
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
|
||||
{
|
||||
return accelerometerName;
|
||||
return SYS_JoystickNames[device_index];
|
||||
}
|
||||
|
||||
/* Function to perform the mapping from device index to the instance id for this index */
|
||||
@@ -81,15 +221,22 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
|
||||
int
|
||||
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
|
||||
{
|
||||
if (device_index == 0) {
|
||||
joystick->nbuttons = 0;
|
||||
if (device_index < SYS_numjoysticks) {
|
||||
joystick->nhats = 0;
|
||||
joystick->nballs = 0;
|
||||
joystick->naxes = 3;
|
||||
if (SYS_accelAsJoy && device_index == ANDROID_ACCELEROMETER_INDEX) {
|
||||
joystick->nbuttons = 0;
|
||||
joystick->naxes = 3;
|
||||
} else {
|
||||
/* FIXME: Get the real number of buttons in the device? */
|
||||
joystick->nbuttons = ANDROID_MAX_NBUTTONS;
|
||||
joystick->naxes = Android_JNI_GetJoystickAxes(device_index);
|
||||
}
|
||||
|
||||
SYS_Joysticks[device_index] = joystick;
|
||||
return 0;
|
||||
} else {
|
||||
SDL_SetError("No joystick available with that index");
|
||||
return (-1);
|
||||
return SDL_SetError("No joystick available with that index");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +258,8 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||
Sint16 value;
|
||||
float values[3];
|
||||
|
||||
if (Android_JNI_GetAccelerometerValues(values)) {
|
||||
if (SYS_accelAsJoy && Android_JNI_GetAccelerometerValues(values) &&
|
||||
joystick->instance_id == ANDROID_ACCELEROMETER_INDEX) {
|
||||
for ( i = 0; i < 3; i++ ) {
|
||||
value = (Sint16)(values[i] * 32767.0f);
|
||||
SDL_PrivateJoystickAxis(joystick, i, value);
|
||||
@@ -123,12 +271,25 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
|
||||
void
|
||||
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
|
||||
{
|
||||
int device_index;
|
||||
|
||||
for (device_index = 0; device_index < SYS_numjoysticks; device_index++) {
|
||||
if ( SYS_Joysticks[device_index] == joystick ) {
|
||||
SYS_Joysticks[device_index] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
joystick->closed = 1;
|
||||
}
|
||||
|
||||
/* Function to perform any system-specific joystick related cleanup */
|
||||
void
|
||||
SDL_SYS_JoystickQuit(void)
|
||||
{
|
||||
SDL_free(SYS_JoystickNames);
|
||||
SDL_free(SYS_Joysticks);
|
||||
SYS_JoystickNames = NULL;
|
||||
SYS_Joysticks = NULL;
|
||||
}
|
||||
|
||||
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
|
||||
@@ -151,6 +312,46 @@ SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
|
||||
return guid;
|
||||
}
|
||||
|
||||
int
|
||||
Android_OnPadDown(int padId, int keycode)
|
||||
{
|
||||
int button = keycode_to_SDL(keycode);
|
||||
if (button >= 0) {
|
||||
if (SYS_Joysticks[padId]) {
|
||||
SDL_PrivateJoystickButton(SYS_Joysticks[padId], button , SDL_PRESSED);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Android_OnPadUp(int padId, int keycode)
|
||||
{
|
||||
int button = keycode_to_SDL(keycode);
|
||||
if (button >= 0) {
|
||||
if (SYS_Joysticks[padId]) {
|
||||
SDL_PrivateJoystickButton(SYS_Joysticks[padId], button, SDL_RELEASED);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
Android_OnJoy(int joyId, int axis, float value)
|
||||
{
|
||||
/* Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] */
|
||||
/* TODO: Are the reported values right? */
|
||||
if (SYS_Joysticks[joyId]) {
|
||||
SDL_PrivateJoystickAxis(SYS_Joysticks[joyId], axis, (Sint16) (32767.*value) );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_JOYSTICK_ANDROID */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
28
src/joystick/android/SDL_sysjoystick.h
Normal file
28
src/joystick/android/SDL_sysjoystick.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
extern int Android_OnPadDown(int padId, int keycode);
|
||||
extern int Android_OnPadUp(int padId, int keycode);
|
||||
extern int Android_OnJoy(int joyId, int axisnum, float value);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -32,12 +32,7 @@
|
||||
#include <mach/mach_error.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/IOCFPlugIn.h>
|
||||
#ifdef MACOS_10_0_4
|
||||
#include <IOKit/hidsystem/IOHIDUsageTables.h>
|
||||
#else
|
||||
/* The header was moved here in Mac OS X 10.1 */
|
||||
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
|
||||
#endif
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <IOKit/hid/IOHIDKeys.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_BEOS
|
||||
#ifdef SDL_JOYSTICK_HAIKU
|
||||
|
||||
/* This is the system specific header for the SDL joystick API */
|
||||
|
||||
#include <be/support/String.h>
|
||||
#include <be/device/Joystick.h>
|
||||
#include <os/support/String.h>
|
||||
#include <os/device/Joystick.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -276,5 +276,6 @@ extern "C"
|
||||
|
||||
}; // extern "C"
|
||||
|
||||
#endif /* SDL_JOYSTICK_BEOS */
|
||||
#endif /* SDL_JOYSTICK_HAIKU */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -85,11 +85,14 @@ static int instance_counter = 0;
|
||||
static int
|
||||
IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *guid)
|
||||
{
|
||||
struct input_id inpid;
|
||||
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
|
||||
|
||||
#if !SDL_USE_LIBUDEV
|
||||
/* When udev is enabled we only get joystick devices here, so there's no need to test them */
|
||||
unsigned long evbit[NBITS(EV_MAX)] = { 0 };
|
||||
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
|
||||
unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
|
||||
struct input_id inpid;
|
||||
Uint16 *guid16 = (Uint16 *) ((char *) &guid->data);
|
||||
|
||||
if ((ioctl(fd, EVIOCGBIT(0, sizeof(evbit)), evbit) < 0) ||
|
||||
(ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
|
||||
@@ -101,6 +104,7 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui
|
||||
test_bit(ABS_X, absbit) && test_bit(ABS_Y, absbit))) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ioctl(fd, EVIOCGNAME(namebuflen), namebuf) < 0) {
|
||||
return 0;
|
||||
@@ -230,12 +234,15 @@ MaybeAddDevice(const char *path)
|
||||
SDL_joylist_tail = item;
|
||||
}
|
||||
|
||||
/* Need to increment the joystick count before we post the event */
|
||||
++numjoysticks;
|
||||
|
||||
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceAdded() function? */
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
event.type = SDL_JOYDEVICEADDED;
|
||||
|
||||
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
|
||||
event.jdevice.which = numjoysticks;
|
||||
event.jdevice.which = (numjoysticks - 1);
|
||||
if ( (SDL_EventOK == NULL) ||
|
||||
(*SDL_EventOK) (SDL_EventOKParam, &event) ) {
|
||||
SDL_PushEvent(&event);
|
||||
@@ -243,7 +250,7 @@ MaybeAddDevice(const char *path)
|
||||
}
|
||||
#endif /* !SDL_EVENTS_DISABLED */
|
||||
|
||||
return numjoysticks++;
|
||||
return numjoysticks;
|
||||
}
|
||||
|
||||
#if SDL_USE_LIBUDEV
|
||||
@@ -278,6 +285,9 @@ MaybeRemoveDevice(const char *path)
|
||||
SDL_joylist_tail = prev;
|
||||
}
|
||||
|
||||
/* Need to decrement the joystick count before we post the event */
|
||||
--numjoysticks;
|
||||
|
||||
/* !!! FIXME: Move this to an SDL_PrivateJoyDeviceRemoved() function? */
|
||||
#if !SDL_EVENTS_DISABLED
|
||||
event.type = SDL_JOYDEVICEREMOVED;
|
||||
@@ -294,7 +304,6 @@ MaybeRemoveDevice(const char *path)
|
||||
SDL_free(item->path);
|
||||
SDL_free(item->name);
|
||||
SDL_free(item);
|
||||
numjoysticks--;
|
||||
return retval;
|
||||
}
|
||||
prev = item;
|
||||
|
||||
@@ -112,3 +112,29 @@ double atan(double x)
|
||||
}
|
||||
}
|
||||
libm_hidden_def(atan)
|
||||
|
||||
double SDL_acos(double val)
|
||||
{
|
||||
double result;
|
||||
if (val == -1.0) {
|
||||
result = M_PI;
|
||||
} else {
|
||||
result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
|
||||
if (result < 0.0)
|
||||
{
|
||||
result += M_PI;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
double SDL_asin(double val)
|
||||
{
|
||||
double result;
|
||||
if (val == -1.0) {
|
||||
result = -(M_PI / 2.0);
|
||||
} else {
|
||||
result = (M_PI / 2.0) - SDL_acos(val);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_LOADSO_BEOS
|
||||
#ifdef SDL_LOADSO_HAIKU
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/* System dependent library loading routines */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <be/kernel/image.h>
|
||||
#include <os/kernel/image.h>
|
||||
|
||||
#include "SDL_loadso.h"
|
||||
|
||||
@@ -66,6 +66,6 @@ SDL_UnloadObject(void *handle)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_LOADSO_BEOS */
|
||||
#endif /* SDL_LOADSO_HAIKU */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <InterfaceKit.h>
|
||||
#include <OpenGLKit.h>
|
||||
|
||||
#include "../../video/bwindow/SDL_bkeyboard.h"
|
||||
#include "../../video/haiku/SDL_bkeyboard.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -37,8 +37,8 @@ extern "C" {
|
||||
|
||||
/* Local includes */
|
||||
#include "../../events/SDL_events_c.h"
|
||||
#include "../../video/bwindow/SDL_bkeyboard.h"
|
||||
#include "../../video/bwindow/SDL_bframebuffer.h"
|
||||
#include "../../video/haiku/SDL_bkeyboard.h"
|
||||
#include "../../video/haiku/SDL_bframebuffer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
#if defined(__HAIKU__)
|
||||
|
||||
/* Handle the BeApp specific portions of the application */
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_error.h"
|
||||
|
||||
#include "../../video/bwindow/SDL_BWin.h"
|
||||
#include "../../video/haiku/SDL_BWin.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -67,7 +67,7 @@ SDL_InitBeApp(void)
|
||||
return SDL_SetError("Couldn't create BApplication thread");
|
||||
}
|
||||
|
||||
/* Change working to directory to that of executable */
|
||||
/* Change working directory to that of executable */
|
||||
app_info info;
|
||||
if (B_OK == be_app->GetAppInfo(&info)) {
|
||||
entry_ref ref = info.ref;
|
||||
@@ -131,6 +131,6 @@ void SDL_BApp::ClearID(SDL_BWin *bwin) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __BEOS__ */
|
||||
#endif /* __HAIKU__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -33,7 +33,7 @@ SDL_bool SDL_GetPowerInfo_Linux_proc_acpi(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Linux_proc_apm(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Windows(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_MacOSX(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_BeOS(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Haiku(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_UIKit(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_Android(SDL_PowerState *, int *, int *);
|
||||
SDL_bool SDL_GetPowerInfo_PSP(SDL_PowerState *, int *, int *);
|
||||
@@ -68,8 +68,8 @@ static SDL_GetPowerInfo_Impl implementations[] = {
|
||||
#ifdef SDL_POWER_MACOSX /* handles Mac OS X, Darwin. */
|
||||
SDL_GetPowerInfo_MacOSX,
|
||||
#endif
|
||||
#ifdef SDL_POWER_BEOS /* handles BeOS, Zeta, with euc.jp apm driver. */
|
||||
SDL_GetPowerInfo_BeOS,
|
||||
#ifdef SDL_POWER_HAIKU /* with BeOS euc.jp apm driver. Does this work on Haiku? */
|
||||
SDL_GetPowerInfo_Haiku,
|
||||
#endif
|
||||
#ifdef SDL_POWER_ANDROID /* handles Android. */
|
||||
SDL_GetPowerInfo_Android,
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
/* !!! FIXME: does this thing even work on Haiku? */
|
||||
#ifndef SDL_POWER_DISABLED
|
||||
#if SDL_POWER_BEOS
|
||||
#if SDL_POWER_HAIKU
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -40,7 +41,7 @@
|
||||
#include "SDL_power.h"
|
||||
|
||||
SDL_bool
|
||||
SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent)
|
||||
SDL_GetPowerInfo_Haiku(SDL_PowerState * state, int *seconds, int *percent)
|
||||
{
|
||||
const int fd = open("/dev/misc/apm", O_RDONLY);
|
||||
SDL_bool need_details = SDL_FALSE;
|
||||
@@ -119,7 +120,7 @@ SDL_GetPowerInfo_BeOS(SDL_PowerState * state, int *seconds, int *percent)
|
||||
return SDL_TRUE; /* the definitive answer if APM driver replied. */
|
||||
}
|
||||
|
||||
#endif /* SDL_POWER_BEOS */
|
||||
#endif /* SDL_POWER_HAIKU */
|
||||
#endif /* SDL_POWER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -351,8 +351,7 @@ SDL_GetRendererOutputSize(SDL_Renderer * renderer, int *w, int *h)
|
||||
return 0;
|
||||
} else {
|
||||
/* This should never happen */
|
||||
SDL_SetError("Renderer doesn't support querying output size");
|
||||
return -1;
|
||||
return SDL_SetError("Renderer doesn't support querying output size");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ SDL_PROC_UNUSED(void, glDepthFunc, (GLenum func))
|
||||
SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
|
||||
SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar))
|
||||
SDL_PROC(void, glDisable, (GLenum cap))
|
||||
SDL_PROC(void, glDisableClientState, (GLenum array))
|
||||
SDL_PROC(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
|
||||
SDL_PROC_UNUSED(void, glDisableClientState, (GLenum array))
|
||||
SDL_PROC_UNUSED(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
|
||||
SDL_PROC_UNUSED(void, glDrawBuffer, (GLenum mode))
|
||||
SDL_PROC_UNUSED(void, glDrawElements,
|
||||
(GLenum mode, GLsizei count, GLenum type,
|
||||
@@ -103,7 +103,7 @@ SDL_PROC_UNUSED(void, glEdgeFlagPointer,
|
||||
(GLsizei stride, const GLvoid * pointer))
|
||||
SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean * flag))
|
||||
SDL_PROC(void, glEnable, (GLenum cap))
|
||||
SDL_PROC(void, glEnableClientState, (GLenum array))
|
||||
SDL_PROC_UNUSED(void, glEnableClientState, (GLenum array))
|
||||
SDL_PROC(void, glEnd, (void))
|
||||
SDL_PROC_UNUSED(void, glEndList, (void))
|
||||
SDL_PROC_UNUSED(void, glEvalCoord1d, (GLdouble u))
|
||||
@@ -448,7 +448,7 @@ SDL_PROC_UNUSED(void, glVertex4iv, (const GLint * v))
|
||||
SDL_PROC_UNUSED(void, glVertex4s,
|
||||
(GLshort x, GLshort y, GLshort z, GLshort w))
|
||||
SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort * v))
|
||||
SDL_PROC(void, glVertexPointer,
|
||||
SDL_PROC_UNUSED(void, glVertexPointer,
|
||||
(GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid * pointer))
|
||||
SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
|
||||
|
||||
@@ -919,8 +919,16 @@ GL_UpdateViewport(SDL_Renderer * renderer)
|
||||
return 0;
|
||||
}
|
||||
|
||||
data->glViewport(renderer->viewport.x, renderer->viewport.y,
|
||||
renderer->viewport.w, renderer->viewport.h);
|
||||
if (renderer->target) {
|
||||
data->glViewport(renderer->viewport.x, renderer->viewport.y,
|
||||
renderer->viewport.w, renderer->viewport.h);
|
||||
} else {
|
||||
int w, h;
|
||||
|
||||
SDL_GetRendererOutputSize(renderer, &w, &h);
|
||||
data->glViewport(renderer->viewport.x, (h - renderer->viewport.y - renderer->viewport.h),
|
||||
renderer->viewport.w, renderer->viewport.h);
|
||||
}
|
||||
|
||||
data->glMatrixMode(GL_PROJECTION);
|
||||
data->glLoadIdentity();
|
||||
@@ -1048,17 +1056,15 @@ GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
|
||||
int count)
|
||||
{
|
||||
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
|
||||
GL_SetDrawingState(renderer);
|
||||
|
||||
data->glTranslatef(0.5f, 0.5f, 0.0f);
|
||||
data->glVertexPointer(2, GL_FLOAT, 0, points);
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
data->glDrawArrays(GL_POINTS, 0, count);
|
||||
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
data->glTranslatef(-0.5f, -0.5f, 0.0f);
|
||||
data->glBegin(GL_POINTS);
|
||||
for (i = 0; i < count; ++i) {
|
||||
data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
|
||||
}
|
||||
data->glEnd();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1068,28 +1074,62 @@ GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
|
||||
int count)
|
||||
{
|
||||
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
|
||||
GL_SetDrawingState(renderer);
|
||||
|
||||
data->glTranslatef(0.5f, 0.5f, 0.0f);
|
||||
data->glVertexPointer(2, GL_FLOAT, 0, points);
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
if (count > 2 &&
|
||||
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
|
||||
data->glBegin(GL_LINE_LOOP);
|
||||
/* GL_LINE_LOOP takes care of the final segment */
|
||||
data->glDrawArrays(GL_LINE_LOOP, 0, count-1);
|
||||
--count;
|
||||
for (i = 0; i < count; ++i) {
|
||||
data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
|
||||
}
|
||||
data->glEnd();
|
||||
} else {
|
||||
data->glDrawArrays(GL_LINE_STRIP, 0, count);
|
||||
}
|
||||
/* Make sure all the line endpoints are closed.
|
||||
* http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
|
||||
* Which points need to be drawn varies by driver, so just draw all of them.
|
||||
*/
|
||||
data->glDrawArrays(GL_POINTS, 0, count);
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
data->glTranslatef(-0.5f, -0.5f, 0.0f);
|
||||
#if defined(__MACOSX__) || defined(__WIN32__)
|
||||
#else
|
||||
int x1, y1, x2, y2;
|
||||
#endif
|
||||
|
||||
data->glBegin(GL_LINE_STRIP);
|
||||
for (i = 0; i < count; ++i) {
|
||||
data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
|
||||
}
|
||||
data->glEnd();
|
||||
|
||||
/* The line is half open, so we need one more point to complete it.
|
||||
* http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
|
||||
* If we have to, we can use vertical line and horizontal line textures
|
||||
* for vertical and horizontal lines, and then create custom textures
|
||||
* for diagonal lines and software render those. It's terrible, but at
|
||||
* least it would be pixel perfect.
|
||||
*/
|
||||
data->glBegin(GL_POINTS);
|
||||
#if defined(__MACOSX__) || defined(__WIN32__)
|
||||
/* Mac OS X and Windows seem to always leave the last point open */
|
||||
data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
|
||||
#else
|
||||
/* Linux seems to leave the right-most or bottom-most point open */
|
||||
x1 = points[0].x;
|
||||
y1 = points[0].y;
|
||||
x2 = points[count-1].x;
|
||||
y2 = points[count-1].y;
|
||||
|
||||
if (x1 > x2) {
|
||||
data->glVertex2f(0.5f + x1, 0.5f + y1);
|
||||
} else if (x2 > x1) {
|
||||
data->glVertex2f(0.5f + x2, 0.5f + y2);
|
||||
}
|
||||
if (y1 > y2) {
|
||||
data->glVertex2f(0.5f + x1, 0.5f + y1);
|
||||
} else if (y2 > y1) {
|
||||
data->glVertex2f(0.5f + x2, 0.5f + y2);
|
||||
}
|
||||
#endif
|
||||
data->glEnd();
|
||||
}
|
||||
return GL_CheckError("", renderer);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,3 +46,5 @@ SDL_PROC(void, glBindFramebuffer, (GLenum, GLuint))
|
||||
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 *))
|
||||
|
||||
@@ -52,7 +52,12 @@ SDL_ceil(double x)
|
||||
#ifdef HAVE_CEIL
|
||||
return ceil(x);
|
||||
#else
|
||||
return (double)(int)((x)+0.5);
|
||||
double integer = SDL_floor(x);
|
||||
double fraction = x - integer;
|
||||
if (fraction > 0.0) {
|
||||
integer += 1.0;
|
||||
}
|
||||
return integer;
|
||||
#endif /* HAVE_CEIL */
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define VIDEO_USAGE \
|
||||
"[--video driver] [--renderer driver] [--gldebug] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--logical WxH] [--scale N] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--allow-hidpi]"
|
||||
"[--video driver] [--renderer driver] [--gldebug] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--logical WxH] [--scale N] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--allow-highdpi]"
|
||||
|
||||
#define AUDIO_USAGE \
|
||||
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
|
||||
@@ -809,6 +809,9 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
|
||||
state->renderers =
|
||||
(SDL_Renderer **) SDL_malloc(state->num_windows *
|
||||
sizeof(*state->renderers));
|
||||
state->targets =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows *
|
||||
sizeof(*state->targets));
|
||||
if (!state->windows || !state->renderers) {
|
||||
fprintf(stderr, "Out of memory!\n");
|
||||
return SDL_FALSE;
|
||||
@@ -861,6 +864,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
|
||||
SDL_ShowWindow(state->windows[i]);
|
||||
|
||||
state->renderers[i] = NULL;
|
||||
state->targets[i] = NULL;
|
||||
|
||||
if (!state->skip_renderer
|
||||
&& (state->renderdriver
|
||||
@@ -1338,7 +1342,7 @@ SDLTest_CommonEvent(SDLTest_CommonState * state, SDL_Event * event, int *done)
|
||||
if (flags & SDL_WINDOW_FULLSCREEN) {
|
||||
SDL_SetWindowFullscreen(window, SDL_FALSE);
|
||||
} else {
|
||||
SDL_SetWindowFullscreen(window, SDL_TRUE);
|
||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
} else if (event->key.keysym.mod & KMOD_ALT) {
|
||||
@@ -1412,6 +1416,14 @@ SDLTest_CommonQuit(SDLTest_CommonState * state)
|
||||
int i;
|
||||
|
||||
SDL_free(state->windows);
|
||||
if (state->targets) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->targets[i]) {
|
||||
SDL_DestroyTexture(state->targets[i]);
|
||||
}
|
||||
}
|
||||
SDL_free(state->targets);
|
||||
}
|
||||
if (state->renderers) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (state->renderers[i]) {
|
||||
|
||||
@@ -51,6 +51,9 @@ extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority);
|
||||
*/
|
||||
extern void SDL_SYS_WaitThread(SDL_Thread * thread);
|
||||
|
||||
/* Mark thread as cleaned up as soon as it exits, without joining. */
|
||||
extern void SDL_SYS_DetachThread(SDL_Thread * thread);
|
||||
|
||||
/* Get the thread local storage for this thread */
|
||||
extern SDL_TLSData *SDL_SYS_GetTLSData();
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
/* System independent thread management routines for SDL */
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_thread_c.h"
|
||||
#include "SDL_systhread.h"
|
||||
@@ -265,13 +266,14 @@ SDL_RunThread(void *data)
|
||||
thread_args *args = (thread_args *) data;
|
||||
int (SDLCALL * userfunc) (void *) = args->func;
|
||||
void *userdata = args->data;
|
||||
int *statusloc = &args->info->status;
|
||||
SDL_Thread *thread = args->info;
|
||||
int *statusloc = &thread->status;
|
||||
|
||||
/* Perform any system-dependent setup - this function may not fail */
|
||||
SDL_SYS_SetupThread(args->info->name);
|
||||
SDL_SYS_SetupThread(thread->name);
|
||||
|
||||
/* Get the thread id */
|
||||
args->info->threadid = SDL_ThreadID();
|
||||
thread->threadid = SDL_ThreadID();
|
||||
|
||||
/* Wake up the parent thread */
|
||||
SDL_SemPost(args->wait);
|
||||
@@ -281,6 +283,17 @@ SDL_RunThread(void *data)
|
||||
|
||||
/* Clean up thread-local storage */
|
||||
SDL_TLSCleanup();
|
||||
|
||||
/* Mark us as ready to be joined (or detached) */
|
||||
if (!SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_ZOMBIE)) {
|
||||
/* Clean up if something already detached us. */
|
||||
if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_DETACHED, SDL_THREAD_STATE_CLEANED)) {
|
||||
if (thread->name) {
|
||||
SDL_free(thread->name);
|
||||
}
|
||||
SDL_free(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
@@ -306,8 +319,9 @@ SDL_CreateThread(int (SDLCALL * fn) (void *),
|
||||
SDL_OutOfMemory();
|
||||
return (NULL);
|
||||
}
|
||||
SDL_memset(thread, 0, (sizeof *thread));
|
||||
SDL_zerop(thread);
|
||||
thread->status = -1;
|
||||
SDL_AtomicSet(&thread->state, SDL_THREAD_STATE_ALIVE);
|
||||
|
||||
/* Set up the arguments for the thread */
|
||||
if (name != NULL) {
|
||||
@@ -410,4 +424,27 @@ SDL_WaitThread(SDL_Thread * thread, int *status)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Grab dibs if the state is alive+joinable. */
|
||||
if (SDL_AtomicCAS(&thread->state, SDL_THREAD_STATE_ALIVE, SDL_THREAD_STATE_DETACHED)) {
|
||||
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)) {
|
||||
return; /* already detached (you shouldn't call this twice!) */
|
||||
} else if (state == SDL_THREAD_STATE_ZOMBIE) {
|
||||
SDL_WaitThread(thread, NULL); /* already done, clean it up. */
|
||||
} else {
|
||||
SDL_assert(0 && "Unexpected thread state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -28,10 +28,6 @@
|
||||
/* Need the definitions of SYS_ThreadHandle */
|
||||
#if SDL_THREADS_DISABLED
|
||||
#include "generic/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_BEOS
|
||||
#include "beos/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_EPOC
|
||||
#include "epoc/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_PTHREAD
|
||||
#include "pthread/SDL_systhread_c.h"
|
||||
#elif SDL_THREAD_WINDOWS
|
||||
@@ -46,12 +42,21 @@
|
||||
#endif
|
||||
#include "../SDL_error_c.h"
|
||||
|
||||
typedef enum SDL_ThreadState
|
||||
{
|
||||
SDL_THREAD_STATE_ALIVE,
|
||||
SDL_THREAD_STATE_DETACHED,
|
||||
SDL_THREAD_STATE_ZOMBIE,
|
||||
SDL_THREAD_STATE_CLEANED,
|
||||
} SDL_ThreadState;
|
||||
|
||||
/* This is the system-independent thread info structure */
|
||||
struct SDL_Thread
|
||||
{
|
||||
SDL_threadID threadid;
|
||||
SYS_ThreadHandle handle;
|
||||
int status;
|
||||
SDL_atomic_t state; /* SDL_THREAD_STATE_* */
|
||||
SDL_error errbuf;
|
||||
char *name;
|
||||
void *data;
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifdef SDL_THREAD_BEOS
|
||||
|
||||
/* Semaphores in the BeOS environment */
|
||||
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
#include "SDL_thread.h"
|
||||
|
||||
|
||||
struct SDL_semaphore
|
||||
{
|
||||
sem_id id;
|
||||
};
|
||||
|
||||
/* Create a counting semaphore */
|
||||
SDL_sem *
|
||||
SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem *sem;
|
||||
|
||||
sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
sem->id = create_sem(initial_value, "SDL semaphore");
|
||||
if (sem->id < B_NO_ERROR) {
|
||||
SDL_SetError("create_sem() failed");
|
||||
SDL_free(sem);
|
||||
sem = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
return (sem);
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
void
|
||||
SDL_DestroySemaphore(SDL_sem * sem)
|
||||
{
|
||||
if (sem) {
|
||||
if (sem->id >= B_NO_ERROR) {
|
||||
delete_sem(sem->id);
|
||||
}
|
||||
SDL_free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
{
|
||||
int32 val;
|
||||
int retval;
|
||||
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
}
|
||||
|
||||
tryagain:
|
||||
if (timeout == SDL_MUTEX_MAXWAIT) {
|
||||
val = acquire_sem(sem->id);
|
||||
} else {
|
||||
timeout *= 1000; /* BeOS uses a timeout in microseconds */
|
||||
val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout);
|
||||
}
|
||||
switch (val) {
|
||||
case B_INTERRUPTED:
|
||||
goto tryagain;
|
||||
case B_NO_ERROR:
|
||||
retval = 0;
|
||||
break;
|
||||
case B_TIMED_OUT:
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
break;
|
||||
case B_WOULD_BLOCK:
|
||||
retval = SDL_MUTEX_TIMEDOUT;
|
||||
break;
|
||||
default:
|
||||
retval = SDL_SetError("acquire_sem() failed");
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemTryWait(SDL_sem * sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, 0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWait(SDL_sem * sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
Uint32
|
||||
SDL_SemValue(SDL_sem * sem)
|
||||
{
|
||||
int32 count;
|
||||
Uint32 value;
|
||||
|
||||
value = 0;
|
||||
if (sem) {
|
||||
get_sem_count(sem->id, &count);
|
||||
if (count > 0) {
|
||||
value = (Uint32) count;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Atomically increases the semaphore's count (not blocking) */
|
||||
int
|
||||
SDL_SemPost(SDL_sem * sem)
|
||||
{
|
||||
if (!sem) {
|
||||
return SDL_SetError("Passed a NULL semaphore");
|
||||
}
|
||||
|
||||
if (release_sem(sem->id) != B_NO_ERROR) {
|
||||
return SDL_SetError("release_sem() failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_BEOS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifdef SDL_THREAD_BEOS
|
||||
|
||||
/* BeOS thread management routines for SDL */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
#include "SDL_mutex.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
|
||||
|
||||
static int sig_list[] = {
|
||||
SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
|
||||
};
|
||||
|
||||
void
|
||||
SDL_MaskSignals(sigset_t * omask)
|
||||
{
|
||||
sigset_t mask;
|
||||
int i;
|
||||
|
||||
sigemptyset(&mask);
|
||||
for (i = 0; sig_list[i]; ++i) {
|
||||
sigaddset(&mask, sig_list[i]);
|
||||
}
|
||||
sigprocmask(SIG_BLOCK, &mask, omask);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_UnmaskSignals(sigset_t * omask)
|
||||
{
|
||||
sigprocmask(SIG_SETMASK, omask, NULL);
|
||||
}
|
||||
|
||||
static int32
|
||||
RunThread(void *data)
|
||||
{
|
||||
SDL_RunThread(data);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||
{
|
||||
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
|
||||
const char *threadname = thread->name ? thread->name : "SDL Thread";
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
SDL_snprintf(name, sizeof (name), "%s", threadname);
|
||||
name[sizeof (name) - 1] = '\0';
|
||||
|
||||
/* Create the thread and go! */
|
||||
thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args);
|
||||
if ((thread->handle == B_NO_MORE_THREADS) ||
|
||||
(thread->handle == B_NO_MEMORY)) {
|
||||
return SDL_SetError("Not enough resources to create thread");
|
||||
}
|
||||
resume_thread(thread->handle);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* We set the thread name during SDL_SYS_CreateThread(). */
|
||||
/* Mask asynchronous signals for this thread */
|
||||
SDL_MaskSignals(NULL);
|
||||
}
|
||||
|
||||
SDL_threadID
|
||||
SDL_ThreadID(void)
|
||||
{
|
||||
return ((SDL_threadID) find_thread(NULL));
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
int32 value;
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
value = B_LOW_PRIORITY;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
value = B_URGENT_DISPLAY_PRIORITY;
|
||||
} else {
|
||||
value = B_NORMAL_PRIORITY;
|
||||
}
|
||||
set_thread_priority(find_thread(NULL), value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
{
|
||||
status_t the_status;
|
||||
|
||||
wait_for_thread(thread->handle, &the_status);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_BEOS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <be/kernel/OS.h>
|
||||
|
||||
typedef thread_id SYS_ThreadHandle;
|
||||
|
||||
/* Functions needed to work with system threads in other portions of SDL */
|
||||
extern void SDL_MaskSignals(sigset_t * omask);
|
||||
extern void SDL_UnmaskSignals(sigset_t * omask);
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../SDL_thread_c.h"
|
||||
|
||||
#if SDL_THREAD_BEOS
|
||||
|
||||
#include <support/TLS.h>
|
||||
|
||||
|
||||
static int32 thread_local_storage = B_NO_MEMORY;
|
||||
static SDL_bool generic_local_storage = SDL_FALSE;
|
||||
|
||||
SDL_TLSData *
|
||||
SDL_SYS_GetTLSData()
|
||||
{
|
||||
if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) {
|
||||
static SDL_SpinLock lock;
|
||||
SDL_AtomicLock(&lock);
|
||||
if (thread_local_storage == B_NO_MEMORY && !generic_local_storage) {
|
||||
int32 storage = tls_allocate();
|
||||
if (storage != B_NO_MEMORY) {
|
||||
SDL_MemoryBarrierRelease();
|
||||
thread_local_storage = storage;
|
||||
} else {
|
||||
generic_local_storage = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
SDL_AtomicUnlock(&lock);
|
||||
}
|
||||
if (generic_local_storage) {
|
||||
return SDL_Generic_GetTLSData();
|
||||
}
|
||||
SDL_MemoryBarrierAcquire();
|
||||
return (SDL_TLSData *)tls_get(thread_local_storage);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
{
|
||||
if (generic_local_storage) {
|
||||
return SDL_Generic_SetTLSData(data);
|
||||
}
|
||||
tls_set(thread_local_storage, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_BEOS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -62,4 +62,10 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -77,6 +77,12 @@ void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
/* !!! FIXME: is this correct? */
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
void SDL_SYS_KillThread(SDL_Thread *thread)
|
||||
{
|
||||
sceKernelTerminateDeleteThread(thread->handle);
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
#include "../../core/android/SDL_android.h"
|
||||
#endif
|
||||
|
||||
#ifdef __HAIKU__
|
||||
#include <be/kernel/OS.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_assert.h"
|
||||
|
||||
/* List of signals to mask in the subthreads */
|
||||
@@ -59,7 +63,6 @@ static const int sig_list[] = {
|
||||
SIGVTALRM, SIGPROF, 0
|
||||
};
|
||||
|
||||
|
||||
static void *
|
||||
RunThread(void *data)
|
||||
{
|
||||
@@ -129,6 +132,12 @@ SDL_SYS_SetupThread(const char *name)
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
#elif HAVE_PTHREAD_SET_NAME_NP
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#elif defined(__HAIKU__)
|
||||
/* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
|
||||
char namebuf[B_OS_NAME_LENGTH];
|
||||
SDL_snprintf(namebuf, sizeof (namebuf), "%s", name);
|
||||
namebuf[sizeof (namebuf) - 1] = '\0';
|
||||
rename_thread(find_thread(NULL), namebuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -204,4 +213,10 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
pthread_join(thread->handle, 0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
pthread_detach(thread->handle);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -234,6 +234,12 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
{
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
#endif /* SDL_THREAD_WINDOWS */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#ifdef SDL_TIMER_BEOS
|
||||
#ifdef SDL_TIMER_HAIKU
|
||||
|
||||
#include <be/kernel/OS.h>
|
||||
#include <os/kernel/OS.h>
|
||||
|
||||
#include "SDL_timer.h"
|
||||
|
||||
@@ -69,6 +69,6 @@ SDL_Delay(Uint32 ms)
|
||||
snooze(ms * 1000);
|
||||
}
|
||||
|
||||
#endif /* SDL_TIMER_BEOS */
|
||||
#endif /* SDL_TIMER_HAIKU */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -150,6 +150,8 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
|
||||
biBitCount = SDL_ReadLE16(src);
|
||||
biCompression = BI_RGB;
|
||||
} else {
|
||||
const unsigned int headerSize = 40;
|
||||
|
||||
biWidth = SDL_ReadLE32(src);
|
||||
biHeight = SDL_ReadLE32(src);
|
||||
/* biPlanes = */ SDL_ReadLE16(src);
|
||||
@@ -160,6 +162,10 @@ SDL_LoadBMP_RW(SDL_RWops * src, int freesrc)
|
||||
/* biYPelsPerMeter = */ SDL_ReadLE32(src);
|
||||
biClrUsed = SDL_ReadLE32(src);
|
||||
/* biClrImportant = */ SDL_ReadLE32(src);
|
||||
|
||||
if (biSize > headerSize) {
|
||||
SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
|
||||
}
|
||||
}
|
||||
if (biHeight < 0) {
|
||||
topDown = SDL_TRUE;
|
||||
|
||||
@@ -23,8 +23,9 @@
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "SDL_sysvideo.h"
|
||||
#include "SDL_egl.h"
|
||||
|
||||
#include "SDL_egl_c.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_hints.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
/* Raspbian places the OpenGL ES/EGL binaries in a non standard path */
|
||||
@@ -40,12 +41,12 @@
|
||||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
|
||||
#define DEFAULT_OGL_ES "libGLESv1_CM.so"
|
||||
|
||||
#elif SDL_VIDEO_DRIVER_WINRT
|
||||
/* WinRT (via a modified version of Google's ANGLE library) */
|
||||
#elif SDL_VIDEO_DRIVER_WINDOWS
|
||||
/* EGL AND OpenGL ES support via ANGLE */
|
||||
#define DEFAULT_EGL "libEGL.dll"
|
||||
#define DEFAULT_OGL_ES2 "libGLESv2.dll"
|
||||
#define DEFAULT_OGL_ES_PVR NULL
|
||||
#define DEFAULT_OGL_ES NULL
|
||||
#define DEFAULT_OGL_ES_PVR "libGLES_CM.dll"
|
||||
#define DEFAULT_OGL_ES "libGLESv1_CM.dll"
|
||||
|
||||
#else
|
||||
/* Desktop Linux */
|
||||
@@ -56,7 +57,7 @@
|
||||
#endif /* SDL_VIDEO_DRIVER_RPI */
|
||||
|
||||
#define LOAD_FUNC(NAME) \
|
||||
*((void**)&_this->egl_data->NAME) = dlsym(dll_handle, #NAME); \
|
||||
*((void**)&_this->egl_data->NAME) = SDL_LoadFunction(_this->egl_data->dll_handle, #NAME); \
|
||||
if (!_this->egl_data->NAME) \
|
||||
{ \
|
||||
return SDL_SetError("Could not retrieve EGL function " #NAME); \
|
||||
@@ -68,12 +69,10 @@ void *
|
||||
SDL_EGL_GetProcAddress(_THIS, const char *proc)
|
||||
{
|
||||
static char procname[1024];
|
||||
void *handle;
|
||||
void *retval;
|
||||
|
||||
/* eglGetProcAddress is busted on Android http://code.google.com/p/android/issues/detail?id=7681 */
|
||||
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
handle = _this->egl_data->egl_dll_handle;
|
||||
#if !defined(SDL_VIDEO_DRIVER_ANDROID)
|
||||
if (_this->egl_data->eglGetProcAddress) {
|
||||
retval = _this->egl_data->eglGetProcAddress(proc);
|
||||
if (retval) {
|
||||
@@ -82,15 +81,11 @@ SDL_EGL_GetProcAddress(_THIS, const char *proc)
|
||||
}
|
||||
#endif
|
||||
|
||||
handle = _this->gl_config.dll_handle;
|
||||
#if defined(__OpenBSD__) && !defined(__ELF__)
|
||||
#undef dlsym(x,y);
|
||||
#endif
|
||||
retval = dlsym(handle, proc);
|
||||
if (!retval && strlen(proc) <= 1022) {
|
||||
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, proc);
|
||||
if (!retval && SDL_strlen(proc) <= 1022) {
|
||||
procname[0] = '_';
|
||||
strcpy(procname + 1, proc);
|
||||
retval = dlsym(handle, procname);
|
||||
SDL_strlcpy(procname + 1, proc, 1022);
|
||||
retval = SDL_LoadFunction(_this->egl_data->egl_dll_handle, procname);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -104,12 +99,12 @@ SDL_EGL_UnloadLibrary(_THIS)
|
||||
_this->egl_data->egl_display = NULL;
|
||||
}
|
||||
|
||||
if (_this->gl_config.dll_handle) {
|
||||
dlclose(_this->gl_config.dll_handle);
|
||||
_this->gl_config.dll_handle = NULL;
|
||||
if (_this->egl_data->dll_handle) {
|
||||
SDL_UnloadObject(_this->egl_data->dll_handle);
|
||||
_this->egl_data->dll_handle = NULL;
|
||||
}
|
||||
if (_this->egl_data->egl_dll_handle) {
|
||||
dlclose(_this->egl_data->egl_dll_handle);
|
||||
SDL_UnloadObject(_this->egl_data->egl_dll_handle);
|
||||
_this->egl_data->egl_dll_handle = NULL;
|
||||
}
|
||||
|
||||
@@ -121,10 +116,12 @@ SDL_EGL_UnloadLibrary(_THIS)
|
||||
int
|
||||
SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_display)
|
||||
{
|
||||
void *dll_handle, *egl_dll_handle; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
|
||||
char *path;
|
||||
int dlopen_flags;
|
||||
|
||||
void *dll_handle = NULL, *egl_dll_handle = NULL; /* The naming is counter intuitive, but hey, I just work here -- Gabriel */
|
||||
char *path = NULL;
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
const char *d3dcompiler;
|
||||
#endif
|
||||
|
||||
if (_this->egl_data) {
|
||||
return SDL_SetError("OpenGL ES context already created");
|
||||
}
|
||||
@@ -134,59 +131,63 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
#ifdef RTLD_GLOBAL
|
||||
dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
|
||||
#else
|
||||
dlopen_flags = RTLD_LAZY;
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
d3dcompiler = SDL_GetHint(SDL_HINT_VIDEO_WIN_D3DCOMPILER);
|
||||
if (!d3dcompiler) {
|
||||
/* By default we load the Vista+ compatible compiler */
|
||||
d3dcompiler = "d3dcompiler_46.dll";
|
||||
}
|
||||
if (SDL_strcasecmp(d3dcompiler, "none") != 0) {
|
||||
SDL_LoadObject(d3dcompiler);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* A funny thing, loading EGL.so first does not work on the Raspberry, so we load libGL* first */
|
||||
#ifdef __WINRT__
|
||||
path = NULL;
|
||||
egl_dll_handle = NULL;
|
||||
#else
|
||||
path = getenv("SDL_VIDEO_GL_DRIVER");
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
#endif
|
||||
if ((path == NULL) | (egl_dll_handle == NULL)) {
|
||||
path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
|
||||
if (path != NULL) {
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
|
||||
if (egl_dll_handle == NULL) {
|
||||
if (_this->gl_config.major_version > 1) {
|
||||
path = DEFAULT_OGL_ES2;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
} else {
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
else {
|
||||
path = DEFAULT_OGL_ES;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
if (egl_dll_handle == NULL) {
|
||||
path = DEFAULT_OGL_ES_PVR;
|
||||
egl_dll_handle = dlopen(path, dlopen_flags);
|
||||
egl_dll_handle = SDL_LoadObject(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
_this->egl_data->egl_dll_handle = egl_dll_handle;
|
||||
|
||||
if (egl_dll_handle == NULL) {
|
||||
return SDL_SetError("Could not initialize OpenGL ES library: %s", dlerror());
|
||||
return SDL_SetError("Could not initialize OpenGL ES library");
|
||||
}
|
||||
|
||||
|
||||
/* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
|
||||
dll_handle = dlopen(egl_path, dlopen_flags);
|
||||
if (egl_path != NULL) {
|
||||
dll_handle = SDL_LoadObject(egl_path);
|
||||
}
|
||||
/* Catch the case where the application isn't linked with EGL */
|
||||
if ((dlsym(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
|
||||
dlclose(dll_handle);
|
||||
#ifdef __WINRT__
|
||||
path = NULL;
|
||||
#else
|
||||
path = getenv("SDL_VIDEO_EGL_DRIVER");
|
||||
#endif
|
||||
if ((SDL_LoadFunction(dll_handle, "eglChooseConfig") == NULL) && (egl_path == NULL)) {
|
||||
if (dll_handle != NULL) {
|
||||
SDL_UnloadObject(dll_handle);
|
||||
}
|
||||
path = SDL_getenv("SDL_VIDEO_EGL_DRIVER");
|
||||
if (path == NULL) {
|
||||
path = DEFAULT_EGL;
|
||||
}
|
||||
dll_handle = dlopen(path, dlopen_flags);
|
||||
dll_handle = SDL_LoadObject(path);
|
||||
if (dll_handle == NULL) {
|
||||
return SDL_SetError("Could not load EGL library");
|
||||
}
|
||||
}
|
||||
_this->gl_config.dll_handle = dll_handle;
|
||||
|
||||
if (dll_handle == NULL) {
|
||||
return SDL_SetError("Could not load EGL library: %s", dlerror());
|
||||
}
|
||||
_this->egl_data->dll_handle = dll_handle;
|
||||
|
||||
/* Load new function pointers */
|
||||
LOAD_FUNC(eglGetDisplay);
|
||||
@@ -214,20 +215,18 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
|
||||
return SDL_SetError("Could not initialize EGL");
|
||||
}
|
||||
|
||||
_this->gl_config.dll_handle = dll_handle;
|
||||
_this->egl_data->dll_handle = dll_handle;
|
||||
_this->egl_data->egl_dll_handle = egl_dll_handle;
|
||||
_this->gl_config.driver_loaded = 1;
|
||||
|
||||
if (path) {
|
||||
strncpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
SDL_strlcpy(_this->gl_config.driver_path, path, sizeof(_this->gl_config.driver_path) - 1);
|
||||
} else {
|
||||
strcpy(_this->gl_config.driver_path, "");
|
||||
*_this->gl_config.driver_path = '\0';
|
||||
}
|
||||
|
||||
/* We need to select a config here to satisfy some video backends such as X11 */
|
||||
SDL_EGL_ChooseConfig(_this);
|
||||
|
||||
return 0;
|
||||
return SDL_EGL_ChooseConfig(_this);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -235,8 +234,10 @@ SDL_EGL_ChooseConfig(_THIS)
|
||||
{
|
||||
/* 64 seems nice. */
|
||||
EGLint attribs[64];
|
||||
EGLint found_configs = 0;
|
||||
int i;
|
||||
EGLint found_configs = 0, value;
|
||||
/* 128 seems even nicer here */
|
||||
EGLConfig configs[128];
|
||||
int i, j, best_bitdiff = -1, bitdiff;
|
||||
|
||||
if (!_this->egl_data) {
|
||||
/* The EGL library wasn't loaded, SDL_GetError() should have info */
|
||||
@@ -291,12 +292,43 @@ SDL_EGL_ChooseConfig(_THIS)
|
||||
|
||||
if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
|
||||
attribs,
|
||||
&_this->egl_data->egl_config, 1,
|
||||
configs, SDL_arraysize(configs),
|
||||
&found_configs) == EGL_FALSE ||
|
||||
found_configs == 0) {
|
||||
return SDL_SetError("Couldn't find matching EGL config");
|
||||
}
|
||||
|
||||
/* eglChooseConfig returns a number of configurations that match or exceed the requested attribs. */
|
||||
/* From those, we select the one that matches our requirements more closely via a makeshift algorithm */
|
||||
|
||||
for ( i=0; i<found_configs; i++ ) {
|
||||
bitdiff = 0;
|
||||
for (j = 0; j < SDL_arraysize(attribs) - 1; j += 2) {
|
||||
if (attribs[j] == EGL_NONE) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( attribs[j+1] != EGL_DONT_CARE && (
|
||||
attribs[j] == EGL_RED_SIZE ||
|
||||
attribs[j] == EGL_GREEN_SIZE ||
|
||||
attribs[j] == EGL_BLUE_SIZE ||
|
||||
attribs[j] == EGL_ALPHA_SIZE ||
|
||||
attribs[j] == EGL_DEPTH_SIZE ||
|
||||
attribs[j] == EGL_STENCIL_SIZE)) {
|
||||
_this->egl_data->eglGetConfigAttrib(_this->egl_data->egl_display, configs[i], attribs[j], &value);
|
||||
bitdiff += value - attribs[j + 1]; /* value is always >= attrib */
|
||||
}
|
||||
}
|
||||
|
||||
if (bitdiff < best_bitdiff || best_bitdiff == -1) {
|
||||
_this->egl_data->egl_config = configs[i];
|
||||
|
||||
best_bitdiff = bitdiff;
|
||||
}
|
||||
|
||||
if (bitdiff == 0) break; /* we found an exact match! */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -410,14 +442,11 @@ SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!egl_context && egl_context != EGL_NO_CONTEXT) {
|
||||
if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) {
|
||||
SDL_EGL_MakeCurrent(_this, NULL, NULL);
|
||||
_this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
|
||||
}
|
||||
|
||||
/* FIXME: This "crappy fix" comes from the X11 code,
|
||||
* it's required so you can create a GLX context, destroy it and create a EGL one */
|
||||
SDL_EGL_UnloadLibrary(_this);
|
||||
}
|
||||
|
||||
EGLSurface *
|
||||
|
||||
@@ -25,63 +25,44 @@
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#if defined(__WINRT__)
|
||||
|
||||
// DavidL: including this here leads to a compiler error:
|
||||
// C2016: C requires that a struct or union has at least one member
|
||||
// The error originates from a WinRT header file itself, roapi.h.
|
||||
//
|
||||
// Instead of including that file (EGL/egl.h), a subset of its contents is
|
||||
// made available as part of winrt/SDL_winrtegl.h
|
||||
//#include <EGL/egl.h>
|
||||
#include "winrt/SDL_winrtegl.h"
|
||||
|
||||
#else
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#if defined(__OpenBSD__) && !defined(__ELF__)
|
||||
#define dlsym(x,y) dlsym(x, "_" y)
|
||||
#endif
|
||||
|
||||
#endif /* ! defined(__WINRT__) */
|
||||
#include "SDL_egl.h"
|
||||
|
||||
#include "SDL_sysvideo.h"
|
||||
|
||||
typedef struct SDL_EGL_VideoData
|
||||
{
|
||||
void *egl_dll_handle;
|
||||
void *egl_dll_handle, *dll_handle;
|
||||
EGLDisplay egl_display;
|
||||
EGLConfig egl_config;
|
||||
int egl_swapinterval;
|
||||
|
||||
EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
|
||||
EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
|
||||
EGLint * minor);
|
||||
EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);
|
||||
EGLint * minor);
|
||||
EGLBoolean(EGLAPIENTRY *eglTerminate) (EGLDisplay dpy);
|
||||
|
||||
void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
|
||||
const EGLint * attrib_list,
|
||||
EGLConfig * configs,
|
||||
EGLint config_size, EGLint * num_config);
|
||||
const EGLint * attrib_list,
|
||||
EGLConfig * configs,
|
||||
EGLint config_size, EGLint * num_config);
|
||||
|
||||
EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
|
||||
EGLConfig config,
|
||||
EGLContext share_list,
|
||||
const EGLint * attrib_list);
|
||||
EGLConfig config,
|
||||
EGLContext share_list,
|
||||
const EGLint * attrib_list);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
|
||||
|
||||
EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
|
||||
EGLConfig config,
|
||||
NativeWindowType window,
|
||||
const EGLint * attrib_list);
|
||||
EGLConfig config,
|
||||
NativeWindowType window,
|
||||
const EGLint * attrib_list);
|
||||
EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
|
||||
EGLSurface read, EGLContext ctx);
|
||||
EGLSurface read, EGLContext ctx);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
|
||||
|
||||
@@ -89,12 +70,12 @@ typedef struct SDL_EGL_VideoData
|
||||
|
||||
const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
|
||||
EGLint attribute, EGLint * value);
|
||||
EGLBoolean(EGLAPIENTRY *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
|
||||
EGLint attribute, EGLint * value);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint engine);
|
||||
|
||||
EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
|
||||
EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
|
||||
} SDL_EGL_VideoData;
|
||||
|
||||
/* OpenGLES functions */
|
||||
@@ -132,105 +132,6 @@ DEFINE_SSE_FILLRECT(4, Uint32)
|
||||
/* *INDENT-ON* */
|
||||
#endif /* __SSE__ */
|
||||
|
||||
#ifdef __MMX__
|
||||
/* *INDENT-OFF* */
|
||||
|
||||
#define MMX_BEGIN \
|
||||
__m64 c64 = _mm_set_pi32(color, color)
|
||||
|
||||
#define MMX_WORK \
|
||||
for (i = n / 64; i--;) { \
|
||||
_mm_stream_pi((__m64 *)(p+0), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+8), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+16), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+24), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+32), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+40), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+48), c64); \
|
||||
_mm_stream_pi((__m64 *)(p+56), c64); \
|
||||
p += 64; \
|
||||
}
|
||||
|
||||
#define MMX_END \
|
||||
_mm_empty()
|
||||
|
||||
#define DEFINE_MMX_FILLRECT(bpp, type) \
|
||||
static void \
|
||||
SDL_FillRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
|
||||
{ \
|
||||
int i, n; \
|
||||
Uint8 *p = NULL; \
|
||||
\
|
||||
MMX_BEGIN; \
|
||||
\
|
||||
while (h--) { \
|
||||
n = w * bpp; \
|
||||
p = pixels; \
|
||||
\
|
||||
if (n > 63) { \
|
||||
int adjust = 8 - ((uintptr_t)p & 7); \
|
||||
if (adjust < 8) { \
|
||||
n -= adjust; \
|
||||
adjust /= bpp; \
|
||||
while (adjust--) { \
|
||||
*((type *)p) = (type)color; \
|
||||
p += bpp; \
|
||||
} \
|
||||
} \
|
||||
MMX_WORK; \
|
||||
} \
|
||||
if (n & 63) { \
|
||||
int remainder = (n & 63); \
|
||||
remainder /= bpp; \
|
||||
while (remainder--) { \
|
||||
*((type *)p) = (type)color; \
|
||||
p += bpp; \
|
||||
} \
|
||||
} \
|
||||
pixels += pitch; \
|
||||
} \
|
||||
\
|
||||
MMX_END; \
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_FillRect1MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
|
||||
{
|
||||
int i, n;
|
||||
Uint8 *p = NULL;
|
||||
|
||||
MMX_BEGIN;
|
||||
|
||||
while (h--) {
|
||||
n = w;
|
||||
p = pixels;
|
||||
|
||||
if (n > 63) {
|
||||
int adjust = 8 - ((uintptr_t)p & 7);
|
||||
if (adjust) {
|
||||
n -= adjust;
|
||||
SDL_memset(p, color, adjust);
|
||||
p += adjust;
|
||||
}
|
||||
MMX_WORK;
|
||||
}
|
||||
if (n & 63) {
|
||||
int remainder = (n & 63);
|
||||
SDL_memset(p, color, remainder);
|
||||
p += remainder;
|
||||
}
|
||||
pixels += pitch;
|
||||
}
|
||||
|
||||
MMX_END;
|
||||
}
|
||||
/* DEFINE_MMX_FILLRECT(1, Uint8) */
|
||||
DEFINE_MMX_FILLRECT(2, Uint16)
|
||||
DEFINE_MMX_FILLRECT(4, Uint32)
|
||||
|
||||
/* *INDENT-ON* */
|
||||
#endif /* __MMX__ */
|
||||
|
||||
static void
|
||||
SDL_FillRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
|
||||
{
|
||||
@@ -372,12 +273,6 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
|
||||
SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef __MMX__
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_FillRect1MMX(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
@@ -391,12 +286,6 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
|
||||
SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef __MMX__
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_FillRect2MMX(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
@@ -416,12 +305,6 @@ SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
|
||||
SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef __MMX__
|
||||
if (SDL_HasMMX()) {
|
||||
SDL_FillRect4MMX(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
|
||||
break;
|
||||
|
||||
@@ -1,401 +1,401 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_sysvideo_h
|
||||
#define _SDL_sysvideo_h
|
||||
|
||||
#include "SDL_messagebox.h"
|
||||
#include "SDL_shape.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* The SDL video driver */
|
||||
|
||||
typedef struct SDL_WindowShaper SDL_WindowShaper;
|
||||
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
|
||||
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
|
||||
typedef struct SDL_VideoDevice SDL_VideoDevice;
|
||||
|
||||
/* Define the SDL window-shaper structure */
|
||||
struct SDL_WindowShaper
|
||||
{
|
||||
/* The window associated with the shaper */
|
||||
SDL_Window *window;
|
||||
|
||||
/* The user's specified coordinates for the window, for once we give it a shape. */
|
||||
Uint32 userx,usery;
|
||||
|
||||
/* The parameters for shape calculation. */
|
||||
SDL_WindowShapeMode mode;
|
||||
|
||||
/* Has this window been assigned a shape? */
|
||||
SDL_bool hasshape;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Define the SDL shape driver structure */
|
||||
struct SDL_ShapeDriver
|
||||
{
|
||||
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
|
||||
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
int (*ResizeWindowShape)(SDL_Window *window);
|
||||
};
|
||||
|
||||
typedef struct SDL_WindowUserData
|
||||
{
|
||||
char *name;
|
||||
void *data;
|
||||
struct SDL_WindowUserData *next;
|
||||
} SDL_WindowUserData;
|
||||
|
||||
/* Define the SDL window structure, corresponding to toplevel windows */
|
||||
struct SDL_Window
|
||||
{
|
||||
const void *magic;
|
||||
Uint32 id;
|
||||
char *title;
|
||||
SDL_Surface *icon;
|
||||
int x, y;
|
||||
int w, h;
|
||||
int min_w, min_h;
|
||||
int max_w, max_h;
|
||||
Uint32 flags;
|
||||
|
||||
/* Stored position and size for windowed mode */
|
||||
SDL_Rect windowed;
|
||||
|
||||
SDL_DisplayMode fullscreen_mode;
|
||||
|
||||
float brightness;
|
||||
Uint16 *gamma;
|
||||
Uint16 *saved_gamma; /* (just offset into gamma) */
|
||||
|
||||
SDL_Surface *surface;
|
||||
SDL_bool surface_valid;
|
||||
|
||||
SDL_WindowShaper *shaper;
|
||||
|
||||
SDL_WindowUserData *data;
|
||||
|
||||
void *driverdata;
|
||||
|
||||
SDL_Window *prev;
|
||||
SDL_Window *next;
|
||||
};
|
||||
#define FULLSCREEN_VISIBLE(W) \
|
||||
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \
|
||||
((W)->flags & SDL_WINDOW_SHOWN) && \
|
||||
!((W)->flags & SDL_WINDOW_MINIMIZED))
|
||||
|
||||
/*
|
||||
* Define the SDL display structure This corresponds to physical monitors
|
||||
* attached to the system.
|
||||
*/
|
||||
struct SDL_VideoDisplay
|
||||
{
|
||||
char *name;
|
||||
int max_display_modes;
|
||||
int num_display_modes;
|
||||
SDL_DisplayMode *display_modes;
|
||||
SDL_DisplayMode desktop_mode;
|
||||
SDL_DisplayMode current_mode;
|
||||
|
||||
SDL_Window *fullscreen_window;
|
||||
|
||||
SDL_VideoDevice *device;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Forward declaration */
|
||||
struct SDL_SysWMinfo;
|
||||
|
||||
/* Define the SDL video driver structure */
|
||||
#define _THIS SDL_VideoDevice *_this
|
||||
|
||||
struct SDL_VideoDevice
|
||||
{
|
||||
/* * * */
|
||||
/* The name of this video driver */
|
||||
const char *name;
|
||||
|
||||
/* * * */
|
||||
/* Initialization/Query functions */
|
||||
|
||||
/*
|
||||
* Initialize the native video subsystem, filling in the list of
|
||||
* displays for this driver, returning 0 or -1 if there's an error.
|
||||
*/
|
||||
int (*VideoInit) (_THIS);
|
||||
|
||||
/*
|
||||
* Reverse the effects VideoInit() -- called if VideoInit() fails or
|
||||
* if the application is shutting down the video subsystem.
|
||||
*/
|
||||
void (*VideoQuit) (_THIS);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Display functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the bounds of a display
|
||||
*/
|
||||
int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
|
||||
|
||||
/*
|
||||
* Get a list of the available display modes for a display.
|
||||
*/
|
||||
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
|
||||
|
||||
/*
|
||||
* Setting the display mode is independent of creating windows, so
|
||||
* when the display mode is changed, all existing windows should have
|
||||
* their data updated accordingly, including the display surfaces
|
||||
* associated with them.
|
||||
*/
|
||||
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Window functions
|
||||
*/
|
||||
int (*CreateWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
|
||||
void (*SetWindowTitle) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
|
||||
void (*SetWindowPosition) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
|
||||
void (*ShowWindow) (_THIS, SDL_Window * window);
|
||||
void (*HideWindow) (_THIS, SDL_Window * window);
|
||||
void (*RaiseWindow) (_THIS, SDL_Window * window);
|
||||
void (*MaximizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*MinimizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*RestoreWindow) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
|
||||
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
|
||||
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
|
||||
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
|
||||
void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
|
||||
void (*DestroyWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
|
||||
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
|
||||
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
|
||||
void (*OnWindowEnter) (_THIS, SDL_Window * window);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Shaped-window functions
|
||||
*/
|
||||
SDL_ShapeDriver shape_driver;
|
||||
|
||||
/* Get some platform dependent window information */
|
||||
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
|
||||
struct SDL_SysWMinfo * info);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* OpenGL support
|
||||
*/
|
||||
int (*GL_LoadLibrary) (_THIS, const char *path);
|
||||
void *(*GL_GetProcAddress) (_THIS, const char *proc);
|
||||
void (*GL_UnloadLibrary) (_THIS);
|
||||
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
|
||||
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
|
||||
int (*GL_SetSwapInterval) (_THIS, int interval);
|
||||
int (*GL_GetSwapInterval) (_THIS);
|
||||
void (*GL_SwapWindow) (_THIS, SDL_Window * window);
|
||||
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Event manager functions
|
||||
*/
|
||||
void (*PumpEvents) (_THIS);
|
||||
|
||||
/* Suspend the screensaver */
|
||||
void (*SuspendScreenSaver) (_THIS);
|
||||
|
||||
/* Text input */
|
||||
void (*StartTextInput) (_THIS);
|
||||
void (*StopTextInput) (_THIS);
|
||||
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
|
||||
|
||||
/* Screen keyboard */
|
||||
SDL_bool (*HasScreenKeyboardSupport) (_THIS);
|
||||
void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
|
||||
|
||||
/* Clipboard */
|
||||
int (*SetClipboardText) (_THIS, const char *text);
|
||||
char * (*GetClipboardText) (_THIS);
|
||||
SDL_bool (*HasClipboardText) (_THIS);
|
||||
|
||||
/* MessageBox */
|
||||
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
|
||||
|
||||
/* * * */
|
||||
/* Data common to all drivers */
|
||||
SDL_bool suspend_screensaver;
|
||||
int num_displays;
|
||||
SDL_VideoDisplay *displays;
|
||||
SDL_Window *windows;
|
||||
Uint8 window_magic;
|
||||
Uint32 next_object_id;
|
||||
char * clipboard_text;
|
||||
|
||||
/* * * */
|
||||
/* Data used by the GL drivers */
|
||||
struct
|
||||
{
|
||||
int red_size;
|
||||
int green_size;
|
||||
int blue_size;
|
||||
int alpha_size;
|
||||
int depth_size;
|
||||
int buffer_size;
|
||||
int stencil_size;
|
||||
int double_buffer;
|
||||
int accum_red_size;
|
||||
int accum_green_size;
|
||||
int accum_blue_size;
|
||||
int accum_alpha_size;
|
||||
int stereo;
|
||||
int multisamplebuffers;
|
||||
int multisamplesamples;
|
||||
int accelerated;
|
||||
int major_version;
|
||||
int minor_version;
|
||||
int flags;
|
||||
int profile_mask;
|
||||
int share_with_current_context;
|
||||
int framebuffer_srgb_capable;
|
||||
int retained_backing;
|
||||
int driver_loaded;
|
||||
char driver_path[256];
|
||||
void *dll_handle;
|
||||
} gl_config;
|
||||
|
||||
/* * * */
|
||||
/* Cache current GL context; don't call the OS when it hasn't changed. */
|
||||
/* We have the global pointers here so Cocoa continues to work the way
|
||||
it always has, and the thread-local storage for the general case.
|
||||
*/
|
||||
SDL_Window *current_glwin;
|
||||
SDL_GLContext current_glctx;
|
||||
SDL_TLSID current_glwin_tls;
|
||||
SDL_TLSID current_glctx_tls;
|
||||
|
||||
/* * * */
|
||||
/* Data private to this driver */
|
||||
void *driverdata;
|
||||
struct SDL_GLDriverData *gl_data;
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
struct SDL_EGL_VideoData *egl_data;
|
||||
#endif
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
||||
struct SDL_PrivateGLESData *gles_data;
|
||||
#endif
|
||||
|
||||
/* * * */
|
||||
/* The function used to dispose of this structure */
|
||||
void (*free) (_THIS);
|
||||
};
|
||||
|
||||
typedef struct VideoBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
int (*available) (void);
|
||||
SDL_VideoDevice *(*create) (int devindex);
|
||||
} VideoBootStrap;
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
extern VideoBootStrap COCOA_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_X11
|
||||
extern VideoBootStrap X11_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DIRECTFB
|
||||
extern VideoBootStrap DirectFB_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
extern VideoBootStrap WINDOWS_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
extern VideoBootStrap WINRT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
extern VideoBootStrap BWINDOW_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PANDORA
|
||||
extern VideoBootStrap PND_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
extern VideoBootStrap UIKIT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
extern VideoBootStrap Android_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PSP
|
||||
extern VideoBootStrap PSP_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
extern VideoBootStrap RPI_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DUMMY
|
||||
extern VideoBootStrap DUMMY_bootstrap;
|
||||
#endif
|
||||
|
||||
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
|
||||
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
|
||||
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
|
||||
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
|
||||
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
|
||||
extern void *SDL_GetDisplayDriverData( int displayIndex );
|
||||
|
||||
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
|
||||
|
||||
extern void SDL_OnWindowShown(SDL_Window * window);
|
||||
extern void SDL_OnWindowHidden(SDL_Window * window);
|
||||
extern void SDL_OnWindowResized(SDL_Window * window);
|
||||
extern void SDL_OnWindowMinimized(SDL_Window * window);
|
||||
extern void SDL_OnWindowRestored(SDL_Window * window);
|
||||
extern void SDL_OnWindowEnter(SDL_Window * window);
|
||||
extern void SDL_OnWindowLeave(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusGained(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusLost(SDL_Window * window);
|
||||
extern void SDL_UpdateWindowGrab(SDL_Window * window);
|
||||
extern SDL_Window * SDL_GetFocusWindow(void);
|
||||
|
||||
extern SDL_bool SDL_ShouldAllowTopmost(void);
|
||||
|
||||
#endif /* _SDL_sysvideo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_sysvideo_h
|
||||
#define _SDL_sysvideo_h
|
||||
|
||||
#include "SDL_messagebox.h"
|
||||
#include "SDL_shape.h"
|
||||
#include "SDL_thread.h"
|
||||
|
||||
/* The SDL video driver */
|
||||
|
||||
typedef struct SDL_WindowShaper SDL_WindowShaper;
|
||||
typedef struct SDL_ShapeDriver SDL_ShapeDriver;
|
||||
typedef struct SDL_VideoDisplay SDL_VideoDisplay;
|
||||
typedef struct SDL_VideoDevice SDL_VideoDevice;
|
||||
|
||||
/* Define the SDL window-shaper structure */
|
||||
struct SDL_WindowShaper
|
||||
{
|
||||
/* The window associated with the shaper */
|
||||
SDL_Window *window;
|
||||
|
||||
/* The user's specified coordinates for the window, for once we give it a shape. */
|
||||
Uint32 userx,usery;
|
||||
|
||||
/* The parameters for shape calculation. */
|
||||
SDL_WindowShapeMode mode;
|
||||
|
||||
/* Has this window been assigned a shape? */
|
||||
SDL_bool hasshape;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Define the SDL shape driver structure */
|
||||
struct SDL_ShapeDriver
|
||||
{
|
||||
SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
|
||||
int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
|
||||
int (*ResizeWindowShape)(SDL_Window *window);
|
||||
};
|
||||
|
||||
typedef struct SDL_WindowUserData
|
||||
{
|
||||
char *name;
|
||||
void *data;
|
||||
struct SDL_WindowUserData *next;
|
||||
} SDL_WindowUserData;
|
||||
|
||||
/* Define the SDL window structure, corresponding to toplevel windows */
|
||||
struct SDL_Window
|
||||
{
|
||||
const void *magic;
|
||||
Uint32 id;
|
||||
char *title;
|
||||
SDL_Surface *icon;
|
||||
int x, y;
|
||||
int w, h;
|
||||
int min_w, min_h;
|
||||
int max_w, max_h;
|
||||
Uint32 flags;
|
||||
|
||||
/* Stored position and size for windowed mode */
|
||||
SDL_Rect windowed;
|
||||
|
||||
SDL_DisplayMode fullscreen_mode;
|
||||
|
||||
float brightness;
|
||||
Uint16 *gamma;
|
||||
Uint16 *saved_gamma; /* (just offset into gamma) */
|
||||
|
||||
SDL_Surface *surface;
|
||||
SDL_bool surface_valid;
|
||||
|
||||
SDL_WindowShaper *shaper;
|
||||
|
||||
SDL_WindowUserData *data;
|
||||
|
||||
void *driverdata;
|
||||
|
||||
SDL_Window *prev;
|
||||
SDL_Window *next;
|
||||
};
|
||||
#define FULLSCREEN_VISIBLE(W) \
|
||||
(((W)->flags & SDL_WINDOW_FULLSCREEN) && \
|
||||
((W)->flags & SDL_WINDOW_SHOWN) && \
|
||||
!((W)->flags & SDL_WINDOW_MINIMIZED))
|
||||
|
||||
/*
|
||||
* Define the SDL display structure This corresponds to physical monitors
|
||||
* attached to the system.
|
||||
*/
|
||||
struct SDL_VideoDisplay
|
||||
{
|
||||
char *name;
|
||||
int max_display_modes;
|
||||
int num_display_modes;
|
||||
SDL_DisplayMode *display_modes;
|
||||
SDL_DisplayMode desktop_mode;
|
||||
SDL_DisplayMode current_mode;
|
||||
|
||||
SDL_Window *fullscreen_window;
|
||||
|
||||
SDL_VideoDevice *device;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
/* Forward declaration */
|
||||
struct SDL_SysWMinfo;
|
||||
|
||||
/* Define the SDL video driver structure */
|
||||
#define _THIS SDL_VideoDevice *_this
|
||||
|
||||
struct SDL_VideoDevice
|
||||
{
|
||||
/* * * */
|
||||
/* The name of this video driver */
|
||||
const char *name;
|
||||
|
||||
/* * * */
|
||||
/* Initialization/Query functions */
|
||||
|
||||
/*
|
||||
* Initialize the native video subsystem, filling in the list of
|
||||
* displays for this driver, returning 0 or -1 if there's an error.
|
||||
*/
|
||||
int (*VideoInit) (_THIS);
|
||||
|
||||
/*
|
||||
* Reverse the effects VideoInit() -- called if VideoInit() fails or
|
||||
* if the application is shutting down the video subsystem.
|
||||
*/
|
||||
void (*VideoQuit) (_THIS);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Display functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the bounds of a display
|
||||
*/
|
||||
int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
|
||||
|
||||
/*
|
||||
* Get a list of the available display modes for a display.
|
||||
*/
|
||||
void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
|
||||
|
||||
/*
|
||||
* Setting the display mode is independent of creating windows, so
|
||||
* when the display mode is changed, all existing windows should have
|
||||
* their data updated accordingly, including the display surfaces
|
||||
* associated with them.
|
||||
*/
|
||||
int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Window functions
|
||||
*/
|
||||
int (*CreateWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
|
||||
void (*SetWindowTitle) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
|
||||
void (*SetWindowPosition) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
|
||||
void (*ShowWindow) (_THIS, SDL_Window * window);
|
||||
void (*HideWindow) (_THIS, SDL_Window * window);
|
||||
void (*RaiseWindow) (_THIS, SDL_Window * window);
|
||||
void (*MaximizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*MinimizeWindow) (_THIS, SDL_Window * window);
|
||||
void (*RestoreWindow) (_THIS, SDL_Window * window);
|
||||
void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
|
||||
void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
|
||||
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
|
||||
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
|
||||
void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
|
||||
void (*DestroyWindow) (_THIS, SDL_Window * window);
|
||||
int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
|
||||
int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
|
||||
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
|
||||
void (*OnWindowEnter) (_THIS, SDL_Window * window);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Shaped-window functions
|
||||
*/
|
||||
SDL_ShapeDriver shape_driver;
|
||||
|
||||
/* Get some platform dependent window information */
|
||||
SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
|
||||
struct SDL_SysWMinfo * info);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* OpenGL support
|
||||
*/
|
||||
int (*GL_LoadLibrary) (_THIS, const char *path);
|
||||
void *(*GL_GetProcAddress) (_THIS, const char *proc);
|
||||
void (*GL_UnloadLibrary) (_THIS);
|
||||
SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
|
||||
int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
|
||||
int (*GL_SetSwapInterval) (_THIS, int interval);
|
||||
int (*GL_GetSwapInterval) (_THIS);
|
||||
void (*GL_SwapWindow) (_THIS, SDL_Window * window);
|
||||
void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
|
||||
|
||||
/* * * */
|
||||
/*
|
||||
* Event manager functions
|
||||
*/
|
||||
void (*PumpEvents) (_THIS);
|
||||
|
||||
/* Suspend the screensaver */
|
||||
void (*SuspendScreenSaver) (_THIS);
|
||||
|
||||
/* Text input */
|
||||
void (*StartTextInput) (_THIS);
|
||||
void (*StopTextInput) (_THIS);
|
||||
void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
|
||||
|
||||
/* Screen keyboard */
|
||||
SDL_bool (*HasScreenKeyboardSupport) (_THIS);
|
||||
void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
|
||||
SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
|
||||
|
||||
/* Clipboard */
|
||||
int (*SetClipboardText) (_THIS, const char *text);
|
||||
char * (*GetClipboardText) (_THIS);
|
||||
SDL_bool (*HasClipboardText) (_THIS);
|
||||
|
||||
/* MessageBox */
|
||||
int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
|
||||
|
||||
/* * * */
|
||||
/* Data common to all drivers */
|
||||
SDL_bool suspend_screensaver;
|
||||
int num_displays;
|
||||
SDL_VideoDisplay *displays;
|
||||
SDL_Window *windows;
|
||||
Uint8 window_magic;
|
||||
Uint32 next_object_id;
|
||||
char * clipboard_text;
|
||||
|
||||
/* * * */
|
||||
/* Data used by the GL drivers */
|
||||
struct
|
||||
{
|
||||
int red_size;
|
||||
int green_size;
|
||||
int blue_size;
|
||||
int alpha_size;
|
||||
int depth_size;
|
||||
int buffer_size;
|
||||
int stencil_size;
|
||||
int double_buffer;
|
||||
int accum_red_size;
|
||||
int accum_green_size;
|
||||
int accum_blue_size;
|
||||
int accum_alpha_size;
|
||||
int stereo;
|
||||
int multisamplebuffers;
|
||||
int multisamplesamples;
|
||||
int accelerated;
|
||||
int major_version;
|
||||
int minor_version;
|
||||
int flags;
|
||||
int profile_mask;
|
||||
int share_with_current_context;
|
||||
int framebuffer_srgb_capable;
|
||||
int retained_backing;
|
||||
int driver_loaded;
|
||||
char driver_path[256];
|
||||
void *dll_handle;
|
||||
} gl_config;
|
||||
|
||||
/* * * */
|
||||
/* Cache current GL context; don't call the OS when it hasn't changed. */
|
||||
/* We have the global pointers here so Cocoa continues to work the way
|
||||
it always has, and the thread-local storage for the general case.
|
||||
*/
|
||||
SDL_Window *current_glwin;
|
||||
SDL_GLContext current_glctx;
|
||||
SDL_TLSID current_glwin_tls;
|
||||
SDL_TLSID current_glctx_tls;
|
||||
|
||||
/* * * */
|
||||
/* Data private to this driver */
|
||||
void *driverdata;
|
||||
struct SDL_GLDriverData *gl_data;
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
struct SDL_EGL_VideoData *egl_data;
|
||||
#endif
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
|
||||
struct SDL_PrivateGLESData *gles_data;
|
||||
#endif
|
||||
|
||||
/* * * */
|
||||
/* The function used to dispose of this structure */
|
||||
void (*free) (_THIS);
|
||||
};
|
||||
|
||||
typedef struct VideoBootStrap
|
||||
{
|
||||
const char *name;
|
||||
const char *desc;
|
||||
int (*available) (void);
|
||||
SDL_VideoDevice *(*create) (int devindex);
|
||||
} VideoBootStrap;
|
||||
|
||||
#if SDL_VIDEO_DRIVER_COCOA
|
||||
extern VideoBootStrap COCOA_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_X11
|
||||
extern VideoBootStrap X11_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DIRECTFB
|
||||
extern VideoBootStrap DirectFB_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS
|
||||
extern VideoBootStrap WINDOWS_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_WINRT
|
||||
extern VideoBootStrap WINRT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
extern VideoBootStrap HAIKU_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PANDORA
|
||||
extern VideoBootStrap PND_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
extern VideoBootStrap UIKIT_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_ANDROID
|
||||
extern VideoBootStrap Android_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_PSP
|
||||
extern VideoBootStrap PSP_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_RPI
|
||||
extern VideoBootStrap RPI_bootstrap;
|
||||
#endif
|
||||
#if SDL_VIDEO_DRIVER_DUMMY
|
||||
extern VideoBootStrap DUMMY_bootstrap;
|
||||
#endif
|
||||
|
||||
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
|
||||
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
|
||||
extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
|
||||
extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
|
||||
extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
|
||||
extern void *SDL_GetDisplayDriverData( int displayIndex );
|
||||
|
||||
extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
|
||||
|
||||
extern void SDL_OnWindowShown(SDL_Window * window);
|
||||
extern void SDL_OnWindowHidden(SDL_Window * window);
|
||||
extern void SDL_OnWindowResized(SDL_Window * window);
|
||||
extern void SDL_OnWindowMinimized(SDL_Window * window);
|
||||
extern void SDL_OnWindowRestored(SDL_Window * window);
|
||||
extern void SDL_OnWindowEnter(SDL_Window * window);
|
||||
extern void SDL_OnWindowLeave(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusGained(SDL_Window * window);
|
||||
extern void SDL_OnWindowFocusLost(SDL_Window * window);
|
||||
extern void SDL_UpdateWindowGrab(SDL_Window * window);
|
||||
extern SDL_Window * SDL_GetFocusWindow(void);
|
||||
|
||||
extern SDL_bool SDL_ShouldAllowTopmost(void);
|
||||
|
||||
#endif /* _SDL_sysvideo_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -82,7 +82,9 @@ Android_PumpEvents(_THIS)
|
||||
isPaused = 0;
|
||||
|
||||
/* Restore the GL Context from here, as this operation is thread dependent */
|
||||
android_egl_context_restore();
|
||||
if (!SDL_HasEvent(SDL_QUIT)) {
|
||||
android_egl_context_restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
/* Android SDL video driver implementation */
|
||||
|
||||
#include "SDL_video.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
#include "SDL_androidwindow.h"
|
||||
|
||||
#include "SDL_androidvideo.h"
|
||||
|
||||
@@ -262,6 +262,7 @@ static SDL_Scancode Android_Keycodes[] = {
|
||||
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_ASSIST */
|
||||
SDL_SCANCODE_BRIGHTNESSDOWN, /* AKEYCODE_BRIGHTNESS_DOWN */
|
||||
SDL_SCANCODE_BRIGHTNESSUP, /* AKEYCODE_BRIGHTNESS_UP */
|
||||
SDL_SCANCODE_UNKNOWN, /* AKEYCODE_MEDIA_AUDIO_TRACK */
|
||||
};
|
||||
|
||||
static SDL_Scancode
|
||||
|
||||
@@ -38,11 +38,8 @@
|
||||
#define ACTION_MOVE 2
|
||||
#define ACTION_CANCEL 3
|
||||
#define ACTION_OUTSIDE 4
|
||||
/* The following two are deprecated but it seems they are still emitted (instead the corresponding ACTION_UP/DOWN) as of Android 3.2 */
|
||||
#define ACTION_POINTER_1_DOWN 5
|
||||
#define ACTION_POINTER_1_UP 6
|
||||
|
||||
static SDL_FingerID leftFingerDown = 0;
|
||||
#define ACTION_POINTER_DOWN 5
|
||||
#define ACTION_POINTER_UP 6
|
||||
|
||||
static void Android_GetWindowCoordinates(float x, float y,
|
||||
int *window_x, int *window_y)
|
||||
@@ -72,6 +69,7 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
|
||||
SDL_TouchID touchDeviceId = 0;
|
||||
SDL_FingerID fingerId = 0;
|
||||
int window_x, window_y;
|
||||
static SDL_FingerID pointerFingerID = 0;
|
||||
|
||||
if (!Android_Window) {
|
||||
return;
|
||||
@@ -85,22 +83,20 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
|
||||
fingerId = (SDL_FingerID)pointer_finger_id_in;
|
||||
switch (action) {
|
||||
case ACTION_DOWN:
|
||||
case ACTION_POINTER_1_DOWN:
|
||||
if (!leftFingerDown) {
|
||||
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||
|
||||
/* send moved event */
|
||||
SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
|
||||
|
||||
/* send mouse down event */
|
||||
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
|
||||
leftFingerDown = fingerId;
|
||||
}
|
||||
/* Primary pointer down */
|
||||
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||
/* send moved event */
|
||||
SDL_SendMouseMotion(NULL, SDL_TOUCH_MOUSEID, 0, window_x, window_y);
|
||||
/* send mouse down event */
|
||||
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
pointerFingerID = fingerId;
|
||||
case ACTION_POINTER_DOWN:
|
||||
/* Non primary pointer down */
|
||||
SDL_SendTouch(touchDeviceId, fingerId, SDL_TRUE, x, y, p);
|
||||
break;
|
||||
|
||||
case ACTION_MOVE:
|
||||
if (!leftFingerDown) {
|
||||
if (!pointerFingerID) {
|
||||
Android_GetWindowCoordinates(x, y, &window_x, &window_y);
|
||||
|
||||
/* send moved event */
|
||||
@@ -108,15 +104,17 @@ void Android_OnTouch(int touch_device_id_in, int pointer_finger_id_in, int actio
|
||||
}
|
||||
SDL_SendTouchMotion(touchDeviceId, fingerId, x, y, p);
|
||||
break;
|
||||
|
||||
case ACTION_UP:
|
||||
case ACTION_POINTER_1_UP:
|
||||
if (fingerId == leftFingerDown) {
|
||||
/* send mouse up */
|
||||
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
leftFingerDown = 0;
|
||||
}
|
||||
/* Primary pointer up */
|
||||
/* send mouse up */
|
||||
pointerFingerID = (SDL_FingerID) 0;
|
||||
SDL_SendMouseButton(NULL, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
case ACTION_POINTER_UP:
|
||||
/* Non primary pointer up */
|
||||
SDL_SendTouch(touchDeviceId, fingerId, SDL_FALSE, x, y, p);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
static int Android_VideoInit(_THIS);
|
||||
static void Android_VideoQuit(_THIS);
|
||||
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
/* GL functions (SDL_androidgl.c) */
|
||||
extern SDL_GLContext Android_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
extern int Android_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
|
||||
@@ -72,6 +72,7 @@ Android_CreateWindow(_THIS, SDL_Window * window)
|
||||
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
|
||||
|
||||
if (data->egl_surface == EGL_NO_SURFACE) {
|
||||
ANativeWindow_release(data->native_window);
|
||||
SDL_free(data);
|
||||
return SDL_SetError("Could not create GLES window surface");
|
||||
}
|
||||
@@ -102,6 +103,9 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
|
||||
|
||||
if(window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
if (data->egl_surface != EGL_NO_SURFACE) {
|
||||
SDL_EGL_DestroySurface(_this, data->egl_surface);
|
||||
}
|
||||
if(data->native_window) {
|
||||
ANativeWindow_release(data->native_window);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#define _SDL_androidwindow_h
|
||||
|
||||
#include "../../core/android/SDL_android.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
extern int Android_CreateWindow(_THIS, SDL_Window * window);
|
||||
extern void Android_SetWindowTitle(_THIS, SDL_Window * window);
|
||||
|
||||
@@ -147,6 +147,7 @@ CreateApplicationMenus(void)
|
||||
NSMenu *appleMenu;
|
||||
NSMenu *serviceMenu;
|
||||
NSMenu *windowMenu;
|
||||
NSMenu *viewMenu;
|
||||
NSMenuItem *menuItem;
|
||||
|
||||
if (NSApp == nil) {
|
||||
@@ -220,6 +221,25 @@ CreateApplicationMenus(void)
|
||||
/* Tell the application object that this is now the window menu */
|
||||
[NSApp setWindowsMenu:windowMenu];
|
||||
[windowMenu release];
|
||||
|
||||
|
||||
/* Add the fullscreen view toggle menu option, if supported */
|
||||
if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) {
|
||||
/* Create the view menu */
|
||||
viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
|
||||
|
||||
/* Add menu items */
|
||||
menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
|
||||
[menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
|
||||
|
||||
/* Put menu into the menubar */
|
||||
menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
|
||||
[menuItem setSubmenu:viewMenu];
|
||||
[[NSApp mainMenu] addItem:menuItem];
|
||||
[menuItem release];
|
||||
|
||||
[viewMenu release];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -198,45 +198,6 @@
|
||||
|
||||
@end
|
||||
|
||||
/* This is the original behavior, before support was added for
|
||||
* differentiating between left and right versions of the keys.
|
||||
*/
|
||||
static void
|
||||
DoUnsidedModifiers(unsigned short scancode,
|
||||
unsigned int oldMods, unsigned int newMods)
|
||||
{
|
||||
const int mapping[] = {
|
||||
SDL_SCANCODE_CAPSLOCK,
|
||||
SDL_SCANCODE_LSHIFT,
|
||||
SDL_SCANCODE_LCTRL,
|
||||
SDL_SCANCODE_LALT,
|
||||
SDL_SCANCODE_LGUI
|
||||
};
|
||||
unsigned int i, bit;
|
||||
|
||||
/* Iterate through the bits, testing each against the current modifiers */
|
||||
for (i = 0, bit = NSAlphaShiftKeyMask; bit <= NSCommandKeyMask; bit <<= 1, ++i) {
|
||||
unsigned int oldMask, newMask;
|
||||
|
||||
oldMask = oldMods & bit;
|
||||
newMask = newMods & bit;
|
||||
|
||||
if (oldMask && oldMask != newMask) { /* modifier up event */
|
||||
/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
|
||||
if (bit == NSAlphaShiftKeyMask) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]);
|
||||
}
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]);
|
||||
} else if (newMask && oldMask != newMask) { /* modifier down event */
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]);
|
||||
/* If this was Caps Lock, we need some additional voodoo to make SDL happy */
|
||||
if (bit == NSAlphaShiftKeyMask) {
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This is a helper function for HandleModifierSide. This
|
||||
* function reverts back to behavior before the distinction between
|
||||
* sides was made.
|
||||
@@ -458,15 +419,7 @@ HandleModifiers(_THIS, unsigned short scancode, unsigned int modifierFlags)
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Starting with Panther (10.3.0), the ability to distinguish between
|
||||
* left side and right side modifiers is available.
|
||||
*/
|
||||
if (data->osversion >= 0x1030) {
|
||||
DoSidedModifiers(scancode, data->modifierFlags, modifierFlags);
|
||||
} else {
|
||||
DoUnsidedModifiers(scancode, data->modifierFlags, modifierFlags);
|
||||
}
|
||||
DoSidedModifiers(scancode, data->modifierFlags, modifierFlags);
|
||||
data->modifierFlags = modifierFlags;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,9 +60,10 @@ static const CGEventMask allGrabbedEventsMask =
|
||||
static CGEventRef
|
||||
Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
|
||||
{
|
||||
SDL_MouseData *driverdata = (SDL_MouseData*)refcon;
|
||||
SDL_MouseEventTapData *tapdata = (SDL_MouseEventTapData*)refcon;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
NSRect windowRect;
|
||||
CGPoint eventLocation;
|
||||
|
||||
@@ -71,7 +72,7 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
|
||||
case kCGEventTapDisabledByTimeout:
|
||||
case kCGEventTapDisabledByUserInput:
|
||||
{
|
||||
CGEventTapEnable(((SDL_MouseEventTapData*)(driverdata->tapdata))->tap, true);
|
||||
CGEventTapEnable(tapdata->tap, true);
|
||||
return NULL;
|
||||
}
|
||||
default:
|
||||
@@ -93,7 +94,7 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
|
||||
|
||||
/* This is the same coordinate system as Cocoa uses. */
|
||||
eventLocation = CGEventGetUnflippedLocation(event);
|
||||
windowRect = [((SDL_WindowData *) window->driverdata)->nswindow frame];
|
||||
windowRect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
|
||||
if (!NSPointInRect(NSPointFromCGPoint(eventLocation), windowRect)) {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
||||
/* New methods for converting to and from backing store pixels, taken from
|
||||
* AppKite/NSView.h in 10.8 SDK. */
|
||||
* AppKit/NSView.h in 10.8 SDK. */
|
||||
@interface NSView (Backing)
|
||||
- (NSPoint)convertPointToBacking:(NSPoint)aPoint;
|
||||
- (NSPoint)convertPointFromBacking:(NSPoint)aPoint;
|
||||
@@ -54,8 +54,11 @@
|
||||
#ifndef kCGLOGLPVersion_Legacy
|
||||
#define kCGLOGLPVersion_Legacy 0x1000
|
||||
#endif
|
||||
#ifndef kCGLOGLPVersion_3_2_Core
|
||||
#define kCGLOGLPVersion_3_2_Core 0x3200
|
||||
#ifndef kCGLOGLPVersion_GL3_Core
|
||||
#define kCGLOGLPVersion_GL3_Core 0x3200
|
||||
#endif
|
||||
#ifndef kCGLOGLPVersion_GL4_Core
|
||||
#define kCGLOGLPVersion_GL4_Core 0x4100
|
||||
#endif
|
||||
|
||||
@implementation SDLOpenGLContext : NSOpenGLContext
|
||||
@@ -179,14 +182,14 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
int i = 0;
|
||||
|
||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
SDL_SetError ("OpenGL ES not supported on this platform");
|
||||
SDL_SetError ("OpenGL ES is not supported on this platform");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Sadly, we'll have to update this as life progresses, since we need to
|
||||
set an enum for context profiles, not a context version number */
|
||||
if (wantver > 0x0302) {
|
||||
SDL_SetError ("OpenGL > 3.2 is not supported on this platform");
|
||||
if (wantver > 0x0401) {
|
||||
SDL_SetError ("OpenGL > 4.1 is not supported on this platform");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -197,7 +200,13 @@ Cocoa_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
NSOpenGLPixelFormatAttribute profile = kCGLOGLPVersion_Legacy;
|
||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_CORE) {
|
||||
if (wantver == 0x0302) {
|
||||
profile = kCGLOGLPVersion_3_2_Core;
|
||||
profile = kCGLOGLPVersion_GL3_Core;
|
||||
} else if ((wantver == 0x0401) && (data->osversion >= 0x1090)) {
|
||||
profile = kCGLOGLPVersion_GL4_Core;
|
||||
} else {
|
||||
SDL_SetError("Requested GL version is not supported on this platform");
|
||||
[pool release];
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
attr[i++] = kCGLPFAOpenGLProfile;
|
||||
|
||||
@@ -92,7 +92,7 @@ Cocoa_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShape
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
closure.view = [windata->nswindow contentView];
|
||||
closure.path = [[NSBezierPath bezierPath] autorelease];
|
||||
closure.path = [[NSBezierPath bezierPath] init];
|
||||
closure.window = shaper->window;
|
||||
SDL_TraverseShapeTree(data->shape,&ConvertRects,&closure);
|
||||
[closure.path addClip];
|
||||
|
||||
@@ -27,16 +27,31 @@
|
||||
|
||||
typedef struct SDL_WindowData SDL_WindowData;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PENDING_OPERATION_NONE,
|
||||
PENDING_OPERATION_ENTER_FULLSCREEN,
|
||||
PENDING_OPERATION_LEAVE_FULLSCREEN,
|
||||
PENDING_OPERATION_MINIMIZE
|
||||
} PendingWindowOperation;
|
||||
|
||||
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
|
||||
SDL_WindowData *_data;
|
||||
BOOL observingVisible;
|
||||
BOOL wasCtrlLeft;
|
||||
BOOL wasVisible;
|
||||
BOOL isFullscreenSpace;
|
||||
BOOL inFullscreenTransition;
|
||||
PendingWindowOperation pendingWindowOperation;
|
||||
}
|
||||
|
||||
-(void) listen:(SDL_WindowData *) data;
|
||||
-(void) pauseVisibleObservation;
|
||||
-(void) resumeVisibleObservation;
|
||||
-(BOOL) setFullscreenSpace:(BOOL) state;
|
||||
-(BOOL) isInFullscreenSpace;
|
||||
-(BOOL) isInFullscreenSpaceTransition;
|
||||
-(void) addPendingWindowOperation:(PendingWindowOperation) operation;
|
||||
-(void) close;
|
||||
|
||||
/* Window delegate functionality */
|
||||
@@ -48,6 +63,10 @@ typedef struct SDL_WindowData SDL_WindowData;
|
||||
-(void) windowDidDeminiaturize:(NSNotification *) aNotification;
|
||||
-(void) windowDidBecomeKey:(NSNotification *) aNotification;
|
||||
-(void) windowDidResignKey:(NSNotification *) aNotification;
|
||||
-(void) windowWillEnterFullScreen:(NSNotification *) aNotification;
|
||||
-(void) windowDidEnterFullScreen:(NSNotification *) aNotification;
|
||||
-(void) windowWillExitFullScreen:(NSNotification *) aNotification;
|
||||
-(void) windowDidExitFullScreen:(NSNotification *) aNotification;
|
||||
|
||||
/* Window event handling */
|
||||
-(void) mouseDown:(NSEvent *) theEvent;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "SDL_syswm.h"
|
||||
#include "SDL_timer.h" /* For SDL_GetTicks() */
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
@@ -49,7 +50,8 @@ static void ConvertNSRect(NSRect *r)
|
||||
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
|
||||
}
|
||||
|
||||
static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
static void
|
||||
ScheduleContextUpdates(SDL_WindowData *data)
|
||||
{
|
||||
NSMutableArray *contexts = data->nscontexts;
|
||||
@synchronized (contexts) {
|
||||
@@ -59,6 +61,59 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
GetHintCtrlClickEmulateRightClick()
|
||||
{
|
||||
const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
|
||||
return hint != NULL && *hint != '0';
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
GetWindowStyle(SDL_Window * window)
|
||||
{
|
||||
unsigned int style;
|
||||
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
style = NSBorderlessWindowMask;
|
||||
} else {
|
||||
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
||||
style = NSBorderlessWindowMask;
|
||||
} else {
|
||||
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
|
||||
}
|
||||
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
||||
style |= NSResizableWindowMask;
|
||||
}
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
SetWindowStyle(SDL_Window * window, unsigned int style)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = data->nswindow;
|
||||
|
||||
if (![nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* The view responder chain gets messed with during setStyleMask */
|
||||
if ([[nswindow contentView] nextResponder] == data->listener) {
|
||||
[[nswindow contentView] setNextResponder:nil];
|
||||
}
|
||||
|
||||
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
|
||||
|
||||
/* The view responder chain gets messed with during setStyleMask */
|
||||
if ([[nswindow contentView] nextResponder] != data->listener) {
|
||||
[[nswindow contentView] setNextResponder:data->listener];
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@implementation Cocoa_WindowListener
|
||||
|
||||
- (void)listen:(SDL_WindowData *)data
|
||||
@@ -71,6 +126,9 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
observingVisible = YES;
|
||||
wasCtrlLeft = NO;
|
||||
wasVisible = [window isVisible];
|
||||
isFullscreenSpace = NO;
|
||||
inFullscreenTransition = NO;
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
|
||||
center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
@@ -82,6 +140,12 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
[center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
[center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
|
||||
[center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
|
||||
#endif /* Mac OS X 10.7+ */
|
||||
} else {
|
||||
[window setDelegate:self];
|
||||
}
|
||||
@@ -145,6 +209,62 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL) setFullscreenSpace:(BOOL) state;
|
||||
{
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
SDL_Window *window = _data->window;
|
||||
NSWindow *nswindow = _data->nswindow;
|
||||
|
||||
if (![nswindow respondsToSelector: @selector(collectionBehavior)]) {
|
||||
return NO;
|
||||
}
|
||||
if ([nswindow collectionBehavior] != NSWindowCollectionBehaviorFullScreenPrimary) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (state == isFullscreenSpace) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
if (inFullscreenTransition) {
|
||||
if (state) {
|
||||
[self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
|
||||
} else {
|
||||
[self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
inFullscreenTransition = YES;
|
||||
|
||||
/* Update the flags here so the state change is available immediately */
|
||||
if (state) {
|
||||
window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
} else {
|
||||
window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
[nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
|
||||
return YES;
|
||||
#else
|
||||
return NO;
|
||||
#endif /* SDK >= 10.7 */
|
||||
}
|
||||
|
||||
-(BOOL) isInFullscreenSpace
|
||||
{
|
||||
return isFullscreenSpace;
|
||||
}
|
||||
|
||||
-(BOOL) isInFullscreenSpaceTransition
|
||||
{
|
||||
return inFullscreenTransition;
|
||||
}
|
||||
|
||||
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
|
||||
{
|
||||
pendingWindowOperation = operation;
|
||||
}
|
||||
|
||||
- (void)close
|
||||
{
|
||||
NSNotificationCenter *center;
|
||||
@@ -162,12 +282,17 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
[center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
[center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
|
||||
[center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
|
||||
[center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
|
||||
#endif /* Mac OS X 10.7+ */
|
||||
} else {
|
||||
[window setDelegate:nil];
|
||||
}
|
||||
|
||||
[window removeObserver:self
|
||||
forKeyPath:@"visible"];
|
||||
[window removeObserver:self forKeyPath:@"visible"];
|
||||
|
||||
if ([window nextResponder] == self) {
|
||||
[window setNextResponder:nil];
|
||||
@@ -236,28 +361,37 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
NSWindow *nswindow = _data->nswindow;
|
||||
int x, y, w, h;
|
||||
NSRect rect = [_data->nswindow contentRectForFrameRect:[_data->nswindow frame]];
|
||||
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
ConvertNSRect(&rect);
|
||||
x = (int)rect.origin.x;
|
||||
y = (int)rect.origin.y;
|
||||
w = (int)rect.size.width;
|
||||
h = (int)rect.size.height;
|
||||
if (SDL_IsShapedWindow(_data->window))
|
||||
Cocoa_ResizeWindowShape(_data->window);
|
||||
|
||||
if (inFullscreenTransition) {
|
||||
/* We'll take care of this at the end of the transition */
|
||||
return;
|
||||
}
|
||||
|
||||
if (SDL_IsShapedWindow(window)) {
|
||||
Cocoa_ResizeWindowShape(window);
|
||||
}
|
||||
|
||||
ScheduleContextUpdates(_data);
|
||||
|
||||
/* The window can move during a resize event, such as when maximizing
|
||||
or resizing from a corner */
|
||||
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MOVED, x, y);
|
||||
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESIZED, w, h);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
|
||||
|
||||
const BOOL zoomed = [_data->nswindow isZoomed];
|
||||
const BOOL zoomed = [nswindow isZoomed];
|
||||
if (!zoomed) {
|
||||
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
||||
} else if (zoomed) {
|
||||
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
||||
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,6 +444,72 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
|
||||
window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
|
||||
|
||||
isFullscreenSpace = YES;
|
||||
inFullscreenTransition = YES;
|
||||
}
|
||||
|
||||
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
|
||||
inFullscreenTransition = NO;
|
||||
|
||||
if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
[self setFullscreenSpace:NO];
|
||||
} else {
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
/* Force the size change event in case it was delivered earlier
|
||||
while the window was still animating into place.
|
||||
*/
|
||||
window->w = 0;
|
||||
window->h = 0;
|
||||
[self windowDidResize:aNotification];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
|
||||
window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
SetWindowStyle(window, GetWindowStyle(window));
|
||||
|
||||
isFullscreenSpace = NO;
|
||||
inFullscreenTransition = YES;
|
||||
}
|
||||
|
||||
- (void)windowDidExitFullScreen:(NSNotification *)aNotification
|
||||
{
|
||||
SDL_Window *window = _data->window;
|
||||
NSWindow *nswindow = _data->nswindow;
|
||||
|
||||
inFullscreenTransition = NO;
|
||||
|
||||
if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
[self setFullscreenSpace:YES];
|
||||
} else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
[nswindow miniaturize:nil];
|
||||
} else {
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
/* Force the size change event in case it was delivered earlier
|
||||
while the window was still animating into place.
|
||||
*/
|
||||
window->w = 0;
|
||||
window->h = 0;
|
||||
[self windowDidResize:aNotification];
|
||||
}
|
||||
}
|
||||
|
||||
/* We'll respond to key events by doing nothing so we don't beep.
|
||||
* We could handle key messages here, but we lose some in the NSApp dispatch,
|
||||
* where they get converted to action messages, etc.
|
||||
@@ -341,7 +541,8 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
|
||||
switch ([theEvent buttonNumber]) {
|
||||
case 0:
|
||||
if ([theEvent modifierFlags] & NSControlKeyMask) {
|
||||
if (([theEvent modifierFlags] & NSControlKeyMask) &&
|
||||
GetHintCtrlClickEmulateRightClick()) {
|
||||
wasCtrlLeft = YES;
|
||||
button = SDL_BUTTON_RIGHT;
|
||||
} else {
|
||||
@@ -598,26 +799,6 @@ static void ScheduleContextUpdates(SDL_WindowData *data)
|
||||
}
|
||||
@end
|
||||
|
||||
static unsigned int
|
||||
GetWindowStyle(SDL_Window * window)
|
||||
{
|
||||
unsigned int style;
|
||||
|
||||
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
||||
style = NSBorderlessWindowMask;
|
||||
} else {
|
||||
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
||||
style = NSBorderlessWindowMask;
|
||||
} else {
|
||||
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
|
||||
}
|
||||
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
||||
style |= NSResizableWindowMask;
|
||||
}
|
||||
}
|
||||
return style;
|
||||
}
|
||||
|
||||
static int
|
||||
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
|
||||
{
|
||||
@@ -740,14 +921,30 @@ Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
||||
rect.origin.y -= screenRect.origin.y;
|
||||
}
|
||||
}
|
||||
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
|
||||
|
||||
@try {
|
||||
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
|
||||
}
|
||||
@catch (NSException *e) {
|
||||
SDL_SetError("%s", [[e reason] UTF8String]);
|
||||
[pool release];
|
||||
return -1;
|
||||
}
|
||||
[nswindow setBackgroundColor:[NSColor blackColor]];
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
if ([nswindow respondsToSelector:@selector(setCollectionBehavior:)]) {
|
||||
const char *hint = SDL_GetHint(SDL_HINT_VIDEO_FULLSCREEN_SPACES);
|
||||
if (hint && SDL_atoi(hint) > 0) {
|
||||
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Create a default view for this window */
|
||||
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
||||
NSView *contentView = [[SDLView alloc] initWithFrame:rect];
|
||||
|
||||
if ((window->flags & SDL_WINDOW_ALLOW_HIGHDPI) > 0) {
|
||||
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
||||
if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
||||
[contentView setWantsBestResolutionOpenGLSurface:YES];
|
||||
}
|
||||
@@ -950,9 +1147,14 @@ void
|
||||
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
NSWindow *nswindow = data->nswindow;
|
||||
|
||||
[nswindow miniaturize:nil];
|
||||
if ([data->listener isInFullscreenSpaceTransition]) {
|
||||
[data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
|
||||
} else {
|
||||
[nswindow miniaturize:nil];
|
||||
}
|
||||
[pool release];
|
||||
}
|
||||
|
||||
@@ -994,9 +1196,7 @@ void
|
||||
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
||||
if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
|
||||
[nswindow setStyleMask:GetWindowStyle(window)];
|
||||
if (SetWindowStyle(window, GetWindowStyle(window))) {
|
||||
if (bordered) {
|
||||
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
|
||||
}
|
||||
@@ -1004,6 +1204,7 @@ Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
||||
[pool release];
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
||||
{
|
||||
@@ -1202,6 +1403,36 @@ Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if ([data->listener isInFullscreenSpace]) {
|
||||
return SDL_TRUE;
|
||||
} else {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
|
||||
{
|
||||
SDL_bool succeeded = SDL_FALSE;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
|
||||
succeeded = SDL_TRUE;
|
||||
}
|
||||
|
||||
[pool release];
|
||||
#endif /* SDK 10.7+ */
|
||||
|
||||
return succeeded;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -43,7 +43,7 @@ extern "C" {
|
||||
#include <be/opengl/GLView.h>
|
||||
#endif
|
||||
#include "SDL_events.h"
|
||||
#include "../../main/beos/SDL_BApp.h"
|
||||
#include "../../main/haiku/SDL_BApp.h"
|
||||
|
||||
|
||||
enum WinCommands {
|
||||
@@ -83,6 +83,8 @@ class SDL_BWin:public BDirectWindow
|
||||
_trash_window_buffer = false;
|
||||
_buffer_locker = new BLocker();
|
||||
_bitmap = NULL;
|
||||
_clips = NULL;
|
||||
|
||||
#ifdef DRAWTHREAD
|
||||
_draw_thread_id = spawn_thread(BE_DrawThread, "drawing_thread",
|
||||
B_NORMAL_PRIORITY, (void*) this);
|
||||
@@ -349,7 +351,7 @@ class SDL_BWin:public BDirectWindow
|
||||
|
||||
default:
|
||||
/* move it after switch{} so it's always handled
|
||||
that way we keep BeOS feautures like:
|
||||
that way we keep Haiku features like:
|
||||
- CTRL+Q to close window (and other shortcuts)
|
||||
- PrintScreen to make screenshot into /boot/home
|
||||
- etc.. */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
/* BWindow based framebuffer implementation */
|
||||
|
||||
@@ -92,4 +92,4 @@ SDL_bool BE_HasClipboardText(_THIS) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
#include "SDL_bevents.h"
|
||||
|
||||
@@ -36,4 +36,4 @@ void BE_PumpEvents(_THIS) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
#include "SDL_bframebuffer.h"
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "SDL_bmodes.h"
|
||||
#include "SDL_BWin.h"
|
||||
|
||||
#include "../../main/beos/SDL_BApp.h"
|
||||
#include "../../main/haiku/SDL_BApp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -251,4 +251,4 @@ int32 BE_UpdateOnce(SDL_Window *window) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <support/UTF8.h>
|
||||
@@ -185,4 +185,4 @@ void BE_SetKeyState(int32 bkey, int8 state) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
#include <AppKit.h>
|
||||
#include <InterfaceKit.h>
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "SDL_bopengl.h"
|
||||
#endif
|
||||
|
||||
#include "../../main/beos/SDL_BApp.h"
|
||||
#include "../../main/haiku/SDL_BApp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -328,4 +328,4 @@ int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
#include "SDL_bopengl.h"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <KernelKit.h>
|
||||
#include <OpenGLKit.h>
|
||||
#include "SDL_BWin.h"
|
||||
#include "../../main/beos/SDL_BApp.h"
|
||||
#include "../../main/haiku/SDL_BApp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -216,4 +216,4 @@ void BE_GL_RebootContexts(_THIS) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -119,8 +119,8 @@ BE_CreateDevice(int devindex)
|
||||
return device;
|
||||
}
|
||||
|
||||
VideoBootStrap BWINDOW_bootstrap = {
|
||||
"bwindow", "BDirectWindow graphics",
|
||||
VideoBootStrap HAIKU_bootstrap = {
|
||||
"haiku", "Haiku graphics",
|
||||
BE_Available, BE_CreateDevice
|
||||
};
|
||||
|
||||
@@ -171,4 +171,4 @@ void BE_VideoQuit(_THIS)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -26,7 +26,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../../main/beos/SDL_BeApp.h"
|
||||
#include "../../main/haiku/SDL_BeApp.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
#include "SDL_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_BWINDOW
|
||||
#if SDL_VIDEO_DRIVER_HAIKU
|
||||
#include "../SDL_sysvideo.h"
|
||||
|
||||
#include "SDL_BWin.h"
|
||||
@@ -122,7 +122,7 @@ void BE_SetWindowTitle(_THIS, SDL_Window * window) {
|
||||
}
|
||||
|
||||
void BE_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon) {
|
||||
/* FIXME: Icons not supported by BeOs/Haiku */
|
||||
/* FIXME: Icons not supported by Haiku */
|
||||
}
|
||||
|
||||
void BE_SetWindowPosition(_THIS, SDL_Window * window) {
|
||||
@@ -185,12 +185,12 @@ void BE_SetWindowFullscreen(_THIS, SDL_Window * window,
|
||||
}
|
||||
|
||||
int BE_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp) {
|
||||
/* FIXME: Not BeOs/Haiku supported */
|
||||
/* FIXME: Not Haiku supported */
|
||||
return -1;
|
||||
}
|
||||
|
||||
int BE_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp) {
|
||||
/* FIXME: Not BeOs/Haiku supported */
|
||||
/* FIXME: Not Haiku supported */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -220,4 +220,4 @@ SDL_bool BE_GetWindowWMInfo(_THIS, SDL_Window * window,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_BWINDOW */
|
||||
#endif /* SDL_VIDEO_DRIVER_HAIKU */
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "SDL_rpievents_c.h"
|
||||
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
#include "../../input/evdev/SDL_evdev.h"
|
||||
#include "../../core/linux/SDL_evdev.h"
|
||||
#endif
|
||||
|
||||
void RPI_PumpEvents(_THIS)
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#if SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define RPI_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
|
||||
#ifdef SDL_INPUT_LINUXEV
|
||||
#include "../../input/evdev/SDL_evdev.h"
|
||||
#include "../../core/linux/SDL_evdev.h"
|
||||
#endif
|
||||
|
||||
/* RPI declarations */
|
||||
@@ -281,6 +281,22 @@ RPI_CreateWindow(_THIS, SDL_Window * window)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
RPI_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_WindowData *data;
|
||||
|
||||
if(window->driverdata) {
|
||||
data = (SDL_WindowData *) window->driverdata;
|
||||
if (data->egl_surface != EGL_NO_SURFACE) {
|
||||
SDL_EGL_DestroySurface(_this, data->egl_surface);
|
||||
data->egl_surface = EGL_NO_SURFACE;
|
||||
}
|
||||
SDL_free(window->driverdata);
|
||||
window->driverdata = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
||||
{
|
||||
@@ -331,10 +347,6 @@ void
|
||||
RPI_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
|
||||
{
|
||||
|
||||
}
|
||||
void
|
||||
RPI_DestroyWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -89,6 +89,7 @@ UIKit_CreateDevice(int devindex)
|
||||
device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
|
||||
device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
|
||||
device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
|
||||
device->SetTextInputRect = UIKit_SetTextInputRect;
|
||||
#endif
|
||||
|
||||
/* OpenGL (ES) functions */
|
||||
|
||||
@@ -45,6 +45,8 @@
|
||||
#if SDL_IPHONE_KEYBOARD
|
||||
UITextField *textField;
|
||||
BOOL keyboardVisible;
|
||||
SDL_Rect textInputRect;
|
||||
int keyboardHeight;
|
||||
#endif
|
||||
|
||||
@public
|
||||
@@ -60,11 +62,14 @@
|
||||
- (void)hideKeyboard;
|
||||
- (void)initializeKeyboard;
|
||||
@property (readonly) BOOL keyboardVisible;
|
||||
@property (nonatomic,assign) SDL_Rect textInputRect;
|
||||
@property (nonatomic,assign) int keyboardHeight;
|
||||
|
||||
SDL_bool UIKit_HasScreenKeyboardSupport(_THIS);
|
||||
void UIKit_ShowScreenKeyboard(_THIS, SDL_Window *window);
|
||||
void UIKit_HideScreenKeyboard(_THIS, SDL_Window *window);
|
||||
SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window);
|
||||
void UIKit_SetTextInputRect(_THIS, SDL_Rect *rect);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "SDL_uikitmodes.h"
|
||||
#include "SDL_uikitwindow.h"
|
||||
|
||||
void _uikit_keyboard_init() ;
|
||||
|
||||
@implementation SDL_uikitview
|
||||
|
||||
- (void)dealloc
|
||||
@@ -197,6 +199,9 @@
|
||||
*/
|
||||
#if SDL_IPHONE_KEYBOARD
|
||||
|
||||
@synthesize textInputRect = textInputRect;
|
||||
@synthesize keyboardHeight = keyboardHeight;
|
||||
|
||||
/* Is the iPhone virtual keyboard visible onscreen? */
|
||||
- (BOOL)keyboardVisible
|
||||
{
|
||||
@@ -225,6 +230,8 @@
|
||||
/* add the UITextField (hidden) to our view */
|
||||
[self addSubview: textField];
|
||||
[textField release];
|
||||
|
||||
_uikit_keyboard_init();
|
||||
}
|
||||
|
||||
/* reveal onscreen virtual keyboard */
|
||||
@@ -352,6 +359,103 @@ SDL_bool UIKit_IsScreenKeyboardShown(_THIS, SDL_Window *window)
|
||||
return view.keyboardVisible;
|
||||
}
|
||||
|
||||
|
||||
void _uikit_keyboard_update() {
|
||||
SDL_Window *window = SDL_GetFocusWindow();
|
||||
if (!window) { return; }
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
if (!data) { return; }
|
||||
SDL_uikitview *view = data->view;
|
||||
if (!view) { return; }
|
||||
|
||||
SDL_Rect r = view.textInputRect;
|
||||
int height = view.keyboardHeight;
|
||||
int offsetx = 0;
|
||||
int offsety = 0;
|
||||
if (height) {
|
||||
int sw,sh;
|
||||
SDL_GetWindowSize(window,&sw,&sh);
|
||||
int bottom = (r.y + r.h);
|
||||
int kbottom = sh - height;
|
||||
if (kbottom < bottom) {
|
||||
offsety = kbottom-bottom;
|
||||
}
|
||||
}
|
||||
UIInterfaceOrientation ui_orient = [[UIApplication sharedApplication] statusBarOrientation];
|
||||
if (ui_orient == UIInterfaceOrientationLandscapeLeft) {
|
||||
int tmp = offsetx; offsetx = offsety; offsety = tmp;
|
||||
}
|
||||
if (ui_orient == UIInterfaceOrientationLandscapeRight) {
|
||||
offsety = -offsety;
|
||||
int tmp = offsetx; offsetx = offsety; offsety = tmp;
|
||||
}
|
||||
if (ui_orient == UIInterfaceOrientationPortraitUpsideDown) {
|
||||
offsety = -offsety;
|
||||
}
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
|
||||
float scale = [UIScreen mainScreen].scale;
|
||||
offsetx /= scale;
|
||||
offsety /= scale;
|
||||
}
|
||||
view.frame = CGRectMake(offsetx,offsety,view.frame.size.width,view.frame.size.height);
|
||||
}
|
||||
|
||||
void _uikit_keyboard_set_height(int height) {
|
||||
SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
|
||||
if (view == nil) {
|
||||
return ;
|
||||
}
|
||||
|
||||
view.keyboardHeight = height;
|
||||
_uikit_keyboard_update();
|
||||
}
|
||||
|
||||
void _uikit_keyboard_init() {
|
||||
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
||||
NSOperationQueue *queue = [NSOperationQueue mainQueue];
|
||||
[center addObserverForName:UIKeyboardWillShowNotification
|
||||
object:nil
|
||||
queue:queue
|
||||
usingBlock:^(NSNotification *notification) {
|
||||
int height = 0;
|
||||
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
|
||||
height = keyboardSize.height;
|
||||
UIInterfaceOrientation ui_orient = [[UIApplication sharedApplication] statusBarOrientation];
|
||||
if (ui_orient == UIInterfaceOrientationLandscapeRight || ui_orient == UIInterfaceOrientationLandscapeLeft) {
|
||||
height = keyboardSize.width;
|
||||
}
|
||||
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) {
|
||||
height *= [UIScreen mainScreen].scale;
|
||||
}
|
||||
_uikit_keyboard_set_height(height);
|
||||
}
|
||||
];
|
||||
[center addObserverForName:UIKeyboardDidHideNotification
|
||||
object:nil
|
||||
queue:queue
|
||||
usingBlock:^(NSNotification *notification) {
|
||||
_uikit_keyboard_set_height(0);
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
void
|
||||
UIKit_SetTextInputRect(_THIS, SDL_Rect *rect)
|
||||
{
|
||||
if (!rect) {
|
||||
SDL_InvalidParamError("rect");
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_uikitview *view = getWindowView(SDL_GetFocusWindow());
|
||||
if (view == nil) {
|
||||
return ;
|
||||
}
|
||||
|
||||
view.textInputRect = *rect;
|
||||
}
|
||||
|
||||
|
||||
#endif /* SDL_IPHONE_KEYBOARD */
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_UIKIT */
|
||||
|
||||
@@ -67,6 +67,9 @@
|
||||
#ifndef WM_TOUCH
|
||||
#define WM_TOUCH 0x0240
|
||||
#endif
|
||||
#ifndef WM_MOUSEHWHEEL
|
||||
#define WM_MOUSEHWHEEL 0x020E
|
||||
#endif
|
||||
|
||||
static SDL_Scancode
|
||||
WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
|
||||
@@ -283,6 +286,45 @@ WIN_ConvertUTF32toUTF8(UINT32 codepoint, char * text)
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
WIN_UpdateClipCursor(SDL_Window *window)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||
|
||||
/* Don't clip the cursor while we're in the modal resize or move loop */
|
||||
if (data->in_modal_loop) {
|
||||
ClipCursor(NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (SDL_GetMouse()->relative_mode) {
|
||||
LONG cx, cy;
|
||||
RECT rect;
|
||||
GetWindowRect(data->hwnd, &rect);
|
||||
|
||||
cx = (rect.left + rect.right) / 2;
|
||||
cy = (rect.top + rect.bottom) / 2;
|
||||
|
||||
/* Make an absurdly small clip rect */
|
||||
rect.left = cx-1;
|
||||
rect.right = cx+1;
|
||||
rect.top = cy-1;
|
||||
rect.bottom = cy+1;
|
||||
|
||||
ClipCursor(&rect);
|
||||
} else if ((window->flags & SDL_WINDOW_INPUT_GRABBED) &&
|
||||
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
RECT rect;
|
||||
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
|
||||
ClientToScreen(data->hwnd, (LPPOINT) & rect);
|
||||
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
|
||||
ClipCursor(&rect);
|
||||
}
|
||||
} else {
|
||||
ClipCursor(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK
|
||||
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
@@ -309,15 +351,15 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
|
||||
#ifdef WMMSG_DEBUG
|
||||
{
|
||||
char message[1024];
|
||||
if (msg > MAX_WMMSG) {
|
||||
SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
|
||||
} else {
|
||||
SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
|
||||
}
|
||||
OutputDebugStringA(message);
|
||||
}
|
||||
{
|
||||
char message[1024];
|
||||
if (msg > MAX_WMMSG) {
|
||||
SDL_snprintf(message, sizeof(message), "Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
|
||||
} else {
|
||||
SDL_snprintf(message, sizeof(message), "Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd, wmtab[msg], wParam, lParam);
|
||||
}
|
||||
OutputDebugStringA(message);
|
||||
}
|
||||
#endif /* WMMSG_DEBUG */
|
||||
|
||||
if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
|
||||
@@ -345,12 +387,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
SHORT keyState;
|
||||
|
||||
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
||||
SDL_SendWindowEvent(data->window,
|
||||
SDL_WINDOWEVENT_RESTORED, 0, 0);
|
||||
if (IsZoomed(hwnd)) {
|
||||
SDL_SendWindowEvent(data->window,
|
||||
SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
||||
}
|
||||
if (SDL_GetKeyboardFocus() != data->window) {
|
||||
SDL_SetKeyboardFocus(data->window);
|
||||
}
|
||||
@@ -372,22 +408,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
|
||||
data->mouse_button_flags = 0;
|
||||
|
||||
if(SDL_GetMouse()->relative_mode) {
|
||||
LONG cx, cy;
|
||||
RECT rect;
|
||||
GetWindowRect(hwnd, &rect);
|
||||
|
||||
cx = (rect.left + rect.right) / 2;
|
||||
cy = (rect.top + rect.bottom) / 2;
|
||||
|
||||
/* Make an absurdly small clip rect */
|
||||
rect.left = cx-1;
|
||||
rect.right = cx+1;
|
||||
rect.top = cy-1;
|
||||
rect.bottom = cy+1;
|
||||
|
||||
ClipCursor(&rect);
|
||||
}
|
||||
WIN_UpdateClipCursor(data->window);
|
||||
|
||||
/*
|
||||
* FIXME: Update keyboard state
|
||||
@@ -397,10 +418,6 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
if (SDL_GetKeyboardFocus() == data->window) {
|
||||
SDL_SetKeyboardFocus(NULL);
|
||||
}
|
||||
if (minimized) {
|
||||
SDL_SendWindowEvent(data->window,
|
||||
SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
returnCode = 0;
|
||||
@@ -481,13 +498,34 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_MOUSEHWHEEL:
|
||||
{
|
||||
static short s_AccumulatedMotion;
|
||||
|
||||
s_AccumulatedMotion += GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
if (s_AccumulatedMotion > 0) {
|
||||
while (s_AccumulatedMotion >= WHEEL_DELTA) {
|
||||
SDL_SendMouseWheel(data->window, 0, 1, 0);
|
||||
s_AccumulatedMotion -= WHEEL_DELTA;
|
||||
}
|
||||
} else {
|
||||
while (s_AccumulatedMotion <= -WHEEL_DELTA) {
|
||||
SDL_SendMouseWheel(data->window, 0, -1, 0);
|
||||
s_AccumulatedMotion += WHEEL_DELTA;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef WM_MOUSELEAVE
|
||||
case WM_MOUSELEAVE:
|
||||
if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode) {
|
||||
POINT cursorPos;
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
|
||||
if (!IsIconic(hwnd)) {
|
||||
POINT cursorPos;
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
|
||||
}
|
||||
SDL_SetMouseFocus(NULL);
|
||||
}
|
||||
returnCode = 0;
|
||||
@@ -523,9 +561,19 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
case WM_KEYUP:
|
||||
{
|
||||
SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
|
||||
const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
|
||||
|
||||
/* Detect relevant keyboard shortcuts */
|
||||
if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED ) {
|
||||
/* ALT+F4: Close window */
|
||||
if (code == SDL_SCANCODE_F4) {
|
||||
SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if ( code != SDL_SCANCODE_UNKNOWN ) {
|
||||
if (code == SDL_SCANCODE_PRINTSCREEN &&
|
||||
SDL_GetKeyboardState(NULL)[code] == SDL_RELEASED) {
|
||||
keyboardState[code] == SDL_RELEASED) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, code);
|
||||
}
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, code);
|
||||
@@ -561,6 +609,22 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
#endif /* WM_INPUTLANGCHANGE */
|
||||
|
||||
case WM_ENTERSIZEMOVE:
|
||||
case WM_ENTERMENULOOP:
|
||||
{
|
||||
data->in_modal_loop = SDL_TRUE;
|
||||
WIN_UpdateClipCursor(data->window);
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_EXITSIZEMOVE:
|
||||
case WM_EXITMENULOOP:
|
||||
{
|
||||
data->in_modal_loop = SDL_FALSE;
|
||||
WIN_UpdateClipCursor(data->window);
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef WM_GETMINMAXINFO
|
||||
case WM_GETMINMAXINFO:
|
||||
{
|
||||
@@ -574,10 +638,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
BOOL menu;
|
||||
BOOL constrain_max_size;
|
||||
|
||||
/* If we allow resizing, let the resize happen naturally */
|
||||
if (SDL_IsShapedWindow(data->window))
|
||||
Win32_ResizeWindowShape(data->window);
|
||||
|
||||
/* If this is an expected size change, allow it */
|
||||
if (data->expected_resize) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* Get the current position of our window */
|
||||
GetWindowRect(hwnd, &size);
|
||||
x = size.left;
|
||||
@@ -645,20 +713,14 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
RECT rect;
|
||||
int x, y;
|
||||
int w, h;
|
||||
Uint32 window_flags;
|
||||
|
||||
if (!GetClientRect(hwnd, &rect) ||
|
||||
(rect.right == rect.left && rect.bottom == rect.top)) {
|
||||
if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) {
|
||||
break;
|
||||
}
|
||||
ClientToScreen(hwnd, (LPPOINT) & rect);
|
||||
ClientToScreen(hwnd, (LPPOINT) & rect + 1);
|
||||
|
||||
window_flags = SDL_GetWindowFlags(data->window);
|
||||
if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
|
||||
(window_flags & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
ClipCursor(&rect);
|
||||
}
|
||||
WIN_UpdateClipCursor(data->window);
|
||||
|
||||
x = rect.left;
|
||||
y = rect.top;
|
||||
@@ -671,6 +733,26 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_SIZE:
|
||||
{
|
||||
switch (wParam)
|
||||
{
|
||||
case SIZE_MAXIMIZED:
|
||||
SDL_SendWindowEvent(data->window,
|
||||
SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
||||
break;
|
||||
case SIZE_MINIMIZED:
|
||||
SDL_SendWindowEvent(data->window,
|
||||
SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
||||
break;
|
||||
default:
|
||||
SDL_SendWindowEvent(data->window,
|
||||
SDL_WINDOWEVENT_RESTORED, 0, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_SETCURSOR:
|
||||
{
|
||||
Uint16 hittest;
|
||||
|
||||
@@ -207,7 +207,7 @@ WIN_SetRelativeMouseMode(SDL_bool enabled)
|
||||
|
||||
|
||||
/* (Un)register raw input for mice */
|
||||
if(RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
|
||||
if (RegisterRawInputDevices(&rawMouse, 1, sizeof(RAWINPUTDEVICE)) == FALSE) {
|
||||
|
||||
/* Only return an error when registering. If we unregister and fail, then
|
||||
it's probably that we unregistered twice. That's OK. */
|
||||
@@ -216,7 +216,7 @@ WIN_SetRelativeMouseMode(SDL_bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
if(enabled) {
|
||||
if (enabled) {
|
||||
LONG cx, cy;
|
||||
RECT rect;
|
||||
GetWindowRect(hWnd, &rect);
|
||||
@@ -231,10 +231,9 @@ WIN_SetRelativeMouseMode(SDL_bool enabled)
|
||||
rect.bottom = cy+1;
|
||||
|
||||
ClipCursor(&rect);
|
||||
}
|
||||
else
|
||||
} else {
|
||||
ClipCursor(NULL);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_loadso.h"
|
||||
#include "SDL_windowsvideo.h"
|
||||
#include "SDL_windowsopengles.h"
|
||||
|
||||
/* WGL implementation of SDL OpenGL support */
|
||||
|
||||
@@ -323,11 +324,35 @@ HasExtension(const char *extension, const char *extensions)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
WIN_GL_InitExtensions(_THIS, HDC hdc)
|
||||
void
|
||||
WIN_GL_InitExtensions(_THIS)
|
||||
{
|
||||
const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
|
||||
const char *extensions;
|
||||
HWND hwnd;
|
||||
HDC hdc;
|
||||
HGLRC hglrc;
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
|
||||
hwnd =
|
||||
CreateWindow(SDL_Appname, SDL_Appname, (WS_POPUP | WS_DISABLED), 0, 0,
|
||||
10, 10, NULL, NULL, SDL_Instance, NULL);
|
||||
if (!hwnd) {
|
||||
return;
|
||||
}
|
||||
WIN_PumpEvents(_this);
|
||||
|
||||
hdc = GetDC(hwnd);
|
||||
|
||||
WIN_GL_SetupPixelFormat(_this, &pfd);
|
||||
|
||||
SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);
|
||||
|
||||
hglrc = _this->gl_data->wglCreateContext(hdc);
|
||||
if (!hglrc) {
|
||||
return;
|
||||
}
|
||||
_this->gl_data->wglMakeCurrent(hdc, hglrc);
|
||||
|
||||
wglGetExtensionsStringARB = (const char *(WINAPI *) (HDC))
|
||||
_this->gl_data->wglGetProcAddress("wglGetExtensionsStringARB");
|
||||
@@ -369,6 +394,18 @@ WIN_GL_InitExtensions(_THIS, HDC hdc)
|
||||
_this->gl_data->wglSwapIntervalEXT = NULL;
|
||||
_this->gl_data->wglGetSwapIntervalEXT = NULL;
|
||||
}
|
||||
|
||||
/* Check for WGL_EXT_create_context_es2_profile */
|
||||
_this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_FALSE;
|
||||
if (HasExtension("WGL_EXT_create_context_es2_profile", extensions)) {
|
||||
_this->gl_data->HAS_WGL_EXT_create_context_es2_profile = SDL_TRUE;
|
||||
}
|
||||
|
||||
_this->gl_data->wglMakeCurrent(hdc, NULL);
|
||||
_this->gl_data->wglDeleteContext(hglrc);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
DestroyWindow(hwnd);
|
||||
WIN_PumpEvents(_this);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -396,8 +433,6 @@ WIN_GL_ChoosePixelFormatARB(_THIS, int *iAttribs, float *fAttribs)
|
||||
if (hglrc) {
|
||||
_this->gl_data->wglMakeCurrent(hdc, hglrc);
|
||||
|
||||
WIN_GL_InitExtensions(_this, hdc);
|
||||
|
||||
if (_this->gl_data->HAS_WGL_ARB_pixel_format) {
|
||||
_this->gl_data->wglChoosePixelFormatARB(hdc, iAttribs, fAttribs,
|
||||
1, &pixel_format,
|
||||
@@ -548,6 +583,31 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
HDC hdc = ((SDL_WindowData *) window->driverdata)->hdc;
|
||||
HGLRC context, share_context;
|
||||
|
||||
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
|
||||
!_this->gl_data->HAS_WGL_EXT_create_context_es2_profile) {
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
/* Switch to EGL based functions */
|
||||
WIN_GL_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = WIN_GLES_LoadLibrary;
|
||||
_this->GL_GetProcAddress = WIN_GLES_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = WIN_GLES_UnloadLibrary;
|
||||
_this->GL_CreateContext = WIN_GLES_CreateContext;
|
||||
_this->GL_MakeCurrent = WIN_GLES_MakeCurrent;
|
||||
_this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval;
|
||||
_this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval;
|
||||
_this->GL_SwapWindow = WIN_GLES_SwapWindow;
|
||||
_this->GL_DeleteContext = WIN_GLES_DeleteContext;
|
||||
|
||||
if (WIN_GLES_LoadLibrary(_this, NULL) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return WIN_GLES_CreateContext(_this, window);
|
||||
#else
|
||||
return SDL_SetError("SDL not configured with EGL support");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_this->gl_config.share_with_current_context) {
|
||||
share_context = (HGLRC)SDL_GL_GetCurrentContext();
|
||||
} else {
|
||||
@@ -622,8 +682,6 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WIN_GL_InitExtensions(_this, hdc);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ struct SDL_GLDriverData
|
||||
{
|
||||
SDL_bool HAS_WGL_ARB_pixel_format;
|
||||
SDL_bool HAS_WGL_EXT_swap_control_tear;
|
||||
SDL_bool HAS_WGL_EXT_create_context_es2_profile;
|
||||
|
||||
void *(WINAPI * wglGetProcAddress) (const char *proc);
|
||||
HGLRC(WINAPI * wglCreateContext) (HDC hdc);
|
||||
@@ -62,6 +63,7 @@ extern int WIN_GL_SetSwapInterval(_THIS, int interval);
|
||||
extern int WIN_GL_GetSwapInterval(_THIS);
|
||||
extern void WIN_GL_SwapWindow(_THIS, SDL_Window * window);
|
||||
extern void WIN_GL_DeleteContext(_THIS, SDL_GLContext context);
|
||||
extern void WIN_GL_InitExtensions(_THIS);
|
||||
|
||||
#ifndef WGL_ARB_pixel_format
|
||||
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
|
||||
|
||||
141
src/video/windows/SDL_windowsopengles.c
Normal file
141
src/video/windows/SDL_windowsopengles.c
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#if SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "SDL_windowsvideo.h"
|
||||
#include "SDL_windowsopengles.h"
|
||||
#include "SDL_windowsopengl.h"
|
||||
#include "SDL_log.h"
|
||||
|
||||
/* EGL implementation of SDL OpenGL support */
|
||||
|
||||
int
|
||||
WIN_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
|
||||
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
||||
|
||||
/* If the profile requested is not GL ES, switch over to WIN_GL functions */
|
||||
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
WIN_GLES_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = WIN_GL_LoadLibrary;
|
||||
_this->GL_GetProcAddress = WIN_GL_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
|
||||
_this->GL_CreateContext = WIN_GL_CreateContext;
|
||||
_this->GL_MakeCurrent = WIN_GL_MakeCurrent;
|
||||
_this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
|
||||
_this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
|
||||
_this->GL_SwapWindow = WIN_GL_SwapWindow;
|
||||
_this->GL_DeleteContext = WIN_GL_DeleteContext;
|
||||
return WIN_GL_LoadLibrary(_this, path);
|
||||
#else
|
||||
return SDL_SetError("SDL not configured with OpenGL/WGL support");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_this->egl_data == NULL) {
|
||||
return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_GLContext
|
||||
WIN_GLES_CreateContext(_THIS, SDL_Window * window)
|
||||
{
|
||||
SDL_GLContext context;
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
|
||||
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
/* Switch to WGL based functions */
|
||||
WIN_GLES_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = WIN_GL_LoadLibrary;
|
||||
_this->GL_GetProcAddress = WIN_GL_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
|
||||
_this->GL_CreateContext = WIN_GL_CreateContext;
|
||||
_this->GL_MakeCurrent = WIN_GL_MakeCurrent;
|
||||
_this->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
|
||||
_this->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
|
||||
_this->GL_SwapWindow = WIN_GL_SwapWindow;
|
||||
_this->GL_DeleteContext = WIN_GL_DeleteContext;
|
||||
|
||||
if (WIN_GL_LoadLibrary(_this, NULL) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return WIN_GL_CreateContext(_this, window);
|
||||
}
|
||||
|
||||
context = SDL_EGL_CreateContext(_this, data->egl_surface);
|
||||
return context;
|
||||
}
|
||||
|
||||
void
|
||||
WIN_GLES_DeleteContext(_THIS, SDL_GLContext context)
|
||||
{
|
||||
SDL_EGL_DeleteContext(_this, context);
|
||||
WIN_GLES_UnloadLibrary(_this);
|
||||
}
|
||||
|
||||
SDL_EGL_SwapWindow_impl(WIN)
|
||||
SDL_EGL_MakeCurrent_impl(WIN)
|
||||
|
||||
int
|
||||
WIN_GLES_SetupWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
/* The current context is lost in here; save it and reset it. */
|
||||
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
|
||||
SDL_Window *current_win = SDL_GL_GetCurrentWindow();
|
||||
SDL_GLContext current_ctx = SDL_GL_GetCurrentContext();
|
||||
|
||||
|
||||
if (_this->egl_data == NULL) {
|
||||
if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the GLES window surface */
|
||||
windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)windowdata->hwnd);
|
||||
|
||||
if (windowdata->egl_surface == EGL_NO_SURFACE) {
|
||||
return SDL_SetError("Could not create GLES window surface");
|
||||
}
|
||||
|
||||
return WIN_GLES_MakeCurrent(_this, current_win, current_ctx);
|
||||
}
|
||||
|
||||
int
|
||||
WIN_GLES_SetSwapInterval(_THIS, int interval)
|
||||
{
|
||||
/* FIXME: This should call SDL_EGL_SetSwapInterval, but ANGLE has a bug that prevents this
|
||||
* from working if we do (the window contents freeze and don't swap properly). So, we ignore
|
||||
* the request for now.
|
||||
*/
|
||||
SDL_Log("WARNING: Ignoring SDL_GL_SetSwapInterval call due to ANGLE bug");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_WINDOWS && SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
51
src/video/windows/SDL_windowsopengles.h
Normal file
51
src/video/windows/SDL_windowsopengles.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_winopengles_h
|
||||
#define _SDL_winopengles_h
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../SDL_egl_c.h"
|
||||
|
||||
/* OpenGLES functions */
|
||||
#define WIN_GLES_GetAttribute SDL_EGL_GetAttribute
|
||||
#define WIN_GLES_GetProcAddress SDL_EGL_GetProcAddress
|
||||
#define WIN_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
|
||||
#define WIN_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
|
||||
/* See the WIN_GLES_GetSwapInterval implementation to see why this is commented out */
|
||||
/*#define WIN_GLES_SetSwapInterval SDL_EGL_SetSwapInterval*/
|
||||
extern int WIN_GLES_SetSwapInterval(_THIS, int interval);
|
||||
|
||||
extern int WIN_GLES_LoadLibrary(_THIS, const char *path);
|
||||
extern SDL_GLContext WIN_GLES_CreateContext(_THIS, SDL_Window * window);
|
||||
extern void WIN_GLES_SwapWindow(_THIS, SDL_Window * window);
|
||||
extern int WIN_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
|
||||
extern void WIN_GLES_DeleteContext(_THIS, SDL_GLContext context);
|
||||
extern int WIN_GLES_SetupWindow(_THIS, SDL_Window * window);
|
||||
|
||||
#endif /* SDL_VIDEO_OPENGL_EGL */
|
||||
|
||||
#endif /* _SDL_winopengles_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -44,6 +44,7 @@
|
||||
#include "SDL_windowsmodes.h"
|
||||
#include "SDL_windowsmouse.h"
|
||||
#include "SDL_windowsopengl.h"
|
||||
#include "SDL_windowsopengles.h"
|
||||
#include "SDL_windowswindow.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_loadso.h"
|
||||
|
||||
@@ -79,7 +79,8 @@ GetWindowStyle(SDL_Window * window)
|
||||
static void
|
||||
WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
|
||||
{
|
||||
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
RECT rect;
|
||||
DWORD style;
|
||||
HWND top;
|
||||
@@ -105,7 +106,9 @@ WIN_SetWindowPositionInternal(_THIS, SDL_Window * window, UINT flags)
|
||||
x = window->x + rect.left;
|
||||
y = window->y + rect.top;
|
||||
|
||||
data->expected_resize = TRUE;
|
||||
SetWindowPos(hwnd, top, x, y, w, h, flags);
|
||||
data->expected_resize = FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -270,6 +273,32 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
|
||||
DestroyWindow(hwnd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
/* We need to initialize the extensions before deciding how to create ES profiles */
|
||||
if (window->flags & SDL_WINDOW_OPENGL) {
|
||||
WIN_GL_InitExtensions(_this);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES2
|
||||
if ((window->flags & SDL_WINDOW_OPENGL) &&
|
||||
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
&& (!_this->gl_data || !_this->gl_data->HAS_WGL_EXT_create_context_es2_profile)
|
||||
#endif
|
||||
) {
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
if (WIN_GLES_SetupWindow(_this, window) < 0) {
|
||||
WIN_DestroyWindow(_this, window);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
return SDL_SetError("Could not create GLES window surface (no EGL support available)");
|
||||
#endif /* SDL_VIDEO_OPENGL_EGL */
|
||||
} else
|
||||
#endif /* SDL_VIDEO_OPENGL_ES2 */
|
||||
|
||||
#if SDL_VIDEO_OPENGL_WGL
|
||||
if (window->flags & SDL_WINDOW_OPENGL) {
|
||||
if (WIN_GL_SetupWindow(_this, window) < 0) {
|
||||
@@ -278,6 +307,7 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -405,16 +435,16 @@ void
|
||||
WIN_RaiseWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
WIN_SetWindowPositionInternal(_this, window, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
|
||||
|
||||
/* Raising the window while alt-tabbed can cause it to be minimized for some reason? */
|
||||
WIN_RestoreWindow(_this, window);
|
||||
}
|
||||
|
||||
void
|
||||
WIN_MaximizeWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
data->expected_resize = TRUE;
|
||||
ShowWindow(hwnd, SW_MAXIMIZE);
|
||||
data->expected_resize = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -445,9 +475,11 @@ WIN_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
||||
void
|
||||
WIN_RestoreWindow(_THIS, SDL_Window * window)
|
||||
{
|
||||
HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
|
||||
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
data->expected_resize = TRUE;
|
||||
ShowWindow(hwnd, SW_RESTORE);
|
||||
data->expected_resize = FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -493,7 +525,9 @@ WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display,
|
||||
y = window->windowed.y + rect.top;
|
||||
}
|
||||
SetWindowLong(hwnd, GWL_STYLE, style);
|
||||
data->expected_resize = TRUE;
|
||||
SetWindowPos(hwnd, top, x, y, w, h, SWP_NOCOPYBITS);
|
||||
data->expected_resize = FALSE;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#ifndef _SDL_windowswindow_h
|
||||
#define _SDL_windowswindow_h
|
||||
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
#include "../SDL_egl_c.h"
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_Window *window;
|
||||
@@ -33,7 +37,12 @@ typedef struct
|
||||
WNDPROC wndproc;
|
||||
SDL_bool created;
|
||||
WPARAM mouse_button_flags;
|
||||
BOOL expected_resize;
|
||||
SDL_bool in_modal_loop;
|
||||
struct SDL_VideoData *videodata;
|
||||
#if SDL_VIDEO_OPENGL_EGL
|
||||
EGLSurface egl_surface;
|
||||
#endif
|
||||
} SDL_WindowData;
|
||||
|
||||
extern int WIN_CreateWindow(_THIS, SDL_Window * window);
|
||||
|
||||
@@ -245,7 +245,13 @@ X11_DispatchFocusOut(SDL_WindowData *data)
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: Dispatching FocusOut\n", data);
|
||||
#endif
|
||||
SDL_SetKeyboardFocus(NULL);
|
||||
/* If another window has already processed a focus in, then don't try to
|
||||
* remove focus here. Doing so will incorrectly remove focus from that
|
||||
* window, and the focus lost event for this window will have already
|
||||
* been dispatched anyway. */
|
||||
if (data->window == SDL_GetKeyboardFocus()) {
|
||||
SDL_SetKeyboardFocus(NULL);
|
||||
}
|
||||
#ifdef X_HAVE_UTF8_STRING
|
||||
if (data->ic) {
|
||||
X11_XUnsetICFocus(data->ic);
|
||||
@@ -274,19 +280,39 @@ X11_DispatchEvent(_THIS)
|
||||
Display *display = videodata->display;
|
||||
SDL_WindowData *data;
|
||||
XEvent xevent;
|
||||
int i;
|
||||
int orig_event_type;
|
||||
KeyCode orig_keycode;
|
||||
XClientMessageEvent m;
|
||||
int i;
|
||||
|
||||
SDL_zero(xevent); /* valgrind fix. --ryan. */
|
||||
X11_XNextEvent(display, &xevent);
|
||||
|
||||
/* filter events catchs XIM events and sends them to the correct
|
||||
handler */
|
||||
/* Save the original keycode for dead keys, which are filtered out by
|
||||
the XFilterEvent() call below.
|
||||
*/
|
||||
orig_event_type = xevent.type;
|
||||
if (orig_event_type == KeyPress || orig_event_type == KeyRelease) {
|
||||
orig_keycode = xevent.xkey.keycode;
|
||||
} else {
|
||||
orig_keycode = 0;
|
||||
}
|
||||
|
||||
/* filter events catchs XIM events and sends them to the correct handler */
|
||||
if (X11_XFilterEvent(&xevent, None) == True) {
|
||||
#if 0
|
||||
printf("Filtered event type = %d display = %d window = %d\n",
|
||||
xevent.type, xevent.xany.display, xevent.xany.window);
|
||||
#endif
|
||||
if (orig_keycode) {
|
||||
/* Make sure dead key press/release events are sent */
|
||||
SDL_Scancode scancode = videodata->key_layout[orig_keycode];
|
||||
if (orig_event_type == KeyPress) {
|
||||
SDL_SendKeyboardKey(SDL_PRESSED, scancode);
|
||||
} else {
|
||||
SDL_SendKeyboardKey(SDL_RELEASED, scancode);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -373,6 +399,14 @@ X11_DispatchEvent(_THIS)
|
||||
|
||||
/* Gaining input focus? */
|
||||
case FocusIn:{
|
||||
if (xevent.xfocus.mode == NotifyGrab || xevent.xfocus.mode == NotifyUngrab) {
|
||||
/* Someone is handling a global hotkey, ignore it */
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: FocusIn (NotifyGrab/NotifyUngrab, ignoring)\n", data);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (xevent.xfocus.detail == NotifyInferior) {
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: FocusIn (NotifierInferior, ignoring)\n", data);
|
||||
@@ -402,6 +436,13 @@ X11_DispatchEvent(_THIS)
|
||||
|
||||
/* Losing input focus? */
|
||||
case FocusOut:{
|
||||
if (xevent.xfocus.mode == NotifyGrab || xevent.xfocus.mode == NotifyUngrab) {
|
||||
/* Someone is handling a global hotkey, ignore it */
|
||||
#ifdef DEBUG_XEVENTS
|
||||
printf("window %p: FocusOut (NotifyGrab/NotifyUngrab, ignoring)\n", data);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
if (xevent.xfocus.detail == NotifyInferior) {
|
||||
/* We still have focus if a child gets focus */
|
||||
#ifdef DEBUG_XEVENTS
|
||||
|
||||
@@ -552,7 +552,8 @@ X11_InitModes(_THIS)
|
||||
in all cases. Anybody want to give this some love?
|
||||
*/
|
||||
crtc = X11_XRRGetCrtcInfo(data->display, res, output_info->crtc);
|
||||
if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y) {
|
||||
if (!crtc || crtc->x != displaydata->x || crtc->y != displaydata->y ||
|
||||
crtc->width != mode.w || crtc->height != mode.h) {
|
||||
X11_XRRFreeOutputInfo(output_info);
|
||||
X11_XRRFreeCrtcInfo(crtc);
|
||||
continue;
|
||||
|
||||
@@ -36,6 +36,7 @@ X11_GLES_LoadLibrary(_THIS, const char *path) {
|
||||
/* If the profile requested is not GL ES, switch over to X11_GL functions */
|
||||
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
|
||||
#if SDL_VIDEO_OPENGL_GLX
|
||||
X11_GLES_UnloadLibrary(_this);
|
||||
_this->GL_LoadLibrary = X11_GL_LoadLibrary;
|
||||
_this->GL_GetProcAddress = X11_GL_GetProcAddress;
|
||||
_this->GL_UnloadLibrary = X11_GL_UnloadLibrary;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user