aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc21
-rw-r--r--src/library_sdl.js36
-rw-r--r--src/shell.html24
-rw-r--r--tests/sdl_canvas.c8
-rw-r--r--tests/sdl_mouse.c2
-rw-r--r--tools/shared.py4
6 files changed, 56 insertions, 39 deletions
diff --git a/emcc b/emcc
index 044347b7..7e81f830 100755
--- a/emcc
+++ b/emcc
@@ -74,7 +74,7 @@ emcc can be influenced by a few environment variables:
EMMAKEN_COMPILER - The compiler to be used, if you don't want the default clang.
'''
-import os, sys, shutil, tempfile, subprocess
+import os, sys, shutil, tempfile, subprocess, shlex
from subprocess import PIPE, STDOUT
from tools import shared
@@ -174,6 +174,12 @@ Options that are modified or new in %s include:
2: -O2 LLVM optimizations
3: -O3 LLVM optimizations (default in -O2+)
+ --llvm-lto <level> 0: No LLVM LTO (default in -O0)
+ 1: LLVM LTO (default in -O1+)
+ Note: If LLVM optimizations are not run
+ (see --llvm-opts), setting this to 1 has no
+ effect.
+
--closure <on> 0: No closure compiler (default in -O0, -O1)
1: Run closure compiler (default in -O2, -O3)
@@ -307,7 +313,7 @@ if os.environ.get('EMMAKEN_CXX'):
CC_ADDITIONAL_ARGS = shared.COMPILER_OPTS # + ['-g']?
EMMAKEN_CFLAGS = os.environ.get('EMMAKEN_CFLAGS')
-if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += EMMAKEN_CFLAGS.split(' ')
+if EMMAKEN_CFLAGS: CC_ADDITIONAL_ARGS += shlex.split(EMMAKEN_CFLAGS)
# ---------------- Utilities ---------------
@@ -401,6 +407,7 @@ try:
opt_level = 0
llvm_opts = None
+ llvm_lto = None
closure = None
js_transform = None
pre_js = None
@@ -427,6 +434,11 @@ try:
llvm_opts = eval(newargs[i+1])
newargs[i] = ''
newargs[i+1] = ''
+ elif newargs[i].startswith('--llvm-lto'):
+ check_bad_eq(newargs[i])
+ llvm_lto = eval(newargs[i+1])
+ newargs[i] = ''
+ newargs[i+1] = ''
elif newargs[i].startswith('--closure'):
check_bad_eq(newargs[i])
closure = int(newargs[i+1])
@@ -491,6 +503,7 @@ try:
newargs = [ arg for arg in newargs if arg is not '' ]
if llvm_opts is None: llvm_opts = LLVM_OPT_LEVEL[opt_level]
+ if llvm_lto is None: llvm_lto = llvm_opts > 0
if closure is None: closure = 1 if opt_level >= 2 else 0
if minify_whitespace is None:
minify_whitespace = closure # if closure is run, minify whitespace
@@ -776,7 +789,7 @@ try:
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), llvm_opts)
if DEBUG: save_intermediate('opt', 'bc')
# Do LTO in a separate pass to work around LLVM bug XXX (see failure e.g. in cubescript)
- if shared.Building.can_use_unsafe_opts() and shared.Building.can_build_standalone():
+ if llvm_lto and shared.Building.can_use_unsafe_opts() and shared.Building.can_build_standalone():
lto_opts = []
if not shared.Building.can_inline(): lto_opts.append('-disable-inlining')
lto_opts.append('-std-link-opts')
@@ -932,7 +945,7 @@ try:
shutil.copyfile(final, final + '.tr.js')
final += '.tr.js'
if DEBUG: print >> sys.stderr, 'emcc: applying transform: %s' % js_transform
- execute(js_transform.split(' ') + [os.path.abspath(final)])
+ execute(shlex.split(js_transform) + [os.path.abspath(final)])
if DEBUG: save_intermediate('transformed')
# It is useful to run several js optimizer passes together, to save on unneeded unparsing/reparsing
diff --git a/src/library_sdl.js b/src/library_sdl.js
index afc2e3d6..65e72e6e 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -173,17 +173,21 @@ mergeInto(LibraryManager.library, {
},
// Load SDL color into a CSS-style color specification
- loadColorToCSS: function(color) {
+ loadColorToCSSRGB: function(color) {
var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
- return 'rgba(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ',' + (1-((rgba >> 24)&255)/255) + ')';
+ return 'rgb(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ')';
+ },
+ loadColorToCSSRGBA: function(color) {
+ var rgba = {{{ makeGetValue('color', '0', 'i32') }}};
+ return 'rgba(' + (rgba&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba >> 16)&255) + ',' + (((rgba >> 24)&255)/255) + ')';
},
- translateColorToCSS: function(rgba) {
- return 'rgba(' + ((rgba >> 24)&255) + ',' + ((rgba >> 16)&255) + ',' + ((rgba >> 8)&255) + ',' + (1-(rgba&255)/255) + ')';
+ translateColorToCSSRGBA: function(rgba) {
+ return 'rgba(' + ((rgba >> 24)&255) + ',' + ((rgba >> 16)&255) + ',' + ((rgba >> 8)&255) + ',' + ((rgba&255)/255) + ')';
},
- translateRGBAToCSS: function(r, g, b, a) {
- return 'rgba(' + r + ',' + g + ',' + b + ',' + (1-a/255) + ')';
+ translateRGBAToCSSRGBA: function(r, g, b, a) {
+ return 'rgba(' + r + ',' + g + ',' + b + ',' + (a/255) + ')';
},
makeSurface: function(width, height, flags, usePageCanvas, source) {
@@ -574,14 +578,14 @@ mergeInto(LibraryManager.library, {
assert(!surfData.locked); // but we could unlock and re-lock if we must..
var r = SDL.loadRect(rect);
surfData.ctx.save();
- surfData.ctx.fillStyle = SDL.translateColorToCSS(color);
+ surfData.ctx.fillStyle = SDL.translateColorToCSSRGBA(color);
surfData.ctx.fillRect(r.x, r.y, r.w, r.h);
surfData.ctx.restore();
},
SDL_BlitSurface__deps: ['SDL_UpperBlit'],
SDL_BlitSurface: function(src, srcrect, dst, dstrect) {
- return _SDL_Blit(src, srcrect, dst, dstrect);
+ return _SDL_UpperBlit(src, srcrect, dst, dstrect);
},
SDL_SetAlpha: function(surf, flag, alpha) {
@@ -733,14 +737,14 @@ mergeInto(LibraryManager.library, {
},
Mix_FreeChunk: function(id) {
- SDL.audios[id].audio.pause();
- SDL.audios[id] = null;
+ //SDL.audios[id].audio.pause();
+ //SDL.audios[id] = null;
return 0;
},
Mix_PlayChannel: function(channel, id, loops) {
- var audio = SDL.audios[id].audio;
- audio.play();
+ //var audio = SDL.audios[id].audio;
+ //audio.play();
return 0; // XXX should return channel
},
Mix_PlayChannelTimed: 'Mix_PlayChannel', // XXX ignore Timing
@@ -810,7 +814,7 @@ mergeInto(LibraryManager.library, {
var fontData = SDL.fonts[font];
var w = SDL.estimateTextWidth(fontData, text);
var h = fontData.size;
- var color = SDL.loadColorToCSS(color);
+ var color = SDL.loadColorToCSSRGB(color); // XXX alpha breaks fonts?
var fontString = h + 'px sans-serif';
var surf = SDL.makeSurface(w, h, 0, false, 'text:' + text); // bogus numbers..
var surfData = SDL.surfaces[surf];
@@ -853,7 +857,7 @@ mergeInto(LibraryManager.library, {
assert(!surfData.locked); // but we could unlock and re-lock if we must..
// TODO: if ctx does not change, leave as is, and also do not re-set xStyle etc.
surfData.ctx.save();
- surfData.ctx.fillStyle = SDL.translateRGBAToCSS(r, g, b, a);
+ surfData.ctx.fillStyle = SDL.translateRGBAToCSSRGBA(r, g, b, a);
surfData.ctx.fillRect(x1, y1, x2-x1, y2-y1);
surfData.ctx.restore();
},
@@ -862,7 +866,7 @@ mergeInto(LibraryManager.library, {
var surfData = SDL.surfaces[surf];
assert(!surfData.locked); // but we could unlock and re-lock if we must..
surfData.ctx.save();
- surfData.ctx.strokeStyle = SDL.translateRGBAToCSS(r, g, b, a);
+ surfData.ctx.strokeStyle = SDL.translateRGBAToCSSRGBA(r, g, b, a);
surfData.ctx.strokeRect(x1, y1, x2-x1, y2-y1);
surfData.ctx.restore();
},
@@ -871,7 +875,7 @@ mergeInto(LibraryManager.library, {
var surfData = SDL.surfaces[surf];
assert(!surfData.locked); // but we could unlock and re-lock if we must..
surfData.ctx.save();
- surfData.ctx.strokeStyle = SDL.translateRGBAToCSS(r, g, b, a);
+ surfData.ctx.strokeStyle = SDL.translateRGBAToCSSRGBA(r, g, b, a);
surfData.ctx.beginPath();
surfData.ctx.moveTo(x1, y1);
surfData.ctx.lineTo(x2, y2);
diff --git a/src/shell.html b/src/shell.html
index 79b7e9b9..9aa73e83 100644
--- a/src/shell.html
+++ b/src/shell.html
@@ -4,26 +4,26 @@
<body>
<center>
<canvas id='canvas' width='256' height='256'></canvas>
+ <hr>
+ <textarea id="output" style="font-family: monospace; width: 80%" rows="8"></textarea>
+ <hr>
+ <div id='status'>Downloading...</div>
</center>
<hr>
- <div id='output'></div>
- <hr>
- <center><div id='status'></div></center>
- <hr>
<script type='text/javascript'>
// connect to canvas
var Module = {
print: (function() {
var element = document.getElementById('output');
- var printBuffer = [];
+ element.value = ''; // clear browser cache
return function(text) {
- text = text.replace(/&/g, "&amp;");
- text = text.replace(/</g, "&lt;");
- text = text.replace(/>/g, "&gt;");
- text = text.replace('\n', '<br>', 'g');
- if (printBuffer.length > 10) printBuffer.shift();
- printBuffer.push(text);
- element.innerHTML = printBuffer.join('<br>');
+ // These replacements are necessary if you render to raw HTML
+ //text = text.replace(/&/g, "&amp;");
+ //text = text.replace(/</g, "&lt;");
+ //text = text.replace(/>/g, "&gt;");
+ //text = text.replace('\n', '<br>', 'g');
+ element.value += text + "\n";
+ element.scrollTop = 99999; // focus on bottom
};
})(),
canvas: document.getElementById('canvas'),
diff --git a/tests/sdl_canvas.c b/tests/sdl_canvas.c
index aaa9d653..ab1340a8 100644
--- a/tests/sdl_canvas.c
+++ b/tests/sdl_canvas.c
@@ -12,11 +12,11 @@ int main() {
TTF_Font *font = TTF_OpenFont("myfont.ttf", 40);
printf("Font: %p\n", font);
- SDL_Color color = { 0xff, 0x99, 0x00, 0xb0 };
+ SDL_Color color = { 0xff, 0x99, 0x00, 0xff };
- SDL_Surface *text = TTF_RenderText_Solid(font, "hello faint orange world", color);
+ SDL_Surface *text = TTF_RenderText_Solid(font, "hello orange world", color);
- SDL_Color color2 = { 0xbb, 0, 0xff, 0 };
+ SDL_Color color2 = { 0xbb, 0, 0xff, 0xff };
SDL_Surface *text2 = TTF_RenderText_Solid(font, "a second line, purple", color2);
// render
@@ -27,7 +27,7 @@ int main() {
// fill stuff
SDL_Rect rect = { 200, 200, 175, 125 };
- SDL_FillRect(screen, &rect, 0x2222ff00);
+ SDL_FillRect(screen, &rect, 0x2222ffff);
SDL_Flip(screen);
diff --git a/tests/sdl_mouse.c b/tests/sdl_mouse.c
index a0520839..dae3f636 100644
--- a/tests/sdl_mouse.c
+++ b/tests/sdl_mouse.c
@@ -44,7 +44,7 @@ int main() {
SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
SDL_Rect rect = { 0, 0, 600, 450 };
- SDL_FillRect(screen, &rect, 0x2244ff00);
+ SDL_FillRect(screen, &rect, 0x2244ffff);
emscripten_run_script("simulateMouseEvent(10, 20, -1)"); // move from 0,0 to 10,20
emscripten_run_script("simulateMouseEvent(10, 20, 0)"); // click
diff --git a/tools/shared.py b/tools/shared.py
index 61ec912e..3c76d73e 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1,4 +1,4 @@
-import shutil, time, os, sys, json, tempfile, copy
+import shutil, time, os, sys, json, tempfile, copy, shlex
from subprocess import Popen, PIPE, STDOUT
from tempfile import mkstemp
@@ -743,7 +743,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' \
#'--variable_map_output_file', filename + '.vars',
'--js', filename, '--js_output_file', filename + '.cc.js']
if os.environ.get('EMCC_CLOSURE_ARGS'):
- args += os.environ.get('EMCC_CLOSURE_ARGS').split(' ')
+ args += shlex.split(os.environ.get('EMCC_CLOSURE_ARGS'))
process = Popen(args, stdout=PIPE, stderr=STDOUT)
cc_output = process.communicate()[0]
if process.returncode != 0 or not os.path.exists(filename + '.cc.js'):