Skip to content

Commit 89da202

Browse files
committed
8266159: macOS ARM + Metal pipeline shows artifacts on Swing Menu with Java L&F
Reviewed-by: jdv, prr
1 parent 61ab4b9 commit 89da202

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/shaders.metal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct AAVertexInput {
4646

4747
struct ColShaderInOut {
4848
float4 position [[position]];
49+
float ptSize [[point_size]];
4950
half4 color;
5051
};
5152

@@ -58,6 +59,7 @@ struct AAShaderInOut {
5859

5960
struct StencilShaderInOut {
6061
float4 position [[position]];
62+
float ptSize [[point_size]];
6163
char color;
6264
};
6365

@@ -81,6 +83,7 @@ struct GradShaderInOut {
8183

8284
struct ColShaderInOut_XOR {
8385
float4 position [[position]];
86+
float ptSize [[point_size]];
8487
float2 orig_pos;
8588
half4 color;
8689
};
@@ -164,6 +167,7 @@ vertex ColShaderInOut vert_col(VertexInput in [[stage_in]],
164167
ColShaderInOut out;
165168
float4 pos4 = float4(in.position, 0.0, 1.0);
166169
out.position = transform.transformMatrix*pos4;
170+
out.ptSize = 1.0;
167171
out.color = half4(uniforms.color.r, uniforms.color.g, uniforms.color.b, uniforms.color.a);
168172
return out;
169173
}
@@ -186,6 +190,7 @@ vertex StencilShaderInOut vert_stencil(VertexInput in [[stage_in]],
186190
StencilShaderInOut out;
187191
float4 pos4 = float4(in.position, 0.0, 1.0);
188192
out.position = transform.transformMatrix * pos4;
193+
out.ptSize = 1.0;
189194
out.color = 0xFF;
190195
return out;
191196
}
@@ -671,6 +676,7 @@ vertex ColShaderInOut_XOR vert_col_xorMode(VertexInput in [[stage_in]],
671676
ColShaderInOut_XOR out;
672677
float4 pos4 = float4(in.position, 0.0, 1.0);
673678
out.position = transform.transformMatrix*pos4;
679+
out.ptSize = 1.0;
674680
out.orig_pos = in.position;
675681
out.color = half4(uniforms.color.r, uniforms.color.g, uniforms.color.b, uniforms.color.a);
676682
return out;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2021, 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.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @key headful
27+
* @bug 8266159
28+
* @summary Test to detect regression in pixel drawing.
29+
* A small circle is drawn and boundary pixels are compared to expected pixels.
30+
* Note : this test is specifically written for uiScale=1.0
31+
* @run main/othervm -Dsun.java2d.uiScale=1.0 DrawOvalTest
32+
*/
33+
34+
import javax.imageio.ImageIO;
35+
import java.awt.Color;
36+
import java.awt.Graphics2D;
37+
import java.awt.GraphicsConfiguration;
38+
import java.awt.GraphicsEnvironment;
39+
import java.awt.Transparency;
40+
import java.awt.image.BufferedImage;
41+
import java.awt.image.VolatileImage;
42+
import java.io.File;
43+
import java.io.IOException;
44+
45+
public class DrawOvalTest {
46+
public static void main(String[] args) throws IOException {
47+
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
48+
.getDefaultScreenDevice().getDefaultConfiguration();
49+
VolatileImage vi = gc.createCompatibleVolatileImage(10, 10, Transparency.TRANSLUCENT);
50+
51+
// Draw test rendering sequence
52+
BufferedImage snapshot = null;
53+
Graphics2D g2 = vi.createGraphics();
54+
55+
do {
56+
vi.validate(gc);
57+
render(g2);
58+
snapshot = vi.getSnapshot();
59+
} while (vi.contentsLost());
60+
61+
// Pixel color sequence expected after test rendering is complete
62+
// Blue color = -16776961
63+
// Red color = -65536
64+
int sequence[] = {
65+
-16776961,
66+
-16776961,
67+
-16776961,
68+
-65536,
69+
-65536,
70+
-65536,
71+
-65536,
72+
-16776961,
73+
-16776961,
74+
-16776961
75+
};
76+
77+
// Test the color of pixels at the image boundary
78+
for (int i = 0; i < snapshot.getWidth(); i++) {
79+
80+
// Test first row, last row, first column and last column
81+
if ( snapshot.getRGB(i, 0) != sequence[i] ||
82+
snapshot.getRGB(i, 9) != sequence[i] ||
83+
snapshot.getRGB(0, i) != sequence[i] ||
84+
snapshot.getRGB(9, i) != sequence[i] ) {
85+
ImageIO.write(snapshot, "png", new File("DrawOvalTest_snapshot.png"));
86+
throw new RuntimeException("Test failed.");
87+
}
88+
}
89+
}
90+
91+
private static void render(Graphics2D g2) {
92+
g2.setColor(Color.BLUE);
93+
g2.fillRect(0, 0, 10, 10);
94+
g2.setColor(Color.RED);
95+
g2.drawOval(0, 0, 9, 9);
96+
}
97+
}

0 commit comments

Comments
 (0)