diff --git a/buildSrc/android.gradle b/buildSrc/android.gradle index 462b7d6ad15..34735eeab1c 100644 --- a/buildSrc/android.gradle +++ b/buildSrc/android.gradle @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,150 +23,35 @@ * questions. */ -/** - * Gets the most recent android platform installed, relative to the given path. - * The path will either be ANDROID_SDK or ANDROID_NDK - * TODO Shouldn't we instead just ask people to point to the one they want to use? - * - * @param path The path to the Android SDK or NDK - * @return The name of the most recent platform - */ -String getLatestPlatform(String path) { - def max = 0 - file(cygpath("$path/platforms")).eachFile() {file-> - def pname = file.getName() - "android-" - def ptf = pname?.isInteger() ? pname.toInteger() : 0 - if (max < ptf) { - max = ptf - } - } - if (max == 0) { - return null; - } - return "android-" + max -} - -int compareVersions(String s1, String s2) { - def v1t = s1.tokenize(".") - def v2t = s2.tokenize(".") - for(int i = 0; i < v1t.size(); i++) { - if (i == v2t.size()) { - return 1 - } - int n1 = v1t[i].isInteger() ? v1t[i].toInteger() : 0 - int n2 = v2t[i].isInteger() ? v2t[i].toInteger() : 0 - if (n1 == n2) { - continue - } else if (n1 > n2) { - return 1; - } else { - return -1 - } - } - return (v2t.size() > v1t.size()) ? -1 : 0 -} - -String getLatestToolchain(String ndk, String tch) { - def max = "0.0" - def matchFile = null - file(cygpath("$ndk/toolchains")).eachFile() {file-> - def filename = file.getName() - if (filename.startsWith(tch)) { - def p = filename - "$tch-" - if (compareVersions(p, max) > 0) { - max = p - matchFile = file - } - } - } - return matchFile.getAbsolutePath() -} - -boolean assertDir(File dir) { - return dir != null && dir.exists() && dir.isDirectory() && dir.canRead(); -} - -boolean assertDir(String dir) { - return assertDir(file(dir)) -} def closedDir = file("$projectDir/../rt-closed") +def sdk = project.hasProperty("ANDROID_SDK") ? "${ANDROID_SDK}" : "/opt/android-sdk"; +def ndk = project.hasProperty("ANDROID_NDK") ? "${ANDROID_NDK}" : "/opt/android-ndk"; +def sdk_target = "android-25" +def ndk_target="android-21" +def platform="aarch64-linux-android21" -def toolchainArchs = ["arm-linux-androideabi", "mipsel-linux-android", "x86"] -def armArchs = ["armeabi", "armeabiv-7a"] -ANDROID = [:] +ext.ANDROID = [:] ANDROID.compileSwing = false; ANDROID.compileSWT = false; +ANDROID.compileDesignTime = false; ANDROID.glassPlatform = "android" -ANDROID.armArch = armArchs[0] +ANDROID.armArch = "arm64-v8a" ANDROID.libDest = "lib" ANDROID.jfxdvklib = "jfxdvk.jar" -ANDROID.library = { name -> return "lib${name}.so" as String } - -def sdk = project.hasProperty("ANDROID_SDK") ? "${ANDROID_SDK}" : null; -def ndk = project.hasProperty("ANDROID_NDK") ? "${ANDROID_NDK}" : null; -ANDROID.canBuild = sdk != null && ndk != null -if (!ANDROID.canBuild) { - fail("Can't build Android. Path to SDK or NDK was not set or is invalid!") -} - -ANDROID.canBuild = assertDir(sdk) && assertDir(ndk) -if (!ANDROID.canBuild) { - if (!assertDir(sdk)) { - logger.error("Path to ANDROID_SDK is invalid! [$sdk]") - } - if (!assertDir(ndk)) { - logger.error("Path to ANDROID_NDK is invalid! [$ndk]") - } - fail("Cannot build, missing android tools") -} - -def sdk_target = project.hasProperty("ANDROID_SDK_TARGET") ? "${ANDROID_SDK_TARGET}" : getLatestPlatform(sdk); -if (!assertDir(file("$sdk/platforms/$sdk_target"))) { - sdk_target = getLatestPlatform(sdk); - logger.warn("Redefine ANDROID_SDK_TARGET to: [$sdk_target]") -} - -def ndk_target = project.hasProperty("ANDROID_NDK_TARGET") ? "${ANDROID_NDK_TARGET}" : getLatestPlatform(ndk); -if (!assertDir(file("$ndk/platforms/$ndk_target"))) { - ndk_target = getLatestPlatform(ndk); - logger.warn("Redefine ANDROID_NDK_TARGET to: [$ndk_target]") -} - -ANDROID.canBuild = sdk_target != null && ndk_target != null -if (!ANDROID.canBuild) { - fail("Can't determine sdk or ndk target platform!") -} - -def toolchainHome = project.hasProperty("ANDROID_CROSS_TOOLS_VER") ? - "$ndk/toolchains/${ANDROID_CROSS_TOOLS_VER}" : getLatestToolchain(ndk, toolchainArchs[0]) -if (!assertDir(toolchainHome)) { - toolchainHome = getLatestToolchain(ndk, toolchainArchs[0]) - logger.warn("Redefine toolchain to [$toolchainHome]") -} - -// Look for the the Android SDK & NDK to use, as well as the compiler stuff -def compilerHome = null -file("$toolchainHome/prebuilt").eachDir() {subdir -> - compilerHome = subdir.getAbsolutePath() - return -} - -ANDROID.canBuild = compilerHome != null -if (!ANDROID.canBuild) { - fail("Failed to access toolchain [$toolchainHome/prebuilt/$toolsPlatform]!") -} +ANDROID.library = { name -> return IS_STATIC_BUILD ? "lib${name}.a" : "lib${name}.so" as String } +ANDROID.includeMonocle = true +ANDROID.includeLens = false +ANDROID.canBuild = true +def toolchainHome = "$ndk/toolchains/llvm" +def compilerHome = "$toolchainHome/prebuilt/linux-x86_64" def freetypeDir = project.hasProperty("FREETYPE_DIR") ? "${FREETYPE_DIR}" : null -if (!assertDir(freetypeDir)) { - logger.warn("FREETYPE_DIR $freetypeDir doesn't exists! Build continues without native text support.") - freetypeDir = null -} def compileNativeText = freetypeDir != null -def compiler = file("$compilerHome/bin/${toolchainArchs[0]}-gcc").getAbsolutePath() -def linker = file("$compilerHome/bin/${toolchainArchs[0]}-g++").getAbsolutePath() +def compiler = file("$compilerHome/bin/clang").getAbsolutePath() +def linker = IS_STATIC_BUILD ? file("$compilerHome/bin/llvm-ar").getAbsolutePath() : file("$compilerHome/bin/clang").getAbsolutePath() // Log the settings we're building with logger.quiet("ANDROID_SDK: $sdk") @@ -178,255 +63,145 @@ logger.quiet("Compile native text: $compileNativeText") logger.quiet("Android Compiler: $compiler") logger.quiet("Android Linker: $linker") -project(":graphics") { - - task compileDalvikLibs(type: JavaCompile, group: "Build") { - description = "Task compiles dalvik vm based libraries." - sourceCompatibility = JavaVersion.VERSION_1_6 - targetCompatibility = JavaVersion.VERSION_1_6 - options.bootClasspath = "$sdk/platforms/$sdk_target/android.jar" - classpath = files("build/classes/android") - destinationDir = file("build/classes/android") - dependencyCacheDir = file("build/dependency-cache") - source fileTree(dir: 'src/android/java').matching { include 'com/oracle/dalvik/**' } - } +//exclude from build +project(":swing") { + apply plugin: 'java' - task jarDalvikLibs(type: Jar, group: "Build", dependsOn: compileDalvikLibs) { - description = "Creates jfxdvk.jar with all dalvik based classes." - archiveName = "jfxdvk.jar" - includeEmptyDirs = false - from("build/classes/android") - include("com/oracle/dalvik/**/*") - dependsOn(compileDalvikLibs) + compileJava { + enabled = false } +} - afterEvaluate { - addNative(project, "surface", ["android"]) - addNative(project, "vmlauncher", ["android"]) - if (compileNativeText) { - addNative(project, "fontNativeFreetype", ["android"]) - } - tasks["javahAndroidVmlauncher"].dependsOn(compileDalvikLibs) - tasks["native"].dependsOn("nativeSurface", "nativeVmlauncher") - if (compileNativeText) { - tasks["native"].dependsOn("nativeFontNativeFreetype") - } +project(":fxml") { + apply plugin: 'java' - sdkAndroid { - dependsOn(jarDalvikLibs) - doLast { - def props = project.ext["ANDROID"] - copy { - from( - "${project("graphics").buildDir}/libs/vmlauncher/android/${props.library(props.vmlauncher.lib)}", - "${project("graphics").buildDir}/libs/surface/android/${props.library(props.surface.lib)}" - ) - into ("build/android-sdk/dalvik/${props.libDest}") - } - copy { - from ("${project("graphics").buildDir}/libs/${props.jfxdvklib}") - into ("build/android-sdk/dalvik/lib") - } - if (compileNativeText) { - copy { - from ("${project("graphics").buildDir}/libs/fontNativeFreetype/android") - into ("build/android-sdk/$ANDROID.libDest") - } - } - } - } + compileJava { + enabled = true } } -project(":controls") { - afterEvaluate { - task compileControlsJavaAndroid(type: JavaCompile, group: "Build", dependsOn: [":graphics:compileJava", ":controls:compileJava"]) { - description = "Task compiles controls for Android" - classpath = files("${project("base").buildDir}/classes/main", - "${project("graphics").buildDir}/classes/main", - "${project("controls").buildDir}/classes/main" - ) - destinationDir = file("${project("controls").buildDir}/classes/android") - dependencyCacheDir = file("${project("controls").buildDir}/dependency-cache") - source file("${project("controls").projectDir}/src/android/java") - } +allprojects() { + repositories { + mavenCentral() + } +} - task processControlsResourcesAndroid() { - copy { - from ("${project("controls").projectDir}/src/android/resources") - into ("${project("controls").buildDir}/resources/android") - } - } - sdkAndroid { - dependsOn(compileControlsJavaAndroid, processControlsResourcesAndroid) - } - } +project(":base") { + apply plugin: 'java' } project(":web") { + +} + +project(":graphics") { + apply plugin: 'java' - compileJava { - enabled = false + sourceSets.main.java { + exclude "com/sun/glass/ui/swt/**" } afterEvaluate { - if (!BUILD_CLOSED) { - logger.warn("OpenJFX build. Skipping webkit build on Android.") - return + if (compileNativeText) { + addNative(project, "fontNativeFreetype") } - def compileWebJavaAndroid = task("compileWebJavaAndroid", - type: JavaCompile, group: "Build") { - - dependsOn(project(":graphics").classes, project(":base").classes) - description = "Task compiles web component for Android." - classpath = files( - project(":controls").sourceSets.main.java.outputDir, - project(":graphics").sourceSets.main.java.outputDir, - project(":base").sourceSets.main.java.outputDir - ) - destinationDir = file("${project("web").buildDir}/classes/android") - dependencyCacheDir = file("${project("web").buildDir}/dependency-cache") - source file("${project("web").projectDir}/src/android/java") + if (compileNativeText) { + tasks["native"].dependsOn("nativeFontNativeFreetype") } + tasks["ccAndroidPrismSW"].enabled = false; + tasks["linkAndroidPrismSW"].enabled = false; - def jarWebJavaAndroid = task("jarWebJavaAndroid", - type: Jar, group: "Build") { - description = "Creates web.jar for Android." - dependsOn(compileWebJavaAndroid) - archiveName = "web.jar" - includeEmptyDirs = false - destinationDir = project.file("build/libs/android") - from("build/classes/android") - } + } +} - addNative(project, "webview", ["android"]) - addNative(project, "dvkwebview", ["android"]) - javahAndroidWebview.dependsOn(compileWebJavaAndroid) - javahAndroidDvkwebview.dependsOn(compileWebJavaAndroid) +project(":controls") { - jfxrtAndroid { - from "${project("web").buildDir}/classes/android" - } + apply plugin: 'java' - sdkAndroid { - dependsOn(jarWebJavaAndroid) - doLast { - def props = project.ext["ANDROID"] - copy { - from( - "${project("web").buildDir}/libs/dvkwebview/android/${props.library(props.dvkwebview.lib)}" - ) - into ("build/android-sdk/dalvik/${props.libDest}") - } - copy { - from ("${project("web").buildDir}/libs/webview/android/${props.library(props.webview.lib)}") - into ("build/android-sdk/${props.libDest}") - } - } + task copyResources() { + copy { + from ("src/android/resources") + into ("build/classes/java/main/javafx.controls") } } -} + assemble.dependsOn("copyResources"); + +} ANDROID.jfxrtJarExcludes = [ "**/*.hlsl", "com/sun/glass/ui/win", - "com/sun/prism/d3d", - "com/sun/prism/es2/gl/win", - "com/sun/prism/null3d", - "com/sun/scenario/effect/impl/hw/d3d", - "com/sun/glass/events/mac", - "com/sun/glass/ui/mac", - "com/sun/prism/es2/gl/mac", - "com/sun/glass/ui/gtk", + "com/sun/glass/ui/accessible/win", + "com/sun/prism/j2d", + "com/sun/prism/sw", + "com/sun/glass/ui/accessible/mac", "com/sun/glass/ui/ios", - "com/sun/prism/es2/gl/eglx11", - "com/sun/prism/es2/gl/x11", "com/sun/glass/ui/swt", // SWT glass - "javafx/embed/swing", // Swing Interop - "javafx/embed/swt", // SWT Interop - "com/oracle/dalvik" + "com/oracle/dalvik", + // "javafx/scene/media", //exclude all media for now + // "com/sun/media", + // "com/sun/javafx/media", + "com/sun/javafx/font/directwrite", //exclude non freetype font support + "com/sun/javafx/font/coretext", + // "com/sun/javafx/font/freetype/Pango*", + // "com/sun/javafx/font/freetype/OSPango*", + // "com/sun/webkit", //exclude all WebView for now + // "com/sun/javafx/webkit", + // "com/sun/javafx/scene/web", + // "javafx/scene/web", + // "com/sun/javafx/sg/prism/NGWeb*", + // "com/sun/javafx/sg/prism/web*", + "javafx/print", //exclude printing + "com/sun/javafx/print", + "com/sun/javafx/tk/Print*" ] def text = (compileNativeText) ? "native" : "" ANDROID.javafxPlatformProperties = """ javafx.platform=android -android.glass.platform=Lens -android.glass.lens=eglfb +android.javax.xml.stream.XMLInputFactory=com.sun.xml.stream.ZephyrParserFactory +android.javax.xml.stream.XMLOutputFactory=com.sun.xml.stream.ZephyrWriterFactory +android.javax.xml.stream.XMLEventFactory=com.sun.xml.stream.events.ZephyrEventFactory +android.glass.platform=Monocle +android.prism.verbose=true +ANDROID.prism.verbose=true android.prism.glDepthSize=16 android.prism.lcdtext=false android.prism.debugfonts=true android.prism.text=$text -android.embedded=eglfb -android.prism.allowhidpi=false +android.embedded=monocle +android.prism.allowhidpi=true android.prism.maxTextureSize=2048 android.prism.dirtyopts=true android.prism.vsync=false -android.log.lens=FINE android.use.egl=true android.com.sun.javafx.isEmbedded=true +com.sun.javafx.gestures.zoom=true +com.sun.javafx.gestures.rotate=true +com.sun.javafx.gestures.scroll=true """ def sysroot = "$ndk/platforms/$ndk_target/arch-arm" -def ccFlags = ["--sysroot=$sysroot","-std=c99", "-DANDROID", "-c", "-nostdlib", - "-DANDROID_NDK"] - -if (project.hasProperty("DALVIK_VM")) { - ccFlags += ["-DDALVIK_VM"] +def ccFlags = ["-target",platform, "-c", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-DANDROID_NDK", "-DANDROID_VM"] +if ( IS_STATIC_BUILD ) { + ccFlags += "-DSTATIC_BUILD" } -def ccOptFlags = ["-fpic", "-ffunction-sections", "-funwind-tables","-fstack-protector", - "-Os", "-O2", "-fno-strict-aliasing", "-finline-limit=64", "-fomit-frame-pointer"] -def ccWarnFlags = ["-Wa,--noexecstack", "-Wno-psabi"] -def ccArchFlags = ["-mthumb", "-msoft-float", "-D__ARM_ARCH_5__", "-D__ARM_ARCH_5T__", "-D__ARM_ARCH_5E__", - "-D__ARM_ARCH_5TE__", "-march=armv5te" , "-mtune=xscale"] + +def ccOptFlags = ["-fPIC", "-ffunction-sections", "-funwind-tables","-fstack-protector", + "-Os", "-O2", "-fno-strict-aliasing", "-fomit-frame-pointer"] +def ccWarnFlags = ["-Wa,--noexecstack"] +def ccArchFlags = [] def ccDebugFlags = [IS_DEBUG_NATIVE ? "-DDEBUG" : "-DNDEBUG"] def ccDefaultIncludeFlags = ["-I$ndk/platforms/$ndk_target/arch-arm/usr/include"] -def linkFlags = ["--sysroot=$sysroot", +def linkFlags = IS_STATIC_BUILD ? [] : ["-target", platform, "-Wl,--no-undefined", "-Wl,-z,noexecstack", "-lc", "-lm", "-shared", - "-L$ndk/platforms/$ndk_target/arch-arm/usr/lib"] - - -ANDROID.vmlauncher = [:] -ANDROID.vmlauncher.classpath = files("$sdk/platforms/$sdk_target/android.jar", - "${project("graphics").buildDir}/classes/android") - -ANDROID.vmlauncher.javahSource = files("${project("graphics").buildDir}/classes/android") -ANDROID.vmlauncher.javahClasspath = files("${project("graphics").buildDir}/classes/android", - "$sdk/platforms/$sdk_target/android.jar") -ANDROID.vmlauncher.javahInclude = [ - "com/oracle/dalvik/*" -] -ANDROID.vmlauncher.nativeSource = [ - file("${project("graphics").projectDir}/src/android/native/VMLauncher.c"), - file("${project("graphics").projectDir}/src/android/native/NativePipeReader.c"), - file("${project("graphics").projectDir}/src/android/native/DalvikProxySelector.c") -] -ANDROID.vmlauncher.compiler = compiler -ANDROID.vmlauncher.linker = linker -ANDROID.vmlauncher.lib = "vmlauncher" -ANDROID.vmlauncher.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, - ccDebugFlags, ccDefaultIncludeFlags].flatten() -ANDROID.vmlauncher.linkFlags = [linkFlags, "-llog"].flatten() - -ANDROID.surface = [:] -ANDROID.surface.javahInclude = [ - "com/sun/glass/events/*", - "com/sun/glass/ui/android/*" -] -ANDROID.surface.nativeSource = [ - file("${project("graphics").projectDir}/src/main/native-glass/lens/android") -] -ANDROID.surface.compiler = compiler -ANDROID.surface.linker = linker -ANDROID.surface.lib = "glass_lens_android" -ANDROID.surface.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, - ccDebugFlags, ccDefaultIncludeFlags, "-Isrc/main/native-glass/lens"].flatten() -ANDROID.surface.linkFlags = [linkFlags, "-ldl", "-landroid", "-llog"].flatten() + "-L$ndk/platforms/$ndk_target/arch-arm/usr/lib", "-landroid", "-llog"] ANDROID.webview = [:] ANDROID.webview.javahSource = files("${project("web").buildDir}/classes/android") @@ -435,14 +210,15 @@ ANDROID.webview.javahInclude = [ "com/sun/webkit/NativeWebView.class" ] ANDROID.webview.nativeSource = [ - file("${project("web").projectDir}/src/android/native/native_webview.c") + files("${project("web").projectDir}/src/android/native/native_webview.c", +"${project("web").projectDir}/src/android/native/android_webview.c") ] ANDROID.webview.compiler = compiler ANDROID.webview.linker = linker ANDROID.webview.lib = "webview" ANDROID.webview.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, ccDebugFlags, ccDefaultIncludeFlags].flatten() -ANDROID.webview.linkFlags = [linkFlags, "-ldl", "-llog"].flatten() +ANDROID.webview.linkFlags = IS_STATIC_BUILD ? [linkFlags].flatten() : [linkFlags, "-ldl", "-llog"].flatten() ANDROID.dvkwebview = [:] ANDROID.dvkwebview.javahSource = files("${project("web").buildDir}/classes/android") @@ -458,44 +234,63 @@ ANDROID.dvkwebview.linker = linker ANDROID.dvkwebview.lib = "android_webview" ANDROID.dvkwebview.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, ccDebugFlags, ccDefaultIncludeFlags].flatten() -ANDROID.dvkwebview.linkFlags = [linkFlags, "-ldl", "-llog"].flatten() +ANDROID.dvkwebview.linkFlags = IS_STATIC_BUILD ? [linkFlags].flatten() : [linkFlags, "-ldl", "-llog"].flatten() ANDROID.glass = [:] -ANDROID.glass.variants = ["eglfb", "lensport"] +ANDROID.glass.variants = [] +ANDROID.glass.variants = ["monocle"] +ANDROID.glass.javahSource = files("${project("graphics").buildDir}/classes/dalvik", + "${project("graphics").buildDir}/classes/main") +ANDROID.glass.javahClasspath = files("${project("graphics").buildDir}/classes/main", + "${project("graphics").buildDir}/classes/dalvik", + "${project("base").buildDir}/classes/main", + "$sdk/platforms/$sdk_target/android.jar") ANDROID.glass.javahInclude = [ + "javafxports/android/**", + "com/sun/glass/ui/monocle/*", + "com/sun/glass/ui/monocle/util/*", "com/sun/glass/events/**", "com/sun/glass/ui/*", "com/sun/glass/ui/android/*", "com/sun/glass/ui/lens/*"] -ANDROID.glass.lensport = [:] -ANDROID.glass.lensport.nativeSource = [ - file("${project("graphics").projectDir}/src/main/native-glass/lens/lensport"), - file("${project("graphics").projectDir}/src/main/native-glass/lens/lensport/initPlatform.c"), - file("${project("graphics").projectDir}/src/main/native-glass/lens/lensport/wrapped_functions.c") -] -ANDROID.glass.lensport.compiler = compiler -ANDROID.glass.lensport.linker = linker -ANDROID.glass.lensport.lib = "lens_porting" -ANDROID.glass.lensport.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, - ccDebugFlags, ccDefaultIncludeFlags, "-DISEGLFB", "-DLENSPORT", - "-I", file("${project("graphics").projectDir}/src/main/native-glass/lens")].flatten() -ANDROID.glass.lensport.linkFlags = [linkFlags, "-ldl", "-llog"].flatten() - -ANDROID.glass.eglfb = [:] -ANDROID.glass.eglfb.nativeSource = [ - file("${project("graphics").projectDir}/src/main/native-glass/lens"), - file("${project("graphics").projectDir}/src/main/native-glass/lens/wm"), - file("${project("graphics").projectDir}/src/main/native-glass/lens/cursor/nullCursor"), - file("${project("graphics").projectDir}/src/main/native-glass/lens/input/android"), - file("${project("graphics").projectDir}/src/main/native-glass/lens/wm/screen/androidScreen.c") -] -ANDROID.glass.eglfb.compiler = compiler -ANDROID.glass.eglfb.linker = linker -ANDROID.glass.eglfb.lib = "glass_lens_eglfb" -ANDROID.glass.eglfb.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, - ccDebugFlags, ccDefaultIncludeFlags].flatten() -ANDROID.glass.eglfb.linkFlags = [linkFlags, "-ldl", "-landroid", "-llog"].flatten() + +def monocleCFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, + ccDebugFlags, ccDefaultIncludeFlags, "-DISEGLFB", + "-I", file("${project("graphics").projectDir}/src/main/native-glass/monocle/"), + "-I", file("${project("graphics").projectDir}/src/dalvik/native/") +].flatten() + +ANDROID.glass.monocle = [:] +ANDROID.glass.monocle.nativeSource = [ + file("${project("graphics").projectDir}/src/main/native-glass/monocle"), + file("${project("graphics").projectDir}/src/main/native-glass/monocle/android"), + file("${project("graphics").projectDir}/src/main/native-glass/monocle/util") ] +ANDROID.glass.monocle.compiler = compiler +ANDROID.glass.monocle.ccFlags = monocleCFlags +ANDROID.glass.monocle.linker = linker +ANDROID.glass.monocle.linkFlags = IS_STATIC_BUILD ? [linkFlags].flatten() : [linkFlags, "-ldl", "-llog", "-landroid", "-lGLESv2", "-lEGL"].flatten() + +ANDROID.glass.monocle.lib = "glass_monocle" + +ANDROID.javafxPlatformDefault="glass" + +def monoclePlatformAdditions = """ +monocle.glass.platform=Monocle +monocle.prism.order=es2,sw +monocle.prism.lcdtext=false +monocle.prism.maxvram=128m +monocle.prism.targetvram=112m +monocle.use.egl=true +monocle.use.gles2=true +monocle.embedded=monocle +monocle.com.sun.javafx.isEmbedded=true +monocle.doNativeComposite=true +monocle.com.sun.javafx.scene.control.skin.FXVK.cache=true +monocle.prism.glDepthSize=0 +monocle.com.sun.javafx.gestures.zoom=true +monocle.com.sun.javafx.gestures.rotate=true +monocle.com.sun.javafx.gestures.scroll=true""" ANDROID.prism = [:] ANDROID.prism.javahInclude = ["com/sun/prism/impl/**/*", "com/sun/prism/PresentableState*"] @@ -538,20 +333,22 @@ ANDROID.iio.linkFlags = [linkFlags].flatten() ANDROID.iio.lib = "javafx_iio" ANDROID.prismES2 = [:] -ANDROID.prismES2.variants = ["eglfb"] +ANDROID.prismES2.variants = ["monocle"] ANDROID.prismES2.javahInclude = ["com/sun/prism/es2/**/*"] -ANDROID.prismES2.eglfb = [:] -ANDROID.prismES2.eglfb.nativeSource = [ +ANDROID.prismES2.monocle= [:] +ANDROID.prismES2.monocle.nativeSource = [ file("${project("graphics").projectDir}/src/main/native-prism-es2"), file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"), - file("${project("graphics").projectDir}/src/main/native-prism-es2/eglfb")] -ANDROID.prismES2.eglfb.compiler = compiler -ANDROID.prismES2.eglfb.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, + file("${project("graphics").projectDir}/src/main/native-prism-es2/eglWrapper"), + file("${project("graphics").projectDir}/src/main/native-prism-es2/monocle") +] +ANDROID.prismES2.monocle.compiler = compiler +ANDROID.prismES2.monocle.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, ccDebugFlags, ccDefaultIncludeFlags, "-DIS_EGLFB"].flatten() -ANDROID.prismES2.eglfb.linker = linker -ANDROID.prismES2.eglfb.linkFlags = [linkFlags, "-ldl", "-llog", "-lGLESv2", "-lEGL"].flatten() -ANDROID.prismES2.eglfb.lib = "prism_es2_eglfb" +ANDROID.prismES2.monocle.linker = linker +ANDROID.prismES2.monocle.linkFlags = IS_STATIC_BUILD ? [linkFlags].flatten() : [linkFlags, "-ldl", "-llog", "-lGLESv2", "-lEGL"].flatten() +ANDROID.prismES2.monocle.lib = "prism_es2_monocle" ANDROID.font = [:] ANDROID.font.javahInclude = [ @@ -585,11 +382,10 @@ if (compileNativeText) { "-I$freetypeDir/include", "-I$freetypeDir/include/freetype2"].flatten() ANDROID.fontNativeFreetype.linkFlags = +IS_STATIC_BUILD ? [linkFlags].flatten() : [linkFlags, "-llog", "-L$freetypeDir/lib", "$freetypeDir/lib/libfreetype.a"].flatten() } ANDROID.media = [:] -ANDROID.media.compiler = compiler -ANDROID.media.linker = linker -ANDROID.media.lib = file("$compilerHome/bin/${toolchainArchs[0]}-ar").getAbsolutePath() +ext.IS_COMPILE_PANGO = false diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/android/DalvikInput.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/android/DalvikInput.java index 4a81f7fb67e..7f91df83065 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/android/DalvikInput.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/android/DalvikInput.java @@ -28,6 +28,7 @@ import javafx.scene.Node; public class DalvikInput { +/* public static void onMultiTouchEvent(final int count, final int[] actions, final int[] ids, final int[] touchXs, final int[] touchYs) { @@ -71,4 +72,5 @@ public static void setActiveNode (Node n) { public static native void onSurfaceRedrawNeededNative(); public static native void onConfigurationChangedNative(int flag); +*/ } diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDeviceRegistry.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDeviceRegistry.java index 216746e80bb..442f7a7b716 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDeviceRegistry.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDeviceRegistry.java @@ -59,7 +59,7 @@ public static void gotTouchEventFromNative(int count, int[] actions, int[] ids, touchState.addPoint(p); } } - instance.gotTouchEvent(touchState); + Platform.runLater(() -> instance.gotTouchEvent(touchState)); } private void gotTouchEvent(TouchState touchState) { diff --git a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java index b45422f6ce3..31765d9925f 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java +++ b/modules/javafx.graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java @@ -225,9 +225,8 @@ protected Screen[] staticScreen_getScreens() { 0, 0, ns.getWidth(), ns.getHeight(), 0, 0, ns.getWidth(), ns.getHeight(), 0, 0, ns.getWidth(), ns.getHeight(), - ns.getDPI(), ns.getDPI(), - ns.getScale(), ns.getScale(), - ns.getScale(), ns.getScale()); + ns.getWidth(), ns.getHeight(), + 1.f, 1.f, ns.getScale(), ns.getScale()); // Move the cursor to the middle of the screen MouseState mouseState = new MouseState(); mouseState.setX(ns.getWidth() / 2); diff --git a/modules/javafx.graphics/src/main/native-glass/monocle/EGL.c b/modules/javafx.graphics/src/main/native-glass/monocle/EGL.c index 495b8fc769d..1265f90c22f 100644 --- a/modules/javafx.graphics/src/main/native-glass/monocle/EGL.c +++ b/modules/javafx.graphics/src/main/native-glass/monocle/EGL.c @@ -30,6 +30,22 @@ #include +//Builtin library entrypoint +JNIEXPORT jint JNICALL +JNI_OnLoad_glass_monocle(JavaVM *vm, void * reserved) { +fprintf(stderr, "In JNI_OnLoad_glass)monocle\n"); +#ifdef JNI_VERSION_1_8 + //min. returned JNI_VERSION required by JDK8 for builtin libraries + JNIEnv *env; + if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) { + return JNI_VERSION_1_4; + } + return JNI_VERSION_1_8; +#else + return JNI_VERSION_1_4; +#endif +} + void setEGLAttrs(jint *attrs, int *eglAttrs) { int index = 0; diff --git a/modules/javafx.graphics/src/main/native-glass/monocle/android/AndroidScreen.c b/modules/javafx.graphics/src/main/native-glass/monocle/android/AndroidScreen.c index f6fa21458e7..68e326e4612 100644 --- a/modules/javafx.graphics/src/main/native-glass/monocle/android/AndroidScreen.c +++ b/modules/javafx.graphics/src/main/native-glass/monocle/android/AndroidScreen.c @@ -24,11 +24,9 @@ */ #include -// #include "activity.h" -#include "dalvikInput.h" +#include "nativeBridge.h" #include "com_sun_glass_ui_monocle_AndroidScreen.h" #include "Monocle.h" -#include "logging.h" /* @@ -69,7 +67,7 @@ JNIEXPORT jint JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getHeight JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getNativeHandle (JNIEnv *env, jobject obj) { ANativeWindow* androidWindow = android_getNativeWindow(env); - return androidWindow; + return (jlong)androidWindow; } /* @@ -79,9 +77,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getNativeH */ JNIEXPORT jfloat JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getDensity (JNIEnv *env, jobject obj) { - jfloat answer = android_getDensity(); -LOGI("DENSITY", "GETDENSITY, answer = %f\n",answer); - return answer; + return android_getDensity(env); } diff --git a/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikInput.c b/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikInput.c deleted file mode 100644 index 3619b3ae7df..00000000000 --- a/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikInput.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. - * 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. - */ - -#include -#include -#include "dalvikInput.h" -#include "dalvikUtils.h" -#include "com_sun_glass_events_TouchEvent.h" -#include "com_sun_glass_ui_android_SoftwareKeyboard.h" -#include "com_sun_glass_ui_android_Activity.h" -#include "javafxports_android_FXDalvikEntity_InternalSurfaceView.h" -#include "com_sun_glass_ui_android_DalvikInput.h" - -#define asPtr(x) ((void *) (unsigned long) (x)) -#define asJLong(x) ((jlong) (unsigned long) (x)) - - -#define THROW_RUNTIME_EXCEPTION(ENV, MESSAGE, ...) \ - char error_msg[256]; \ - sprintf(error_msg, MESSAGE, __VA_ARGS__); \ - if (env) { \ - (*ENV)->ThrowNew(ENV, \ - (*ENV)->FindClass(ENV, "java/lang/RuntimeException"), error_msg); \ - } - -#ifdef DEBUG - static void *get_check_symbol(JNIEnv *env, void *handle, const char *name) { - void *ret = dlsym(handle, name); - if (!ret) { - THROW_RUNTIME_EXCEPTION(env, "Failed to load symbol %s", name); - } - return ret; - } - #define GET_SYMBOL(env, handle,name) get_check_symbol(env, handle,name) -#else // #ifdef DEBUG - #define GET_SYMBOL(env, handle,name) dlsym(handle,name) -#endif -#define GLASS_LOG_FINE(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) -#define GLASS_LOG_FINEST(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) -#define GLASS_LOG_WARNING(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) - -#define ANDROID_LIB "libactivity.so" - -static int bind = 0; - -static ANativeWindow *(*_ANDROID_getNativeWindow)(); -static jfloat *(*_ANDROID_getDensity)(); -static char *(*_ANDROID_getDataDir)(); -static void *(*_ANDROID_notifyGlassStarted)(); -static void *(*_ANDROID_notifyGlassShutdown)(); -static void *(*_ANDROID_notifyShowIME)(); -static void *(*_ANDROID_notifyHideIME)(); -static jclass jAndroidInputDeviceRegistryClass; -static jclass jMonocleWindowManagerClass; - -static jmethodID monocle_gotTouchEventFromNative; -static jmethodID monocle_gotKeyEventFromNative; -static jmethodID monocle_repaintAll; - -void bind_activity(JNIEnv *env) { - GLASS_LOG_FINEST("Binding to %s", ANDROID_LIB); - void *libandroid = dlopen(ANDROID_LIB, RTLD_LAZY | RTLD_GLOBAL); - if (!libandroid) { - THROW_RUNTIME_EXCEPTION(env, "dlopen failed with error: ", dlerror()); - return; - } - - _ANDROID_getNativeWindow = GET_SYMBOL(env, libandroid, "android_getNativeWindow"); - _ANDROID_getDensity = GET_SYMBOL(env, libandroid, "android_getDensity"); - _ANDROID_getDataDir = GET_SYMBOL(env, libandroid, "android_getDataDir"); - _ANDROID_notifyGlassStarted = GET_SYMBOL(env, libandroid, "android_notifyGlassStarted"); - _ANDROID_notifyGlassShutdown = GET_SYMBOL(env, libandroid, "android_notifyGlassShutdown"); - _ANDROID_notifyShowIME = GET_SYMBOL(env, libandroid, "android_notifyShowIME"); - _ANDROID_notifyHideIME = GET_SYMBOL(env, libandroid, "android_notifyHideIME"); -GLASS_LOG_FINEST("GetNativeWindow = %p, getDensitiy = %p",_ANDROID_getNativeWindow, _ANDROID_getDensity ); - bind = JNI_TRUE; - (*_ANDROID_notifyGlassStarted)(); - jAndroidInputDeviceRegistryClass = (*env)->NewGlobalRef(env, - (*env)->FindClass(env, "com/sun/glass/ui/monocle/AndroidInputDeviceRegistry")); - monocle_gotTouchEventFromNative = (*env)->GetStaticMethodID( - env, jAndroidInputDeviceRegistryClass, "gotTouchEventFromNative", - "(I[I[I[I[II)V"); - monocle_gotKeyEventFromNative = (*env)->GetStaticMethodID( - env, jAndroidInputDeviceRegistryClass, "gotKeyEventFromNative", - "(II)V"); - jMonocleWindowManagerClass = (*env)->NewGlobalRef(env, - (*env)->FindClass(env, "com/sun/glass/ui/monocle/MonocleWindowManager")); - monocle_repaintAll = (*env)->GetStaticMethodID( - env, jMonocleWindowManagerClass, "repaintFromNative", - "()V"); - -} - -ANativeWindow *android_getNativeWindow(JNIEnv *env) { - if(!bind) bind_activity(env); - return (*_ANDROID_getNativeWindow)(); -} - -jfloat android_getDensity(JNIEnv *env) { - if(!bind) bind_activity(env); - jfloat* answer = (*_ANDROID_getDensity)(); - return *answer; -} - -const char *android_getDataDir(JNIEnv *env) { - if(!bind) bind_activity(env); - return (*_ANDROID_getDataDir)(); -} - -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_SoftwareKeyboard__1show -(JNIEnv *env, jclass clazz) { - if(!bind) bind_activity(env); - (*_ANDROID_notifyShowIME)(); -} - -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_SoftwareKeyboard__1hide -(JNIEnv *env, jclass clazz) { - if(!bind) bind_activity(env); - (*_ANDROID_notifyHideIME)(); -} - -/* - * Class: javafxports_android_FXActivity_InternalSurfaceView - * Class: com_sun_glass_ui_android_DalvikInput - * Method: onMultiTouchEventNative - * Signature: (I[I[I[I[I)V - */ -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_DalvikInput_onMultiTouchEventNative - (JNIEnv *env, jobject that, jint jcount, jintArray jactions, jintArray jids, jintArray jxs, jintArray jys) { - GLASS_LOG_FINE("Call InternalSurfaceView_onMultiTouchEventNative"); - - jlong jlongids[jcount]; - int count = jcount; - - int *actions = (*env)->GetIntArrayElements(env, jactions, 0); - int *ids = (*env)->GetIntArrayElements(env, jids, 0); - int *xs = (*env)->GetIntArrayElements(env, jxs, 0); - int *ys = (*env)->GetIntArrayElements(env, jys, 0); - int primary = 0; - for(int i=0;iCallStaticVoidMethod(env, jAndroidInputDeviceRegistryClass, monocle_gotTouchEventFromNative, - jcount, jactions, jids, jxs, jys, primary); - - (*env)->ReleaseIntArrayElements(env, jactions, actions, 0); - (*env)->ReleaseIntArrayElements(env, jids, ids, 0); - (*env)->ReleaseIntArrayElements(env, jxs, xs, 0); - (*env)->ReleaseIntArrayElements(env, jys, ys, 0); -} - - -/* - * Class: com_sun_glass_ui_android_DalvikInput - * Method: onKeyEventNative - * Signature: (IILjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_DalvikInput_onKeyEventNative - (JNIEnv *env, jobject that, jint action, jint keycode, jstring s) { - int linux_keycode = to_linux_keycode(keycode); - (*env)->CallStaticVoidMethod(env, jAndroidInputDeviceRegistryClass, monocle_gotKeyEventFromNative, - action,linux_keycode); - -} - -/* - * Class: com_sun_glass_ui_android_DalvikInput - * Method: onSurfaceChangedNative - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_DalvikInput_onSurfaceChangedNative__ - (JNIEnv *env, jclass that) { - GLASS_LOG_FINEST("Native code is notified that surface has changed (repaintall)!"); - (*env)->CallStaticVoidMethod(env, jMonocleWindowManagerClass, monocle_repaintAll); -} - -/* - * Class: com_sun_glass_ui_android_DalvikInput - * Method: onSurfaceChangedNative - * Signature: (III)V - */ -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_DalvikInput_onSurfaceChangedNative__III - (JNIEnv *env, jclass that, jint i1, jint i2, jint i3) { - GLASS_LOG_FINEST("Native code is notified that surface has changed with size provided (repaintall)!"); - (*env)->CallStaticVoidMethod(env, jMonocleWindowManagerClass, monocle_repaintAll); -} - -/* - * Class: com_sun_glass_ui_android_DalvikInput - * Method: onSurfaceRedrawNeededNative - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_DalvikInput_onSurfaceRedrawNeededNative - (JNIEnv *env, jclass that) { - GLASS_LOG_WARNING("Call surfaceRedrawNeeded"); - GLASS_LOG_FINEST("Native code is notified that surface needs to be redrawn (repaintall)!"); - (*env)->CallStaticVoidMethod(env, jMonocleWindowManagerClass, monocle_repaintAll); -} - -/* - * Class: com_sun_glass_ui_android_DalvikInput - * Method: onConfigurationChangedNative - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_DalvikInput_onConfigurationChangedNative - (JNIEnv *env, jclass that, jint flags) { - GLASS_LOG_FINEST("Call configuration changed."); -} - - -JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_LinuxSystem_dlopen - (JNIEnv *env, jobject UNUSED(obj), jstring filenameS, jint flag) { - const char *filename = (*env)->GetStringUTFChars(env, filenameS, NULL); - GLASS_LOG_FINE("I have to Call dlopen %s\n",filename); - void *handle = dlopen(filename, RTLD_LAZY | RTLD_GLOBAL); - GLASS_LOG_FINE("handle = %p\n",handle); - (*env)->ReleaseStringUTFChars(env, filenameS, filename); - return asJLong(handle); -} - diff --git a/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikUtils.c b/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikUtils.c index 276db82ab42..c510a94adec 100644 --- a/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikUtils.c +++ b/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikUtils.c @@ -23,7 +23,7 @@ * questions. */ -#if (defined(ANDROID_NDK) && defined(DALVIK_VM)) +#if defined(ANDROID_NDK) #include #include "dalvikConst.h" @@ -60,6 +60,7 @@ int to_jfx_key_action(int action) { case KEY_ACTION_MULTIPLE: return com_sun_glass_events_KeyEvent_TYPED; } + return -1; } int to_linux_keycode(int androidKeyCode) { @@ -120,6 +121,7 @@ char *describe_key_action(int action) { case KEY_ACTION_MULTIPLE: return "KEY_ACTION_MULTIPLE"; } + return "UNKNOWN"; } #endif diff --git a/modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.c b/modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.c new file mode 100644 index 00000000000..20456399788 --- /dev/null +++ b/modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.c @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * 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. + */ + +#include +#include +#include "nativeBridge.h" +#include "Monocle.h" + +JNIEnv* javaEnv = NULL; +JavaVM *jVM = NULL; + +static jclass jAndroidInputDeviceRegistryClass; +static jclass jMonocleWindowManagerClass; + +static jmethodID monocle_gotTouchEventFromNative; +static jmethodID monocle_gotKeyEventFromNative; +static jmethodID monocle_repaintAll; +static jmethodID monocle_registerDevice; + +ANativeWindow* androidWindow = NULL; +jfloat androidDensity = 0.f; +static int deviceRegistered = 0; + +void initializeFromJava (JNIEnv *env) { + if (jVM != NULL) return; // already have a jVM + (*env)->GetJavaVM(env, &jVM); + GLASS_LOG_FINE("Initializing native Android Bridge from Java code"); + jMonocleWindowManagerClass = (*env)->NewGlobalRef(env, + (*env)->FindClass(env, "com/sun/glass/ui/monocle/MonocleWindowManager")); + jAndroidInputDeviceRegistryClass = (*env)->NewGlobalRef(env, + (*env)->FindClass(env, "com/sun/glass/ui/monocle/AndroidInputDeviceRegistry")); + monocle_repaintAll = (*env)->GetStaticMethodID( + env, jMonocleWindowManagerClass, "repaintFromNative", + "()V"); + monocle_gotTouchEventFromNative = (*env)->GetStaticMethodID( + env, jAndroidInputDeviceRegistryClass, "gotTouchEventFromNative", + "(I[I[I[I[II)V"); + monocle_gotKeyEventFromNative = (*env)->GetStaticMethodID( + env, jAndroidInputDeviceRegistryClass, "gotKeyEventFromNative", + "(II)V"); + monocle_registerDevice = (*env)->GetStaticMethodID(env, jAndroidInputDeviceRegistryClass, "registerDevice","()V"); + GLASS_LOG_FINE("Initializing native Android Bridge done"); +} + +void initializeFromNative () { + if (javaEnv != NULL) return; // already have a JNIEnv + if (jVM == NULL) { + GLASS_LOG_FINE("initialize from native can't be done without JVM"); + return; // can't initialize from native before we have a jVM + } + GLASS_LOG_FINE("Initializing native Android Bridge from Android/native code"); + jint error = (*jVM)->AttachCurrentThread(jVM, (void **)&javaEnv, NULL); + if (error != 0) { + GLASS_LOG_FINE("initializeFromNative failed with error %d\n", error); + } +} + +/* ===== called from native ===== */ + +void androidJfx_setNativeWindow(ANativeWindow* nativeWindow) { + initializeFromNative(); + androidWindow = nativeWindow; + GLASS_LOG_FINE("after androidSetNativeWindow asked, window is %p\n", nativeWindow); +} + +void androidJfx_setDensity(float nativeDensity) { + initializeFromNative(); + androidDensity = nativeDensity; +} + +void androidJfx_gotTouchEvent (int count, int* actions, int* ids, int* xs, int* ys, int primary) { + initializeFromNative(); + GLASS_LOG_FINE("Call InternalSurfaceView_onMultiTouchEventNative"); + if (javaEnv == NULL) { + GLASS_LOG_FINE("javaEnv still null, not ready to process touch events"); + return; + } + if (deviceRegistered == 0) { + deviceRegistered = 1; + GLASS_LOG_FINE("This is the first time we have a touch even, register device now"); + (*javaEnv)->CallStaticVoidMethod(javaEnv, jAndroidInputDeviceRegistryClass, monocle_registerDevice); + } + jint jcount = (jint)count; + jlong jlongids[jcount]; + + jintArray jactions = (*javaEnv)->NewIntArray(javaEnv, count); + (*javaEnv)->SetIntArrayRegion(javaEnv, jactions, 0, count, actions); + jintArray jids = (*javaEnv)->NewIntArray(javaEnv, count); + (*javaEnv)->SetIntArrayRegion(javaEnv, jids, 0, count, ids); + jintArray jxs = (*javaEnv)->NewIntArray(javaEnv, count); + (*javaEnv)->SetIntArrayRegion(javaEnv, jxs, 0, count, xs); + jintArray jys = (*javaEnv)->NewIntArray(javaEnv, count); + (*javaEnv)->SetIntArrayRegion(javaEnv, jys, 0, count, ys); + + (*javaEnv)->CallStaticVoidMethod(javaEnv, jAndroidInputDeviceRegistryClass, monocle_gotTouchEventFromNative, + jcount, jactions, jids, jxs, jys, primary); + +} + +void androidJfx_requestGlassToRedraw() { + GLASS_LOG_FINEST("Native code is notified that surface needs to be redrawn (repaintall)"); + if (jVM == NULL) { + GLASS_LOG_WARNING("we can't do this yet, no jVM\n"); + return; + } + if (javaEnv == NULL) { + jint error = (*jVM)->AttachCurrentThread(jVM, (void **)&javaEnv, NULL); + GLASS_LOG_WARNING("result of attach: %d\n",error); + } + if (jMonocleWindowManagerClass == NULL) { + GLASS_LOG_WARNING("we can't do this yet, no jMonocleWindowManagerClass\n"); + return; + } + if (monocle_repaintAll == NULL) { + GLASS_LOG_WARNING("we can't do this yet, no monocle_repaintAll\n"); + return; + } + (*javaEnv)->CallStaticVoidMethod(javaEnv, jMonocleWindowManagerClass, monocle_repaintAll); +} + +/* ===== called from Java ===== */ + +ANativeWindow *android_getNativeWindow(JNIEnv *env) { + initializeFromJava(env); + return androidWindow; +} + +jfloat android_getDensity(JNIEnv *env) { + initializeFromJava(env); + return androidDensity; +} + +JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_SoftwareKeyboard__1show +(JNIEnv *env, jclass clazz) { + initializeFromJava(env); +} + +JNIEXPORT void JNICALL Java_com_sun_glass_ui_android_SoftwareKeyboard__1hide +(JNIEnv *env, jclass clazz) { + initializeFromJava(env); +} + +JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_LinuxSystem_dlopen + (JNIEnv *env, jobject obj, jstring filenameS, jint flag) { + const char *filename = (*env)->GetStringUTFChars(env, filenameS, NULL); + GLASS_LOG_FINE("I have to Call dlopen %s\n",filename); + void *handle = dlopen(filename, RTLD_LAZY | RTLD_GLOBAL); + GLASS_LOG_FINE("handle = %p\n",handle); + (*env)->ReleaseStringUTFChars(env, filenameS, filename); + return asJLong(handle); +} + diff --git a/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikInput.h b/modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.h similarity index 57% rename from modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikInput.h rename to modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.h index f37079ab300..4c10242842f 100644 --- a/modules/javafx.graphics/src/main/native-glass/monocle/android/dalvikInput.h +++ b/modules/javafx.graphics/src/main/native-glass/monocle/android/nativeBridge.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -22,34 +22,21 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - -#ifndef DALVIKINPUT_H -#define DALVIKINPUT_H - -#include #include #include -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -ANativeWindow *android_getNativeWindow(JNIEnv *env); -const char *android_getDataDir(JNIEnv *env); -jfloat android_getDensity(); -#ifdef __cplusplus -} -#endif +// the following functions can be invoked by native code invoked by Android Activity code +void androidJfx_setNativeWindow(ANativeWindow* nativeWindow); +void androidJfx_setDensity(float nativeDensity); +void androidJfx_gotTouchEvent (int count, int* actions, int* ids, int* xs, int* ys, int primary); +void androidJfx_requestGlassToRedraw(); +#define GLASS_LOG_INFO(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) +#define GLASS_LOG_FINE(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) +#define GLASS_LOG_FINEST(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) +#define GLASS_LOG_WARNING(...) ((void)__android_log_print(ANDROID_LOG_INFO,"GLASS", __VA_ARGS__)) -#include -#include -#include -#include +ANativeWindow* android_getNativeWindow(JNIEnv *env); +jfloat android_getDensity(JNIEnv *env); -#include -#endif diff --git a/modules/javafx.graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c b/modules/javafx.graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c index 859b9ba3239..579263822fc 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/monocle/MonocleGLFactory.c @@ -43,6 +43,22 @@ extern void *get_dlsym(void *handle, const char *symbol, int warn); #define asPtr(x) ((void *) (unsigned long) (x)) #define asJLong(x) ((jlong) (unsigned long) (x)) +//Builtin library entrypoint +JNIEXPORT jint JNICALL +JNI_OnLoad_prism_es2_monocle(JavaVM *vm, void * reserved) { +fprintf(stderr, "In JNI_OnLoad_prism_es2\n"); +#ifdef JNI_VERSION_1_8 + //min. returned JNI_VERSION required by JDK8 for builtin libraries + JNIEnv *env; + if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_8) != JNI_OK) { + return JNI_VERSION_1_4; + } + return JNI_VERSION_1_8; +#else + return JNI_VERSION_1_4; +#endif +} + JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_MonocleGLFactory_nPopulateNativeCtxInfo (JNIEnv *env, jclass clazz, jlong libraryHandle) { ContextInfo *ctxInfo = NULL; diff --git a/modules/javafx.graphics/src/main/native-prism-es2/monocle/eglUtils.c b/modules/javafx.graphics/src/main/native-prism-es2/monocle/eglUtils.c index 118fff58d4f..59c76939231 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/monocle/eglUtils.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/monocle/eglUtils.c @@ -124,44 +124,6 @@ EGLSurface getSharedWindowSurface(EGLDisplay dpy, return sharedWindowSurface; } -void setEGLAttrs(jint *attrs, int *eglAttrs) { - int index = 0; - - eglAttrs[index++] = EGL_SURFACE_TYPE; - if (attrs[ONSCREEN] != 0) { - eglAttrs[index++] = (EGL_WINDOW_BIT); - } else { - eglAttrs[index++] = EGL_PBUFFER_BIT; - } - - // NOTE: EGL_TRANSPARENT_TYPE ? - - if (attrs[RED_SIZE] == 5 && attrs[GREEN_SIZE] == 6 - && attrs[BLUE_SIZE] == 5 && attrs[ALPHA_SIZE] == 0) { - // Optimization for Raspberry Pi model B. Even though the result - // of setting EGL_BUFFER_SIZE to 16 should be the same as setting - // component sizes separately, we get less per-frame overhead if we - // only set EGL_BUFFER_SIZE. - eglAttrs[index++] = EGL_BUFFER_SIZE; - eglAttrs[index++] = 16; - } else { - eglAttrs[index++] = EGL_RED_SIZE; - eglAttrs[index++] = attrs[RED_SIZE]; - eglAttrs[index++] = EGL_GREEN_SIZE; - eglAttrs[index++] = attrs[GREEN_SIZE]; - eglAttrs[index++] = EGL_BLUE_SIZE; - eglAttrs[index++] = attrs[BLUE_SIZE]; - eglAttrs[index++] = EGL_ALPHA_SIZE; - eglAttrs[index++] = attrs[ALPHA_SIZE]; - } - - eglAttrs[index++] = EGL_DEPTH_SIZE; - eglAttrs[index++] = attrs[DEPTH_SIZE]; - eglAttrs[index++] = EGL_RENDERABLE_TYPE; - eglAttrs[index++] = EGL_OPENGL_ES2_BIT; - eglAttrs[index] = EGL_NONE; -} - ContextInfo *eglContextFromConfig(EGLDisplay *dpy, EGLConfig config) { EGLSurface surface = getDummyWindowSurface(dpy, config);