From edec69ac8b4f2bbc941feb00ce20aa6e47e81318 Mon Sep 17 00:00:00 2001 From: yparitcher Date: Sun, 8 Nov 2020 16:55:11 -0500 Subject: [PATCH] [CRe] Tweak nightmode and CRe call cache interaction (#6859) Simplify 4caf8f28 (#6854), allowing us not to track nightmode in two places. --- frontend/apps/reader/modules/readertypeset.lua | 1 - frontend/device/devicelistener.lua | 2 +- frontend/document/credocument.lua | 12 +++++------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/frontend/apps/reader/modules/readertypeset.lua b/frontend/apps/reader/modules/readertypeset.lua index 8991d80fd..2acc67e4a 100644 --- a/frontend/apps/reader/modules/readertypeset.lua +++ b/frontend/apps/reader/modules/readertypeset.lua @@ -108,7 +108,6 @@ function ReaderTypeset:onReadSettings(config) end self:toggleImageScaling(self.smooth_scaling) - self.ui.document:setNightMode(Screen.night_mode) -- default to automagic nightmode-friendly handling of images self.nightmode_images = config:readSetting("nightmode_images") if self.nightmode_images == nil then diff --git a/frontend/device/devicelistener.lua b/frontend/device/devicelistener.lua index d841e92cf..d2b78768a 100644 --- a/frontend/device/devicelistener.lua +++ b/frontend/device/devicelistener.lua @@ -28,7 +28,7 @@ function DeviceListener:onToggleNightMode() Screen:toggleNightMode() -- Make sure CRe will bypass the call cache if self.ui and self.ui.document and self.ui.document.provider == "crengine" then - self.ui.document:setNightMode(not night_mode) + self.ui.document:resetCallCache() end UIManager:setDirty("all", "full") UIManager:ToggleNightMode(not night_mode) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index c791469cd..d92e1a37a 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -25,7 +25,6 @@ local CreDocument = Document:new{ _view_mode = nil, _smooth_scaling = false, _nightmode_images = true, - _nightmode = false, line_space_percent = 100, default_font = "Noto Serif", @@ -424,7 +423,7 @@ function CreDocument:drawCurrentView(target, x, y, rect, pos) --local start_ts = FFIUtil.getTimestamp() self._drawn_images_count, self._drawn_images_surface_ratio = - self._document:drawCurrentPage(self.buffer, self.render_color, self._nightmode and self._nightmode_images, self._smooth_scaling, Screen.sw_dithering) + self._document:drawCurrentPage(self.buffer, self.render_color, Screen.night_mode and self._nightmode_images, self._smooth_scaling, Screen.sw_dithering) --local end_ts = FFIUtil.getTimestamp() --print(string.format("CreDocument:drawCurrentView: Rendering took %9.3f ms", (end_ts - start_ts) * 1000)) @@ -878,11 +877,6 @@ function CreDocument:setNightmodeImages(toggle) self._nightmode_images = toggle end -function CreDocument:setNightMode(toggle) - logger.dbg("CreDocument: set nightmode", toggle) - self._nightmode = toggle -end - function CreDocument:setFloatingPunctuation(enabled) --- @fixme occasional segmentation fault when toggling floating punctuation logger.dbg("CreDocument: set floating punctuation", enabled) @@ -1055,6 +1049,9 @@ function CreDocument:register(registry) registry:addProvider("py", "text/x-python", self, 90) end +-- no-op that will be wrapped by setupCallCache +function CreDocument:resetCallCache() end + -- Optimise usage of some of the above methods by caching their results, -- either globally, or per page/pos for those whose result may depend on -- current page number or y-position. @@ -1274,6 +1271,7 @@ function CreDocument:setupCallCache() elseif name:sub(1,6) == "update" then add_reset = true elseif name:sub(1,6) == "enable" then add_reset = true elseif name == "zoomFont" then add_reset = true -- not used by koreader + elseif name == "resetCallCache" then add_reset = true -- These may have crengine do native highlight or unhighlight -- (we could keep the original buffer and use a scratch buffer while