diff --git a/javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java b/javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java --- a/javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java +++ b/javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java @@ -783,6 +783,14 @@ public abstract Object renderToImage(ImageRenderingContext context); /** + * Runs a runnable that is synchronized with the graphics system. + * When the runnable is executing, any threads that are accessing + * shared graphics state for the scene are locked. + */ + public void runSynchronized(TKScene scene, Runnable runnable) { + if (runnable != null) runnable.run(); + } + /** * Returns the key code for the key which is commonly used on the * corresponding platform as a modifier key in shortcuts. For example * it is {@code KeyCode.CONTROL} on Windows (Ctrl + C, Ctrl + V ...) and diff --git a/javafx-ui-common/src/javafx/scene/Scene.java b/javafx-ui-common/src/javafx/scene/Scene.java --- a/javafx-ui-common/src/javafx/scene/Scene.java +++ b/javafx-ui-common/src/javafx/scene/Scene.java @@ -2392,27 +2392,28 @@ if (dirty) { getRoot().updateBounds(); if (impl_peer != null) { - try { - long start = PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0; - impl_peer.waitForRenderingToComplete(); - impl_peer.waitForSynchronization(); - if (PULSE_LOGGING_ENABLED) { - PULSE_LOGGER.fxMessage(start, System.currentTimeMillis(), "Waiting for previous rendering"); - } - start = PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0; - // synchronize scene properties - syncLights(); - synchronizeSceneProperties(); - // Run the synchronizer - synchronizeSceneNodes(); - Scene.this.mouseHandler.pulse(); - // Tell the scene peer that it needs to repaint - impl_peer.markDirty(); - if (PULSE_LOGGING_ENABLED) { - PULSE_LOGGER.fxMessage(start, System.currentTimeMillis(), "Copy state to render graph"); - } - } finally { - impl_peer.releaseSynchronization(); + long start = PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0; + if (PULSE_LOGGING_ENABLED) { + PULSE_LOGGER.fxMessage(start, System.currentTimeMillis(), "Waiting for previous rendering"); + } + start = PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0; + Toolkit.getToolkit().runSynchronized( + impl_peer, + new Runnable () { + public void run () { + // synchronize scene properties + syncLights(); + synchronizeSceneProperties(); + // Run the synchronizer + synchronizeSceneNodes(); + mouseHandler.pulse(); + // Tell the scene peer that it needs to repaint + impl_peer.markDirty(); + } + } + ); + if (PULSE_LOGGING_ENABLED) { + PULSE_LOGGER.fxMessage(start, System.currentTimeMillis(), "Copy state to render graph"); } } else { long start = PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0; 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 @@ -72,8 +72,6 @@ protected int width; protected int height; - private boolean renderOverlay = false; - Rectangle dirtyRect; RectBounds clip; RectBounds dirtyRegionTemp; @@ -124,10 +122,6 @@ return (overlayRoot); } - protected void setRenderOverlay(boolean val) { - renderOverlay = val; - } - protected abstract void doPaint(Graphics g, NodePath renderRoot); private void adjustPerspective(PrismCameraImpl camera) { @@ -160,7 +154,7 @@ int status = DirtyRegionContainer.DTR_CONTAINS_CLIP; if (PrismSettings.dirtyOptsEnabled) { long start = PULSE_LOGGING_ENABLED ? System.currentTimeMillis() : 0; - if (!sceneState.getScene().isEntireSceneDirty() && !renderOverlay) { + if (!sceneState.getScene().isEntireSceneDirty()) { status = setDirtyRect(g); if (status == DirtyRegionContainer.DTR_OK) { root.doPreCulling(dirtyRegionContainer, @@ -252,7 +246,7 @@ } } } - if (renderOverlay) { + if (overlayRoot != null) { overlayRoot.render(g); } } diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/OverlayWarning.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/OverlayWarning.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/OverlayWarning.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/OverlayWarning.java @@ -67,19 +67,12 @@ private ViewScene view; private Group sceneRoot; private SequentialTransition overlayTransition; - private AbstractPainter painter; private boolean warningTransition; public OverlayWarning(final ViewScene vs) { view = vs; sceneRoot = createOverlayGroup(); - painter = view.getPainter(); - - // TODO - needs to be thread-safe - see RT-13813 - Scene.impl_setAllowPGAccess(true); - painter.setOverlayRoot((NGNode)sceneRoot.impl_getPGNode()); - Scene.impl_setAllowPGAccess(false); PauseTransition pause = new PauseTransition(Duration.millis(4000)); FadeTransition fade = new FadeTransition(Duration.millis(1000), sceneRoot); @@ -92,7 +85,6 @@ overlayTransition.setOnFinished(new EventHandler() { @Override public void handle(ActionEvent event) { - painter.setRenderOverlay(false); view.entireSceneNeedsRepaint(); warningTransition = false; } @@ -104,25 +96,12 @@ } protected final void setView(ViewScene vs) { - if (painter != null) { - painter.setRenderOverlay(false); - view.entireSceneNeedsRepaint(); - } - + view.entireSceneNeedsRepaint(); view = vs; - painter = vs.getPainter(); - - // TODO - needs to be thread-safe - see RT-13813 - Scene.impl_setAllowPGAccess(true); - painter.setOverlayRoot((NGNode)sceneRoot.impl_getPGNode()); - Scene.impl_setAllowPGAccess(false); - - painter.setRenderOverlay(true); view.entireSceneNeedsRepaint(); overlayTransition.setOnFinished(new EventHandler() { @Override public void handle(ActionEvent event) { - painter.setRenderOverlay(false); view.entireSceneNeedsRepaint(); warningTransition = false; } @@ -131,7 +110,6 @@ protected void warn() { warningTransition = true; - painter.setRenderOverlay(true); overlayTransition.play(); } @@ -141,7 +119,6 @@ overlayTransition.stop(); - painter.setRenderOverlay(false); view.entireSceneNeedsRepaint(); warningTransition = false; } @@ -178,12 +155,11 @@ Group root = (Group)scene.getRoot(); root.getChildren().add(background); root.getChildren().add(text); + + this.text = text; + this.background = background; + this.root = root; - Scene.impl_setAllowPGAccess(true); - text.impl_updatePG(); - background.impl_updatePG(); - root.impl_updatePG(); - Scene.impl_setAllowPGAccess(false); return root; } @@ -208,4 +184,14 @@ return rectangle; } + + public void updatePGNodes () { + text.impl_updatePG(); + background.impl_updatePG(); + root.impl_updatePG(); + } + + public NGNode gePGRoot() { + return (NGNode)sceneRoot.impl_getPGNode(); + } } diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java @@ -415,6 +415,33 @@ private void assertToolkitRunning() { // not implemented } + + /** + * Runs a runnable that is synchronized with the graphics system. + * When the runnable is executing, any threads that are accessing + * shared graphics state for the scene are locked. + */ + public void runSynchronized(TKScene scene, Runnable runnable) { + scene.waitForRenderingToComplete(); + scene.waitForSynchronization(); + try { + if (scene instanceof ViewScene) { + ViewScene view = (ViewScene) scene; + WindowStage stage = (WindowStage) view.getStage(); + OverlayWarning warning = stage.getOverlayWarning(); + AbstractPainter painter = view.getPainter(); + if (warning != null) { + warning.updatePGNodes(); + painter.setOverlayRoot(warning.gePGRoot()); + } else { + painter.setOverlayRoot(null); + } + } + if (runnable != null) runnable.run(); + } finally { + scene.releaseSynchronization(); + } + } // Called by Glass from Application.run() void runToolkit() { diff --git a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/WindowStage.java b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/WindowStage.java --- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/WindowStage.java +++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/WindowStage.java @@ -154,6 +154,10 @@ platformWindows.put(platformWindow, this); } + final OverlayWarning getOverlayWarning() { + return warning; + } + final Window getPlatformWindow() { return platformWindow; }