Commit 4aab7c3a authored by Nikolay Igotti's avatar Nikolay Igotti

Minor tweaks to native code.

parent c83d06cf
...@@ -77,6 +77,10 @@ kotlin { ...@@ -77,6 +77,10 @@ kotlin {
} }
} }
tasks.withType(JavaCompile::class.java).configureEach {
this.getOptions().compilerArgs.addAll(listOf("-source", "11", "-target", "11"))
}
// See https://docs.gradle.org/current/userguide/cpp_library_plugin.html. // See https://docs.gradle.org/current/userguide/cpp_library_plugin.html.
tasks.withType(CppCompile::class.java).configureEach { tasks.withType(CppCompile::class.java).configureEach {
// Prefer 'java.home' system property to simplify overriding from Intellij. // Prefer 'java.home' system property to simplify overriding from Intellij.
...@@ -172,7 +176,6 @@ project.tasks.register<Exec>("objcCompile") { ...@@ -172,7 +176,6 @@ project.tasks.register<Exec>("objcCompile") {
outputs.files("$outDir/$objcSrc.o") outputs.files("$outDir/$objcSrc.o")
} }
tasks.withType(LinkSharedLibrary::class.java).configureEach { tasks.withType(LinkSharedLibrary::class.java).configureEach {
when (target) { when (target) {
"macos" -> { "macos" -> {
...@@ -254,8 +257,6 @@ project.tasks.register<JavaExec>("run") { ...@@ -254,8 +257,6 @@ project.tasks.register<JavaExec>("run") {
classpath = files(skikoJvmRuntimeJar.map { it.archiveFile }) classpath = files(skikoJvmRuntimeJar.map { it.archiveFile })
} }
// disable unexpected native publications (default C++ publications are failing) // disable unexpected native publications (default C++ publications are failing)
tasks.withType<AbstractPublishToMaven>().configureEach { tasks.withType<AbstractPublishToMaven>().configureEach {
doFirst { doFirst {
......
...@@ -10,15 +10,43 @@ ...@@ -10,15 +10,43 @@
typedef jboolean (*JAWT_GetAWT_t)(JNIEnv *, JAWT *); typedef jboolean (*JAWT_GetAWT_t)(JNIEnv *, JAWT *);
#if 0
bool check(JNIEnv* env, const char* msg) {
if (env->ExceptionCheck()) {
jthrowable exception = env->ExceptionOccurred();
jclass throwableClass = env->FindClass("java/lang/Throwable");
jmethodID toStringMethod = env->GetMethodID(
throwableClass, "toString", "()Ljava/lang/String;");
jstring messageObject = (jstring) env->CallObjectMethod(exception, toStringMethod);
const char* messageString = env->GetStringUTFChars(messageObject, 0);
fprintf(stderr, "Java exception: %s\n", messageString);
env->ReleaseStringUTFChars(messageObject, messageString);
jmethodID printStackTraceMethod = env->GetMethodID(throwableClass, "printStackTrace", "()V");
env->CallVoidMethod(exception, printStackTraceMethod);
env->ExceptionClear();
}
}
#endif
void findJdkHome(JNIEnv* env, char* path, int pathLength) {
jclass systemClass = env->FindClass("java/lang/System");
jmethodID getPropertyMethod = env->GetStaticMethodID(
systemClass,
"getProperty",
"(Ljava/lang/String;)Ljava/lang/String;");
jstring javaHomeString = env->NewStringUTF("java.home");
jstring propertyString = (jstring) env->CallStaticObjectMethod(systemClass, getPropertyMethod, javaHomeString);
const char* propertyChars = env->GetStringUTFChars(propertyString, 0);
snprintf(path, pathLength, "%s", propertyChars);
env->ReleaseStringUTFChars(propertyString, propertyChars);
}
extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) { extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) {
static JAWT_GetAWT_t func = nullptr; static JAWT_GetAWT_t func = nullptr;
if (!func) {
char *jdkHome = getenv("JAVA_HOME");
if (!jdkHome) {
fprintf(stderr, "No JAVA_HOME defined!");
abort();
}
#if SK_BUILD_FOR_WIN #if SK_BUILD_FOR_WIN
if (!func) {
char jdkHome[FILENAME_MAX];
findJdkHome(env, jdkHome, sizeof(jdkHome));
char path[FILENAME_MAX]; char path[FILENAME_MAX];
snprintf(path, sizeof(path), "%s\\bin\\jawt.dll", jdkHome); snprintf(path, sizeof(path), "%s\\bin\\jawt.dll", jdkHome);
HMODULE lib = LoadLibrary(path); HMODULE lib = LoadLibrary(path);
...@@ -32,6 +60,9 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) { ...@@ -32,6 +60,9 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) {
abort(); abort();
} }
#else #else
if (!func) {
char jdkHome[FILENAME_MAX];
findJdkHome(env, jdkHome, sizeof(jdkHome));
char path[FILENAME_MAX]; char path[FILENAME_MAX];
snprintf(path, sizeof(path), "%s/lib/libjawt%s", jdkHome, snprintf(path, sizeof(path), "%s/lib/libjawt%s", jdkHome,
#if SK_BUILD_FOR_MAC #if SK_BUILD_FOR_MAC
...@@ -50,7 +81,7 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) { ...@@ -50,7 +81,7 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) {
fprintf(stderr, "Cannot find JAWT_GetAWT in %s\n", path); fprintf(stderr, "Cannot find JAWT_GetAWT in %s\n", path);
abort(); abort();
} }
#endif
} }
#endif
return func(env, awt); return func(env, awt);
} }
\ No newline at end of file
...@@ -117,6 +117,6 @@ open class SkiaWindow : JFrame() { ...@@ -117,6 +117,6 @@ open class SkiaWindow : JFrame() {
} }
fun display() { fun display() {
layer.display() layer.redrawLayer()
} }
} }
...@@ -163,7 +163,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_updateLayer(JNIEnv ...@@ -163,7 +163,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_updateLayer(JNIEnv
jint lock = 0; jint lock = 0;
NSObject<JAWT_SurfaceLayers>* dsi_mac = NULL; NSObject<JAWT_SurfaceLayers>* dsi_mac = NULL;
awt.version = JAWT_VERSION_9; awt.version = JAWT_VERSION_9 /* | JAWT_MACOSX_USE_CALAYER */;
result = Skiko_GetAWT(env, &awt); result = Skiko_GetAWT(env, &awt);
assert(result != JNI_FALSE); assert(result != JNI_FALSE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment