diff --git a/base b/base index e27702835..08090378e 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit e277028350da06a0aac52a0c514b934ed83ab335 +Subproject commit 08090378e2001004a31146bd82b2a411ea083dd2 diff --git a/frontend/device/input.lua b/frontend/device/input.lua index e21baa09e..dd9df6d2b 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -232,6 +232,8 @@ function Input:init() self.input = require("ffi/input_android") elseif self.device:isPocketBook() then self.input = require("ffi/input_pocketbook") + elseif self.device:isRemarkable() and os.getenv("KO_USE_QTFB") == "1" then + self.input = require("ffi/input_qtfb") else self.input = require("libs/libkoreader-input") end diff --git a/frontend/device/remarkable/device.lua b/frontend/device/remarkable/device.lua index 6d29e5de6..37c39ebca 100644 --- a/frontend/device/remarkable/device.lua +++ b/frontend/device/remarkable/device.lua @@ -32,6 +32,7 @@ local is_rmpp = rm_model == "reMarkable Ferrari" local is_rmppm = rm_model == "reMarkable Chiappa" local has_csl = util.which("csl") local is_qtfb_shimmed = (os.getenv("LD_PRELOAD") or ""):find("qtfb%-shim") ~= nil +local is_qtfb_native = os.getenv("KO_USE_QTFB") ~= nil if is_rmpp then screen_width = 1620 -- unscaled_size_check: ignore @@ -202,13 +203,16 @@ function Remarkable:init() logger.info(string.format("QTFB shimmed?: %s", is_qtfb_shimmed)) + logger.info(string.format("QTFB native?: %s", is_qtfb_native)) + -- experiment -- logger.info("PPID:") -- local parent_process = os.execute("echo $PPID") -- os.execute("ps | grep $PPID") -- logger.info(string.format("parent process is oxide?: %s", parent_process_is_oxide)) - self.screen = require("ffi/framebuffer_mxcfb"):new{ + local fb_module = os.getenv("KO_USE_QTFB") and "ffi/framebuffer_qtfb" or "ffi/framebuffer_mxcfb" + self.screen = require(fb_module):new{ device = self, debug = logger.dbg, wf_level = G_reader_settings:readSetting("wf_level") or 2, @@ -222,7 +226,7 @@ function Remarkable:init() local event_map = dofile("frontend/device/remarkable/event_map.lua") -- If we are launched while Oxide or xochitl is running, remove Power from the event map - if oxide_running or is_qtfb_shimmed then + if oxide_running or is_qtfb_shimmed or is_qtfb_native then event_map[116] = nil event_map[143] = nil event_map[20001] = nil @@ -460,11 +464,13 @@ function Remarkable:setEventHandlers(UIManager) end if is_rm2 then + if is_qtfb_native then return Remarkable2 end if not os.getenv("RM2FB_SHIM") and not is_qtfb_shimmed then error("reMarkable 2 requires a RM2FB server and client to work (https://github.com/ddvk/remarkable2-framebuffer or https://github.com/asivery/rmpp-qtfb-shim)") end return Remarkable2 elseif is_rmpp then + if is_qtfb_native then return RemarkablePaperPro end if not is_qtfb_shimmed then error("reMarkable Paper Pro requires a RM2FB server and client to work (https://github.com/asivery/rm-appload)") end @@ -473,6 +479,7 @@ elseif is_rmpp then end return RemarkablePaperPro elseif is_rmppm then + if is_qtfb_native then return RemarkablePaperProMove end if not is_qtfb_shimmed then error("reMarkable Paper Pro Move requires a RM2FB server and client to work (https://github.com/asivery/rm-appload)") end diff --git a/make/remarkable.mk b/make/remarkable.mk index c6f8dc70a..9a14431ec 100644 --- a/make/remarkable.mk +++ b/make/remarkable.mk @@ -15,6 +15,7 @@ update-prepare: all $(SYMLINK) $(REMARKABLE_DIR)/koreader.sh $(INSTALL_DIR)/koreader/ $(SYMLINK) resources/koreader.png $(INSTALL_DIR)/koreader/icon.png $(SYMLINK) $(REMARKABLE_DIR)/external.manifest.json $(INSTALL_DIR)/koreader/ + $(SYMLINK) $(REMARKABLE_DIR)/external.manifest.shim.json $(INSTALL_DIR)/koreader/ ifeq (remarkable,$(TARGET)) $(SYMLINK) $(REMARKABLE_DIR)/README.md $(INSTALL_DIR)/koreader/README_remarkable.md $(SYMLINK) $(REMARKABLE_DIR)/button-listen.service $(INSTALL_DIR)/koreader/ diff --git a/platform/remarkable/external.manifest.json b/platform/remarkable/external.manifest.json index cba1ed449..6fb574584 100644 --- a/platform/remarkable/external.manifest.json +++ b/platform/remarkable/external.manifest.json @@ -2,13 +2,7 @@ "name": "KOReader", "application": "koreader.sh", "environment": { - "LD_PRELOAD": "/home/root/shims/qtfb-shim.so", - "QTFB_SHIM_MODEL": "false", - "QTFB_SHIM_INPUT_MODE": "NATIVE", - "QTFB_SHIM_MODE": "N_RGB565", - "QTFB_SHIM_RESPECT_FULL_REFRESH_REQUESTS": "1", - "KO_DONT_GRAB_INPUT": "1", - "KO_DONT_SET_DEPTH": "1" + "KO_USE_QTFB": "1" }, "qtfb": true } diff --git a/platform/remarkable/external.manifest.shim.json b/platform/remarkable/external.manifest.shim.json new file mode 100644 index 000000000..cba1ed449 --- /dev/null +++ b/platform/remarkable/external.manifest.shim.json @@ -0,0 +1,14 @@ +{ + "name": "KOReader", + "application": "koreader.sh", + "environment": { + "LD_PRELOAD": "/home/root/shims/qtfb-shim.so", + "QTFB_SHIM_MODEL": "false", + "QTFB_SHIM_INPUT_MODE": "NATIVE", + "QTFB_SHIM_MODE": "N_RGB565", + "QTFB_SHIM_RESPECT_FULL_REFRESH_REQUESTS": "1", + "KO_DONT_GRAB_INPUT": "1", + "KO_DONT_SET_DEPTH": "1" + }, + "qtfb": true +} diff --git a/platform/remarkable/koreader.sh b/platform/remarkable/koreader.sh index 7fb1eaa49..f7f371b3f 100755 --- a/platform/remarkable/koreader.sh +++ b/platform/remarkable/koreader.sh @@ -19,6 +19,25 @@ fi # we're always starting from our working directory cd "${KOREADER_DIR}" || exit +# reMarkable QTFB setup +if [ -n "${KO_USE_QTFB}" ]; then + export KO_DONT_GRAB_INPUT=1 + export KO_DONT_SET_DEPTH=1 +fi + +fbink_wrapped() { + if [ -n "${KO_USE_QTFB}" ]; then + LD_PRELOAD="/home/root/shims/qtfb-shim.so" \ + QTFB_SHIM_MODEL="false" \ + QTFB_SHIM_INPUT_MODE="NATIVE" \ + QTFB_SHIM_MODE="N_RGB565" \ + QTFB_SHIM_RESPECT_FULL_REFRESH_REQUESTS="1" \ + ./fbink "$@" + else + ./fbink "$@" + fi +} + # reMarkable 2 check IFS= read -r MACHINE_TYPE <"/sys/devices/soc0/machine" if [ "reMarkable 2.0" = "${MACHINE_TYPE}" ]; then @@ -38,13 +57,13 @@ ko_update_check() { systemctl stop button-listen fi - ./fbink -q -y -7 -pmh "Updating KOReader" + fbink_wrapped -q -y -7 -pmh "Updating KOReader" # Keep a copy of the old manifest for cleaning leftovers later. cp "${KOREADER_DIR}/ota/package.index" /tmp/ # Setup the FBInk daemon export FBINK_NAMED_PIPE="/tmp/koreader.fbink" rm -f "${FBINK_NAMED_PIPE}" - FBINK_PID="$(./fbink --daemon 1 %KOREADER% -q -y -6 -P 0)" + FBINK_PID="$(fbink_wrapped --daemon 1 %KOREADER% -q -y -6 -P 0)" # NOTE: See frontend/ui/otamanager.lua for a few more details on how we squeeze a percentage out of tar's checkpoint feature # NOTE: %B should always be 512 in our case, so let stat do part of the maths for us instead of using %s ;). FILESIZE="$(stat -c %b "${NEWUPDATE}")" @@ -59,12 +78,12 @@ ko_update_check() { mv "${NEWUPDATE}" "${INSTALLED}" # Cleanup leftovers from previous install. (cd "${UNPACK_DIR}" && grep -xvFf "${KOREADER_DIR}/ota/package.index" /tmp/package.index | xargs -r rm -vf) - ./fbink -q -y -6 -pm "Update successful :)" - ./fbink -q -y -5 -pm "KOReader will start momentarily . . ." + fbink_wrapped -q -y -6 -pm "Update successful :)" + fbink_wrapped -q -y -5 -pm "KOReader will start momentarily . . ." else # Uh oh... - ./fbink -q -y -6 -pmh "Update failed :(" - ./fbink -q -y -5 -pm "KOReader may fail to function properly!" + fbink_wrapped -q -y -6 -pmh "Update failed :(" + fbink_wrapped -q -y -5 -pm "KOReader may fail to function properly!" fi rm -f /tmp/package.index "${NEWUPDATE}" # always purge newupdate to prevent update loops unset CPOINTS FBINK_NAMED_PIPE @@ -88,30 +107,34 @@ fi # export dict directory export STARDICT_DATA_DIR="data/dict" -# We'll want to ensure Portrait rotation to allow us to use faster blitting codepaths @ 8bpp, -# so remember the current one before fbdepth does its thing. -ORIG_FB_ROTA="$(./fbdepth -o)" -# In the same vein, swap to 8bpp, -# because 16bpp is the worst idea in the history of time, as RGB565 is generally a PITA without hardware blitting, -# and 32bpp usually gains us nothing except a performance hit (we're not Qt5 with its QPainter constraints). -# The reduced size & complexity should hopefully make things snappier, -# (and hopefully prevent the JIT from going crazy on high-density screens...). -# NOTE: Even though both pickel & Nickel appear to restore their preferred fb setup, we'll have to do it ourselves, -# as they fail to flip the grayscale flag properly. Plus, we get to play nice with every launch method that way. -# So, remember the current bitdepth, so we can restore it on exit. -ORIG_FB_BPP="$(./fbdepth -g)" -echo "Original fb settings: bitdepth = ${ORIG_FB_BPP}, rotation = ${ORIG_FB_ROTA}" >>crash.log 2>&1 +ORIG_FB_BPP="" +ORIG_FB_ROTA="" +if [ -z "${KO_DONT_SET_DEPTH}" ] && [ -z "${KO_USE_QTFB}" ]; then + # We'll want to ensure Portrait rotation to allow us to use faster blitting codepaths @ 8bpp, + # so remember the current one before fbdepth does its thing. + ORIG_FB_ROTA="$(./fbdepth -o)" + # In the same vein, swap to 8bpp, + # because 16bpp is the worst idea in the history of time, as RGB565 is generally a PITA without hardware blitting, + # and 32bpp usually gains us nothing except a performance hit (we're not Qt5 with its QPainter constraints). + # The reduced size & complexity should hopefully make things snappier, + # (and hopefully prevent the JIT from going crazy on high-density screens...). + # NOTE: Even though both pickel & Nickel appear to restore their preferred fb setup, we'll have to do it ourselves, + # as they fail to flip the grayscale flag properly. Plus, we get to play nice with every launch method that way. + # So, remember the current bitdepth, so we can restore it on exit. + ORIG_FB_BPP="$(./fbdepth -g)" + echo "Original fb settings: bitdepth = ${ORIG_FB_BPP}, rotation = ${ORIG_FB_ROTA}" >>crash.log 2>&1 -# Sanity check... -case "${ORIG_FB_BPP}" in - 8) ;; - 16) ;; - 32) ;; - *) - # Uh oh? Don't do anything... - unset ORIG_FB_BPP - ;; -esac + # Sanity check... + case "${ORIG_FB_BPP}" in + 8) ;; + 16) ;; + 32) ;; + *) + # Uh oh? Don't do anything... + unset ORIG_FB_BPP + ;; + esac +fi # The actual swap is done in a function, because we can disable it in the Developer settings, and we want to honor it on restart. ko_do_fbdepth() { @@ -182,26 +205,26 @@ while [ ${RETURN_VALUE} -ne 0 ]; do viewWidth=600 viewHeight=800 FONTH=16 - eval "$(./fbink -e | tr ';' '\n' | grep -e viewWidth -e viewHeight -e FONTH | tr '\n' ';')" + eval "$(fbink_wrapped -e | tr ';' '\n' | grep -e viewWidth -e viewHeight -e FONTH | tr '\n' ';')" # Compute margins & sizes relative to the screen's resolution, so we end up with a similar layout, no matter the device. # Height @ ~56.7%, w/ a margin worth 1.5 lines bombHeight=$((viewHeight / 2 + viewHeight / 15)) bombMargin=$((FONTH + FONTH / 2)) # With a little notice at the top of the screen, on a big gray screen of death ;). - ./fbink -q -b -c -B GRAY9 -m -y 1 "Don't Panic! (Crash n°${CRASH_COUNT} -> ${RETURN_VALUE})" + fbink_wrapped -q -b -c -B GRAY9 -m -y 1 "Don't Panic! (Crash n°${CRASH_COUNT} -> ${RETURN_VALUE})" if [ ${CRASH_COUNT} -eq 1 ]; then # Warn that we're sleeping for a bit... - ./fbink -q -b -O -m -y 2 "KOReader will restart in 15 sec." + fbink_wrapped -q -b -O -m -y 2 "KOReader will restart in 15 sec." fi # U+1F4A3, the hard way, because we can't use \u or \U escape sequences... # shellcheck disable=SC2039,SC3003 - ./fbink -q -b -O -m -t regular=./fonts/freefont/FreeSerif.ttf,px=${bombHeight},top=${bombMargin} -- $'\xf0\x9f\x92\xa3' + fbink_wrapped -q -b -O -m -t regular=./fonts/freefont/FreeSerif.ttf,px=${bombHeight},top=${bombMargin} -- $'\xf0\x9f\x92\xa3' # And then print the tail end of the log on the bottom of the screen... crashLog="$(tail -n 25 crash.log | sed -e 's/\t/ /g')" # The idea for the margins being to leave enough room for an fbink -Z bar, small horizontal margins, and a font size based on what 6pt looked like @ 265dpi - ./fbink -q -b -O -t regular=./fonts/droid/DroidSansMono.ttf,top=$((viewHeight / 2 + FONTH * 2 + FONTH / 2)),left=$((viewWidth / 60)),right=$((viewWidth / 60)),px=$((viewHeight / 64)) -- "${crashLog}" + fbink_wrapped -q -b -O -t regular=./fonts/droid/DroidSansMono.ttf,top=$((viewHeight / 2 + FONTH * 2 + FONTH / 2)),left=$((viewWidth / 60)),right=$((viewWidth / 60)),px=$((viewHeight / 64)) -- "${crashLog}" # So far, we hadn't triggered an actual screen refresh, do that now, to make sure everything is bundled in a single flashing refresh. - ./fbink -q -f -s + fbink_wrapped -q -f -s # Cue a lemming's faceplant sound effect! { @@ -243,12 +266,14 @@ done # Restore original fb bitdepth if need be... # Since we also (almost) always enforce Portrait, we also have to restore the original rotation no matter what ;). -if [ -n "${ORIG_FB_BPP}" ]; then - echo "Restoring original fb bitdepth @ ${ORIG_FB_BPP}bpp & rotation @ ${ORIG_FB_ROTA}" >>crash.log 2>&1 - ./fbdepth -d "${ORIG_FB_BPP}" -r "${ORIG_FB_ROTA}" >>crash.log 2>&1 -else - echo "Restoring original fb rotation @ ${ORIG_FB_ROTA}" >>crash.log 2>&1 - ./fbdepth -r "${ORIG_FB_ROTA}" >>crash.log 2>&1 +if [ -z "${KO_DONT_SET_DEPTH}" ] && [ -z "${KO_USE_QTFB}" ]; then + if [ -n "${ORIG_FB_BPP}" ]; then + echo "Restoring original fb bitdepth @ ${ORIG_FB_BPP}bpp & rotation @ ${ORIG_FB_ROTA}" >>crash.log 2>&1 + ./fbdepth -d "${ORIG_FB_BPP}" -r "${ORIG_FB_ROTA}" >>crash.log 2>&1 + else + echo "Restoring original fb rotation @ ${ORIG_FB_ROTA}" >>crash.log 2>&1 + ./fbdepth -r "${ORIG_FB_ROTA}" >>crash.log 2>&1 + fi fi exit ${RETURN_VALUE}