Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/hw/ExtendedBufferCapabilities.java
41161 views
/*1* Copyright (c) 2007, 2008, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pipe.hw;2627import java.awt.BufferCapabilities;28import java.awt.ImageCapabilities;2930/**31* Provides extended BufferStrategy capabilities, allowing to specify32* the type of vertical refresh synchronization for a buffer strategy.33*34* This BS capability is always page flipping because v-sync is only relevant35* to flipping buffer strategies.36*37* Note that asking for a v-synced BS doesn't necessarily guarantee that it will38* be v-synced since the vsync capability may be disabled in the driver, or39* there may be other restriction (like a number of v-synced buffer strategies40* allowed per vm). Because of this {@code createBufferStrategy} doesn't41* throw {@code AWTException} when a v-synced BS could not be created when42* requested.43*44* @see java.awt.Canvas#createBufferStrategy(int, BufferCapabilities)45* @see java.awt.Window#createBufferStrategy(int, BufferCapabilities)46*/47public class ExtendedBufferCapabilities extends BufferCapabilities {4849/**50* Type of synchronization on vertical retrace.51*/52public static enum VSyncType {53/**54* Use the default v-sync mode appropriate for given BufferStrategy55* and situation.56*/57VSYNC_DEFAULT(0),5859/**60* Synchronize flip on vertical retrace.61*/62VSYNC_ON(1),6364/**65* Do not synchronize flip on vertical retrace.66*/67VSYNC_OFF(2);6869/**70* Used to identify the v-sync type (independent of the constants71* order as opposed to {@code ordinal()}).72*/73public int id() {74return id;75}7677private VSyncType(int id) {78this.id = id;79}80private int id;81}8283private VSyncType vsync;8485/**86* Creates an ExtendedBufferCapabilities object with front/back/flip caps87* from the passed cap, and VSYNC_DEFAULT v-sync mode.88*/89public ExtendedBufferCapabilities(BufferCapabilities caps) {90super(caps.getFrontBufferCapabilities(),91caps.getBackBufferCapabilities(),92caps.getFlipContents());9394this.vsync = VSyncType.VSYNC_DEFAULT;95}9697/**98* Creates an ExtendedBufferCapabilities instance with front/back/flip caps99* from the passed caps, and VSYNC_DEFAULT v-sync mode.100*/101public ExtendedBufferCapabilities(ImageCapabilities front,102ImageCapabilities back, FlipContents flip)103{104super(front, back, flip);105106this.vsync = VSyncType.VSYNC_DEFAULT;107}108109/**110* Creates an ExtendedBufferCapabilities instance with front/back/flip caps111* from the passed image/flip caps, and the v-sync type.112*/113public ExtendedBufferCapabilities(ImageCapabilities front,114ImageCapabilities back, FlipContents flip,115VSyncType t)116{117super(front, back, flip);118119this.vsync = t;120}121122/**123* Creates an ExtendedBufferCapabilities instance with front/back/flip caps124* from the passed cap, and the passed v-sync mode.125*/126public ExtendedBufferCapabilities(BufferCapabilities caps, VSyncType t) {127super(caps.getFrontBufferCapabilities(),128caps.getBackBufferCapabilities(),129caps.getFlipContents());130131this.vsync = t;132}133134/**135* Creates an ExtendedBufferCapabilities instance with front/back/flip caps136* from the object, and passed v-sync mode.137*/138public ExtendedBufferCapabilities derive(VSyncType t) {139return new ExtendedBufferCapabilities(this, t);140}141142/**143* Returns the type of v-sync requested by this capabilities instance.144*/145public VSyncType getVSync() {146return vsync;147}148149@Override150public final boolean isPageFlipping() {151return true;152}153}154155156