diff --git a/glass/glass/src/com/sun/glass/ui/Application.java b/glass/glass/src/com/sun/glass/ui/Application.java --- a/glass/glass/src/com/sun/glass/ui/Application.java +++ b/glass/glass/src/com/sun/glass/ui/Application.java @@ -145,7 +145,12 @@ // on Linux - TODO application.name = "java"; // default try { - application.runLoop(launchable); + application.runLoop(new Runnable () { + public void run() { + Screen.init(); + launchable.run(); + } + }); } catch (Throwable t) { t.printStackTrace(); } diff --git a/glass/glass/src/com/sun/glass/ui/Screen.java b/glass/glass/src/com/sun/glass/ui/Screen.java --- a/glass/glass/src/com/sun/glass/ui/Screen.java +++ b/glass/glass/src/com/sun/glass/ui/Screen.java @@ -24,10 +24,17 @@ */ package com.sun.glass.ui; +import java.util.Collections; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; public final class Screen { + static List<Screen> Screens; + static Screen MainScreen; + static final boolean CACHE_SCREENS = true; + static ReentrantLock Lock; + public static class EventHandler { public void handleSettingsChanged() { } @@ -38,30 +45,23 @@ return Application.GetApplication().staticScreen_getVideoRefreshPeriod(); } - public static Screen getDeepestScreen() { - Application.checkEventThread(); - return Application.GetApplication().staticScreen_getDeepestScreen(); - } - + // Can be called from any thread public static Screen getMainScreen() { - //Application.checkEventThread(); // Quantum - return Application.GetApplication().staticScreen_getMainScreen(); - } - - public static Screen getScreenForLocation(int x, int y) { - Application.checkEventThread(); - return Application.GetApplication().staticScreen_getScreenForLocation(x, y); + return CACHE_SCREENS ? MainScreen : Application.GetApplication().staticScreen_getMainScreen(); } // used by Window.notifyMoveToAnotherScreen static Screen getScreenForPtr(long screenPtr) { Application.checkEventThread(); - return Application.GetApplication().staticScreen_getScreenForPtr(screenPtr); + for(Screen screen : Screens) { + if (screen.ptr == screenPtr) return screen; + } + return null; } + // Can be called by any thread public static List<Screen> getScreens() { - //Application.checkEventThread(); // Quantum - return Application.GetApplication().staticScreen_getScreens(); + return CACHE_SCREENS ? Screens : Application.GetApplication().staticScreen_getScreens(); } private static EventHandler eventHandler; @@ -86,7 +86,6 @@ private float scale; public Screen() { - //Application.checkEventThread(); // Quantum this.ptr = 0L; this.depth = 0; @@ -108,67 +107,54 @@ } public int getDepth() { - Application.checkEventThread(); return this.depth; } public int getX() { - Application.checkEventThread(); return this.x; } public int getY() { - Application.checkEventThread(); return this.y; } public int getWidth() { - Application.checkEventThread(); return this.width; } public int getHeight() { - Application.checkEventThread(); return this.height; } public int getVisibleX() { - Application.checkEventThread(); return this.visibleX; } public int getVisibleY() { - Application.checkEventThread(); return this.visibleY; } public int getVisibleWidth() { - Application.checkEventThread(); return this.visibleWidth; } public int getVisibleHeight() { - Application.checkEventThread(); return this.visibleHeight; } public int getResolutionX() { - Application.checkEventThread(); return this.resolutionX; } public int getResolutionY() { - Application.checkEventThread(); return this.resolutionY; } public float getScale() { - Application.checkEventThread(); return this.scale; } public long getNativeScreen() { - //Application.checkEventThread(); // Quantum return this.ptr; } @@ -181,8 +167,30 @@ Application.checkEventThread(); eventHandler = eh; } + + public static void setLock(ReentrantLock lock) { + Application.checkEventThread(); + Lock = lock; + } + + static void init() { + if (CACHE_SCREENS) { + if (Lock != null) Lock.lock(); + try { + if (MainScreen != null) MainScreen.ptr = 0; + if (Screens != null) { + for (Screen screen : Screens) screen.ptr = 0; + } + MainScreen = Application.GetApplication().staticScreen_getMainScreen(); + Screens = Collections.unmodifiableList(Application.GetApplication().staticScreen_getScreens()); + } finally { + if (Lock != null) Lock.unlock(); + } + } + } private static void notifySettingsChanged() { + init(); if (eventHandler != null) { eventHandler.handleSettingsChanged(); } diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/AbstractPainter.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/AbstractPainter.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/AbstractPainter.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/AbstractPainter.java @@ -31,6 +31,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; +import com.sun.glass.ui.Screen; import com.sun.javafx.geom.DirtyRegionContainer; import com.sun.javafx.geom.DirtyRegionPool; import com.sun.javafx.geom.RectBounds; @@ -72,6 +73,9 @@ * FX handlers called in GlassViewEventHandler would not modify other scenes. */ protected static final ReentrantLock renderLock = new ReentrantLock(); + static { + Screen.setLock(renderLock); + } protected static final PaintCollector collector = PaintCollector.getInstance(); diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/SceneState.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/SceneState.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/SceneState.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/SceneState.java @@ -25,6 +25,9 @@ package com.sun.javafx.tk.quantum; +import java.util.List; + +import com.sun.glass.ui.Screen; import com.sun.prism.PresentableState; /** @@ -68,6 +71,10 @@ * May be called on any thread. */ public boolean isValid() { + List<Screen> screens = getScreens(); + for (Screen screen : screens) { + if (screen.getNativeScreen() == 0) return false; + } return getWindow() != null && getView() != null && !isViewClosed() && getWidth() > 0 && getHeight() > 0; } diff --git a/prism-common/src/com/sun/prism/PresentableState.java b/prism-common/src/com/sun/prism/PresentableState.java --- a/prism-common/src/com/sun/prism/PresentableState.java +++ b/prism-common/src/com/sun/prism/PresentableState.java @@ -25,6 +25,8 @@ package com.sun.prism; +import java.util.List; + import com.sun.glass.ui.Application; import com.sun.glass.ui.Screen; import com.sun.glass.ui.View; @@ -57,7 +59,8 @@ // the associated View can be closed. This variable allows us // to shortcut the queued *Painter task. private boolean isClosed; - + private List<Screen> screens; + /** Create a PresentableState based on a View. * * Must be called on the event thread. @@ -150,6 +153,15 @@ public int getScreenHeight() { return screenHeight; } + + /** + * @return the current height of the screen + * + * May be called on any thread. + */ + public List<Screen> getScreens() { + return screens; + } /** * Updates this object's state to indicate that the underlying View is @@ -272,6 +284,7 @@ nativeWindowHandle = -1; isClosed = true; } + screens = Screen.getScreens(); } public boolean isUpToDate() {