7141393: [macosx] CARemoteLayer code refactoring and unit test
Reviewed-by: dmarkov, jdv
This commit is contained in:
parent
f123015ce0
commit
a9f9b8ff41
@ -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 @@ static BOOL shouldUsePressAndHold() {
|
||||
//[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;
|
||||
|
@ -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).
|
||||
|
@ -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 @@ OGLGC_DestroyOGLGraphicsConfig(jlong pConfigInfo)
|
||||
#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 @@ Java_sun_java2d_opengl_CGLGraphicsConfig_initCGL
|
||||
OGLFuncs_CloseLibrary();
|
||||
return JNI_FALSE;
|
||||
}
|
||||
#ifdef REMOTELAYER
|
||||
pthread_t jrsRemoteThread;
|
||||
pthread_create(&jrsRemoteThread, NULL, JRSRemoteThreadFn, NULL);
|
||||
#endif
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 @@ extern NSOpenGLContext *sharedContext;
|
||||
@synthesize target;
|
||||
@synthesize textureWidth;
|
||||
@synthesize textureHeight;
|
||||
#ifdef REMOTELAYER
|
||||
@synthesize parentLayer;
|
||||
@synthesize remoteLayer;
|
||||
@synthesize jrsRemoteLayer;
|
||||
#endif
|
||||
|
||||
- (id) initWithJavaLayer:(JNFWeakJObjectWrapper *)layer;
|
||||
{
|
||||
@ -179,10 +174,10 @@ JNF_COCOA_ENTER(env);
|
||||
|
||||
[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 @@ Java_sun_java2d_opengl_CGLLayer_nativeSetScale
|
||||
{
|
||||
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;
|
||||
|
@ -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 @@ OGLSD_Flush(JNIEnv *env)
|
||||
[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 */
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user