8263363: Minor cleanup of Lanai code - unused code removal and comments correction
Reviewed-by: serb
This commit is contained in:
parent
7e30130e35
commit
8fa50ebdf2
@ -78,7 +78,7 @@ public abstract class CGraphicsConfig extends GraphicsConfiguration
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new SurfaceData that will be associated with the given
|
* Creates a new SurfaceData that will be associated with the given
|
||||||
* CGLLayer.
|
* layer (CGLLayer/MTLLayer).
|
||||||
*/
|
*/
|
||||||
public abstract SurfaceData createSurfaceData(CFRetainedResource layer);
|
public abstract SurfaceData createSurfaceData(CFRetainedResource layer);
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ import sun.java2d.pipe.hw.ContextCapabilities;
|
|||||||
|
|
||||||
import java.lang.annotation.Native;
|
import java.lang.annotation.Native;
|
||||||
|
|
||||||
import static sun.java2d.pipe.BufferedOpCodes.INVALIDATE_CONTEXT;
|
|
||||||
import static sun.java2d.pipe.BufferedOpCodes.SET_SCRATCH_SURFACE;
|
import static sun.java2d.pipe.BufferedOpCodes.SET_SCRATCH_SURFACE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,32 +78,6 @@ final class MTLContext extends BufferedContext {
|
|||||||
buf.putLong(pConfigInfo);
|
buf.putLong(pConfigInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Invalidates the currentContext field to ensure that we properly
|
|
||||||
* revalidate the MTLContext (make it current, etc.) next time through
|
|
||||||
* the validate() method. This is typically invoked from methods
|
|
||||||
* that affect the current context state (e.g. disposing a context or
|
|
||||||
* surface).
|
|
||||||
*/
|
|
||||||
public static void invalidateCurrentContext() {
|
|
||||||
// assert MTLRenderQueue.getInstance().lock.isHeldByCurrentThread();
|
|
||||||
|
|
||||||
// invalidate the current Java-level context so that we
|
|
||||||
// revalidate everything the next time around
|
|
||||||
if (currentContext != null) {
|
|
||||||
currentContext.invalidateContext();
|
|
||||||
currentContext = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// invalidate the context reference at the native level, and
|
|
||||||
// then flush the queue so that we have no pending operations
|
|
||||||
// dependent on the current context
|
|
||||||
MTLRenderQueue rq = MTLRenderQueue.getInstance();
|
|
||||||
rq.ensureCapacity(4);
|
|
||||||
rq.getBuffer().putInt(INVALIDATE_CONTEXT);
|
|
||||||
rq.flushNow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class MTLContextCaps extends ContextCapabilities {
|
public static class MTLContextCaps extends ContextCapabilities {
|
||||||
|
|
||||||
/** Indicates that the context is doublebuffered. */
|
/** Indicates that the context is doublebuffered. */
|
||||||
|
@ -145,10 +145,6 @@ public final class MTLGraphicsConfig extends CGraphicsConfig
|
|||||||
MTLRenderQueue rq = MTLRenderQueue.getInstance();
|
MTLRenderQueue rq = MTLRenderQueue.getInstance();
|
||||||
rq.lock();
|
rq.lock();
|
||||||
try {
|
try {
|
||||||
// getMTLConfigInfo() creates and destroys temporary
|
|
||||||
// surfaces/contexts, so we should first invalidate the current
|
|
||||||
// Java-level context and flush the queue...
|
|
||||||
MTLContext.invalidateCurrentContext();
|
|
||||||
cfginfo = getMTLConfigInfo(displayID, mtlShadersLib);
|
cfginfo = getMTLConfigInfo(displayID, mtlShadersLib);
|
||||||
if (cfginfo != 0L) {
|
if (cfginfo != 0L) {
|
||||||
textureSize = nativeGetMaxTextureSize();
|
textureSize = nativeGetMaxTextureSize();
|
||||||
|
@ -26,13 +26,9 @@
|
|||||||
#import "sun_java2d_metal_MTLGraphicsConfig.h"
|
#import "sun_java2d_metal_MTLGraphicsConfig.h"
|
||||||
|
|
||||||
#import "MTLGraphicsConfig.h"
|
#import "MTLGraphicsConfig.h"
|
||||||
#import "MTLSurfaceData.h"
|
|
||||||
#import "ThreadUtilities.h"
|
#import "ThreadUtilities.h"
|
||||||
#import "awt.h"
|
#import "awt.h"
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark "--- Mac OS X specific methods for Metal pipeline ---"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disposes all memory and resources associated with the given
|
* Disposes all memory and resources associated with the given
|
||||||
* MTLGraphicsConfigInfo (including its native MTLContext data).
|
* MTLGraphicsConfigInfo (including its native MTLContext data).
|
||||||
@ -58,10 +54,6 @@ MTLGC_DestroyMTLGraphicsConfig(jlong pConfigInfo)
|
|||||||
free(mtlinfo);
|
free(mtlinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark "--- MTLGraphicsConfig methods ---"
|
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL
|
JNIEXPORT jboolean JNICALL
|
||||||
Java_sun_java2d_metal_MTLGraphicsConfig_isMetalFrameworkAvailable
|
Java_sun_java2d_metal_MTLGraphicsConfig_isMetalFrameworkAvailable
|
||||||
(JNIEnv *env, jclass mtlgc)
|
(JNIEnv *env, jclass mtlgc)
|
||||||
@ -82,143 +74,76 @@ JNIEXPORT jboolean JNICALL
|
|||||||
Java_sun_java2d_metal_MTLGraphicsConfig_tryLoadMetalLibrary
|
Java_sun_java2d_metal_MTLGraphicsConfig_tryLoadMetalLibrary
|
||||||
(JNIEnv *env, jclass mtlgc, jint displayID, jstring shadersLibName)
|
(JNIEnv *env, jclass mtlgc, jint displayID, jstring shadersLibName)
|
||||||
{
|
{
|
||||||
jboolean ret = JNI_FALSE;
|
__block jboolean ret = JNI_FALSE;
|
||||||
JNI_COCOA_ENTER(env);
|
|
||||||
NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
|
JNI_COCOA_ENTER(env);
|
||||||
[retArray addObject: [NSNumber numberWithInt: (int)displayID]];
|
|
||||||
char *str = JNU_GetStringPlatformChars(env, shadersLibName, 0);
|
__block NSString* path = NormalizedPathNSStringFromJavaString(env, shadersLibName);
|
||||||
[retArray addObject: [NSString stringWithUTF8String: str]];
|
|
||||||
|
|
||||||
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
|
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
|
||||||
[MTLGraphicsConfigUtil _tryLoadMetalLibrary: retArray];
|
|
||||||
|
id<MTLDevice> device = CGDirectDisplayCopyCurrentMetalDevice(displayID);
|
||||||
|
if (device != nil) {
|
||||||
|
NSError* error = nil;
|
||||||
|
id<MTLLibrary> lib = [device newLibraryWithFile:path error:&error];
|
||||||
|
if (lib != nil) {
|
||||||
|
ret = JNI_TRUE;
|
||||||
|
} else {
|
||||||
|
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_tryLoadMetalLibrary - Failed to load Metal shader library.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_tryLoadMetalLibrary - Failed to create MTLDevice.");
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
|
JNI_COCOA_EXIT(env);
|
||||||
ret = (jboolean)[num boolValue];
|
|
||||||
JNU_ReleaseStringPlatformChars(env, shadersLibName, str);
|
|
||||||
JNI_COCOA_EXIT(env);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the MTL pipeline can be used for a given GraphicsConfig
|
* Determines whether the Metal pipeline can be used for a given screen number and
|
||||||
* provided its screen number and visual ID. If the minimum requirements are
|
* shader library path. A MTLContext is created and the native MTLGraphicsConfigInfo
|
||||||
* met, the native MTLGraphicsConfigInfo structure is initialized for this
|
* structure is initialized for this context. A pointer to this structure is
|
||||||
* GraphicsConfig with the necessary information (pixel format, etc.)
|
* returned as a jlong.
|
||||||
* and a pointer to this structure is returned as a jlong. If
|
* If initialization fails at any point, zero is returned, indicating that Metal pipeline
|
||||||
* initialization fails at any point, zero is returned, indicating that MTL
|
* cannot be used for this GraphicsConfig (we should fallback on an existing 2D pipeline).
|
||||||
* cannot be used for this GraphicsConfig (we should fallback on an existing
|
|
||||||
* 2D pipeline).
|
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jlong JNICALL
|
JNIEXPORT jlong JNICALL
|
||||||
Java_sun_java2d_metal_MTLGraphicsConfig_getMTLConfigInfo
|
Java_sun_java2d_metal_MTLGraphicsConfig_getMTLConfigInfo
|
||||||
(JNIEnv *env, jclass mtlgc, jint displayID, jstring mtlShadersLib)
|
(JNIEnv *env, jclass mtlgc, jint displayID, jstring mtlShadersLib)
|
||||||
{
|
{
|
||||||
jlong ret = 0L;
|
__block MTLContext* mtlc = nil;
|
||||||
JNI_COCOA_ENTER(env);
|
__block MTLGraphicsConfigInfo* mtlinfo = nil;
|
||||||
NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
|
|
||||||
[retArray addObject: [NSNumber numberWithInt: (int)displayID]];
|
JNI_COCOA_ENTER(env);
|
||||||
char *str = JNU_GetStringPlatformChars(env, mtlShadersLib, 0);
|
|
||||||
[retArray addObject: [NSString stringWithUTF8String: str]];
|
__block NSString* path = NormalizedPathNSStringFromJavaString(env, mtlShadersLib);
|
||||||
|
|
||||||
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
|
[ThreadUtilities performOnMainThreadWaiting:YES block:^() {
|
||||||
[MTLGraphicsConfigUtil _getMTLConfigInfo: retArray];
|
|
||||||
|
mtlc = [[MTLContext alloc] initWithDevice:CGDirectDisplayCopyCurrentMetalDevice(displayID)
|
||||||
|
shadersLib:path];
|
||||||
|
if (mtlc != 0L) {
|
||||||
|
// create the MTLGraphicsConfigInfo record for this context
|
||||||
|
mtlinfo = (MTLGraphicsConfigInfo *)malloc(sizeof(MTLGraphicsConfigInfo));
|
||||||
|
if (mtlinfo != NULL) {
|
||||||
|
memset(mtlinfo, 0, sizeof(MTLGraphicsConfigInfo));
|
||||||
|
mtlinfo->context = mtlc;
|
||||||
|
} else {
|
||||||
|
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_getMTLConfigInfo: could not allocate memory for mtlinfo");
|
||||||
|
[mtlc release];
|
||||||
|
mtlc = nil;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_getMTLConfigInfo: could not initialze MTLContext.");
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
|
JNI_COCOA_EXIT(env);
|
||||||
ret = (jlong)[num longValue];
|
|
||||||
JNU_ReleaseStringPlatformChars(env, mtlShadersLib, str);
|
return ptr_to_jlong(mtlinfo);
|
||||||
JNI_COCOA_EXIT(env);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@implementation MTLGraphicsConfigUtil
|
|
||||||
+ (void) _getMTLConfigInfo: (NSMutableArray *)argValue {
|
|
||||||
AWT_ASSERT_APPKIT_THREAD;
|
|
||||||
|
|
||||||
jint displayID = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
|
|
||||||
NSString *mtlShadersLib = (NSString *)[argValue objectAtIndex: 1];
|
|
||||||
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
|
|
||||||
[argValue removeAllObjects];
|
|
||||||
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_INFO, "MTLGraphicsConfig_getMTLConfigInfo");
|
|
||||||
|
|
||||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
|
||||||
|
|
||||||
|
|
||||||
NSRect contentRect = NSMakeRect(0, 0, 64, 64);
|
|
||||||
NSWindow *window =
|
|
||||||
[[NSWindow alloc]
|
|
||||||
initWithContentRect: contentRect
|
|
||||||
styleMask: NSBorderlessWindowMask
|
|
||||||
backing: NSBackingStoreBuffered
|
|
||||||
defer: false];
|
|
||||||
if (window == nil) {
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_getMTLConfigInfo: NSWindow is NULL");
|
|
||||||
[argValue addObject: [NSNumber numberWithLong: 0L]];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
MTLContext *mtlc = [[MTLContext alloc] initWithDevice:CGDirectDisplayCopyCurrentMetalDevice(displayID)
|
|
||||||
shadersLib:mtlShadersLib];
|
|
||||||
if (mtlc == 0L) {
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGC_InitMTLContext: could not initialze MTLContext.");
|
|
||||||
[argValue addObject: [NSNumber numberWithLong: 0L]];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// create the MTLGraphicsConfigInfo record for this config
|
|
||||||
MTLGraphicsConfigInfo *mtlinfo = (MTLGraphicsConfigInfo *)malloc(sizeof(MTLGraphicsConfigInfo));
|
|
||||||
if (mtlinfo == NULL) {
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_getMTLConfigInfo: could not allocate memory for mtlinfo");
|
|
||||||
free(mtlc);
|
|
||||||
[argValue addObject: [NSNumber numberWithLong: 0L]];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
memset(mtlinfo, 0, sizeof(MTLGraphicsConfigInfo));
|
|
||||||
mtlinfo->context = mtlc;
|
|
||||||
|
|
||||||
[argValue addObject: [NSNumber numberWithLong:ptr_to_jlong(mtlinfo)]];
|
|
||||||
[pool drain];
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (void) _tryLoadMetalLibrary: (NSMutableArray *)argValue {
|
|
||||||
AWT_ASSERT_APPKIT_THREAD;
|
|
||||||
|
|
||||||
jint displayID = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
|
|
||||||
NSString *mtlShadersLib = (NSString *)[argValue objectAtIndex: 1];
|
|
||||||
JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
|
|
||||||
[argValue removeAllObjects];
|
|
||||||
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_INFO, "MTLGraphicsConfigUtil_tryLoadMTLLibrary");
|
|
||||||
|
|
||||||
|
|
||||||
BOOL ret = FALSE;;
|
|
||||||
id<MTLDevice> device = CGDirectDisplayCopyCurrentMetalDevice(displayID);
|
|
||||||
if (device != nil) {
|
|
||||||
NSError *error = nil;
|
|
||||||
id<MTLLibrary> lib = [device newLibraryWithFile:mtlShadersLib error:&error];
|
|
||||||
if (lib != nil) {
|
|
||||||
ret = TRUE;
|
|
||||||
} else {
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_tryLoadMetalLibrary - Failed to load Metal shader library.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
J2dRlsTraceLn(J2D_TRACE_ERROR, "MTLGraphicsConfig_tryLoadMetalLibrary - Failed to create MTLDevice.");
|
|
||||||
}
|
|
||||||
|
|
||||||
[argValue addObject: [NSNumber numberWithBool: ret]];
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end //GraphicsConfigUtil
|
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_sun_java2d_metal_MTLGraphicsConfig_nativeGetMaxTextureSize
|
Java_sun_java2d_metal_MTLGraphicsConfig_nativeGetMaxTextureSize
|
||||||
(JNIEnv *env, jclass mtlgc)
|
(JNIEnv *env, jclass mtlgc)
|
||||||
|
@ -667,26 +667,7 @@ Java_sun_java2d_metal_MTLRenderQueue_flushBuffer
|
|||||||
// dstOps = NULL;
|
// dstOps = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case sun_java2d_pipe_BufferedOpCodes_INVALIDATE_CONTEXT:
|
|
||||||
{
|
|
||||||
CHECK_PREVIOUS_OP(MTL_OP_OTHER);
|
|
||||||
// invalidate the references to the current context and
|
|
||||||
// destination surface that are maintained at the native level
|
|
||||||
if (mtlc != NULL) {
|
|
||||||
commitEncodedCommands();
|
|
||||||
RESET_PREVIOUS_OP();
|
|
||||||
[mtlc reset];
|
|
||||||
}
|
|
||||||
|
|
||||||
MTLTR_FreeGlyphCaches();
|
|
||||||
if (dstOps != NULL) {
|
|
||||||
MTLSD_Delete(env, dstOps);
|
|
||||||
}
|
|
||||||
|
|
||||||
mtlc = NULL;
|
|
||||||
dstOps = NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case sun_java2d_pipe_BufferedOpCodes_SYNC:
|
case sun_java2d_pipe_BufferedOpCodes_SYNC:
|
||||||
{
|
{
|
||||||
CHECK_PREVIOUS_OP(MTL_OP_SYNC);
|
CHECK_PREVIOUS_OP(MTL_OP_SYNC);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user