X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fplat%2FPlatform.java;h=32fea9dc7f76f57ef4086f331483b839c29e0b4c;hb=cab49a265d0483f7162711a12193a966c2dd3521;hp=b7d88d16b2880323711e0dca2116c8dd3b16eb86;hpb=76982fccac3c46ccc47621dd22dc0c96b6b9cd62;p=org.ibex.core.git diff --git a/src/org/ibex/plat/Platform.java b/src/org/ibex/plat/Platform.java index b7d88d1..32fea9d 100644 --- a/src/org/ibex/plat/Platform.java +++ b/src/org/ibex/plat/Platform.java @@ -1,4 +1,7 @@ -// Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] +// Copyright 2000-2005 the Contributors, as shown in the revision logs. +// Licensed under the GNU General Public License version 2 ("the License"). +// You may not use this file except in compliance with the License. + package org.ibex.plat; import java.lang.reflect.*; @@ -8,7 +11,7 @@ import org.ibex.js.*; import org.ibex.util.*; import org.ibex.graphics.*; import org.ibex.core.*; -import org.ibex.graphics.*; +import org.ibex.crypto.*; import org.ibex.core.*; import org.ibex.net.*; @@ -48,7 +51,7 @@ public abstract class Platform { String os_name = System.getProperty("os.name", ""); String os_version = System.getProperty("os.version", ""); String platform_class = null; - + if (vendor.startsWith("Free Software Foundation")) { if (os_name.startsWith("Window")) platform_class = "Win32"; else if (os_name.startsWith("Linux")) platform_class = "Linux"; @@ -57,8 +60,8 @@ public abstract class Platform { else if (os_name.startsWith("Darwin")) platform_class = "Darwin"; else platform_class = "X11"; } + else if (version.startsWith("1.4")) platform_class = "Java4"; else if (!version.startsWith("1.0") && !version.startsWith("1.1")) platform_class = "Java2"; - if (platform_class == null) { Log.error(Platform.class, "Unable to detect JVM"); criticalAbort("Unable to detect JVM"); @@ -115,11 +118,11 @@ public abstract class Platform { ret.setInvisible(false); if (refreshable) { Surface.allSurfaces.addElement(ret); - ret.dirty(0, 0, b.width, b.height); + b.dirty(); ret.Refresh(); } try { - if (b.get(JS.S("titlebar")) != null) ret.setTitleBarText(JS.toString(b.get(JS.S("titlebar")))); + if (b.get(JSU.S("titlebar")) != null) ret.setTitleBarText(JSU.toString(b.get(JSU.S("titlebar")))); } catch (JSExn e) { Log.warn(Platform.class, e); } @@ -290,6 +293,141 @@ public abstract class Platform { return p; } } + + /** Implements cooperative multitasking */ + public static class Scheduler { + + // Public API Exposed to org.ibex ///////////////////////////////////////////////// + + private static Scheduler singleton; + public static void add(Callable t) { Log.debug(Scheduler.class, "scheduling " + t); Scheduler.runnable.append(t); } + public static void init() { if (singleton == null) (singleton = Platform.getScheduler()).run(); } + + private static Callable current = null; + + private static volatile boolean rendering = false; + private static volatile boolean again = false; + + /** synchronizd so that we can safely call it from an event-delivery thread, in-context */ + public static void renderAll() { + if (rendering) { again = true; return; } + synchronized(Scheduler.class) { + try { + rendering = true; + do { + // FEATURE: this could be cleaner + again = false; + for(int i=0; i