diff -r e8beeeaa062e buildSrc/dalvik.gradle --- a/buildSrc/dalvik.gradle Fri May 08 12:39:39 2015 +0300 +++ b/buildSrc/dalvik.gradle Fri May 08 21:58:27 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -101,6 +101,7 @@ DALVIK.compileSwing = false; DALVIK.compileSWT = false; DALVIK.compileFXPackager = false; +DALVIK.compileDesignTime = false; DALVIK.glassPlatform = "android" DALVIK.armArch = armArchs[0] DALVIK.libDest = "lib/${DALVIK.armArch}" @@ -231,7 +232,7 @@ classdirs.eachDir{t -> javaexec { inputdir = t - basecp = files(lf, "modules/base/build/classes/main", "modules/graphics/build/classes/main").asPath + basecp = files(lf, "modules/base/build/classes/main", "modules/graphics/build/classes/main", "modules/controls/build/classes/main").asPath myconfig = configurations.retroconfig; lambdaloc = myconfig.resolve().toArray()[0]; classpath = configurations.retroconfig @@ -250,11 +251,81 @@ project(":base") { + apply plugin: 'java' + jar.dependsOn("retroClass"); +} +project(":web") { apply plugin: 'java' + jar.dependsOn("retroClass"); + compileJava.dependsOn(":graphics:assemble"); + sourceSets.main.java.srcDirs = ['src/android/java']; + sourceSets { + main { + java { + srcDirs= ['src/android/java'] + } + } + } + dependencies { + compile files("../graphics/build/classes/dalvik"); + } + + afterEvaluate { + sourceSets.main.java.srcDirs = ['src/android/java']; + 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.output.classesDir, + project(":graphics").sourceSets.main.output.classesDir, + project(":base").sourceSets.main.output.classesDir, + "modules/graphics/build/classes/dalvik" + ) + destinationDir = file("modules/web/build/classes/android") + dependencyCacheDir = file("modules/web/build/dependency-cache") + source file("modules/web/src/android/java") + } + + 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") + // addNative(project, "dvkwebview") + javahDalvikWebview.dependsOn(compileWebJavaAndroid) + // javahDalvikDvkwebview.dependsOn(compileWebJavaAndroid) + + jfxrtDalvik { + from "modules/web/build/classes/android" + } + + sdkDalvik { + dependsOn(jarWebJavaAndroid) + doLast { + def props = project.ext["DALVIK"] + copy { + from ("modules/web/build/libs/webview/dalvik/${props.library(props.webview.lib)}") + into ("build/dalvik-sdk/rt/${props.libDest}") + } + } + } + } + jar.dependsOn("retroClass"); +} +project(":media") { + apply plugin: 'java' + jar.dependsOn("retroClass"); } @@ -273,7 +344,7 @@ classpath = files("build/classes/dalvik", "build/classes/main") destinationDir = file("build/classes/dalvik") dependencyCacheDir = file("build/dependency-cache") - source fileTree(dir: 'src/dalvik/java').matching { include 'javafxports/**' } + source fileTree(dir: 'src/dalvik/java').matching { include '**' } } task jarDalvikLibs(type: Jar, group: "Build", dependsOn: compileDalvikLibs) { @@ -282,6 +353,7 @@ includeEmptyDirs = false from("build/classes/dalvik") include("javafxports/**/*") + include("com/oracle/**/*") dependsOn(compileDalvikLibs) } @@ -345,37 +417,35 @@ project(":controls") { apply plugin: 'java' +/* + compileJava { + options.bootClasspath="/home/johan/open-jfx/bitbucket/8u-dev-build/compat/build/libs/compat-1.0.0.jar:$sdk/platforms/$sdk_target/android.jar" + } +*/ - assemble.dependsOn("compileControlsJavaDalvik","retroClass"); + sourceSets.main.java.srcDir('src/android/java') +/* sourceSets.main.java { exclude 'javafx/scene/control/Date*.java' exclude 'com/sun/javafx/scene/control/skin/Date*.java' exclude 'com/sun/javafx/scene/control/behavior/Date*.java' } - task compileControlsJavaDalvik(type: JavaCompile, group: "Build", dependsOn: [":graphics:compileJava", ":controls:compileJava"]) << { - description = "Task compiles controls for Android" - classpath = files("modules/base/build/classes/main", - "modules/graphics/build/classes/main", - "modules/controls/build/classes/main" - ) - destinationDir = file("modules/controls/build/classes/dalvik") - dependencyCacheDir = file("modules/controls/build/dependency-cache") - source file("modules/controls/src/android/java") +*/ + task copyResources() << { + copy { + from ("src/android/resources") + into ("build/resources/dalvik") + } } + + assemble.dependsOn("copyResources","retroClass"); + afterEvaluate { - task processControlsResourcesDalvik() { - copy { - from ("modules/controls/src/android/resources") - into ("modules/controls/build/resources/dalvik") - } - } - jfxrtDalvik { from ("modules/controls/build/classes/dalvik", "modules/controls/build/resources/dalvik") - dependsOn(compileControlsJavaDalvik, processControlsResourcesDalvik) } } @@ -403,18 +473,19 @@ "com/sun/glass/ui/ios", "com/sun/glass/ui/swt", // SWT glass "com/oracle/dalvik", - "javafx/scene/media", //exclude all media for now - "com/sun/media", - "com/sun/javafx/media", + // "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/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*" @@ -424,20 +495,28 @@ DALVIK.javafxPlatformProperties = """ javafx.platform=android +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.glass.lens=eglfb android.log.lens=FINEST +android.prism.verbose=true +DALVIK.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.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" @@ -469,13 +548,14 @@ DALVIK.activity.linkFlags = [linkFlags, "-landroid", "-llog"].flatten() DALVIK.webview = [:] -DALVIK.webview.javahSource = files("modules/web/build/classes/dalvik") -DALVIK.webview.javahClasspath = files("modules/web/build/classes/dalvik") +DALVIK.webview.javahSource = files("modules/web/build/classes/android") +DALVIK.webview.javahClasspath = files("modules/web/build/classes/android") DALVIK.webview.javahInclude = [ "com/sun/webkit/NativeWebView.class" ] DALVIK.webview.nativeSource = [ - file("modules/web/src/android/native/native_webview.c") + files("modules/web/src/android/native/native_webview.c", +"modules/web/src/android/native/android_webview.c") ] DALVIK.webview.compiler = compiler DALVIK.webview.linker = linker @@ -485,8 +565,8 @@ DALVIK.webview.linkFlags = [linkFlags, "-ldl", "-llog"].flatten() DALVIK.dvkwebview = [:] -DALVIK.dvkwebview.javahSource = files("modules/web/build/classes/dalvik") -DALVIK.dvkwebview.javahClasspath = files("modules/web/build/classes/dalvik") +DALVIK.dvkwebview.javahSource = files("modules/web/build/classes/android") +DALVIK.dvkwebview.javahClasspath = files("modules/web/build/classes/android") DALVIK.dvkwebview.javahInclude = [ "com/sun/webkit/NativeWebView.class" ] @@ -534,7 +614,8 @@ def monocleCFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, ccDebugFlags, ccDefaultIncludeFlags, "-DISEGLFB", - "-I", file("modules/graphics/src/main/native-glass/monocle/") + "-I", file("modules/graphics/src/main/native-glass/monocle/"), + "-I", file("modules/graphics/src/dalvik/native/") ].flatten() DALVIK.glass.monocle = [:] @@ -545,9 +626,31 @@ DALVIK.glass.monocle.compiler = compiler DALVIK.glass.monocle.ccFlags = monocleCFlags DALVIK.glass.monocle.linker = linker -DALVIK.glass.monocle.linkFlags = [linkFlags, "-ldl", "-llog", "-lGLESv2", "-lEGL"].flatten() +DALVIK.glass.monocle.linkFlags = [linkFlags, "-ldl", "-llog", "-landroid", "-lGLESv2", "-lEGL"].flatten() + DALVIK.glass.monocle.lib = "glass_monocle" +DALVIK.javafxPlatformDefault="eglfb" + +def monoclePlatformAdditions = """ +monocle.glass.platform=Monocle +monocle.prism.order=es2,sw +monocle.prism.eglfb=true +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""" + + DALVIK.glass.eglfb = [:] DALVIK.glass.eglfb.nativeSource = [ @@ -604,9 +707,22 @@ DALVIK.iio.lib = "javafx_iio" DALVIK.prismES2 = [:] -DALVIK.prismES2.variants = ["eglfb"] +DALVIK.prismES2.variants = ["eglfb", "monocle"] DALVIK.prismES2.javahInclude = ["com/sun/prism/es2/**/*"] +DALVIK.prismES2.monocle= [:] +DALVIK.prismES2.monocle.nativeSource = [ + file("modules/graphics/src/main/native-prism-es2"), + file("modules/graphics/src/main/native-prism-es2/GL"), + file("modules/graphics/src/main/native-prism-es2/monocle") +] +DALVIK.prismES2.monocle.compiler = compiler +DALVIK.prismES2.monocle.ccFlags = [ccFlags, ccWarnFlags, ccArchFlags, ccOptFlags, + ccDebugFlags, ccDefaultIncludeFlags, "-DIS_EGLFB"].flatten() +DALVIK.prismES2.monocle.linker = linker +DALVIK.prismES2.monocle.linkFlags = [linkFlags, "-ldl", "-llog", "-lGLESv2", "-lEGL"].flatten() +DALVIK.prismES2.monocle.lib = "prism_es2_monocle" + DALVIK.prismES2.eglfb = [:] DALVIK.prismES2.eglfb.nativeSource = [ file("modules/graphics/src/main/native-prism-es2"), diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AcceleratedScreen.java Fri May 08 21:58:27 2015 +0200 @@ -36,8 +36,10 @@ private long eglSurface; private long eglContext; private long eglDisplay; + private long nativeWindow; protected static final LinuxSystem ls = LinuxSystem.getLinuxSystem(); private EGL egl; + long eglConfigs[] = {0}; /** Returns a platform-specific native display handle suitable for use with * eglGetDisplay. @@ -93,7 +95,6 @@ "Error binding OPENGL API"); } - long eglConfigs[] = {0}; int configCount[] = {0}; if (!egl.eglChooseConfig(eglDisplay, attributes, eglConfigs, @@ -119,6 +120,13 @@ } } + private void createSurface() { + nativeWindow = platformGetNativeWindow(); + eglSurface = egl._eglCreateWindowSurface(eglDisplay, eglConfigs[0], + nativeWindow, null); + } + + /** Make the EGL drawing surface current or not * * @param flag @@ -171,10 +179,17 @@ * @return success or failure */ public boolean swapBuffers() { + boolean result = false; synchronized(NativeScreen.framebufferSwapLock) { - egl.eglSwapBuffers(eglDisplay, eglSurface); + result = egl.eglSwapBuffers(eglDisplay, eglSurface); +// TODO this shouldn't happen. In case the surface is invalid, we need to have recreated it before this method is called + if (!result) { + createSurface(); + result = egl.eglSwapBuffers(eglDisplay, eglSurface); + } } - return true; + return result; + } } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidAcceleratedScreen.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidAcceleratedScreen.java Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2014, 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. + */ + +package com.sun.glass.ui.monocle; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +/** + * Provide Android implementation of AcceleratedScreen + * + */ +class AndroidAcceleratedScreen extends AcceleratedScreen { + + + AndroidAcceleratedScreen(int[] attributes) throws GLException { + super(attributes); + } + + boolean initPlatformLibraries() { + return super.initPlatformLibraries(); + } + + @Override + protected long platformGetNativeDisplay() { + return 0; + } + + @Override + protected long platformGetNativeWindow() { + long answer = NativePlatformFactory.getNativePlatform() + .getScreen().getNativeHandle(); + return answer; + } + +} diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDevice.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDevice.java Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2013, 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. + */ + +package com.sun.glass.ui.monocle; + +import java.io.IOException; + +/** + * + */ +class AndroidInputDevice implements Runnable, InputDevice { + + private AndroidInputProcessor inputProcessor; + + @Override + public void run() { + if (inputProcessor == null) { + System.err.println("Error: no input processor"); + return; + } + // read from the android device (change this into push) + // and process the events + } + + @Override + public boolean isTouch() { + return true; + } + + @Override + public boolean isMultiTouch() { + return true; + } + + @Override + public boolean isRelative() { + return false; + } + + @Override + public boolean is5Way() { + return false; + } + + @Override + public boolean isFullKeyboard() { +// if we return false, the JavaFX virtual keyboard will be used instead of the android built-in one + return true; + } + + void setInputProcessor(AndroidInputProcessor inputProcessor) { + this.inputProcessor = inputProcessor; + } +} diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDeviceRegistry.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputDeviceRegistry.java Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2013, 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. + */ +package com.sun.glass.ui.monocle; + +import com.sun.glass.ui.monocle.TouchState.Point; +import java.security.AllPermission; +import javafx.application.Platform; + + +public class AndroidInputDeviceRegistry extends InputDeviceRegistry { + + private static AndroidInputDeviceRegistry instance = new AndroidInputDeviceRegistry(); + private AndroidInputDevice androidDevice; + private AndroidInputProcessor processor; + private final KeyState keyState = new KeyState(); + + static AndroidInputDeviceRegistry getInstance() { + return instance; + } + + public static void registerDevice() { + Platform.runLater(() -> instance.createDevice()); + } + + public static void gotTouchEventFromNative(int count, int[] actions, int[] ids, int[] x, int[] y, int primary) { + TouchState touchState = new TouchState(); + + if (primary == -1) { + System.out.println("don't add points, primary = -1"); + } + else { + for (int i = 0; i < count; i++) { + Point p = new Point(); + p.id = ids[i]; + p.x = x[i]; + p.y = y[i]; + touchState.addPoint(p); + } + } + instance.gotTouchEvent(touchState); + } + + private void gotTouchEvent(TouchState touchState) { + if (androidDevice == null) { + System.out.println("[MON] got touch event, but no registered device yet"); + Thread.dumpStack(); + return; + } + if (processor == null) { + System.out.println("[MON] got touch event, but processor not yet initialized"); + Thread.dumpStack(); + return; + } + processor.pushEvent(touchState); + } + + + public static void gotKeyEventFromNative(int action, int linuxKey) { + instance.gotKeyEvent (action, linuxKey); + } + + private void gotKeyEvent(int action, int lk) { + int vk = LinuxKeyProcessor.getVirtualKeyCode(lk); + if (action == 0) { + keyState.pressKey(vk); + } + else if (action ==1) { + keyState.releaseKey(vk); + } + else { + System.out.println("[JVDBG] ERROR, what action is this? "+action); + } + instance.gotKeyEvent(keyState); + } + + private void gotKeyEvent(KeyState keyState) { + processor.pushKeyEvent(keyState); + } + + private AndroidInputDeviceRegistry() { + } + + private void createDevice() { + System.out.println("[MON] Create device"); + AndroidInputDevice device = new AndroidInputDevice(); + androidDevice = addDeviceInternal(device, "Android Touch Input"); + System.out.println("[MON] Create device done, add done"); + } + + private AndroidInputDevice addDeviceInternal(AndroidInputDevice device, String name) { + processor = createInputProcessor(device); + + device.setInputProcessor(processor); + Thread thread = new Thread(device); + thread.setName(name); + thread.setDaemon(true); + thread.start(); + devices.add(device); + + return device; + + } + + void removeDevice(AndroidInputDevice device) { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + security.checkPermission(new AllPermission()); + } + devices.remove(device); + } + + private AndroidInputProcessor createInputProcessor(AndroidInputDevice device) { + return new AndroidInputProcessor(device); + } + +} diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidInputProcessor.java Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 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. + */ +package com.sun.glass.ui.monocle; + +class AndroidInputProcessor { + + private final AndroidInputDevice device; + final TouchPipeline touchPipeline; + private final KeyInput keyInput = new KeyInput(); + + AndroidInputProcessor(AndroidInputDevice device) { + this.device = device; + touchPipeline = new TouchPipeline(); + touchPipeline.add(TouchInput.getInstance().getBasePipeline()); + } + + void pushEvent(TouchState state) { + touchPipeline.pushState(state); + } + + /** + * Called when events are waiting on the input device to be processed. + * Called on the runnable processor provided to the input device. + * + * @param device The device on which events are pending + */ + void processEvents(AndroidInputDevice device) { + touchPipeline.pushState(null); + } + + synchronized void pushKeyEvent(KeyState keyState) { + keyInput.setState(keyState); + } + +} diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidPlatform.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidPlatform.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidPlatform.java Fri May 08 21:58:27 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -24,25 +24,41 @@ */ package com.sun.glass.ui.monocle; +import com.sun.glass.utils.NativeLibLoader; -/** AndroidPlatform matches any Linux system */ class AndroidPlatform extends NativePlatform { AndroidPlatform() { + NativeLibLoader.loadLibrary("glass_monocle"); } @Override protected InputDeviceRegistry createInputDeviceRegistry() { - return new InputDeviceRegistry(); + return AndroidInputDeviceRegistry.getInstance(); } @Override protected NativeCursor createCursor() { - return null; + return new NullCursor(); } @Override protected NativeScreen createScreen() { - return null; + return new AndroidScreen(); } + + /** Create the accelerated screen for this platform + * + * @param attributes a sequence of pairs (GLAttibute, value) + * @throws GLException + */ + @Override + public synchronized AcceleratedScreen getAcceleratedScreen( + int[] attributes) throws GLException { + if (accScreen == null) { + accScreen = new AndroidAcceleratedScreen(attributes); + } + return accScreen; + } + } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidScreen.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/AndroidScreen.java Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2013, 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. + */ + +package com.sun.glass.ui.monocle; + +import com.sun.glass.ui.Pixels; + +import java.nio.Buffer; +import java.nio.ByteBuffer; + +public class AndroidScreen implements NativeScreen { + + private float density = -1; + public int getDepth() { + return 24; + } + + /** + * Returns the native format of the screen, as a constant from the Pixels + * class. + */ + public int getNativeFormat() { + return Pixels.Format.BYTE_ARGB; + } + + /** + * Returns the pixel width of the screen. + */ + public int getWidth() { + int answer = (int)(_getWidth()/getScale()); + return answer; + } + + /** + * Returns the pixel height of the screen. + */ + public int getHeight() { + return (int)(_getHeight()/getScale()); + } + + /** + * Returns the number of pixels per inch in the screen. + */ + public int getDPI() { + return 100; + } + + @Override + public float getScale () { + if (density < 0) { + density = _getDensity(); + } + return density; + } + + /** + * Returns a native handle for the screen. The handle is platform-specific. + */ + public long getNativeHandle() { + long answer = _getNativeHandle(); + return answer; + } + + /** + * Called during JavaFX shutdown to release the screen. Called only once. + */ + public void shutdown() { + _shutdown(); + } + + /** Uploads a pixel buffer to the screen. Called on the JavaFX application thread. + * + * @param b Pixel data, in BYTE_BGRA_PRE format. The byte stride of the + * data is equal to width * 4. + * @param x The X offset of the pixel data on the screen + * @param y The Y offset of the pixel data on the screen + * @param width The pixel width of the data + * @param height The pixel height of the data + * @param alpha The alpha level to use to compose the data over existing + * pixels + */ + public void uploadPixels(Buffer b, + int x, int y, int width, int height, float alpha) { + _uploadPixels (b, x, y, width, height, alpha); + } + + /** + * Called on the JavaFX application thread when pixel data for all windows + * has been uploaded. + */ + public void swapBuffers() { + _swapBuffers(); + } + + /** + * Returns a read-only ByteBuffer in the native pixel format containing the screen contents. + * @return ByteBuffer a read-only ByteBuffer containing the screen contents + */ + public ByteBuffer getScreenCapture() { + return _getScreenCapture(); + } + + /** + * An Object to lock against when swapping screen buffers. + */ + public static final Object framebufferSwapLock = new Object(); + + native int _getWidth(); + native int _getHeight(); + native float _getDensity(); + native long _getNativeHandle(); + native void _shutdown(); + native void _uploadPixels(Buffer b, + int x, int y, int width, int height, float alpha); + native void _swapBuffers(); + native ByteBuffer _getScreenCapture(); +} diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/FBDevScreen.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/FBDevScreen.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/FBDevScreen.java Fri May 08 21:58:27 2015 +0200 @@ -105,6 +105,11 @@ } @Override + public float getScale() { + return 1.0f; + } + + @Override public int getDPI() { return 96; // no way to read DPI from sysfs and ioctl returns junk values } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/HeadlessScreen.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/HeadlessScreen.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/HeadlessScreen.java Fri May 08 21:58:27 2015 +0200 @@ -93,6 +93,11 @@ } @Override + public float getScale() { + return 1.0f; + } + + @Override public long getNativeHandle() { return 1l; } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/LinuxKeyProcessor.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/LinuxKeyProcessor.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/LinuxKeyProcessor.java Fri May 08 21:58:27 2015 +0200 @@ -64,7 +64,7 @@ } } - private int getVirtualKeyCode(int linuxKeyCode) { + static int getVirtualKeyCode(int linuxKeyCode) { if (linuxKeyCode >= LinuxInput.KEY_1 && linuxKeyCode <= LinuxInput.KEY_9) { return linuxKeyCode - LinuxInput.KEY_1 + KeyEvent.VK_1; } else if (linuxKeyCode >= LinuxInput.KEY_NUMERIC_0 && linuxKeyCode <= LinuxInput.KEY_NUMERIC_9) { diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleApplication.java Fri May 08 21:58:27 2015 +0200 @@ -250,7 +250,7 @@ 0, 0, ns.getWidth(), ns.getHeight(), 0, 0, ns.getWidth(), ns.getHeight(), ns.getDPI(), ns.getDPI(), - 1.0f); + ns.getScale()); // Move the cursor to the middle of the screen MouseState mouseState = new MouseState(); mouseState.setX(ns.getWidth() / 2); diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleWindowManager.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleWindowManager.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/MonocleWindowManager.java Fri May 08 21:58:27 2015 +0200 @@ -26,10 +26,14 @@ package com.sun.glass.ui.monocle; import com.sun.glass.events.WindowEvent; +import com.sun.glass.ui.Screen; +import com.sun.javafx.tk.Toolkit; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import javafx.application.Platform; final class MonocleWindowManager { @@ -166,4 +170,17 @@ } } + static void repaintFromNative () { + Platform.runLater(new Runnable () { + + @Override + public void run() { + Screen.notifySettingsChanged(); + instance.getFocusedWindow().setFullScreen(true); + instance.repaintAll(); + Toolkit.getToolkit().requestNextPulse(); + } + }); + } + } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/NativeScreen.java Fri May 08 21:58:27 2015 +0200 @@ -98,4 +98,10 @@ */ public static final Object framebufferSwapLock = new Object(); + /** + * Return the scale factor between the physical pixels and the logical pixels + * e.g. hdpi = 1.5, xhdpi = 2.0 + */ + public float getScale(); + } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/glass/ui/monocle/X11Screen.java --- a/modules/graphics/src/main/java/com/sun/glass/ui/monocle/X11Screen.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/glass/ui/monocle/X11Screen.java Fri May 08 21:58:27 2015 +0200 @@ -185,6 +185,11 @@ } @Override + public float getScale() { + return 1.0f; + } + + @Override public long getNativeHandle() { return nativeHandle; } diff -r e8beeeaa062e modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java --- a/modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java Fri May 08 12:39:39 2015 +0300 +++ b/modules/graphics/src/main/java/com/sun/prism/es2/GLFactory.java Fri May 08 21:58:27 2015 +0200 @@ -80,7 +80,9 @@ } else if (PlatformUtil.isAndroid()) { if ("eglfb".equals(PlatformUtil.getEmbeddedType())) { factoryClassName = "com.sun.prism.es2.EGLFBGLFactory"; - } else { + } else if ("monocle".equals(PlatformUtil.getEmbeddedType())) + factoryClassName = "com.sun.prism.es2.MonocleGLFactory"; + else { factoryClassName = null; System.err.println("GLFactory.static - Only eglfb supported for Android!"); } diff -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/AndroidScreen.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/AndroidScreen.c Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2012, 2014, 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 "activity.h" +#include "dalvikInput.h" +#include "com_sun_glass_ui_monocle_AndroidScreen.h" +#include "Monocle.h" +#include "logging.h" + + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _getWidth + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getWidth + (JNIEnv *env, jobject obj) { + ANativeWindow* androidWindow = android_getNativeWindow(env); + if (androidWindow == NULL) { + return 0; + } + int32_t width = ANativeWindow_getWidth(androidWindow); + return width; +} + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _getHeight + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getHeight + (JNIEnv *env, jobject obj) { + ANativeWindow* androidWindow = android_getNativeWindow(env); + if (androidWindow == NULL) { + return 0; + } + int32_t height = ANativeWindow_getHeight(androidWindow); + return height; +} + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _getNativeHandle + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getNativeHandle + (JNIEnv *env, jobject obj) { + ANativeWindow* androidWindow = android_getNativeWindow(env); + return androidWindow; +} + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _getDensity + * Signature: ()F + */ +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; +} + + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _shutdown + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1shutdown + (JNIEnv *env, jobject obj) { +} + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _uploadPixels + * Signature: (Ljava/nio/Buffer;IIIIF)V + */ +JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1uploadPixels + (JNIEnv *env, jobject obj, jobject obj2, jint ji1, jint ji2, jint ji3, jint j4, jfloat jf1) { +} + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _swapBuffers + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1swapBuffers + (JNIEnv *env, jobject obj) { +} + +/* + * Class: com_sun_glass_ui_monocle_AndroidScreen + * Method: _getScreenCapture + * Signature: ()Ljava/nio/ByteBuffer; + */ +JNIEXPORT jobject JNICALL Java_com_sun_glass_ui_monocle_AndroidScreen__1getScreenCapture + (JNIEnv *env, jobject obj) { + return NULL; +} + + diff -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/Udev.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/Udev.c Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2012, 2014, 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 "com_sun_glass_ui_monocle_Udev.h" +#include "Monocle.h" + + JNIEXPORT jlong JNICALL + Java_com_sun_glass_ui_monocle_Udev__1open + (JNIEnv *env, jobject UNUSED(jUdev)) { + return 0l; + } + +JNIEXPORT jint JNICALL +Java_com_sun_glass_ui_monocle_Udev__1readEvent +(JNIEnv *env, jobject UNUSED(jUdev), jlong fdL, jobject bufferObj) { + return 0; +} + +JNIEXPORT void JNICALL +Java_com_sun_glass_ui_monocle_Udev__1close +(JNIEnv *env, jobject UNUSED(jUdev), jlong fdL) { +} + +JNIEXPORT jint JNICALL +Java_com_sun_glass_ui_monocle_Udev__1getPropertiesOffset +(JNIEnv *env, jobject UNUSED(jUdev), jobject bufferObj) { + return -1; +} + +JNIEXPORT jint JNICALL +Java_com_sun_glass_ui_monocle_Udev__1getPropertiesLength +(JNIEnv *env, jobject UNUSED(jUdev), jobject bufferObj) { + return -1; +} + diff -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/dalvikConst.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/dalvikConst.h Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, 2014, 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. + */ + +#ifndef DALVIKCONST_H +#define DALVIKCONST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define RGBA_8888 1 +#define RGBX_8888 2 +#define RGB_888 3 +#define RGB_565 4 + +#define TOUCH_ACTION_STILL -1 +#define TOUCH_ACTION_DOWN 0 +#define TOUCH_ACTION_UP 1 +#define TOUCH_ACTION_MOVE 2 +#define TOUCH_ACTION_CANCEL 3 +#define TOUCH_ACTION_OUTSIDE 4 +#define TOUCH_ACTION_POINTER_DOWN 5 +#define TOUCH_ACTION_POINTER_UP 6 + +#define KEY_ACTION_DOWN 0 +#define KEY_ACTION_UP 1 +#define KEY_ACTION_MULTIPLE 2 + +#ifdef __cplusplus +} +#endif + +#endif /* DALVIKCONST_H */ diff -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/dalvikInput.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/dalvikInput.c Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2012, 2014, 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 -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/dalvikInput.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/dalvikInput.h Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, 2014, 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. + */ + +#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 + + +#include +#include +#include +#include + +#include + +#endif diff -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/dalvikUtils.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/dalvikUtils.c Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2012, 2014, 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. + */ + +#if (defined(ANDROID_NDK) && defined(DALVIK_VM)) + +#include +#include "dalvikConst.h" +#include "dalvikUtils.h" +#include "com_sun_glass_events_TouchEvent.h" +#include "com_sun_glass_events_MouseEvent.h" +#include "com_sun_glass_events_KeyEvent.h" + +int to_jfx_touch_action(int state) { + switch (state) { + case TOUCH_ACTION_DOWN: + case TOUCH_ACTION_POINTER_DOWN: + return com_sun_glass_events_TouchEvent_TOUCH_PRESSED; + case TOUCH_ACTION_UP: + case TOUCH_ACTION_POINTER_UP: + return com_sun_glass_events_TouchEvent_TOUCH_RELEASED; + case TOUCH_ACTION_MOVE: + return com_sun_glass_events_TouchEvent_TOUCH_MOVED; + case TOUCH_ACTION_CANCEL: + return com_sun_glass_events_TouchEvent_TOUCH_RELEASED; + case TOUCH_ACTION_STILL: + return com_sun_glass_events_TouchEvent_TOUCH_STILL; + default: + return 0; + } +} + +int to_jfx_key_action(int action) { + switch (action) { + case KEY_ACTION_DOWN: + return com_sun_glass_events_KeyEvent_PRESS; + case KEY_ACTION_UP: + return com_sun_glass_events_KeyEvent_RELEASE; + case KEY_ACTION_MULTIPLE: + return com_sun_glass_events_KeyEvent_TYPED; + } +} + +int to_linux_keycode(int androidKeyCode) { + int keySize = sizeof(keyMap)/sizeof(keyMap[0]); + for (int i = 0; i < keySize; ++i) { + if (keyMap[i].androidKC == androidKeyCode) { + return keyMap[i].linuxKC; + } + } + return KEY_RESERVED; +} + + +char *describe_surface_format(int f) { + switch (f) { + case RGBA_8888: + return "RGBA_8888"; + case RGBX_8888: + return "RGBX_8888"; + case RGB_888: + return "RGB_888"; + case RGB_565: + return "RGB_565"; + default: + return "UNKNOWN"; + } +} + +char *describe_touch_action(int state) { + switch (state) { + case TOUCH_ACTION_DOWN: + return "TOUCH_ACTION_DOWN"; + case TOUCH_ACTION_UP: + return "TOUCH_ACTION_UP"; + case TOUCH_ACTION_MOVE: + return "TOUCH_ACTION_MOVE"; + case TOUCH_ACTION_CANCEL: + return "TOUCH_ACTION_CANCEL"; + case TOUCH_ACTION_OUTSIDE: + return "TOUCH_ACTION_OUTSIDE"; + case TOUCH_ACTION_POINTER_DOWN: + return "TOUCH_ACTION_POINTER_DOWN"; + case TOUCH_ACTION_POINTER_UP: + return "TOUCH_ACTION_POINTER_UP"; + case TOUCH_ACTION_STILL: + return "TOUCH_ACTION_STILL"; + default: + return "TOUCH_ACTION_UNKNOWN"; + } +} + +char *describe_key_action(int action) { + switch(action) { + case KEY_ACTION_DOWN: + return "KEY_ACTION_DOWN"; + case KEY_ACTION_UP: + return "KEY_ACTION_UP"; + case KEY_ACTION_MULTIPLE: + return "KEY_ACTION_MULTIPLE"; + } +} + +#endif diff -r e8beeeaa062e modules/graphics/src/main/native-glass/monocle/android/dalvikUtils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-glass/monocle/android/dalvikUtils.h Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2012, 2014, 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. + */ + +#ifndef DALVIKUTILS_H +#define DALVIKUTILS_H + +#include "dalvikConst.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define CHECK_EXCEPTION(env) \ + if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \ + LOGE("Detected outstanding Java exception at %s:%s:%d\n", \ + __FUNCTION__, __FILE__, __LINE__); \ + (*env)->ExceptionDescribe(env); \ + (*env)->ExceptionClear(env); \ + }; + +int to_jfx_key_action(int action); +int to_jfx_touch_action(int state); +int to_linux_keycode(int androidKeyCode); +char *describe_surface_format(int format); +char *describe_touch_action(int state); +char *describe_key_action(int action); + +typedef struct { + int32_t androidKC; + int32_t linuxKC; +} AndroidLinuxKC; + +static AndroidLinuxKC keyMap[] = { + {AKEYCODE_UNKNOWN, KEY_RESERVED}, + {AKEYCODE_0, KEY_0}, + {AKEYCODE_1, KEY_1}, + {AKEYCODE_2, KEY_2}, + {AKEYCODE_3, KEY_3}, + {AKEYCODE_4, KEY_4}, + {AKEYCODE_5, KEY_5}, + {AKEYCODE_6, KEY_6}, + {AKEYCODE_7, KEY_7}, + {AKEYCODE_8, KEY_8}, + {AKEYCODE_9, KEY_9}, + {AKEYCODE_MINUS, KEY_MINUS}, + {AKEYCODE_EQUALS, KEY_EQUAL}, + {AKEYCODE_TAB, KEY_TAB}, + {AKEYCODE_Q, KEY_Q}, + {AKEYCODE_W, KEY_W}, + {AKEYCODE_E, KEY_E}, + {AKEYCODE_R, KEY_R}, + {AKEYCODE_T, KEY_T}, + {AKEYCODE_Y, KEY_Y}, + {AKEYCODE_U, KEY_U}, + {AKEYCODE_I, KEY_I}, + {AKEYCODE_O, KEY_O}, + {AKEYCODE_P, KEY_P}, + {AKEYCODE_LEFT_BRACKET, KEY_LEFTBRACE}, + {AKEYCODE_RIGHT_BRACKET, KEY_RIGHTBRACE}, + {AKEYCODE_ENTER, KEY_ENTER}, + //{AKEYCODE_CTRL_LEFT, KEY_LEFTCTRL}, + //{AKEYCODE_CTRL_RIGHT, KEY_RIGHTCTRL}, + {AKEYCODE_A, KEY_A}, + {AKEYCODE_S, KEY_S}, + {AKEYCODE_D, KEY_D}, + {AKEYCODE_F, KEY_F}, + {AKEYCODE_G, KEY_G}, + {AKEYCODE_H, KEY_H}, + {AKEYCODE_J, KEY_J}, + {AKEYCODE_K, KEY_K}, + {AKEYCODE_L, KEY_L}, + {AKEYCODE_SEMICOLON, KEY_SEMICOLON}, + {AKEYCODE_GRAVE, KEY_GRAVE}, + {AKEYCODE_SHIFT_LEFT, KEY_LEFTSHIFT}, + {AKEYCODE_BACKSLASH, KEY_BACKSLASH}, + {AKEYCODE_Z, KEY_Z}, + {AKEYCODE_X, KEY_X}, + {AKEYCODE_C, KEY_C}, + {AKEYCODE_V, KEY_V}, + {AKEYCODE_B, KEY_B}, + {AKEYCODE_N, KEY_N}, + {AKEYCODE_M, KEY_M}, + {AKEYCODE_APOSTROPHE, KEY_APOSTROPHE}, + {AKEYCODE_COMMA, KEY_COMMA}, + {AKEYCODE_PERIOD, KEY_DOT}, + {AKEYCODE_SLASH, KEY_SLASH}, + {AKEYCODE_SHIFT_RIGHT, KEY_RIGHTSHIFT}, + {AKEYCODE_STAR, KEY_KPASTERISK}, + {AKEYCODE_ALT_LEFT, KEY_LEFTALT}, + {AKEYCODE_SPACE, KEY_SPACE}, + //{AKEYCODE_CAPSLOCK, KEY_CAPSLOCK}, + //{AKEYCODE_CTRL_RIGHT, KEY_RIGHTCTRL}, + {AKEYCODE_ALT_RIGHT, KEY_RIGHTALT}, + {AKEYCODE_HOME, KEY_HOME}, + {AKEYCODE_BACK, KEY_ESC}, //special back key mapped to ESC + {AKEYCODE_DPAD_UP, KEY_UP}, + {AKEYCODE_PAGE_UP, KEY_PAGEUP}, + {AKEYCODE_DPAD_LEFT, KEY_LEFT}, + {AKEYCODE_DPAD_RIGHT, KEY_RIGHT}, + //{AKEYCODE_END, KEY_END}, + {AKEYCODE_DPAD_DOWN, KEY_DOWN}, + {AKEYCODE_PAGE_DOWN, KEY_PAGEDOWN}, + //{AKEYCODE_INSERT, KEY_INSERT}, + {AKEYCODE_DEL, KEY_BACKSPACE}, + {AKEYCODE_FORWARD_DEL, KEY_DELETE}, + {AKEYCODE_MENU, KEY_MENU }, +}; + + +#ifdef __cplusplus +} +#endif + +#endif /* DALVIKUTILS_H */ diff -r e8beeeaa062e modules/graphics/src/main/native-prism-es2/monocle/wrapped_egl.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/graphics/src/main/native-prism-es2/monocle/wrapped_egl.c Fri May 08 21:58:27 2015 +0200 @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2012, 2014, 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. + */ + +/* + * an EGL library wrapper + * + * The why of this GL/EGL library wrapper: + * Vendors provide very different versions of the libraries, and linking + * directly with those libraries introduces a loader depenancy chain. + * But using this wrapper allows us to avoid this at the code of loading + * all the symbols needed at runtime and one level of indirection. + * + * to use, simply link this file, as well as the provided stub versions of -lEGL -lGLESv2 + * call openNativeFramebuffer() to get the NativeDisplayType and the NativeWindowType + * that match the platform. + * + */ + +#include +#include +#include +#include +#ifndef __USE_GNU // required for dladdr() & Dl_info +#define __USE_GNU +#endif +#include +#include + +#include +#include + +#if !defined(ANDROID_NDK) +#include "lensPort.h" +#endif + +#define WRAPPEDAPI +#include "eglfb/wrapped_egl.h" + +int load_wrapped_gles_symbols(void); +void *libglesv2; +void *libegl; +int done_loading_symbols = 0; + +/***************************** UTILITY ********************************/ + +#ifdef ANDROID_NDK + +static EGLDisplay(*_eglGetDisplay)(EGLNativeDisplayType display_id); +static EGLNativeWindowType(*_ANDROID_getNativeWindow)(); + +#else + +PrismNativePort prismPort; + +#endif + +int load_wrapped_gles_symbols() { + if (done_loading_symbols) { + return 0; + } + done_loading_symbols = 1; + +#ifdef ANDROID_NDK + libegl = dlopen("libEGL.so", RTLD_LAZY | RTLD_GLOBAL); + if (!libegl) { + fprintf(stderr, "Did not find libEGL.so %s\n", dlerror()); + return 0; + } + + _eglGetDisplay = dlsym(libegl, "eglGetDisplay"); + + libglesv2 = dlopen("libGLESv2.so", RTLD_LAZY | RTLD_GLOBAL); + if (!libglesv2) { + fprintf(stderr, "Did not find libGLESv2.so %s\n", dlerror()); + return 0; + } +#else + + Dl_info dlinfo; + if (dladdr(&load_wrapped_gles_symbols, &dlinfo)) { + + size_t rslash = (size_t)rindex(dlinfo.dli_fname,'/'); + if (rslash) { + char *b = (char *) alloca(strlen(dlinfo.dli_fname)+20); + rslash = rslash + 1 - (size_t)dlinfo.dli_fname; + strncpy(b, dlinfo.dli_fname,rslash); + strcpy(b + rslash, LENSPORT_LIBRARY_NAME); + + jboolean (*prism_platform_init)(PrismNativePort*) = 0; + + void *dlhand = dlopen(b,RTLD_NOW); + if (dlhand) { + prism_platform_init = dlsym(dlhand, "prism_platform_initialize"); + if (!prism_platform_init) { + fprintf(stderr,"prism_platform_initialize missing in %s\n",LENSPORT_LIBRARY_NAME); + exit(-1); + } + } else { + fprintf(stderr,"Prism FAILED TO OPEN %s\n",b); + fprintf(stderr,"dlopen reports %s\n",dlerror()); + exit(-1); + } + prismPort.version = NATIVE_PRISM_PORT_VERSION; + + if (!(*prism_platform_init)(&prismPort)) { + fprintf(stderr,"prism_platform_initialize failed\n"); + exit(-1); + } + } + } else { + printf("Did not get DLINFO\n"); + exit(-1); + } + +#endif + return 1; +} + +EGLNativeDisplayType getNativeDisplayType() { + if (!done_loading_symbols) { + load_wrapped_gles_symbols(); + } +#ifdef ANDROID_NDK + return (EGLNativeDisplayType) NULL; +#else + return (EGLNativeDisplayType) (*prismPort.getNativeDisplayType)(); +#endif + +} + +EGLNativeWindowType getNativeWindowType() { + if (!done_loading_symbols) { + load_wrapped_gles_symbols(); + } + +#ifdef ANDROID_NDK +#ifdef DALVIK_VM +#define ANDROID_LIB "libactivity.so" +#define GET_NATIVE_WINDOW "android_getNativeWindow" +#else +#define ANDROID_LIB "libglass_lens_android.so" +#define GET_NATIVE_WINDOW "ANDROID_getNativeWindow" +#endif + //don't cache for Android! + printf("Using %s\n", ANDROID_LIB); + void *libglass_android = dlopen(ANDROID_LIB, RTLD_LAZY | RTLD_GLOBAL); + if (!libglass_android) { + fprintf(stderr, "Did not find %s %s\n", ANDROID_LIB, dlerror()); + return NULL; + } + _ANDROID_getNativeWindow = dlsym(libglass_android, GET_NATIVE_WINDOW); + if (!_ANDROID_getNativeWindow) { + fprintf(stderr, "Did not find symbol \"%s\" %s\n", GET_NATIVE_WINDOW, dlerror()); + return NULL; + } + return (*_ANDROID_getNativeWindow)(); +#else + return (EGLNativeWindowType) (*prismPort.getNativeWindowType)(); +#endif +} + +EGLDisplay wr_eglGetDisplay(EGLNativeDisplayType display_id) { +#ifdef ANDROID_NDK + return (*_eglGetDisplay)(display_id); +#else + return (EGLDisplay) (*prismPort.wr_eglGetDisplay)((void*)display_id); +#endif +} + +void * getLibGLEShandle() { +#ifdef ANDROID_NDK + return libglesv2; +#else + return (*prismPort.getLibGLEShandle)(); +#endif +} +