--- old/src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java 2020-01-28 19:36:55.000000000 -0800 +++ new/src/java.desktop/macosx/classes/sun/awt/CGraphicsDevice.java 2020-01-28 19:36:55.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020, 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 @@ -63,7 +63,7 @@ public CGraphicsDevice(final int displayID) { this.displayID = displayID; - config = CGLGraphicsConfig.getConfig(this, displayID, 0); + config = CGLGraphicsConfig.getConfig(this); // initializes default device state, might be redundant step since we // call "displayChanged()" later anyway, but we do not want to leave the // device in an inconsistent state after construction --- old/src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java 2020-01-28 19:36:57.000000000 -0800 +++ new/src/java.desktop/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java 2020-01-28 19:36:57.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, 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 @@ -64,13 +64,9 @@ public final class CGLGraphicsConfig extends CGraphicsConfig implements OGLGraphicsConfig { - //private static final int kOpenGLSwapInterval = - // RuntimeOptions.getCurrentOptions().OpenGLSwapInterval; - private static final int kOpenGLSwapInterval = 0; // TODO private static boolean cglAvailable; private static ImageCapabilities imageCaps = new CGLImageCaps(); - private int pixfmt; private BufferCapabilities bufferCaps; private long pConfigInfo; private ContextCapabilities oglCaps; @@ -79,8 +75,7 @@ private final int maxTextureSize; private static native boolean initCGL(); - private static native long getCGLConfigInfo(int displayID, int visualnum, - int swapInterval); + private static native long getCGLConfigInfo(); private static native int getOGLCapabilities(long configInfo); /** @@ -95,12 +90,9 @@ cglAvailable = initCGL(); } - private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt, - long configInfo, int maxTextureSize, - ContextCapabilities oglCaps) { + private CGLGraphicsConfig(CGraphicsDevice device, long configInfo, + int maxTextureSize, ContextCapabilities oglCaps) { super(device); - - this.pixfmt = pixfmt; this.pConfigInfo = configInfo; this.oglCaps = oglCaps; this.maxTextureSize = maxTextureSize; @@ -125,8 +117,7 @@ OGLSurfaceData.TEXTURE); } - public static CGLGraphicsConfig getConfig(CGraphicsDevice device, - int displayID, int pixfmt) + public static CGLGraphicsConfig getConfig(CGraphicsDevice device) { if (!cglAvailable) { return null; @@ -142,7 +133,7 @@ // surfaces/contexts, so we should first invalidate the current // Java-level context and flush the queue... OGLContext.invalidateCurrentContext(); - cfginfo = getCGLConfigInfo(displayID, pixfmt, kOpenGLSwapInterval); + cfginfo = getCGLConfigInfo(); if (cfginfo != 0L) { textureSize = nativeGetMaxTextureSize(); // 7160609: GL still fails to create a square texture of this @@ -163,7 +154,7 @@ int oglCaps = getOGLCapabilities(cfginfo); ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]); - return new CGLGraphicsConfig(device, pixfmt, cfginfo, textureSize, caps); + return new CGLGraphicsConfig(device, cfginfo, textureSize, caps); } public static boolean isCGLAvailable() { @@ -253,8 +244,7 @@ @Override public String toString() { - String display = getDevice().getIDstring(); - return ("CGLGraphicsConfig[" + display + ", pixfmt=" + pixfmt + "]"); + return ("CGLGraphicsConfig[" + getDevice().getIDstring() + "]"); } @Override --- old/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.h 2020-01-28 19:37:00.000000000 -0800 +++ new/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.h 2020-01-28 19:36:59.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, 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 @@ -32,10 +32,6 @@ #import "OGLContext.h" #import -@interface GraphicsConfigUtil : NSObject {} -+ (void) _getCGLConfigInfo: (NSMutableArray *)argValue; -@end - // REMIND: Using an NSOpenGLPixelBuffer as the scratch surface has been // problematic thus far (seeing garbage and flickering when switching // between an NSView and the scratch surface), so the following enables @@ -50,20 +46,12 @@ /** * The CGLGraphicsConfigInfo structure contains information specific to a - * given CGLGraphicsConfig (pixel format). - * - * jint screen; - * The screen and PixelFormat for the associated CGLGraphicsConfig. - * - * NSOpenGLPixelFormat *pixfmt; - * The pixel format of the native NSOpenGL context. + * given CGLGraphicsConfig. * * OGLContext *context; * The context associated with this CGLGraphicsConfig. */ typedef struct _CGLGraphicsConfigInfo { - jint screen; - NSOpenGLPixelFormat *pixfmt; OGLContext *context; } CGLGraphicsConfigInfo; --- old/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m 2020-01-28 19:37:02.000000000 -0800 +++ new/src/java.desktop/macosx/native/libawt_lwawt/java2d/opengl/CGLGraphicsConfig.m 2020-01-28 19:37:01.000000000 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2020, 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 @@ -34,9 +34,6 @@ #import #import -#pragma mark - -#pragma mark "--- Mac OS X specific methods for GL pipeline ---" - /** * Disposes all memory and resources associated with the given * CGLGraphicsConfigInfo (including its native OGLContext data). @@ -77,9 +74,6 @@ free(cglinfo); } -#pragma mark - -#pragma mark "--- CGLGraphicsConfig methods ---" - /** * This is a globally shared context used when creating textures. When any * new contexts are created, they specify this context as the "share list" @@ -112,233 +106,191 @@ return JNI_TRUE; } - /** - * Determines whether the CGL pipeline can be used for a given GraphicsConfig - * provided its screen number and visual ID. If the minimum requirements are - * met, the native CGLGraphicsConfigInfo structure is initialized for this - * GraphicsConfig with the necessary information (pixel format, etc.) - * and a pointer to this structure is returned as a jlong. If + * Determines whether the CGL pipeline can be used for a given GraphicsConfig. + * If the minimum requirements are met, the native CGLGraphicsConfigInfo + * structure is initialized for this GraphicsConfig with the necessary + * information and a pointer to this structure is returned as a jlong. If * initialization fails at any point, zero is returned, indicating that CGL - * 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 Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo - (JNIEnv *env, jclass cglgc, - jint displayID, jint pixfmt, jint swapInterval) + (JNIEnv *env, jclass cglgc) { - jlong ret = 0L; - JNF_COCOA_ENTER(env); - NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3]; - [retArray addObject: [NSNumber numberWithInt: (int)displayID]]; - [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]]; - [retArray addObject: [NSNumber numberWithInt: (int)swapInterval]]; - if ([NSThread isMainThread]) { - [GraphicsConfigUtil _getCGLConfigInfo: retArray]; - } else { - [GraphicsConfigUtil performSelectorOnMainThread: @selector(_getCGLConfigInfo:) withObject: retArray waitUntilDone: YES]; - } - NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0]; - ret = (jlong)[num longValue]; - JNF_COCOA_EXIT(env); - return ret; -} + __block jlong ret = 0L; + JNF_COCOA_ENTER(env); + [ThreadUtilities performOnMainThreadWaiting:YES block:^(){ + JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; + J2dRlsTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo"); + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; -@implementation GraphicsConfigUtil -+ (void) _getCGLConfigInfo: (NSMutableArray *)argValue { - AWT_ASSERT_APPKIT_THREAD; - - jint displayID = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue]; - jint swapInterval = (jint)[(NSNumber *)[argValue objectAtIndex: 2] intValue]; - JNIEnv *env = [ThreadUtilities getJNIEnvUncached]; - [argValue removeAllObjects]; - - J2dRlsTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo"); - - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - if (sharedContext == NULL) { - - NSOpenGLPixelFormatAttribute attrs[] = { - NSOpenGLPFAAllowOfflineRenderers, - NSOpenGLPFAClosestPolicy, - NSOpenGLPFAWindow, - NSOpenGLPFAPixelBuffer, - NSOpenGLPFADoubleBuffer, - NSOpenGLPFAColorSize, 32, - NSOpenGLPFAAlphaSize, 8, - NSOpenGLPFADepthSize, 16, - 0 - }; - - sharedPixelFormat = - [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; - if (sharedPixelFormat == nil) { - J2dRlsTraceLn(J2D_TRACE_ERROR, - "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLPixelFormat is NULL"); - - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } + if (sharedContext == NULL) { - sharedContext = - [[NSOpenGLContext alloc] - initWithFormat:sharedPixelFormat - shareContext: NULL]; - if (sharedContext == nil) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLContext is NULL"); - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; + NSOpenGLPixelFormatAttribute attrs[] = { + NSOpenGLPFAAllowOfflineRenderers, + NSOpenGLPFAClosestPolicy, + NSOpenGLPFAWindow, + NSOpenGLPFAPixelBuffer, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAColorSize, 32, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADepthSize, 16, + 0 + }; + + sharedPixelFormat = + [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]; + if (sharedPixelFormat == nil) { + J2dRlsTraceLn(J2D_TRACE_ERROR, + "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLPixelFormat is NULL"); + return; + } + + sharedContext = + [[NSOpenGLContext alloc] + initWithFormat:sharedPixelFormat + shareContext: NULL]; + if (sharedContext == nil) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: shared NSOpenGLContext is NULL"); + return; + } } - } #if USE_NSVIEW_FOR_SCRATCH - 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, "CGLGraphicsConfig_getCGLConfigInfo: NSWindow is NULL"); - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } + 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, "CGLGraphicsConfig_getCGLConfigInfo: NSWindow is NULL"); + return; + } - NSView *scratchSurface = - [[NSView alloc] - initWithFrame: contentRect]; - if (scratchSurface == nil) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSView is NULL"); - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } - [window setContentView: scratchSurface]; + NSView *scratchSurface = + [[NSView alloc] + initWithFrame: contentRect]; + if (scratchSurface == nil) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSView is NULL"); + return; + } + [window setContentView: scratchSurface]; #else - NSOpenGLPixelBuffer *scratchSurface = - [[NSOpenGLPixelBuffer alloc] - initWithTextureTarget:GL_TEXTURE_2D - textureInternalFormat:GL_RGB - textureMaxMipMapLevel:0 - pixelsWide:64 - pixelsHigh:64]; + NSOpenGLPixelBuffer *scratchSurface = + [[NSOpenGLPixelBuffer alloc] + initWithTextureTarget:GL_TEXTURE_2D + textureInternalFormat:GL_RGB + textureMaxMipMapLevel:0 + pixelsWide:64 + pixelsHigh:64]; #endif - NSOpenGLContext *context = - [[NSOpenGLContext alloc] - initWithFormat: sharedPixelFormat - shareContext: sharedContext]; - if (context == nil) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSOpenGLContext is NULL"); - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } + NSOpenGLContext *context = + [[NSOpenGLContext alloc] + initWithFormat: sharedPixelFormat + shareContext: sharedContext]; + if (context == nil) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: NSOpenGLContext is NULL"); + return; + } - GLint contextVirtualScreen = [context currentVirtualScreen]; + GLint contextVirtualScreen = [context currentVirtualScreen]; #if USE_NSVIEW_FOR_SCRATCH - [context setView: scratchSurface]; + [context setView: scratchSurface]; #else - [context - setPixelBuffer: scratchSurface - cubeMapFace:0 - mipMapLevel:0 - currentVirtualScreen: contextVirtualScreen]; + [context + setPixelBuffer: scratchSurface + cubeMapFace:0 + mipMapLevel:0 + currentVirtualScreen: contextVirtualScreen]; #endif - [context makeCurrentContext]; + [context makeCurrentContext]; - // get version and extension strings - const unsigned char *versionstr = j2d_glGetString(GL_VERSION); - if (!OGLContext_IsVersionSupported(versionstr)) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: OpenGL 1.2 is required"); - [NSOpenGLContext clearCurrentContext]; - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } - J2dRlsTraceLn1(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo: OpenGL version=%s", versionstr); + // get version and extension strings + const unsigned char *versionstr = j2d_glGetString(GL_VERSION); + if (!OGLContext_IsVersionSupported(versionstr)) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: OpenGL 1.2 is required"); + [NSOpenGLContext clearCurrentContext]; + return; + } + J2dRlsTraceLn1(J2D_TRACE_INFO, "CGLGraphicsConfig_getCGLConfigInfo: OpenGL version=%s", versionstr); - jint caps = CAPS_EMPTY; - OGLContext_GetExtensionInfo(env, &caps); + jint caps = CAPS_EMPTY; + OGLContext_GetExtensionInfo(env, &caps); - GLint value = 0; - [sharedPixelFormat - getValues: &value - forAttribute: NSOpenGLPFADoubleBuffer - forVirtualScreen: contextVirtualScreen]; - if (value != 0) { - caps |= CAPS_DOUBLEBUFFERED; - } + GLint value = 0; + [sharedPixelFormat + getValues: &value + forAttribute: NSOpenGLPFADoubleBuffer + forVirtualScreen: contextVirtualScreen]; + if (value != 0) { + caps |= CAPS_DOUBLEBUFFERED; + } - J2dRlsTraceLn1(J2D_TRACE_INFO, - "CGLGraphicsConfig_getCGLConfigInfo: db=%d", - (caps & CAPS_DOUBLEBUFFERED) != 0); + J2dRlsTraceLn1(J2D_TRACE_INFO, + "CGLGraphicsConfig_getCGLConfigInfo: db=%d", + (caps & CAPS_DOUBLEBUFFERED) != 0); - // remove before shipping (?) + // remove before shipping (?) #if 1 - [sharedPixelFormat - getValues: &value - forAttribute: NSOpenGLPFAAccelerated - forVirtualScreen: contextVirtualScreen]; - if (value == 0) { [sharedPixelFormat getValues: &value - forAttribute: NSOpenGLPFARendererID + forAttribute: NSOpenGLPFAAccelerated forVirtualScreen: contextVirtualScreen]; - fprintf(stderr, "WARNING: GL pipe is running in software mode (Renderer ID=0x%x)\n", (int)value); - } + if (value == 0) { + [sharedPixelFormat + getValues: &value + forAttribute: NSOpenGLPFARendererID + forVirtualScreen: contextVirtualScreen]; + fprintf(stderr, "WARNING: GL pipe is running in software mode (Renderer ID=0x%x)\n", (int)value); + } #endif + CGLCtxInfo *ctxinfo = (CGLCtxInfo *)malloc(sizeof(CGLCtxInfo)); + if (ctxinfo == NULL) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGC_InitOGLContext: could not allocate memory for ctxinfo"); + [NSOpenGLContext clearCurrentContext]; + return; + } + memset(ctxinfo, 0, sizeof(CGLCtxInfo)); + ctxinfo->context = context; + ctxinfo->scratchSurface = scratchSurface; + + OGLContext *oglc = (OGLContext *)malloc(sizeof(OGLContext)); + if (oglc == 0L) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGC_InitOGLContext: could not allocate memory for oglc"); + [NSOpenGLContext clearCurrentContext]; + free(ctxinfo); + return; + } + memset(oglc, 0, sizeof(OGLContext)); + oglc->ctxInfo = ctxinfo; + oglc->caps = caps; + + // create the CGLGraphicsConfigInfo record for this config + CGLGraphicsConfigInfo *cglinfo = (CGLGraphicsConfigInfo *)malloc(sizeof(CGLGraphicsConfigInfo)); + if (cglinfo == NULL) { + J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: could not allocate memory for cglinfo"); + [NSOpenGLContext clearCurrentContext]; + free(oglc); + free(ctxinfo); + return; + } + memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo)); + cglinfo->context = oglc; - // 0: the buffers are swapped with no regard to the vertical refresh rate - // 1: the buffers are swapped only during the vertical retrace - GLint params = swapInterval; - [context setValues: ¶ms forParameter: NSOpenGLCPSwapInterval]; - - CGLCtxInfo *ctxinfo = (CGLCtxInfo *)malloc(sizeof(CGLCtxInfo)); - if (ctxinfo == NULL) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGC_InitOGLContext: could not allocate memory for ctxinfo"); - [NSOpenGLContext clearCurrentContext]; - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } - memset(ctxinfo, 0, sizeof(CGLCtxInfo)); - ctxinfo->context = context; - ctxinfo->scratchSurface = scratchSurface; - - OGLContext *oglc = (OGLContext *)malloc(sizeof(OGLContext)); - if (oglc == 0L) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGC_InitOGLContext: could not allocate memory for oglc"); - [NSOpenGLContext clearCurrentContext]; - free(ctxinfo); - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } - memset(oglc, 0, sizeof(OGLContext)); - oglc->ctxInfo = ctxinfo; - oglc->caps = caps; - - // create the CGLGraphicsConfigInfo record for this config - CGLGraphicsConfigInfo *cglinfo = (CGLGraphicsConfigInfo *)malloc(sizeof(CGLGraphicsConfigInfo)); - if (cglinfo == NULL) { - J2dRlsTraceLn(J2D_TRACE_ERROR, "CGLGraphicsConfig_getCGLConfigInfo: could not allocate memory for cglinfo"); [NSOpenGLContext clearCurrentContext]; - free(oglc); - free(ctxinfo); - [argValue addObject: [NSNumber numberWithLong: 0L]]; - return; - } - memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo)); - cglinfo->screen = displayID; - cglinfo->pixfmt = sharedPixelFormat; - cglinfo->context = oglc; - - [NSOpenGLContext clearCurrentContext]; - [argValue addObject: [NSNumber numberWithLong:ptr_to_jlong(cglinfo)]]; - [pool drain]; + ret = ptr_to_jlong(cglinfo); + [pool drain]; + }]; + JNF_COCOA_EXIT(env); + return ret; } -@end //GraphicsConfigUtil JNIEXPORT jint JNICALL Java_sun_java2d_opengl_CGLGraphicsConfig_getOGLCapabilities