mirror of
https://github.com/love2d/love-android.git
synced 2026-08-17 19:24:07 +02:00
actual update to latest mobile-common
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
/* Program to load a wave file and loop playing it using SDL sound queueing */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
struct
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
Uint8 *sound; /* Pointer to wave data */
|
||||
Uint32 soundlen; /* Length of wave data */
|
||||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static int done = 0;
|
||||
void
|
||||
poked(int sig)
|
||||
{
|
||||
done = 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
char filename[4096];
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
SDL_strlcpy(filename, argv[1], sizeof(filename));
|
||||
} else {
|
||||
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
|
||||
}
|
||||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
wave.spec.callback = NULL; /* we'll push audio. */
|
||||
|
||||
#if HAVE_SIGNAL_H
|
||||
/* Set the signals */
|
||||
#ifdef SIGHUP
|
||||
signal(SIGHUP, poked);
|
||||
#endif
|
||||
signal(SIGINT, poked);
|
||||
#ifdef SIGQUIT
|
||||
signal(SIGQUIT, poked);
|
||||
#endif
|
||||
signal(SIGTERM, poked);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Initialize fillerup() variables */
|
||||
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_FreeWAV(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/*static x[99999]; SDL_QueueAudio(1, x, sizeof (x));*/
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
/* Note that we stuff the entire audio buffer into the queue in one
|
||||
shot. Most apps would want to feed it a little at a time, as it
|
||||
plays, but we're going for simplicity here. */
|
||||
|
||||
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
|
||||
{
|
||||
/* The device from SDL_OpenAudio() is always device #1. */
|
||||
const Uint32 queued = SDL_GetQueuedAudioSize(1);
|
||||
SDL_Log("Device has %u bytes queued.\n", (unsigned int) queued);
|
||||
if (queued <= 8192) { /* time to requeue the whole thing? */
|
||||
if (SDL_QueueAudio(1, wave.sound, wave.soundlen) == 0) {
|
||||
SDL_Log("Device queued %u more bytes.\n", (unsigned int) wave.soundlen);
|
||||
} else {
|
||||
SDL_Log("Device FAILED to queue %u more bytes: %s\n", (unsigned int) wave.soundlen, SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(100); /* let it play for awhile. */
|
||||
}
|
||||
|
||||
/* Clean up on signal */
|
||||
SDL_CloseAudio();
|
||||
SDL_FreeWAV(wave.sound);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -0,0 +1,63 @@
|
||||
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# GNU Makefile based on shared rules provided by the Native Client SDK.
|
||||
# See README.Makefiles for more details.
|
||||
|
||||
VALID_TOOLCHAINS := pnacl
|
||||
|
||||
# NACL_SDK_ROOT ?= $(abspath $(CURDIR)/../../..)
|
||||
include $(NACL_SDK_ROOT)/tools/common.mk
|
||||
|
||||
|
||||
TARGET = sdl_app
|
||||
DEPS = ppapi_simple nacl_io
|
||||
# ppapi_simple and SDL2 end up being listed twice due to dependency solving issues -- Gabriel
|
||||
LIBS = SDL2_test SDL2 ppapi_simple SDL2main SDL2 $(DEPS) ppapi_gles2 ppapi_cpp ppapi pthread
|
||||
|
||||
CFLAGS := -Wall
|
||||
SOURCES ?= testgles2.c
|
||||
|
||||
# Build rules generated by macros from common.mk:
|
||||
# Overriden macro from NACL SDK to be able to customize the library search path -- Gabriel
|
||||
# Specific Link Macro
|
||||
#
|
||||
# $1 = Target Name
|
||||
# $2 = List of inputs
|
||||
# $3 = List of libs
|
||||
# $4 = List of deps
|
||||
# $5 = List of lib dirs
|
||||
# $6 = Other Linker Args
|
||||
#
|
||||
# For debugging, we translate the pre-finalized .bc file.
|
||||
#
|
||||
define LINKER_RULE
|
||||
all: $(1).pexe
|
||||
$(1)_x86_32.nexe : $(1).bc
|
||||
$(call LOG,TRANSLATE,$$@,$(PNACL_TRANSLATE) --allow-llvm-bitcode-input -arch x86-32 $$^ -o $$@)
|
||||
|
||||
$(1)_x86_64.nexe : $(1).bc
|
||||
$(call LOG,TRANSLATE,$$@,$(PNACL_TRANSLATE) --allow-llvm-bitcode-input -arch x86-64 $$^ -o $$@)
|
||||
|
||||
$(1)_arm.nexe : $(1).bc
|
||||
$(call LOG,TRANSLATE,$$@,$(PNACL_TRANSLATE) --allow-llvm-bitcode-input -arch arm $$^ -o $$@)
|
||||
|
||||
$(1).pexe: $(1).bc
|
||||
$(call LOG,FINALIZE,$$@,$(PNACL_FINALIZE) -o $$@ $$^)
|
||||
|
||||
$(1).bc: $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp)
|
||||
$(call LOG,LINK,$$@,$(PNACL_LINK) -o $$@ $(2) $(PNACL_LDFLAGS) $(foreach path,$(5),-L$(path)/pnacl/$(CONFIG)) -L./lib $(foreach lib,$(3),-l$(lib)) $(6))
|
||||
endef
|
||||
|
||||
$(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
|
||||
$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
|
||||
|
||||
ifeq ($(CONFIG),Release)
|
||||
$(eval $(call LINK_RULE,$(TARGET)_unstripped,$(SOURCES),$(LIBS),$(DEPS)))
|
||||
$(eval $(call STRIP_RULE,$(TARGET),$(TARGET)_unstripped))
|
||||
else
|
||||
$(eval $(call LINK_RULE,$(TARGET),$(SOURCES),$(LIBS),$(DEPS)))
|
||||
endif
|
||||
|
||||
$(eval $(call NMF_RULE,$(TARGET),))
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
function makeURL(toolchain, config) {
|
||||
return 'index.html?tc=' + toolchain + '&config=' + config;
|
||||
}
|
||||
|
||||
function createWindow(url) {
|
||||
console.log('loading ' + url);
|
||||
chrome.app.window.create(url, {
|
||||
width: 1024,
|
||||
height: 800,
|
||||
frame: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
function onLaunched(launchData) {
|
||||
// Send and XHR to get the URL to load from a configuration file.
|
||||
// Normally you won't need to do this; just call:
|
||||
//
|
||||
// chrome.app.window.create('<your url>', {...});
|
||||
//
|
||||
// In the SDK we want to be able to load different URLs (for different
|
||||
// toolchain/config combinations) from the commandline, so we to read
|
||||
// this information from the file "run_package_config".
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'run_package_config', true);
|
||||
xhr.onload = function() {
|
||||
var toolchain_config = this.responseText.split(' ');
|
||||
createWindow(makeURL.apply(null, toolchain_config));
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
// Can't find the config file, just load the default.
|
||||
createWindow('index.html');
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
chrome.app.runtime.onLaunched.addListener(onLaunched);
|
||||
@@ -0,0 +1,469 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Set to true when the Document is loaded IFF "test=true" is in the query
|
||||
// string.
|
||||
var isTest = false;
|
||||
|
||||
// Set to true when loading a "Release" NaCl module, false when loading a
|
||||
// "Debug" NaCl module.
|
||||
var isRelease = true;
|
||||
|
||||
// Javascript module pattern:
|
||||
// see http://en.wikipedia.org/wiki/Unobtrusive_JavaScript#Namespaces
|
||||
// In essence, we define an anonymous function which is immediately called and
|
||||
// returns a new object. The new object contains only the exported definitions;
|
||||
// all other definitions in the anonymous function are inaccessible to external
|
||||
// code.
|
||||
var common = (function() {
|
||||
|
||||
function isHostToolchain(tool) {
|
||||
return tool == 'win' || tool == 'linux' || tool == 'mac';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mime type for NaCl plugin.
|
||||
*
|
||||
* @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
|
||||
* @return {string} The mime-type for the kind of NaCl plugin matching
|
||||
* the given toolchain.
|
||||
*/
|
||||
function mimeTypeForTool(tool) {
|
||||
// For NaCl modules use application/x-nacl.
|
||||
var mimetype = 'application/x-nacl';
|
||||
if (isHostToolchain(tool)) {
|
||||
// For non-NaCl PPAPI plugins use the x-ppapi-debug/release
|
||||
// mime type.
|
||||
if (isRelease)
|
||||
mimetype = 'application/x-ppapi-release';
|
||||
else
|
||||
mimetype = 'application/x-ppapi-debug';
|
||||
} else if (tool == 'pnacl' && isRelease) {
|
||||
mimetype = 'application/x-pnacl';
|
||||
}
|
||||
return mimetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the browser supports NaCl plugins.
|
||||
*
|
||||
* @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
|
||||
* @return {bool} True if the browser supports the type of NaCl plugin
|
||||
* produced by the given toolchain.
|
||||
*/
|
||||
function browserSupportsNaCl(tool) {
|
||||
// Assume host toolchains always work with the given browser.
|
||||
// The below mime-type checking might not work with
|
||||
// --register-pepper-plugins.
|
||||
if (isHostToolchain(tool)) {
|
||||
return true;
|
||||
}
|
||||
var mimetype = mimeTypeForTool(tool);
|
||||
return navigator.mimeTypes[mimetype] !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject a script into the DOM, and call a callback when it is loaded.
|
||||
*
|
||||
* @param {string} url The url of the script to load.
|
||||
* @param {Function} onload The callback to call when the script is loaded.
|
||||
* @param {Function} onerror The callback to call if the script fails to load.
|
||||
*/
|
||||
function injectScript(url, onload, onerror) {
|
||||
var scriptEl = document.createElement('script');
|
||||
scriptEl.type = 'text/javascript';
|
||||
scriptEl.src = url;
|
||||
scriptEl.onload = onload;
|
||||
if (onerror) {
|
||||
scriptEl.addEventListener('error', onerror, false);
|
||||
}
|
||||
document.head.appendChild(scriptEl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all tests for this example.
|
||||
*
|
||||
* @param {Object} moduleEl The module DOM element.
|
||||
*/
|
||||
function runTests(moduleEl) {
|
||||
console.log('runTests()');
|
||||
common.tester = new Tester();
|
||||
|
||||
// All NaCl SDK examples are OK if the example exits cleanly; (i.e. the
|
||||
// NaCl module returns 0 or calls exit(0)).
|
||||
//
|
||||
// Without this exception, the browser_tester thinks that the module
|
||||
// has crashed.
|
||||
common.tester.exitCleanlyIsOK();
|
||||
|
||||
common.tester.addAsyncTest('loaded', function(test) {
|
||||
test.pass();
|
||||
});
|
||||
|
||||
if (typeof window.addTests !== 'undefined') {
|
||||
window.addTests();
|
||||
}
|
||||
|
||||
common.tester.waitFor(moduleEl);
|
||||
common.tester.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Native Client <embed> element as a child of the DOM element
|
||||
* named "listener".
|
||||
*
|
||||
* @param {string} name The name of the example.
|
||||
* @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
|
||||
* @param {string} path Directory name where .nmf file can be found.
|
||||
* @param {number} width The width to create the plugin.
|
||||
* @param {number} height The height to create the plugin.
|
||||
* @param {Object} attrs Dictionary of attributes to set on the module.
|
||||
*/
|
||||
function createNaClModule(name, tool, path, width, height, attrs) {
|
||||
var moduleEl = document.createElement('embed');
|
||||
moduleEl.setAttribute('name', 'nacl_module');
|
||||
moduleEl.setAttribute('id', 'nacl_module');
|
||||
moduleEl.setAttribute('width', width);
|
||||
moduleEl.setAttribute('height', height);
|
||||
moduleEl.setAttribute('path', path);
|
||||
moduleEl.setAttribute('src', path + '/' + name + '.nmf');
|
||||
|
||||
// Add any optional arguments
|
||||
if (attrs) {
|
||||
for (var key in attrs) {
|
||||
moduleEl.setAttribute(key, attrs[key]);
|
||||
}
|
||||
}
|
||||
|
||||
var mimetype = mimeTypeForTool(tool);
|
||||
moduleEl.setAttribute('type', mimetype);
|
||||
|
||||
// The <EMBED> element is wrapped inside a <DIV>, which has both a 'load'
|
||||
// and a 'message' event listener attached. This wrapping method is used
|
||||
// instead of attaching the event listeners directly to the <EMBED> element
|
||||
// to ensure that the listeners are active before the NaCl module 'load'
|
||||
// event fires.
|
||||
var listenerDiv = document.getElementById('listener');
|
||||
listenerDiv.appendChild(moduleEl);
|
||||
|
||||
// Host plugins don't send a moduleDidLoad message. We'll fake it here.
|
||||
var isHost = isHostToolchain(tool);
|
||||
if (isHost) {
|
||||
window.setTimeout(function() {
|
||||
moduleEl.readyState = 1;
|
||||
moduleEl.dispatchEvent(new CustomEvent('loadstart'));
|
||||
moduleEl.readyState = 4;
|
||||
moduleEl.dispatchEvent(new CustomEvent('load'));
|
||||
moduleEl.dispatchEvent(new CustomEvent('loadend'));
|
||||
}, 100); // 100 ms
|
||||
}
|
||||
|
||||
// This is code that is only used to test the SDK.
|
||||
if (isTest) {
|
||||
var loadNaClTest = function() {
|
||||
injectScript('nacltest.js', function() {
|
||||
runTests(moduleEl);
|
||||
});
|
||||
};
|
||||
|
||||
// Try to load test.js for the example. Whether or not it exists, load
|
||||
// nacltest.js.
|
||||
injectScript('test.js', loadNaClTest, loadNaClTest);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the default "load" and "message" event listeners to the element with
|
||||
* id "listener".
|
||||
*
|
||||
* The "load" event is sent when the module is successfully loaded. The
|
||||
* "message" event is sent when the naclModule posts a message using
|
||||
* PPB_Messaging.PostMessage() (in C) or pp::Instance().PostMessage() (in
|
||||
* C++).
|
||||
*/
|
||||
function attachDefaultListeners() {
|
||||
var listenerDiv = document.getElementById('listener');
|
||||
listenerDiv.addEventListener('load', moduleDidLoad, true);
|
||||
listenerDiv.addEventListener('message', handleMessage, true);
|
||||
listenerDiv.addEventListener('error', handleError, true);
|
||||
listenerDiv.addEventListener('crash', handleCrash, true);
|
||||
if (typeof window.attachListeners !== 'undefined') {
|
||||
window.attachListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the NaCl module fails to load.
|
||||
*
|
||||
* This event listener is registered in createNaClModule above.
|
||||
*/
|
||||
function handleError(event) {
|
||||
// We can't use common.naclModule yet because the module has not been
|
||||
// loaded.
|
||||
var moduleEl = document.getElementById('nacl_module');
|
||||
updateStatus('ERROR [' + moduleEl.lastError + ']');
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Browser can not communicate with the Module
|
||||
*
|
||||
* This event listener is registered in attachDefaultListeners above.
|
||||
*/
|
||||
function handleCrash(event) {
|
||||
if (common.naclModule.exitStatus == -1) {
|
||||
updateStatus('CRASHED');
|
||||
} else {
|
||||
updateStatus('EXITED [' + common.naclModule.exitStatus + ']');
|
||||
}
|
||||
if (typeof window.handleCrash !== 'undefined') {
|
||||
window.handleCrash(common.naclModule.lastError);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the NaCl module is loaded.
|
||||
*
|
||||
* This event listener is registered in attachDefaultListeners above.
|
||||
*/
|
||||
function moduleDidLoad() {
|
||||
common.naclModule = document.getElementById('nacl_module');
|
||||
updateStatus('RUNNING');
|
||||
|
||||
if (typeof window.moduleDidLoad !== 'undefined') {
|
||||
window.moduleDidLoad();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the NaCl module's embed element.
|
||||
*
|
||||
* We don't want to hide by default; if we do, it is harder to determine that
|
||||
* a plugin failed to load. Instead, call this function inside the example's
|
||||
* "moduleDidLoad" function.
|
||||
*
|
||||
*/
|
||||
function hideModule() {
|
||||
// Setting common.naclModule.style.display = "None" doesn't work; the
|
||||
// module will no longer be able to receive postMessages.
|
||||
common.naclModule.style.height = '0';
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the NaCl module from the page.
|
||||
*/
|
||||
function removeModule() {
|
||||
common.naclModule.parentNode.removeChild(common.naclModule);
|
||||
common.naclModule = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true when |s| starts with the string |prefix|.
|
||||
*
|
||||
* @param {string} s The string to search.
|
||||
* @param {string} prefix The prefix to search for in |s|.
|
||||
*/
|
||||
function startsWith(s, prefix) {
|
||||
// indexOf would search the entire string, lastIndexOf(p, 0) only checks at
|
||||
// the first index. See: http://stackoverflow.com/a/4579228
|
||||
return s.lastIndexOf(prefix, 0) === 0;
|
||||
}
|
||||
|
||||
/** Maximum length of logMessageArray. */
|
||||
var kMaxLogMessageLength = 20;
|
||||
|
||||
/** An array of messages to display in the element with id "log". */
|
||||
var logMessageArray = [];
|
||||
|
||||
/**
|
||||
* Add a message to an element with id "log".
|
||||
*
|
||||
* This function is used by the default "log:" message handler.
|
||||
*
|
||||
* @param {string} message The message to log.
|
||||
*/
|
||||
function logMessage(message) {
|
||||
logMessageArray.push(message);
|
||||
if (logMessageArray.length > kMaxLogMessageLength)
|
||||
logMessageArray.shift();
|
||||
|
||||
document.getElementById('log').textContent = logMessageArray.join('\n');
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
var defaultMessageTypes = {
|
||||
'alert': alert,
|
||||
'log': logMessage
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the NaCl module sends a message to JavaScript (via
|
||||
* PPB_Messaging.PostMessage())
|
||||
*
|
||||
* This event listener is registered in createNaClModule above.
|
||||
*
|
||||
* @param {Event} message_event A message event. message_event.data contains
|
||||
* the data sent from the NaCl module.
|
||||
*/
|
||||
function handleMessage(message_event) {
|
||||
if (typeof message_event.data === 'string') {
|
||||
for (var type in defaultMessageTypes) {
|
||||
if (defaultMessageTypes.hasOwnProperty(type)) {
|
||||
if (startsWith(message_event.data, type + ':')) {
|
||||
func = defaultMessageTypes[type];
|
||||
func(message_event.data.slice(type.length + 1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window.handleMessage !== 'undefined') {
|
||||
window.handleMessage(message_event);
|
||||
return;
|
||||
}
|
||||
|
||||
logMessage('Unhandled message: ' + message_event.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the DOM content has loaded; i.e. the page's document is fully
|
||||
* parsed. At this point, we can safely query any elements in the document via
|
||||
* document.querySelector, document.getElementById, etc.
|
||||
*
|
||||
* @param {string} name The name of the example.
|
||||
* @param {string} tool The name of the toolchain, e.g. "glibc", "newlib" etc.
|
||||
* @param {string} path Directory name where .nmf file can be found.
|
||||
* @param {number} width The width to create the plugin.
|
||||
* @param {number} height The height to create the plugin.
|
||||
* @param {Object} attrs Optional dictionary of additional attributes.
|
||||
*/
|
||||
function domContentLoaded(name, tool, path, width, height, attrs) {
|
||||
// If the page loads before the Native Client module loads, then set the
|
||||
// status message indicating that the module is still loading. Otherwise,
|
||||
// do not change the status message.
|
||||
updateStatus('Page loaded.');
|
||||
if (!browserSupportsNaCl(tool)) {
|
||||
updateStatus(
|
||||
'Browser does not support NaCl (' + tool + '), or NaCl is disabled');
|
||||
} else if (common.naclModule == null) {
|
||||
updateStatus('Creating embed: ' + tool);
|
||||
|
||||
// We use a non-zero sized embed to give Chrome space to place the bad
|
||||
// plug-in graphic, if there is a problem.
|
||||
width = typeof width !== 'undefined' ? width : 200;
|
||||
height = typeof height !== 'undefined' ? height : 200;
|
||||
attachDefaultListeners();
|
||||
createNaClModule(name, tool, path, width, height, attrs);
|
||||
} else {
|
||||
// It's possible that the Native Client module onload event fired
|
||||
// before the page's onload event. In this case, the status message
|
||||
// will reflect 'SUCCESS', but won't be displayed. This call will
|
||||
// display the current message.
|
||||
updateStatus('Waiting.');
|
||||
}
|
||||
}
|
||||
|
||||
/** Saved text to display in the element with id 'statusField'. */
|
||||
var statusText = 'NO-STATUSES';
|
||||
|
||||
/**
|
||||
* Set the global status message. If the element with id 'statusField'
|
||||
* exists, then set its HTML to the status message as well.
|
||||
*
|
||||
* @param {string} opt_message The message to set. If null or undefined, then
|
||||
* set element 'statusField' to the message from the last call to
|
||||
* updateStatus.
|
||||
*/
|
||||
function updateStatus(opt_message) {
|
||||
if (opt_message) {
|
||||
statusText = opt_message;
|
||||
}
|
||||
var statusField = document.getElementById('statusField');
|
||||
if (statusField) {
|
||||
statusField.innerHTML = statusText;
|
||||
}
|
||||
}
|
||||
|
||||
// The symbols to export.
|
||||
return {
|
||||
/** A reference to the NaCl module, once it is loaded. */
|
||||
naclModule: null,
|
||||
|
||||
attachDefaultListeners: attachDefaultListeners,
|
||||
domContentLoaded: domContentLoaded,
|
||||
createNaClModule: createNaClModule,
|
||||
hideModule: hideModule,
|
||||
removeModule: removeModule,
|
||||
logMessage: logMessage,
|
||||
updateStatus: updateStatus
|
||||
};
|
||||
|
||||
}());
|
||||
|
||||
// Listen for the DOM content to be loaded. This event is fired when parsing of
|
||||
// the page's document has finished.
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var body = document.body;
|
||||
|
||||
// The data-* attributes on the body can be referenced via body.dataset.
|
||||
if (body.dataset) {
|
||||
var loadFunction;
|
||||
if (!body.dataset.customLoad) {
|
||||
loadFunction = common.domContentLoaded;
|
||||
} else if (typeof window.domContentLoaded !== 'undefined') {
|
||||
loadFunction = window.domContentLoaded;
|
||||
}
|
||||
|
||||
// From https://developer.mozilla.org/en-US/docs/DOM/window.location
|
||||
var searchVars = {};
|
||||
if (window.location.search.length > 1) {
|
||||
var pairs = window.location.search.substr(1).split('&');
|
||||
for (var key_ix = 0; key_ix < pairs.length; key_ix++) {
|
||||
var keyValue = pairs[key_ix].split('=');
|
||||
searchVars[unescape(keyValue[0])] =
|
||||
keyValue.length > 1 ? unescape(keyValue[1]) : '';
|
||||
}
|
||||
}
|
||||
|
||||
if (loadFunction) {
|
||||
var toolchains = body.dataset.tools.split(' ');
|
||||
var configs = body.dataset.configs.split(' ');
|
||||
|
||||
var attrs = {};
|
||||
if (body.dataset.attrs) {
|
||||
var attr_list = body.dataset.attrs.split(' ');
|
||||
for (var key in attr_list) {
|
||||
var attr = attr_list[key].split('=');
|
||||
var key = attr[0];
|
||||
var value = attr[1];
|
||||
attrs[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
var tc = toolchains.indexOf(searchVars.tc) !== -1 ?
|
||||
searchVars.tc : toolchains[0];
|
||||
|
||||
// If the config value is included in the search vars, use that.
|
||||
// Otherwise default to Release if it is valid, or the first value if
|
||||
// Release is not valid.
|
||||
if (configs.indexOf(searchVars.config) !== -1)
|
||||
var config = searchVars.config;
|
||||
else if (configs.indexOf('Release') !== -1)
|
||||
var config = 'Release';
|
||||
else
|
||||
var config = configs[0];
|
||||
|
||||
var pathFormat = body.dataset.path;
|
||||
var path = pathFormat.replace('{tc}', tc).replace('{config}', config);
|
||||
|
||||
isTest = searchVars.test === 'true';
|
||||
isRelease = path.toLowerCase().indexOf('release') != -1;
|
||||
|
||||
loadFunction(body.dataset.name, tc, path, body.dataset.width,
|
||||
body.dataset.height, attrs);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
Use of this source code is governed by a BSD-style license that can be
|
||||
found in the LICENSE file.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Expires" content="-1">
|
||||
<title>SDL NACL Test</title>
|
||||
<script type="text/javascript" src="common.js"></script>
|
||||
</head>
|
||||
<body data-width="640" data-height="640" data-name="sdl_app" data-tools="pnacl" data-configs="Debug Release" data-path="{tc}/{config}">
|
||||
<h1>SDL NACL Test</h1>
|
||||
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
|
||||
<!-- The NaCl plugin will be embedded inside the element with id "listener".
|
||||
See common.js.-->
|
||||
<div id="listener"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "SDL testgles2",
|
||||
"version": "33.0.1750.117",
|
||||
"minimum_chrome_version": "33.0.1750.117",
|
||||
"manifest_version": 2,
|
||||
"description": "testgles2",
|
||||
"offline_enabled": true,
|
||||
"icons": {
|
||||
"128": "icon128.png"
|
||||
},
|
||||
"app": {
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
}
|
||||
},
|
||||
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMN716Qyu0l2EHNFqIJVqVysFcTR6urqhaGGqW4UK7slBaURz9+Sb1b4Ot5P1uQNE5c+CTU5Vu61wpqmSqMMxqHLWdPPMh8uRlyctsb2cxWwG6XoGSvpX29NsQVUFXd4v2tkJm3G9t+V0X8TYskrvWQmnyOW8OEIDvrBhUEfFxWQIDAQAB",
|
||||
"oauth2": {
|
||||
"client_id": "903965034255.apps.googleusercontent.com",
|
||||
"scopes": ["https://www.googleapis.com/auth/drive"]
|
||||
},
|
||||
"permissions": []
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/**
|
||||
* Hints test suite
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_test.h"
|
||||
|
||||
|
||||
const int _numHintsEnum = 25;
|
||||
char* _HintsEnum[] =
|
||||
{
|
||||
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
|
||||
SDL_HINT_FRAMEBUFFER_ACCELERATION,
|
||||
SDL_HINT_GAMECONTROLLERCONFIG,
|
||||
SDL_HINT_GRAB_KEYBOARD,
|
||||
SDL_HINT_IDLE_TIMER_DISABLED,
|
||||
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
|
||||
SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
|
||||
SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
|
||||
SDL_HINT_ORIENTATIONS,
|
||||
SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
|
||||
SDL_HINT_RENDER_DRIVER,
|
||||
SDL_HINT_RENDER_OPENGL_SHADERS,
|
||||
SDL_HINT_RENDER_SCALE_QUALITY,
|
||||
SDL_HINT_RENDER_VSYNC,
|
||||
SDL_HINT_TIMER_RESOLUTION,
|
||||
SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
|
||||
SDL_HINT_VIDEO_HIGHDPI_DISABLED,
|
||||
SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
|
||||
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
|
||||
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
|
||||
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
|
||||
SDL_HINT_VIDEO_X11_XINERAMA,
|
||||
SDL_HINT_VIDEO_X11_XRANDR,
|
||||
SDL_HINT_VIDEO_X11_XVIDMODE,
|
||||
SDL_HINT_XINPUT_ENABLED,
|
||||
};
|
||||
char* _HintsVerbose[] =
|
||||
{
|
||||
"SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
|
||||
"SDL_HINT_FRAMEBUFFER_ACCELERATION",
|
||||
"SDL_HINT_GAMECONTROLLERCONFIG",
|
||||
"SDL_HINT_GRAB_KEYBOARD",
|
||||
"SDL_HINT_IDLE_TIMER_DISABLED",
|
||||
"SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
|
||||
"SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
|
||||
"SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
|
||||
"SDL_HINT_ORIENTATIONS",
|
||||
"SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
|
||||
"SDL_HINT_RENDER_DRIVER",
|
||||
"SDL_HINT_RENDER_OPENGL_SHADERS",
|
||||
"SDL_HINT_RENDER_SCALE_QUALITY",
|
||||
"SDL_HINT_RENDER_VSYNC",
|
||||
"SDL_HINT_TIMER_RESOLUTION",
|
||||
"SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
|
||||
"SDL_HINT_VIDEO_HIGHDPI_DISABLED",
|
||||
"SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
|
||||
"SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
|
||||
"SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
|
||||
"SDL_HINT_VIDEO_WIN_D3DCOMPILER",
|
||||
"SDL_HINT_VIDEO_X11_XINERAMA",
|
||||
"SDL_HINT_VIDEO_X11_XRANDR",
|
||||
"SDL_HINT_VIDEO_X11_XVIDMODE",
|
||||
"SDL_HINT_XINPUT_ENABLED"
|
||||
};
|
||||
|
||||
|
||||
/* Test case functions */
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_GetHint
|
||||
*/
|
||||
int
|
||||
hints_getHint(void *arg)
|
||||
{
|
||||
char *result1;
|
||||
char *result2;
|
||||
int i;
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
|
||||
result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
|
||||
"Verify returned values are equal; got: result1='%s' result2='%s",
|
||||
(result1 == NULL) ? "null" : result1,
|
||||
(result2 == NULL) ? "null" : result2);
|
||||
}
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Call to SDL_SetHint
|
||||
*/
|
||||
int
|
||||
hints_setHint(void *arg)
|
||||
{
|
||||
char *originalValue;
|
||||
char *value;
|
||||
char *testValue;
|
||||
SDL_bool result;
|
||||
int i, j;
|
||||
|
||||
/* Create random values to set */
|
||||
value = SDLTest_RandomAsciiStringOfSize(10);
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
/* Capture current value */
|
||||
originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
|
||||
|
||||
/* Set value (twice) */
|
||||
for (j=1; j<=2; j++) {
|
||||
result = SDL_SetHint((char*)_HintsEnum[i], value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(SDL_strcmp(value, testValue) == 0),
|
||||
"Verify returned value equals set value; got: testValue='%s' value='%s",
|
||||
(testValue == NULL) ? "null" : testValue,
|
||||
value);
|
||||
}
|
||||
|
||||
/* Reset original value */
|
||||
result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
}
|
||||
|
||||
SDL_free(value);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Hints test cases */
|
||||
static const SDLTest_TestCaseReference hintsTest1 =
|
||||
{ (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference hintsTest2 =
|
||||
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
|
||||
|
||||
/* Sequence of Hints test cases */
|
||||
static const SDLTest_TestCaseReference *hintsTests[] = {
|
||||
&hintsTest1, &hintsTest2, NULL
|
||||
};
|
||||
|
||||
/* Hints test suite (global) */
|
||||
SDLTest_TestSuiteReference hintsTestSuite = {
|
||||
"Hints",
|
||||
NULL,
|
||||
hintsTests,
|
||||
NULL
|
||||
};
|
||||
@@ -0,0 +1,134 @@
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
/* !!! FIXME: rewrite this to be wired in to test framework. */
|
||||
|
||||
#define RESIZE_BORDER 20
|
||||
|
||||
const SDL_Rect drag_areas[] = {
|
||||
{ 20, 20, 100, 100 },
|
||||
{ 200, 70, 100, 100 },
|
||||
{ 400, 90, 100, 100 }
|
||||
};
|
||||
|
||||
static const SDL_Rect *areas = drag_areas;
|
||||
static int numareas = SDL_arraysize(drag_areas);
|
||||
|
||||
static SDL_HitTestResult
|
||||
hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
|
||||
{
|
||||
int i;
|
||||
int w, h;
|
||||
|
||||
for (i = 0; i < numareas; i++) {
|
||||
if (SDL_PointInRect(pt, &areas[i])) {
|
||||
SDL_Log("HIT-TEST: DRAGGABLE\n");
|
||||
return SDL_HITTEST_DRAGGABLE;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
|
||||
#define REPORT_RESIZE_HIT(name) { \
|
||||
SDL_Log("HIT-TEST: RESIZE_" #name "\n"); \
|
||||
return SDL_HITTEST_RESIZE_##name; \
|
||||
}
|
||||
|
||||
if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(TOPLEFT);
|
||||
} else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(TOP);
|
||||
} else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(TOPRIGHT);
|
||||
} else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(RIGHT);
|
||||
} else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(BOTTOMRIGHT);
|
||||
} else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(BOTTOM);
|
||||
} else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(BOTTOMLEFT);
|
||||
} else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) {
|
||||
REPORT_RESIZE_HIT(LEFT);
|
||||
}
|
||||
|
||||
SDL_Log("HIT-TEST: NORMAL\n");
|
||||
return SDL_HITTEST_NORMAL;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int done = 0;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* !!! FIXME: check for errors. */
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
window = SDL_CreateWindow("Drag the red boxes", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE);
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
|
||||
if (SDL_SetWindowHitTest(window, hitTest, NULL) == -1) {
|
||||
SDL_Log("Enabling hit-testing failed!\n");
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!done)
|
||||
{
|
||||
SDL_Event e;
|
||||
int nothing_to_do = 1;
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 127, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
SDL_RenderFillRects(renderer, areas, SDL_arraysize(drag_areas));
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
while (SDL_PollEvent(&e)) {
|
||||
nothing_to_do = 0;
|
||||
|
||||
switch (e.type)
|
||||
{
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
SDL_Log("button down!\n");
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
SDL_Log("button up!\n");
|
||||
break;
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
if (e.window.event == SDL_WINDOWEVENT_MOVED) {
|
||||
SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
} else if (e.key.keysym.sym == SDLK_x) {
|
||||
if (!areas) {
|
||||
areas = drag_areas;
|
||||
numareas = SDL_arraysize(drag_areas);
|
||||
} else {
|
||||
areas = NULL;
|
||||
numareas = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (nothing_to_do) {
|
||||
SDL_Delay(50);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user