mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add pre-rendering in pdf/djvu readers
"HintPage" tasks are scheduled into the execution stack of UIManager after each page drawing. These tasks should be checked immediately after screen is refreshed so tasks are double-checked in the main loop.
This commit is contained in:
@@ -50,6 +50,7 @@ function ReaderView:paintTo(bb, x, y)
|
||||
self.state.zoom,
|
||||
self.state.rotation,
|
||||
self.render_mode)
|
||||
UIManager:scheduleIn(0, function() self.ui:handleEvent(Event:new("HintPage")) end)
|
||||
else
|
||||
if self.view_mode == "page" then
|
||||
self.ui.document:drawCurrentViewByPage(
|
||||
@@ -162,6 +163,10 @@ function ReaderView:onRotationUpdate(rotation)
|
||||
self:recalculate()
|
||||
end
|
||||
|
||||
function ReaderView:onHintPage()
|
||||
self.ui.document:hintPage(self.state.page+1, self.state.zoom, self.state.rotation)
|
||||
end
|
||||
|
||||
function ReaderView:onCloseDocument()
|
||||
self.ui.doc_settings:saveSetting("render_mode", self.render_mode)
|
||||
end
|
||||
|
||||
@@ -106,6 +106,39 @@ function UIManager:sendEvent(event)
|
||||
end
|
||||
end
|
||||
|
||||
function UIManager:checkTasks()
|
||||
local now = { util.gettime() }
|
||||
|
||||
-- check if we have timed events in our queue and search next one
|
||||
local wait_until = nil
|
||||
local all_tasks_checked
|
||||
repeat
|
||||
all_tasks_checked = true
|
||||
for i = #self._execution_stack, 1, -1 do
|
||||
local task = self._execution_stack[i]
|
||||
if not task.time
|
||||
or task.time[1] < now[1]
|
||||
or task.time[1] == now[1] and task.time[2] < now[2] then
|
||||
-- task is pending to be executed right now. do it.
|
||||
task.action()
|
||||
-- and remove from table
|
||||
table.remove(self._execution_stack, i)
|
||||
-- start loop again, since new tasks might be on the
|
||||
-- queue now
|
||||
all_tasks_checked = false
|
||||
elseif not wait_until
|
||||
or wait_until[1] > task.time[1]
|
||||
or wait_until[1] == task.time[1] and wait_until[2] > task.time[2] then
|
||||
-- task is to be run in the future _and_ is scheduled
|
||||
-- earlier than the tasks we looked at already
|
||||
-- so adjust to the currently examined task instead.
|
||||
wait_until = task.time
|
||||
end
|
||||
end
|
||||
until all_tasks_checked
|
||||
return wait_until
|
||||
end
|
||||
|
||||
-- this is the main loop of the UI controller
|
||||
-- it is intended to manage input events and delegate
|
||||
-- them to dialogs
|
||||
@@ -113,35 +146,8 @@ function UIManager:run()
|
||||
self._running = true
|
||||
while self._running do
|
||||
local now = { util.gettime() }
|
||||
|
||||
-- check if we have timed events in our queue and search next one
|
||||
local wait_until = nil
|
||||
local all_tasks_checked
|
||||
repeat
|
||||
all_tasks_checked = true
|
||||
for i = #self._execution_stack, 1, -1 do
|
||||
local task = self._execution_stack[i]
|
||||
if not task.time
|
||||
or task.time[1] < now[1]
|
||||
or task.time[1] == now[1] and task.time[2] < now[2] then
|
||||
-- task is pending to be executed right now. do it.
|
||||
task.action()
|
||||
-- and remove from table
|
||||
table.remove(self._execution_stack, i)
|
||||
-- start loop again, since new tasks might be on the
|
||||
-- queue now
|
||||
all_tasks_checked = false
|
||||
elseif not wait_until
|
||||
or wait_until[1] > task.time[1]
|
||||
or wait_until[1] == task.time[1] and wait_until[2] > task.time[2] then
|
||||
-- task is to be run in the future _and_ is scheduled
|
||||
-- earlier than the tasks we looked at already
|
||||
-- so adjust to the currently examined task instead.
|
||||
wait_until = task.time
|
||||
end
|
||||
end
|
||||
until all_tasks_checked
|
||||
|
||||
local wait_until = self:checkTasks()
|
||||
|
||||
--DEBUG("---------------------------------------------------")
|
||||
--DEBUG("exec stack", self._execution_stack)
|
||||
--DEBUG("window stack", self._window_stack)
|
||||
@@ -175,7 +181,9 @@ function UIManager:run()
|
||||
-- reset refresh_type
|
||||
self.refresh_type = 1
|
||||
end
|
||||
|
||||
|
||||
self:checkTasks()
|
||||
|
||||
-- wait for next event
|
||||
-- note that we will skip that if in the meantime we have tasks that are ready to run
|
||||
local input_event = nil
|
||||
|
||||
Reference in New Issue
Block a user