7172187: [macosx] JAWT native CALayer not positioned over Canvas
authorserb
Wed, 15 Aug 2012 15:02:34 +0400
changeset 13544 bd136eb2a932
parent 13543 3b09d120a91c
child 13545 e8d21339d624
7172187: [macosx] JAWT native CALayer not positioned over Canvas Reviewed-by: art, anthony
jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java
jdk/src/macosx/classes/sun/lwawt/PlatformComponent.java
jdk/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java
jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java
jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.m
--- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Wed Aug 15 14:33:44 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Wed Aug 15 15:02:34 2012 +0400
@@ -282,7 +282,7 @@
      * Note that we call setVisible() at the end of initialization.
      */
     public final void initialize() {
-        platformComponent.initialize(target, this, getPlatformWindow());
+        platformComponent.initialize(getPlatformWindow());
         initializeImpl();
         setVisible(target.isVisible());
     }
--- a/jdk/src/macosx/classes/sun/lwawt/PlatformComponent.java	Wed Aug 15 14:33:44 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/PlatformComponent.java	Wed Aug 15 15:02:34 2012 +0400
@@ -23,15 +23,38 @@
  * questions.
  */
 
+
 package sun.lwawt;
 
-import java.awt.Component;
-
+/**
+ * Can be used to store information about native resource related to the
+ * lightweight component.
+ */
 public interface PlatformComponent {
 
-    public void initialize(Component target, LWComponentPeer peer, PlatformWindow platformWindow);
+    /**
+     * Initializes platform component.
+     *
+     * @param platformWindow already initialized {@code PlatformWindow}.
+     */
+    void initialize(PlatformWindow platformWindow);
 
-    public void setBounds(int x, int y, int w, int h);
+    /**
+     * Moves and resizes this component. The new location of the top-left corner
+     * is specified by {@code x} and {@code y}, and the new size is specified by
+     * {@code w} and {@code h}. The location is specified relative to the {@code
+     * platformWindow}.
+     *
+     * @param x the X location of the component
+     * @param y the Y location of the component
+     * @param w the width of the component
+     * @param h the height of the component
+     */
+    void setBounds(int x, int y, int w, int h);
 
-    public void dispose();
+    /**
+     * Releases all of the native resources used by this {@code
+     * PlatformComponent}.
+     */
+    void dispose();
 }
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java	Wed Aug 15 14:33:44 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CFRetainedResource.java	Wed Aug 15 15:02:34 2012 +0400
@@ -33,8 +33,8 @@
 public class CFRetainedResource {
     private static native void nativeCFRelease(final long ptr, final boolean disposeOnAppKitThread);
 
-    final boolean disposeOnAppKitThread;
-    protected long ptr;
+    private final boolean disposeOnAppKitThread;
+    protected volatile long ptr;
 
     /**
      * @param ptr CFRetained native object pointer
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java	Wed Aug 15 14:33:44 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformComponent.java	Wed Aug 15 15:02:34 2012 +0400
@@ -23,27 +23,24 @@
  * questions.
  */
 
+
 package sun.lwawt.macosx;
 
-import java.awt.Component;
 import java.awt.Insets;
 
 import sun.lwawt.PlatformComponent;
 import sun.lwawt.PlatformWindow;
-import sun.lwawt.LWComponentPeer;
-
-import sun.lwawt.macosx.CFRetainedResource;
-
-public class CPlatformComponent extends CFRetainedResource implements PlatformComponent {
 
-    Component target;
-    LWComponentPeer peer;
-    PlatformWindow platformWindow;
+/**
+ * On OSX {@code CPlatformComponent} stores pointer to the native CAlayer which
+ * can be used from JAWT.
+ */
+final class CPlatformComponent extends CFRetainedResource
+        implements PlatformComponent {
 
-    private native long nativeCreateComponent(long windowLayer);
-    private native long nativeSetBounds(long ptr, int x, int y, int width, int height);
+    private volatile PlatformWindow platformWindow;
 
-    public CPlatformComponent() {
+    CPlatformComponent() {
         super(0, true);
     }
 
@@ -51,27 +48,28 @@
         return ptr;
     }
 
-    public void initialize(Component target, LWComponentPeer peer, PlatformWindow platformWindow) {
-        this.target = target;
-        this.peer = peer;
+    @Override
+    public void initialize(final PlatformWindow platformWindow) {
         this.platformWindow = platformWindow;
-
-        long windowLayerPtr = platformWindow.getLayerPtr();
-        setPtr(nativeCreateComponent(windowLayerPtr));
+        setPtr(nativeCreateComponent(platformWindow.getLayerPtr()));
     }
 
     // TODO: visibility, z-order
 
     @Override
-    public void setBounds(int x, int y, int width, int height) {
+    public void setBounds(final int x, final int y, final int w, final int h) {
         // translates values from the coordinate system of the top-level window
         // to the coordinate system of the content view
-        Insets insets = platformWindow.getPeer().getInsets();
-        nativeSetBounds(getPointer(), x - insets.left, y - insets.top, width, height);
+        final Insets insets = platformWindow.getPeer().getInsets();
+        nativeSetBounds(getPointer(), x - insets.left, y - insets.top, w, h);
     }
 
     @Override
     public void dispose() {
         super.dispose();
     }
+
+    private native long nativeCreateComponent(long windowLayer);
+
+    private native void nativeSetBounds(long ptr, int x, int y, int w, int h);
 }
--- a/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.m	Wed Aug 15 14:33:44 2012 +0400
+++ b/jdk/src/macosx/native/sun/awt/AWTSurfaceLayers.m	Wed Aug 15 15:02:34 2012 +0400
@@ -78,11 +78,10 @@
 
     // translates values to the coordinate system of the "root" layer
     CGFloat newY = windowLayer.bounds.size.height - rect.origin.y - rect.size.height;
+    CGRect newRect = CGRectMake(rect.origin.x, newY, rect.size.width, rect.size.height);
 
-    // REMIND: why do we need to inverse position?
-    CGRect newRect = CGRectMake(-rect.origin.x, -newY, rect.size.width, rect.size.height);
+    layer.frame = newRect;
 
-    layer.bounds = newRect;
     [AWTSurfaceLayers repaintLayersRecursively:layer];
 }