jdk/src/windows/classes/sun/java2d/opengl/WGLSurfaceData.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 887 0aab8d3fa11a
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
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.java2d.opengl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.windows.WComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public abstract class WGLSurfaceData extends OGLSurfaceData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    protected WComponentPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private WGLGraphicsConfig graphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private native void initOps(long pConfigInfo, long pPeerData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                                int xoff, int yoff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    protected native boolean initPbuffer(long pData, long pConfigInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                                         boolean isOpaque,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                         int width, int height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                             ColorModel cm, int type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        super(gc, cm, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        this.graphicsConfig = gc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        long pConfigInfo = gc.getNativeConfigInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        long pPeerData = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int xoff = 0, yoff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            Component c = (Component)peer.getTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            if (c instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                Insets insets = ((Container)c).getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                xoff = -insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                yoff = -insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            pPeerData = peer.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        initOps(pConfigInfo, pPeerData, xoff, yoff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public GraphicsConfiguration getDeviceConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        return graphicsConfig;
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
     * Creates a SurfaceData object representing the primary (front) buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * of an on-screen Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static WGLWindowSurfaceData createData(WComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        WGLGraphicsConfig gc = getGC(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return new WGLWindowSurfaceData(peer, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Creates a SurfaceData object representing the back buffer of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * double-buffered on-screen Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static WGLOffScreenSurfaceData createData(WComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                                     Image image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        WGLGraphicsConfig gc = getGC(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Rectangle r = peer.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return new WGLOffScreenSurfaceData(peer, gc, r.width, r.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                           image, peer.getColorModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                           FLIP_BACKBUFFER);
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
     * Creates a SurfaceData object representing an off-screen buffer (either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * a Pbuffer or Texture).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static WGLOffScreenSurfaceData createData(WGLGraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                                     int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                                     ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                                     Image image, int type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return new WGLOffScreenSurfaceData(null, gc, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                           image, cm, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public static WGLGraphicsConfig getGC(WComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return (WGLGraphicsConfig)peer.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            // REMIND: this should rarely (never?) happen, but what if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            //         default config is not WGL?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            GraphicsEnvironment env =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            GraphicsDevice gd = env.getDefaultScreenDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return (WGLGraphicsConfig)gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static class WGLWindowSurfaceData extends WGLSurfaceData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        public WGLWindowSurfaceData(WComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                    WGLGraphicsConfig gc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            super(peer, gc, peer.getColorModel(), WINDOW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public SurfaceData getReplacement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            return peer.getSurfaceData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            Rectangle r = peer.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            r.x = r.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * Returns destination Component associated with this SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        public Object getDestination() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return peer.getTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public static class WGLOffScreenSurfaceData extends WGLSurfaceData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        private Image offscreenImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        private int width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        public WGLOffScreenSurfaceData(WComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                       WGLGraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                       int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                       Image image, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                       int type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            super(peer, gc, cm, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            offscreenImage = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            initSurface(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        public SurfaceData getReplacement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            return restoreContents(offscreenImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            if (type == FLIP_BACKBUFFER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                Rectangle r = peer.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                r.x = r.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                return new Rectangle(width, height);
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 destination Image associated with this SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public Object getDestination() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return offscreenImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
}