free blitbuffer as soon as tile is kicked out from cache

other than waiting for the lazy garbage collector of lua
pull/303/head
chrox 11 years ago
parent 3934176b6c
commit 39da1251ec

@ -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"

@ -212,6 +212,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 +242,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 +606,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 +727,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 +736,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

Loading…
Cancel
Save