430N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
430N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
430N/A *
430N/A * This code is free software; you can redistribute it and/or modify it
430N/A * under the terms of the GNU General Public License version 2 only, as
430N/A * published by the Free Software Foundation.
430N/A *
430N/A * This code is distributed in the hope that it will be useful, but WITHOUT
430N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
430N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
430N/A * version 2 for more details (a copy is included in the LICENSE file that
430N/A * accompanied this code).
430N/A *
430N/A * You should have received a copy of the GNU General Public License version
430N/A * 2 along with this work; if not, write to the Free Software Foundation,
430N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
430N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
430N/A */
430N/A
430N/A/**
430N/A * @test
430N/A * @bug 6705443
430N/A * @summary tests that we don't crash during exit if font strikes were disposed
430N/A * during the lifetime of the application
430N/A *
430N/A * @run main/othervm -Dsun.java2d.font.reftype=weak StrikeDisposalCrashTest
430N/A * @run main/othervm -Dsun.java2d.font.reftype=weak -Dsun.java2d.noddraw=true StrikeDisposalCrashTest
430N/A * @run main/othervm -Dsun.java2d.font.reftype=weak -Dsun.java2d.opengl=True StrikeDisposalCrashTest
430N/A */
430N/A
430N/Aimport java.awt.Font;
430N/Aimport java.awt.Frame;
430N/Aimport java.awt.Graphics2D;
430N/Aimport java.awt.GraphicsConfiguration;
430N/Aimport java.awt.GraphicsDevice;
430N/Aimport java.awt.GraphicsEnvironment;
430N/Aimport java.awt.RenderingHints;
430N/Aimport java.awt.Toolkit;
430N/Aimport java.awt.image.VolatileImage;
430N/A
430N/Apublic class StrikeDisposalCrashTest {
430N/A
430N/A public static void main(String[] args) {
430N/A System.setProperty("sun.java2d.font.reftype", "weak");
430N/A
430N/A GraphicsDevice gd[] =
430N/A GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
430N/A
430N/A Frame frames[] = new Frame[gd.length];
430N/A for (int i = 0; i < frames.length; i++) {
430N/A GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
430N/A Frame f = new Frame("Frame on "+gc, gc);
430N/A f.setSize(100, 100);
430N/A f.setLocation(gc.getBounds().x, gc.getBounds().y);
430N/A f.pack();
430N/A frames[i] = f;
430N/A }
430N/A
430N/A Font f1 = new Font("Dialog", Font.PLAIN, 10);
430N/A Font f2 = new Font("Dialog", Font.ITALIC, 12);
430N/A
430N/A for (int i = 0; i < frames.length/2; i++) {
430N/A // making sure the glyphs are cached in the accel. cache on
430N/A // one frame, then the other
430N/A renderText(frames[i], f1);
430N/A renderText(frames[frames.length -1 - i], f1);
430N/A
430N/A // and now the other way around, with different glyphs
430N/A renderText(frames[frames.length -1 - i], f2);
430N/A renderText(frames[i], f2);
430N/A }
430N/A
430N/A // try to force strike disposal (note that we have to use
430N/A // -Dsun.java2d.font.reftype=weak to facilitate the disposal)
430N/A
430N/A System.gc();
430N/A System.runFinalization();
430N/A System.gc();
430N/A System.runFinalization();
430N/A
430N/A for (Frame f : frames) {
430N/A f.dispose();
430N/A }
430N/A
430N/A System.err.println("Exiting. If the test crashed after this it FAILED");
430N/A }
430N/A
430N/A private static final String text =
430N/A "The quick brown fox jumps over the lazy dog 1234567890";
430N/A private static void renderText(Frame frame, Font f1) {
430N/A VolatileImage vi = frame.createVolatileImage(256, 32);
430N/A vi.validate(frame.getGraphicsConfiguration());
430N/A
430N/A Graphics2D g = vi.createGraphics();
430N/A g.setFont(f1);
430N/A g.drawString(text, 0, vi.getHeight()/2);
430N/A g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
430N/A RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
430N/A g.drawString(text, 0, vi.getHeight()/2);
430N/A g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
430N/A RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
430N/A g.drawString(text, 0, vi.getHeight()/2);
430N/A Toolkit.getDefaultToolkit().sync();
430N/A }
430N/A}