jdk/src/windows/classes/sun/awt/Win32GraphicsConfig.java
author anthony
Tue, 21 Apr 2009 11:35:52 +0400
changeset 2648 aa45a227fce3
parent 2451 597df8e1d786
child 5506 202f599c92aa
permissions -rw-r--r--
6802853: API: shaped & translucent windows Summary: A public API for the feature forward-ported from 6u10. Reviewed-by: yan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.BufferCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.ImageCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.image.DirectColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.image.VolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.awt.windows.WComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.awt.image.OffScreenImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.awt.image.SunVolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.awt.image.SurfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.java2d.InvalidPipeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.java2d.loops.RenderLoops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.java2d.loops.CompositeType;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    58
import sun.java2d.windows.GDIWindowSurfaceData;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * This is an implementation of a GraphicsConfiguration object for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * single Win32 visual.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @see GraphicsEnvironment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @see GraphicsDevice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
public class Win32GraphicsConfig extends GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    implements DisplayChangedListener, SurfaceManager.ProxiedGraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected Win32GraphicsDevice screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected int visual;  //PixelFormatID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected RenderLoops solidloops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Returns a Win32GraphicsConfiguration object with the given device
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * and PixelFormat.  Note that this method does NOT check to ensure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * the returned Win32GraphicsConfig will correctly support rendering into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Java window.  This method is provided so that client code can do its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * own checking as to the appropriateness of a particular PixelFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Safer access to Win32GraphicsConfigurations is provided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Win32GraphicsDevice.getConfigurations().
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static Win32GraphicsConfig getConfig(Win32GraphicsDevice device,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                int pixFormatID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return new Win32GraphicsConfig(device, pixFormatID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @deprecated as of JDK version 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * replaced by <code>getConfig()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public Win32GraphicsConfig(GraphicsDevice device, int visualnum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.screen = (Win32GraphicsDevice)device;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.visual = visualnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        ((Win32GraphicsDevice)device).addDisplayChangedListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Return the graphics device associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public GraphicsDevice getDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Return the PixelFormatIndex this GraphicsConfig uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public int getVisual() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return visual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public Object getProxyKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Return the RenderLoops this type of destination uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * solid fills and strokes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private SurfaceType sTypeOrig = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public synchronized RenderLoops getSolidLoops(SurfaceType stype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (solidloops == null || sTypeOrig != stype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            solidloops = SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                                     CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                                     stype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            sTypeOrig = stype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return solidloops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Returns the color model associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public synchronized ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return screen.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Returns a new color model for this configuration.  This call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * is only used internally, by images and components that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * associated with the graphics device.  When attributes of that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * device change (for example, when the device palette is updated),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * then this device-based color model will be updated internally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * to reflect the new situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public ColorModel getDeviceColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return screen.getDynamicColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
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 the color model associated with this configuration that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * supports the specified transparency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public ColorModel getColorModel(int transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        switch (transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        case Transparency.OPAQUE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            return getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        case Transparency.BITMASK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        case Transparency.TRANSLUCENT:
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   169
            return ColorModel.getRGBdefault();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns the default Transform for this configuration.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Transform is typically the Identity transform for most normal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * screens.  Device coordinates for screen and printer devices will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * have the origin in the upper left-hand corner of the target region of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * the device, with X coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * increasing to the right and Y coordinates increasing downwards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * For image buffers, this Transform will be the Identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public AffineTransform getDefaultTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        return new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns a Transform that can be composed with the default Transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * of a Graphics2D so that 72 units in user space will equal 1 inch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * in device space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Given a Graphics2D, g, one can reset the transformation to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * such a mapping by using the following pseudocode:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *      GraphicsConfiguration gc = g.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *      g.setTransform(gc.getDefaultTransform());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *      g.transform(gc.getNormalizingTransform());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Note that sometimes this Transform will be identity (e.g. for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * printers or metafile output) and that this Transform is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * as accurate as the information supplied by the underlying system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * For image buffers, this Transform will be the Identity transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * since there is no valid distance measurement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public AffineTransform getNormalizingTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Win32GraphicsEnvironment ge = (Win32GraphicsEnvironment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        double xscale = ge.getXResolution() / 72.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        double yscale = ge.getYResolution() / 72.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return (super.toString()+"[dev="+screen+",pixfmt="+visual+"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private native Rectangle getBounds(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return getBounds(screen.getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public synchronized void displayChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        solidloops = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public void paletteChanged() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * The following methods are invoked from WComponentPeer.java rather
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * than having the Win32-dependent implementations hardcoded in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * class.  This way the appropriate actions are taken based on the peer's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * GraphicsConfig, whether it is a Win32GraphicsConfig or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * WGLGraphicsConfig.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Creates a new SurfaceData that will be associated with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * WComponentPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public SurfaceData createSurfaceData(WComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                         int numBackBuffers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   246
        return GDIWindowSurfaceData.createData(peer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   250
     * Creates a new managed image of the given width and height
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * that is associated with the target Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public Image createAcceleratedImage(Component target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                                        int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        ColorModel model = getColorModel(Transparency.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        WritableRaster wr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            model.createCompatibleWritableRaster(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return new OffScreenImage(target, model, wr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                  model.isAlphaPremultiplied());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * The following methods correspond to the multibuffering methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * WComponentPeer.java...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Checks that the requested configuration is natively supported; if not,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * an AWTException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void assertOperationSupported(Component target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                         int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                         BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   277
        // the default pipeline doesn't support flip buffer strategy
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   278
        throw new AWTException(
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   279
            "The operation requested is not supported");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   283
     * This method is called from WComponentPeer when a surface data is replaced
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   284
     * REMIND: while the default pipeline doesn't support flipping, it may
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   285
     * happen that the accelerated device may have this graphics config
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   286
     * (like if the device restoration failed when one device exits fs mode
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   287
     * while others remain).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public VolatileImage createBackBuffer(WComponentPeer peer) {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   290
        Component target = (Component)peer.getTarget();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   291
        return new SunVolatileImage(target,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   292
                                    target.getWidth(), target.getHeight(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   293
                                    Boolean.TRUE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Performs the native flip operation for the given target Component.
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   298
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   299
     * REMIND: we should really not get here because that would mean that
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   300
     * a FLIP BufferStrategy has been created, and one could only be created
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   301
     * if accelerated pipeline is present but in some rare (and transitional)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   302
     * cases it may happen that the accelerated graphics device may have a
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   303
     * default graphics configuraiton, so this is just a precaution.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public void flip(WComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                     Component target, VolatileImage backBuffer,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   307
                     int x1, int y1, int x2, int y2,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                     BufferCapabilities.FlipContents flipAction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    {
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   310
        if (flipAction == BufferCapabilities.FlipContents.COPIED ||
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   311
            flipAction == BufferCapabilities.FlipContents.UNDEFINED) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   312
            Graphics g = peer.getGraphics();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   313
            try {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   314
                g.drawImage(backBuffer,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   315
                            x1, y1, x2, y2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   316
                            x1, y1, x2, y2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   317
                            null);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   318
            } finally {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   319
                g.dispose();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   320
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   321
        } else if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   322
            Graphics g = backBuffer.getGraphics();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   323
            try {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   324
                g.setColor(target.getBackground());
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   325
                g.fillRect(0, 0,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   326
                           backBuffer.getWidth(),
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   327
                           backBuffer.getHeight());
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   328
            } finally {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   329
                g.dispose();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   330
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   332
        // the rest of the flip actions are not supported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   334
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   335
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   336
    public boolean isTranslucencyCapable() {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   337
        //XXX: worth checking if 8-bit? Anyway, it doesn't hurt.
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   338
        return true;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 888
diff changeset
   339
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
}