Path: blob/master/test/jdk/sun/java2d/xrender/HugeGradientTest.java
41149 views
/*1* Copyright (c) 2014, 2017, 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*/2223import java.awt.*;24import java.awt.image.*;25import javax.swing.*;2627/**28* @test29* @key headful30* @bug 816259131* @summary tests gradients with start/endpoints exceeding Short.MAX coordinates32* @author ceisserer33*/3435public class HugeGradientTest extends Frame {36public static volatile boolean success = false;3738public HugeGradientTest() {39Image dstImg = getGraphicsConfiguration()40.createCompatibleVolatileImage(30, 30);41Graphics2D g = (Graphics2D) dstImg.getGraphics();4243g.setPaint(new LinearGradientPaint(0f, Short.MAX_VALUE, 0f, Short.MAX_VALUE +31,44new float[]{0f, 1f}, new Color[]{Color.BLACK, Color.RED}));45g.translate(0, -Short.MAX_VALUE);46g.fillRect (0, 0, Short.MAX_VALUE*2 , Short.MAX_VALUE*2);4748BufferedImage readBackImg = new BufferedImage(dstImg.getWidth(null),49dstImg.getHeight(null), BufferedImage.TYPE_INT_RGB);50readBackImg.getGraphics().drawImage(dstImg, 0, 0, null);5152for (int x = 0; x < readBackImg.getWidth(); x++) {53for (int y = 0; y < readBackImg.getHeight(); y++) {54int redVal = (readBackImg.getRGB(x, y) & 0x00FF0000) >> 16;5556if (redVal > 127) {57return;58}59}60}6162throw new RuntimeException("Test Failed");63}6465public static void main(String[] args) throws Exception {66SwingUtilities.invokeLater(new Runnable() {67public void run() {68new HugeGradientTest();69}70});71}72}737475