Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259825: Find a better way to detect Metal framework availability on …
…system

Reviewed-by: prr
  • Loading branch information
aghaisas committed Mar 10, 2021
1 parent 8ba59cf commit d729f30fdfac866fde53c7aae86dca879edd065a
Showing with 3 additions and 34 deletions.
  1. +3 −34 src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m
@@ -29,19 +29,10 @@
#import "MTLSurfaceData.h"
#import "ThreadUtilities.h"
#import "awt.h"
#import "MTLUtils.h"


#import <stdlib.h>
#import <string.h>
#import <ApplicationServices/ApplicationServices.h>

#pragma mark -
#pragma mark "--- Mac OS X specific methods for Metal pipeline ---"

// Uncomment this line to see Metal specific fprintfs
//#define METAL_DEBUG

/**
* Disposes all memory and resources associated with the given
* MTLGraphicsConfigInfo (including its native MTLContext data).
@@ -71,38 +62,16 @@
#pragma mark "--- MTLGraphicsConfig methods ---"


/**
* Probe Metal framework availability using system profiler
*/
JNIEXPORT jboolean JNICALL
Java_sun_java2d_metal_MTLGraphicsConfig_isMetalFrameworkAvailable
(JNIEnv *env, jclass mtlgc)
{
FILE *f = popen("/usr/sbin/system_profiler SPDisplaysDataType", "r");
jboolean metalSupported = JNI_FALSE;
while (getc(f) != EOF)
{
char str[60];

if (fgets(str, 60, f) != NULL) {
// Check for string
// "Metal: Supported, feature set macOS GPUFamily1 v4"
if (strstr(str, "Metal") != NULL) {
//puts(str);
metalSupported = JNI_TRUE;
break;
}
}
}
pclose(f);

#ifdef METAL_DEBUG
if (!metalSupported) {
fprintf(stderr, "Metal support not present\n");
} else {
fprintf(stderr, "Metal support is present\n");
// It is guranteed that metal supported GPU is available macOS 10.14 onwards
if (@available(macOS 10.14, *)) {
metalSupported = JNI_TRUE;
}
#endif

J2dRlsTraceLn1(J2D_TRACE_INFO, "MTLGraphicsConfig_isMetalFrameworkAvailable : %d", metalSupported);

0 comments on commit d729f30

Please sign in to comment.