749 } finally {
750 rq.unlock();
751 }
752 }
753
754 static void swapBuffers(D3DSurfaceData sd,
755 final int x1, final int y1,
756 final int x2, final int y2)
757 {
758 long pData = sd.getNativeOps();
759 D3DRenderQueue rq = D3DRenderQueue.getInstance();
760 // swapBuffers can be called from the toolkit thread by swing, we
761 // should detect this and prevent the deadlocks
762 if (D3DRenderQueue.isRenderQueueThread()) {
763 if (!rq.tryLock()) {
764 // if we could not obtain the lock, repaint the area
765 // that was supposed to be swapped, and no-op this swap
766 final Component target = (Component)sd.getPeer().getTarget();
767 SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
768 public void run() {
769 target.repaint(x1, y1, x2, y2);
770 }
771 });
772 return;
773 }
774 } else {
775 rq.lock();
776 }
777 try {
778 RenderBuffer buf = rq.getBuffer();
779 rq.ensureCapacityAndAlignment(28, 4);
780 buf.putInt(SWAP_BUFFERS);
781 buf.putLong(pData);
782 buf.putInt(x1);
783 buf.putInt(y1);
784 buf.putInt(x2);
785 buf.putInt(y2);
786 rq.flushNow();
787 } finally {
788 rq.unlock();
789 }
|
749 } finally {
750 rq.unlock();
751 }
752 }
753
754 static void swapBuffers(D3DSurfaceData sd,
755 final int x1, final int y1,
756 final int x2, final int y2)
757 {
758 long pData = sd.getNativeOps();
759 D3DRenderQueue rq = D3DRenderQueue.getInstance();
760 // swapBuffers can be called from the toolkit thread by swing, we
761 // should detect this and prevent the deadlocks
762 if (D3DRenderQueue.isRenderQueueThread()) {
763 if (!rq.tryLock()) {
764 // if we could not obtain the lock, repaint the area
765 // that was supposed to be swapped, and no-op this swap
766 final Component target = (Component)sd.getPeer().getTarget();
767 SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
768 public void run() {
769 double scaleX = sd.getDefaultScaleX();
770 double scaleY = sd.getDefaultScaleY();
771 if (scaleX > 1 || scaleY > 1) {
772 int sx1 = (int) Math.floor(x1 / scaleX);
773 int sy1 = (int) Math.floor(y1 / scaleY);
774 int sx2 = (int) Math.ceil(x2 / scaleX);
775 int sy2 = (int) Math.ceil(y2 / scaleY);
776 target.repaint(sx1, sy1, sx2 - sx1, sy2 - sy1);
777 } else {
778 target.repaint(x1, y1, x2 - x1, y2 - y1);
779 }
780 }
781 });
782 return;
783 }
784 } else {
785 rq.lock();
786 }
787 try {
788 RenderBuffer buf = rq.getBuffer();
789 rq.ensureCapacityAndAlignment(28, 4);
790 buf.putInt(SWAP_BUFFERS);
791 buf.putLong(pData);
792 buf.putInt(x1);
793 buf.putInt(y1);
794 buf.putInt(x2);
795 buf.putInt(y2);
796 rq.flushNow();
797 } finally {
798 rq.unlock();
799 }
|