Path: blob/master/src/java.desktop/share/classes/java/awt/BufferCapabilities.java
41152 views
/*1* Copyright (c) 2000, 2018, 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 java.awt;2627/**28* Capabilities and properties of buffers.29*30* @see java.awt.image.BufferStrategy#getCapabilities()31* @see GraphicsConfiguration#getBufferCapabilities32* @author Michael Martak33* @since 1.434*/35public class BufferCapabilities implements Cloneable {3637private ImageCapabilities frontCaps;38private ImageCapabilities backCaps;39private FlipContents flipContents;4041/**42* Creates a new object for specifying buffering capabilities43* @param frontCaps the capabilities of the front buffer; cannot be44* {@code null}45* @param backCaps the capabilities of the back and intermediate buffers;46* cannot be {@code null}47* @param flipContents the contents of the back buffer after page-flipping,48* {@code null} if page flipping is not used (implies blitting)49* @exception IllegalArgumentException if frontCaps or backCaps are50* {@code null}51*/52public BufferCapabilities(ImageCapabilities frontCaps,53ImageCapabilities backCaps, FlipContents flipContents) {54if (frontCaps == null || backCaps == null) {55throw new IllegalArgumentException(56"Image capabilities specified cannot be null");57}58this.frontCaps = frontCaps;59this.backCaps = backCaps;60this.flipContents = flipContents;61}6263/**64* @return the image capabilities of the front (displayed) buffer65*/66public ImageCapabilities getFrontBufferCapabilities() {67return frontCaps;68}6970/**71* @return the image capabilities of all back buffers (intermediate buffers72* are considered back buffers)73*/74public ImageCapabilities getBackBufferCapabilities() {75return backCaps;76}7778/**79* @return whether or not the buffer strategy uses page flipping; a set of80* buffers that uses page flipping81* can swap the contents internally between the front buffer and one or82* more back buffers by switching the video pointer (or by copying memory83* internally). A non-flipping set of84* buffers uses blitting to copy the contents from one buffer to85* another; when this is the case, {@code getFlipContents} returns86* {@code null}87*/88public boolean isPageFlipping() {89return (getFlipContents() != null);90}9192/**93* @return the resulting contents of the back buffer after page-flipping.94* This value is {@code null} when the {@code isPageFlipping}95* returns {@code false}, implying blitting. It can be one of96* {@code FlipContents.UNDEFINED}97* (the assumed default), {@code FlipContents.BACKGROUND},98* {@code FlipContents.PRIOR}, or99* {@code FlipContents.COPIED}.100* @see #isPageFlipping101* @see FlipContents#UNDEFINED102* @see FlipContents#BACKGROUND103* @see FlipContents#PRIOR104* @see FlipContents#COPIED105*/106public FlipContents getFlipContents() {107return flipContents;108}109110/**111* @return whether page flipping is only available in full-screen mode. If this112* is {@code true}, full-screen exclusive mode is required for113* page-flipping.114* @see #isPageFlipping115* @see GraphicsDevice#setFullScreenWindow116*/117public boolean isFullScreenRequired() {118return false;119}120121/**122* @return whether or not123* page flipping can be performed using more than two buffers (one or more124* intermediate buffers as well as the front and back buffer).125* @see #isPageFlipping126*/127public boolean isMultiBufferAvailable() {128return false;129}130131/**132* @return a copy of this BufferCapabilities object.133*/134public Object clone() {135try {136return super.clone();137} catch (CloneNotSupportedException e) {138// Since we implement Cloneable, this should never happen139throw new InternalError(e);140}141}142143// Inner class FlipContents144/**145* A type-safe enumeration of the possible back buffer contents after146* page-flipping147* @since 1.4148*/149public static final class FlipContents extends AttributeValue {150151private static int I_UNDEFINED = 0;152private static int I_BACKGROUND = 1;153private static int I_PRIOR = 2;154private static int I_COPIED = 3;155156private static final String[] NAMES =157{ "undefined", "background", "prior", "copied" };158159/**160* When flip contents are {@code UNDEFINED}, the161* contents of the back buffer are undefined after flipping.162* @see #isPageFlipping163* @see #getFlipContents164* @see #BACKGROUND165* @see #PRIOR166* @see #COPIED167*/168public static final FlipContents UNDEFINED =169new FlipContents(I_UNDEFINED);170171/**172* When flip contents are {@code BACKGROUND}, the173* contents of the back buffer are cleared with the background color after174* flipping.175* @see #isPageFlipping176* @see #getFlipContents177* @see #UNDEFINED178* @see #PRIOR179* @see #COPIED180*/181public static final FlipContents BACKGROUND =182new FlipContents(I_BACKGROUND);183184/**185* When flip contents are {@code PRIOR}, the186* contents of the back buffer are the prior contents of the front buffer187* (a true page flip).188* @see #isPageFlipping189* @see #getFlipContents190* @see #UNDEFINED191* @see #BACKGROUND192* @see #COPIED193*/194public static final FlipContents PRIOR =195new FlipContents(I_PRIOR);196197/**198* When flip contents are {@code COPIED}, the199* contents of the back buffer are copied to the front buffer when200* flipping.201* @see #isPageFlipping202* @see #getFlipContents203* @see #UNDEFINED204* @see #BACKGROUND205* @see #PRIOR206*/207public static final FlipContents COPIED =208new FlipContents(I_COPIED);209210private FlipContents(int type) {211super(type, NAMES);212}213214} // Inner class FlipContents215216}217218219