Path: blob/master/test/jdk/sun/java2d/SunGraphics2D/SurfaceDestination/SurfaceDestination.java
41153 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*/2223import java.awt.Component;24import java.awt.Frame;25import java.awt.Graphics;26import java.awt.GraphicsConfiguration;27import java.awt.GraphicsDevice;28import java.awt.GraphicsEnvironment;29import java.awt.Image;30import java.awt.Window;31import java.awt.image.BufferedImage;3233import sun.java2d.SunGraphics2D;3435import static java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment;36import static java.awt.Transparency.BITMASK;37import static java.awt.Transparency.OPAQUE;38import static java.awt.Transparency.TRANSLUCENT;39import static java.awt.image.BufferedImage.TYPE_INT_ARGB;4041/**42* @test43* @key headful44* @bug 813460345* @modules java.desktop/sun.java2d46* @run main/othervm SurfaceDestination47*/48public final class SurfaceDestination {4950public static void main(final String[] args) {51final GraphicsEnvironment lge = getLocalGraphicsEnvironment();52final GraphicsDevice dev = lge.getDefaultScreenDevice();53final GraphicsConfiguration config = dev.getDefaultConfiguration();5455test(config.createCompatibleImage(10, 10).getGraphics());56test(config.createCompatibleImage(10, 10, OPAQUE).getGraphics());57test(config.createCompatibleImage(10, 10, BITMASK).getGraphics());58test(config.createCompatibleImage(10, 10, TRANSLUCENT).getGraphics());5960test(new BufferedImage(10, 10, TYPE_INT_ARGB).getGraphics());6162final Window frame = new Frame();63frame.pack();64try {65test(frame.getGraphics());66test(frame.createImage(10, 10).getGraphics());67} finally {68frame.dispose();69}70}7172private static void test(final Graphics graphics) {73try {74if (graphics instanceof SunGraphics2D) {75final Object dst = ((SunGraphics2D) graphics).getDestination();76if (!(dst instanceof Image) && !(dst instanceof Component)) {77throw new RuntimeException("Wrong type:" + dst);78}79}80} finally {81graphics.dispose();82}83}84}858687