7141393: [macosx] CARemoteLayer code refactoring and unit test
authorserb
Wed, 08 May 2019 14:34:21 -0700
changeset 54873 442e683e65fa
parent 54872 fa917627b17b
child 54874 631c31a5bf40
7141393: [macosx] CARemoteLayer code refactoring and unit test Reviewed-by: dmarkov, jdv
src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m
src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.h
src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m
src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h
src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m
src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Wed May 08 11:59:18 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m	Wed May 08 14:34:21 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -99,27 +99,6 @@
         //[self setLayerContentsRedrawPolicy: NSViewLayerContentsRedrawDuringViewResize];
         //[self setLayerContentsPlacement: NSViewLayerContentsPlacementTopLeft];
         //[self setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
-
-#ifdef REMOTELAYER
-        CGLLayer *parentLayer = (CGLLayer*)self.cglLayer;
-        parentLayer.parentLayer = NULL;
-        parentLayer.remoteLayer = NULL;
-        if (JRSRemotePort != 0 && remoteSocketFD > 0) {
-            CGLLayer *remoteLayer = [[CGLLayer alloc] initWithJavaLayer: parentLayer.javaLayer];
-            remoteLayer.target = GL_TEXTURE_2D;
-            NSLog(@"Creating Parent=%p, Remote=%p", parentLayer, remoteLayer);
-            parentLayer.remoteLayer = remoteLayer;
-            remoteLayer.parentLayer = parentLayer;
-            remoteLayer.remoteLayer = NULL;
-            remoteLayer.jrsRemoteLayer = [remoteLayer createRemoteLayerBoundTo:JRSRemotePort];
-            [remoteLayer retain];  // REMIND
-            remoteLayer.frame = CGRectMake(0, 0, 720, 500); // REMIND
-            [remoteLayer.jrsRemoteLayer retain]; // REMIND
-            int layerID = [remoteLayer.jrsRemoteLayer layerID];
-            NSLog(@"layer id to send = %d", layerID);
-            sendLayerID(layerID);
-        }
-#endif /* REMOTELAYER */
     }
 
     return self;
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.h	Wed May 08 11:59:18 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.h	Wed May 08 14:34:21 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -48,30 +48,6 @@
 /* Do we need this if we are using all off-screen drawing ? */
 #define USE_NSVIEW_FOR_SCRATCH 1
 
-/* Uncomment to have an additional CAOGLLayer instance tied to
- * each instance, which can be used to test remoting the layer
- * to an out of process window. The additional layer is needed
- * because a layer can only be attached to one context (view/window).
- * This is only for testing purposes and can be removed if/when no
- * longer needed.
- */
-//#define REMOTELAYER 1
-
-#ifdef REMOTELAYER
-#import <JavaRuntimeSupport/JRSRemoteLayer.h>
-#import <pthread.h>
-#include <unistd.h>
-#include <stdio.h>
-#import <sys/socket.h>
-#import <sys/un.h>
-
-extern mach_port_t JRSRemotePort;
-extern int remoteSocketFD;
-extern void sendLayerID(int layerID);
-
-#endif /* REMOTELAYER */
-
-
 /**
  * The CGLGraphicsConfigInfo structure contains information specific to a
  * given CGLGraphicsConfig (pixel format).
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m	Wed May 08 11:59:18 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m	Wed May 08 14:34:21 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -80,67 +80,6 @@
 #pragma mark -
 #pragma mark "--- CGLGraphicsConfig methods ---"
 
-#ifdef REMOTELAYER
-mach_port_t JRSRemotePort;
-int remoteSocketFD = -1;
-
-static void *JRSRemoteThreadFn(void *data) {
-    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
-    // Negotiate a unix domain socket to communicate the
-    // out of band data: to read the mach port server name, and
-    // subsequently write out the layer ID.
-    static char* sock_path = "/tmp/JRSRemoteDemoSocket";
-    struct sockaddr_un address;
-    int  socket_fd, nbytes;
-    int BUFLEN = 256;
-    char buffer[BUFLEN];
-
-    remoteSocketFD = socket(PF_LOCAL, SOCK_STREAM, 0);
-    if (remoteSocketFD < 0) {
-        NSLog(@"socket() failed");
-        return NULL;
-    }
-    memset(&address, 0, sizeof(struct sockaddr_un));
-    address.sun_family = AF_UNIX;
-    memcpy(address.sun_path, sock_path, strlen(sock_path)+1);
-    int tries=0, status=-1;
-    while (status !=0 && tries<600) {
-        status = connect(remoteSocketFD, (struct sockaddr *) &address,
-                         sizeof(struct sockaddr_un));
-        if (status != 0) {
-            tries++;
-            NSLog(@"connection attempt %d failed.", tries);
-            usleep(5000000);
-        }
-    }
-    if (status != 0) {
-        NSLog(@"failed to connect");
-        return NULL;
-    }
-    nbytes = read(remoteSocketFD, buffer, BUFLEN);
-    NSString* serverString = [[NSString alloc] initWithUTF8String:buffer];
-    CFRetain(serverString);
-    NSLog(@"Read server name %@", serverString);
-    JRSRemotePort = [JRSRenderServer recieveRenderServer:serverString];
-    NSLog(@"Read server port %d", JRSRemotePort);
-
-    [pool drain];
-    return NULL;
-}
-
-void sendLayerID(int layerID) {
-    if (JRSRemotePort == 0 || remoteSocketFD < 0) {
-        NSLog(@"No connection to send ID");
-        return;
-    }
-    int BUFLEN = 256;
-    char buffer[BUFLEN];
-    snprintf(buffer, BUFLEN, "%d", layerID);
-    write(remoteSocketFD, buffer, BUFLEN);
-}
-#endif  /* REMOTELAYER */
-
 /**
  * This is a globally shared context used when creating textures.  When any
  * new contexts are created, they specify this context as the "share list"
@@ -170,10 +109,6 @@
         OGLFuncs_CloseLibrary();
         return JNI_FALSE;
     }
-#ifdef REMOTELAYER
-    pthread_t jrsRemoteThread;
-    pthread_create(&jrsRemoteThread, NULL, JRSRemoteThreadFn, NULL);
-#endif
     return JNI_TRUE;
 }
 
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h	Wed May 08 11:59:18 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.h	Wed May 08 14:34:21 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,11 +38,6 @@
     GLenum target;
     float textureWidth;
     float textureHeight;
-#ifdef REMOTELAYER
-    CGLLayer *parentLayer;
-    CGLLayer *remoteLayer;
-    NSObject<JRSRemoteLayer> *jrsRemoteLayer;
-#endif /* REMOTELAYER */
 }
 
 @property (nonatomic, retain) JNFWeakJObjectWrapper *javaLayer;
