This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit a55b18b3b32b16134662ece6aaa1761f969e99cd Author: Martin Desruisseaux <[email protected]> AuthorDate: Sun Jul 10 21:11:30 2022 +0200 Transfer of pixel data from Java2D image to JavaFX image should be scheduled to occur just before a JavaFX pulse. It seems to resolve the mysterious flickering effects that happened for so long. --- .../java/org/apache/sis/gui/map/MapCanvasAWT.java | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java index 926d4be804..267efa7ce9 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvasAWT.java @@ -33,6 +33,7 @@ import javafx.application.Platform; import javafx.geometry.Bounds; import javafx.geometry.Insets; import javafx.geometry.Rectangle2D; +import javafx.scene.Scene; import javafx.scene.image.ImageView; import javafx.scene.image.PixelBuffer; import javafx.scene.image.PixelFormat; @@ -560,13 +561,34 @@ public abstract class MapCanvasAWT extends MapCanvas { return null; // Indicate that the entire buffer was dirty. } + /** + * Invoked in JavaFX thread on success. The actual transfer from Java2D image to JavaFX image + * will happen just before the next pulse for making sure that the affine transform and the + * image are updated together before rendering. Doing that way avoid flickering effects. + */ + @Override + protected void succeeded() { + final Scene scene = fixedPane.getScene(); + if (scene != null) { + final Runnable pulseAction = new Runnable() { + @Override public void run() { + scene.removePreLayoutPulseListener(this); + transferImage(); + } + }; + scene.addPreLayoutPulseListener(pulseAction); + Platform.requestNextPulse(); + } else { + transferImage(); + } + } + /** * Invoked in JavaFX thread on success. The JavaFX image is set to the result, then the double buffer * created by this task is saved in {@link MapCanvas} fields for reuse next time that an image of the * same size will be rendered again. */ - @Override - protected void succeeded() { + private void transferImage() { final VolatileImage drawTo = getValue(); doubleBuffer = drawTo; try {
