Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/MacOSFlags.java
41152 views
1
/*
2
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
package sun.java2d;
27
28
import java.security.PrivilegedAction;
29
import sun.java2d.metal.MTLGraphicsConfig;
30
import sun.java2d.opengl.CGLGraphicsConfig;
31
32
33
public class MacOSFlags {
34
35
/**
36
* Description of command-line flags. All flags with [true|false]
37
* values
38
* metalEnabled: usage: "-Dsun.java2d.metal=[true|false]"
39
*/
40
41
private static boolean oglEnabled;
42
private static boolean oglVerbose;
43
private static boolean metalEnabled;
44
private static boolean metalVerbose;
45
46
private enum PropertyState {ENABLED, DISABLED, UNSPECIFIED};
47
48
static {
49
initJavaFlags();
50
}
51
52
private static PropertyState getBooleanProp(String p, PropertyState defaultVal) {
53
String propString = System.getProperty(p);
54
PropertyState returnVal = defaultVal;
55
if (propString != null) {
56
if (propString.equals("true") ||
57
propString.equals("t") ||
58
propString.equals("True") ||
59
propString.equals("T") ||
60
propString.equals("")) // having the prop name alone
61
{ // is equivalent to true
62
returnVal = PropertyState.ENABLED;
63
} else if (propString.equals("false") ||
64
propString.equals("f") ||
65
propString.equals("False") ||
66
propString.equals("F"))
67
{
68
returnVal = PropertyState.DISABLED;
69
}
70
}
71
return returnVal;
72
}
73
74
private static boolean isBooleanPropTrueVerbose(String p) {
75
String propString = System.getProperty(p);
76
if (propString != null) {
77
if (propString.equals("True") ||
78
propString.equals("T"))
79
{
80
return true;
81
}
82
}
83
return false;
84
}
85
86
@SuppressWarnings("removal")
87
private static void initJavaFlags() {
88
java.security.AccessController.doPrivileged(
89
(PrivilegedAction<Object>) () -> {
90
PropertyState oglState = getBooleanProp("sun.java2d.opengl", PropertyState.UNSPECIFIED);
91
PropertyState metalState = getBooleanProp("sun.java2d.metal", PropertyState.UNSPECIFIED);
92
93
// Handle invalid combinations to use the default rendering pipeline
94
// Current default rendering pipeline is OpenGL
95
// (The default can be changed to Metal in future just by toggling two states in this if condition block)
96
if ((oglState == PropertyState.UNSPECIFIED && metalState == PropertyState.UNSPECIFIED) ||
97
(oglState == PropertyState.DISABLED && metalState == PropertyState.DISABLED) ||
98
(oglState == PropertyState.ENABLED && metalState == PropertyState.ENABLED)) {
99
oglState = PropertyState.ENABLED; // Enable default pipeline
100
metalState = PropertyState.DISABLED; // Disable non-default pipeline
101
}
102
103
if (metalState == PropertyState.UNSPECIFIED) {
104
if (oglState == PropertyState.DISABLED) {
105
oglEnabled = false;
106
metalEnabled = true;
107
} else {
108
oglEnabled = true;
109
metalEnabled = false;
110
}
111
} else if (metalState == PropertyState.ENABLED) {
112
oglEnabled = false;
113
metalEnabled = true;
114
} else if (metalState == PropertyState.DISABLED) {
115
oglEnabled = true;
116
metalEnabled = false;
117
}
118
119
oglVerbose = isBooleanPropTrueVerbose("sun.java2d.opengl");
120
metalVerbose = isBooleanPropTrueVerbose("sun.java2d.metal");
121
122
if (oglEnabled && !metalEnabled) {
123
// Check whether OGL is available
124
if (!CGLGraphicsConfig.isCGLAvailable()) {
125
if (oglVerbose) {
126
System.out.println("Could not enable OpenGL pipeline (CGL not available)");
127
}
128
oglEnabled = false;
129
metalEnabled = MTLGraphicsConfig.isMetalAvailable();
130
}
131
} else if (metalEnabled && !oglEnabled) {
132
// Check whether Metal framework is available
133
if (!MTLGraphicsConfig.isMetalAvailable()) {
134
if (metalVerbose) {
135
System.out.println("Could not enable Metal pipeline (Metal framework not available)");
136
}
137
metalEnabled = false;
138
oglEnabled = CGLGraphicsConfig.isCGLAvailable();
139
}
140
}
141
142
// At this point one of the rendering pipeline must be enabled.
143
if (!metalEnabled && !oglEnabled) {
144
throw new InternalError("Error - unable to initialize any rendering pipeline.");
145
}
146
147
return null;
148
});
149
}
150
151
public static boolean isMetalEnabled() {
152
return metalEnabled;
153
}
154
155
public static boolean isMetalVerbose() {
156
return metalVerbose;
157
}
158
159
public static boolean isOGLEnabled() {
160
return oglEnabled;
161
}
162
163
public static boolean isOGLVerbose() {
164
return oglVerbose;
165
}
166
}
167
168