Skip to content

Commit 871b7da

Browse files
author
Alexey Ushakov
committed
8291266: RenderPerfTest: missing content while rendering some primitives
Reviewed-by: aghaisas, prr
1 parent 0c40128 commit 871b7da

File tree

2 files changed

+156
-2
lines changed

2 files changed

+156
-2
lines changed

src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderQueue.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ void MTLRenderQueue_CheckPreviousOp(jint op) {
6767
return;
6868
}
6969

70-
if (isDrawOp(mtlPreviousOp) && !isDrawOp(op)) {
70+
if (isDrawOp(mtlPreviousOp)) {
7171
// submit the vertex batch
7272
MTLRenderer_SubmitVertexBatch(mtlc, dstOps);
73-
mtlPreviousOp = op;
73+
if (isDrawOp(op)) {
74+
// Do not cause endEncoder if we continue with Draw operations
75+
mtlPreviousOp = op;
76+
return;
77+
}
7478
}
7579

7680
if (op == MTL_OP_SET_COLOR) {
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2022, JetBrains s.r.o.. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
/**
26+
* @test
27+
* @key headful
28+
* @bug 8287600 8291266
29+
* @requires os.family == "mac"
30+
* @summary [macosx] Some primitives do not render in metal pipeline
31+
* @run main DrawPrimitivesTest
32+
*/
33+
34+
import java.awt.AWTException;
35+
import java.awt.Color;
36+
import java.awt.Dimension;
37+
import java.awt.Graphics;
38+
import java.awt.Graphics2D;
39+
import java.awt.Point;
40+
import java.awt.RenderingHints;
41+
import java.awt.Robot;
42+
import java.lang.reflect.InvocationTargetException;
43+
import java.util.concurrent.CountDownLatch;
44+
import javax.swing.JFrame;
45+
import javax.swing.JPanel;
46+
import javax.swing.SwingUtilities;
47+
48+
public abstract class DrawPrimitivesTest extends JFrame {
49+
private final static int W = 800;
50+
private final static int H = 800;
51+
private final static Color[] color = { Color.RED, Color.BLUE, Color.GREEN};
52+
private final static int COLOR_TOLERANCE = 10;
53+
private final CountDownLatch latchRender = new CountDownLatch(1);
54+
private volatile int frameX0 = 0;
55+
private volatile int frameY0 = 0;
56+
private final String name;
57+
58+
59+
private static boolean isAlmostEqual(Color c1, Color c2) {
60+
return Math.abs(c1.getRed() - c2.getRed()) < COLOR_TOLERANCE &&
61+
Math.abs(c1.getGreen() - c2.getGreen()) < COLOR_TOLERANCE &&
62+
Math.abs(c1.getBlue() - c2.getBlue()) < COLOR_TOLERANCE;
63+
64+
}
65+
66+
public static void main(String[] args) throws InterruptedException, AWTException, InvocationTargetException {
67+
new DrawPrimitivesTest("drawLine") {
68+
public void renderPrimitive(Graphics2D g2d, int x0, int y0, int w, int h) {
69+
g2d.drawLine(x0, y0, x0+w, y0+h);
70+
}
71+
}.runTest();
72+
73+
new DrawPrimitivesTest("fillRect") {
74+
public void renderPrimitive(Graphics2D g2d, int x0, int y0, int w, int h) {
75+
g2d.fillRect(x0, y0, w, h);
76+
}
77+
}.runTest();
78+
79+
new DrawPrimitivesTest("fillOvalAA") {
80+
public void renderPrimitive(Graphics2D g2d, int x0, int y0, int w, int h) {
81+
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
82+
g2d.fillOval(x0, y0, w, h);
83+
}
84+
}.runTest();
85+
}
86+
87+
public abstract void renderPrimitive(Graphics2D g2d, int x0, int y0, int w, int h);
88+
89+
public DrawPrimitivesTest(String name) {
90+
super();
91+
this.name = name;
92+
}
93+
94+
public void runTest() throws InterruptedException, InvocationTargetException, AWTException {
95+
SwingUtilities.invokeLater(() -> {
96+
add(new JPanel() {
97+
@Override
98+
public Dimension getPreferredSize() {
99+
return new Dimension(W, H);
100+
}
101+
102+
@Override
103+
public void paintComponent(Graphics g) {
104+
Graphics2D g2d = (Graphics2D) g;
105+
g2d.setColor(Color.YELLOW);
106+
int c = 0;
107+
for (int i = 0; i < W; i += 10) {
108+
for (int j = 0; j < H; j += 10) {
109+
c = (c + 1) % color.length;
110+
g2d.setColor(color[c]);
111+
renderPrimitive(g2d, i, j, 10, 10);
112+
}
113+
}
114+
Point p = getLocationOnScreen();
115+
frameX0 = p.x;
116+
frameY0 = p.y - getInsets().top;
117+
118+
latchRender.countDown();
119+
}
120+
});
121+
setPreferredSize(new Dimension(W, H));
122+
pack();
123+
setVisible(true);
124+
});
125+
126+
latchRender.await();
127+
Thread.sleep(1000);
128+
129+
Robot robot = new Robot();
130+
131+
boolean hasEmptyContent = true;
132+
l:for (int i = frameX0 + W/3; i < frameX0 + (2*W)/3; i++) {
133+
for (int j = 0; j < 10; j += 2) {
134+
if (isAlmostEqual(robot.getPixelColor(i, frameY0 + H / 2 + j), Color.RED)) {
135+
hasEmptyContent = false;
136+
break l;
137+
}
138+
}
139+
}
140+
141+
SwingUtilities.invokeAndWait(() -> {
142+
setVisible(false);
143+
dispose();
144+
});
145+
146+
if (hasEmptyContent) {
147+
throw new RuntimeException(name + ": Empty content");
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)