001/* BufferCapabilities.java -- double-buffering capabilities descriptor 002 Copyright (C) 2002, 2005 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.awt; 040 041import java.awt.image.BufferStrategy; 042 043/** 044 * A double-buffering capability descriptor. This class exposes 045 * details about the double-buffering algorithms used by image 046 * buffers. 047 * 048 * BufferCapabilities represents algorithms that involve at least two 049 * buffers but it can also specify so-called "multi-buffer" schemes 050 * involving more than two buffers. This class describes the 051 * capabilities of the front and back buffers as well as the results 052 * of "flipping" -- that is, what happens when an image is transferred 053 * from the back buffer to the front buffer. 054 * 055 * Flipping may or may not be supported or may be supported only in 056 * fullscreen mode. If it is not supported then "blitting" is implied 057 * -- that is, the contents of the back buffer are copied using a fast 058 * block transfer operation from the back buffer to the front buffer. 059 * 060 * The front buffer is the one that is displayed. 061 * 062 * @author Eric Blake (ebb9@email.byu.edu) 063 * 064 * @see BufferStrategy#getCapabilities() 065 * @see GraphicsConfiguration#getBufferCapabilities() 066 * 067 * @since 1.4 068 */ 069public class BufferCapabilities implements Cloneable 070{ 071 /** 072 * A type-safe enumeration of buffer flipping results. 073 * 074 * @see AttributeValue 075 */ 076 public static final class FlipContents extends AttributeValue 077 { 078 /** 079 * The names of the different flipping results. 080 */ 081 private static final String[] NAMES 082 = { "undefined", "background", "prior", "copied" }; 083 084 /** 085 * The contents of the back buffer are undefined after flipping. 086 */ 087 public static final FlipContents UNDEFINED = new FlipContents(0); 088 089 /** 090 * The back buffer is cleared with the background color after 091 * flipping. 092 */ 093 public static final FlipContents BACKGROUND = new FlipContents(1); 094 095 /** 096 * The back buffer contains the pre-flipping contents of the front 097 * buffer after flipping. In other words a true "flip" has been 098 * performed. 099 */ 100 public static final FlipContents PRIOR = new FlipContents(2); 101 102 /** 103 * The back buffer has the same contents as the front buffer after 104 * flipping. 105 */ 106 public static final FlipContents COPIED = new FlipContents(3); 107 108 /** 109 * Create a new flipping result descriptor. 110 * 111 * @param value the enumeration value 112 */ 113 private FlipContents(int value) 114 { 115 super(value, NAMES); 116 } 117 } 118 119 /** 120 * Front buffer capabilities descriptor. 121 */ 122 private final ImageCapabilities front; 123 124 /** 125 * Back buffer capabilities descriptor. 126 */ 127 private final ImageCapabilities back; 128 129 /** 130 * Describes the results of a "flip" operation. 131 */ 132 private final FlipContents flip; 133 134 /** 135 * Creates a buffer capabilities object. 136 * 137 * @param frontCaps front buffer capabilities descriptor 138 * @param backCaps back buffer capabilities descriptor 139 * @param flip the results of a flip operation or null if 140 * flipping is not supported 141 * 142 * @exception IllegalArgumentException if frontCaps or backCaps is 143 * null 144 */ 145 public BufferCapabilities(ImageCapabilities frontCaps, 146 ImageCapabilities backCaps, 147 FlipContents flip) 148 { 149 if (frontCaps == null || backCaps == null) 150 throw new IllegalArgumentException(); 151 this.front = frontCaps; 152 this.back = backCaps; 153 this.flip = flip; 154 } 155 156 /** 157 * Retrieve the front buffer's image capabilities. 158 * 159 * @return the front buffer's image capabilities 160 */ 161 public ImageCapabilities getFrontBufferCapabilities() 162 { 163 return front; 164 } 165 166 /** 167 * Retrieve the back buffer's image capabilities. 168 * 169 * @return the back buffer's image capabilities 170 */ 171 public ImageCapabilities getBackBufferCapabilities() 172 { 173 return back; 174 } 175 176 /** 177 * Return whether or not flipping is supported. 178 * 179 * @return true if flipping is supported, false otherwise 180 */ 181 public boolean isPageFlipping() 182 { 183 return flip != null; 184 } 185 186 /** 187 * Retrieve the result of a flipping operation. If this method 188 * returns null then flipping is not supported. This implies that 189 * "blitting", a fast block transfer, is used to copy the contents 190 * of the back buffer to the front buffer. Other possible return 191 * values are: 192 * <ul> 193 * <li><code>FlipContents.UNDEFINED</code> the contents of the 194 * back buffer are undefined after flipping.</li> 195 * <li><code>FlipContents.BACKGROUND</code> the contents of the 196 * back buffer are cleared to the background color after 197 * flipping.</li> 198 * <li><code>FlipContents.PRIOR</code> the back buffer contains 199 * the pre-flipping contents of the front * buffer after 200 * flipping.</li> 201 * <li><code>FlipContents.COPIED</code> the back buffer has the 202 * same contents as the front buffer after flipping.</li> 203 * </ul> 204 * 205 * @return the result of a flipping operation or null if flipping is 206 * not supported 207 */ 208 public FlipContents getFlipContents() 209 { 210 return flip; 211 } 212 213 /** 214 * Returns true if flipping is only supported in fullscreen mode. 215 * 216 * @return true if flipping is only supported in fullscreen mode, 217 * false otherwise 218 */ 219 public boolean isFullScreenRequired() 220 { 221 return true; 222 } 223 224 /** 225 * Returns true if flipping can involve more than two buffers. One 226 * or more intermediate buffers may be available in addition to the 227 * front and back buffers. 228 * 229 * @return true if there are more than two buffers available for 230 * flipping, false otherwise 231 */ 232 public boolean isMultiBufferAvailable() 233 { 234 return false; 235 } 236 237 /** 238 * Clone this buffering capability descriptor. 239 * 240 * @return a clone of this buffer capability descriptor 241 */ 242 public Object clone() 243 { 244 try 245 { 246 return super.clone(); 247 } 248 catch (CloneNotSupportedException e) 249 { 250 throw (Error) new InternalError().initCause(e); 251 } 252 } 253}