author | mchung |
Tue, 29 Sep 2009 16:03:03 -0700 | |
changeset 3938 | ef327bd847c0 |
parent 3928 | be186a33df9b |
child 5506 | 202f599c92aa |
child 5579 | 1a5e995a710b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 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.awt; |
|
27 |
||
28 |
import java.awt.GraphicsDevice; |
|
29 |
import java.awt.Point; |
|
30 |
import java.awt.Rectangle; |
|
31 |
import java.io.BufferedReader; |
|
32 |
import java.io.File; |
|
33 |
import java.io.FileReader; |
|
34 |
import java.io.FileNotFoundException; |
|
35 |
import java.io.InputStream; |
|
36 |
import java.io.IOException; |
|
37 |
import java.io.StreamTokenizer; |
|
38 |
import java.net.InetAddress; |
|
39 |
import java.net.NetworkInterface; |
|
40 |
import java.net.SocketException; |
|
41 |
import java.net.UnknownHostException; |
|
42 |
||
43 |
import java.util.*; |
|
44 |
||
45 |
import sun.awt.motif.MFontConfiguration; |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
46 |
import sun.font.FcFontConfiguration; |
2 | 47 |
import sun.font.Font2D; |
48 |
import sun.font.FontManager; |
|
49 |
import sun.font.NativeFont; |
|
50 |
import sun.java2d.SunGraphicsEnvironment; |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
51 |
import sun.java2d.SurfaceManagerFactory; |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
52 |
import sun.java2d.UnixSurfaceManagerFactory; |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
53 |
import sun.util.logging.PlatformLogger; |
2 | 54 |
|
55 |
/** |
|
56 |
* This is an implementation of a GraphicsEnvironment object for the |
|
57 |
* default local GraphicsEnvironment used by the Java Runtime Environment |
|
58 |
* for X11 environments. |
|
59 |
* |
|
60 |
* @see GraphicsDevice |
|
61 |
* @see GraphicsConfiguration |
|
62 |
*/ |
|
63 |
public class X11GraphicsEnvironment |
|
64 |
extends SunGraphicsEnvironment |
|
65 |
{ |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
66 |
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11GraphicsEnvironment"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
67 |
private static final PlatformLogger screenLog = PlatformLogger.getLogger("sun.awt.screen.X11GraphicsEnvironment"); |
2 | 68 |
|
69 |
private static Boolean xinerState; |
|
70 |
||
71 |
static { |
|
72 |
java.security.AccessController.doPrivileged( |
|
73 |
new java.security.PrivilegedAction() { |
|
74 |
public Object run() { |
|
75 |
System.loadLibrary("awt"); |
|
76 |
||
77 |
/* |
|
78 |
* Note: The MToolkit object depends on the static initializer |
|
79 |
* of X11GraphicsEnvironment to initialize the connection to |
|
80 |
* the X11 server. |
|
81 |
*/ |
|
82 |
if (!isHeadless()) { |
|
83 |
// first check the OGL system property |
|
84 |
boolean glxRequested = false; |
|
85 |
String prop = System.getProperty("sun.java2d.opengl"); |
|
86 |
if (prop != null) { |
|
87 |
if (prop.equals("true") || prop.equals("t")) { |
|
88 |
glxRequested = true; |
|
89 |
} else if (prop.equals("True") || prop.equals("T")) { |
|
90 |
glxRequested = true; |
|
91 |
glxVerbose = true; |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
// initialize the X11 display connection |
|
96 |
initDisplay(glxRequested); |
|
97 |
||
98 |
// only attempt to initialize GLX if it was requested |
|
99 |
if (glxRequested) { |
|
100 |
glxAvailable = initGLX(); |
|
101 |
if (glxVerbose && !glxAvailable) { |
|
102 |
System.out.println( |
|
103 |
"Could not enable OpenGL " + |
|
104 |
"pipeline (GLX 1.3 not available)"); |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
return null; |
|
110 |
} |
|
111 |
}); |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
112 |
|
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
113 |
// Install the correct surface manager factory. |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
114 |
SurfaceManagerFactory.setInstance(new UnixSurfaceManagerFactory()); |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
2
diff
changeset
|
115 |
|
2 | 116 |
} |
117 |
||
118 |
private static boolean glxAvailable; |
|
119 |
private static boolean glxVerbose; |
|
120 |
||
121 |
private static native boolean initGLX(); |
|
122 |
||
123 |
public static boolean isGLXAvailable() { |
|
124 |
return glxAvailable; |
|
125 |
} |
|
126 |
||
127 |
public static boolean isGLXVerbose() { |
|
128 |
return glxVerbose; |
|
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* Checks if Shared Memory extension can be used. |
|
133 |
* Returns: |
|
134 |
* -1 if server doesn't support MITShm |
|
135 |
* 1 if server supports it and it can be used |
|
136 |
* 0 otherwise |
|
137 |
*/ |
|
138 |
private static native int checkShmExt(); |
|
139 |
||
140 |
private static native String getDisplayString(); |
|
1724
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
141 |
private Boolean isDisplayLocal; |
2 | 142 |
|
143 |
/** |
|
144 |
* This should only be called from the static initializer, so no need for |
|
145 |
* the synchronized keyword. |
|
146 |
*/ |
|
147 |
private static native void initDisplay(boolean glxRequested); |
|
148 |
||
149 |
public X11GraphicsEnvironment() { |
|
150 |
} |
|
151 |
||
152 |
protected native int getNumScreens(); |
|
153 |
||
154 |
protected GraphicsDevice makeScreenDevice(int screennum) { |
|
155 |
return new X11GraphicsDevice(screennum); |
|
156 |
} |
|
157 |
||
158 |
protected native int getDefaultScreenNum(); |
|
159 |
/** |
|
160 |
* Returns the default screen graphics device. |
|
161 |
*/ |
|
162 |
public GraphicsDevice getDefaultScreenDevice() { |
|
163 |
return getScreenDevices()[getDefaultScreenNum()]; |
|
164 |
} |
|
165 |
||
1724
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
166 |
public boolean isDisplayLocal() { |
2 | 167 |
if (isDisplayLocal == null) { |
168 |
SunToolkit.awtLock(); |
|
169 |
try { |
|
170 |
if (isDisplayLocal == null) { |
|
171 |
isDisplayLocal = Boolean.valueOf(_isDisplayLocal()); |
|
172 |
} |
|
173 |
} finally { |
|
174 |
SunToolkit.awtUnlock(); |
|
175 |
} |
|
176 |
} |
|
177 |
return isDisplayLocal.booleanValue(); |
|
178 |
} |
|
179 |
||
180 |
private static boolean _isDisplayLocal() { |
|
181 |
if (isHeadless()) { |
|
182 |
return true; |
|
183 |
} |
|
184 |
||
185 |
String isRemote = (String)java.security.AccessController.doPrivileged( |
|
186 |
new sun.security.action.GetPropertyAction("sun.java2d.remote")); |
|
187 |
if (isRemote != null) { |
|
188 |
return isRemote.equals("false"); |
|
189 |
} |
|
190 |
||
191 |
int shm = checkShmExt(); |
|
192 |
if (shm != -1) { |
|
193 |
return (shm == 1); |
|
194 |
} |
|
195 |
||
196 |
// If XServer doesn't support ShMem extension, |
|
197 |
// try the other way |
|
198 |
||
199 |
String display = getDisplayString(); |
|
200 |
int ind = display.indexOf(':'); |
|
201 |
final String hostName = display.substring(0, ind); |
|
202 |
if (ind <= 0) { |
|
203 |
// ':0' case |
|
204 |
return true; |
|
205 |
} |
|
206 |
||
207 |
Boolean result = (Boolean)java.security.AccessController.doPrivileged( |
|
208 |
new java.security.PrivilegedAction() { |
|
209 |
public Object run() { |
|
210 |
InetAddress remAddr[] = null; |
|
211 |
Enumeration locals = null; |
|
212 |
Enumeration interfaces = null; |
|
213 |
try { |
|
214 |
interfaces = NetworkInterface.getNetworkInterfaces(); |
|
215 |
remAddr = InetAddress.getAllByName(hostName); |
|
216 |
if (remAddr == null) { |
|
217 |
return Boolean.FALSE; |
|
218 |
} |
|
219 |
} catch (UnknownHostException e) { |
|
220 |
System.err.println("Unknown host: " + hostName); |
|
221 |
return Boolean.FALSE; |
|
222 |
} catch (SocketException e1) { |
|
223 |
System.err.println(e1.getMessage()); |
|
224 |
return Boolean.FALSE; |
|
225 |
} |
|
226 |
||
227 |
for (; interfaces.hasMoreElements();) { |
|
228 |
locals = ((NetworkInterface)interfaces.nextElement()).getInetAddresses(); |
|
229 |
for (; locals.hasMoreElements();) { |
|
230 |
for (int i = 0; i < remAddr.length; i++) { |
|
231 |
if (locals.nextElement().equals(remAddr[i])) { |
|
232 |
return Boolean.TRUE; |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
return Boolean.FALSE; |
|
238 |
}}); |
|
239 |
return result.booleanValue(); |
|
240 |
} |
|
241 |
||
242 |
||
243 |
||
244 |
/** |
|
245 |
* Returns face name for default font, or null if |
|
246 |
* no face names are used for CompositeFontDescriptors |
|
247 |
* for this platform. |
|
248 |
*/ |
|
249 |
public String getDefaultFontFaceName() { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
250 |
|
2 | 251 |
return null; |
252 |
} |
|
253 |
||
254 |
private static native boolean pRunningXinerama(); |
|
255 |
private static native Point getXineramaCenterPoint(); |
|
256 |
||
257 |
/** |
|
258 |
* Override for Xinerama case: call new Solaris API for getting the correct |
|
259 |
* centering point from the windowing system. |
|
260 |
*/ |
|
261 |
public Point getCenterPoint() { |
|
262 |
if (runningXinerama()) { |
|
263 |
Point p = getXineramaCenterPoint(); |
|
264 |
if (p != null) { |
|
265 |
return p; |
|
266 |
} |
|
267 |
} |
|
268 |
return super.getCenterPoint(); |
|
269 |
} |
|
270 |
||
271 |
/** |
|
272 |
* Override for Xinerama case |
|
273 |
*/ |
|
274 |
public Rectangle getMaximumWindowBounds() { |
|
275 |
if (runningXinerama()) { |
|
276 |
return getXineramaWindowBounds(); |
|
277 |
} else { |
|
278 |
return super.getMaximumWindowBounds(); |
|
279 |
} |
|
280 |
} |
|
281 |
||
282 |
public boolean runningXinerama() { |
|
283 |
if (xinerState == null) { |
|
284 |
// pRunningXinerama() simply returns a global boolean variable, |
|
285 |
// so there is no need to synchronize here |
|
286 |
xinerState = Boolean.valueOf(pRunningXinerama()); |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
287 |
if (screenLog.isLoggable(PlatformLogger.FINER)) { |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
288 |
screenLog.finer("Running Xinerama: " + xinerState); |
2 | 289 |
} |
290 |
} |
|
291 |
return xinerState.booleanValue(); |
|
292 |
} |
|
293 |
||
294 |
/** |
|
295 |
* Return the bounds for a centered Window on a system running in Xinerama |
|
296 |
* mode. |
|
297 |
* |
|
298 |
* Calculations are based on the assumption of a perfectly rectangular |
|
299 |
* display area (display edges line up with one another, and displays |
|
300 |
* have consistent width and/or height). |
|
301 |
* |
|
302 |
* The bounds to return depend on the arrangement of displays and on where |
|
303 |
* Windows are to be centered. There are two common situations: |
|
304 |
* |
|
305 |
* 1) The center point lies at the center of the combined area of all the |
|
306 |
* displays. In this case, the combined area of all displays is |
|
307 |
* returned. |
|
308 |
* |
|
309 |
* 2) The center point lies at the center of a single display. In this case |
|
310 |
* the user most likely wants centered Windows to be constrained to that |
|
311 |
* single display. The boundaries of the one display are returned. |
|
312 |
* |
|
313 |
* It is possible for the center point to be at both the center of the |
|
314 |
* entire display space AND at the center of a single monitor (a square of |
|
315 |
* 9 monitors, for instance). In this case, the entire display area is |
|
316 |
* returned. |
|
317 |
* |
|
318 |
* Because the center point is arbitrarily settable by the user, it could |
|
319 |
* fit neither of the cases above. The fallback case is to simply return |
|
320 |
* the combined area for all screens. |
|
321 |
*/ |
|
322 |
protected Rectangle getXineramaWindowBounds() { |
|
323 |
Point center = getCenterPoint(); |
|
324 |
Rectangle unionRect, tempRect; |
|
325 |
GraphicsDevice[] gds = getScreenDevices(); |
|
326 |
Rectangle centerMonitorRect = null; |
|
327 |
int i; |
|
328 |
||
329 |
// if center point is at the center of all monitors |
|
330 |
// return union of all bounds |
|
331 |
// |
|
332 |
// MM*MM MMM M |
|
333 |
// M*M * |
|
334 |
// MMM M |
|
335 |
||
336 |
// if center point is at center of a single monitor (but not of all |
|
337 |
// monitors) |
|
338 |
// return bounds of single monitor |
|
339 |
// |
|
340 |
// MMM MM |
|
341 |
// MM* *M |
|
342 |
||
343 |
// else, center is in some strange spot (such as on the border between |
|
344 |
// monitors), and we should just return the union of all monitors |
|
345 |
// |
|
346 |
// MM MMM |
|
347 |
// MM MMM |
|
348 |
||
349 |
unionRect = getUsableBounds(gds[0]); |
|
350 |
||
351 |
for (i = 0; i < gds.length; i++) { |
|
352 |
tempRect = getUsableBounds(gds[i]); |
|
353 |
if (centerMonitorRect == null && |
|
354 |
// add a pixel or two for fudge-factor |
|
355 |
(tempRect.width / 2) + tempRect.x > center.x - 1 && |
|
356 |
(tempRect.height / 2) + tempRect.y > center.y - 1 && |
|
357 |
(tempRect.width / 2) + tempRect.x < center.x + 1 && |
|
358 |
(tempRect.height / 2) + tempRect.y < center.y + 1) { |
|
359 |
centerMonitorRect = tempRect; |
|
360 |
} |
|
361 |
unionRect = unionRect.union(tempRect); |
|
362 |
} |
|
363 |
||
364 |
// first: check for center of all monitors (video wall) |
|
365 |
// add a pixel or two for fudge-factor |
|
366 |
if ((unionRect.width / 2) + unionRect.x > center.x - 1 && |
|
367 |
(unionRect.height / 2) + unionRect.y > center.y - 1 && |
|
368 |
(unionRect.width / 2) + unionRect.x < center.x + 1 && |
|
369 |
(unionRect.height / 2) + unionRect.y < center.y + 1) { |
|
370 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
371 |
if (screenLog.isLoggable(PlatformLogger.FINER)) { |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
372 |
screenLog.finer("Video Wall: center point is at center of all displays."); |
2 | 373 |
} |
374 |
return unionRect; |
|
375 |
} |
|
376 |
||
377 |
// next, check if at center of one monitor |
|
378 |
if (centerMonitorRect != null) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
379 |
if (screenLog.isLoggable(PlatformLogger.FINER)) { |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
380 |
screenLog.finer("Center point at center of a particular " + |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
381 |
"monitor, but not of the entire virtual display."); |
2 | 382 |
} |
383 |
return centerMonitorRect; |
|
384 |
} |
|
385 |
||
386 |
// otherwise, the center is at some weird spot: return unionRect |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
387 |
if (screenLog.isLoggable(PlatformLogger.FINER)) { |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
3928
diff
changeset
|
388 |
screenLog.finer("Center point is somewhere strange - return union of all bounds."); |
2 | 389 |
} |
390 |
return unionRect; |
|
391 |
} |
|
392 |
||
393 |
/** |
|
394 |
* From the DisplayChangedListener interface; devices do not need |
|
395 |
* to react to this event. |
|
396 |
*/ |
|
397 |
@Override |
|
398 |
public void paletteChanged() { |
|
399 |
} |
|
400 |
} |