Path: blob/master/test/jdk/sun/java2d/marlin/OpenJDKFillBug.java
41149 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.awt.Color;23import java.awt.Composite;24import java.awt.CompositeContext;25import java.awt.Graphics2D;26import java.awt.RenderingHints;27import java.awt.geom.AffineTransform;28import java.awt.geom.GeneralPath;29import java.awt.image.BufferedImage;30import java.awt.image.ColorModel;31import java.awt.image.Raster;32import java.awt.image.WritableRaster;33import java.awt.image.RasterFormatException;3435/**36* @test37* @bug 804878238* @summary Test program that demonstrates PiscesRendering bug in39* OpenJDK 1.7.0.60 (and probably in all other OpenJDK versions, too).40*/4142public class OpenJDKFillBug43{44/**45* Test program that demonstrates a bug in OpenJDK 1.7.0.60 (and46* probably in all other OpenJDK versions, too). To see the bug, simply run47* the 'main' program with OpenJDK. The bug makes the 'g2d.fill'48* method fail with the following exception:49*50* This bug is found in OpenJDK but also is present in OracleJDK51* if run with52* -Dsun.java2d.renderer=sun.java2d.pisces.PiscesRenderingEngine53*54* The bug is related to sun.java2d.pisces.PiscesCache constructor55* that accepts '(int minx,int miny,int maxx,int maxy)' arguments:56* the internal 'bboxX1' and 'bboxY1' are set to values one greater57* than given maximum X and Y values. Those maximum values are then58* later used in AAShapePipe' class 'renderTiles' method, where a59* Y/X loop eventually calls 'GeneralCompositePipe' class60* 'renderPathTile' method. In that method, the operation will61* eventually call 'IntegerInterleavedRaster' class62* 'createWritableChild' method with arguments:63*64* <UL>65* <LI>x=80066* <LI>y=067* <LI>width=2 (this value is too high: should be 1)68* <LI>height=3269* <LI>x0=070* <LI>y0=071* <LI>bandList[]=null72* </UL>73*74* This calls for a sub-raster with bounds that fall outside the75* original raster, and therefore the 'createWritableChild' method76* correctly throws 'RasterFormatException'.77*78* The bug is closely related to the use of a custom Composite79* implementation, which are quite rare. The application where this80* bug was first detected implements a high-quality PDF rendering81* engine that needs custom Composite operations to properly82* implement PDF advanced color blending and masking operators.83*/8485public static void main(String args[])86{87BufferedImage bi = new BufferedImage(801,1202,88BufferedImage.TYPE_INT_ARGB);89Graphics2D g2d = bi.createGraphics();90GeneralPath gp = new GeneralPath();91AffineTransform m = new AffineTransform(2.483489907915543,920.0,930.0,94-2.4844977263331955,950.0,961202.0);97Composite c = new CustomComposite();9899gp.moveTo(-4.511, -14.349);100gp.lineTo(327.489, -14.349);101gp.lineTo(327.489, 494.15);102gp.lineTo(-4.511, 494.15);103gp.closePath();104105g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,106RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);107g2d.setRenderingHint(RenderingHints.KEY_RENDERING,108RenderingHints.VALUE_RENDER_QUALITY);109g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,110RenderingHints.VALUE_COLOR_RENDER_QUALITY);111g2d.setRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST,112Integer.valueOf(140));113g2d.setRenderingHint(RenderingHints.KEY_DITHERING,114RenderingHints.VALUE_DITHER_ENABLE);115g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,116RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);117g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,118RenderingHints.VALUE_ANTIALIAS_ON);119g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,120RenderingHints.VALUE_STROKE_NORMALIZE);121g2d.setPaint(Color.red);122g2d.setComposite(c);123g2d.setTransform(m);124try {125g2d.fill(gp);126} catch (RasterFormatException rfe) {127System.out.println("Test failed");128throw new RuntimeException("xmax/ymax rounding cause RasterFormatException: " + rfe);129}130g2d.dispose();131System.out.println("Test passed");132}133134// === CustomComposite ===135136/**137* Dummy custom Composite implementation.138*/139140public static class CustomComposite implements Composite141{142@Override143public CompositeContext createContext(ColorModel srcColorModel,144ColorModel dstColorModel,145RenderingHints hints)146{147return new CustomCompositeContext();148}149150// === CustomCompositeContext ===151152/**153* Dummy custom CompositeContext implementation.154*/155156public static class CustomCompositeContext implements CompositeContext157{158159@Override160public void dispose()161{162// NOP163}164165@Override166public void compose(Raster src,Raster dstIn,WritableRaster dstOut)167{168// NOP169}170}171}172}173174175