1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /** 26 * @test 27 * @bug 8146042 28 * @run main RenderRectTest 29 */ 30 31 import java.awt.*; 32 33 import java.awt.image.BufferedImage; 34 import java.awt.image.VolatileImage; 35 36 37 public class RenderRectTest { 38 39 public static void main(String[] args) throws Exception { 40 GraphicsConfiguration gc = 41 GraphicsEnvironment.getLocalGraphicsEnvironment(). 42 getDefaultScreenDevice().getDefaultConfiguration(); 43 VolatileImage vi = gc.createCompatibleVolatileImage(12, 12); 44 Graphics2D g = vi.createGraphics(); 45 g.setColor(Color.black); 46 g.drawRect(1, 1, 9, 9); 47 g.dispose(); 48 BufferedImage capture = vi.getSnapshot(); 49 50 int w = capture.getWidth(); 51 int h = capture.getHeight(); 52 for(int y = 0; y < h >> 1; y++) { 53 for(int x = 0; x < w >> 1; x++) { 54 if( x > 0 && y > 0 && (x == 1 || y == 1)) { 55 if((capture.getRGB(x, y) 56 | capture.getRGB(x, h - 1 - y) 57 | capture.getRGB(w - 1 - x, y) 58 | capture.getRGB(w - 1 - x, h - 1 - y)) != 59 Color.black.getRGB()) { 60 throw new RuntimeException("Wrong rectangle"); 61 } 62 } else { 63 if((capture.getRGB(x, y) 64 & capture.getRGB(x, h - 1 - y) 65 & capture.getRGB(w - 1 - x, y) 66 & capture.getRGB(w - 1 - x, h - 1 - y)) != 67 Color.white.getRGB()) { 68 throw new RuntimeException("Wrong rectangle"); 69 } 70 } 71 } 72 } 73 } 74 }