decouple device from document modules

pull/4721/head
Qingping Hou 6 years ago committed by Frans de Jonge
parent 2ba480b41d
commit 02eca23649

@ -7,7 +7,8 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local md5 = require("ffi/MD5")
if require("device"):isAndroid() then
local runtimectl = require("runtimectl")
if runtimectl.should_restrict_JIT then
require("jit").off(true, true)
end

@ -99,10 +99,6 @@ function Device:init()
end
self.screen.isColorScreen = self.hasColorScreen
self.screen.isColorEnabled = function()
if G_reader_settings:has("color_rendering") then return G_reader_settings:isTrue("color_rendering") end
return self.screen.isColorScreen()
end
self.screen.isBGRFrameBuffer = self.hasBGRFrameBuffer

@ -5,7 +5,6 @@ local Configurable = require("configurable")
local DrawContext = require("ffi/drawcontext")
local Geom = require("ui/geometry")
local Math = require("optmath")
local Screen = require("device").screen
local TileCacheItem = require("document/tilecacheitem")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
@ -291,7 +290,7 @@ function Document:findText()
end
function Document:updateColorRendering()
if self.is_color_capable and Screen:isColorEnabled() then
if self.is_color_capable and Runtimectl.is_color_rendering_enabled then
self.render_color = true
else
self.render_color = false

@ -1,6 +1,6 @@
local Document = require("document/document")
local DrawContext = require("ffi/drawcontext")
local Screen = require("device").screen
local Runtimectl = require("runtimectl")
local pic = nil
local PicDocument = Document:new{
@ -15,7 +15,7 @@ function PicDocument:init()
self:updateColorRendering()
if not pic then pic = require("ffi/pic") end
-- pic.color needs to be true before opening document to allow toggling color
pic.color = Screen.isColorScreen()
pic.color = Runtimectl.is_color_rendering_enabled
local ok
ok, self._document = pcall(pic.openDocument, self.file)
if not ok then

@ -1,14 +1,17 @@
local Event = require("ui/event")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local Runtimectl = require("runtimectl")
local _ = require("gettext")
return {
text = _("Color rendering"),
enabled_func = Screen.isColorScreen,
checked_func = Screen.isColorEnabled,
checked_func = function() return Runtimectl.is_color_rendering_enabled end,
callback = function()
G_reader_settings:saveSetting("color_rendering", not Screen.isColorEnabled())
Runtimectl:setColorRenderingEnabled(not Runtimectl.is_color_rendering_enabled)
G_reader_settings:saveSetting(
"color_rendering", Runtimectl.is_color_rendering_enabled)
UIManager:broadcastEvent(Event:new("ColorRenderingUpdate"))
end
}

@ -8,7 +8,8 @@ local CacheItem = require("cacheitem")
local BlitBuffer = require("ffi/blitbuffer")
local logger = require("logger")
if require("device"):isAndroid() then
local runtimectl = require("runtimectl")
if runtimectl.should_restrict_JIT then
require("jit").off(true, true)
end

@ -33,7 +33,8 @@ local WidgetContainer = require("ui/widget/container/widgetcontainer")
local _ = require("gettext")
local Screen = require("device").screen
if require("device"):isAndroid() then
local runtimectl = require("runtimectl")
if runtimectl.should_restrict_JIT then
require("jit").off(true, true)
end

@ -16,7 +16,8 @@ It handles event propagation and painting (with different alignments) for its ch
local Geom = require("ui/geometry")
local Widget = require("ui/widget/widget")
if require("device"):isAndroid() then
local runtimectl = require("runtimectl")
if runtimectl.should_restrict_JIT then
require("jit").off(true, true)
end

@ -8,10 +8,10 @@ local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange")
local InputContainer = require("ui/widget/container/inputcontainer")
local Mupdf = require("ffi/mupdf")
local Screen = require("device").screen
local TimeVal = require("ui/timeval")
local logger = require("logger")
local util = require("util")
local Runtimectl = require("runtimectl")
local HtmlBoxWidget = InputContainer:new{
bb = nil,
@ -89,7 +89,7 @@ function HtmlBoxWidget:_render()
-- In pdfdocument.lua, color is activated only at the moment of
-- rendering and then immediately disabled, for safety with kopt.
-- We do the same here.
Mupdf.color = Screen:isColorEnabled()
Mupdf.color = Runtimectl.is_color_rendering_enabled
local page = self.document:openPage(self.page_number)
local dc = DrawContext.new()

@ -361,14 +361,18 @@ function TextBoxWidget:_renderText(start_row_idx, end_row_idx)
if self._bb then self._bb:free() end
local bbtype = nil
if self.line_num_to_image and self.line_num_to_image[start_row_idx] then
-- Whether Screen:isColorEnabled() or not, it's best to always use BBRGB32
-- and alphablitFrom() for the best display of various images:
-- With greyscale screen TYPE_BB8 (the default, and what we would
-- have chosen when not Screen:isColorEnabled()):
-- alphablitFrom: some images are all white (ex: flags on Milan, Ilkhanides on wiki.fr)
-- blitFrom: some images have a black background (ex: RDA, Allemagne on wiki.fr)
-- Whether Runtimectl.is_color_rendering_enabled or not, it's best to
-- always use BBRGB32 and alphablitFrom() for the best display of
-- various images:
-- With greyscale screen TYPE_BB8 (the default, and
-- what we would have chosen when not Runtimectl.is_color_rendering_enabled):
-- alphablitFrom: some images are all white (ex: flags on Milan,
-- Ilkhanides on wiki.fr)
-- blitFrom: some images have a black background (ex: RDA,
-- Allemagne on wiki.fr)
-- With TYPE_BBRGB32:
-- blitFrom: some images have a black background (ex: RDA, Allemagne on wiki.fr)
-- blitFrom: some images have a black background (ex: RDA,
-- Allemagne on wiki.fr)
-- alphablitFrom: all these images looks good, with a white background
bbtype = Blitbuffer.TYPE_BBRGB32
end

@ -19,6 +19,7 @@ local DataStorage = require("datastorage")
pcall(dofile, DataStorage:getDataDir() .. "/defaults.persistent.lua")
require("setupkoenv")
Runtimectl = require("runtimectl")
io.stdout:write(" [*] Version: ", require("version"):getCurrentRevision(), "\n\n")
io.stdout:flush()
@ -34,6 +35,23 @@ if lang_locale then
_.changeLang(lang_locale)
end
-- setup various runtime control
local Device = require("device")
if Device:isAndroid() then
Runtimectl:restrictJIT()
end
if G_reader_settings:has("color_rendering") then
Runtimectl:setColorRenderingEnabled(G_reader_settings:isTrue("color_rendering"))
else
Runtimectl:setColorRenderingEnabled(Device.screen.isColorScreen())
end
local dpi_override = G_reader_settings:readSetting("screen_dpi")
if dpi_override ~= nil then
Device.screen:setDPI(dpi_override)
end
-- option parsing:
local longopts = {
debug = "d",
@ -95,7 +113,6 @@ while argidx <= #ARGV do
end
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Font = require("ui/font")
local QuickStart = require("ui/quickstart")
local UIManager = require("ui/uimanager")

Loading…
Cancel
Save