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

Minor tweaks to native code.

parent c83d06cf
......@@ -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.
tasks.withType(CppCompile::class.java).configureEach {
// Prefer 'java.home' system property to simplify overriding from Intellij.
......@@ -172,7 +176,6 @@ project.tasks.register<Exec>("objcCompile") {
outputs.files("$outDir/$objcSrc.o")
}
tasks.withType(LinkSharedLibrary::class.java).configureEach {
when (target) {
"macos" -> {
......@@ -254,8 +257,6 @@ project.tasks.register<JavaExec>("run") {
classpath = files(skikoJvmRuntimeJar.map { it.archiveFile })
}
// disable unexpected native publications (default C++ publications are failing)
tasks.withType<AbstractPublishToMaven>().configureEach {
doFirst {
......
......@@ -10,15 +10,43 @@
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) {
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 (!func) {
char jdkHome[FILENAME_MAX];
findJdkHome(env, jdkHome, sizeof(jdkHome));
char path[FILENAME_MAX];
snprintf(path, sizeof(path), "%s\\bin\\jawt.dll", jdkHome);
HMODULE lib = LoadLibrary(path);
......@@ -32,25 +60,28 @@ extern "C" jboolean Skiko_GetAWT(JNIEnv *env, JAWT *awt) {
abort();
}
#else
char path[FILENAME_MAX];
snprintf(path, sizeof(path), "%s/lib/libjawt%s", jdkHome,
if (!func) {
char jdkHome[FILENAME_MAX];
findJdkHome(env, jdkHome, sizeof(jdkHome));
char path[FILENAME_MAX];
snprintf(path, sizeof(path), "%s/lib/libjawt%s", jdkHome,
#if SK_BUILD_FOR_MAC
".dylib"
#else
".so"
#endif
);
void *lib = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
if (!lib) {
fprintf(stderr, "Cannot open %s: %s\n", path, dlerror());
abort();
}
func = reinterpret_cast<JAWT_GetAWT_t>(dlsym(lib, "JAWT_GetAWT"));
if (!func) {
fprintf(stderr, "Cannot find JAWT_GetAWT in %s\n", path);
abort();
}
#endif
);
void *lib = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
if (!lib) {
fprintf(stderr, "Cannot open %s: %s\n", path, dlerror());
abort();
}
func = reinterpret_cast<JAWT_GetAWT_t>(dlsym(lib, "JAWT_GetAWT"));
if (!func) {
fprintf(stderr, "Cannot find JAWT_GetAWT in %s\n", path);
abort();
}
}
#endif
return func(env, awt);
}
\ No newline at end of file
......@@ -117,6 +117,6 @@ open class SkiaWindow : JFrame() {
}
fun display() {
layer.display()
}
layer.redrawLayer()
}
}
......@@ -163,7 +163,7 @@ JNIEXPORT void JNICALL Java_org_jetbrains_skiko_HardwareLayer_updateLayer(JNIEnv
jint lock = 0;
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);
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