Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/java2d/DrawXORModeTest.java
38833 views
/*1* Copyright (c) 2014, 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*/2223/*24* @test25* @bug 803602226* @summary Test verifies that drawing shapes with XOR composite27* does not trigger an InternalError in GDI surface data.28* @run main/othervm -Dsun.java2d.d3d=True DrawXORModeTest29*/30import java.awt.BasicStroke;31import java.awt.Color;32import java.awt.Component;33import java.awt.Dimension;34import java.awt.Frame;35import java.awt.Graphics;36import java.awt.Graphics2D;37import java.awt.Stroke;38import java.awt.geom.Line2D;39import java.util.concurrent.CountDownLatch;4041public class DrawXORModeTest extends Component {4243public static void main(String[] args) {44final DrawXORModeTest c = new DrawXORModeTest();4546final Frame f = new Frame("XOR mode test");47f.add(c);48f.pack();4950f.setVisible(true);5152try {53c.checkResult();54} finally {55f.dispose();56}57}5859@Override60public void paint(Graphics g) {61if (g == null || !(g instanceof Graphics2D)) {62return;63}64g.setColor(Color.white);65g.setXORMode(Color.black);66Graphics2D dg = (Graphics2D) g;67Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,68BasicStroke.JOIN_MITER,6910.0f,70new float[]{1.0f, 1.0f},710.0f);72dg.setStroke(stroke);73try {74dg.draw(new Line2D.Float(10, 10, 20, 20));75} catch (Throwable e) {76synchronized (this) {77theError = e;78}79} finally {80didDraw.countDown();81}82}8384@Override85public Dimension getPreferredSize() {86return new Dimension(400, 100);87}8889public void checkResult() {90try {91didDraw.await();92} catch (InterruptedException e) {93}9495synchronized (this) {96if (theError != null) {97System.out.println("Error: " + theError);9899throw new RuntimeException("Test FAILED.");100}101}102System.out.println("Test PASSED.");103104}105106private Throwable theError = null;107108private final CountDownLatch didDraw = new CountDownLatch(1);109}110111112