diff options
Diffstat (limited to 'support')
28 files changed, 401 insertions, 872 deletions
diff --git a/support/android/apk/build.gradle b/support/android/apk/build.gradle index aa429b3da22..c2619efb978 100644 --- a/support/android/apk/build.gradle +++ b/support/android/apk/build.gradle @@ -1,42 +1,30 @@ -import org.apache.tools.ant.taskdefs.condition.Os - -buildscript { - repositories { - jcenter() - google() - } - dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' - } -} - -allprojects { - repositories { - jcenter() - flatDir { - dirs rootDir.absolutePath + "/../../../target/android/aar" - } - google() - } +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id 'com.android.application' version '8.0.1' apply false + id 'com.android.library' version '8.0.1' apply false } // Utility methods -String getTargetDir(boolean debug, String arch) { +ext.getTargetDir = { boolean debug, String arch -> def basePath = project.rootDir.getParentFile().getParentFile().getParentFile().absolutePath return basePath + '/target/android/' + getSubTargetDir(debug, arch) } -String getSubTargetDir(boolean debug, String arch) { +ext.getNativeTargetDir = { boolean debug, String arch -> + def basePath = project.rootDir.getParentFile().getParentFile().getParentFile().absolutePath + return basePath + '/target/' + getSubTargetDir(debug, arch) +} + +ext.getSubTargetDir = { boolean debug, String arch -> return getRustTarget(arch) + '/' + (debug ? 'debug' : 'release') } -String getJniLibsPath(boolean debug, String arch) { - return getTargetDir(debug, arch) + '/apk/jniLibs' +ext.getJniLibsPath = { boolean debug, String arch -> + return getTargetDir(debug, arch) + '/jniLibs' } -static String getRustTarget(String arch) { +ext.getRustTarget = { String arch -> switch (arch.toLowerCase()) { - case 'arm' : return 'arm-linux-androideabi' case 'armv7' : return 'armv7-linux-androideabi' case 'arm64' : return 'aarch64-linux-android' case 'x86' : return 'i686-linux-android' @@ -44,9 +32,8 @@ static String getRustTarget(String arch) { } } -static String getNDKAbi(String arch) { +ext.getNDKAbi = { String arch -> switch (arch.toLowerCase()) { - case 'arm' : return 'armeabi' case 'armv7' : return 'armeabi-v7a' case 'arm64' : return 'arm64-v8a' case 'x86' : return 'x86' @@ -54,16 +41,10 @@ static String getNDKAbi(String arch) { } } -String getNdkDir() { +ext.getNdkDir = { -> // Read environment variable used in rust build system - String ndkDir = System.getenv('ANDROID_NDK') - if (ndkDir == null) { - ndkDir = System.getenv('ANDROID_NDK_HOME') - } - if (ndkDir == null) { - ndkDir = System.getenv('ANDROID_NDK_ROOT') - } - if (ndkDir == null) { + String ndkRoot = System.getenv('ANDROID_NDK_ROOT') + if (ndkRoot == null) { // Fallback to ndkDir in local.properties def rootDir = project.rootDir def localProperties = new File(rootDir, "local.properties") @@ -72,14 +53,13 @@ String getNdkDir() { properties.load(instr) } - ndkDir = properties.getProperty('ndk.dir') + ndkRoot = properties.getProperty('ndk.dir') } - def cmd = Os.isFamily(Os.FAMILY_WINDOWS) ? 'ndk-build.cmd' : 'ndk-build' - def ndkbuild = new File(ndkDir + '/' + cmd) - if (!ndkbuild.exists()) { - throw new GradleException("Please set a valid NDK_HOME environment variable" + + def ndkDir = ndkRoot != null ? new File(ndkRoot) : null + if (!ndkDir || !ndkDir.exists()) { + throw new GradleException("Please set a valid ANDROID_NDK_ROOT environment variable" + "or ndk.dir path in local.properties file"); } - return ndkbuild.absolutePath + return ndkDir.absolutePath } diff --git a/support/android/apk/gradle.properties b/support/android/apk/gradle.properties new file mode 100644 index 00000000000..a03b3548962 --- /dev/null +++ b/support/android/apk/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true diff --git a/support/android/apk/gradle/wrapper/gradle-wrapper.jar b/support/android/apk/gradle/wrapper/gradle-wrapper.jar Binary files differindex 13372aef5e2..87b738cbd05 100644 --- a/support/android/apk/gradle/wrapper/gradle-wrapper.jar +++ b/support/android/apk/gradle/wrapper/gradle-wrapper.jar diff --git a/support/android/apk/gradle/wrapper/gradle-wrapper.properties b/support/android/apk/gradle/wrapper/gradle-wrapper.properties index 915f189a922..da1db5f04e8 100644 --- a/support/android/apk/gradle/wrapper/gradle-wrapper.properties +++ b/support/android/apk/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Wed Jul 11 13:23:08 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/support/android/apk/gradlew b/support/android/apk/gradlew index 9d82f789151..af6708ff229 100755 --- a/support/android/apk/gradlew +++ b/support/android/apk/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m"' + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -150,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/support/android/apk/gradlew.bat b/support/android/apk/gradlew.bat index aec99730b4e..0f8d5937c4a 100644 --- a/support/android/apk/gradlew.bat +++ b/support/android/apk/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m"
+
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -46,10 +46,9 @@ echo location of your Java installation. goto fail
:init
-@rem Get command-line arguments, handling Windowz variants
+@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
-if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
@@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
-goto execute
-
-:4NT_args
-@rem Get arguments from the 4NT Shell from JP Software
-set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
diff --git a/support/android/apk/jni/Android.mk b/support/android/apk/jni/Android.mk index 20a4de2d4b2..7ee4ffe58d8 100644 --- a/support/android/apk/jni/Android.mk +++ b/support/android/apk/jni/Android.mk @@ -16,13 +16,7 @@ MY_LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_PATH:= $(SERVO_TARGET_DIR) +LOCAL_PATH := $(SERVO_TARGET_DIR) LOCAL_MODULE := servojni LOCAL_SRC_FILES := libsimpleservo.so include $(PREBUILT_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_PATH:= $(SERVO_TARGET_DIR)/../../gstreamer/gst-build-$(APP_ABI) -LOCAL_MODULE := gstreamer -LOCAL_SRC_FILES := libgstreamer_android.so -include $(PREBUILT_SHARED_LIBRARY) diff --git a/support/android/apk/jni/Application.mk b/support/android/apk/jni/Application.mk index 9944120aebe..5b349f06d44 100644 --- a/support/android/apk/jni/Application.mk +++ b/support/android/apk/jni/Application.mk @@ -1,5 +1,5 @@ NDK_TOOLCHAIN_VERSION := clang -APP_MODULES := c++_shared servojni gstreamer -APP_PLATFORM := android-21 -APP_STL:= c++_shared -APP_ABI:= armeabi-v7a x86 +APP_MODULES := c++_shared servojni +APP_PLATFORM := android-30 +APP_STL := c++_shared +APP_ABI := armeabi-v7a x86 diff --git a/support/android/apk/servoapp/build.gradle b/support/android/apk/servoapp/build.gradle index 6b440e7b2c7..6e1cb514d26 100644 --- a/support/android/apk/servoapp/build.gradle +++ b/support/android/apk/servoapp/build.gradle @@ -1,18 +1,22 @@ -apply plugin: 'com.android.application' +plugins { + id 'com.android.application' +} import java.util.regex.Matcher import java.util.regex.Pattern android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdk 33 + buildToolsVersion "33.0.2" + + namespace 'org.mozilla.servo' buildDir = rootDir.absolutePath + "/../../../target/android/gradle/servoapp" defaultConfig { applicationId "org.mozilla.servo" - minSdkVersion 21 - targetSdkVersion 27 + minSdk 30 + targetSdk 30 versionCode 1 versionName "1.0.0" } @@ -26,11 +30,7 @@ android { flavorDimensions "default" productFlavors { - main { - } - googlevr { - } - oculusvr { + basic { } } @@ -61,19 +61,6 @@ android { } // Custom build types - armDebug { - initWith(debug) - ndk { - abiFilters getNDKAbi('arm') - } - } - - armRelease { - initWith(release) - ndk { - abiFilters getNDKAbi('arm') - } - } armv7Debug { initWith(debug) ndk { @@ -144,7 +131,6 @@ android { } dependencies { - implementation 'com.android.support.constraint:constraint-layout:1.1.2' if (findProject(':servoview-local')) { implementation project(':servoview-local') } else { diff --git a/support/android/apk/servoapp/src/googlevr/AndroidManifest.xml b/support/android/apk/servoapp/src/googlevr/AndroidManifest.xml deleted file mode 100644 index a7df4ac14a9..00000000000 --- a/support/android/apk/servoapp/src/googlevr/AndroidManifest.xml +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- BEGIN_INCLUDE(manifest) --> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" - package="org.mozilla.servo"> - <application android:label="Servo"> - <activity android:name=".MainActivity" - android:label="Servo"> - <meta-data android:name="android.app.lib_name" android:value="servo" /> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="com.google.intent.category.LAUNCHER"/> - <category android:name="com.google.intent.category.DAYDREAM"/> - <category android:name="com.google.intent.category.CARDBOARD"/> - </intent-filter> - </activity> - </application> - -</manifest> -<!-- END_INCLUDE(manifest) --> diff --git a/support/android/apk/servoapp/src/main/AndroidManifest.xml b/support/android/apk/servoapp/src/main/AndroidManifest.xml index 71db56c53a1..3bedf50ffbf 100644 --- a/support/android/apk/servoapp/src/main/AndroidManifest.xml +++ b/support/android/apk/servoapp/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!-- BEGIN_INCLUDE(manifest) --> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" - package="org.mozilla.servo"> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto"> <uses-feature android:glEsVersion="0x00030000" android:required="true" /> <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/> diff --git a/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java b/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java index 1e1c9dbabeb..a366e8037d2 100644 --- a/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java +++ b/support/android/apk/servoapp/src/main/java/org/mozilla/servo/MainActivity.java @@ -78,8 +78,7 @@ public class MainActivity extends Activity implements Servo.Client { Intent intent = getIntent(); String args = intent.getStringExtra("servoargs"); String log = intent.getStringExtra("servolog"); - String gstdebug = intent.getStringExtra("gstdebug"); - mServoView.setServoArgs(args, log, gstdebug); + mServoView.setServoArgs(args, log); if (Intent.ACTION_VIEW.equals(intent.getAction())) { mServoView.loadUri(intent.getData()); @@ -89,8 +88,10 @@ public class MainActivity extends Activity implements Servo.Client { @Override protected void onDestroy() { - super.onDestroy(); - mMediaSession.hideMediaSessionControls(); + super.onDestroy(); + if (mMediaSession != null) { + mMediaSession.hideMediaSessionControls(); + } } private void setupUrlField() { @@ -229,31 +230,31 @@ public class MainActivity extends Activity implements Servo.Client { @Override public void onMediaSessionMetadata(String title, String artist, String album) { - if (mMediaSession == null) { - mMediaSession = new MediaSession(mServoView, this, getApplicationContext()); - } - Log.d("onMediaSessionMetadata", title + " " + artist + " " + album); - mMediaSession.updateMetadata(title, artist, album); + if (mMediaSession == null) { + mMediaSession = new MediaSession(mServoView, this, getApplicationContext()); + } + Log.d("onMediaSessionMetadata", title + " " + artist + " " + album); + mMediaSession.updateMetadata(title, artist, album); } @Override public void onMediaSessionPlaybackStateChange(int state) { - Log.d("onMediaSessionPlaybackStateChange", String.valueOf(state)); - if (mMediaSession == null) { - mMediaSession = new MediaSession(mServoView, this, getApplicationContext()); - } - - mMediaSession.setPlaybackState(state); - - if (state == MediaSession.PLAYBACK_STATE_NONE) { - mMediaSession.hideMediaSessionControls(); - return; - } - if (state == MediaSession.PLAYBACK_STATE_PLAYING || - state == MediaSession.PLAYBACK_STATE_PAUSED) { - mMediaSession.showMediaSessionControls(); - return; - } + Log.d("onMediaSessionPlaybackStateChange", String.valueOf(state)); + if (mMediaSession == null) { + mMediaSession = new MediaSession(mServoView, this, getApplicationContext()); + } + + mMediaSession.setPlaybackState(state); + + if (state == MediaSession.PLAYBACK_STATE_NONE) { + mMediaSession.hideMediaSessionControls(); + return; + } + if (state == MediaSession.PLAYBACK_STATE_PLAYING || + state == MediaSession.PLAYBACK_STATE_PAUSED) { + mMediaSession.showMediaSessionControls(); + return; + } } @Override diff --git a/support/android/apk/servoapp/src/main/res/layout/activity_main.xml b/support/android/apk/servoapp/src/main/res/layout/activity_main.xml index 2cfb3357a01..42cf7a1a4b9 100644 --- a/support/android/apk/servoapp/src/main/res/layout/activity_main.xml +++ b/support/android/apk/servoapp/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" @@ -102,4 +102,4 @@ android:focusable="true"/> </LinearLayout> -</android.support.constraint.ConstraintLayout> +</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/support/android/apk/servoview/build.gradle b/support/android/apk/servoview/build.gradle index 51bab4b45e2..5898bb7bca2 100644 --- a/support/android/apk/servoview/build.gradle +++ b/support/android/apk/servoview/build.gradle @@ -1,18 +1,23 @@ -apply plugin: 'com.android.library' +plugins { + id 'com.android.library' +} import groovy.io.FileType import java.util.regex.Matcher import java.util.regex.Pattern android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdk 33 + buildToolsVersion "33.0.2" + + namespace 'org.mozilla.servoview' buildDir = rootDir.absolutePath + "/../../../target/android/gradle/servoview" + ndkPath = getNdkDir() defaultConfig { - minSdkVersion 18 - targetSdkVersion 27 + minSdk 30 + targetSdk 30 versionCode 1 versionName "1.0" } @@ -26,25 +31,19 @@ android { flavorDimensions "default" productFlavors { - main { + basic { } - googlevr { - minSdkVersion 21 + } + + splits { + density { + enable false } - oculusvr { - minSdkVersion 21 + abi { + enable false } } - splits { - density { - enable false - } - abi { - enable false - } - } - buildTypes { // Default debug and release build types are used as templates @@ -59,65 +58,29 @@ android { } // Custom build types - armDebug { - initWith(debug) - ndk { - abiFilters getNDKAbi('arm') - } - } - armRelease { - initWith(release) - ndk { - abiFilters getNDKAbi('arm') - } - } armv7Debug { initWith(debug) - ndk { - abiFilters getNDKAbi('armv7') - } } armv7Release { initWith(release) - ndk { - abiFilters getNDKAbi('armv7') - } } arm64Debug { initWith(debug) - ndk { - abiFilters getNDKAbi('arm64') - } } arm64Release { initWith(release) - ndk { - abiFilters getNDKAbi('arm64') - } } x86Debug { initWith(debug) - ndk { - abiFilters getNDKAbi('x86') - } } x86Release { initWith(release) - ndk { - abiFilters getNDKAbi('x86') - } } } sourceSets { main { } - armDebug { - jniLibs.srcDirs = [getJniLibsPath(true, 'arm')] - } - armRelease { - jniLibs.srcDirs = [getJniLibsPath(false, 'arm')] - } armv7Debug { jniLibs.srcDirs = [getJniLibsPath(true, 'armv7')] } @@ -145,34 +108,49 @@ android { } } - - // Call our custom NDK Build task using flavor parameters + // Call our custom NDK Build task using flavor parameters. + // This step is needed because the Android Gradle Plugin system's + // integration with native C/C++ shared objects (based on the + // `android.externalNativeBuild` dsl object) assumes that we + // actually execute compiler commands to produced the shared + // objects. We already have the libsimpleservo.so produced by rustc. + // We could simply copy the .so to the `sourceSet.jniLibs` folder + // to make AGP bundle it with the APK, but this doesn't copy the STL + // (libc++_shared.so) as well. So we use ndk-build as a glorified + // `cp` command to copy the libsimpleservo.so from target/<arch> + // to target/android and crucially also include libc++_shared.so + // as well. + // + // FIXME(mukilan): According to the AGP docs, we should not be + // relying on task names used by the plugin system to hook into + // the build process, but instead we should use officially supported + // extension points such as `androidComponents.beforeVariants` tasks.all { compileTask -> - Pattern pattern = Pattern.compile(/^compile[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)Ndk/) + // This matches the task `mergeBasicArmv7DebugJniLibFolders`. + Pattern pattern = Pattern.compile(/^merge[A-Z][\w\d]+([A-Z][\w\d]+)(Debug|Release)JniLibFolders/) Matcher matcher = pattern.matcher(compileTask.name) if (!matcher.find()) { - return + return } def taskName = "ndkbuild" + compileTask.name tasks.create(name: taskName, type: Exec) { def debug = compileTask.name.contains("Debug") def arch = matcher.group(1) - commandLine getNdkDir(), - 'APP_BUILD_SCRIPT=../jni/Android.mk', - 'NDK_APPLICATION_MK=../jni/Application.mk', - 'NDK_LIBS_OUT=' + getJniLibsPath(debug, arch), - 'NDK_OUT=' + getTargetDir(debug, arch) + '/apk/obj', - 'NDK_DEBUG=' + (debug ? '1' : '0'), - 'APP_ABI=' + getNDKAbi(arch), - 'SERVO_TARGET_DIR=' + getTargetDir(debug, arch) + commandLine getNdkDir() + "/ndk-build", + 'APP_BUILD_SCRIPT=../jni/Android.mk', + 'NDK_APPLICATION_MK=../jni/Application.mk', + 'NDK_LIBS_OUT=' + getJniLibsPath(debug, arch), + 'NDK_DEBUG=' + (debug ? '1' : '0'), + 'APP_ABI=' + getNDKAbi(arch), + 'NDK_LOG=1', + 'SERVO_TARGET_DIR=' + getNativeTargetDir(debug, arch) } compileTask.dependsOn taskName } - project.afterEvaluate { android.libraryVariants.all { variant -> Pattern pattern = Pattern.compile(/^[\w\d]+([A-Z][\w\d]+)(Debug|Release)/) @@ -205,7 +183,7 @@ dependencies { ] // Iterate all build types and dependencies // For each dependency call the proper implementation command and set the correct dependency path - def list = ['arm', 'armv7', 'arm64', 'x86'] + def list = ['armv7', 'arm64', 'x86'] for (arch in list) { for (debug in [true, false]) { String basePath = getTargetDir(debug, arch) + "/build" @@ -220,10 +198,9 @@ dependencies { } } - googlevrImplementation 'com.google.vr:sdk-base:1.140.0' - googlevrImplementation(name: 'GVRService', ext: 'aar') - oculusvrImplementation(name: 'OVRService', ext: 'aar') - implementation 'com.android.support.constraint:constraint-layout:1.1.2' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.3' } // folderFilter can be used to improve search performance @@ -258,42 +235,3 @@ class ServoDependency { public String fileName; public String folderFilter; } - -apply plugin: 'maven' -import org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact - -uploadArchives { - doFirst { - for ( arch in ["arm", "armv7", "arm64", "x86"] ) { - def target = getTargetDir(false, arch) - def aar = new File(target, "servoview.aar") - if (aar.exists()) { - def art = new DefaultPublishArtifact("servoview-" + arch, "aar", "aar", null, new Date(), aar); - project.artifacts.add('archives', art) - } - } - } - repositories.mavenDeployer { - repository(url: "file://localhost/${buildDir}/maven") - def cmd = "git rev-parse --short HEAD" - def proc = cmd.execute() - def commit = proc.text.trim() - def version = "0.0.1." + new Date().format('yyyyMMdd') + "." + commit - for ( arch_ in ["arm", "armv7", "arm64", "x86"] ) { - def arch = arch_ - addFilter(arch) {artifact, file -> artifact.name == "servoview-" + arch} - pom(arch).artifactId = "servoview-" + arch - pom(arch).groupId = 'org.mozilla.servoview' - pom(arch).version = version - pom(arch).project { - licenses { - license { - name 'The Mozilla Public License, v. 2.0' - url 'https://mozilla.org/MPL/2.0/' - distribution 'repo' - } - } - } - } - } -} diff --git a/support/android/apk/servoview/src/googlevr/AndroidManifest.xml b/support/android/apk/servoview/src/googlevr/AndroidManifest.xml deleted file mode 100644 index 7e1c7048634..00000000000 --- a/support/android/apk/servoview/src/googlevr/AndroidManifest.xml +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- BEGIN_INCLUDE(manifest) --> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.mozilla.servoview"> - <application> - <activity android:name=".MainActivity" - android:screenOrientation="landscape" - android:enableVrMode="@string/gvr_vr_mode_component" - android:resizeableActivity="false"> - <!-- Intent filter that enables this app to be launched from the -Daydream Home menu. --> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - <category android:name="com.google.intent.category.DAYDREAM"/> - </intent-filter> - </activity> - </application> - -</manifest> - <!-- END_INCLUDE(manifest) --> diff --git a/support/android/apk/servoview/src/main/AndroidManifest.xml b/support/android/apk/servoview/src/main/AndroidManifest.xml index 1e916f18c97..94cbbcfc396 100644 --- a/support/android/apk/servoview/src/main/AndroidManifest.xml +++ b/support/android/apk/servoview/src/main/AndroidManifest.xml @@ -1,2 +1 @@ -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.mozilla.servoview" /> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" /> diff --git a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/JNIServo.java b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/JNIServo.java index 5fa91fa34f6..29dce9f01b1 100644 --- a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/JNIServo.java +++ b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/JNIServo.java @@ -6,7 +6,7 @@ package org.mozilla.servoview; import android.app.Activity; - +import android.view.Surface; /** * Maps /ports/libsimpleservo API */ @@ -14,13 +14,12 @@ import android.app.Activity; public class JNIServo { JNIServo() { System.loadLibrary("c++_shared"); - System.loadLibrary("gstreamer_android"); System.loadLibrary("simpleservo"); } public native String version(); - public native void init(Activity activity, ServoOptions options, Callbacks callbacks); + public native void init(Activity activity, ServoOptions options, Callbacks callbacks, Surface surface); public native void deinit(); @@ -66,6 +65,9 @@ public class JNIServo { public native void click(float x, float y); + public native void pauseCompositor(); + public native void resumeCompositor(Surface surface, ServoCoordinates coords); + public native void mediaSessionAction(int action); public static class ServoOptions { diff --git a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/Servo.java b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/Servo.java index 7f8bd3fc211..e8dfd332a11 100644 --- a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/Servo.java +++ b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/Servo.java @@ -8,6 +8,7 @@ package org.mozilla.servoview; import android.app.Activity; import android.content.Context; import android.util.Log; +import android.view.Surface; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; @@ -30,21 +31,16 @@ public class Servo { RunCallback runCallback, GfxCallbacks gfxcb, Client client, - Activity activity) { + Activity activity, + Surface surface) { mRunCallback = runCallback; mServoCallbacks = new Callbacks(client, gfxcb); mRunCallback.inGLThread(() -> { - mJNI.init(activity, options, mServoCallbacks); + mJNI.init(activity, options, mServoCallbacks, surface); }); - - try { - GStreamer.init((Context) activity); - } catch (Exception e) { - e.printStackTrace(); - } } public void resetGfxCallbacks(GfxCallbacks gfxcb) { @@ -164,6 +160,13 @@ public class Servo { mRunCallback.inGLThread(() -> mJNI.click(x, y)); } + public void pauseCompositor() { + mRunCallback.inGLThread(() -> mJNI.pauseCompositor()); + } + public void resumeCompositor(Surface surface, ServoCoordinates coords) { + mRunCallback.inGLThread(() -> mJNI.resumeCompositor(surface, coords)); + } + public void suspend(boolean suspended) { mSuspended = suspended; } diff --git a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoSurface.java b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoSurface.java deleted file mode 100644 index 80f897fa4b9..00000000000 --- a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoSurface.java +++ /dev/null @@ -1,302 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -package org.mozilla.servoview; - -import android.app.Activity; -import android.net.Uri; -import android.opengl.EGL14; -import android.opengl.EGLConfig; -import android.opengl.EGLContext; -import android.opengl.EGLDisplay; -import android.opengl.EGLSurface; -import android.opengl.GLUtils; -import android.os.Handler; -import android.os.Looper; -import android.util.Log; -import android.view.Surface; - -import org.mozilla.servoview.JNIServo.ServoCoordinates; -import org.mozilla.servoview.JNIServo.ServoOptions; -import org.mozilla.servoview.Servo.Client; -import org.mozilla.servoview.Servo.GfxCallbacks; -import org.mozilla.servoview.Servo.RunCallback; - -import static android.opengl.EGL14.EGL_CONTEXT_CLIENT_VERSION; -import static android.opengl.EGL14.EGL_NO_CONTEXT; -import static android.opengl.EGL14.EGL_NO_SURFACE; -import static android.opengl.EGL14.EGL_OPENGL_ES2_BIT; - -public class ServoSurface { - private static final String LOGTAG = "ServoSurface"; - private final GLThread mGLThread; - private final Handler mMainLooperHandler; - private Handler mGLLooperHandler; - private Surface mASurface; - private int mPadding; - private int mWidth; - private int mHeight; - private long mVRExternalContext; - private Servo mServo; - private Client mClient = null; - private String mServoArgs; - private String mServoLog; - private String mInitialUri; - private Activity mActivity; - - public ServoSurface(Surface surface, int width, int height, int padding) { - mPadding = padding; - mWidth = width; - mHeight = height; - mASurface = surface; - mMainLooperHandler = new Handler(Looper.getMainLooper()); - mGLThread = new GLThread(); - } - - public void onSurfaceChanged(Surface surface) { - mASurface = surface; - mGLThread.onSurfaceChanged(); - } - - public void setClient(Client client) { - mClient = client; - } - - public void setServoArgs(String args, String log) { - mServoArgs = args; - mServoLog = log; - } - - public void setActivity(Activity activity) { - mActivity = activity; - } - - public void setVRExternalContext(long context) { - mVRExternalContext = context; - } - - public void runLoop() { - mGLThread.start(); - } - - public void shutdown() { - Log.d(LOGTAG, "shutdown"); - mServo.shutdown(); - mServo = null; - mGLThread.shutdown(); - try { - Log.d(LOGTAG, "Waiting for GL thread to shutdown"); - mGLThread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - public void reload() { - mServo.reload(); - } - - public void goBack() { - mServo.goBack(); - } - - public void goForward() { - mServo.goForward(); - } - - public void stop() { - mServo.stop(); - } - - public void loadUri(String uri) { - if (mServo != null) { - mServo.loadUri(uri); - } else { - mInitialUri = uri; - } - } - - public void loadUri(Uri uri) { - loadUri(uri.toString()); - } - - public void scrollStart(int dx, int dy, int x, int y) { - mServo.scrollStart(dx, dy, x, y); - } - - public void scroll(int dx, int dy, int x, int y) { - mServo.scroll(dx, dy, x, y); - } - - public void scrollEnd(int dx, int dy, int x, int y) { - mServo.scrollEnd(dx, dy, x, y); - } - - public void click(float x, float y) { - mServo.click(x, y); - } - - public void onSurfaceResized(int width, int height) { - mWidth = width; - mHeight = height; - - ServoCoordinates coords = new ServoCoordinates(); - coords.x = mPadding; - coords.y = mPadding; - coords.width = width - 2 * mPadding; - coords.height = height - 2 * mPadding; - coords.fb_width = width; - coords.fb_height = height; - - mServo.resize(coords); - } - - static class GLSurface implements GfxCallbacks { - private EGLConfig[] mEGLConfigs; - private EGLDisplay mEglDisplay; - private EGLContext mEglContext; - private EGLSurface mEglSurface; - - void throwGLError(String function) { - throwGLError(function, EGL14.eglGetError()); - } - - void throwGLError(String function, int error) { - throw new RuntimeException("Error: " + function + "() Failed " + GLUtils.getEGLErrorString(error)); - } - - GLSurface(Surface surface) { - mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); - int[] version = new int[2]; - if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) { - throwGLError("eglInitialize"); - } - mEGLConfigs = new EGLConfig[1]; - int[] configsCount = new int[1]; - int[] configSpec = new int[]{ - EGL14.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL14.EGL_RED_SIZE, 8, - EGL14.EGL_GREEN_SIZE, 8, - EGL14.EGL_BLUE_SIZE, 8, - EGL14.EGL_ALPHA_SIZE, 8, - EGL14.EGL_DEPTH_SIZE, 24, - EGL14.EGL_STENCIL_SIZE, 0, - EGL14.EGL_NONE - }; - if ((!EGL14.eglChooseConfig(mEglDisplay, configSpec, 0, mEGLConfigs, 0, 1, configsCount, 0)) || (configsCount[0] == 0)) { - throwGLError("eglChooseConfig"); - } - if (mEGLConfigs[0] == null) { - throw new RuntimeException("Error: eglConfig() not Initialized"); - } - int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL14.EGL_NONE}; - mEglContext = EGL14.eglCreateContext(mEglDisplay, mEGLConfigs[0], EGL14.EGL_NO_CONTEXT, attrib_list, 0); - int glError = EGL14.eglGetError(); - if (glError != EGL14.EGL_SUCCESS) { - throwGLError("eglCreateContext", glError); - } - mEglSurface = EGL14.eglCreateWindowSurface(mEglDisplay, mEGLConfigs[0], surface, new int[]{EGL14.EGL_NONE}, 0); - if (mEglSurface == null || mEglSurface == EGL14.EGL_NO_SURFACE) { - glError = EGL14.eglGetError(); - if (glError == EGL14.EGL_BAD_NATIVE_WINDOW) { - Log.e(LOGTAG, "Error: createWindowSurface() Returned EGL_BAD_NATIVE_WINDOW."); - return; - } - throwGLError("createWindowSurface", glError); - } - - makeCurrent(); - } - - - public void makeCurrent() { - if (!EGL14.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) { - throwGLError("eglMakeCurrent"); - } - } - - public void flushGLBuffers() { - EGL14.eglSwapBuffers(mEglDisplay, mEglSurface); - } - - public void animationStateChanged(boolean animating) { - // FIXME - } - - void destroy() { - Log.d(LOGTAG, "Destroying surface"); - if (!EGL14.eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { - throwGLError("eglMakeCurrent"); - } - if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) { - throwGLError("eglDestroyContext"); - } - if (!EGL14.eglDestroySurface(mEglDisplay, mEglSurface)) { - throwGLError("eglDestroySurface"); - } - if (!EGL14.eglTerminate(mEglDisplay)) { - throwGLError("eglTerminate"); - } - } - - } - - class GLThread extends Thread implements RunCallback { - private GLSurface mSurface; - - public void inGLThread(Runnable r) { - mGLLooperHandler.post(r); - } - - public void inUIThread(Runnable r) { - mMainLooperHandler.post(r); - } - - public void onSurfaceChanged() { - Log.d(LOGTAG, "GLThread::onSurfaceChanged"); - mSurface.destroy(); - mSurface = new GLSurface(mASurface); - mServo.resetGfxCallbacks(mSurface); - } - - public void shutdown() { - Log.d(LOGTAG, "GLThread::shutdown"); - mSurface.destroy(); - mGLLooperHandler.getLooper().quitSafely(); - } - - public void run() { - Looper.prepare(); - - mSurface = new GLSurface(mASurface); - - mGLLooperHandler = new Handler(); - - inUIThread(() -> { - ServoCoordinates coords = new ServoCoordinates(); - coords.x = mPadding; - coords.y = mPadding; - coords.width = mWidth - 2 * mPadding; - coords.height = mHeight - 2 * mPadding; - coords.fb_width = mWidth; - coords.fb_height = mHeight; - - ServoOptions options = new ServoOptions(); - options.coordinates = coords; - options.args = mServoArgs; - options.density = 1; - options.url = mInitialUri; - options.logStr = mServoLog; - options.enableLogs = true; - options.enableSubpixelTextAntialiasing = false; - options.VRExternalContext = mVRExternalContext; - - mServo = new Servo(options, this, mSurface, mClient, mActivity); - }); - - Looper.loop(); - } - } -} diff --git a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java index 3784bbf58cb..19343d134d7 100644 --- a/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java +++ b/support/android/apk/servoview/src/main/java/org/mozilla/servoview/ServoView.java @@ -7,17 +7,15 @@ package org.mozilla.servoview; import android.app.Activity; import android.content.Context; -import android.net.Uri; -import android.opengl.GLES31; -import android.opengl.GLSurfaceView; import android.util.AttributeSet; +import android.net.Uri; +import android.os.Handler; +import android.os.Looper; import android.util.DisplayMetrics; import android.util.Log; -import android.view.Choreographer; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.ScaleGestureDetector; -import android.widget.OverScroller; +import android.view.Surface; +import android.view.SurfaceView; +import android.view.SurfaceHolder; import org.mozilla.servoview.JNIServo.ServoCoordinates; import org.mozilla.servoview.JNIServo.ServoOptions; @@ -25,41 +23,45 @@ import org.mozilla.servoview.Servo.Client; import org.mozilla.servoview.Servo.GfxCallbacks; import org.mozilla.servoview.Servo.RunCallback; -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; +import android.view.Choreographer; +import android.view.GestureDetector; +import android.view.MotionEvent; +import android.view.ScaleGestureDetector; +import android.widget.OverScroller; -public class ServoView extends GLSurfaceView - implements - GestureDetector.OnGestureListener, - ScaleGestureDetector.OnScaleGestureListener, - Choreographer.FrameCallback, - GfxCallbacks, - RunCallback { +import java.util.ArrayList; +public class ServoView extends SurfaceView + implements + GfxCallbacks, + RunCallback, + Choreographer.FrameCallback, + GestureDetector.OnGestureListener, + ScaleGestureDetector.OnScaleGestureListener { private static final String LOGTAG = "ServoView"; - - private Activity mActivity; - private Servo mServo; + private GLThread mGLThread; + private Handler mGLLooperHandler; + private Surface mASurface; + protected Servo mServo = null; private Client mClient = null; - private Uri mInitialUri = null; - private boolean mAnimating; private String mServoArgs; private String mServoLog; - private String mGstDebug; + private String mInitialUri; + private Activity mActivity; private GestureDetector mGestureDetector; - private ScaleGestureDetector mScaleGestureDetector; - - private OverScroller mScroller; private int mLastX = 0; private int mCurX = 0; private int mLastY = 0; private int mCurY = 0; private boolean mFlinging; + private ScaleGestureDetector mScaleGestureDetector; + private OverScroller mScroller; private boolean mZooming; private float mZoomFactor = 1; - private boolean mRedrawing; + private boolean mAnimating; + private boolean mPaused = false; public ServoView(Context context) { super(context); @@ -71,79 +73,49 @@ public class ServoView extends GLSurfaceView init(context); } - public void onDetachedFromWindow() { - mServo.shutdown(); - mServo = null; - super.onDetachedFromWindow(); - } - private void init(Context context) { mActivity = (Activity) context; setFocusable(true); setFocusableInTouchMode(true); + setClickable(true); + ArrayList view = new ArrayList(); + view.add(this); + addTouchables(view); setWillNotCacheDrawing(false); - setEGLContextClientVersion(3); - setEGLConfigChooser(8, 8, 8, 8, 24, 0); - setPreserveEGLContextOnPause(true); - ServoGLRenderer mRenderer = new ServoGLRenderer(this); - setRenderer(mRenderer); - setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); initGestures(context); - } - public void setServoArgs(String args, String log, String gstdebug) { - mServoArgs = args; - mServoLog = log; - mGstDebug = gstdebug; + mGLThread = new GLThread(mActivity, this); + getHolder().addCallback(mGLThread); + mGLThread.start(); } - public void reload() { - mServo.reload(); - } - public void goBack() { - mServo.goBack(); - } - - public void goForward() { - mServo.goForward(); + public void setClient(Client client) { + mClient = client; } - public void stop() { - mServo.stop(); + public void setServoArgs(String args, String log) { + mServoArgs = args; + mServoLog = log; } - public void onSurfaceInvalidated(int width, int height) { - if (mServo != null) { - ServoCoordinates coords = new ServoCoordinates(); - coords.width = width; - coords.height = height; - coords.fb_width = width; - coords.fb_height = height; - mServo.resize(coords); - mServo.refresh(); - } + // RunCallback + public void inGLThread(Runnable r) { + mGLLooperHandler.post(r); } - public void loadUri(Uri uri) { - if (mServo != null) { - mServo.loadUri(uri.toString()); - } else { - mInitialUri = uri; - } + public void inUIThread(Runnable r) { + post(r); } - public void mediaSessionAction(int action) { - mServo.mediaSessionAction(action); - } + // GfxCallbacks public void flushGLBuffers() { - requestRender(); } - // Scroll and click + // Scroll and click public void animationStateChanged(boolean animating) { if (!mAnimating && animating) { post(() -> startLooping()); @@ -154,48 +126,6 @@ public class ServoView extends GLSurfaceView public void makeCurrent() { } - public void inGLThread(Runnable f) { - queueEvent(f); - } - - public void inUIThread(Runnable f) { - post(f); - } - - public void onGLReady() { - ServoCoordinates coords = new ServoCoordinates(); - coords.width = getWidth(); - coords.height = getHeight(); - coords.fb_width = getWidth(); - coords.fb_height = getHeight(); - - ServoOptions options = new ServoOptions(); - options.args = mServoArgs; - options.coordinates = coords; - options.enableLogs = true; - options.enableSubpixelTextAntialiasing = true; - - DisplayMetrics metrics = new DisplayMetrics(); - mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); - options.density = metrics.density; - inGLThread(() -> { - String uri = mInitialUri == null ? null : mInitialUri.toString(); - options.url = uri; - options.logStr = mServoLog; - options.gstDebugStr = mGstDebug; - mServo = new Servo(options, this, this, mClient, mActivity); - }); - } - - public void setClient(Client client) { - mClient = client; - } - - private void initGestures(Context context) { - mGestureDetector = new GestureDetector(context, this); - mScaleGestureDetector = new ScaleGestureDetector(context, this); - mScroller = new OverScroller(context); - } private void startLooping() { // In case we were already drawing. @@ -253,6 +183,63 @@ public class ServoView extends GLSurfaceView } } + // Calls from Activity + public void onPause() { + if (mServo != null) { + mServo.suspend(true); + } + } + + public void onResume() { + if (mServo != null) { + mServo.suspend(false); + } + } + + public void reload() { + mServo.reload(); + } + + public void goBack() { + mServo.goBack(); + } + + public void goForward() { + mServo.goForward(); + } + + public void stop() { + mServo.stop(); + } + + public void loadUri(String uri) { + if (mServo != null) { + mServo.loadUri(uri); + } else { + mInitialUri = uri; + } + } + + public void loadUri(Uri uri) { + loadUri(uri.toString()); + } + + public void scrollStart(int dx, int dy, int x, int y) { + mServo.scrollStart(dx, dy, x, y); + } + + public void scroll(int dx, int dy, int x, int y) { + mServo.scroll(dx, dy, x, y); + } + + public void scrollEnd(int dx, int dy, int x, int y) { + mServo.scrollEnd(dx, dy, x, y); + } + + public void click(float x, float y) { + mServo.click(x, y); + } + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { mFlinging = true; @@ -275,20 +262,22 @@ public class ServoView extends GLSurfaceView return true; } + @Override public boolean onTouchEvent(final MotionEvent e) { mGestureDetector.onTouchEvent(e); mScaleGestureDetector.onTouchEvent(e); int action = e.getActionMasked(); + float x = e.getX(); - float y = e.getY(); - + int pointerIndex = e.getActionIndex(); int pointerId = e.getPointerId(pointerIndex); + switch (action) { case (MotionEvent.ACTION_DOWN): - mServo.touchDown(x, y, pointerId); + case (MotionEvent.ACTION_POINTER_DOWN): mFlinging = false; mScroller.forceFinished(true); mCurX = (int) x; @@ -299,32 +288,35 @@ public class ServoView extends GLSurfaceView case (MotionEvent.ACTION_MOVE): mCurX = (int) x; mCurY = (int) y; - mServo.touchMove(x, y, pointerId); return true; case (MotionEvent.ACTION_UP): - mServo.touchUp(x, y, pointerId); + case (MotionEvent.ACTION_POINTER_UP): + return true; case (MotionEvent.ACTION_CANCEL): - mServo.touchCancel(x, y, pointerId); return true; default: return true; } } - public boolean onSingleTapUp(MotionEvent e) { - return false; - } - + // OnGestureListener public void onLongPress(MotionEvent e) { } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + mServo.scroll((int) -distanceX, (int) -distanceY, (int) e1.getX(), (int) e1.getY()); return true; } + public boolean onSingleTapUp(MotionEvent e) { + click(e.getX(), e.getY()); + return false; + } + public void onShowPress(MotionEvent e) { } + // OnScaleGestureListener @Override public boolean onScaleBegin(ScaleGestureDetector detector) { if (mScroller.isFinished()) { @@ -351,41 +343,81 @@ public class ServoView extends GLSurfaceView mServo.pinchZoomEnd(mZoomFactor, 0, 0); } - - @Override - public void onPause() { - super.onPause(); - if (mServo != null) { - mServo.suspend(true); - } + private void initGestures(Context context) { + mGestureDetector = new GestureDetector(context, this); + mScaleGestureDetector = new ScaleGestureDetector(context, this); + mScroller = new OverScroller(context); } - @Override - public void onResume() { - super.onResume(); - if (mServo != null) { - mServo.suspend(false); - } + public void mediaSessionAction(int action) { + mServo.mediaSessionAction(action); } - static class ServoGLRenderer implements Renderer { + class GLThread extends Thread implements SurfaceHolder.Callback { + private Activity mActivity; + private ServoView mServoView; + GLThread(Activity activity, ServoView servoView) { + mActivity = activity; + mServoView = servoView; + } - private final ServoView mView; + public void surfaceCreated(SurfaceHolder holder) { + Log.d(LOGTAG, "GLThread::surfaceCreated"); + + ServoCoordinates coords = new ServoCoordinates(); + coords.width = mServoView.getWidth(); + coords.height = mServoView.getHeight(); + coords.fb_width = mServoView.getWidth(); + coords.fb_height = mServoView.getHeight(); + + Surface surface = holder.getSurface(); + ServoOptions options = new ServoOptions(); + options.args = mServoView.mServoArgs; + options.coordinates = coords; + options.enableLogs = true; + options.enableSubpixelTextAntialiasing = true; + + DisplayMetrics metrics = new DisplayMetrics(); + mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + options.density = metrics.density; + if (mServoView.mServo == null && !mPaused) { + mServoView.mServo = new Servo( + options, mServoView, mServoView, mClient, mActivity, surface); + } else { + mPaused = false; + mServoView.mServo.resumeCompositor(surface, coords); + } - ServoGLRenderer(ServoView view) { - mView = view; } - public void onSurfaceCreated(GL10 unused, EGLConfig config) { - mView.onGLReady(); + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + Log.d(LOGTAG, "GLThread::surfaceChanged"); + ServoCoordinates coords = new ServoCoordinates(); + coords.width = width; + coords.height = height; + coords.fb_width = width; + coords.fb_height = height; + + mServoView.mServo.resize(coords); } - public void onDrawFrame(GL10 unused) { + public void surfaceDestroyed(SurfaceHolder holder) { + Log.d(LOGTAG, "GLThread::surfaceDestroyed"); + mPaused = true; + mServoView.mServo.pauseCompositor(); } - public void onSurfaceChanged(GL10 gl, int width, int height) { - GLES31.glViewport(0, 0, width, height); - mView.onSurfaceInvalidated(width, height); + public void shutdown() { + Log.d(LOGTAG, "GLThread::shutdown"); + mGLLooperHandler.getLooper().quitSafely(); + } + + public void run() { + Looper.prepare(); + + mGLLooperHandler = new Handler(); + + Looper.loop(); } } } diff --git a/support/android/apk/servoview/src/oculusvr/AndroidManifest.xml b/support/android/apk/servoview/src/oculusvr/AndroidManifest.xml deleted file mode 100644 index 076c3dfa688..00000000000 --- a/support/android/apk/servoview/src/oculusvr/AndroidManifest.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- BEGIN_INCLUDE(manifest) --> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.mozilla.servoview">> - <application> - <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only"/> - <activity android:name=".MainActivity" android:screenOrientation="landscape"> - </activity> - </application> -</manifest> -<!-- END_INCLUDE(manifest) --> diff --git a/support/android/apk/settings.gradle b/support/android/apk/settings.gradle index 3d36551554c..d8826861853 100644 --- a/support/android/apk/settings.gradle +++ b/support/android/apk/settings.gradle @@ -1,3 +1,19 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + include ':servoapp' def userPropertiesFile = new File('user.properties') diff --git a/support/android/fakeld/fake-ld-arm.sh b/support/android/fakeld/fake-ld-arm.sh deleted file mode 100755 index 0e81b85fb14..00000000000 --- a/support/android/fakeld/fake-ld-arm.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -set -o errexit -set -o nounset -set -o pipefail - -source ./support/android/fakeld/fake-ld.sh - -export _GCC_PARAMS="${@}" -call_gcc "arch-arm" "armeabi" "arm-linux-androideabi" diff --git a/support/android/fakeld/fake-ld-arm64.sh b/support/android/fakeld/fake-ld-arm64.sh deleted file mode 100755 index eb7b0ada9a2..00000000000 --- a/support/android/fakeld/fake-ld-arm64.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -set -o errexit -set -o nounset -set -o pipefail - -source ./support/android/fakeld/fake-ld.sh - -export _GCC_PARAMS="${@}" -call_gcc "arch-arm64" "arm64-v8a" "aarch64-linux-android" diff --git a/support/android/fakeld/fake-ld-armv7.sh b/support/android/fakeld/fake-ld-armv7.sh deleted file mode 100755 index b1758a9b07a..00000000000 --- a/support/android/fakeld/fake-ld-armv7.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -set -o errexit -set -o nounset -set -o pipefail - -source ./support/android/fakeld/fake-ld.sh - -export _GCC_PARAMS="${@}" -call_gcc "arch-arm" "armeabi-v7a" "armv7-linux-androideabi" diff --git a/support/android/fakeld/fake-ld-x86.sh b/support/android/fakeld/fake-ld-x86.sh deleted file mode 100755 index 2df1d5e49e9..00000000000 --- a/support/android/fakeld/fake-ld-x86.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -set -o errexit -set -o nounset -set -o pipefail - -source ./support/android/fakeld/fake-ld.sh - -export _GCC_PARAMS="${@}" -call_gcc "arch-x86" "x86" "i686-linux-android" diff --git a/support/android/fakeld/fake-ld.cmd b/support/android/fakeld/fake-ld.cmd deleted file mode 100644 index b13c7e818ab..00000000000 --- a/support/android/fakeld/fake-ld.cmd +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -gcc -mwindows %* diff --git a/support/android/fakeld/fake-ld.sh b/support/android/fakeld/fake-ld.sh deleted file mode 100755 index 29eef1326ba..00000000000 --- a/support/android/fakeld/fake-ld.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -set -o errexit -set -o nounset -set -o pipefail - -call_gcc() -{ - TARGET_DIR="${OUT_DIR}/../../.." - - export _ANDROID_ARCH=$1 - export _ANDROID_TARGET=$3 - export ANDROID_SYSROOT="${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/${_ANDROID_ARCH}" - ANDROID_TOOLCHAIN="" - for host in "linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86"; do - if [[ -d "${ANDROID_NDK}/toolchains/llvm/prebuilt/${host}/bin" ]]; then - ANDROID_TOOLCHAIN="${ANDROID_NDK}/toolchains/llvm/prebuilt/${host}/bin" - break - fi - done - - ANDROID_CPU_ARCH_DIR=$2 - ANDROID_CXX_LIBS="${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/${ANDROID_CPU_ARCH_DIR}" - - echo "toolchain: ${ANDROID_TOOLCHAIN}" - echo "libs dir: ${ANDROID_CXX_LIBS}" - echo "sysroot: ${ANDROID_SYSROOT}" - echo "targetdir: ${TARGET_DIR}" - - "${ANDROID_TOOLCHAIN}/clang" \ - --sysroot="${ANDROID_SYSROOT}" \ - --gcc-toolchain="${GCC_TOOLCHAIN}" \ - --target="${_ANDROID_TARGET}" \ - -L "${ANDROID_CXX_LIBS}" ${_GCC_PARAMS} -lc++ -} |