Skip to content

Commit aae8b6b

Browse files
Merge
2 parents 9260fd1 + 3cc29e3 commit aae8b6b

File tree

8 files changed

+358
-11
lines changed

8 files changed

+358
-11
lines changed

build.gradle

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,8 +2574,18 @@ project(":swing") {
25742574

25752575
sourceSets {
25762576
main
2577-
//shims // no test shims needed
2578-
test
2577+
shims {
2578+
java {
2579+
compileClasspath += sourceSets.main.output
2580+
runtimeClasspath += sourceSets.main.output
2581+
}
2582+
}
2583+
test {
2584+
java {
2585+
compileClasspath += sourceSets.shims.output
2586+
runtimeClasspath += sourceSets.shims.output
2587+
}
2588+
}
25792589
}
25802590

25812591
project.ext.moduleSourcePath = defaultModuleSourcePath

modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleTimer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* Monocle implementation class for Timer.
3535
*/
3636
final class MonocleTimer extends Timer {
37+
private static final String THREAD_NAME = "Monocle Timer";
38+
3739
private static ScheduledThreadPoolExecutor scheduler;
3840
private ScheduledFuture<?> task;
3941

@@ -51,7 +53,11 @@ static int getMaxPeriod_impl() {
5153

5254
@Override protected long _start(final Runnable runnable, int period) {
5355
if (scheduler == null) {
54-
scheduler = new ScheduledThreadPoolExecutor(1);
56+
scheduler = new ScheduledThreadPoolExecutor(1, target -> {
57+
Thread thread = new Thread(target, THREAD_NAME);
58+
thread.setDaemon(true);
59+
return thread;
60+
});
5561
}
5662

5763
task = scheduler.scheduleAtFixedRate(runnable, 0, period, TimeUnit.MILLISECONDS);

modules/javafx.graphics/src/main/java/com/sun/javafx/tk/quantum/EmbeddedScene.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ public boolean getPixels(final IntBuffer dest, final int width, final int height
231231
{
232232
return false;
233233
}
234-
scaledWidth = Math.round(scaledWidth * texScaleFactorX);
235-
scaledHeight = Math.round(scaledHeight * texScaleFactorY);
234+
scaledWidth = (int) Math.ceil(scaledWidth * texScaleFactorX);
235+
scaledHeight = (int) Math.ceil(scaledHeight * texScaleFactorY);
236236

237237
dest.rewind();
238238
texBits.rewind();

modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ private void createResizePixelBuffer(double newScaleFactorX, double newScaleFact
687687
double ratioX = newScaleFactorX / scaleFactorX;
688688
double ratioY = newScaleFactorY / scaleFactorY;
689689
// Transform old size to the new coordinate space.
690-
int oldW = (int)Math.round(oldIm.getWidth() * ratioX);
691-
int oldH = (int)Math.round(oldIm.getHeight() * ratioY);
690+
int oldW = (int)Math.ceil(oldIm.getWidth() * ratioX);
691+
int oldH = (int)Math.ceil(oldIm.getHeight() * ratioY);
692692

693693
Graphics g = pixelsIm.getGraphics();
694694
try {
@@ -932,6 +932,11 @@ private void invokeOnClientEDT(Runnable r) {
932932
jfxPanelIOP.postEvent(this, new InvocationEvent(this, r));
933933
}
934934

935+
// Package scope method for testing
936+
final BufferedImage test_getPixelsIm() {
937+
return pixelsIm;
938+
}
939+
935940
private class HostContainer implements HostInterface {
936941

937942
@Override
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package javafx.embed.swing;
26+
27+
import java.awt.image.BufferedImage;
28+
29+
public class JFXPanelShim {
30+
31+
public static BufferedImage getPixelsIm(JFXPanel panel) {
32+
return panel.test_getPixelsIm();
33+
}
34+
35+
}

modules/javafx.swt/src/main/java/javafx/embed/swt/FXCanvas.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ private void paintControl(PaintEvent pe) {
634634
height = lastHeight;
635635
buffer = lastPixelsBuf;
636636
}
637-
width = (int)Math.round(width * scaleFactor);
638-
height = (int)Math.round(height * scaleFactor);
637+
width = (int)Math.ceil(width * scaleFactor);
638+
height = (int)Math.ceil(height * scaleFactor);
639639

640640
// Consider optimizing this
641641
ImageData imageData = null;
@@ -1053,8 +1053,8 @@ private void resizePixelBuffer(double newScaleFactor) {
10531053
if ((pWidth <= 0) || (pHeight <= 0)) {
10541054
pixelsBuf = null;
10551055
} else {
1056-
pixelsBuf = IntBuffer.allocate((int)Math.round(pWidth * newScaleFactor) *
1057-
(int)Math.round(pHeight * newScaleFactor));
1056+
pixelsBuf = IntBuffer.allocate((int)Math.ceil(pWidth * newScaleFactor) *
1057+
(int)Math.ceil(pHeight * newScaleFactor));
10581058
// The bg color may show through on resize. See RT-34380.
10591059
RGB rgb = getBackground().getRGB();
10601060
Arrays.fill(pixelsBuf.array(), rgb.red << 16 | rgb.green << 8 | rgb.blue);
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package test.javafx.embed.swt;
27+
28+
import static org.junit.Assert.fail;
29+
30+
import java.util.Timer;
31+
import java.util.TimerTask;
32+
33+
import org.eclipse.swt.SWT;
34+
import org.eclipse.swt.graphics.GC;
35+
import org.eclipse.swt.graphics.Image;
36+
import org.eclipse.swt.graphics.PaletteData;
37+
import org.eclipse.swt.graphics.RGB;
38+
import org.eclipse.swt.layout.FillLayout;
39+
import org.eclipse.swt.widgets.Display;
40+
import org.eclipse.swt.widgets.Shell;
41+
import org.junit.Test;
42+
43+
import javafx.embed.swt.FXCanvas;
44+
import javafx.scene.Scene;
45+
import javafx.scene.layout.Region;
46+
47+
public class FXCanvasScaledTest {
48+
49+
private int cnt;
50+
51+
static Shell shell;
52+
53+
static Display display;
54+
55+
/* Base size, so that with a scaling of 125% there are different results for Math.round and Math.ceil */
56+
final static int TARGET_BASE_SIZE = 101;
57+
58+
@Test(timeout = 10000)
59+
public void testScale() throws Throwable {
60+
System.setProperty("sun.java2d.uiScale.enabled", "true");
61+
System.setProperty("sun.java2d.uiScale", "125%");
62+
System.setProperty("glass.win.uiScale", "125%");
63+
System.setProperty("glass.win.renderScale", "125%");
64+
System.setProperty("glass.gtk.uiScale", "1.25");
65+
System.setProperty("swt.autoScale", "125");
66+
67+
// Start the Application
68+
display = new Display();
69+
shell = new Shell(display);
70+
shell.setLayout(new FillLayout());
71+
final FXCanvas canvas = new FXCanvas(shell, SWT.NONE);
72+
initFX(canvas);
73+
74+
Timer t = new Timer();
75+
TimerTask task = new TimerTask() {
76+
@Override
77+
public void run() {
78+
switch (cnt) {
79+
case 0:
80+
display.asyncExec(() -> canvas.setBounds(0, 0, 201, 201));
81+
break;
82+
case 1:
83+
display.asyncExec(() -> canvas.setBounds(0, 0, TARGET_BASE_SIZE, TARGET_BASE_SIZE));
84+
break;
85+
case 2:
86+
t.cancel();
87+
display.asyncExec(() -> {
88+
// Capture painted component. Bounds are in pt, so size is 101 and not 127
89+
GC gc = new GC(canvas);
90+
final Image image = new Image(display, canvas.getBounds());
91+
gc.copyArea(image, canvas.getBounds().x, canvas.getBounds().y);
92+
gc.dispose();
93+
PaletteData palette = image.getImageData().palette;
94+
int referenceWhitePixel = image.getImageData().getPixel(0, 0);
95+
RGB referenceRGB = palette.getRGB(referenceWhitePixel);
96+
// check if there is a diagonal, which should be the right border
97+
for (int x = 10; x < 30; x++) {
98+
for (int y = 80; y < 100; y++) {
99+
int pixel = image.getImageData().getPixel(x, y);
100+
RGB rgb = palette.getRGB(pixel);
101+
if (!referenceRGB.equals(rgb)) {
102+
fail("image is skewed");
103+
}
104+
}
105+
}
106+
shell.close();
107+
});
108+
break;
109+
}
110+
cnt++;
111+
}
112+
};
113+
t.schedule(task, 500, 500);
114+
115+
shell.open();
116+
while (!shell.isDisposed()) {
117+
if (!display.readAndDispatch())
118+
display.sleep();
119+
}
120+
display.dispose();
121+
}
122+
123+
private static void initFX(FXCanvas canvas) {
124+
Region region = new Region();
125+
region.setStyle("-fx-background-color: #FFFFFF;" + "-fx-border-color: #000000;" + "-fx-border-width: 0 5px 0 0;"
126+
+ "-fx-border-style: solid");
127+
Scene scene = new Scene(region);
128+
canvas.setScene(scene);
129+
canvas.setBounds(0, 0, 100, 100);
130+
}
131+
}

0 commit comments

Comments
 (0)