mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #303 from chrox/master
free blitbuffer as soon as tile is kicked out from cache
This commit is contained in:
10
defaults.lua
10
defaults.lua
@@ -34,6 +34,10 @@ DCREREADER_VIEW_MODE = "page"
|
||||
-- default to false
|
||||
DSHOWOVERLAP = false
|
||||
|
||||
-- show hidden files in filemanager
|
||||
-- default to false
|
||||
DSHOWHIDDENFILES = false
|
||||
|
||||
-- koptreader config defaults
|
||||
DKOPTREADER_CONFIG_FONT_SIZE = 1.0 -- range from 0.1 to 3.0
|
||||
DKOPTREADER_CONFIG_TEXT_WRAP = 0 -- 1 = on, 0 = off
|
||||
@@ -52,9 +56,9 @@ DKOPTREADER_CONFIG_CONTRAST = 1.0 -- range from 0.2 to 2.0
|
||||
DKOPTREADER_CONFIG_WORD_SAPCINGS = {0.05, 0.15, 0.375} -- range from 0.05 to 0.5
|
||||
DKOPTREADER_CONFIG_DEFAULT_WORD_SAPCING = 0.15 -- range from 0.05 to 0.5
|
||||
-- document languages for OCR
|
||||
DKOPTREADER_CONFIG_DOC_LANGS_TEXT = {"English", "Chinese_S", "Chinese_T"}
|
||||
DKOPTREADER_CONFIG_DOC_LANGS_CODE = {"eng", "chi_sim", "chi_tra"} -- ISO 639-3 language string,
|
||||
DKOPTREADER_CONFIG_DOC_DEFAULT_LANG_CODE = "eng" -- and make sure you have corresponding training data
|
||||
DKOPTREADER_CONFIG_DOC_LANGS_TEXT = {"English", "Chinese"}
|
||||
DKOPTREADER_CONFIG_DOC_LANGS_CODE = {"eng", "chi_sim"} -- language code, make sure you have corresponding training data
|
||||
DKOPTREADER_CONFIG_DOC_DEFAULT_LANG_CODE = "eng" -- that have filenames starting with the language codes
|
||||
|
||||
-- gesture detector defaults
|
||||
DGESDETECT_DISABLE_DOUBLE_TAP = true
|
||||
|
||||
@@ -36,3 +36,6 @@ function LvDEBUG(lv, ...)
|
||||
print("#"..line)
|
||||
end
|
||||
|
||||
function DEBUGBT()
|
||||
DEBUG(debug.traceback())
|
||||
end
|
||||
|
||||
@@ -28,6 +28,14 @@ function DocumentRegistry:openDocument(file)
|
||||
end
|
||||
end
|
||||
|
||||
TileCacheItem = CacheItem:new{}
|
||||
|
||||
function TileCacheItem:onFree()
|
||||
if self.bb.free then
|
||||
DEBUG("free blitbuffer", self.bb)
|
||||
self.bb:free()
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
This is an abstract interface to a document
|
||||
@@ -216,7 +224,7 @@ function Document:renderPage(pageno, rect, zoom, rotation, gamma, render_mode)
|
||||
end
|
||||
|
||||
-- prepare cache item with contained blitbuffer
|
||||
local tile = CacheItem:new{
|
||||
local tile = TileCacheItem:new{
|
||||
size = size.w * size.h / 2 + 64, -- estimation
|
||||
excerpt = size,
|
||||
pageno = pageno,
|
||||
@@ -296,7 +304,6 @@ function Document:getPageText(pageno)
|
||||
return text
|
||||
end
|
||||
|
||||
|
||||
-- load implementations:
|
||||
|
||||
require "document/pdfdocument"
|
||||
|
||||
@@ -100,7 +100,7 @@ end
|
||||
--[[
|
||||
auto detect bbox
|
||||
--]]
|
||||
function KoptInterface:getAutoBBox(doc, pageno)
|
||||
function KoptInterface:getAutoBBox(doc, pageno)
|
||||
local native_size = Document.getNativePageDimensions(doc, pageno)
|
||||
local bbox = {
|
||||
x0 = 0, y0 = 0,
|
||||
@@ -113,8 +113,9 @@ function KoptInterface:getAutoBBox(doc, pageno)
|
||||
if not cached then
|
||||
local page = doc._document:openPage(pageno)
|
||||
local kc = self:createContext(doc, pageno, bbox)
|
||||
--DEBUGBT()
|
||||
bbox.x0, bbox.y0, bbox.x1, bbox.y1 = page:getAutoBBox(kc)
|
||||
DEBUG("Auto detected bbox", bbox)
|
||||
--DEBUG("Auto detected bbox", bbox)
|
||||
Cache:insert(hash, CacheItem:new{ autobbox = bbox })
|
||||
page:close()
|
||||
kc:free()
|
||||
@@ -212,6 +213,8 @@ function KoptInterface:getRFPageDimensions(doc, pageno, zoom, rotation)
|
||||
end
|
||||
|
||||
function KoptInterface:renderPage(doc, pageno, rect, zoom, rotation, gamma, render_mode)
|
||||
--DEBUG("log memory usage at renderPage")
|
||||
--self:logMemoryUsage(pageno)
|
||||
if doc.configurable.text_wrap == 1 then
|
||||
return self:renderreflowedPage(doc, pageno, rect, zoom, rotation, render_mode)
|
||||
else
|
||||
@@ -240,7 +243,7 @@ function KoptInterface:renderreflowedPage(doc, pageno, rect, zoom, rotation, ren
|
||||
end
|
||||
local page = doc._document:openPage(pageno)
|
||||
-- prepare cache item with contained blitbuffer
|
||||
local tile = CacheItem:new{
|
||||
local tile = TileCacheItem:new{
|
||||
size = fullwidth * fullheight / 2 + 64, -- estimation
|
||||
excerpt = Geom:new{ w = fullwidth, h = fullheight },
|
||||
pageno = pageno,
|
||||
@@ -604,7 +607,6 @@ end
|
||||
get word and word box from position in native page
|
||||
]]--
|
||||
function KoptInterface:getWordFromNativePosition(doc, boxes, pos)
|
||||
DEBUG("boxes", boxes)
|
||||
local native_word_box = self:getWordFromBoxes(boxes, pos)
|
||||
local word_box = {
|
||||
word = native_word_box.word,
|
||||
@@ -726,7 +728,7 @@ end
|
||||
helper functions
|
||||
--]]
|
||||
function KoptInterface:logReflowDuration(pageno, dur)
|
||||
local file = io.open("reflowlog.txt", "a+")
|
||||
local file = io.open("reflow_dur_log.txt", "a+")
|
||||
if file then
|
||||
if file:seek("end") == 0 then -- write the header only once
|
||||
file:write("PAGE\tDUR\n")
|
||||
@@ -735,3 +737,25 @@ function KoptInterface:logReflowDuration(pageno, dur)
|
||||
file:close()
|
||||
end
|
||||
end
|
||||
|
||||
function KoptInterface:logMemoryUsage(pageno)
|
||||
local status_file = io.open("/proc/self/status", "r")
|
||||
local log_file = io.open("reflow_mem_log.txt", "a+")
|
||||
local data = -1
|
||||
if status_file then
|
||||
for line in status_file:lines() do
|
||||
local s, n
|
||||
s, n = line:gsub("VmData:%s-(%d+) kB", "%1")
|
||||
if n ~= 0 then data = tonumber(s) end
|
||||
if data ~= -1 then break end
|
||||
end
|
||||
status_file:close()
|
||||
end
|
||||
if log_file then
|
||||
if log_file:seek("end") == 0 then -- write the header only once
|
||||
log_file:write("PAGE\tMEM\n")
|
||||
end
|
||||
log_file:write(string.format("%s\t%s\n", pageno, data))
|
||||
log_file:close()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,6 +24,7 @@ KoptOptions = {
|
||||
{
|
||||
name = "trim_page",
|
||||
name_text = PAGE_CROP_STR,
|
||||
width = 225,
|
||||
toggle = {MANUAL_STR, AUTO_STR, SEMIAUTO_STR},
|
||||
alternate = false,
|
||||
values = {0, 1, 2},
|
||||
@@ -187,7 +188,7 @@ KoptOptions = {
|
||||
name = "defect_size",
|
||||
name_text = DEFECT_SIZE_STR,
|
||||
toggle = {SMALL_STR, MEDIUM_STR, LARGE_STR},
|
||||
values = {1.0, 8.0, 15.0},
|
||||
values = {1.0, 3.0, 5.0},
|
||||
default_value = DKOPTREADER_CONFIG_DEFECT_SIZE,
|
||||
event = "DefectSizeUpdate",
|
||||
},
|
||||
|
||||
@@ -99,7 +99,8 @@ function Device:isKobo()
|
||||
end
|
||||
|
||||
function Device:hasNoKeyboard()
|
||||
return self:isTouchDevice() or (self:getModel() == "Kindle4")
|
||||
local model = self:getModel()
|
||||
return (model == "KindlePaperWhite") or (model == "KindleTouch") or self:isKobo()
|
||||
end
|
||||
|
||||
function Device:hasKeyboard()
|
||||
|
||||
@@ -434,7 +434,6 @@ function ReaderView:onSetScreenMode(new_mode, rotation)
|
||||
|
||||
if new_mode == "landscape" and self.document.info.has_pages then
|
||||
self.ui:handleEvent(Event:new("SetZoomMode", "contentwidth"))
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -482,6 +481,7 @@ function ReaderView:onReadSettings(config)
|
||||
self.render_mode = config:readSetting("render_mode") or 0
|
||||
local screen_mode = config:readSetting("screen_mode")
|
||||
if screen_mode then
|
||||
Screen:setScreenMode(screen_mode)
|
||||
table.insert(self.ui.postInitCallback, function()
|
||||
self:onSetScreenMode(screen_mode, config:readSetting("rotation_mode"))
|
||||
end)
|
||||
|
||||
@@ -323,6 +323,7 @@ function ConfigOption:init()
|
||||
|
||||
if self.options[c].toggle then
|
||||
local switch = ToggleSwitch:new{
|
||||
width = scaleByDPI(self.options[c].width or 216),
|
||||
name = self.options[c].name,
|
||||
toggle = self.options[c].toggle,
|
||||
alternate = self.options[c].alternate,
|
||||
|
||||
@@ -6,7 +6,7 @@ FileChooser = Menu:extend{
|
||||
no_title = true,
|
||||
path = lfs.currentdir(),
|
||||
parent = nil,
|
||||
show_hidden = false,
|
||||
show_hidden = DSHOWHIDDENFILES,
|
||||
filter = function(filename) return true end,
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ function ItemShortCutIcon:init()
|
||||
end
|
||||
|
||||
--@TODO calculate font size by icon size 01.05 2012 (houqp)
|
||||
local sc_face = nil
|
||||
if self.key:len() > 1 then
|
||||
sc_face = Font:getFace("ffont", 14)
|
||||
else
|
||||
@@ -49,6 +50,7 @@ function ItemShortCutIcon:init()
|
||||
TextWidget:new{
|
||||
text = self.key,
|
||||
face = sc_face,
|
||||
bgcolor = background/15,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -123,7 +125,8 @@ function MenuItem:init()
|
||||
doc = "Select Menu Item",
|
||||
},
|
||||
}
|
||||
else
|
||||
end
|
||||
if Device:hasKeyboard() then
|
||||
self.active_key_events = {
|
||||
Select = { {"Press"}, doc = "chose selected item" },
|
||||
}
|
||||
@@ -261,6 +264,10 @@ function Menu:_recalculateDimen()
|
||||
}
|
||||
self.perpage = math.floor((self.dimen.h - self.dimen.x) / self.item_dimen.h) - 2
|
||||
self.page_num = math.ceil(#self.item_table / self.perpage)
|
||||
-- update page info layout, fixed #281
|
||||
if self.page_info then
|
||||
self.page_info:resetLayout()
|
||||
end
|
||||
end
|
||||
|
||||
function Menu:init()
|
||||
@@ -374,7 +381,8 @@ function Menu:init()
|
||||
range = self.dimen,
|
||||
}
|
||||
}
|
||||
else
|
||||
end
|
||||
if Device:hasKeyboard() then
|
||||
-- set up keyboard events
|
||||
self.key_events.Close = { {"Back"}, doc = _("close menu") }
|
||||
self.key_events.NextPage = {
|
||||
|
||||
@@ -11,6 +11,8 @@ end
|
||||
ToggleSwitch = InputContainer:new{
|
||||
width = scaleByDPI(216),
|
||||
height = scaleByDPI(30),
|
||||
bgcolor = 0, -- unfoused item color
|
||||
fgcolor = 7, -- focused item color
|
||||
}
|
||||
|
||||
function ToggleSwitch:init()
|
||||
@@ -65,13 +67,13 @@ function ToggleSwitch:update()
|
||||
local pos = self.position
|
||||
for i=1,#self.toggle_content do
|
||||
if pos == i then
|
||||
self.toggle_content[i].color = 7
|
||||
self.toggle_content[i].background = 7
|
||||
self.toggle_content[i][1][1].bgcolor = 0.5
|
||||
self.toggle_content[i].color = self.fgcolor
|
||||
self.toggle_content[i].background = self.fgcolor
|
||||
self.toggle_content[i][1][1].bgcolor = self.fgcolor/15
|
||||
self.toggle_content[i][1][1].fgcolor = 0.0
|
||||
else
|
||||
self.toggle_content[i].color = 0
|
||||
self.toggle_content[i].background = 0
|
||||
self.toggle_content[i].color = self.bgcolor
|
||||
self.toggle_content[i].background = self.bgcolor
|
||||
self.toggle_content[i][1][1].bgcolor = 0.0
|
||||
self.toggle_content[i][1][1].fgcolor = 1.0
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user