2
|
1 |
/*
|
|
2 |
* Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.java2d.opengl;
|
|
27 |
|
|
28 |
import java.awt.Component;
|
|
29 |
import java.awt.Container;
|
|
30 |
import java.awt.GraphicsConfiguration;
|
|
31 |
import java.awt.GraphicsDevice;
|
|
32 |
import java.awt.GraphicsEnvironment;
|
|
33 |
import java.awt.Image;
|
|
34 |
import java.awt.Insets;
|
|
35 |
import java.awt.Rectangle;
|
|
36 |
import java.awt.Transparency;
|
|
37 |
import java.awt.image.ColorModel;
|
|
38 |
import sun.awt.windows.WComponentPeer;
|
|
39 |
import sun.java2d.SurfaceData;
|
|
40 |
import sun.java2d.loops.SurfaceType;
|
|
41 |
|
|
42 |
public abstract class WGLSurfaceData extends OGLSurfaceData {
|
|
43 |
|
|
44 |
protected WComponentPeer peer;
|
|
45 |
private WGLGraphicsConfig graphicsConfig;
|
|
46 |
|
|
47 |
private native void initOps(long pConfigInfo, long pPeerData,
|
|
48 |
int xoff, int yoff);
|
|
49 |
protected native boolean initPbuffer(long pData, long pConfigInfo,
|
|
50 |
boolean isOpaque,
|
|
51 |
int width, int height);
|
|
52 |
|
|
53 |
protected WGLSurfaceData(WComponentPeer peer, WGLGraphicsConfig gc,
|
|
54 |
ColorModel cm, int type)
|
|
55 |
{
|
|
56 |
super(gc, cm, type);
|
|
57 |
this.peer = peer;
|
|
58 |
this.graphicsConfig = gc;
|
|
59 |
|
|
60 |
long pConfigInfo = gc.getNativeConfigInfo();
|
|
61 |
long pPeerData = 0L;
|
|
62 |
int xoff = 0, yoff = 0;
|
|
63 |
if (peer != null) {
|
|
64 |
Component c = (Component)peer.getTarget();
|
|
65 |
if (c instanceof Container) {
|
|
66 |
Insets insets = ((Container)c).getInsets();
|
|
67 |
xoff = -insets.left;
|
|
68 |
yoff = -insets.bottom;
|
|
69 |
}
|
|
70 |
pPeerData = peer.getData();
|
|
71 |
}
|
|
72 |
|
|
73 |
initOps(pConfigInfo, pPeerData, xoff, yoff);
|
|
74 |
}
|
|
75 |
|
|
76 |
public GraphicsConfiguration getDeviceConfiguration() {
|
|
77 |
return graphicsConfig;
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Creates a SurfaceData object representing the primary (front) buffer
|
|
82 |
* of an on-screen Window.
|
|
83 |
*/
|
|
84 |
public static WGLWindowSurfaceData createData(WComponentPeer peer) {
|
|
85 |
WGLGraphicsConfig gc = getGC(peer);
|
|
86 |
return new WGLWindowSurfaceData(peer, gc);
|
|
87 |
}
|
|
88 |
|
|
89 |
/**
|
|
90 |
* Creates a SurfaceData object representing the back buffer of a
|
|
91 |
* double-buffered on-screen Window.
|
|
92 |
*/
|
|
93 |
public static WGLOffScreenSurfaceData createData(WComponentPeer peer,
|
|
94 |
Image image)
|
|
95 |
{
|
|
96 |
WGLGraphicsConfig gc = getGC(peer);
|
|
97 |
Rectangle r = peer.getBounds();
|
|
98 |
return new WGLOffScreenSurfaceData(peer, gc, r.width, r.height,
|
|
99 |
image, peer.getColorModel(),
|
|
100 |
FLIP_BACKBUFFER);
|
|
101 |
}
|
|
102 |
|
|
103 |
/**
|
|
104 |
* Creates a SurfaceData object representing an off-screen buffer (either
|
|
105 |
* a Pbuffer or Texture).
|
|
106 |
*/
|
|
107 |
public static WGLOffScreenSurfaceData createData(WGLGraphicsConfig gc,
|
|
108 |
int width, int height,
|
|
109 |
ColorModel cm,
|
|
110 |
Image image, int type)
|
|
111 |
{
|
|
112 |
return new WGLOffScreenSurfaceData(null, gc, width, height,
|
|
113 |
image, cm, type);
|
|
114 |
}
|
|
115 |
|
|
116 |
public static WGLGraphicsConfig getGC(WComponentPeer peer) {
|
|
117 |
if (peer != null) {
|
|
118 |
return (WGLGraphicsConfig)peer.getGraphicsConfiguration();
|
|
119 |
} else {
|
|
120 |
// REMIND: this should rarely (never?) happen, but what if
|
|
121 |
// default config is not WGL?
|
|
122 |
GraphicsEnvironment env =
|
|
123 |
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
|
124 |
GraphicsDevice gd = env.getDefaultScreenDevice();
|
|
125 |
return (WGLGraphicsConfig)gd.getDefaultConfiguration();
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
public static class WGLWindowSurfaceData extends WGLSurfaceData {
|
|
130 |
|
|
131 |
public WGLWindowSurfaceData(WComponentPeer peer,
|
|
132 |
WGLGraphicsConfig gc)
|
|
133 |
{
|
|
134 |
super(peer, gc, peer.getColorModel(), WINDOW);
|
|
135 |
}
|
|
136 |
|
|
137 |
public SurfaceData getReplacement() {
|
|
138 |
return peer.getSurfaceData();
|
|
139 |
}
|
|
140 |
|
|
141 |
public Rectangle getBounds() {
|
|
142 |
Rectangle r = peer.getBounds();
|
|
143 |
r.x = r.y = 0;
|
|
144 |
return r;
|
|
145 |
}
|
|
146 |
|
|
147 |
/**
|
|
148 |
* Returns destination Component associated with this SurfaceData.
|
|
149 |
*/
|
|
150 |
public Object getDestination() {
|
|
151 |
return peer.getTarget();
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
public static class WGLOffScreenSurfaceData extends WGLSurfaceData {
|
|
156 |
|
|
157 |
private Image offscreenImage;
|
|
158 |
private int width, height;
|
|
159 |
|
|
160 |
public WGLOffScreenSurfaceData(WComponentPeer peer,
|
|
161 |
WGLGraphicsConfig gc,
|
|
162 |
int width, int height,
|
|
163 |
Image image, ColorModel cm,
|
|
164 |
int type)
|
|
165 |
{
|
|
166 |
super(peer, gc, cm, type);
|
|
167 |
|
|
168 |
this.width = width;
|
|
169 |
this.height = height;
|
|
170 |
offscreenImage = image;
|
|
171 |
|
|
172 |
initSurface(width, height);
|
|
173 |
}
|
|
174 |
|
|
175 |
public SurfaceData getReplacement() {
|
|
176 |
return restoreContents(offscreenImage);
|
|
177 |
}
|
|
178 |
|
|
179 |
public Rectangle getBounds() {
|
|
180 |
if (type == FLIP_BACKBUFFER) {
|
|
181 |
Rectangle r = peer.getBounds();
|
|
182 |
r.x = r.y = 0;
|
|
183 |
return r;
|
|
184 |
} else {
|
|
185 |
return new Rectangle(width, height);
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Returns destination Image associated with this SurfaceData.
|
|
191 |
*/
|
|
192 |
public Object getDestination() {
|
|
193 |
return offscreenImage;
|
|
194 |
}
|
|
195 |
}
|
|
196 |
}
|