Skip to content

Commit

Permalink
kopt: minor factorization
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit-pierre committed Nov 20, 2024
1 parent fa20344 commit b75f682
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions frontend/document/koptinterface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ function KoptInterface:getSemiAutoBBox(doc, pageno)
end
end

function KoptInterface:reflowPage(doc, pageno, bbox, background)
logger.dbg("reflowing page", pageno, background and "in background" or "in foreground")
local kc = self:createContext(doc, pageno, bbox)
if background then
kc:setPreCache()
self.bg_thread = true
end
local page = doc._document:openPage(pageno)
page:reflow(kc, doc.render_mode)
page:close()
return kc
end

--[[--
Get cached koptcontext for a certain page.
Expand All @@ -277,13 +290,9 @@ function KoptInterface:getCachedContext(doc, pageno)
local cached = DocCache:check(hash, ContextCacheItem)
if not cached then
-- If kctx is not cached, create one and get reflowed bmp in foreground.
local kc = self:createContext(doc, pageno, bbox)
local page = doc._document:openPage(pageno)
logger.dbg("reflowing page", pageno, "in foreground")
-- reflow page
--local secs, usecs = FFIUtil.gettime()
page:reflow(kc, doc.render_mode)
page:close()
local kc = self:reflowPage(doc, pageno, bbox, false)
-- reflow page
--local nsecs, nusecs = FFIUtil.gettime()
--local dur = nsecs - secs + (nusecs - usecs) / 1000000
--self:logReflowDuration(pageno, dur)
Expand Down Expand Up @@ -472,20 +481,11 @@ function KoptInterface:hintReflowedPage(doc, pageno, zoom, rotation, gamma, hint
if hinting then
CanvasContext:enableCPUCores(2)
end

local kc = self:createContext(doc, pageno, bbox)
local page = doc._document:openPage(pageno)
logger.dbg("hinting page", pageno, "in background")
-- reflow will return immediately and running in background thread
kc:setPreCache()
self.bg_thread = true
page:reflow(kc, doc.render_mode)
page:close()
local kc = self:reflowPage(doc, pageno, bbox, true)
DocCache:insert(hash, ContextCacheItem:new{
size = self.last_context_size or self.default_context_size,
kctx = kc,
})

-- We'll wait until the background thread is done to go back to a single core, as this returns immediately!
-- c.f., :waitForContext
end
Expand Down

0 comments on commit b75f682

Please sign in to comment.