001: /*
002: * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package java.awt;
027:
028: /**
029: * Capabilities and properties of buffers.
030: *
031: * @see java.awt.image.BufferStrategy#getCapabilities()
032: * @see GraphicsConfiguration#getBufferCapabilities
033: * @author Michael Martak
034: * @since 1.4
035: */
036: public class BufferCapabilities implements Cloneable {
037:
038: private ImageCapabilities frontCaps;
039: private ImageCapabilities backCaps;
040: private FlipContents flipContents;
041:
042: /**
043: * Creates a new object for specifying buffering capabilities
044: * @param frontCaps the capabilities of the front buffer; cannot be
045: * <code>null</code>
046: * @param backCaps the capabilities of the back and intermediate buffers;
047: * cannot be <code>null</code>
048: * @param flipContents the contents of the back buffer after page-flipping,
049: * <code>null</code> if page flipping is not used (implies blitting)
050: * @exception IllegalArgumentException if frontCaps or backCaps are
051: * <code>null</code>
052: */
053: public BufferCapabilities(ImageCapabilities frontCaps,
054: ImageCapabilities backCaps, FlipContents flipContents) {
055: if (frontCaps == null || backCaps == null) {
056: throw new IllegalArgumentException(
057: "Image capabilities specified cannot be null");
058: }
059: this .frontCaps = frontCaps;
060: this .backCaps = backCaps;
061: this .flipContents = flipContents;
062: }
063:
064: /**
065: * @return the image capabilities of the front (displayed) buffer
066: */
067: public ImageCapabilities getFrontBufferCapabilities() {
068: return frontCaps;
069: }
070:
071: /**
072: * @return the image capabilities of all back buffers (intermediate buffers
073: * are considered back buffers)
074: */
075: public ImageCapabilities getBackBufferCapabilities() {
076: return backCaps;
077: }
078:
079: /**
080: * @return whether or not the buffer strategy uses page flipping; a set of
081: * buffers that uses page flipping
082: * can swap the contents internally between the front buffer and one or
083: * more back buffers by switching the video pointer (or by copying memory
084: * internally). A non-flipping set of
085: * buffers uses blitting to copy the contents from one buffer to
086: * another; when this is the case, <code>getFlipContents</code> returns
087: * <code>null</code>
088: */
089: public boolean isPageFlipping() {
090: return (getFlipContents() != null);
091: }
092:
093: /**
094: * @return the resulting contents of the back buffer after page-flipping.
095: * This value is <code>null</code> when the <code>isPageFlipping</code>
096: * returns <code>false</code>, implying blitting. It can be one of
097: * <code>FlipContents.UNDEFINED</code>
098: * (the assumed default), <code>FlipContents.BACKGROUND</code>,
099: * <code>FlipContents.PRIOR</code>, or
100: * <code>FlipContents.COPIED</code>.
101: * @see #isPageFlipping
102: * @see FlipContents#UNDEFINED
103: * @see FlipContents#BACKGROUND
104: * @see FlipContents#PRIOR
105: * @see FlipContents#COPIED
106: */
107: public FlipContents getFlipContents() {
108: return flipContents;
109: }
110:
111: /**
112: * @return whether page flipping is only available in full-screen mode. If this
113: * is <code>true</code>, full-screen exclusive mode is required for
114: * page-flipping.
115: * @see #isPageFlipping
116: * @see GraphicsDevice#setFullScreenWindow
117: */
118: public boolean isFullScreenRequired() {
119: return false;
120: }
121:
122: /**
123: * @return whether or not
124: * page flipping can be performed using more than two buffers (one or more
125: * intermediate buffers as well as the front and back buffer).
126: * @see #isPageFlipping
127: */
128: public boolean isMultiBufferAvailable() {
129: return false;
130: }
131:
132: /**
133: * @return a copy of this BufferCapabilities object.
134: */
135: public Object clone() {
136: try {
137: return super .clone();
138: } catch (CloneNotSupportedException e) {
139: // Since we implement Cloneable, this should never happen
140: throw new InternalError();
141: }
142: }
143:
144: // Inner class FlipContents
145: /**
146: * A type-safe enumeration of the possible back buffer contents after
147: * page-flipping
148: * @since 1.4
149: */
150: public static final class FlipContents extends AttributeValue {
151:
152: private static int I_UNDEFINED = 0;
153: private static int I_BACKGROUND = 1;
154: private static int I_PRIOR = 2;
155: private static int I_COPIED = 3;
156:
157: private static final String NAMES[] = { "undefined",
158: "background", "prior", "copied" };
159:
160: /**
161: * When flip contents are <code>UNDEFINED</code>, the
162: * contents of the back buffer are undefined after flipping.
163: * @see #isPageFlipping
164: * @see #getFlipContents
165: * @see #BACKGROUND
166: * @see #PRIOR
167: * @see #COPIED
168: */
169: public static final FlipContents UNDEFINED = new FlipContents(
170: I_UNDEFINED);
171:
172: /**
173: * When flip contents are <code>BACKGROUND</code>, the
174: * contents of the back buffer are cleared with the background color after
175: * flipping.
176: * @see #isPageFlipping
177: * @see #getFlipContents
178: * @see #UNDEFINED
179: * @see #PRIOR
180: * @see #COPIED
181: */
182: public static final FlipContents BACKGROUND = new FlipContents(
183: I_BACKGROUND);
184:
185: /**
186: * When flip contents are <code>PRIOR</code>, the
187: * contents of the back buffer are the prior contents of the front buffer
188: * (a true page flip).
189: * @see #isPageFlipping
190: * @see #getFlipContents
191: * @see #UNDEFINED
192: * @see #BACKGROUND
193: * @see #COPIED
194: */
195: public static final FlipContents PRIOR = new FlipContents(
196: I_PRIOR);
197:
198: /**
199: * When flip contents are <code>COPIED</code>, the
200: * contents of the back buffer are copied to the front buffer when
201: * flipping.
202: * @see #isPageFlipping
203: * @see #getFlipContents
204: * @see #UNDEFINED
205: * @see #BACKGROUND
206: * @see #PRIOR
207: */
208: public static final FlipContents COPIED = new FlipContents(
209: I_COPIED);
210:
211: private FlipContents(int type) {
212: super (type, NAMES);
213: }
214:
215: } // Inner class FlipContents
216:
217: }
|