src/java.desktop/share/classes/java/awt/image/VolatileImage.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
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.image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.ImageCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * VolatileImage is an image which can lose its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * contents at any time due to circumstances beyond the control of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * application (e.g., situations caused by the operating system or by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * other applications). Because of the potential for hardware acceleration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * a VolatileImage object can have significant performance benefits on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * some platforms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The drawing surface of an image (the memory where the image contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * actually reside) can be lost or invalidated, causing the contents of that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * memory to go away.  The drawing surface thus needs to be restored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * or recreated and the contents of that surface need to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * re-rendered.  VolatileImage provides an interface for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * allowing the user to detect these problems and fix them
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * when they occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * When a VolatileImage object is created, limited system resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * such as video memory (VRAM) may be allocated in order to support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * When a VolatileImage object is no longer used, it may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * garbage-collected and those system resources will be returned,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * but this process does not happen at guaranteed times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Applications that create many VolatileImage objects (for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * a resizing window may force recreation of its back buffer as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * size changes) may run out of optimal system resources for new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * VolatileImage objects simply because the old objects have not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * yet been removed from the system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * (New VolatileImage objects may still be created, but they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * may not perform as well as those created in accelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * memory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * The flush method may be called at any time to proactively release
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * the resources used by a VolatileImage so that it does not prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * subsequent VolatileImage objects from being accelerated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * In this way, applications can have more control over the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * of the resources taken up by obsolete VolatileImage objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * This image should not be subclassed directly but should be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * by using the {@link java.awt.Component#createVolatileImage(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Component.createVolatileImage} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * {@link java.awt.GraphicsConfiguration#createCompatibleVolatileImage(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * GraphicsConfiguration.createCompatibleVolatileImage(int, int)} methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * An example of using a VolatileImage object follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * // image creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * VolatileImage vImg = createVolatileImage(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * // rendering to the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * void renderOffscreen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *      do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *          if (vImg.validate(getGraphicsConfiguration()) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *              VolatileImage.IMAGE_INCOMPATIBLE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *              // old vImg doesn't work with new GraphicsConfig; re-create it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *              vImg = createVolatileImage(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *          Graphics2D g = vImg.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *          // miscellaneous rendering commands...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *          //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *          g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *      } while (vImg.contentsLost());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * // copying from the image (here, gScreen is the Graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * // object for the onscreen window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *      int returnCode = vImg.validate(getGraphicsConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *      if (returnCode == VolatileImage.IMAGE_RESTORED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *          // Contents need to be restored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *          renderOffscreen();      // restore contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *      } else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *          // old vImg doesn't work with new GraphicsConfig; re-create it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *          vImg = createVolatileImage(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *          renderOffscreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *      gScreen.drawImage(vImg, 0, 0, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * } while (vImg.contentsLost());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * Note that this class subclasses from the {@link Image} class, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * includes methods that take an {@link ImageObserver} parameter for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * asynchronous notifications as information is received from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   123
 * a potential {@link ImageProducer}.  Since this {@code VolatileImage}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * is not loaded from an asynchronous source, the various methods that take
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   125
 * an {@code ImageObserver} parameter will behave as if the data has
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   126
 * already been obtained from the {@code ImageProducer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * Specifically, this means that the return values from such methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * will never indicate that the information is not yet available and
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   129
 * the {@code ImageObserver} used in such methods will never
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * need to be recorded for an asynchronous callback notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
public abstract class VolatileImage extends Image implements Transparency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // Return codes for validate() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Validated image is ready to use as-is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static final int IMAGE_OK = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Validated image has been restored and is now ready to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Note that restoration causes contents of the image to be lost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static final int IMAGE_RESTORED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Validated image is incompatible with supplied
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   151
     * {@code GraphicsConfiguration} object and should be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * re-created as appropriate.  Usage of the image as-is
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   153
     * after receiving this return code from {@code validate}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public static final int IMAGE_INCOMPATIBLE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Returns a static snapshot image of this object.  The
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   160
     * {@code BufferedImage} returned is only current with
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   161
     * the {@code VolatileImage} at the time of the request
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * and will not be updated with any future changes to the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   163
     * {@code VolatileImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return a {@link BufferedImage} representation of this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   165
     *          {@code VolatileImage}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @see BufferedImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public abstract BufferedImage getSnapshot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   171
     * Returns the width of the {@code VolatileImage}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   172
     * @return the width of this {@code VolatileImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public abstract int getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   177
     * Returns the height of the {@code VolatileImage}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   178
     * @return the height of this {@code VolatileImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public abstract int getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    // Image overrides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * This returns an ImageProducer for this VolatileImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Note that the VolatileImage object is optimized for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * rendering operations and blitting to the screen or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * VolatileImage objects, as opposed to reading back the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * pixels of the image.  Therefore, operations such as
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   190
     * {@code getSource} may not perform as fast as
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * operations that do not rely on reading the pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Note also that the pixel values read from the image are current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * with those in the image only at the time that they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * retrieved. This method takes a snapshot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * of the image at the time the request is made and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * ImageProducer object returned works with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * that static snapshot image, not the original VolatileImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Calling getSource()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * is equivalent to calling getSnapshot().getSource().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @return an {@link ImageProducer} that can be used to produce the
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   201
     * pixels for a {@code BufferedImage} representation of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * this Image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @see ImageProducer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #getSnapshot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public ImageProducer getSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        // REMIND: Make sure this functionality is in line with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // spec.  In particular, we are returning the Source for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // static image (the snapshot), not a changing image (the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // VolatileImage).  So if the user expects the Source to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // up-to-date with the current contents of the VolatileImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // they will be disappointed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // REMIND: This assumes that getSnapshot() returns something
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        // valid and not the default null object returned by this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // (so it assumes that the actual VolatileImage object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // subclassed off something that does the right thing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // (e.g., SunVolatileImage).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return getSnapshot().getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    // REMIND: if we want any decent performance for getScaledInstance(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    // we should override the Image implementation of it...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * This method returns a {@link Graphics2D}, but is here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * for backwards compatibility.  {@link #createGraphics() createGraphics} is more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * convenient, since it is declared to return a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   228
     * {@code Graphics2D}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   229
     * @return a {@code Graphics2D}, which can be used to draw into
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *          this image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   237
     * Creates a {@code Graphics2D}, which can be used to draw into
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   238
     * this {@code VolatileImage}.
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   239
     * @return a {@code Graphics2D}, used for drawing into this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *          image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public abstract Graphics2D createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    // Volatile management methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Attempts to restore the drawing surface of the image if the surface
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   249
     * had been lost since the last {@code validate} call.  Also
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * validates this image against the given GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * parameter to see whether operations from this image to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * GraphicsConfiguration are compatible.  An example of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * incompatible combination might be a situation where a VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * object was created on one graphics device and then was used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * to render to a different graphics device.  Since VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * objects tend to be very device-specific, this operation might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * not work as intended, so the return code from this validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * call would note that incompatibility.  A null or incorrect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * value for gc may cause incorrect values to be returned from
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   260
     * {@code validate} and may cause later problems with rendering.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   262
     * @param   gc   a {@code GraphicsConfiguration} object for this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *          image to be validated against.  A null gc implies that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *          validate method should skip the compatibility test.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   265
     * @return  {@code IMAGE_OK} if the image did not need validation<BR>
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   266
     *          {@code IMAGE_RESTORED} if the image needed restoration.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *          Restoration implies that the contents of the image may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *          been affected and the image may need to be re-rendered.<BR>
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   269
     *          {@code IMAGE_INCOMPATIBLE} if the image is incompatible
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   270
     *          with the {@code GraphicsConfiguration} object passed
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   271
     *          into the {@code validate} method.  Incompatibility
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *          implies that the image may need to be recreated with a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   273
     *          new {@code Component} or
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   274
     *          {@code GraphicsConfiguration} in order to get an image
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *          that can be used successfully with this
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   276
     *          {@code GraphicsConfiguration}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *          An incompatible image is not checked for whether restoration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *          was necessary, so the state of the image is unchanged
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   279
     *          after a return value of {@code IMAGE_INCOMPATIBLE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *          and this return value implies nothing about whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *          image needs to be restored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @see java.awt.GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see java.awt.Component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see #IMAGE_OK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see #IMAGE_RESTORED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @see #IMAGE_INCOMPATIBLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public abstract int validate(GraphicsConfiguration gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   291
     * Returns {@code true} if rendering data was lost since last
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   292
     * {@code validate} call.  This method should be called by the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * application at the end of any series of rendering operations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * or from the image to see whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * the image needs to be validated and the rendering redone.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   296
     * @return {@code true} if the drawing surface needs to be restored;
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   297
     * {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public abstract boolean contentsLost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Returns an ImageCapabilities object which can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * inquired as to the specific capabilities of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * VolatileImage.  This would allow programmers to find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * out more runtime information on the specific VolatileImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * object that they have created.  For example, the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * might create a VolatileImage but the system may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * no video memory left for creating an image of that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * size, so although the object is a VolatileImage, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * not as accelerated as other VolatileImage objects on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * this platform might be.  The user might want that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * information to find other solutions to their problem.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   313
     * @return an {@code ImageCapabilities} object that contains
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   314
     *         the capabilities of this {@code VolatileImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public abstract ImageCapabilities getCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * The transparency value with which this image was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @see java.awt.GraphicsConfiguration#createCompatibleVolatileImage(int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *      int,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see java.awt.GraphicsConfiguration#createCompatibleVolatileImage(int,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *      int,ImageCapabilities,int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see Transparency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    protected int transparency = TRANSLUCENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Returns the transparency.  Returns either OPAQUE, BITMASK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * or TRANSLUCENT.
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 25859
diff changeset
   333
     * @return the transparency of this {@code VolatileImage}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see Transparency#OPAQUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @see Transparency#BITMASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @see Transparency#TRANSLUCENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public int getTransparency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}