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