@@ -51,12 +46,6 @@
 @property (readwrite, assign) float textureWidth;
 @property (readwrite, assign) float textureHeight;
 
-#ifdef REMOTELAYER
-@property (nonatomic, retain) CGLLayer *parentLayer;
-@property (nonatomic, retain) CGLLayer *remoteLayer;
-@property (nonatomic, retain) NSObject<JRSRemoteLayer> *jrsRemoteLayer;
-#endif
-
 - (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)javaLayer;
 - (void) blitTexture;
 @end
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m	Wed May 08 11:59:18 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLLayer.m	Wed May 08 14:34:21 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -40,11 +40,6 @@
 @synthesize target;
 @synthesize textureWidth;
 @synthesize textureHeight;
-#ifdef REMOTELAYER
-@synthesize parentLayer;
-@synthesize remoteLayer;
-@synthesize jrsRemoteLayer;
-#endif
 
 - (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer;
 {
@@ -179,10 +174,10 @@
 
     [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
             AWT_ASSERT_APPKIT_THREAD;
-        
+
             layer = [[CGLLayer alloc] initWithJavaLayer: javaLayer];
     }];
-    
+
 JNF_COCOA_EXIT(env);
 
     return ptr_to_jlong(layer);
@@ -222,9 +217,9 @@
 {
     JNF_COCOA_ENTER(env);
     CGLLayer *layer = jlong_to_ptr(layerPtr);
-    // We always call all setXX methods asynchronously, exception is only in 
+    // We always call all setXX methods asynchronously, exception is only in
     // this method where we need to change native texture size and layer's scale
-    // in one call on appkit, otherwise we'll get window's contents blinking, 
+    // in one call on appkit, otherwise we'll get window's contents blinking,
     // during screen-2-screen moving.
     [ThreadUtilities performOnMainThreadWaiting:[NSThread isMainThread] block:^(){
         layer.contentsScale = scale;
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m	Wed May 08 11:59:18 2019 +0530
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLSurfaceData.m	Wed May 08 14:34:21 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -344,23 +344,6 @@
             [JNFRunLoop performOnMainThreadWaiting:NO withBlock:^(){
                 AWT_ASSERT_APPKIT_THREAD;
                 [layer setNeedsDisplay];
-
-#ifdef REMOTELAYER
-                /* If there's a remote layer (being used for testing)
-                 * then we want to have that also receive the texture.
-                 * First sync. up its dimensions with that of the layer
-                 * we have attached to the local window and tell it that
-                 * it also needs to copy the texture.
-                 */
-                if (layer.remoteLayer != nil) {
-                    CGLLayer* remoteLayer = layer.remoteLayer;
-                    remoteLayer.target = GL_TEXTURE_2D;
-                    remoteLayer.textureID = layer.textureID;
-                    remoteLayer.textureWidth = layer.textureWidth;
-                    remoteLayer.textureHeight = layer.textureHeight;
-                    [remoteLayer setNeedsDisplay];
-                }
-#endif /* REMOTELAYER */
             }];
         }
     }