actual update to latest mobile-common

This commit is contained in:
fysx
2014-08-27 23:23:26 +02:00
parent abb819335b
commit c6ac06c366
992 changed files with 169762 additions and 177 deletions
@@ -0,0 +1,147 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_naclaudio.h"
#include "SDL_audio.h"
#include "SDL_mutex.h"
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
#include "../SDL_audiodev_c.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi_simple/ps.h"
#include "ppapi_simple/ps_interface.h"
#include "ppapi_simple/ps_event.h"
/* The tag name used by NACL audio */
#define NACLAUD_DRIVER_NAME "nacl"
#define SAMPLE_FRAME_COUNT 4096
/* Audio driver functions */
static int NACLAUD_OpenDevice(_THIS, const char *devname, int iscapture);
static void NACLAUD_CloseDevice(_THIS);
static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data);
/* FIXME: Make use of latency if needed */
static void nacl_audio_callback(void* samples, uint32_t buffer_size, PP_TimeDelta latency, void* data) {
SDL_AudioDevice* _this = (SDL_AudioDevice*) data;
SDL_LockMutex(private->mutex);
if (_this->enabled && !_this->paused) {
if (_this->convert.needed) {
SDL_LockMutex(_this->mixer_lock);
(*_this->spec.callback) (_this->spec.userdata,
(Uint8 *) _this->convert.buf,
_this->convert.len);
SDL_UnlockMutex(_this->mixer_lock);
SDL_ConvertAudio(&_this->convert);
SDL_memcpy(samples, _this->convert.buf, _this->convert.len_cvt);
} else {
SDL_LockMutex(_this->mixer_lock);
(*_this->spec.callback) (_this->spec.userdata, (Uint8 *) samples, buffer_size);
SDL_UnlockMutex(_this->mixer_lock);
}
} else {
SDL_memset(samples, 0, buffer_size);
}
return;
}
static void NACLAUD_CloseDevice(SDL_AudioDevice *device) {
const PPB_Core *core = PSInterfaceCore();
const PPB_Audio *ppb_audio = PSInterfaceAudio();
SDL_PrivateAudioData *hidden = (SDL_PrivateAudioData *) device->hidden;
ppb_audio->StopPlayback(hidden->audio);
SDL_DestroyMutex(hidden->mutex);
core->ReleaseResource(hidden->audio);
}
static int
NACLAUD_OpenDevice(_THIS, const char *devname, int iscapture) {
PP_Instance instance = PSGetInstanceId();
const PPB_Audio *ppb_audio = PSInterfaceAudio();
const PPB_AudioConfig *ppb_audiocfg = PSInterfaceAudioConfig();
private = (SDL_PrivateAudioData *) SDL_calloc(1, (sizeof *private));
if (private == NULL) {
SDL_OutOfMemory();
return 0;
}
private->mutex = SDL_CreateMutex();
_this->spec.freq = 44100;
_this->spec.format = AUDIO_S16LSB;
_this->spec.channels = 2;
_this->spec.samples = ppb_audiocfg->RecommendSampleFrameCount(
instance,
PP_AUDIOSAMPLERATE_44100,
SAMPLE_FRAME_COUNT);
/* Calculate the final parameters for this audio specification */
SDL_CalculateAudioSpec(&_this->spec);
private->audio = ppb_audio->Create(
instance,
ppb_audiocfg->CreateStereo16Bit(instance, PP_AUDIOSAMPLERATE_44100, _this->spec.samples),
nacl_audio_callback,
_this);
/* Start audio playback while we are still on the main thread. */
ppb_audio->StartPlayback(private->audio);
return 1;
}
static int
NACLAUD_Init(SDL_AudioDriverImpl * impl)
{
if (PSGetInstanceId() == 0) {
return 0;
}
/* Set the function pointers */
impl->OpenDevice = NACLAUD_OpenDevice;
impl->CloseDevice = NACLAUD_CloseDevice;
impl->HasCaptureSupport = 0;
impl->OnlyHasDefaultOutputDevice = 1;
impl->OnlyHasDefaultInputDevice = 1;
impl->ProvidesOwnCallbackThread = 1;
/*
* impl->WaitDevice = NACLAUD_WaitDevice;
* impl->GetDeviceBuf = NACLAUD_GetDeviceBuf;
* impl->PlayDevice = NACLAUD_PlayDevice;
* impl->Deinitialize = NACLAUD_Deinitialize;
*/
return 1;
}
AudioBootStrap NACLAUD_bootstrap = {
NACLAUD_DRIVER_NAME, "SDL NaCl Audio Driver",
NACLAUD_Init, 0
};
@@ -0,0 +1,41 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclaudio_h
#define _SDL_naclaudio_h
#include "SDL_audio.h"
#include "../SDL_sysaudio.h"
#include "SDL_mutex.h"
#include "ppapi/c/ppb_audio.h"
#define _THIS SDL_AudioDevice *_this
#define private _this->hidden
typedef struct SDL_PrivateAudioData {
SDL_mutex* mutex;
PP_Resource audio;
} SDL_PrivateAudioData;
#endif /* _SDL_naclaudio_h */
+238
View File
@@ -0,0 +1,238 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_dbus.h"
#if SDL_USE_LIBDBUS
/* we never link directly to libdbus. */
#include "SDL_loadso.h"
static const char *dbus_library = "libdbus-1.so.3";
static void *dbus_handle = NULL;
static unsigned int screensaver_cookie = 0;
static SDL_DBusContext dbus = {0};
static int
load_dbus_syms(void)
{
#define SDL_DBUS_SYM2(x, y) \
if (!(dbus.x = SDL_LoadFunction(dbus_handle, #y))) return -1
#define SDL_DBUS_SYM(x) \
SDL_DBUS_SYM2(x, dbus_##x)
SDL_DBUS_SYM(bus_get_private);
SDL_DBUS_SYM(bus_register);
SDL_DBUS_SYM(bus_add_match);
SDL_DBUS_SYM(connection_open_private);
SDL_DBUS_SYM(connection_set_exit_on_disconnect);
SDL_DBUS_SYM(connection_get_is_connected);
SDL_DBUS_SYM(connection_add_filter);
SDL_DBUS_SYM(connection_send);
SDL_DBUS_SYM(connection_send_with_reply_and_block);
SDL_DBUS_SYM(connection_close);
SDL_DBUS_SYM(connection_unref);
SDL_DBUS_SYM(connection_flush);
SDL_DBUS_SYM(connection_read_write);
SDL_DBUS_SYM(connection_dispatch);
SDL_DBUS_SYM(message_is_signal);
SDL_DBUS_SYM(message_new_method_call);
SDL_DBUS_SYM(message_append_args);
SDL_DBUS_SYM(message_get_args);
SDL_DBUS_SYM(message_iter_init);
SDL_DBUS_SYM(message_iter_next);
SDL_DBUS_SYM(message_iter_get_basic);
SDL_DBUS_SYM(message_iter_get_arg_type);
SDL_DBUS_SYM(message_iter_recurse);
SDL_DBUS_SYM(message_unref);
SDL_DBUS_SYM(error_init);
SDL_DBUS_SYM(error_is_set);
SDL_DBUS_SYM(error_free);
SDL_DBUS_SYM(get_local_machine_id);
SDL_DBUS_SYM(free);
SDL_DBUS_SYM(shutdown);
#undef SDL_DBUS_SYM
#undef SDL_DBUS_SYM2
return 0;
}
static void
UnloadDBUSLibrary(void)
{
if (dbus_handle != NULL) {
SDL_UnloadObject(dbus_handle);
dbus_handle = NULL;
}
}
static int
LoadDBUSLibrary(void)
{
int retval = 0;
if (dbus_handle == NULL) {
dbus_handle = SDL_LoadObject(dbus_library);
if (dbus_handle == NULL) {
retval = -1;
/* Don't call SDL_SetError(): SDL_LoadObject already did. */
} else {
retval = load_dbus_syms();
if (retval < 0) {
UnloadDBUSLibrary();
}
}
}
return retval;
}
void
SDL_DBus_Init(void)
{
if (!dbus.session_conn && LoadDBUSLibrary() != -1) {
DBusError err;
dbus.error_init(&err);
dbus.session_conn = dbus.bus_get_private(DBUS_BUS_SESSION, &err);
if (dbus.error_is_set(&err)) {
dbus.error_free(&err);
if (dbus.session_conn) {
dbus.connection_unref(dbus.session_conn);
dbus.session_conn = NULL;
}
return; /* oh well */
}
dbus.connection_set_exit_on_disconnect(dbus.session_conn, 0);
}
}
void
SDL_DBus_Quit(void)
{
if (dbus.session_conn) {
dbus.connection_close(dbus.session_conn);
dbus.connection_unref(dbus.session_conn);
dbus.shutdown();
SDL_memset(&dbus, 0, sizeof(dbus));
}
UnloadDBUSLibrary();
}
SDL_DBusContext *
SDL_DBus_GetContext(void)
{
if(!dbus_handle || !dbus.session_conn){
SDL_DBus_Init();
}
if(dbus_handle && dbus.session_conn){
return &dbus;
} else {
return NULL;
}
}
void
SDL_DBus_ScreensaverTickle(void)
{
DBusConnection *conn = dbus.session_conn;
if (conn != NULL) {
DBusMessage *msg = dbus.message_new_method_call("org.gnome.ScreenSaver",
"/org/gnome/ScreenSaver",
"org.gnome.ScreenSaver",
"SimulateUserActivity");
if (msg != NULL) {
if (dbus.connection_send(conn, msg, NULL)) {
dbus.connection_flush(conn);
}
dbus.message_unref(msg);
}
}
}
SDL_bool
SDL_DBus_ScreensaverInhibit(SDL_bool inhibit)
{
DBusConnection *conn = dbus.session_conn;
if (conn == NULL)
return SDL_FALSE;
if (inhibit &&
screensaver_cookie != 0)
return SDL_TRUE;
if (!inhibit &&
screensaver_cookie == 0)
return SDL_TRUE;
if (inhibit) {
const char *app = "My SDL application";
const char *reason = "Playing a game";
DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
"/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver",
"Inhibit");
if (msg != NULL) {
dbus.message_append_args (msg,
DBUS_TYPE_STRING, &app,
DBUS_TYPE_STRING, &reason,
DBUS_TYPE_INVALID);
}
if (msg != NULL) {
DBusMessage *reply;
reply = dbus.connection_send_with_reply_and_block(conn, msg, 300, NULL);
if (reply) {
if (!dbus.message_get_args(reply, NULL,
DBUS_TYPE_UINT32, &screensaver_cookie,
DBUS_TYPE_INVALID))
screensaver_cookie = 0;
dbus.message_unref(reply);
}
dbus.message_unref(msg);
}
if (screensaver_cookie == 0) {
return SDL_FALSE;
}
return SDL_TRUE;
} else {
DBusMessage *msg = dbus.message_new_method_call("org.freedesktop.ScreenSaver",
"/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver",
"UnInhibit");
dbus.message_append_args (msg,
DBUS_TYPE_UINT32, &screensaver_cookie,
DBUS_TYPE_INVALID);
if (msg != NULL) {
if (dbus.connection_send(conn, msg, NULL)) {
dbus.connection_flush(conn);
}
dbus.message_unref(msg);
}
screensaver_cookie = 0;
return SDL_TRUE;
}
}
#endif
+80
View File
@@ -0,0 +1,80 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_dbus_h
#define _SDL_dbus_h
#ifdef HAVE_DBUS_DBUS_H
#define SDL_USE_LIBDBUS 1
#include "SDL_stdinc.h"
#include <dbus/dbus.h>
typedef struct SDL_DBusContext {
DBusConnection *session_conn;
DBusConnection *(*bus_get_private)(DBusBusType, DBusError *);
dbus_bool_t (*bus_register)(DBusConnection *, DBusError *);
void (*bus_add_match)(DBusConnection *, const char *, DBusError *);
DBusConnection * (*connection_open_private)(const char *, DBusError *);
void (*connection_set_exit_on_disconnect)(DBusConnection *, dbus_bool_t);
dbus_bool_t (*connection_get_is_connected)(DBusConnection *);
dbus_bool_t (*connection_add_filter)(DBusConnection *, DBusHandleMessageFunction,
void *, DBusFreeFunction);
dbus_bool_t (*connection_send)(DBusConnection *, DBusMessage *, dbus_uint32_t *);
DBusMessage *(*connection_send_with_reply_and_block)(DBusConnection *, DBusMessage *, int, DBusError *);
void (*connection_close)(DBusConnection *);
void (*connection_unref)(DBusConnection *);
void (*connection_flush)(DBusConnection *);
dbus_bool_t (*connection_read_write)(DBusConnection *, int);
DBusDispatchStatus (*connection_dispatch)(DBusConnection *);
dbus_bool_t (*message_is_signal)(DBusMessage *, const char *, const char *);
DBusMessage *(*message_new_method_call)(const char *, const char *, const char *, const char *);
dbus_bool_t (*message_append_args)(DBusMessage *, int, ...);
dbus_bool_t (*message_get_args)(DBusMessage *, DBusError *, int, ...);
dbus_bool_t (*message_iter_init)(DBusMessage *, DBusMessageIter *);
dbus_bool_t (*message_iter_next)(DBusMessageIter *);
void (*message_iter_get_basic)(DBusMessageIter *, void *);
int (*message_iter_get_arg_type)(DBusMessageIter *);
void (*message_iter_recurse)(DBusMessageIter *, DBusMessageIter *);
void (*message_unref)(DBusMessage *);
void (*error_init)(DBusError *);
dbus_bool_t (*error_is_set)(const DBusError *);
void (*error_free)(DBusError *);
char *(*get_local_machine_id)(void);
void (*free)(void *);
void (*shutdown)(void);
} SDL_DBusContext;
extern void SDL_DBus_Init(void);
extern void SDL_DBus_Quit(void);
extern SDL_DBusContext * SDL_DBus_GetContext(void);
extern void SDL_DBus_ScreensaverTickle(void);
extern SDL_bool SDL_DBus_ScreensaverInhibit(SDL_bool inhibit);
#endif /* HAVE_DBUS_DBUS_H */
#endif /* _SDL_dbus_h */
/* vi: set ts=4 sw=4 expandtab: */
+593
View File
@@ -0,0 +1,593 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifdef HAVE_IBUS_IBUS_H
#include "SDL.h"
#include "SDL_ibus.h"
#include "SDL_dbus.h"
#include "../../video/SDL_sysvideo.h"
#include "../../events/SDL_keyboard_c.h"
#include <sys/inotify.h>
#include <unistd.h>
#include <fcntl.h>
static const char IBUS_SERVICE[] = "org.freedesktop.IBus";
static const char IBUS_PATH[] = "/org/freedesktop/IBus";
static const char IBUS_INTERFACE[] = "org.freedesktop.IBus";
static const char IBUS_INPUT_INTERFACE[] = "org.freedesktop.IBus.InputContext";
static char *input_ctx_path = NULL;
static SDL_Rect ibus_cursor_rect = {0};
static DBusConnection *ibus_conn = NULL;
static char *ibus_addr_file = NULL;
int inotify_fd = -1;
static Uint32
IBus_ModState(void)
{
Uint32 ibus_mods = 0;
SDL_Keymod sdl_mods = SDL_GetModState();
/* Not sure about MOD3, MOD4 and HYPER mappings */
if(sdl_mods & KMOD_LSHIFT) ibus_mods |= IBUS_SHIFT_MASK;
if(sdl_mods & KMOD_CAPS) ibus_mods |= IBUS_LOCK_MASK;
if(sdl_mods & KMOD_LCTRL) ibus_mods |= IBUS_CONTROL_MASK;
if(sdl_mods & KMOD_LALT) ibus_mods |= IBUS_MOD1_MASK;
if(sdl_mods & KMOD_NUM) ibus_mods |= IBUS_MOD2_MASK;
if(sdl_mods & KMOD_MODE) ibus_mods |= IBUS_MOD5_MASK;
if(sdl_mods & KMOD_LGUI) ibus_mods |= IBUS_SUPER_MASK;
if(sdl_mods & KMOD_RGUI) ibus_mods |= IBUS_META_MASK;
return ibus_mods;
}
static const char *
IBus_GetVariantText(DBusConnection *conn, DBusMessageIter *iter, SDL_DBusContext *dbus)
{
/* The text we need is nested weirdly, use dbus-monitor to see the structure better */
const char *text = NULL;
DBusMessageIter sub1, sub2;
if(dbus->message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT){
return NULL;
}
dbus->message_iter_recurse(iter, &sub1);
if(dbus->message_iter_get_arg_type(&sub1) != DBUS_TYPE_STRUCT){
return NULL;
}
dbus->message_iter_recurse(&sub1, &sub2);
if(dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING){
return NULL;
}
const char *struct_id = NULL;
dbus->message_iter_get_basic(&sub2, &struct_id);
if(!struct_id || SDL_strncmp(struct_id, "IBusText", sizeof("IBusText")) != 0){
return NULL;
}
dbus->message_iter_next(&sub2);
dbus->message_iter_next(&sub2);
if(dbus->message_iter_get_arg_type(&sub2) != DBUS_TYPE_STRING){
return NULL;
}
dbus->message_iter_get_basic(&sub2, &text);
return text;
}
static size_t
IBus_utf8_strlen(const char *str)
{
size_t utf8_len = 0;
const char *p;
for(p = str; *p; ++p){
if(!((*p & 0x80) && !(*p & 0x40))){
++utf8_len;
}
}
return utf8_len;
}
static DBusHandlerResult
IBus_MessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data)
{
SDL_DBusContext *dbus = (SDL_DBusContext *)user_data;
if(dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "CommitText")){
DBusMessageIter iter;
dbus->message_iter_init(msg, &iter);
const char *text = IBus_GetVariantText(conn, &iter, dbus);
if(text && *text){
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
size_t text_bytes = SDL_strlen(text), i = 0;
while(i < text_bytes){
size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
SDL_SendKeyboardText(buf);
i += sz;
}
}
return DBUS_HANDLER_RESULT_HANDLED;
}
if(dbus->message_is_signal(msg, IBUS_INPUT_INTERFACE, "UpdatePreeditText")){
DBusMessageIter iter;
dbus->message_iter_init(msg, &iter);
const char *text = IBus_GetVariantText(conn, &iter, dbus);
if(text && *text){
char buf[SDL_TEXTEDITINGEVENT_TEXT_SIZE];
size_t text_bytes = SDL_strlen(text), i = 0;
size_t cursor = 0;
while(i < text_bytes){
size_t sz = SDL_utf8strlcpy(buf, text+i, sizeof(buf));
size_t chars = IBus_utf8_strlen(buf);
SDL_SendEditingText(buf, cursor, chars);
i += sz;
cursor += chars;
}
} else {
SDL_SendEditingText("", 0, 0);
}
SDL_IBus_UpdateTextRect(NULL);
return DBUS_HANDLER_RESULT_HANDLED;
}
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
static char *
IBus_ReadAddressFromFile(const char *file_path)
{
FILE *addr_file = fopen(file_path, "r");
if(!addr_file){
return NULL;
}
char addr_buf[1024];
SDL_bool success = SDL_FALSE;
while(fgets(addr_buf, sizeof(addr_buf), addr_file)){
if(SDL_strncmp(addr_buf, "IBUS_ADDRESS=", sizeof("IBUS_ADDRESS=")-1) == 0){
size_t sz = SDL_strlen(addr_buf);
if(addr_buf[sz-1] == '\n') addr_buf[sz-1] = 0;
if(addr_buf[sz-2] == '\r') addr_buf[sz-2] = 0;
success = SDL_TRUE;
break;
}
}
fclose(addr_file);
if(success){
return SDL_strdup(addr_buf + (sizeof("IBUS_ADDRESS=") - 1));
} else {
return NULL;
}
}
static char *
IBus_GetDBusAddressFilename(void)
{
if(ibus_addr_file){
return SDL_strdup(ibus_addr_file);
}
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(!dbus){
return NULL;
}
/* Use this environment variable if it exists. */
const char *addr = SDL_getenv("IBUS_ADDRESS");
if(addr && *addr){
return SDL_strdup(addr);
}
/* Otherwise, we have to get the hostname, display, machine id, config dir
and look up the address from a filepath using all those bits, eek. */
const char *disp_env = SDL_getenv("DISPLAY");
char *display = NULL;
if(!disp_env || !*disp_env){
display = SDL_strdup(":0.0");
} else {
display = SDL_strdup(disp_env);
}
const char *host = display;
char *disp_num = SDL_strrchr(display, ':'),
*screen_num = SDL_strrchr(display, '.');
if(!disp_num){
SDL_free(display);
return NULL;
}
*disp_num = 0;
disp_num++;
if(screen_num){
*screen_num = 0;
}
if(!*host){
host = "unix";
}
char config_dir[PATH_MAX];
SDL_memset(config_dir, 0, sizeof(config_dir));
const char *conf_env = SDL_getenv("XDG_CONFIG_HOME");
if(conf_env && *conf_env){
SDL_strlcpy(config_dir, conf_env, sizeof(config_dir));
} else {
const char *home_env = SDL_getenv("HOME");
if(!home_env || !*home_env){
SDL_free(display);
return NULL;
}
SDL_snprintf(config_dir, sizeof(config_dir), "%s/.config", home_env);
}
char *key = dbus->get_local_machine_id();
char file_path[PATH_MAX];
SDL_memset(file_path, 0, sizeof(file_path));
SDL_snprintf(file_path, sizeof(file_path), "%s/ibus/bus/%s-%s-%s",
config_dir, key, host, disp_num);
dbus->free(key);
SDL_free(display);
return SDL_strdup(file_path);
}
static SDL_bool
IBus_SetupConnection(SDL_DBusContext *dbus, const char* addr)
{
const char *path = NULL;
SDL_bool result = SDL_FALSE;
ibus_conn = dbus->connection_open_private(addr, NULL);
if(!ibus_conn){
return SDL_FALSE;
}
dbus->connection_flush(ibus_conn);
if(!dbus->bus_register(ibus_conn, NULL)){
ibus_conn = NULL;
return SDL_FALSE;
}
dbus->connection_flush(ibus_conn);
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
IBUS_PATH,
IBUS_INTERFACE,
"CreateInputContext");
if(msg){
const char *client_name = "SDL2_Application";
dbus->message_append_args(msg,
DBUS_TYPE_STRING, &client_name,
DBUS_TYPE_INVALID);
}
if(msg){
DBusMessage *reply;
reply = dbus->connection_send_with_reply_and_block(ibus_conn, msg, 1000, NULL);
if(reply){
if(dbus->message_get_args(reply, NULL,
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID)){
if(input_ctx_path){
SDL_free(input_ctx_path);
}
input_ctx_path = SDL_strdup(path);
result = SDL_TRUE;
}
dbus->message_unref(reply);
}
dbus->message_unref(msg);
}
if(result){
msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
"SetCapabilities");
if(msg){
Uint32 caps = IBUS_CAP_FOCUS | IBUS_CAP_PREEDIT_TEXT;
dbus->message_append_args(msg,
DBUS_TYPE_UINT32, &caps,
DBUS_TYPE_INVALID);
}
if(msg){
if(dbus->connection_send(ibus_conn, msg, NULL)){
dbus->connection_flush(ibus_conn);
}
dbus->message_unref(msg);
}
dbus->bus_add_match(ibus_conn, "type='signal',interface='org.freedesktop.IBus.InputContext'", NULL);
dbus->connection_add_filter(ibus_conn, &IBus_MessageFilter, dbus, NULL);
dbus->connection_flush(ibus_conn);
}
SDL_IBus_SetFocus(SDL_GetFocusWindow() != NULL);
SDL_IBus_UpdateTextRect(NULL);
return result;
}
static SDL_bool
IBus_CheckConnection(SDL_DBusContext *dbus)
{
if(!dbus) return SDL_FALSE;
if(ibus_conn && dbus->connection_get_is_connected(ibus_conn)){
return SDL_TRUE;
}
if(inotify_fd != -1){
char buf[1024];
ssize_t readsize = read(inotify_fd, buf, sizeof(buf));
if(readsize > 0){
char *p;
SDL_bool file_updated = SDL_FALSE;
for(p = buf; p < buf + readsize; /**/){
struct inotify_event *event = (struct inotify_event*) p;
if(event->len > 0){
char *addr_file_no_path = SDL_strrchr(ibus_addr_file, '/');
if(!addr_file_no_path) return SDL_FALSE;
if(SDL_strcmp(addr_file_no_path + 1, event->name) == 0){
file_updated = SDL_TRUE;
break;
}
}
p += sizeof(struct inotify_event) + event->len;
}
if(file_updated){
char *addr = IBus_ReadAddressFromFile(ibus_addr_file);
if(addr){
SDL_bool result = IBus_SetupConnection(dbus, addr);
SDL_free(addr);
return result;
}
}
}
}
return SDL_FALSE;
}
SDL_bool
SDL_IBus_Init(void)
{
SDL_bool result = SDL_FALSE;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(dbus){
char *addr_file = IBus_GetDBusAddressFilename();
if(!addr_file){
return SDL_FALSE;
}
ibus_addr_file = SDL_strdup(addr_file);
char *addr = IBus_ReadAddressFromFile(addr_file);
inotify_fd = inotify_init();
fcntl(inotify_fd, F_SETFL, O_NONBLOCK);
char *addr_file_dir = SDL_strrchr(addr_file, '/');
if(addr_file_dir){
*addr_file_dir = 0;
}
inotify_add_watch(inotify_fd, addr_file, IN_CREATE | IN_MODIFY);
SDL_free(addr_file);
result = IBus_SetupConnection(dbus, addr);
SDL_free(addr);
}
return result;
}
void
SDL_IBus_Quit(void)
{
if(input_ctx_path){
SDL_free(input_ctx_path);
input_ctx_path = NULL;
}
if(ibus_addr_file){
SDL_free(ibus_addr_file);
ibus_addr_file = NULL;
}
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(dbus && ibus_conn){
dbus->connection_close(ibus_conn);
dbus->connection_unref(ibus_conn);
}
SDL_memset(&ibus_cursor_rect, 0, sizeof(ibus_cursor_rect));
}
static void
IBus_SimpleMessage(const char *method)
{
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
method);
if(msg){
if(dbus->connection_send(ibus_conn, msg, NULL)){
dbus->connection_flush(ibus_conn);
}
dbus->message_unref(msg);
}
}
}
void
SDL_IBus_SetFocus(SDL_bool focused)
{
const char *method = focused ? "FocusIn" : "FocusOut";
IBus_SimpleMessage(method);
}
void
SDL_IBus_Reset(void)
{
IBus_SimpleMessage("Reset");
}
SDL_bool
SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode)
{
SDL_bool result = SDL_FALSE;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
"ProcessKeyEvent");
if(msg){
Uint32 mods = IBus_ModState();
dbus->message_append_args(msg,
DBUS_TYPE_UINT32, &keysym,
DBUS_TYPE_UINT32, &keycode,
DBUS_TYPE_UINT32, &mods,
DBUS_TYPE_INVALID);
}
if(msg){
DBusMessage *reply;
reply = dbus->connection_send_with_reply_and_block(ibus_conn, msg, 300, NULL);
if(reply){
if(!dbus->message_get_args(reply, NULL,
DBUS_TYPE_BOOLEAN, &result,
DBUS_TYPE_INVALID)){
result = SDL_FALSE;
}
dbus->message_unref(reply);
}
dbus->message_unref(msg);
}
}
return result;
}
void
SDL_IBus_UpdateTextRect(SDL_Rect *rect)
{
if(rect){
SDL_memcpy(&ibus_cursor_rect, rect, sizeof(ibus_cursor_rect));
}
SDL_Window *focused_win = SDL_GetFocusWindow();
if(!focused_win) return;
int x = 0, y = 0;
SDL_GetWindowPosition(focused_win, &x, &y);
x += ibus_cursor_rect.x;
y += ibus_cursor_rect.y;
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
DBusMessage *msg = dbus->message_new_method_call(IBUS_SERVICE,
input_ctx_path,
IBUS_INPUT_INTERFACE,
"SetCursorLocation");
if(msg){
dbus->message_append_args(msg,
DBUS_TYPE_INT32, &x,
DBUS_TYPE_INT32, &y,
DBUS_TYPE_INT32, &ibus_cursor_rect.w,
DBUS_TYPE_INT32, &ibus_cursor_rect.h,
DBUS_TYPE_INVALID);
}
if(msg){
if(dbus->connection_send(ibus_conn, msg, NULL)){
dbus->connection_flush(ibus_conn);
}
dbus->message_unref(msg);
}
}
}
void
SDL_IBus_PumpEvents(void)
{
SDL_DBusContext *dbus = SDL_DBus_GetContext();
if(IBus_CheckConnection(dbus)){
dbus->connection_read_write(ibus_conn, 0);
while(dbus->connection_dispatch(ibus_conn) == DBUS_DISPATCH_DATA_REMAINS){
/* Do nothing, actual work happens in IBus_MessageFilter */
}
}
}
#endif
+58
View File
@@ -0,0 +1,58 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_ibus_h
#define _SDL_ibus_h
#ifdef HAVE_IBUS_IBUS_H
#define SDL_USE_IBUS 1
#include "SDL_stdinc.h"
#include <ibus-1.0/ibus.h>
extern SDL_bool SDL_IBus_Init(void);
extern void SDL_IBus_Quit(void);
/* Lets the IBus server know about changes in window focus */
extern void SDL_IBus_SetFocus(SDL_bool focused);
/* Closes the candidate list and resets any text currently being edited */
extern void SDL_IBus_Reset(void);
/* Sends a keypress event to IBus, returns SDL_TRUE if IBus used this event to
update its candidate list or change input methods. PumpEvents should be
called some time after this, to recieve the TextInput / TextEditing event back. */
extern SDL_bool SDL_IBus_ProcessKeyEvent(Uint32 keysym, Uint32 keycode);
/* Update the position of IBus' candidate list. If rect is NULL then this will
just reposition it relative to the focused window's new position. */
extern void SDL_IBus_UpdateTextRect(SDL_Rect *window_relative_rect);
/* Checks DBus for new IBus events, and calls SDL_SendKeyboardText /
SDL_SendEditingText for each event it finds */
extern void SDL_IBus_PumpEvents();
#endif /* HAVE_IBUS_IBUS_H */
#endif /* _SDL_ibus_h */
/* vi: set ts=4 sw=4 expandtab: */
@@ -0,0 +1,41 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_error.h"
#include "SDL_filesystem.h"
#ifdef SDL_FILESYSTEM_NACL
char *
SDL_GetBasePath(void)
{
SDL_Unsupported();
return NULL;
}
char *
SDL_GetPrefPath(const char *org, const char *app)
{
SDL_Unsupported();
return NULL;
}
#endif /* __NACL__ */
+118
View File
@@ -0,0 +1,118 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/* __kernel_tan( x, y, k )
* kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
* Input x is assumed to be bounded by ~pi/4 in magnitude.
* Input y is the tail of x.
* Input k indicates whether tan (if k=1) or
* -1/tan (if k= -1) is returned.
*
* Algorithm
* 1. Since tan(-x) = -tan(x), we need only to consider positive x.
* 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
* 3. tan(x) is approximated by a odd polynomial of degree 27 on
* [0,0.67434]
* 3 27
* tan(x) ~ x + T1*x + ... + T13*x
* where
*
* |tan(x) 2 4 26 | -59.2
* |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
* | x |
*
* Note: tan(x+y) = tan(x) + tan'(x)*y
* ~ tan(x) + (1+x*x)*y
* Therefore, for better accuracy in computing tan(x+y), let
* 3 2 2 2 2
* r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
* then
* 3 2
* tan(x+y) = x + (T1*x + (x *(r+y)+y))
*
* 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
* tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
* = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
*/
#include "math_libm.h"
#include "math_private.h"
static const double
one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
T[] = {
3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
-1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
};
double __kernel_tan(double x, double y, int iy)
{
double z,r,v,w,s;
int32_t ix,hx;
GET_HIGH_WORD(hx,x);
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x3e300000) /* x < 2**-28 */
{if((int)x==0) { /* generate inexact */
u_int32_t low;
GET_LOW_WORD(low,x);
if(((ix|low)|(iy+1))==0) return one/fabs(x);
else return (iy==1)? x: -one/x;
}
}
if(ix>=0x3FE59428) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
/* Break x^5*(T[1]+x^2*T[2]+...) into
* x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
* x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
*/
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3FE59428) {
v = (double)iy;
return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
/* compute -1.0/(x+r) accurately */
double a,t;
z = w;
SET_LOW_WORD(z,0);
v = r-(z - x); /* z+v = r+x */
t = a = -1.0/w; /* a = -1.0/w */
SET_LOW_WORD(t,0);
s = 1.0+t*z;
return t+a*(s+t*v);
}
}
+67
View File
@@ -0,0 +1,67 @@
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
/* tan(x)
* Return tangent function of x.
*
* kernel function:
* __kernel_tan ... tangent function on [-pi/4,pi/4]
* __ieee754_rem_pio2 ... argument reduction routine
*
* Method.
* Let S,C and T denote the sin, cos and tan respectively on
* [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
* in [-pi/4 , +pi/4], and let n = k mod 4.
* We have
*
* n sin(x) cos(x) tan(x)
* ----------------------------------------------------------
* 0 S C T
* 1 C -S -1/T
* 2 -S -C T
* 3 -C S -1/T
* ----------------------------------------------------------
*
* Special cases:
* Let trig be any of sin, cos, or tan.
* trig(+-INF) is NaN, with signals;
* trig(NaN) is that NaN;
*
* Accuracy:
* TRIG(x) returns trig(x) nearly rounded
*/
#include "math_libm.h"
#include "math_private.h"
double tan(double x)
{
double y[2],z=0.0;
int32_t n, ix;
/* High word of x. */
GET_HIGH_WORD(ix,x);
/* |x| ~< pi/4 */
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
/* tan(Inf or NaN) is NaN */
else if (ix>=0x7ff00000) return x-x; /* NaN */
/* argument reduction needed */
else {
n = __ieee754_rem_pio2(x,y);
return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
-1 -- n odd */
}
}
libm_hidden_def(tan)
@@ -0,0 +1,93 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
/* Include the SDL main definition header */
#include "SDL_main.h"
#include "ppapi_simple/ps_main.h"
#include "ppapi_simple/ps_event.h"
#include "ppapi_simple/ps_interface.h"
#include "nacl_io/nacl_io.h"
#include "sys/mount.h"
extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
int
nacl_main(int argc, char *argv[])
{
int status;
PSEvent* ps_event;
PP_Resource event;
struct PP_Rect rect;
int ready = 0;
const PPB_View *ppb_view = PSInterfaceView();
/* This is started in a worker thread by ppapi_simple! */
/* Wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before starting the app */
PSEventSetFilter(PSE_INSTANCE_DIDCHANGEVIEW);
while (!ready) {
/* Process all waiting events without blocking */
while (!ready && (ps_event = PSEventWaitAcquire()) != NULL) {
event = ps_event->as_resource;
switch(ps_event->type) {
/* From DidChangeView, contains a view resource */
case PSE_INSTANCE_DIDCHANGEVIEW:
ppb_view->GetRect(event, &rect);
NACL_SetScreenResolution(rect.size.width, rect.size.height, 0);
ready = 1;
break;
default:
break;
}
PSEventRelease(ps_event);
}
}
/* Do a default httpfs mount on /,
* apps can override this by unmounting /
* and remounting with the desired configuration
*/
nacl_io_init_ppapi(PSGetInstanceId(), PSGetInterface);
umount("/");
mount(
"", /* source */
"/", /* target */
"httpfs", /* filesystemtype */
0, /* mountflags */
""); /* data specific to the html5fs type */
/* Everything is ready, start the user main function */
SDL_SetMainReady();
status = SDL_main(argc, argv);
return 0;
}
/* ppapi_simple will start nacl_main in a worker thread */
PPAPI_SIMPLE_REGISTER_MAIN(nacl_main);
#endif /* SDL_VIDEO_DRIVER_NACL */
@@ -0,0 +1,432 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL.h"
#include "../../events/SDL_sysevents.h"
#include "../../events/SDL_events_c.h"
#include "SDL_naclevents_c.h"
#include "SDL_naclvideo.h"
#include "ppapi_simple/ps_event.h"
/* Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent */
static SDL_Scancode NACL_Keycodes[] = {
SDL_SCANCODE_UNKNOWN, /* 0 */
SDL_SCANCODE_UNKNOWN, /* 1 */
SDL_SCANCODE_UNKNOWN, /* 2 */
SDL_SCANCODE_CANCEL, /* DOM_VK_CANCEL 3 */
SDL_SCANCODE_UNKNOWN, /* 4 */
SDL_SCANCODE_UNKNOWN, /* 5 */
SDL_SCANCODE_HELP, /* DOM_VK_HELP 6 */
SDL_SCANCODE_UNKNOWN, /* 7 */
SDL_SCANCODE_BACKSPACE, /* DOM_VK_BACK_SPACE 8 */
SDL_SCANCODE_TAB, /* DOM_VK_TAB 9 */
SDL_SCANCODE_UNKNOWN, /* 10 */
SDL_SCANCODE_UNKNOWN, /* 11 */
SDL_SCANCODE_CLEAR, /* DOM_VK_CLEAR 12 */
SDL_SCANCODE_RETURN, /* DOM_VK_RETURN 13 */
SDL_SCANCODE_RETURN, /* DOM_VK_ENTER 14 */
SDL_SCANCODE_UNKNOWN, /* 15 */
SDL_SCANCODE_LSHIFT, /* DOM_VK_SHIFT 16 */
SDL_SCANCODE_LCTRL, /* DOM_VK_CONTROL 17 */
SDL_SCANCODE_LALT, /* DOM_VK_ALT 18 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_PAUSE 19 */
SDL_SCANCODE_CAPSLOCK, /* DOM_VK_CAPS_LOCK 20 */
SDL_SCANCODE_LANG1, /* DOM_VK_KANA DOM_VK_HANGUL 21 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_EISU 22 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_JUNJA 23 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_FINAL 24 */
SDL_SCANCODE_LANG2, /* DOM_VK_HANJA DOM_VK_KANJI 25 */
SDL_SCANCODE_UNKNOWN, /* 26 */
SDL_SCANCODE_ESCAPE, /* DOM_VK_ESCAPE 27 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_CONVERT 28 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_NONCONVERT 29 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_ACCEPT 30 */
SDL_SCANCODE_MODE, /* DOM_VK_MODECHANGE 31 */
SDL_SCANCODE_SPACE, /* DOM_VK_SPACE 32 */
SDL_SCANCODE_PAGEUP, /* DOM_VK_PAGE_UP 33 */
SDL_SCANCODE_PAGEDOWN, /* DOM_VK_PAGE_DOWN 34 */
SDL_SCANCODE_END, /* DOM_VK_END 35 */
SDL_SCANCODE_HOME, /* DOM_VK_HOME 36 */
SDL_SCANCODE_LEFT, /* DOM_VK_LEFT 37 */
SDL_SCANCODE_UP, /* DOM_VK_UP 38 */
SDL_SCANCODE_RIGHT, /* DOM_VK_RIGHT 39 */
SDL_SCANCODE_DOWN, /* DOM_VK_DOWN 40 */
SDL_SCANCODE_SELECT, /* DOM_VK_SELECT 41 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_PRINT 42 */
SDL_SCANCODE_EXECUTE, /* DOM_VK_EXECUTE 43 */
SDL_SCANCODE_PRINTSCREEN, /* DOM_VK_PRINTSCREEN 44 */
SDL_SCANCODE_INSERT, /* DOM_VK_INSERT 45 */
SDL_SCANCODE_DELETE, /* DOM_VK_DELETE 46 */
SDL_SCANCODE_UNKNOWN, /* 47 */
SDL_SCANCODE_0, /* DOM_VK_0 48 */
SDL_SCANCODE_1, /* DOM_VK_1 49 */
SDL_SCANCODE_2, /* DOM_VK_2 50 */
SDL_SCANCODE_3, /* DOM_VK_3 51 */
SDL_SCANCODE_4, /* DOM_VK_4 52 */
SDL_SCANCODE_5, /* DOM_VK_5 53 */
SDL_SCANCODE_6, /* DOM_VK_6 54 */
SDL_SCANCODE_7, /* DOM_VK_7 55 */
SDL_SCANCODE_8, /* DOM_VK_8 56 */
SDL_SCANCODE_9, /* DOM_VK_9 57 */
SDL_SCANCODE_KP_COLON, /* DOM_VK_COLON 58 */
SDL_SCANCODE_SEMICOLON, /* DOM_VK_SEMICOLON 59 */
SDL_SCANCODE_KP_LESS, /* DOM_VK_LESS_THAN 60 */
SDL_SCANCODE_EQUALS, /* DOM_VK_EQUALS 61 */
SDL_SCANCODE_KP_GREATER, /* DOM_VK_GREATER_THAN 62 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_QUESTION_MARK 63 */
SDL_SCANCODE_KP_AT, /* DOM_VK_AT 64 */
SDL_SCANCODE_A, /* DOM_VK_A 65 */
SDL_SCANCODE_B, /* DOM_VK_B 66 */
SDL_SCANCODE_C, /* DOM_VK_C 67 */
SDL_SCANCODE_D, /* DOM_VK_D 68 */
SDL_SCANCODE_E, /* DOM_VK_E 69 */
SDL_SCANCODE_F, /* DOM_VK_F 70 */
SDL_SCANCODE_G, /* DOM_VK_G 71 */
SDL_SCANCODE_H, /* DOM_VK_H 72 */
SDL_SCANCODE_I, /* DOM_VK_I 73 */
SDL_SCANCODE_J, /* DOM_VK_J 74 */
SDL_SCANCODE_K, /* DOM_VK_K 75 */
SDL_SCANCODE_L, /* DOM_VK_L 76 */
SDL_SCANCODE_M, /* DOM_VK_M 77 */
SDL_SCANCODE_N, /* DOM_VK_N 78 */
SDL_SCANCODE_O, /* DOM_VK_O 79 */
SDL_SCANCODE_P, /* DOM_VK_P 80 */
SDL_SCANCODE_Q, /* DOM_VK_Q 81 */
SDL_SCANCODE_R, /* DOM_VK_R 82 */
SDL_SCANCODE_S, /* DOM_VK_S 83 */
SDL_SCANCODE_T, /* DOM_VK_T 84 */
SDL_SCANCODE_U, /* DOM_VK_U 85 */
SDL_SCANCODE_V, /* DOM_VK_V 86 */
SDL_SCANCODE_W, /* DOM_VK_W 87 */
SDL_SCANCODE_X, /* DOM_VK_X 88 */
SDL_SCANCODE_Y, /* DOM_VK_Y 89 */
SDL_SCANCODE_Z, /* DOM_VK_Z 90 */
SDL_SCANCODE_LGUI, /* DOM_VK_WIN 91 */
SDL_SCANCODE_UNKNOWN, /* 92 */
SDL_SCANCODE_APPLICATION, /* DOM_VK_CONTEXT_MENU 93 */
SDL_SCANCODE_UNKNOWN, /* 94 */
SDL_SCANCODE_SLEEP, /* DOM_VK_SLEEP 95 */
SDL_SCANCODE_KP_0, /* DOM_VK_NUMPAD0 96 */
SDL_SCANCODE_KP_1, /* DOM_VK_NUMPAD1 97 */
SDL_SCANCODE_KP_2, /* DOM_VK_NUMPAD2 98 */
SDL_SCANCODE_KP_3, /* DOM_VK_NUMPAD3 99 */
SDL_SCANCODE_KP_4, /* DOM_VK_NUMPAD4 100 */
SDL_SCANCODE_KP_5, /* DOM_VK_NUMPAD5 101 */
SDL_SCANCODE_KP_6, /* DOM_VK_NUMPAD6 102 */
SDL_SCANCODE_KP_7, /* DOM_VK_NUMPAD7 103 */
SDL_SCANCODE_KP_8, /* DOM_VK_NUMPAD8 104 */
SDL_SCANCODE_KP_9, /* DOM_VK_NUMPAD9 105 */
SDL_SCANCODE_KP_MULTIPLY, /* DOM_VK_MULTIPLY 106 */
SDL_SCANCODE_KP_PLUS, /* DOM_VK_ADD 107 */
SDL_SCANCODE_KP_COMMA, /* DOM_VK_SEPARATOR 108 */
SDL_SCANCODE_KP_MINUS, /* DOM_VK_SUBTRACT 109 */
SDL_SCANCODE_KP_PERIOD, /* DOM_VK_DECIMAL 110 */
SDL_SCANCODE_KP_DIVIDE, /* DOM_VK_DIVIDE 111 */
SDL_SCANCODE_F1, /* DOM_VK_F1 112 */
SDL_SCANCODE_F2, /* DOM_VK_F2 113 */
SDL_SCANCODE_F3, /* DOM_VK_F3 114 */
SDL_SCANCODE_F4, /* DOM_VK_F4 115 */
SDL_SCANCODE_F5, /* DOM_VK_F5 116 */
SDL_SCANCODE_F6, /* DOM_VK_F6 117 */
SDL_SCANCODE_F7, /* DOM_VK_F7 118 */
SDL_SCANCODE_F8, /* DOM_VK_F8 119 */
SDL_SCANCODE_F9, /* DOM_VK_F9 120 */
SDL_SCANCODE_F10, /* DOM_VK_F10 121 */
SDL_SCANCODE_F11, /* DOM_VK_F11 122 */
SDL_SCANCODE_F12, /* DOM_VK_F12 123 */
SDL_SCANCODE_F13, /* DOM_VK_F13 124 */
SDL_SCANCODE_F14, /* DOM_VK_F14 125 */
SDL_SCANCODE_F15, /* DOM_VK_F15 126 */
SDL_SCANCODE_F16, /* DOM_VK_F16 127 */
SDL_SCANCODE_F17, /* DOM_VK_F17 128 */
SDL_SCANCODE_F18, /* DOM_VK_F18 129 */
SDL_SCANCODE_F19, /* DOM_VK_F19 130 */
SDL_SCANCODE_F20, /* DOM_VK_F20 131 */
SDL_SCANCODE_F21, /* DOM_VK_F21 132 */
SDL_SCANCODE_F22, /* DOM_VK_F22 133 */
SDL_SCANCODE_F23, /* DOM_VK_F23 134 */
SDL_SCANCODE_F24, /* DOM_VK_F24 135 */
SDL_SCANCODE_UNKNOWN, /* 136 */
SDL_SCANCODE_UNKNOWN, /* 137 */
SDL_SCANCODE_UNKNOWN, /* 138 */
SDL_SCANCODE_UNKNOWN, /* 139 */
SDL_SCANCODE_UNKNOWN, /* 140 */
SDL_SCANCODE_UNKNOWN, /* 141 */
SDL_SCANCODE_UNKNOWN, /* 142 */
SDL_SCANCODE_UNKNOWN, /* 143 */
SDL_SCANCODE_NUMLOCKCLEAR, /* DOM_VK_NUM_LOCK 144 */
SDL_SCANCODE_SCROLLLOCK, /* DOM_VK_SCROLL_LOCK 145 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_JISHO 146 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_MASSHOU 147 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_TOUROKU 148 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_LOYA 149 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FJ_ROYA 150 */
SDL_SCANCODE_UNKNOWN, /* 151 */
SDL_SCANCODE_UNKNOWN, /* 152 */
SDL_SCANCODE_UNKNOWN, /* 153 */
SDL_SCANCODE_UNKNOWN, /* 154 */
SDL_SCANCODE_UNKNOWN, /* 155 */
SDL_SCANCODE_UNKNOWN, /* 156 */
SDL_SCANCODE_UNKNOWN, /* 157 */
SDL_SCANCODE_UNKNOWN, /* 158 */
SDL_SCANCODE_UNKNOWN, /* 159 */
SDL_SCANCODE_GRAVE, /* DOM_VK_CIRCUMFLEX 160 */
SDL_SCANCODE_KP_EXCLAM, /* DOM_VK_EXCLAMATION 161 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_DOUBLE_QUOTE 162 */
SDL_SCANCODE_KP_HASH, /* DOM_VK_HASH 163 */
SDL_SCANCODE_CURRENCYUNIT, /* DOM_VK_DOLLAR 164 */
SDL_SCANCODE_KP_PERCENT, /* DOM_VK_PERCENT 165 */
SDL_SCANCODE_KP_AMPERSAND, /* DOM_VK_AMPERSAND 166 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_UNDERSCORE 167 */
SDL_SCANCODE_KP_LEFTPAREN, /* DOM_VK_OPEN_PAREN 168 */
SDL_SCANCODE_KP_RIGHTPAREN, /* DOM_VK_CLOSE_PAREN 169 */
SDL_SCANCODE_KP_MULTIPLY, /* DOM_VK_ASTERISK 170 */
SDL_SCANCODE_KP_PLUS, /* DOM_VK_PLUS 171 */
SDL_SCANCODE_KP_PLUS, /* DOM_VK_PIPE 172 */
SDL_SCANCODE_MINUS, /* DOM_VK_HYPHEN_MINUS 173 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_OPEN_CURLY_BRACKET 174 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_CLOSE_CURLY_BRACKET 175 */
SDL_SCANCODE_NONUSBACKSLASH, /* DOM_VK_TILDE 176 */
SDL_SCANCODE_UNKNOWN, /* 177 */
SDL_SCANCODE_UNKNOWN, /* 178 */
SDL_SCANCODE_UNKNOWN, /* 179 */
SDL_SCANCODE_UNKNOWN, /* 180 */
SDL_SCANCODE_MUTE, /* DOM_VK_VOLUME_MUTE 181 */
SDL_SCANCODE_VOLUMEDOWN, /* DOM_VK_VOLUME_DOWN 182 */
SDL_SCANCODE_VOLUMEUP, /* DOM_VK_VOLUME_UP 183 */
SDL_SCANCODE_UNKNOWN, /* 184 */
SDL_SCANCODE_UNKNOWN, /* 185 */
SDL_SCANCODE_UNKNOWN, /* 186 */
SDL_SCANCODE_UNKNOWN, /* 187 */
SDL_SCANCODE_COMMA, /* DOM_VK_COMMA 188 */
SDL_SCANCODE_UNKNOWN, /* 189 */
SDL_SCANCODE_PERIOD, /* DOM_VK_PERIOD 190 */
SDL_SCANCODE_SLASH, /* DOM_VK_SLASH 191 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_BACK_QUOTE 192 */
SDL_SCANCODE_UNKNOWN, /* 193 */
SDL_SCANCODE_UNKNOWN, /* 194 */
SDL_SCANCODE_UNKNOWN, /* 195 */
SDL_SCANCODE_UNKNOWN, /* 196 */
SDL_SCANCODE_UNKNOWN, /* 197 */
SDL_SCANCODE_UNKNOWN, /* 198 */
SDL_SCANCODE_UNKNOWN, /* 199 */
SDL_SCANCODE_UNKNOWN, /* 200 */
SDL_SCANCODE_UNKNOWN, /* 201 */
SDL_SCANCODE_UNKNOWN, /* 202 */
SDL_SCANCODE_UNKNOWN, /* 203 */
SDL_SCANCODE_UNKNOWN, /* 204 */
SDL_SCANCODE_UNKNOWN, /* 205 */
SDL_SCANCODE_UNKNOWN, /* 206 */
SDL_SCANCODE_UNKNOWN, /* 207 */
SDL_SCANCODE_UNKNOWN, /* 208 */
SDL_SCANCODE_UNKNOWN, /* 209 */
SDL_SCANCODE_UNKNOWN, /* 210 */
SDL_SCANCODE_UNKNOWN, /* 211 */
SDL_SCANCODE_UNKNOWN, /* 212 */
SDL_SCANCODE_UNKNOWN, /* 213 */
SDL_SCANCODE_UNKNOWN, /* 214 */
SDL_SCANCODE_UNKNOWN, /* 215 */
SDL_SCANCODE_UNKNOWN, /* 216 */
SDL_SCANCODE_UNKNOWN, /* 217 */
SDL_SCANCODE_UNKNOWN, /* 218 */
SDL_SCANCODE_LEFTBRACKET, /* DOM_VK_OPEN_BRACKET 219 */
SDL_SCANCODE_BACKSLASH, /* DOM_VK_BACK_SLASH 220 */
SDL_SCANCODE_RIGHTBRACKET, /* DOM_VK_CLOSE_BRACKET 221 */
SDL_SCANCODE_APOSTROPHE, /* DOM_VK_QUOTE 222 */
SDL_SCANCODE_UNKNOWN, /* 223 */
SDL_SCANCODE_RGUI, /* DOM_VK_META 224 */
SDL_SCANCODE_RALT, /* DOM_VK_ALTGR 225 */
SDL_SCANCODE_UNKNOWN, /* 226 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_HELP 227 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_00 228 */
SDL_SCANCODE_UNKNOWN, /* 229 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_ICO_CLEAR 230 */
SDL_SCANCODE_UNKNOWN, /* 231 */
SDL_SCANCODE_UNKNOWN, /* 232 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_RESET 233 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_JUMP 234 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA1 235 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA2 236 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_PA3 237 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_WSCTRL 238 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_CUSEL 239 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_ATTN 240 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_FINISH 241 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_COPY 242 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_AUTO 243 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_ENLW 244 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_BACKTAB 245 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_ATTN 246 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_CRSEL 247 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_EXSEL 248 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_EREOF 249 */
SDL_SCANCODE_AUDIOPLAY, /* DOM_VK_PLAY 250 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_ZOOM 251 */
SDL_SCANCODE_UNKNOWN, /* 252 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_PA1 253 */
SDL_SCANCODE_UNKNOWN, /* DOM_VK_WIN_OEM_CLEAR 254 */
SDL_SCANCODE_UNKNOWN, /* 255 */
};
static Uint8 SDL_NACL_translate_mouse_button(int32_t button) {
switch (button) {
case PP_INPUTEVENT_MOUSEBUTTON_LEFT:
return SDL_BUTTON_LEFT;
case PP_INPUTEVENT_MOUSEBUTTON_MIDDLE:
return SDL_BUTTON_MIDDLE;
case PP_INPUTEVENT_MOUSEBUTTON_RIGHT:
return SDL_BUTTON_RIGHT;
case PP_INPUTEVENT_MOUSEBUTTON_NONE:
default:
return 0;
}
}
static SDL_Scancode
SDL_NACL_translate_keycode(int keycode)
{
SDL_Scancode scancode = SDL_SCANCODE_UNKNOWN;
if (keycode < SDL_arraysize(NACL_Keycodes)) {
scancode = NACL_Keycodes[keycode];
}
if (scancode == SDL_SCANCODE_UNKNOWN) {
SDL_Log("The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> NACL KeyCode %d \n", keycode);
}
return scancode;
}
void NACL_PumpEvents(_THIS) {
PSEvent* ps_event;
PP_Resource event;
PP_InputEvent_Type type;
PP_InputEvent_Modifier modifiers;
struct PP_Rect rect;
struct PP_FloatPoint fp;
struct PP_Point location;
struct PP_Var var;
const char *str;
char text[64];
Uint32 str_len;
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();
if (driverdata->window) {
while ((ps_event = PSEventTryAcquire()) != NULL) {
event = ps_event->as_resource;
switch(ps_event->type) {
/* From DidChangeView, contains a view resource */
case PSE_INSTANCE_DIDCHANGEVIEW:
driverdata->ppb_view->GetRect(event, &rect);
NACL_SetScreenResolution(rect.size.width, rect.size.height, SDL_PIXELFORMAT_UNKNOWN);
// FIXME: Rebuild context? See life.c UpdateContext
break;
/* From HandleInputEvent, contains an input resource. */
case PSE_INSTANCE_HANDLEINPUT:
type = driverdata->ppb_input_event->GetType(event);
modifiers = driverdata->ppb_input_event->GetModifiers(event);
switch(type) {
case PP_INPUTEVENT_TYPE_MOUSEDOWN:
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_PRESSED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
break;
case PP_INPUTEVENT_TYPE_MOUSEUP:
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, SDL_NACL_translate_mouse_button(driverdata->ppb_mouse_input_event->GetButton(event)));
break;
case PP_INPUTEVENT_TYPE_WHEEL:
/* FIXME: GetTicks provides high resolution scroll events */
fp = driverdata->ppb_wheel_input_event->GetDelta(event);
SDL_SendMouseWheel(mouse->focus, mouse->mouseID, (int) fp.x, (int) fp.y);
break;
case PP_INPUTEVENT_TYPE_MOUSEENTER:
case PP_INPUTEVENT_TYPE_MOUSELEAVE:
/* FIXME: Mouse Focus */
break;
case PP_INPUTEVENT_TYPE_MOUSEMOVE:
location = driverdata->ppb_mouse_input_event->GetPosition(event);
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, SDL_FALSE, location.x, location.y);
break;
case PP_INPUTEVENT_TYPE_TOUCHSTART:
case PP_INPUTEVENT_TYPE_TOUCHMOVE:
case PP_INPUTEVENT_TYPE_TOUCHEND:
case PP_INPUTEVENT_TYPE_TOUCHCANCEL:
/* FIXME: Touch events */
break;
case PP_INPUTEVENT_TYPE_KEYDOWN:
SDL_SendKeyboardKey(SDL_PRESSED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
break;
case PP_INPUTEVENT_TYPE_KEYUP:
SDL_SendKeyboardKey(SDL_RELEASED, SDL_NACL_translate_keycode(driverdata->ppb_keyboard_input_event->GetKeyCode(event)));
break;
case PP_INPUTEVENT_TYPE_CHAR:
var = driverdata->ppb_keyboard_input_event->GetCharacterText(event);
str = driverdata->ppb_var->VarToUtf8(var, &str_len);
/* str is not null terminated! */
if ( str_len >= SDL_arraysize(text) ) {
str_len = SDL_arraysize(text) - 1;
}
SDL_strlcpy(text, str, str_len );
text[str_len] = '\0';
SDL_SendKeyboardText(text);
/* FIXME: Do we have to handle ref counting? driverdata->ppb_var->Release(var);*/
break;
default:
break;
}
break;
/* From HandleMessage, contains a PP_Var. */
case PSE_INSTANCE_HANDLEMESSAGE:
break;
/* From DidChangeFocus, contains a PP_Bool with the current focus state. */
case PSE_INSTANCE_DIDCHANGEFOCUS:
break;
/* When the 3D context is lost, no resource. */
case PSE_GRAPHICS3D_GRAPHICS3DCONTEXTLOST:
break;
/* When the mouse lock is lost. */
case PSE_MOUSELOCK_MOUSELOCKLOST:
break;
default:
break;
}
PSEventRelease(ps_event);
}
}
}
@@ -0,0 +1,30 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclevents_c_h
#define _SDL_naclevents_c_h
#include "SDL_naclvideo.h"
extern void NACL_PumpEvents(_THIS);
#endif /* _SDL_naclevents_c_h */
@@ -0,0 +1,24 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
#endif /* SDL_VIDEO_DRIVER_NACL */
@@ -0,0 +1,171 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
/* NaCl SDL video GLES 2 driver implementation */
#include "SDL_video.h"
#include "SDL_naclvideo.h"
#if SDL_LOADSO_DLOPEN
#include "dlfcn.h"
#endif
#include "ppapi/gles2/gl2ext_ppapi.h"
#include "ppapi_simple/ps.h"
/* GL functions */
int
NACL_GLES_LoadLibrary(_THIS, const char *path)
{
/* FIXME: Support dynamic linking when PNACL supports it */
return glInitializePPAPI(PSGetInterface) == 0;
}
void *
NACL_GLES_GetProcAddress(_THIS, const char *proc)
{
#if SDL_LOADSO_DLOPEN
return dlsym( 0 /* RTLD_DEFAULT */, proc);
#else
return NULL;
#endif
}
void
NACL_GLES_UnloadLibrary(_THIS)
{
/* FIXME: Support dynamic linking when PNACL supports it */
glTerminatePPAPI();
}
int
NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext sdl_context)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
/* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
driverdata->ppb_instance->BindGraphics(driverdata->instance, (PP_Resource) sdl_context);
glSetCurrentContextPPAPI((PP_Resource) sdl_context);
return 0;
}
SDL_GLContext
NACL_GLES_CreateContext(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
PP_Resource context, share_context = 0;
/* 64 seems nice. */
Sint32 attribs[64];
int i = 0;
if (_this->gl_config.share_with_current_context) {
share_context = (PP_Resource) SDL_GL_GetCurrentContext();
}
/* FIXME: Some ATTRIBS from PP_Graphics3DAttrib are not set here */
attribs[i++] = PP_GRAPHICS3DATTRIB_WIDTH;
attribs[i++] = window->w;
attribs[i++] = PP_GRAPHICS3DATTRIB_HEIGHT;
attribs[i++] = window->h;
attribs[i++] = PP_GRAPHICS3DATTRIB_RED_SIZE;
attribs[i++] = _this->gl_config.red_size;
attribs[i++] = PP_GRAPHICS3DATTRIB_GREEN_SIZE;
attribs[i++] = _this->gl_config.green_size;
attribs[i++] = PP_GRAPHICS3DATTRIB_BLUE_SIZE;
attribs[i++] = _this->gl_config.blue_size;
if (_this->gl_config.alpha_size) {
attribs[i++] = PP_GRAPHICS3DATTRIB_ALPHA_SIZE;
attribs[i++] = _this->gl_config.alpha_size;
}
/*if (_this->gl_config.buffer_size) {
attribs[i++] = EGL_BUFFER_SIZE;
attribs[i++] = _this->gl_config.buffer_size;
}*/
attribs[i++] = PP_GRAPHICS3DATTRIB_DEPTH_SIZE;
attribs[i++] = _this->gl_config.depth_size;
if (_this->gl_config.stencil_size) {
attribs[i++] = PP_GRAPHICS3DATTRIB_STENCIL_SIZE;
attribs[i++] = _this->gl_config.stencil_size;
}
if (_this->gl_config.multisamplebuffers) {
attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS;
attribs[i++] = _this->gl_config.multisamplebuffers;
}
if (_this->gl_config.multisamplesamples) {
attribs[i++] = PP_GRAPHICS3DATTRIB_SAMPLES;
attribs[i++] = _this->gl_config.multisamplesamples;
}
attribs[i++] = PP_GRAPHICS3DATTRIB_NONE;
context = driverdata->ppb_graphics->Create(driverdata->instance, share_context, attribs);
if (context) {
/* We need to make the context current, otherwise nothing works */
SDL_GL_MakeCurrent(window, (SDL_GLContext) context);
}
return (SDL_GLContext) context;
}
int
NACL_GLES_SetSwapInterval(_THIS, int interval)
{
/* STUB */
return 0;
}
int
NACL_GLES_GetSwapInterval(_THIS)
{
/* STUB */
return 0;
}
void
NACL_GLES_SwapWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
struct PP_CompletionCallback callback = { NULL, 0, PP_COMPLETIONCALLBACK_FLAG_NONE };
driverdata->ppb_graphics->SwapBuffers((PP_Resource) SDL_GL_GetCurrentContext(), callback );
}
void
NACL_GLES_DeleteContext(_THIS, SDL_GLContext context)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
driverdata->ppb_core->ReleaseResource((PP_Resource) context);
}
#endif /* SDL_VIDEO_DRIVER_NACL */
/* vi: set ts=4 sw=4 expandtab: */
@@ -0,0 +1,38 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclgl_h
#define _SDL_naclgl_h
extern int NACL_GLES_LoadLibrary(_THIS, const char *path);
extern void *NACL_GLES_GetProcAddress(_THIS, const char *proc);
extern void NACL_GLES_UnloadLibrary(_THIS);
extern SDL_GLContext NACL_GLES_CreateContext(_THIS, SDL_Window * window);
extern int NACL_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
extern int NACL_GLES_SetSwapInterval(_THIS, int interval);
extern int NACL_GLES_GetSwapInterval(_THIS);
extern void NACL_GLES_SwapWindow(_THIS, SDL_Window * window);
extern void NACL_GLES_DeleteContext(_THIS, SDL_GLContext context);
#endif /* _SDL_naclgl_h */
/* vi: set ts=4 sw=4 expandtab: */
@@ -0,0 +1,183 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi_simple/ps.h"
#include "ppapi_simple/ps_interface.h"
#include "ppapi_simple/ps_event.h"
#include "nacl_io/nacl_io.h"
#include "SDL_naclvideo.h"
#include "SDL_naclwindow.h"
#include "SDL_naclevents_c.h"
#include "SDL_naclopengles.h"
#include "SDL_video.h"
#include "../SDL_sysvideo.h"
#include "../../events/SDL_events_c.h"
#define NACLVID_DRIVER_NAME "nacl"
/* Static init required because NACL_SetScreenResolution
* may appear even before SDL starts and we want to remember
* the window width and height
*/
static SDL_VideoData nacl = {0};
void
NACL_SetScreenResolution(int width, int height, Uint32 format)
{
PP_Resource context;
nacl.w = width;
nacl.h = height;
nacl.format = format;
if (nacl.window) {
nacl.window->w = width;
nacl.window->h = height;
SDL_SendWindowEvent(nacl.window, SDL_WINDOWEVENT_RESIZED, width, height);
}
/* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
context = (PP_Resource) SDL_GL_GetCurrentContext();
if (context) {
PSInterfaceGraphics3D()->ResizeBuffers(context, width, height);
}
}
/* Initialization/Query functions */
static int NACL_VideoInit(_THIS);
static void NACL_VideoQuit(_THIS);
static int NACL_Available(void) {
return PSGetInstanceId() != 0;
}
static void NACL_DeleteDevice(SDL_VideoDevice *device) {
SDL_VideoData *driverdata = (SDL_VideoData*) device->driverdata;
driverdata->ppb_core->ReleaseResource((PP_Resource) driverdata->ppb_message_loop);
SDL_free(device->driverdata);
SDL_free(device);
}
static int
NACL_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
{
return 0;
}
static SDL_VideoDevice *NACL_CreateDevice(int devindex) {
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_OutOfMemory();
return NULL;
}
device->driverdata = &nacl;
/* Set the function pointers */
device->VideoInit = NACL_VideoInit;
device->VideoQuit = NACL_VideoQuit;
device->PumpEvents = NACL_PumpEvents;
device->CreateWindow = NACL_CreateWindow;
device->SetWindowTitle = NACL_SetWindowTitle;
device->DestroyWindow = NACL_DestroyWindow;
device->SetDisplayMode = NACL_SetDisplayMode;
device->free = NACL_DeleteDevice;
/* GL pointers */
device->GL_LoadLibrary = NACL_GLES_LoadLibrary;
device->GL_GetProcAddress = NACL_GLES_GetProcAddress;
device->GL_UnloadLibrary = NACL_GLES_UnloadLibrary;
device->GL_CreateContext = NACL_GLES_CreateContext;
device->GL_MakeCurrent = NACL_GLES_MakeCurrent;
device->GL_SetSwapInterval = NACL_GLES_SetSwapInterval;
device->GL_GetSwapInterval = NACL_GLES_GetSwapInterval;
device->GL_SwapWindow = NACL_GLES_SwapWindow;
device->GL_DeleteContext = NACL_GLES_DeleteContext;
return device;
}
VideoBootStrap NACL_bootstrap = {
NACLVID_DRIVER_NAME, "SDL Native Client Video Driver",
NACL_Available, NACL_CreateDevice
};
int NACL_VideoInit(_THIS) {
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayMode mode;
SDL_zero(mode);
mode.format = driverdata->format;
mode.w = driverdata->w;
mode.h = driverdata->h;
mode.refresh_rate = 0;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
}
SDL_AddDisplayMode(&_this->displays[0], &mode);
PSInterfaceInit();
driverdata->instance = PSGetInstanceId();
driverdata->ppb_graphics = PSInterfaceGraphics3D();
driverdata->ppb_message_loop = PSInterfaceMessageLoop();
driverdata->ppb_core = PSInterfaceCore();
driverdata->ppb_fullscreen = PSInterfaceFullscreen();
driverdata->ppb_instance = PSInterfaceInstance();
driverdata->ppb_image_data = PSInterfaceImageData();
driverdata->ppb_view = PSInterfaceView();
driverdata->ppb_var = PSInterfaceVar();
driverdata->ppb_input_event = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE);
driverdata->ppb_keyboard_input_event = (PPB_KeyboardInputEvent*) PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
driverdata->ppb_mouse_input_event = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE);
driverdata->ppb_wheel_input_event = (PPB_WheelInputEvent*) PSGetInterface(PPB_WHEEL_INPUT_EVENT_INTERFACE);
driverdata->ppb_touch_input_event = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE);
driverdata->message_loop = driverdata->ppb_message_loop->Create(driverdata->instance);
PSEventSetFilter(PSE_ALL);
/* We're done! */
return 0;
}
void NACL_VideoQuit(_THIS) {
}
#endif /* SDL_VIDEO_DRIVER_NACL */
/* vi: set ts=4 sw=4 expandtab: */
@@ -0,0 +1,67 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclvideo_h
#define _SDL_naclvideo_h
#include "../SDL_sysvideo.h"
#include "ppapi_simple/ps_interface.h"
#include "ppapi/c/pp_input_event.h"
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *_this
/* Private display data */
typedef struct SDL_VideoData {
Uint32 format;
int w, h;
SDL_Window *window;
const PPB_Graphics3D *ppb_graphics;
const PPB_MessageLoop *ppb_message_loop;
const PPB_Core *ppb_core;
const PPB_Fullscreen *ppb_fullscreen;
const PPB_Instance *ppb_instance;
const PPB_ImageData *ppb_image_data;
const PPB_View *ppb_view;
const PPB_Var *ppb_var;
const PPB_InputEvent *ppb_input_event;
const PPB_KeyboardInputEvent *ppb_keyboard_input_event;
const PPB_MouseInputEvent *ppb_mouse_input_event;
const PPB_WheelInputEvent *ppb_wheel_input_event;
const PPB_TouchInputEvent *ppb_touch_input_event;
PP_Resource message_loop;
PP_Instance instance;
/* FIXME: Check threading issues...otherwise use a hardcoded _this->context across all threads */
/* PP_Resource context; */
} SDL_VideoData;
extern void NACL_SetScreenResolution(int width, int height, Uint32 format);
#endif /* _SDL_naclvideo_h */
@@ -0,0 +1,79 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_NACL
#include "../SDL_sysvideo.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_keyboard_c.h"
#include "SDL_naclvideo.h"
#include "SDL_naclwindow.h"
int
NACL_CreateWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
if (driverdata->window) {
SDL_SetError("NaCl only supports one window");
return -1;
}
driverdata->window = window;
/* Adjust the window data to match the screen */
window->x = 0;
window->y = 0;
window->w = driverdata->w;
window->h = driverdata->h;
window->flags &= ~SDL_WINDOW_RESIZABLE; /* window is NEVER resizeable */
window->flags |= SDL_WINDOW_FULLSCREEN; /* window is always fullscreen */
window->flags &= ~SDL_WINDOW_HIDDEN;
window->flags |= SDL_WINDOW_SHOWN; /* only one window on NaCl */
window->flags |= SDL_WINDOW_INPUT_FOCUS; /* always has input focus */
window->flags |= SDL_WINDOW_OPENGL;
SDL_SetMouseFocus(window);
SDL_SetKeyboardFocus(window);
return 0;
}
void
NACL_SetWindowTitle(_THIS, SDL_Window * window)
{
/* TODO */
}
void
NACL_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_VideoData *driverdata = (SDL_VideoData *) _this->driverdata;
if (window == driverdata->window) {
driverdata->window = NULL;
}
}
#endif /* SDL_VIDEO_DRIVER_NACL */
/* vi: set ts=4 sw=4 expandtab: */
@@ -0,0 +1,32 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_naclwindow_h
#define _SDL_naclwindow_h
extern int NACL_CreateWindow(_THIS, SDL_Window * window);
extern void NACL_SetWindowTitle(_THIS, SDL_Window * window);
extern void NACL_DestroyWindow(_THIS, SDL_Window * window);
#endif /* _SDL_naclwindow_h */
/* vi: set ts=4 sw=4 expandtab: */