jdk/src/solaris/classes/sun/awt/X11GraphicsConfig.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 889 6549643c008c
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 1997-2008 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.Toolkit;
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.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.ImageCapabilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.image.DirectColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.ImageProducer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.image.VolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.java2d.Disposer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.java2d.DisposerRecord;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.java2d.loops.RenderLoops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.java2d.loops.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import sun.java2d.x11.X11SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.awt.image.OffScreenImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.awt.image.SunVolatileImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.awt.image.SurfaceManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.awt.X11ComponentPeer;
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 X11 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 X11GraphicsConfig extends GraphicsConfiguration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    implements SurfaceManager.ProxiedGraphicsConfig
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected X11GraphicsDevice screen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    protected int visual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    int depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    int colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    ColorModel colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    long aData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    boolean doubleBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private Object disposerReferent = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private BufferCapabilities bufferCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static ImageCapabilities imageCaps =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        new ImageCapabilities(X11SurfaceData.isAccelerationEnabled());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // will be set on native level from init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected int bitsPerPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected SurfaceType surfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public RenderLoops solidloops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static X11GraphicsConfig getConfig(X11GraphicsDevice device,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                              int visualnum, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                              int colormap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                              boolean doubleBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return new X11GraphicsConfig(device, visualnum, depth, colormap, doubleBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Note this method is currently here for backward compatability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * as this was the method used in jdk 1.2 beta4 to create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * X11GraphicsConfig objects. Java3D code had called this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * explicitly so without this, if a user tries to use JDK1.2 fcs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * with Java3D beta1, a NoSuchMethod execption is thrown and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * the program exits. REMOVE this method after Java3D fcs is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * released!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public static X11GraphicsConfig getConfig(X11GraphicsDevice device,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                              int visualnum, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                              int colormap, int type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return new X11GraphicsConfig(device, visualnum, depth, colormap, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private native int getNumColors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private native void init(int visualNum, int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private native ColorModel makeColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    protected X11GraphicsConfig(X11GraphicsDevice device,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                int visualnum, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                int colormap, boolean doubleBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.screen = device;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.visual = visualnum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.doubleBuffer = doubleBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.depth = depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.colormap = colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        init (visualnum, screen.getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // add a record to the Disposer so that we destroy the native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        // AwtGraphicsConfigData when this object goes away (i.e. after a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // display change event)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        long x11CfgData = getAData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        Disposer.addRecord(disposerReferent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                           new X11GCDisposerRecord(x11CfgData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Return the graphics device associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public GraphicsDevice getDevice() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return screen;
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
     * Returns the visual id associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public int getVisual () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return visual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Returns the depth associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public int getDepth () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return depth;
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 colormap associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public int getColormap () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return colormap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns a number of bits allocated per pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * (might be different from depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public int getBitsPerPixel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return bitsPerPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public synchronized SurfaceType getSurfaceType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (surfaceType != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return surfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        surfaceType = X11SurfaceData.getSurfaceType(this, Transparency.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return surfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public Object getProxyKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return screen.getProxyKeyFor(getSurfaceType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Return the RenderLoops this type of destination uses for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * solid fills and strokes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public synchronized RenderLoops getSolidLoops(SurfaceType stype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (solidloops == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            solidloops = SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                                     CompositeType.SrcNoEa,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                                     stype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return solidloops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns the color model associated with this configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public synchronized ColorModel getColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (colorModel == null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            // Force SystemColors to be resolved before we create the CM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            java.awt.SystemColor.window.getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            // This method, makeColorModel(), can return null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // toolkit is not initialized yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // The toolkit will then call back to this routine after it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // is initialized and makeColorModel() should return a non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            // colorModel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            colorModel = makeColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (colorModel == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                colorModel = Toolkit.getDefaultToolkit ().getColorModel ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Returns the color model associated with this configuration that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * supports the specified transparency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public ColorModel getColorModel(int transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        switch (transparency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        case Transparency.OPAQUE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        case Transparency.BITMASK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return new DirectColorModel(25, 0xff0000, 0xff00, 0xff, 0x1000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        case Transparency.TRANSLUCENT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return ColorModel.getRGBdefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Returns the default Transform for this configuration.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Transform is typically the Identity transform for most normal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * screens.  Device coordinates for screen and printer devices will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * have the origin in the upper left-hand corner of the target region of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * the device, with X coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * increasing to the right and Y coordinates increasing downwards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * For image buffers, this Transform will be the Identity transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public AffineTransform getDefaultTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Returns a Transform that can be composed with the default Transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * of a Graphics2D so that 72 units in user space will equal 1 inch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * in device space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Given a Graphics2D, g, one can reset the transformation to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * such a mapping by using the following pseudocode:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *      GraphicsConfiguration gc = g.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *      g.setTransform(gc.getDefaultTransform());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *      g.transform(gc.getNormalizingTransform());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Note that sometimes this Transform will be identity (e.g. for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * printers or metafile output) and that this Transform is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * as accurate as the information supplied by the underlying system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * For image buffers, this Transform will be the Identity transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * since there is no valid distance measurement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public AffineTransform getNormalizingTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        double xscale = getXResolution(screen.getScreen()) / 72.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        double yscale = getYResolution(screen.getScreen()) / 72.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return new AffineTransform(xscale, 0.0, 0.0, yscale, 0.0, 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    private native double getXResolution(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    private native double getYResolution(int screen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public long getAData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return aData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return ("X11GraphicsConfig[dev="+screen+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                ",vis=0x"+Integer.toHexString(visual)+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *  accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        initIDs ();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return pGetBounds(screen.getScreen());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public native Rectangle pGetBounds(int screenNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    private static class XDBECapabilities extends BufferCapabilities {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        public XDBECapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            super(imageCaps, imageCaps, FlipContents.UNDEFINED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public BufferCapabilities getBufferCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (bufferCaps == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (doubleBuffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                bufferCaps = new XDBECapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                bufferCaps = super.getBufferCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        return bufferCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public ImageCapabilities getImageCapabilities() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return imageCaps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public boolean isDoubleBuffered() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return doubleBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    private static native void dispose(long x11ConfigData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    private static class X11GCDisposerRecord implements DisposerRecord {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        private long x11ConfigData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        public X11GCDisposerRecord(long x11CfgData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            this.x11ConfigData = x11CfgData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        public synchronized void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            if (x11ConfigData != 0L) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                X11GraphicsConfig.dispose(x11ConfigData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                x11ConfigData = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * The following methods are invoked from {M,X}Toolkit.java and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * X11ComponentPeer.java rather than having the X11-dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * implementations hardcoded in those classes.  This way the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * actions are taken based on the peer's GraphicsConfig, whether it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * an X11GraphicsConfig or a GLXGraphicsConfig.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Creates a new SurfaceData that will be associated with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * X11ComponentPeer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public SurfaceData createSurfaceData(X11ComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return X11SurfaceData.createData(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Creates a new hidden-acceleration image of the given width and height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * that is associated with the target Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public Image createAcceleratedImage(Component target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                        int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // As of 1.7 we no longer create pmoffscreens here...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        ColorModel model = getColorModel(Transparency.OPAQUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        WritableRaster wr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            model.createCompatibleWritableRaster(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return new OffScreenImage(target, model, wr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                  model.isAlphaPremultiplied());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * The following methods correspond to the multibuffering methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * X11ComponentPeer.java...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    private native long createBackBuffer(long window, int swapAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    private native void swapBuffers(long window, int swapAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * Attempts to create an XDBE-based backbuffer for the given peer.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * the requested configuration is not natively supported, an AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * is thrown.  Otherwise, if the backbuffer creation is successful, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * handle to the native backbuffer is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public long createBackBuffer(X11ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                 int numBuffers, BufferCapabilities caps)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        throws AWTException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (!X11GraphicsDevice.isDBESupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            throw new AWTException("Page flipping is not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (numBuffers > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            throw new AWTException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                "Only double or single buffering is supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        BufferCapabilities configCaps = getBufferCapabilities();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        if (!configCaps.isPageFlipping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            throw new AWTException("Page flipping is not supported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        long window = peer.getContentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        int swapAction = getSwapAction(caps.getFlipContents());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return createBackBuffer(window, swapAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Destroys the backbuffer object represented by the given handle value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public native void destroyBackBuffer(long backBuffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Creates a VolatileImage that essentially wraps the target Component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * backbuffer, using the provided backbuffer handle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public VolatileImage createBackBufferImage(Component target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                               long backBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return new SunVolatileImage(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                    target.getWidth(), target.getHeight(),
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   424
                                    Long.valueOf(backBuffer));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Performs the native XDBE flip operation for the given target Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public void flip(X11ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                     Component target, VolatileImage xBackBuffer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                     BufferCapabilities.FlipContents flipAction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        long window = peer.getContentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        int swapAction = getSwapAction(flipAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        swapBuffers(window, swapAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Maps the given FlipContents constant to the associated XDBE swap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * action constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    private static int getSwapAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        BufferCapabilities.FlipContents flipAction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        } else if (flipAction == BufferCapabilities.FlipContents.COPIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            return 0x00; // UNDEFINED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}