AppletFlipBuffer.java revision 14851:980da45565c8
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 24import java.applet.Applet; 25import java.awt.AWTException; 26import java.awt.BufferCapabilities; 27import java.awt.BufferCapabilities.FlipContents; 28import java.awt.Frame; 29import java.awt.ImageCapabilities; 30import java.util.HashSet; 31import java.util.Set; 32 33import sun.awt.AWTAccessor; 34import sun.awt.AWTAccessor.ComponentAccessor; 35 36import static java.awt.BufferCapabilities.FlipContents.BACKGROUND; 37import static java.awt.BufferCapabilities.FlipContents.COPIED; 38import static java.awt.BufferCapabilities.FlipContents.PRIOR; 39import static java.awt.BufferCapabilities.FlipContents.UNDEFINED; 40 41/** 42 * @test 43 * @key headful 44 * @bug 8130390 8134732 45 * @summary Applet fails to launch on virtual desktop 46 * @modules java.desktop/sun.awt 47 * @author Semyon Sadetsky 48 */ 49public final class AppletFlipBuffer { 50 51 static final ImageCapabilities[] ics = {new ImageCapabilities(true), 52 new ImageCapabilities(false)}; 53 static final FlipContents[] cntx = {UNDEFINED, BACKGROUND, PRIOR, COPIED}; 54 static final Set<BufferCapabilities> bcs = new HashSet<>(); 55 56 static { 57 for (final ImageCapabilities icFront : ics) { 58 for (final ImageCapabilities icBack : ics) { 59 for (final FlipContents cnt : cntx) { 60 bcs.add(new BufferCapabilities(icFront, icBack, cnt)); 61 } 62 } 63 } 64 } 65 66 public static void main(final String[] args) throws Exception { 67 Applet applet = new Applet(); 68 Frame frame = new Frame(); 69 try { 70 frame.setSize(10, 10); 71 frame.add(applet); 72 frame.setUndecorated(true); 73 frame.setVisible(true); 74 test(applet); 75 System.out.println("ok"); 76 } finally { 77 frame.dispose(); 78 } 79 } 80 81 private static void test(final Applet applet) { 82 ComponentAccessor acc = AWTAccessor.getComponentAccessor(); 83 for (int i = 1; i < 10; ++i) { 84 for (final BufferCapabilities caps : bcs) { 85 try { 86 acc.createBufferStrategy(applet, i, caps); 87 } catch (final AWTException ignored) { 88 // this kind of buffer strategy is not supported 89 } 90 } 91 } 92 } 93} 94