1. /*
  2. * @(#)BufferCapabilities.java 1.8 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. /**
  9. * Capabilities and properties of buffers.
  10. *
  11. * @see java.awt.image.BufferStrategy#getCapabilities()
  12. * @see GraphicsConfiguration#getBufferCapabilities
  13. * @author Michael Martak
  14. * @since 1.4
  15. */
  16. public class BufferCapabilities implements Cloneable {
  17. private ImageCapabilities frontCaps;
  18. private ImageCapabilities backCaps;
  19. private FlipContents flipContents;
  20. /**
  21. * Creates a new object for specifying buffering capabilities
  22. * @param frontCaps the capabilities of the front buffer; cannot be
  23. * <code>null</code>
  24. * @param backCaps the capabilities of the back and intermediate buffers;
  25. * cannot be <code>null</code>
  26. * @param flipContents the contents of the back buffer after page-flipping,
  27. * <code>null</code> if page flipping is not used (implies blitting)
  28. * @exception IllegalArgumentException if frontCaps or backCaps are
  29. * <code>null</code>
  30. */
  31. public BufferCapabilities(ImageCapabilities frontCaps,
  32. ImageCapabilities backCaps, FlipContents flipContents) {
  33. if (frontCaps == null || backCaps == null) {
  34. throw new IllegalArgumentException(
  35. "Image capabilities specified cannot be null");
  36. }
  37. this.frontCaps = frontCaps;
  38. this.backCaps = backCaps;
  39. this.flipContents = flipContents;
  40. }
  41. /**
  42. * @return the image capabilities of the front (displayed) buffer
  43. */
  44. public ImageCapabilities getFrontBufferCapabilities() {
  45. return frontCaps;
  46. }
  47. /**
  48. * @return the image capabilities of all back buffers (intermediate buffers
  49. * are considered back buffers)
  50. */
  51. public ImageCapabilities getBackBufferCapabilities() {
  52. return backCaps;
  53. }
  54. /**
  55. * @return whether or not the buffer strategy uses page flipping; a set of
  56. * buffers that uses page flipping
  57. * can swap the contents internally between the front buffer and one or
  58. * more back buffers by switching the video pointer (or by copying memory
  59. * internally). A non-flipping set of
  60. * buffers uses blitting to copy the contents from one buffer to
  61. * another; when this is the case, <code>getFlipContents</code> returns
  62. * <code>null</code>
  63. */
  64. public boolean isPageFlipping() {
  65. return (getFlipContents() != null);
  66. }
  67. /**
  68. * @return the resulting contents of the back buffer after page-flipping.
  69. * This value is <code>null</code> when the <code>isPageFlipping</code>
  70. * returns <code>false</code>, implying blitting. It can be one of
  71. * <code>FlipContents.UNDEFINED</code>
  72. * (the assumed default), <code>FlipContents.BACKGROUND</code>,
  73. * <code>FlipContents.PRIOR</code>, or
  74. * <code>FlipContents.COPIED</code>.
  75. * @see #isPageFlipping
  76. * @see FlipContents#UNDEFINED
  77. * @see FlipContents#BACKGROUND
  78. * @see FlipContents#PRIOR
  79. * @see FlipContents#COPIED
  80. */
  81. public FlipContents getFlipContents() {
  82. return flipContents;
  83. }
  84. /**
  85. * @return whether page flipping is only available in full-screen mode. If this
  86. * is <code>true</code>, full-screen exclusive mode is required for
  87. * page-flipping.
  88. * @see #isPageFlipping
  89. * @see GraphicsDevice#setFullScreenWindow
  90. */
  91. public boolean isFullScreenRequired() {
  92. return false;
  93. }
  94. /**
  95. * @return whether or not
  96. * page flipping can be performed using more than two buffers (one or more
  97. * intermediate buffers as well as the front and back buffer).
  98. * @see #isPageFlipping
  99. */
  100. public boolean isMultiBufferAvailable() {
  101. return false;
  102. }
  103. /**
  104. * @return a copy of this BufferCapabilities object.
  105. */
  106. public Object clone() {
  107. try {
  108. return super.clone();
  109. } catch (CloneNotSupportedException e) {
  110. // Since we implement Cloneable, this should never happen
  111. throw new InternalError();
  112. }
  113. }
  114. // Inner class FlipContents
  115. /**
  116. * A type-safe enumeration of the possible back buffer contents after
  117. * page-flipping
  118. */
  119. public static final class FlipContents extends AttributeValue {
  120. private static int I_UNDEFINED = 0;
  121. private static int I_BACKGROUND = 1;
  122. private static int I_PRIOR = 2;
  123. private static int I_COPIED = 3;
  124. private static final String NAMES[] =
  125. { "undefined", "background", "prior", "copied" };
  126. /**
  127. * When flip contents are <code>UNDEFINED</code>, the
  128. * contents of the back buffer are undefined after flipping.
  129. * @see #isPageFlipping
  130. * @see #getFlipContents
  131. * @see #BACKGROUND
  132. * @see #PRIOR
  133. * @see #COPIED
  134. */
  135. public static final FlipContents UNDEFINED =
  136. new FlipContents(I_UNDEFINED);
  137. /**
  138. * When flip contents are <code>BACKGROUND</code>, the
  139. * contents of the back buffer are cleared with the background color after
  140. * flipping.
  141. * @see #isPageFlipping
  142. * @see #getFlipContents
  143. * @see #UNDEFINED
  144. * @see #PRIOR
  145. * @see #COPIED
  146. */
  147. public static final FlipContents BACKGROUND =
  148. new FlipContents(I_BACKGROUND);
  149. /**
  150. * When flip contents are <code>PRIOR</code>, the
  151. * contents of the back buffer are the prior contents of the front buffer
  152. * (a true page flip).
  153. * @see #isPageFlipping
  154. * @see #getFlipContents
  155. * @see #UNDEFINED
  156. * @see #BACKGROUND
  157. * @see #COPIED
  158. */
  159. public static final FlipContents PRIOR =
  160. new FlipContents(I_PRIOR);
  161. /**
  162. * When flip contents are <code>COPIED</code>, the
  163. * contents of the back buffer are copied to the front buffer when
  164. * flipping.
  165. * @see #isPageFlipping
  166. * @see #getFlipContents
  167. * @see #UNDEFINED
  168. * @see #BACKGROUND
  169. * @see #PRIOR
  170. */
  171. public static final FlipContents COPIED =
  172. new FlipContents(I_COPIED);
  173. private FlipContents(int type) {
  174. super(type, NAMES);
  175. }
  176. } // Inner class FlipContents
  177. }