Skip to content

Commit

Permalink
8274932: Render scales in EmbeddedWindow are not properly updated
Browse files Browse the repository at this point in the history
8222209: JavaFX is rendered blurry on systems with monitors in different configuration

Co-authored-by: John Hendrikx <jhendrikx@openjdk.org>
Reviewed-by: angorya, kcr, jhendrikx
  • Loading branch information
prsadhuk and hjohn committed Aug 21, 2023
1 parent 2e937bb commit 6a7c743
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ public void setPixelScaleFactors(float scalex, float scaley) {
renderScaleX = scalex;
renderScaleY = scaley;
entireSceneNeedsRepaint();
Platform.runLater(() -> {
QuantumToolkit.runWithRenderLock(() -> {
updateSceneState();
return null;
});
});
}

public float getRenderScaleX() {
Expand Down
33 changes: 16 additions & 17 deletions modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.Graphics2D;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
Expand All @@ -38,7 +39,6 @@
import java.awt.EventQueue;
import java.awt.SecondaryLoop;
import java.awt.GraphicsEnvironment;
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.event.AWTEventListener;
import java.awt.event.ComponentEvent;
Expand Down Expand Up @@ -604,6 +604,15 @@ protected void processComponentEvent(ComponentEvent e) {
super.processComponentEvent(e);
}

private AffineTransform getCurrentTransform() {
GraphicsConfiguration config = getGraphicsConfiguration();
if (config == null) {
config = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
return config.getDefaultTransform();
}

// called on EDT only
private void updateComponentSize() {
int oldWidth = pWidth;
Expand All @@ -617,15 +626,10 @@ private void updateComponentSize() {
// what JavaFX embedded scenes/stages are ready to
pWidth = Math.max(0, getWidth());
pHeight = Math.max(0, getHeight());
double newScaleFactorX = scaleFactorX;
double newScaleFactorY = scaleFactorY;
Graphics g = getGraphics();
newScaleFactorX = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getDefaultTransform().getScaleX();
newScaleFactorY = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getDefaultTransform().getScaleY();
AffineTransform trnsForm = getCurrentTransform();
double newScaleFactorX = trnsForm.getScaleX();
double newScaleFactorY = trnsForm.getScaleY();
if (oldWidth == 0 && oldHeight == 0 && pWidth == 0 && pHeight == 0) {
return;
}
Expand Down Expand Up @@ -818,14 +822,9 @@ protected void paintComponent(Graphics g) {
}
gg.drawImage(pixelsIm, 0, 0, pWidth, pHeight, null);

double newScaleFactorX = scaleFactorX;
double newScaleFactorY = scaleFactorY;
newScaleFactorX = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getDefaultTransform().getScaleX();
newScaleFactorY = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().
getDefaultTransform().getScaleY();
AffineTransform trnsForm = getCurrentTransform();
double newScaleFactorX = trnsForm.getScaleX();
double newScaleFactorY = trnsForm.getScaleY();
if (scaleFactorX != newScaleFactorX || scaleFactorY != newScaleFactorY) {
createResizePixelBuffer(newScaleFactorX, newScaleFactorY);
// The scene will request repaint.
Expand Down

1 comment on commit 6a7c743

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.