jdk/src/share/classes/java/awt/BufferCapabilities.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Capabilities and properties of buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @see java.awt.image.BufferStrategy#getCapabilities()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @see GraphicsConfiguration#getBufferCapabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class BufferCapabilities implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private ImageCapabilities frontCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    private ImageCapabilities backCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private FlipContents flipContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Creates a new object for specifying buffering capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * @param frontCaps the capabilities of the front buffer; cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * @param backCaps the capabilities of the back and intermediate buffers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * cannot be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @param flipContents the contents of the back buffer after page-flipping,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * <code>null</code> if page flipping is not used (implies blitting)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @exception IllegalArgumentException if frontCaps or backCaps are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public BufferCapabilities(ImageCapabilities frontCaps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        ImageCapabilities backCaps, FlipContents flipContents) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (frontCaps == null || backCaps == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                "Image capabilities specified cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        this.frontCaps = frontCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        this.backCaps = backCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.flipContents = flipContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * @return the image capabilities of the front (displayed) buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public ImageCapabilities getFrontBufferCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        return frontCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @return the image capabilities of all back buffers (intermediate buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * are considered back buffers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public ImageCapabilities getBackBufferCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        return backCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @return whether or not the buffer strategy uses page flipping; a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * buffers that uses page flipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * can swap the contents internally between the front buffer and one or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * more back buffers by switching the video pointer (or by copying memory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * internally).  A non-flipping set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * buffers uses blitting to copy the contents from one buffer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * another; when this is the case, <code>getFlipContents</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public boolean isPageFlipping() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return (getFlipContents() != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @return the resulting contents of the back buffer after page-flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * This value is <code>null</code> when the <code>isPageFlipping</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * returns <code>false</code>, implying blitting.  It can be one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * <code>FlipContents.UNDEFINED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * (the assumed default), <code>FlipContents.BACKGROUND</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>FlipContents.PRIOR</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <code>FlipContents.COPIED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @see FlipContents#UNDEFINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @see FlipContents#BACKGROUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @see FlipContents#PRIOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see FlipContents#COPIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public FlipContents getFlipContents() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return flipContents;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return whether page flipping is only available in full-screen mode.  If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * is <code>true</code>, full-screen exclusive mode is required for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * page-flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @see GraphicsDevice#setFullScreenWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public boolean isFullScreenRequired() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * page flipping can be performed using more than two buffers (one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * intermediate buffers as well as the front and back buffer).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public boolean isMultiBufferAvailable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @return a copy of this BufferCapabilities object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            // Since we implement Cloneable, this should never happen
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   140
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    // Inner class FlipContents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * A type-safe enumeration of the possible back buffer contents after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * page-flipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static final class FlipContents extends AttributeValue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        private static int I_UNDEFINED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        private static int I_BACKGROUND = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        private static int I_PRIOR = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        private static int I_COPIED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        private static final String NAMES[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            { "undefined", "background", "prior", "copied" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * When flip contents are <code>UNDEFINED</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * contents of the back buffer are undefined after flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * @see #getFlipContents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * @see #BACKGROUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         * @see #PRIOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         * @see #COPIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        public static final FlipContents UNDEFINED =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            new FlipContents(I_UNDEFINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         * When flip contents are <code>BACKGROUND</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         * contents of the back buffer are cleared with the background color after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * @see #getFlipContents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         * @see #UNDEFINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * @see #PRIOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         * @see #COPIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        public static final FlipContents BACKGROUND =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            new FlipContents(I_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * When flip contents are <code>PRIOR</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * contents of the back buffer are the prior contents of the front buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * (a true page flip).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * @see #getFlipContents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * @see #UNDEFINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * @see #BACKGROUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * @see #COPIED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public static final FlipContents PRIOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            new FlipContents(I_PRIOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * When flip contents are <code>COPIED</code>, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * contents of the back buffer are copied to the front buffer when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         * flipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         * @see #isPageFlipping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         * @see #getFlipContents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * @see #UNDEFINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         * @see #BACKGROUND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
         * @see #PRIOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        public static final FlipContents COPIED =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            new FlipContents(I_COPIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        private FlipContents(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            super(type, NAMES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    } // Inner class FlipContents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
}