diff options
-rw-r--r-- | display/renderer/Android.mk | 11 | ||||
-rw-r--r-- | display/renderer/device-files/androidsw.sh | 51 | ||||
-rw-r--r-- | display/renderer/device-files/graphics.sh | 137 | ||||
-rw-r--r-- | display/renderer/device-files/llvmpipe.sh | 51 |
4 files changed, 139 insertions, 111 deletions
diff --git a/display/renderer/Android.mk b/display/renderer/Android.mk index 338b020..c0b619e 100644 --- a/display/renderer/Android.mk +++ b/display/renderer/Android.mk @@ -2,14 +2,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_MODULE := llvmpipe.sh -LOCAL_SRC_FILES := device-files/llvmpipe.sh +LOCAL_MODULE := graphics.sh +LOCAL_SRC_FILES := device-files/graphics.sh LOCAL_MODULE_CLASS := EXECUTABLES include $(BUILD_PREBUILT) - -include $(CLEAR_VARS) -LOCAL_MODULE := androidsw.sh -LOCAL_SRC_FILES := device-files/androidsw.sh -LOCAL_MODULE_CLASS := EXECUTABLES - -include $(BUILD_PREBUILT) diff --git a/display/renderer/device-files/androidsw.sh b/display/renderer/device-files/androidsw.sh deleted file mode 100644 index 175e41f..0000000 --- a/display/renderer/device-files/androidsw.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/system/xbin/bash -# -# Copyright (C) 2017 Jeremy Rand <jeremy@veclabs.net> -# Partially based on code by Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> and Filippo Fil Bergamo -# -# This file is part of "Replicant Renderer Switcher", a set of shell scripts to switch between -# the Android Software Renderer and the llvmpipe renderer in Replicant. -# -# Replicant Renderer Switcher is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Replicant Renderer Switcher 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 for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -set -euf -o pipefail - -grep -q "ro.libagl=0" /system/build.prop && renderer="llvmpipe" || renderer="android" - -if [ "${renderer}" == "android" ] -then - echo "Android software renderer is already enabled!" - exit 1 -fi - -echo "Remounting system partition as writable..." -mount -o rw,remount /system - -echo "Enabling Android software renderer..." -sed "s/ro.libagl=0/ro.libagl=1/" -i /system/build.prop - -echo "Syncing filesystem..." -sync -sync - -echo "Remounting system partition as read-only..." -mount -o ro,remount /system - -echo "Syncing filesystem..." -sync -sync - -# https://android.stackexchange.com/a/139139 -echo "Android software renderer will be enabled after we reboot now..." -am start -a android.intent.action.REBOOT diff --git a/display/renderer/device-files/graphics.sh b/display/renderer/device-files/graphics.sh new file mode 100644 index 0000000..daf4ee1 --- /dev/null +++ b/display/renderer/device-files/graphics.sh @@ -0,0 +1,137 @@ +#!/system/xbin/bash +# +# Copyright (C) 2017 Jeremy Rand <jeremy@veclabs.net> +# Partially based on code by Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> and Filippo Fil Bergamo +# +# This file is part of "Replicant Renderer Switcher", a set of shell scripts to switch between +# the Android Software Renderer and the llvmpipe renderer in Replicant. +# +# Replicant Renderer Switcher is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Replicant Renderer Switcher 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 for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -euf -o pipefail + +usage() +{ + echo "Usage: graphics.sh [faster|compatible]" + echo "Examples:" + echo "graphics.sh faster" + echo "|-> Uses Android's libagl" + echo " which is faster" + echo " but some applications" + echo " like icecat won't work" + echo "graphics.sh compatible" + echo "|-> Uses llvmpipe" + echo " which is slower" + echo " but more compatible" + exit 1 +} + +check_permissions() +{ + new_renderer="$1" + + root_access="$(getprop persist.sys.root_access)" + uid="$(id -u)" + + # 0: Root access: Disabled, 2: Root access: ADB only + # For both the terminal application and ADB we have something + # like that: + # shell@i9100:/ $ su + # 255|shell@i9100:/ $ + # 1: Root access: Apps only + # From ADB: + # shell@i9100:/ $ su + # Permission denied + # 1|shell@i9100:/ $ + # From the terminal application + # u0_a51@i9100:/ $ su + # root@i9100:/ # + if [ "${uid}" != "0" ] ; then + echo "" + echo "This script requires root." + echo "To give it root:" + case "${root_access}" in + "0"|"1"|"2") + echo "- Go in Settings" + echo "- Go in Developer options" + echo "- Select Root access" + echo "- Set it to \"Apps and ADB\"" + ;; + esac + echo "- Run these 2 commands:" + echo " su" + echo " graphics.sh ${new_renderer}" + exit 1 + fi +} + +graphics() +{ + new_renderer="$1" # libagl || llvmpipe + + check_permissions "${new_renderer}" + + grep -q "ro.libagl=0" /system/build.prop && \ + old_renderer="llvmpipe" || old_renderer="libagl" + + if [ "${old_renderer}" == "${new_renderer}" ] ; then + if [ "${old_renderer}" = "libagl" ] ; then + echo "Android software renderer is already enabled!" + else + echo "${old_renderer} renderer is already enabled!" + fi + exit 1 + fi + + echo "Remounting system partition as writable..." + mount -o rw,remount /system + + if [ "${new_renderer}" == "libagl" ] ; then + echo "Enabling Android software renderer..." + sed "s/ro.libagl=0/ro.libagl=1/" -i /system/build.prop + else + echo "Enabling ${new_renderer}..." + sed "s/ro.libagl=1/ro.libagl=0/" -i /system/build.prop + fi + + echo "Syncing filesystem..." + sync + sync + + echo "Remounting system partition as read-only..." + mount -o ro,remount /system + + echo "Syncing filesystem..." + sync + sync + + if [ "${new_renderer}" == "libagl" ] ; then + echo "Android software renderer will be enabled after we reboot now..." + else + echo "${new_renderer} will be enabled after we reboot now..." + fi + + # https://android.stackexchange.com/a/139139 + am start -a android.intent.action.REBOOT +} + +if [ $# -ne 1 ] ; then + usage +fi + +if [ "$1" = "faster" -o "$1" = "compatible" ] ;then + graphics "$1" +else + usage +fi diff --git a/display/renderer/device-files/llvmpipe.sh b/display/renderer/device-files/llvmpipe.sh deleted file mode 100644 index d40c4ec..0000000 --- a/display/renderer/device-files/llvmpipe.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/system/xbin/bash -# -# Copyright (C) 2017 Jeremy Rand <jeremy@veclabs.net> -# Partially based on code by Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> and Filippo Fil Bergamo -# -# This file is part of "Replicant Renderer Switcher", a set of shell scripts to switch between -# the Android Software Renderer and the llvmpipe renderer in Replicant. -# -# Replicant Renderer Switcher is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Replicant Renderer Switcher 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 for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -set -euf -o pipefail - -grep -q "ro.libagl=0" /system/build.prop && renderer="llvmpipe" || renderer="android" - -if [ "${renderer}" == "llvmpipe" ] -then - echo "llvmpipe is already enabled!" - exit 1 -fi - -echo "Remounting system partition as writable..." -mount -o rw,remount /system - -echo "Enabling llvmpipe..." -sed "s/ro.libagl=1/ro.libagl=0/" -i /system/build.prop - -echo "Syncing filesystem..." -sync -sync - -echo "Remounting system partition as read-only..." -mount -o ro,remount /system - -echo "Syncing filesystem..." -sync -sync - -# https://android.stackexchange.com/a/139139 -echo "llvmpipe will be enabled after we reboot now..." -am start -a android.intent.action.REBOOT |