changeset 10131:bfe35c702696 jdk-9+145

8088179: [Quantum] White flashing when opening a stage with dark background Reviewed-by: flar, kcr
author ckyang
date Sat, 12 Nov 2016 09:52:31 -0800
parents e2928ffe8952
children 13d3a94c0c54 bd16088b7c04
files modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/WindowStage.java
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/WindowStage.java	Fri Nov 11 06:35:43 2016 -0800
+++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/WindowStage.java	Sat Nov 12 09:52:31 2016 -0800
@@ -201,11 +201,41 @@
                 if (securityDialog) {
                     platformWindow.setLevel(Window.Level.FLOATING);
                 }
+                if (fxStage != null && fxStage.getScene() != null) {
+                    javafx.scene.paint.Paint paint = fxStage.getScene().getFill();
+                    if (paint instanceof javafx.scene.paint.Color) {
+                        javafx.scene.paint.Color color = (javafx.scene.paint.Color) paint;
+                        platformWindow.setBackground((float) color.getRed(), (float) color.getGreen(), (float) color.getBlue());
+                    } else if (paint instanceof javafx.scene.paint.LinearGradient) {
+                        javafx.scene.paint.LinearGradient lgradient = (javafx.scene.paint.LinearGradient) paint;
+                        computeAndSetBackground(lgradient.getStops());
+                    } else if (paint instanceof javafx.scene.paint.RadialGradient) {
+                        javafx.scene.paint.RadialGradient rgradient = (javafx.scene.paint.RadialGradient) paint;
+                        computeAndSetBackground(rgradient.getStops());
+                    }
+                }
+
             }
         }
         platformWindows.put(platformWindow, this);
     }
 
+    private void computeAndSetBackground(List<javafx.scene.paint.Stop> stops) {
+        if (stops.size() == 1) {
+            javafx.scene.paint.Color color = stops.get(0).getColor();
+            platformWindow.setBackground((float) color.getRed(),
+                    (float) color.getGreen(), (float) color.getBlue());
+        } else if (stops.size() > 1) {
+            // A simple attempt to find a reasonable average color that is
+            // within the stops arrange.
+            javafx.scene.paint.Color color = stops.get(0).getColor();
+            javafx.scene.paint.Color color2 = stops.get(stops.size() - 1).getColor();
+            platformWindow.setBackground((float) ((color.getRed() + color2.getRed()) / 2.0),
+                    (float) ((color.getGreen() + color2.getGreen()) / 2.0),
+                    (float) ((color.getBlue() + color2.getBlue()) / 2.0));
+        }
+    }
+
     final Window getPlatformWindow() {
         return platformWindow;
     }