OpenJDK / jdk / jdk
changeset 1726:6b8261d50f69
6749060: LCD AA text rendered incorrectly when destination is non opaque (sw pipeline only)
Reviewed-by: campbell, prr
author | tdv |
---|---|
date | Thu, 09 Oct 2008 17:12:50 -0700 |
parents | 3be564c67d63 |
children | 5e5e0235b14f |
files | jdk/src/share/classes/sun/java2d/SurfaceData.java jdk/test/sun/java2d/DirectX/NonOpaqueDestLCDAATest/NonOpaqueDestLCDAATest.java |
diffstat | 2 files changed, 70 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/jdk/src/share/classes/sun/java2d/SurfaceData.java Wed Sep 24 11:58:21 2008 -0700 +++ b/jdk/src/share/classes/sun/java2d/SurfaceData.java Thu Oct 09 17:12:50 2008 -0700 @@ -449,7 +449,8 @@ // For now the answer can only be true in the following cases: if (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY && sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR && - sg2d.clipState <= SunGraphics2D.CLIP_RECTANGULAR) + sg2d.clipState <= SunGraphics2D.CLIP_RECTANGULAR && + sg2d.surfaceData.getTransparency() == Transparency.OPAQUE) { if (haveLCDLoop == LCDLOOP_UNKNOWN) { DrawGlyphListLCD loop =
--- a/jdk/test/sun/java2d/DirectX/NonOpaqueDestLCDAATest/NonOpaqueDestLCDAATest.java Wed Sep 24 11:58:21 2008 -0700 +++ b/jdk/test/sun/java2d/DirectX/NonOpaqueDestLCDAATest/NonOpaqueDestLCDAATest.java Thu Oct 09 17:12:50 2008 -0700 @@ -23,10 +23,11 @@ /* * @test - * @bug 6728834 + * @bug 6728834 6749060 * @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 -Dsun.java2d.d3d=false NonOpaqueDestLCDAATest * @run main/manual/othervm NonOpaqueDestLCDAATest * @run main/manual/othervm -Dsun.java2d.opengl=True NonOpaqueDestLCDAATest */ @@ -35,9 +36,11 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; +import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; +import java.awt.Image; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -45,6 +48,7 @@ import java.awt.event.ComponentEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; import java.awt.image.VolatileImage; import java.io.File; import java.util.concurrent.CountDownLatch; @@ -62,35 +66,43 @@ 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"); + "\n Instructions: the three text strings below should appear" + + " readable, without smudges or misshapen bold glyphs.\n" + + " You may need a magnifier to notice some bad colorfringing in "+ + " in SW Translucent case, especially in vertical stems.\n\n"+ + " Basically text rendered to TRANSLUCENT destination should look"+ + " similar to one rendered to OPAQUE - it may differ in whether or" + + " not it's LCD, but it should look 'correct'\n\n"+ + "If the text looks 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() { + @Override public void paintComponent(Graphics g) { render(g, getWidth(), getHeight()); } }; - renderPanel.setPreferredSize(new Dimension(350, 150)); + renderPanel.setPreferredSize(new Dimension(1024, 650)); renderPanel.addComponentListener(new ComponentAdapter() { + @Override 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); + JButton passedBtn = new JButton("Passed"); + JButton failedBtn = new JButton("Failed"); + passedBtn.addActionListener(this); + failedBtn.addActionListener(this); JPanel p = new JPanel(); - p.add(passed); - p.add(failed); + p.add(passedBtn); + p.add(failedBtn); add("South", p); addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { complete.countDown(); } @@ -101,14 +113,18 @@ public void render(Graphics g, int w, int h) { initImages(w, h); + g.setColor(new Color(0xAD, 0xD8, 0xE6)); + g.fillRect(0, 0, w, h); + Graphics2D g2d = (Graphics2D) g.create(); - for (VolatileImage vi : images) { - g2d.drawImage(vi, 0, 0, null); - g2d.translate(0, vi.getHeight()); + for (Image im : images) { + g2d.drawImage(im, 0, 0, null); + g2d.translate(0, im.getHeight(null)); } } String tr[] = { "OPAQUE", "BITMASK", "TRANSLUCENT" }; + @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("Passed")) { passed = true; @@ -116,9 +132,17 @@ } 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"; + String f = "NonOpaqueDestLCDAATest_"+tr[i]; try { - ImageIO.write(images[i].getSnapshot(), "png", new File(f)); + if (images[i] instanceof VolatileImage) { + f += "_vi.png"; + ImageIO.write(((VolatileImage)images[i]). + getSnapshot(), "png", new File(f)); + } else { + f += "_bi.png"; + ImageIO.write((BufferedImage)images[i], + "png", new File(f)); + } System.out.printf("Dumped %s image to %s\n", tr[i], f); } catch (Throwable t) {} } @@ -128,37 +152,51 @@ complete.countDown(); } - static void clear(Graphics2D g, int w, int h) { + static void clear(Graphics2D g, int type, int w, int h) { Graphics2D gg = (Graphics2D) g.create(); - gg.setColor(new Color(0, 0, 0, 0)); - gg.setComposite(AlphaComposite.Src); + if (type > OPAQUE) { + gg.setColor(new Color(0, 0, 0, 0)); + gg.setComposite(AlphaComposite.Src); + } else { + gg.setColor(new Color(0xAD, 0xD8, 0xE6)); + } gg.fillRect(0, 0, w, h); } - VolatileImage images[]; + private void render(Image im, int type, String s) { + Graphics2D g2d = (Graphics2D) im.getGraphics(); + clear(g2d, type, im.getWidth(null), im.getHeight(null)); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); + Font f = new Font("Dialog", Font.BOLD, 40);// g2d.getFont().deriveFont(32.0f); + g2d.setColor(Color.white); + g2d.setFont(g2d.getFont().deriveFont(36.0f)); + g2d.drawString(s, 10, im.getHeight(null) / 2); + } + + Image images[]; private void initImages(int w, int h) { if (images == null) { - images = new VolatileImage[3]; + images = new Image[6]; GraphicsConfiguration gc = getGraphicsConfiguration(); for (int i = OPAQUE; i <= TRANSLUCENT; i++) { VolatileImage vi = - gc.createCompatibleVolatileImage(w,h/3,i); + gc.createCompatibleVolatileImage(w,h/images.length,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); + String s = "LCD AA Text rendered to " + tr[i - 1] + " HW destination"; + render(vi, i, s); + + s = "LCD AA Text rendered to " + tr[i - 1] + " SW destination"; + images[i-1+3] = gc.createCompatibleImage(w, h/images.length, i); + render(images[i-1+3], i, s); } } } public static void main(String[] args) throws InterruptedException { EventQueue.invokeLater(new Runnable() { + @Override public void run() { NonOpaqueDestLCDAATest t = new NonOpaqueDestLCDAATest(); t.pack();