887
|
1 |
/*
|
|
2 |
* Copyright 2007-2008 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.d3d;
|
|
27 |
|
|
28 |
import java.awt.Color;
|
|
29 |
import java.awt.Component;
|
|
30 |
import java.awt.Container;
|
|
31 |
import java.awt.Font;
|
|
32 |
import java.awt.Graphics2D;
|
|
33 |
import java.awt.Rectangle;
|
|
34 |
import java.awt.Window;
|
|
35 |
import java.security.AccessController;
|
|
36 |
import java.security.PrivilegedAction;
|
|
37 |
import java.util.ArrayList;
|
|
38 |
import java.util.HashMap;
|
|
39 |
import sun.awt.SunToolkit;
|
|
40 |
import sun.awt.Win32GraphicsConfig;
|
|
41 |
import sun.awt.windows.WComponentPeer;
|
|
42 |
import sun.java2d.InvalidPipeException;
|
|
43 |
import sun.java2d.ScreenUpdateManager;
|
|
44 |
import sun.java2d.SunGraphics2D;
|
|
45 |
import sun.java2d.SurfaceData;
|
|
46 |
import sun.java2d.windows.GDIWindowSurfaceData;
|
|
47 |
import sun.java2d.d3d.D3DSurfaceData.D3DWindowSurfaceData;
|
|
48 |
import sun.java2d.windows.WindowsFlags;
|
|
49 |
|
|
50 |
/**
|
|
51 |
* This class handles rendering to the screen with the D3D pipeline.
|
|
52 |
*
|
|
53 |
* Since it is not possible to render directly to the front buffer
|
|
54 |
* with D3D9, we create a swap chain surface (with COPY effect) in place of the
|
|
55 |
* GDIWindowSurfaceData. A background thread handles the swap chain flips.
|
|
56 |
*
|
|
57 |
* There are some restrictions to which windows we would use this for.
|
|
58 |
* @see #createScreenSurface()
|
|
59 |
*/
|
|
60 |
public class D3DScreenUpdateManager extends ScreenUpdateManager
|
|
61 |
implements Runnable
|
|
62 |
{
|
|
63 |
/**
|
|
64 |
* A window must be at least MIN_WIN_SIZE in one or both dimensions
|
|
65 |
* to be considered for the update manager.
|
|
66 |
*/
|
|
67 |
private static final int MIN_WIN_SIZE = 150;
|
|
68 |
|
|
69 |
private volatile boolean done;
|
|
70 |
private volatile Thread screenUpdater;
|
|
71 |
private boolean needsUpdateNow;
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Object used by the screen updater thread for waiting
|
|
75 |
*/
|
|
76 |
private Object runLock = new Object();
|
|
77 |
/**
|
|
78 |
* List of D3DWindowSurfaceData surfaces. Surfaces are added to the
|
|
79 |
* list when a graphics object is created, and removed when the surface
|
|
80 |
* is invalidated.
|
|
81 |
*/
|
|
82 |
private ArrayList<D3DWindowSurfaceData> d3dwSurfaces;
|
|
83 |
/**
|
|
84 |
* Cache of GDIWindowSurfaceData surfaces corresponding to the
|
|
85 |
* D3DWindowSurfaceData surfaces. Surfaces are added to the list when
|
|
86 |
* a d3dw surface is lost and could not be restored (due to lack of vram,
|
|
87 |
* for example), and removed then the d3dw surface is invalidated.
|
|
88 |
*/
|
|
89 |
private HashMap<D3DWindowSurfaceData, GDIWindowSurfaceData> gdiSurfaces;
|
|
90 |
|
|
91 |
public D3DScreenUpdateManager() {
|
|
92 |
done = false;
|
|
93 |
AccessController.doPrivileged(
|
|
94 |
new PrivilegedAction() {
|
|
95 |
public Object run() {
|
|
96 |
ThreadGroup currentTG =
|
|
97 |
Thread.currentThread().getThreadGroup();
|
|
98 |
ThreadGroup parentTG = currentTG.getParent();
|
|
99 |
while (parentTG != null) {
|
|
100 |
currentTG = parentTG;
|
|
101 |
parentTG = currentTG.getParent();
|
|
102 |
}
|
|
103 |
try {
|
|
104 |
Runtime.getRuntime().addShutdownHook(
|
|
105 |
new Thread(currentTG,
|
|
106 |
new Runnable() {
|
|
107 |
public void run() {
|
|
108 |
done = true;
|
|
109 |
wakeUpUpdateThread();
|
|
110 |
}
|
|
111 |
}
|
|
112 |
)
|
|
113 |
);
|
|
114 |
} catch (Exception e) {
|
|
115 |
done = true;
|
|
116 |
}
|
|
117 |
return null;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
);
|
|
121 |
}
|
|
122 |
|
|
123 |
/**
|
|
124 |
* If possible, creates a D3DWindowSurfaceData (which is actually
|
|
125 |
* a back-buffer surface). If the creation fails, returns GDI
|
|
126 |
* onscreen surface instead.
|
|
127 |
*
|
|
128 |
* Note that the created D3D surface does not initialize the native
|
|
129 |
* resources (and is marked lost) to avoid wasting video memory. It is
|
|
130 |
* restored when a graphics object is requested from the peer.
|
|
131 |
*
|
|
132 |
* Note that this method is called from a synchronized block in
|
|
133 |
* WComponentPeer, so we don't need to synchronize
|
|
134 |
*
|
|
135 |
* Note that we only create a substibute d3dw surface if certain conditions
|
|
136 |
* are met
|
|
137 |
* <ul>
|
|
138 |
* <li>the fake d3d rendering on screen is not disabled via flag
|
|
139 |
* <li>d3d on the device is enabled
|
|
140 |
* <li>surface is larger than MIN_WIN_SIZE (don't bother for smaller ones)
|
|
141 |
* <li>it doesn't have a backBuffer for a BufferStrategy already
|
|
142 |
* <li>the peer is either Canvas, Panel, Window, Frame,
|
|
143 |
* Dialog or EmbeddedFrame
|
|
144 |
* </ul>
|
|
145 |
*
|
|
146 |
* @param gc GraphicsConfiguration on associated with the surface
|
|
147 |
* @param peer peer for which the surface is to be created
|
|
148 |
* @param bbNum number of back-buffers requested. if this number is >0,
|
|
149 |
* method returns GDI surface (we don't want to have two swap chains)
|
|
150 |
* @param isResize whether this surface is being created in response to
|
|
151 |
* a component resize event. This determines whether a repaint event will
|
|
152 |
* be issued after a surface is created: it will be if <code>isResize</code>
|
|
153 |
* is <code>true</code>.
|
|
154 |
* @return surface data to be use for onscreen rendering
|
|
155 |
*/
|
|
156 |
@Override
|
|
157 |
public SurfaceData createScreenSurface(Win32GraphicsConfig gc,
|
|
158 |
WComponentPeer peer,
|
|
159 |
int bbNum, boolean isResize)
|
|
160 |
{
|
|
161 |
if (done || !(gc instanceof D3DGraphicsConfig)) {
|
|
162 |
return super.createScreenSurface(gc, peer, bbNum, isResize);
|
|
163 |
}
|
|
164 |
|
|
165 |
SurfaceData sd = null;
|
|
166 |
|
|
167 |
if (canUseD3DOnScreen(peer, gc, bbNum)) {
|
|
168 |
try {
|
|
169 |
// note that the created surface will be in the "lost"
|
|
170 |
// state, it will be restored prior to rendering to it
|
|
171 |
// for the first time. This is done so that vram is not
|
|
172 |
// wasted for surfaces never rendered to
|
|
173 |
sd = D3DSurfaceData.createData(peer);
|
|
174 |
} catch (InvalidPipeException ipe) {
|
|
175 |
sd = null;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
if (sd == null) {
|
|
179 |
sd = GDIWindowSurfaceData.createData(peer);
|
|
180 |
// note that we do not add this surface to the list of cached gdi
|
|
181 |
// surfaces as there's no d3dw surface to associate it with;
|
|
182 |
// this peer will have a gdi surface until next time a surface
|
|
183 |
// will need to be replaced
|
|
184 |
}
|
|
185 |
|
|
186 |
if (isResize) {
|
|
187 |
// since we'd potentially replaced the back-buffer surface
|
|
188 |
// (either with another bb, or a gdi one), the
|
|
189 |
// component will need to be completely repainted;
|
|
190 |
// this only need to be done when the surface is created in
|
|
191 |
// response to a resize event since when a component is created it
|
|
192 |
// will be repainted anyway
|
|
193 |
repaintPeerTarget(peer);
|
|
194 |
}
|
|
195 |
|
|
196 |
return sd;
|
|
197 |
}
|
|
198 |
|
|
199 |
/**
|
|
200 |
* Determines if we can use a d3d surface for onscreen rendering for this
|
|
201 |
* peer.
|
|
202 |
* We only create onscreen d3d surfaces if the following conditions are met:
|
|
203 |
* - d3d is enabled on this device and onscreen emulation is enabled
|
|
204 |
* - window is big enough to bother (either dimension > MIN_WIN_SIZE)
|
|
205 |
* - this heavyweight doesn't have a BufferStrategy
|
|
206 |
* - if we are in full-screen mode then it must be the peer of the
|
|
207 |
* full-screen window (since there could be only one SwapChain in fs)
|
|
208 |
* and it must not have any heavyweight children
|
|
209 |
* (as Present() doesn't respect component clipping in fullscreen mode)
|
|
210 |
* - it's one of the classes likely to have custom rendering worth
|
|
211 |
* accelerating
|
|
212 |
*
|
|
213 |
* @returns true if we can use a d3d surface for this peer's onscreen
|
|
214 |
* rendering
|
|
215 |
*/
|
|
216 |
public static boolean canUseD3DOnScreen(final WComponentPeer peer,
|
|
217 |
final Win32GraphicsConfig gc,
|
|
218 |
final int bbNum)
|
|
219 |
{
|
|
220 |
if (!(gc instanceof D3DGraphicsConfig)) {
|
|
221 |
return false;
|
|
222 |
}
|
|
223 |
D3DGraphicsConfig d3dgc = (D3DGraphicsConfig)gc;
|
|
224 |
D3DGraphicsDevice d3dgd = d3dgc.getD3DDevice();
|
|
225 |
String peerName = peer.getClass().getName();
|
|
226 |
Rectangle r = peer.getBounds();
|
|
227 |
Component target = (Component)peer.getTarget();
|
|
228 |
Window fsw = d3dgd.getFullScreenWindow();
|
|
229 |
|
|
230 |
return
|
|
231 |
WindowsFlags.isD3DOnScreenEnabled() &&
|
|
232 |
d3dgd.isD3DEnabledOnDevice() &&
|
|
233 |
peer.isAccelCapable() &&
|
|
234 |
(r.width > MIN_WIN_SIZE || r.height > MIN_WIN_SIZE) &&
|
|
235 |
bbNum == 0 &&
|
|
236 |
(fsw == null || (fsw == target && !hasHWChildren(target))) &&
|
|
237 |
(peerName.equals("sun.awt.windows.WCanvasPeer") ||
|
|
238 |
peerName.equals("sun.awt.windows.WDialogPeer") ||
|
|
239 |
peerName.equals("sun.awt.windows.WPanelPeer") ||
|
|
240 |
peerName.equals("sun.awt.windows.WWindowPeer") ||
|
|
241 |
peerName.equals("sun.awt.windows.WFramePeer") ||
|
|
242 |
peerName.equals("sun.awt.windows.WEmbeddedFramePeer"));
|
|
243 |
}
|
|
244 |
|
|
245 |
/**
|
|
246 |
* Creates a graphics object for the passed in surface data. If
|
|
247 |
* the surface is lost, it is restored.
|
|
248 |
* If the surface wasn't lost or the restoration was successful
|
|
249 |
* the surface is added to the list of maintained surfaces
|
|
250 |
* (if it hasn't been already).
|
|
251 |
*
|
|
252 |
* If the updater thread hasn't been created yet , it will be created and
|
|
253 |
* started.
|
|
254 |
*
|
|
255 |
* @param sd surface data for which to create SunGraphics2D
|
|
256 |
* @param peer peer associated with the surface data
|
|
257 |
* @param fgColor fg color to be used in graphics
|
|
258 |
* @param bgColor bg color to be used in graphics
|
|
259 |
* @param font font to be used in graphics
|
|
260 |
* @return a SunGraphics2D object for the surface (or for temp GDI
|
|
261 |
* surface data)
|
|
262 |
*/
|
|
263 |
@Override
|
|
264 |
public Graphics2D createGraphics(SurfaceData sd,
|
|
265 |
WComponentPeer peer, Color fgColor, Color bgColor, Font font)
|
|
266 |
{
|
|
267 |
if (!done && sd instanceof D3DWindowSurfaceData) {
|
|
268 |
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
|
|
269 |
if (!d3dw.isSurfaceLost() || validate(d3dw)) {
|
|
270 |
trackScreenSurface(d3dw);
|
|
271 |
return new SunGraphics2D(sd, fgColor, bgColor, font);
|
|
272 |
}
|
|
273 |
// could not restore the d3dw surface, use the cached gdi surface
|
|
274 |
// instead for this graphics object; note that we do not track
|
|
275 |
// this new gdi surface, it is only used for this graphics
|
|
276 |
// object
|
|
277 |
sd = getGdiSurface(d3dw);
|
|
278 |
}
|
|
279 |
return super.createGraphics(sd, peer, fgColor, bgColor, font);
|
|
280 |
}
|
|
281 |
|
|
282 |
/**
|
|
283 |
* Posts a repaint event for the peer's target to the EDT
|
|
284 |
* @param peer for which target's the repaint should be issued
|
|
285 |
*/
|
|
286 |
private void repaintPeerTarget(WComponentPeer peer) {
|
|
287 |
// we don't want to call user code on our priveleged
|
|
288 |
// thread, delegate to EDT
|
|
289 |
final Component target = (Component)peer.getTarget();
|
|
290 |
SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
|
|
291 |
public void run() {
|
|
292 |
target.repaint();
|
|
293 |
}
|
|
294 |
});
|
|
295 |
}
|
|
296 |
|
|
297 |
/**
|
|
298 |
* Adds a surface to the list of tracked surfaces.
|
|
299 |
*
|
|
300 |
* @param d3dw the surface to be added
|
|
301 |
*/
|
|
302 |
private void trackScreenSurface(SurfaceData sd) {
|
|
303 |
if (!done && sd instanceof D3DWindowSurfaceData) {
|
|
304 |
synchronized (this) {
|
|
305 |
if (d3dwSurfaces == null) {
|
|
306 |
d3dwSurfaces = new ArrayList<D3DWindowSurfaceData>();
|
|
307 |
}
|
|
308 |
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
|
|
309 |
if (!d3dwSurfaces.contains(d3dw)) {
|
|
310 |
d3dwSurfaces.add(d3dw);
|
|
311 |
}
|
|
312 |
}
|
|
313 |
startUpdateThread();
|
|
314 |
}
|
|
315 |
}
|
|
316 |
|
|
317 |
@Override
|
|
318 |
public synchronized void dropScreenSurface(SurfaceData sd) {
|
|
319 |
if (d3dwSurfaces != null && sd instanceof D3DWindowSurfaceData) {
|
|
320 |
D3DWindowSurfaceData d3dw = (D3DWindowSurfaceData)sd;
|
|
321 |
removeGdiSurface(d3dw);
|
|
322 |
d3dwSurfaces.remove(d3dw);
|
|
323 |
}
|
|
324 |
}
|
|
325 |
|
|
326 |
@Override
|
|
327 |
public SurfaceData getReplacementScreenSurface(WComponentPeer peer,
|
|
328 |
SurfaceData sd)
|
|
329 |
{
|
|
330 |
SurfaceData newSurface = super.getReplacementScreenSurface(peer, sd);
|
|
331 |
// if some outstanding graphics context wants to get a replacement we
|
|
332 |
// need to make sure that the new surface (if it is accelerated) is
|
|
333 |
// being tracked
|
|
334 |
trackScreenSurface(newSurface);
|
|
335 |
return newSurface;
|
|
336 |
}
|
|
337 |
|
|
338 |
/**
|
|
339 |
* Remove the gdi surface corresponding to the passed d3dw surface
|
|
340 |
* from list of the cached gdi surfaces.
|
|
341 |
*
|
|
342 |
* @param d3dw surface for which associated gdi surface is to be removed
|
|
343 |
*/
|
|
344 |
private void removeGdiSurface(final D3DWindowSurfaceData d3dw) {
|
|
345 |
if (gdiSurfaces != null) {
|
|
346 |
GDIWindowSurfaceData gdisd = gdiSurfaces.get(d3dw);
|
|
347 |
if (gdisd != null) {
|
|
348 |
gdisd.invalidate();
|
|
349 |
gdiSurfaces.remove(d3dw);
|
|
350 |
}
|
|
351 |
}
|
|
352 |
}
|
|
353 |
|
|
354 |
/**
|
|
355 |
* If the update thread hasn't yet been created, it will be;
|
|
356 |
* otherwise it is awaken
|
|
357 |
*/
|
|
358 |
private synchronized void startUpdateThread() {
|
|
359 |
if (screenUpdater == null) {
|
|
360 |
screenUpdater = (Thread)java.security.AccessController.doPrivileged(
|
|
361 |
new java.security.PrivilegedAction() {
|
|
362 |
public Object run() {
|
|
363 |
ThreadGroup tg =
|
|
364 |
Thread.currentThread().getThreadGroup();
|
|
365 |
for (ThreadGroup tgn = tg;
|
|
366 |
tgn != null; tg = tgn, tgn = tg.getParent());
|
|
367 |
Thread t = new Thread(tg, D3DScreenUpdateManager.this,
|
|
368 |
"D3D Screen Updater");
|
|
369 |
// REMIND: should it be higher?
|
|
370 |
t.setPriority(Thread.NORM_PRIORITY + 2);
|
|
371 |
t.setDaemon(true);
|
|
372 |
return t;
|
|
373 |
}
|
|
374 |
});
|
|
375 |
screenUpdater.start();
|
|
376 |
} else {
|
|
377 |
wakeUpUpdateThread();
|
|
378 |
}
|
|
379 |
}
|
|
380 |
|
|
381 |
/**
|
|
382 |
* Wakes up the screen updater thread.
|
|
383 |
*
|
|
384 |
* This method is not synchronous, it doesn't wait
|
|
385 |
* for the updater thread to complete the updates.
|
|
386 |
*
|
|
387 |
* It should be used when it is not necessary to wait for the
|
|
388 |
* completion, for example, when a new surface had been added
|
|
389 |
* to the list of tracked surfaces (which means that it's about
|
|
390 |
* to be rendered to).
|
|
391 |
*/
|
|
392 |
public void wakeUpUpdateThread() {
|
|
393 |
synchronized (runLock) {
|
|
394 |
runLock.notifyAll();
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
/**
|
|
399 |
* Wakes up the screen updater thread and waits for the completion
|
|
400 |
* of the update.
|
|
401 |
*
|
|
402 |
* This method is called from Toolkit.sync() or
|
|
403 |
* when there was a copy from a VI to the screen
|
|
404 |
* so that swing applications would not appear to be
|
|
405 |
* sluggish.
|
|
406 |
*/
|
|
407 |
public void runUpdateNow() {
|
|
408 |
synchronized (this) {
|
|
409 |
// nothing to do if the updater thread hadn't been started or if
|
|
410 |
// there are no tracked surfaces
|
|
411 |
if (done || screenUpdater == null ||
|
|
412 |
d3dwSurfaces == null || d3dwSurfaces.size() == 0)
|
|
413 |
{
|
|
414 |
return;
|
|
415 |
}
|
|
416 |
}
|
|
417 |
synchronized (runLock) {
|
|
418 |
needsUpdateNow = true;
|
|
419 |
runLock.notifyAll();
|
|
420 |
while (needsUpdateNow) {
|
|
421 |
try {
|
|
422 |
runLock.wait();
|
|
423 |
} catch (InterruptedException e) {}
|
|
424 |
}
|
|
425 |
}
|
|
426 |
}
|
|
427 |
|
|
428 |
public void run() {
|
|
429 |
while (!done) {
|
|
430 |
synchronized (runLock) {
|
|
431 |
// If the list is empty, suspend the thread until a
|
|
432 |
// new surface is added. Note that we have to check before
|
|
433 |
// wait() (and inside the runLock), otherwise we could miss a
|
|
434 |
// notify() when a new surface is added and sleep forever.
|
|
435 |
long timeout = d3dwSurfaces.size() > 0 ? 100 : 0;
|
|
436 |
|
|
437 |
// don't go to sleep if there's a thread waiting for an update
|
|
438 |
if (!needsUpdateNow) {
|
|
439 |
try { runLock.wait(timeout); }
|
|
440 |
catch (InterruptedException e) {}
|
|
441 |
}
|
|
442 |
// if we were woken up, there are probably surfaces in the list,
|
|
443 |
// no need to check if the list is empty
|
|
444 |
}
|
|
445 |
|
|
446 |
// make a copy to avoid synchronization during the loop
|
|
447 |
D3DWindowSurfaceData surfaces[] = new D3DWindowSurfaceData[] {};
|
|
448 |
synchronized (this) {
|
|
449 |
surfaces = d3dwSurfaces.toArray(surfaces);
|
|
450 |
}
|
|
451 |
for (D3DWindowSurfaceData sd : surfaces) {
|
|
452 |
// skip invalid surfaces (they could have become invalid
|
|
453 |
// after we made a copy of the list) - just a precaution
|
|
454 |
if (sd.isValid() && (sd.isDirty() || sd.isSurfaceLost())) {
|
|
455 |
if (!sd.isSurfaceLost()) {
|
|
456 |
// the flip and the clearing of the dirty state
|
|
457 |
// must be done under the lock, otherwise it's
|
|
458 |
// possible to miss an update to the surface
|
|
459 |
D3DRenderQueue rq = D3DRenderQueue.getInstance();
|
|
460 |
rq.lock();
|
|
461 |
try {
|
|
462 |
Rectangle r = sd.getBounds();
|
|
463 |
D3DSurfaceData.swapBuffers(sd, 0, 0,
|
|
464 |
r.width, r.height);
|
|
465 |
sd.markClean();
|
|
466 |
} finally {
|
|
467 |
rq.unlock();
|
|
468 |
}
|
|
469 |
} else if (!validate(sd)) {
|
|
470 |
// it is possible that the validation may never
|
|
471 |
// succeed, we need to detect this and replace
|
|
472 |
// the d3dw surface with gdi; the replacement of
|
|
473 |
// the surface will also trigger a repaint
|
|
474 |
sd.getPeer().replaceSurfaceDataLater();
|
|
475 |
}
|
|
476 |
}
|
|
477 |
}
|
|
478 |
synchronized (runLock) {
|
|
479 |
needsUpdateNow = false;
|
|
480 |
runLock.notifyAll();
|
|
481 |
}
|
|
482 |
}
|
|
483 |
}
|
|
484 |
|
|
485 |
/**
|
|
486 |
* Restores the passed surface if it was lost, resets the lost status.
|
|
487 |
* @param sd surface to be validated
|
|
488 |
* @return true if surface wasn't lost or if restoration was successful,
|
|
489 |
* false otherwise
|
|
490 |
*/
|
|
491 |
private boolean validate(D3DWindowSurfaceData sd) {
|
|
492 |
if (sd.isSurfaceLost()) {
|
|
493 |
try {
|
|
494 |
sd.restoreSurface();
|
|
495 |
// if succeeded, first fill the surface with bg color
|
|
496 |
// note: use the non-synch method to avoid incorrect lock order
|
|
497 |
Color bg = sd.getPeer().getBackgroundNoSync();
|
|
498 |
SunGraphics2D sg2d = new SunGraphics2D(sd, bg, bg, null);
|
|
499 |
sg2d.fillRect(0, 0, sd.getBounds().width, sd.getBounds().height);
|
|
500 |
sg2d.dispose();
|
|
501 |
// now clean the dirty status so that we don't flip it
|
|
502 |
// next time before it gets repainted; it is safe
|
|
503 |
// to do without the lock because we will issue a
|
|
504 |
// repaint anyway so we will not lose any rendering
|
|
505 |
sd.markClean();
|
|
506 |
// since the surface was successfully restored we need to
|
|
507 |
// repaint whole window to repopulate the back-buffer
|
|
508 |
repaintPeerTarget(sd.getPeer());
|
|
509 |
} catch (InvalidPipeException ipe) {
|
|
510 |
return false;
|
|
511 |
}
|
|
512 |
}
|
|
513 |
return true;
|
|
514 |
}
|
|
515 |
|
|
516 |
/**
|
|
517 |
* Creates (or returns a cached one) gdi surface for the same peer as
|
|
518 |
* the passed d3dw surface has.
|
|
519 |
*
|
|
520 |
* @param d3dw surface used as key into the cache
|
|
521 |
* @return gdi window surface associated with the d3d window surfaces' peer
|
|
522 |
*/
|
|
523 |
private synchronized SurfaceData getGdiSurface(D3DWindowSurfaceData d3dw) {
|
|
524 |
if (gdiSurfaces == null) {
|
|
525 |
gdiSurfaces =
|
|
526 |
new HashMap<D3DWindowSurfaceData, GDIWindowSurfaceData>();
|
|
527 |
}
|
|
528 |
GDIWindowSurfaceData gdisd = gdiSurfaces.get(d3dw);
|
|
529 |
if (gdisd == null) {
|
|
530 |
gdisd = GDIWindowSurfaceData.createData(d3dw.getPeer());
|
|
531 |
gdiSurfaces.put(d3dw, gdisd);
|
|
532 |
}
|
|
533 |
return gdisd;
|
|
534 |
}
|
|
535 |
|
|
536 |
/**
|
|
537 |
* Returns true if the component has heavyweight children.
|
|
538 |
*
|
|
539 |
* @param comp component to check for hw children
|
|
540 |
* @return true if Component has heavyweight children
|
|
541 |
*/
|
|
542 |
private static boolean hasHWChildren(Component comp) {
|
|
543 |
if (comp instanceof Container) {
|
|
544 |
for (Component c : ((Container)comp).getComponents()) {
|
|
545 |
if (c.getPeer() instanceof WComponentPeer || hasHWChildren(c)) {
|
|
546 |
return true;
|
|
547 |
}
|
|
548 |
}
|
|
549 |
}
|
|
550 |
return false;
|
|
551 |
}
|
|
552 |
}
|