changeset 4682:4a8cbf11c3b4

7124994: [macosx] GUI app is stuck in i18n testing (caused by reference cast) Reviewed-by: alexp
author serb
date Wed, 25 Jan 2012 20:28:16 +0400
parents 28fb85f284a4
children ea8458a4ada3
files src/macosx/classes/sun/lwawt/LWComponentPeer.java src/macosx/classes/sun/lwawt/LWWindowPeer.java
diffstat 2 files changed, 72 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Wed Jan 25 20:00:58 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Wed Jan 25 20:28:16 2012 +0400
@@ -124,6 +124,7 @@
     private D delegate = null;
     private Container delegateContainer;
     private Component delegateDropTarget;
+    private final Object dropTargetLock = new Object();
 
     private int fNumDropTargets = 0;
     private CDropTarget fDropTarget = null;
@@ -445,7 +446,7 @@
     }
 
     @Override
-    public final synchronized Graphics getGraphics() {
+    public final Graphics getGraphics() {
         Graphics g = getWindowPeerOrSelf().isOpaque() ? getOnscreenGraphics()
                                                       : getOffscreenGraphics();
         if (g != null) {
@@ -990,31 +991,37 @@
     }
 
     // DropTargetPeer Method
-    public synchronized void addDropTarget(DropTarget dt) {
-        // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
-        // if it's the first (or last) one for the component. Otherwise this call is a no-op.
-        if (++fNumDropTargets == 1) {
-            // Having a non-null drop target would be an error but let's check just in case:
-            if (fDropTarget != null)
-                System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
+    @Override
+    public void addDropTarget(DropTarget dt) {
+        synchronized (dropTargetLock){
+            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
+            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
+            if (++fNumDropTargets == 1) {
+                // Having a non-null drop target would be an error but let's check just in case:
+                if (fDropTarget != null)
+                    System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
 
-            // Create a new drop target:
-            fDropTarget = CDropTarget.createDropTarget(dt, target, this);
+                // Create a new drop target:
+                fDropTarget = CDropTarget.createDropTarget(dt, target, this);
+            }
         }
     }
 
     // DropTargetPeer Method
-    public synchronized void removeDropTarget(DropTarget dt) {
-        // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
-        // if it's the first (or last) one for the component. Otherwise this call is a no-op.
-        if (--fNumDropTargets == 0) {
-            // Having a null drop target would be an error but let's check just in case:
-            if (fDropTarget != null) {
-                // Dispose of the drop target:
-                fDropTarget.dispose();
-                fDropTarget = null;
-            } else
-                System.err.println("CComponent.removeDropTarget(): current drop target is null.");
+    @Override
+    public void removeDropTarget(DropTarget dt) {
+        synchronized (dropTargetLock){
+            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
+            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
+            if (--fNumDropTargets == 0) {
+                // Having a null drop target would be an error but let's check just in case:
+                if (fDropTarget != null) {
+                    // Dispose of the drop target:
+                    fDropTarget.dispose();
+                    fDropTarget = null;
+                } else
+                    System.err.println("CComponent.removeDropTarget(): current drop target is null.");
+            }
         }
     }
 
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed Jan 25 20:00:58 2012 +0400
+++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Wed Jan 25 20:28:16 2012 +0400
@@ -69,6 +69,7 @@
     private GraphicsConfiguration graphicsConfig;
 
     private SurfaceData surfaceData;
+    private final Object surfaceDataLock = new Object();
 
     private int backBufferCount;
     private BufferCapabilities backBufferCaps;
@@ -241,7 +242,9 @@
     @Override
     protected void disposeImpl() {
         SurfaceData oldData = getSurfaceData();
-        surfaceData = null;
+        synchronized (surfaceDataLock){
+            surfaceData = null;
+        }
         if (oldData != null) {
             oldData.invalidate();
         }
@@ -295,7 +298,7 @@
         return false;
     }
 
-    protected final synchronized Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
+    protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
         if (getSurfaceData() == null) {
             return null;
         }
@@ -968,53 +971,55 @@
     /*
      * May be called by delegate to provide SD to Java2D code.
      */
-    public synchronized SurfaceData getSurfaceData() {
-        //TODO: synchronize access to the surfaceData.
-        return surfaceData;
+    public SurfaceData getSurfaceData() {
+        synchronized (surfaceDataLock) {
+            return surfaceData;
+        }
     }
 
     private void replaceSurfaceData() {
         replaceSurfaceData(backBufferCount, backBufferCaps);
     }
 
-    private synchronized void replaceSurfaceData(int newBackBufferCount,
+    private void replaceSurfaceData(int newBackBufferCount,
                                                  BufferCapabilities newBackBufferCaps) {
-        // TODO: need some kind of synchronization here?
-        final SurfaceData oldData = getSurfaceData();
-        surfaceData = platformWindow.replaceSurfaceData();
-        // TODO: volatile image
-//        VolatileImage oldBB = backBuffer;
-        BufferedImage oldBB = backBuffer;
-        backBufferCount = newBackBufferCount;
-        backBufferCaps = newBackBufferCaps;
-        final Rectangle size = getSize();
-        if (getSurfaceData() != null && oldData != getSurfaceData()) {
-            clearBackground(size.width, size.height);
-        }
-        blitSurfaceData(oldData, getSurfaceData());
+        synchronized (surfaceDataLock) {
+            final SurfaceData oldData = getSurfaceData();
+            surfaceData = platformWindow.replaceSurfaceData();
+            // TODO: volatile image
+    //        VolatileImage oldBB = backBuffer;
+            BufferedImage oldBB = backBuffer;
+            backBufferCount = newBackBufferCount;
+            backBufferCaps = newBackBufferCaps;
+            final Rectangle size = getSize();
+            if (getSurfaceData() != null && oldData != getSurfaceData()) {
+                clearBackground(size.width, size.height);
+            }
+            blitSurfaceData(oldData, getSurfaceData());
 
-        if (oldData != null && oldData != getSurfaceData()) {
-            // TODO: drop oldData for D3D/WGL pipelines
-            // This can only happen when this peer is being created
-            oldData.flush();
-        }
+            if (oldData != null && oldData != getSurfaceData()) {
+                // TODO: drop oldData for D3D/WGL pipelines
+                // This can only happen when this peer is being created
+                oldData.flush();
+            }
 
-        // TODO: volatile image
-//        backBuffer = (VolatileImage)delegate.createBackBuffer();
-        backBuffer = (BufferedImage) platformWindow.createBackBuffer();
-        if (backBuffer != null) {
-            Graphics g = backBuffer.getGraphics();
-            try {
-                Rectangle r = getBounds();
-                g.setColor(getBackground());
-                g.fillRect(0, 0, r.width, r.height);
-                if (oldBB != null) {
-                    // Draw the old back buffer to the new one
-                    g.drawImage(oldBB, 0, 0, null);
-                    oldBB.flush();
+            // TODO: volatile image
+    //        backBuffer = (VolatileImage)delegate.createBackBuffer();
+            backBuffer = (BufferedImage) platformWindow.createBackBuffer();
+            if (backBuffer != null) {
+                Graphics g = backBuffer.getGraphics();
+                try {
+                    Rectangle r = getBounds();
+                    g.setColor(getBackground());
+                    g.fillRect(0, 0, r.width, r.height);
+                    if (oldBB != null) {
+                        // Draw the old back buffer to the new one
+                        g.drawImage(oldBB, 0, 0, null);
+                        oldBB.flush();
+                    }
+                } finally {
+                    g.dispose();
                 }
-            } finally {
-                g.dispose();
             }
         }
     }