From c776d5cb1a018c1731172c871c4a0a6e4ef64b1b Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:40:46 +0000 Subject: [PATCH] 2003/11/03 00:08:27 darcs-hash:20040130074046-2ba56-9cdc2720b8fe9cd9c9f0dd4ade67b32642ab7972.gz --- src/org/xwt/js/JS.java | 30 ++++++++++++++++-------------- src/org/xwt/plat/OpenGL.java | 4 +--- src/org/xwt/translators/Freetype.java | 12 +++++++----- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/org/xwt/js/JS.java b/src/org/xwt/js/JS.java index ebd2e36..ce48cb5 100644 --- a/src/org/xwt/js/JS.java +++ b/src/org/xwt/js/JS.java @@ -15,7 +15,6 @@ import java.util.*; */ public abstract class JS { - // Public Helper Methods ////////////////////////////////////////////////////////////////////// /** parse and compile a function */ @@ -78,6 +77,7 @@ public abstract class JS { public abstract Object get(Object key) throws JS.Exn; public abstract void put(Object key, Object val) throws JS.Exn; + public void put(Object key, Object val, TailCall tail) throws JS.Exn { put(key, val); } public abstract Object[] keys(); public Object callMethod(Object method, Array args, boolean checkOnly) throws JS.Exn { if(checkOnly) return Boolean.FALSE; @@ -107,8 +107,8 @@ public abstract class JS { public Obj() { this(false); } public Obj(boolean sealed) { this.sealed = sealed; } public void setSeal(boolean sealed) { this.sealed = sealed; } ///< a sealed object cannot have its properties modified - public void put(Object key, Object val) { put(key, null, val); } - protected void put(Object key, Object key2, Object val) { + public void put(Object key, Object val) { put2(key, null, val); } + protected void put2(Object key, Object key2, Object val) { if (sealed) return; if (entries == null) entries = new Hash(); entries.put(key, key2, val); } @@ -213,6 +213,14 @@ public abstract class JS { } public static final JS Math = new org.xwt.js.Math(); + + public static class TailCall { + CompiledFunction func = null; + JS.Array args = null; + public TailCall() { } + public TailCall set(CompiledFunction func) { this.func = func; this.args = new JS.Array(); return this; } + public TailCall set(CompiledFunction func, JS.Array args) { this.func = func; this.args = args; return this; } + } /** encapsulates a single JavaScript thread; the JS.Thread->java.lang.Thread mapping is 1:1 */ public static class Thread { @@ -223,23 +231,17 @@ public abstract class JS { int pc = 0; boolean paused = false; - CompiledFunction tailCallFunction = null; - JS.Array tailCallArgs = null; - - public Thread(CompiledFunction function) { - this(function, new CompiledFunctionImpl.FunctionScope("unknown", function.parentScope)); - } - public Thread(CompiledFunction function, Scope scope) { + public Thread(CompiledFunction function) { this(function, null); } + public Thread(CompiledFunction function, Scope scope) { this(function, scope, new JS.Array()); } + public Thread(CompiledFunction function, Scope scope, JS.Array args) { + if (scope == null) scope = new CompiledFunctionImpl.FunctionScope("unknown", function.parentScope); stack.push(new CompiledFunctionImpl.CallMarker(this)); - stack.push(new JS.Array()); + stack.push(args); this.currentCompiledFunction = function; this.scope = scope; } - public void setTailCall(JS.CompiledFunction f, JS.Array args) { tailCallFunction = f; tailCallArgs = args; } - public static JS.Thread current() { return (JS.Thread)javaThreadToJSThread.get(java.lang.Thread.currentThread()); } - public Object resume() { bind(); paused = false; Object ret = CompiledFunctionImpl.eval(this); unbind(); return ret; } public void pause() { paused = true; unbind(); } public void bind() { javaThreadToJSThread.put(java.lang.Thread.currentThread(), this); } diff --git a/src/org/xwt/plat/OpenGL.java b/src/org/xwt/plat/OpenGL.java index 4cc0bd3..d4bbe1e 100644 --- a/src/org/xwt/plat/OpenGL.java +++ b/src/org/xwt/plat/OpenGL.java @@ -120,9 +120,7 @@ abstract class OpenGL { public void deleteTexture(final int tex) { // CHECKME: Is this safe to do from finalize()? // natDeleteTexture MUST be run from the message queue thread - Scheduler.add(new Scheduler.Task() { public Object call(Object o) { - natDeleteTexture(tex); return null; - }}); + Scheduler.add(new Scheduler.Task() { public void perform() { natDeleteTexture(tex); }}); } private static abstract class GLPicture extends Picture { diff --git a/src/org/xwt/translators/Freetype.java b/src/org/xwt/translators/Freetype.java index 9d89d7f..de5e0c0 100644 --- a/src/org/xwt/translators/Freetype.java +++ b/src/org/xwt/translators/Freetype.java @@ -37,16 +37,16 @@ public class Freetype { } } - public synchronized void renderGlyph(Res res, Glyph glyph) { + public synchronized void renderGlyph(Font.Glyph glyph) { try { - if (loadedStream != res) loadFontByteStream(res); + if (loadedStream != glyph.font.res) loadFontByteStream(glyph.font.res); vm.setUserInfo(2, (int)glyph.c); vm.setUserInfo(3, (int)glyph.c); - vm.setUserInfo(4, glyph.pointsize); + vm.setUserInfo(4, glyph.font.pointsize); long start = System.currentTimeMillis(); vm.execute(); - glyph.max_ascent = vm.getUserInfo(8); - glyph.max_descent = vm.getUserInfo(9); + glyph.font.max_ascent = vm.getUserInfo(8); + glyph.font.max_descent = vm.getUserInfo(9); glyph.baseline = vm.getUserInfo(10); glyph.advance = vm.getUserInfo(11); @@ -54,6 +54,7 @@ public class Freetype { int height = vm.getUserInfo(7); if (width == 0 || height == 0) { Log.log(Freetype.class, "warning glyph has zero width/height"); + glyph.p = Platform.createAlphaOnlyPicture(new byte[] { }, 0, 0); } else { byte[] data = new byte[width * height]; @@ -61,6 +62,7 @@ public class Freetype { vm.copyin(addr,data,width*height); glyph.p = Platform.createAlphaOnlyPicture(data, width, height); } + } catch (Exception e) { Log.log(this, e); } -- 1.7.10.4