6728834: D3D/OGL: LCD AA text becomes bold and blurred when rendering to a non-opaque destination
Reviewed-by: campbell
--- a/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java Mon Aug 04 18:50:43 2008 +0400
+++ b/jdk/src/share/classes/sun/java2d/opengl/OGLSurfaceData.java Mon Aug 04 11:29:28 2008 -0700
@@ -401,6 +401,7 @@
* - the fragment shader extension is available, and
* - blending is disabled, and
* - the source color is opaque
+ * - and the destination is opaque
*
* Eventually, we could enhance the native OGL text rendering code
* and remove the above restrictions, but that would require significantly
@@ -410,7 +411,8 @@
return
graphicsConfig.isCapPresent(CAPS_EXT_LCD_SHADER) &&
sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
- sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR;
+ sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR &&
+ sg2d.surfaceData.getTransparency() == Transparency.OPAQUE;
}
public void validatePipe(SunGraphics2D sg2d) {
--- a/jdk/src/windows/classes/sun/java2d/d3d/D3DSurfaceData.java Mon Aug 04 18:50:43 2008 +0400
+++ b/jdk/src/windows/classes/sun/java2d/d3d/D3DSurfaceData.java Mon Aug 04 11:29:28 2008 -0700
@@ -501,12 +501,14 @@
* - the pixel shaders are available, and
* - blending is disabled, and
* - the source color is opaque
+ * - and the destination is opaque
*/
public boolean canRenderLCDText(SunGraphics2D sg2d) {
return
graphicsDevice.isCapPresent(CAPS_LCD_SHADER) &&
sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
- sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR;
+ sg2d.paintState <= SunGraphics2D.PAINT_OPAQUECOLOR &&
+ sg2d.surfaceData.getTransparency() == Transparency.OPAQUE;
}
public void validatePipe(SunGraphics2D sg2d) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/sun/java2d/DirectX/NonOpaqueDestLCDAATest/NonOpaqueDestLCDAATest.java Mon Aug 04 11:29:28 2008 -0700
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6728834
+ * @summary Tests that LCD AA text rendering works properly with destinations
+ * being VolatileImage of all transparency types
+ * @author Dmitri.Trembovetski: area=Graphics
+ * @run main/manual/othervm NonOpaqueDestLCDAATest
+ * @run main/manual/othervm -Dsun.java2d.opengl=True NonOpaqueDestLCDAATest
+ */
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.GraphicsConfiguration;
+import java.awt.RenderingHints;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.image.VolatileImage;
+import java.io.File;
+import java.util.concurrent.CountDownLatch;
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JTextArea;
+import static java.awt.Transparency.*;
+
+public class NonOpaqueDestLCDAATest extends JFrame implements ActionListener {
+ private static volatile boolean passed = true;
+ private static CountDownLatch complete = new CountDownLatch(1);
+
+ public NonOpaqueDestLCDAATest() {
+ JTextArea desc = new JTextArea();
+ desc.setText(
+ "\n Instructions: the three text strings below should appear\n" +
+ " readable, without smudges or misshapen bold glyphs.\n\n" +
+ " If they look fine the test PASSED otherwise it FAILED.\n");
+ desc.setEditable(false);
+ desc.setBackground(Color.black);
+ desc.setForeground(Color.green);
+ add("North", desc);
+ JPanel renderPanel = new JPanel() {
+ public void paintComponent(Graphics g) {
+ render(g, getWidth(), getHeight());
+ }
+ };
+ renderPanel.setPreferredSize(new Dimension(350, 150));
+ renderPanel.addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent e) {
+ images = null;
+ }
+ });
+ add("Center", renderPanel);
+
+ JButton passed = new JButton("Passed");
+ JButton failed = new JButton("Failed");
+ passed.addActionListener(this);
+ failed.addActionListener(this);
+ JPanel p = new JPanel();
+ p.add(passed);
+ p.add(failed);
+ add("South", p);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ complete.countDown();
+ }
+ });
+ setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ }
+
+ public void render(Graphics g, int w, int h) {
+ initImages(w, h);
+
+ Graphics2D g2d = (Graphics2D) g.create();
+ for (VolatileImage vi : images) {
+ g2d.drawImage(vi, 0, 0, null);
+ g2d.translate(0, vi.getHeight());
+ }
+ }
+
+ String tr[] = { "OPAQUE", "BITMASK", "TRANSLUCENT" };
+ public void actionPerformed(ActionEvent e) {
+ if (e.getActionCommand().equals("Passed")) {
+ passed = true;
+ System.out.println("Test Passed");
+ } else if (e.getActionCommand().equals("Failed")) {
+ System.out.println("Test Failed");
+ for (int i = 0; i < images.length; i++) {
+ String f = "NonOpaqueDestLCDAATest_"+tr[i]+".png";
+ try {
+ ImageIO.write(images[i].getSnapshot(), "png", new File(f));
+ System.out.printf("Dumped %s image to %s\n", tr[i], f);
+ } catch (Throwable t) {}
+ }
+ passed = false;
+ }
+ dispose();
+ complete.countDown();
+ }
+
+ static void clear(Graphics2D g, int w, int h) {
+ Graphics2D gg = (Graphics2D) g.create();
+ gg.setColor(new Color(0, 0, 0, 0));
+ gg.setComposite(AlphaComposite.Src);
+ gg.fillRect(0, 0, w, h);
+ }
+
+ VolatileImage images[];
+ private void initImages(int w, int h) {
+ if (images == null) {
+ images = new VolatileImage[3];
+ GraphicsConfiguration gc = getGraphicsConfiguration();
+ for (int i = OPAQUE; i <= TRANSLUCENT; i++) {
+ VolatileImage vi =
+ gc.createCompatibleVolatileImage(w,h/3,i);
+ images[i-1] = vi;
+ vi.validate(gc);
+ Graphics2D g2d = (Graphics2D) vi.getGraphics();
+ if (i > OPAQUE) {
+ clear(g2d, vi.getWidth(), vi.getHeight());
+ }
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
+ String s = "LCD AA Text rendered to "+tr[i-1]+ " destination";
+ g2d.drawString(s, 10, vi.getHeight()/2);
+ }
+ }
+ }
+
+ public static void main(String[] args) throws InterruptedException {
+ EventQueue.invokeLater(new Runnable() {
+ public void run() {
+ NonOpaqueDestLCDAATest t = new NonOpaqueDestLCDAATest();
+ t.pack();
+ t.setVisible(true);
+ }
+ });
+
+ complete.await();
+ if (!passed) {
+ throw new RuntimeException("Test Failed!");
+ }
+ }
+}