-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JBR-7237 Fix cyclic dependency of Wayland and Vulkan initialization #396
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2024 JetBrains s.r.o. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package sun.java2d.vulkan; | ||
|
||
import sun.util.logging.PlatformLogger; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
public class VKInstance { | ||
|
||
private static final PlatformLogger log = PlatformLogger.getLogger("sun.java2d.vulkan.VKInstance"); | ||
private static Boolean initialized; | ||
|
||
private static native boolean initNative(long nativePtr, boolean verbose, int deviceNumber); | ||
|
||
public static void init(long nativePtr) { | ||
@SuppressWarnings("removal") | ||
String vulkanOption = AccessController.doPrivileged( | ||
(PrivilegedAction<String>) () -> System.getProperty("sun.java2d.vulkan", "")); | ||
if ("true".equalsIgnoreCase(vulkanOption)) { | ||
@SuppressWarnings("removal") | ||
String deviceNumberOption = AccessController.doPrivileged( | ||
(PrivilegedAction<String>) () -> System.getProperty("sun.java2d.vulkan.deviceNumber", "0")); | ||
int parsedDeviceNumber = 0; | ||
try { | ||
parsedDeviceNumber = Integer.parseInt(deviceNumberOption); | ||
} catch (NumberFormatException e) { | ||
log.warning("Invalid Vulkan device number:" + deviceNumberOption); | ||
} | ||
final int deviceNumber = parsedDeviceNumber; | ||
final boolean verbose = "True".equals(vulkanOption); | ||
System.loadLibrary("awt"); | ||
initialized = initNative(nativePtr, verbose, deviceNumber); | ||
} else initialized = false; | ||
if (log.isLoggable(PlatformLogger.Level.FINE)) { | ||
log.fine("Vulkan rendering enabled: " + (initialized ? "YES" : "NO")); | ||
} | ||
} | ||
|
||
public static boolean isVulkanEnabled() { | ||
if (initialized == null) throw new RuntimeException("Vulkan not initialized"); | ||
return initialized; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,14 +44,13 @@ static const uint32_t REQUIRED_VULKAN_VERSION = VK_MAKE_API_VERSION(0, 1, 2, 0); | |
#define VALIDATION_LAYER_NAME "VK_LAYER_KHRONOS_validation" | ||
#define COUNT_OF(x) (sizeof(x)/sizeof(x[0])) | ||
#if defined(VK_USE_PLATFORM_WAYLAND_KHR) | ||
extern struct wl_display *wl_display; | ||
static struct wl_display *wl_display; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This name clashes with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's even better to put this info as a field into VKGraphicsEnvironment, it's already platform-dependent so one more field would not hurt. |
||
#endif | ||
|
||
static jboolean verbose; | ||
static jint requestedDeviceNumber = -1; | ||
static VKGraphicsEnvironment* geInstance = NULL; | ||
static void* pVulkanLib = NULL; | ||
#define DEBUG | ||
#define INCLUDE_BYTECODE | ||
#define SHADER_ENTRY(NAME, TYPE) static uint32_t NAME ## _ ## TYPE ## _data[] = { | ||
#define BYTECODE_END }; | ||
|
@@ -151,8 +150,16 @@ void* vulkanLibProc(VkInstance vkInstance, char* procName) { | |
return vkProc; | ||
} | ||
|
||
|
||
jboolean VK_Init(jboolean verb, jint requestedDevice) { | ||
/* | ||
* Class: sun_java2d_vulkan_VKInstance | ||
* Method: init | ||
* Signature: (JZI)Z | ||
*/ | ||
JNIEXPORT jboolean JNICALL | ||
Java_sun_java2d_vulkan_VKInstance_initNative(JNIEnv *env, jclass wlge, jlong nativePtr, jboolean verb, jint requestedDevice) { | ||
#if defined(VK_USE_PLATFORM_WAYLAND_KHR) | ||
wl_display = (struct wl_display*) jlong_to_ptr(nativePtr); | ||
#endif | ||
verbose = verb; | ||
if (VKGE_graphics_environment() == NULL) { | ||
return JNI_FALSE; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oracle copyright is also needed here.