1 /*
2 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
411
412 public void run() {
413 while (!done) {
414 synchronized (runLock) {
415 // If the list is empty, suspend the thread until a
416 // new surface is added. Note that we have to check before
417 // wait() (and inside the runLock), otherwise we could miss a
418 // notify() when a new surface is added and sleep forever.
419 long timeout = d3dwSurfaces.size() > 0 ? 100 : 0;
420
421 // don't go to sleep if there's a thread waiting for an update
422 if (!needsUpdateNow) {
423 try { runLock.wait(timeout); }
424 catch (InterruptedException e) {}
425 }
426 // if we were woken up, there are probably surfaces in the list,
427 // no need to check if the list is empty
428 }
429
430 // make a copy to avoid synchronization during the loop
431 D3DWindowSurfaceData surfaces[] = new D3DWindowSurfaceData[] {};
432 synchronized (this) {
433 surfaces = d3dwSurfaces.toArray(surfaces);
434 }
435 for (D3DWindowSurfaceData sd : surfaces) {
436 // skip invalid surfaces (they could have become invalid
437 // after we made a copy of the list) - just a precaution
438 if (sd.isValid() && (sd.isDirty() || sd.isSurfaceLost())) {
439 if (!sd.isSurfaceLost()) {
440 // the flip and the clearing of the dirty state
441 // must be done under the lock, otherwise it's
442 // possible to miss an update to the surface
443 D3DRenderQueue rq = D3DRenderQueue.getInstance();
444 rq.lock();
445 try {
446 Rectangle r = sd.getBounds();
447 D3DSurfaceData.swapBuffers(sd, 0, 0,
448 r.width, r.height);
449 sd.markClean();
450 } finally {
451 rq.unlock();
|
1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
411
412 public void run() {
413 while (!done) {
414 synchronized (runLock) {
415 // If the list is empty, suspend the thread until a
416 // new surface is added. Note that we have to check before
417 // wait() (and inside the runLock), otherwise we could miss a
418 // notify() when a new surface is added and sleep forever.
419 long timeout = d3dwSurfaces.size() > 0 ? 100 : 0;
420
421 // don't go to sleep if there's a thread waiting for an update
422 if (!needsUpdateNow) {
423 try { runLock.wait(timeout); }
424 catch (InterruptedException e) {}
425 }
426 // if we were woken up, there are probably surfaces in the list,
427 // no need to check if the list is empty
428 }
429
430 // make a copy to avoid synchronization during the loop
431 D3DWindowSurfaceData[] surfaces = new D3DWindowSurfaceData[] {};
432 synchronized (this) {
433 surfaces = d3dwSurfaces.toArray(surfaces);
434 }
435 for (D3DWindowSurfaceData sd : surfaces) {
436 // skip invalid surfaces (they could have become invalid
437 // after we made a copy of the list) - just a precaution
438 if (sd.isValid() && (sd.isDirty() || sd.isSurfaceLost())) {
439 if (!sd.isSurfaceLost()) {
440 // the flip and the clearing of the dirty state
441 // must be done under the lock, otherwise it's
442 // possible to miss an update to the surface
443 D3DRenderQueue rq = D3DRenderQueue.getInstance();
444 rq.lock();
445 try {
446 Rectangle r = sd.getBounds();
447 D3DSurfaceData.swapBuffers(sd, 0, 0,
448 r.width, r.height);
449 sd.markClean();
450 } finally {
451 rq.unlock();
|