author | lana |
Sun, 22 Feb 2009 12:26:39 -0800 | |
changeset 2460 | 15e4d52f9ed4 |
parent 2451 | 597df8e1d786 |
parent 1724 | a22a286aa16f |
child 3928 | be186a33df9b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2451 | 2 |
* Copyright 1997-2009 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 |
||
887 | 28 |
import java.awt.GraphicsConfiguration; |
2 | 29 |
import java.awt.GraphicsDevice; |
30 |
import java.awt.GraphicsEnvironment; |
|
31 |
import java.awt.Toolkit; |
|
887 | 32 |
import java.awt.peer.ComponentPeer; |
2 | 33 |
import java.io.File; |
34 |
import java.io.IOException; |
|
35 |
import java.lang.ref.WeakReference; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.ListIterator; |
|
38 |
import java.util.NoSuchElementException; |
|
39 |
import java.util.StringTokenizer; |
|
40 |
import sun.awt.DisplayChangedListener; |
|
41 |
import sun.awt.SunDisplayChanger; |
|
42 |
import sun.awt.windows.WFontConfiguration; |
|
43 |
import sun.awt.windows.WPrinterJob; |
|
44 |
import sun.awt.windows.WToolkit; |
|
45 |
import sun.font.FontManager; |
|
46 |
import sun.java2d.SunGraphicsEnvironment; |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
47 |
import sun.java2d.SurfaceManagerFactory; |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
48 |
import sun.java2d.WindowsSurfaceManagerFactory; |
887 | 49 |
import sun.java2d.d3d.D3DGraphicsDevice; |
2 | 50 |
import sun.java2d.windows.WindowsFlags; |
51 |
||
52 |
/** |
|
53 |
* This is an implementation of a GraphicsEnvironment object for the |
|
54 |
* default local GraphicsEnvironment used by the Java Runtime Environment |
|
55 |
* for Windows. |
|
56 |
* |
|
57 |
* @see GraphicsDevice |
|
58 |
* @see GraphicsConfiguration |
|
59 |
*/ |
|
60 |
||
61 |
public class Win32GraphicsEnvironment |
|
62 |
extends SunGraphicsEnvironment |
|
63 |
{ |
|
64 |
static { |
|
65 |
// Ensure awt is loaded already. Also, this forces static init |
|
66 |
// of WToolkit and Toolkit, which we depend upon |
|
67 |
WToolkit.loadLibraries(); |
|
68 |
// setup flags before initializing native layer |
|
69 |
WindowsFlags.initFlags(); |
|
70 |
initDisplayWrapper(); |
|
71 |
eudcFontFileName = getEUDCFontFile(); |
|
557
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
72 |
|
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
73 |
// Install correct surface manager factory. |
800259d3792b
6675596: SurfaceManagerFactory should allow plugging in different implementations
tdv
parents:
550
diff
changeset
|
74 |
SurfaceManagerFactory.setInstance(new WindowsSurfaceManagerFactory()); |
2 | 75 |
} |
76 |
||
77 |
/** |
|
78 |
* Noop function that just acts as an entry point for someone to force |
|
79 |
* a static initialization of this class. |
|
80 |
*/ |
|
81 |
public static void init() {} |
|
82 |
||
83 |
/** |
|
84 |
* Initializes native components of the graphics environment. This |
|
85 |
* includes everything from the native GraphicsDevice elements to |
|
86 |
* the DirectX rendering layer. |
|
87 |
*/ |
|
88 |
private static native void initDisplay(); |
|
89 |
||
90 |
private static boolean displayInitialized; // = false; |
|
91 |
public static void initDisplayWrapper() { |
|
92 |
if (!displayInitialized) { |
|
93 |
displayInitialized = true; |
|
94 |
initDisplay(); |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
public Win32GraphicsEnvironment() { |
|
99 |
} |
|
100 |
||
101 |
protected native int getNumScreens(); |
|
102 |
protected native int getDefaultScreen(); |
|
103 |
||
104 |
public GraphicsDevice getDefaultScreenDevice() { |
|
105 |
return getScreenDevices()[getDefaultScreen()]; |
|
106 |
} |
|
107 |
||
108 |
/** |
|
109 |
* Returns the number of pixels per logical inch along the screen width. |
|
110 |
* In a system with multiple display monitors, this value is the same for |
|
111 |
* all monitors. |
|
112 |
* @returns number of pixels per logical inch in X direction |
|
113 |
*/ |
|
114 |
public native int getXResolution(); |
|
115 |
/** |
|
116 |
* Returns the number of pixels per logical inch along the screen height. |
|
117 |
* In a system with multiple display monitors, this value is the same for |
|
118 |
* all monitors. |
|
119 |
* @returns number of pixels per logical inch in Y direction |
|
120 |
*/ |
|
121 |
public native int getYResolution(); |
|
122 |
||
123 |
||
124 |
/* |
|
125 |
* ----DISPLAY CHANGE SUPPORT---- |
|
126 |
*/ |
|
127 |
||
128 |
// list of invalidated graphics devices (those which were removed) |
|
129 |
private ArrayList<WeakReference<Win32GraphicsDevice>> oldDevices; |
|
130 |
/* |
|
131 |
* From DisplayChangeListener interface. |
|
132 |
* Called from WToolkit and executed on the event thread when the |
|
133 |
* display settings are changed. |
|
134 |
*/ |
|
135 |
@Override |
|
136 |
public void displayChanged() { |
|
137 |
// getNumScreens() will return the correct current number of screens |
|
138 |
GraphicsDevice newDevices[] = new GraphicsDevice[getNumScreens()]; |
|
139 |
GraphicsDevice oldScreens[] = screens; |
|
140 |
// go through the list of current devices and determine if they |
|
141 |
// could be reused, or will have to be replaced |
|
142 |
if (oldScreens != null) { |
|
143 |
for (int i = 0; i < oldScreens.length; i++) { |
|
144 |
if (!(screens[i] instanceof Win32GraphicsDevice)) { |
|
145 |
// REMIND: can we ever have anything other than Win32GD? |
|
146 |
assert (false) : oldScreens[i]; |
|
147 |
continue; |
|
148 |
} |
|
149 |
Win32GraphicsDevice gd = (Win32GraphicsDevice)oldScreens[i]; |
|
150 |
// devices may be invalidated from the native code when the |
|
151 |
// display change happens (device add/removal also causes a |
|
152 |
// display change) |
|
153 |
if (!gd.isValid()) { |
|
154 |
if (oldDevices == null) { |
|
155 |
oldDevices = |
|
156 |
new ArrayList<WeakReference<Win32GraphicsDevice>>(); |
|
157 |
} |
|
158 |
oldDevices.add(new WeakReference<Win32GraphicsDevice>(gd)); |
|
159 |
} else if (i < newDevices.length) { |
|
160 |
// reuse the device |
|
161 |
newDevices[i] = gd; |
|
162 |
} |
|
163 |
} |
|
164 |
oldScreens = null; |
|
165 |
} |
|
166 |
// create the new devices (those that weren't reused) |
|
167 |
for (int i = 0; i < newDevices.length; i++) { |
|
168 |
if (newDevices[i] == null) { |
|
169 |
newDevices[i] = makeScreenDevice(i); |
|
170 |
} |
|
171 |
} |
|
172 |
// install the new array of devices |
|
173 |
// Note: no synchronization here, it doesn't matter if a thread gets |
|
174 |
// a new or an old array this time around |
|
175 |
screens = newDevices; |
|
176 |
for (GraphicsDevice gd : screens) { |
|
177 |
if (gd instanceof DisplayChangedListener) { |
|
178 |
((DisplayChangedListener)gd).displayChanged(); |
|
179 |
} |
|
180 |
} |
|
181 |
// re-invalidate all old devices. It's needed because those in the list |
|
182 |
// may become "invalid" again - if the current default device is removed, |
|
183 |
// for example. Also, they need to be notified about display |
|
184 |
// changes as well. |
|
185 |
if (oldDevices != null) { |
|
186 |
int defScreen = getDefaultScreen(); |
|
187 |
for (ListIterator<WeakReference<Win32GraphicsDevice>> it = |
|
188 |
oldDevices.listIterator(); it.hasNext();) |
|
189 |
{ |
|
190 |
Win32GraphicsDevice gd = it.next().get(); |
|
191 |
if (gd != null) { |
|
192 |
gd.invalidate(defScreen); |
|
193 |
gd.displayChanged(); |
|
194 |
} else { |
|
195 |
// no more references to this device, remove it |
|
196 |
it.remove(); |
|
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
// Reset the static GC for the (possibly new) default screen |
|
201 |
WToolkit.resetGC(); |
|
202 |
||
203 |
// notify SunDisplayChanger list (e.g. VolatileSurfaceManagers and |
|
204 |
// CachingSurfaceManagers) about the display change event |
|
205 |
displayChanger.notifyListeners(); |
|
206 |
// note: do not call super.displayChanged, we've already done everything |
|
207 |
} |
|
208 |
||
209 |
||
210 |
/* |
|
211 |
* ----END DISPLAY CHANGE SUPPORT---- |
|
212 |
*/ |
|
213 |
||
214 |
/* Used on Windows to obtain from the windows registry the name |
|
215 |
* of a file containing the system EUFC font. If running in one of |
|
216 |
* the locales for which this applies, and one is defined, the font |
|
217 |
* defined by this file is appended to all composite fonts as a |
|
218 |
* fallback component. |
|
219 |
*/ |
|
220 |
private static native String getEUDCFontFile(); |
|
221 |
||
222 |
/** |
|
223 |
* Whether registerFontFile expects absolute or relative |
|
224 |
* font file names. |
|
225 |
*/ |
|
226 |
protected boolean useAbsoluteFontFileNames() { |
|
227 |
return false; |
|
228 |
} |
|
229 |
||
230 |
/* Unlike the shared code version, this expects a base file name - |
|
231 |
* not a full path name. |
|
232 |
* The font configuration file has base file names and the FontConfiguration |
|
233 |
* class reports these back to the GraphicsEnvironment, so these |
|
234 |
* are the componentFileNames of CompositeFonts. |
|
235 |
*/ |
|
236 |
protected void registerFontFile(String fontFileName, String[] nativeNames, |
|
237 |
int fontRank, boolean defer) { |
|
238 |
||
239 |
// REMIND: case compare depends on platform |
|
240 |
if (registeredFontFiles.contains(fontFileName)) { |
|
241 |
return; |
|
242 |
} |
|
243 |
registeredFontFiles.add(fontFileName); |
|
244 |
||
245 |
int fontFormat; |
|
246 |
if (ttFilter.accept(null, fontFileName)) { |
|
247 |
fontFormat = FontManager.FONTFORMAT_TRUETYPE; |
|
248 |
} else if (t1Filter.accept(null, fontFileName)) { |
|
249 |
fontFormat = FontManager.FONTFORMAT_TYPE1; |
|
250 |
} else { |
|
251 |
/* on windows we don't use/register native fonts */ |
|
252 |
return; |
|
253 |
} |
|
254 |
||
255 |
if (fontPath == null) { |
|
256 |
fontPath = getPlatformFontPath(noType1Font); |
|
257 |
} |
|
258 |
||
259 |
/* Look in the JRE font directory first. |
|
260 |
* This is playing it safe as we would want to find fonts in the |
|
261 |
* JRE font directory ahead of those in the system directory |
|
262 |
*/ |
|
263 |
String tmpFontPath = jreFontDirName+File.pathSeparator+fontPath; |
|
264 |
StringTokenizer parser = new StringTokenizer(tmpFontPath, |
|
265 |
File.pathSeparator); |
|
266 |
||
267 |
boolean found = false; |
|
268 |
try { |
|
269 |
while (!found && parser.hasMoreTokens()) { |
|
270 |
String newPath = parser.nextToken(); |
|
550
e85f91b9bb95
6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents:
548
diff
changeset
|
271 |
boolean ujr = newPath.equals(jreFontDirName); |
2 | 272 |
File theFile = new File(newPath, fontFileName); |
273 |
if (theFile.canRead()) { |
|
274 |
found = true; |
|
275 |
String path = theFile.getAbsolutePath(); |
|
276 |
if (defer) { |
|
277 |
FontManager.registerDeferredFont(fontFileName, path, |
|
278 |
nativeNames, |
|
550
e85f91b9bb95
6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents:
548
diff
changeset
|
279 |
fontFormat, ujr, |
2 | 280 |
fontRank); |
281 |
} else { |
|
282 |
FontManager.registerFontFile(path, nativeNames, |
|
550
e85f91b9bb95
6656651: Windows Look and Feel LCD glyph images have some differences from native applications.
prr
parents:
548
diff
changeset
|
283 |
fontFormat, ujr, |
2 | 284 |
fontRank); |
285 |
} |
|
286 |
break; |
|
287 |
} |
|
288 |
} |
|
289 |
} catch (NoSuchElementException e) { |
|
290 |
System.err.println(e); |
|
291 |
} |
|
292 |
if (!found) { |
|
293 |
addToMissingFontFileList(fontFileName); |
|
294 |
} |
|
295 |
} |
|
296 |
||
297 |
/* register only TrueType/OpenType fonts |
|
298 |
* Because these need to be registed just for use when printing, |
|
299 |
* we defer the actual registration and the static initialiser |
|
300 |
* for the printing class makes the call to registerJREFontsForPrinting() |
|
301 |
*/ |
|
302 |
static String fontsForPrinting = null; |
|
303 |
protected void registerJREFontsWithPlatform(String pathName) { |
|
304 |
fontsForPrinting = pathName; |
|
305 |
} |
|
306 |
||
307 |
public static void registerJREFontsForPrinting() { |
|
548
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
308 |
final String pathName; |
2 | 309 |
synchronized (Win32GraphicsEnvironment.class) { |
310 |
GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
311 |
if (fontsForPrinting == null) { |
|
312 |
return; |
|
313 |
} |
|
314 |
pathName = fontsForPrinting; |
|
315 |
fontsForPrinting = null; |
|
316 |
} |
|
548
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
317 |
java.security.AccessController.doPrivileged( |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
318 |
new java.security.PrivilegedAction() { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
319 |
public Object run() { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
320 |
File f1 = new File(pathName); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
321 |
String[] ls = f1.list(new TTFilter()); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
322 |
if (ls == null) { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
323 |
return null; |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
324 |
} |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
325 |
for (int i=0; i <ls.length; i++ ) { |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
326 |
File fontFile = new File(f1, ls[i]); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
327 |
registerFontWithPlatform(fontFile.getAbsolutePath()); |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
328 |
} |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
329 |
return null; |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
330 |
} |
caed182cee6e
6664915: SecurityException using javax.print APIs when queuePrintJob permission is granted.
prr
parents:
2
diff
changeset
|
331 |
}); |
2 | 332 |
} |
333 |
||
334 |
protected static native void registerFontWithPlatform(String fontName); |
|
335 |
||
336 |
protected static native void deRegisterFontWithPlatform(String fontName); |
|
337 |
||
338 |
protected GraphicsDevice makeScreenDevice(int screennum) { |
|
887 | 339 |
GraphicsDevice device = null; |
340 |
if (WindowsFlags.isD3DEnabled()) { |
|
341 |
device = D3DGraphicsDevice.createDevice(screennum); |
|
342 |
} |
|
343 |
if (device == null) { |
|
344 |
device = new Win32GraphicsDevice(screennum); |
|
345 |
} |
|
346 |
return device; |
|
2 | 347 |
} |
348 |
||
349 |
// Implements SunGraphicsEnvironment.createFontConfiguration. |
|
350 |
protected FontConfiguration createFontConfiguration() { |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
351 |
FontConfiguration fc = new WFontConfiguration(this); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
352 |
fc.init(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
557
diff
changeset
|
353 |
return fc; |
2 | 354 |
} |
355 |
||
356 |
public FontConfiguration createFontConfiguration(boolean preferLocaleFonts, |
|
357 |
boolean preferPropFonts) { |
|
358 |
||
359 |
return new WFontConfiguration(this, preferLocaleFonts,preferPropFonts); |
|
360 |
} |
|
887 | 361 |
|
362 |
@Override |
|
363 |
public boolean isFlipStrategyPreferred(ComponentPeer peer) { |
|
364 |
GraphicsConfiguration gc; |
|
365 |
if (peer != null && (gc = peer.getGraphicsConfiguration()) != null) { |
|
366 |
GraphicsDevice gd = gc.getDevice(); |
|
367 |
if (gd instanceof D3DGraphicsDevice) { |
|
368 |
return ((D3DGraphicsDevice)gd).isD3DEnabledOnDevice(); |
|
369 |
} |
|
370 |
} |
|
371 |
return false; |
|
372 |
} |
|
373 |
||
374 |
private static volatile boolean isDWMCompositionEnabled; |
|
375 |
/** |
|
376 |
* Returns true if dwm composition is currently enabled, false otherwise. |
|
377 |
* |
|
378 |
* @return true if dwm composition is enabled, false otherwise |
|
379 |
*/ |
|
380 |
public static boolean isDWMCompositionEnabled() { |
|
381 |
return isDWMCompositionEnabled; |
|
382 |
} |
|
383 |
||
384 |
/** |
|
385 |
* Called from the native code when DWM composition state changed. |
|
386 |
* May be called multiple times during the lifetime of the application. |
|
387 |
* REMIND: we may want to create a listener mechanism for this. |
|
388 |
* |
|
389 |
* Note: called on the Toolkit thread, no user code or locks are allowed. |
|
390 |
* |
|
391 |
* @param enabled indicates the state of dwm composition |
|
392 |
*/ |
|
393 |
private static void dwmCompositionChanged(boolean enabled) { |
|
394 |
isDWMCompositionEnabled = enabled; |
|
395 |
} |
|
1724
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
396 |
|
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
397 |
@Override |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
398 |
public boolean isDisplayLocal() { |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
399 |
return true; |
a22a286aa16f
6748082: remove platform-specific code from SwingUtilities2.isDisplayLocal
tdv
parents:
889
diff
changeset
|
400 |
} |
2460 | 401 |
|
2451 | 402 |
/** |
403 |
* Used to find out if the OS is Windows Vista or later. |
|
404 |
* |
|
405 |
* @return {@code true} if the OS is Vista or later, {@code false} otherwise |
|
406 |
*/ |
|
407 |
public static native boolean isVistaOS(); |
|
2 | 408 |
} |