From ee6c93a516ea3ec97d7db64e555dcd81641baee7 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 22 Jul 2013 22:04:54 +0800 Subject: [PATCH] add regional screen refresh support and waveform mode can be specified when calling screen refresh --- frontend/ui/screen.lua | 25 ++++++++++++++--- frontend/ui/uimanager.lua | 56 +++++++++++++++++++++++++++++++-------- koreader-base | 2 +- 3 files changed, 68 insertions(+), 15 deletions(-) diff --git a/frontend/ui/screen.lua b/frontend/ui/screen.lua index 819efd584..b3cf969d3 100644 --- a/frontend/ui/screen.lua +++ b/frontend/ui/screen.lua @@ -72,19 +72,38 @@ function Screen:init() self.cur_rotation_mode = self.native_rotation_mode end -function Screen:refresh(refesh_type) - if self.native_rotation_mode == self.cur_rotation_mode then +function Screen:refresh(refesh_type, waveform_mode, x, y, w, h) + if x then x = x < 0 and 0 or math.floor(x) end + if y then y = y < 0 and 0 or math.floor(y) end + if w then w = w > self.width and self.width or math.ceil(w) end + if h then h = h > self.height and self.height or math.ceil(h) end + if self.native_rotation_mode == self.cur_rotation_mode then self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height) elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then self.fb.bb:blitFromRotate(self.bb, 270) + if x and y and w and h then + x, y = y, self.width - w - x + w, h = h, w + end elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 3 then self.fb.bb:blitFromRotate(self.bb, 90) + if x and y and w and h then + x, y = self.height - h - y, x + w, h = h, w + end elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then self.fb.bb:blitFromRotate(self.bb, 90) + if x and y and w and h then + x, y = self.height - h - y, x + w, h = h, w + end elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 3 then self.fb.bb:blitFromRotate(self.bb, 180) + if x and y and w and h then + x, y = self.width - w - x, self.height - h - y + end end - self.fb:refresh(refesh_type) + self.fb:refresh(refesh_type, waveform_mode, x, y, w, h) end function Screen:getSize() diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 962b95915..88871619b 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -10,18 +10,33 @@ Screen:init() -- initialize the input handling Input:init() +WAVEFORM_MODE_INIT = 0x0 -- Screen goes to white (clears) +WAVEFORM_MODE_DU = 0x1 -- Grey->white/grey->black +WAVEFORM_MODE_GC16 = 0x2 -- High fidelity (flashing) +WAVEFORM_MODE_GC4 = WAVEFORM_MODE_GC16 -- For compatibility +WAVEFORM_MODE_GC16_FAST = 0x3 -- Medium fidelity +WAVEFORM_MODE_A2 = 0x4 -- Faster but even lower fidelity +WAVEFORM_MODE_GL16 = 0x5 -- High fidelity from white transition +WAVEFORM_MODE_GL16_FAST = 0x6 -- Medium fidelity from white transition +WAVEFORM_MODE_AUTO = 0x101 -- there is only one instance of this UIManager = { -- change this to set refresh type for next refresh -- defaults to 1 initially and will be set to 1 after each refresh refresh_type = 1, + -- change this to set refresh waveform for next refresh + -- default to WAVEFORM_MODE_GC16 + waveform_mode = WAVEFORM_MODE_GC16, -- force to repaint all the widget is stack, will be reset to false -- after each ui loop repaint_all = false, -- force to do full refresh, will be reset to false -- after each ui loop full_refresh = false, + -- force to do patial refresh, will be reset to false + -- after each ui loop + patial_refresh = false, -- trigger a full refresh when counter reaches FULL_REFRESH_COUNT FULL_REFRESH_COUNT = DRCOUNTMAX, refresh_count = 0, @@ -173,6 +188,7 @@ function UIManager:run() local dirty = false local request_full_refresh = false local force_full_refresh = false + local force_patial_refresh = false for _, widget in ipairs(self._window_stack) do if self.repaint_all or self._dirty[widget.widget] then widget.widget:paintTo(Screen.bb, widget.x, widget.y) @@ -182,6 +198,9 @@ function UIManager:run() if self._dirty[widget.widget] == "full" then force_full_refresh = true end + if self._dirty[widget.widget] == "patial" then + force_patial_refresh = true + end -- and remove from list after painting self._dirty[widget.widget] = nil -- trigger repaint @@ -193,26 +212,41 @@ function UIManager:run() dirty = true force_full_refresh = true end + + if self.patial_refresh then + dirty = true + force_patial_refresh = true + end self.repaint_all = false self.full_refresh = false + self.patial_refresh = false if dirty then - if force_full_refresh then - self.refresh_count = self.FULL_REFRESH_COUNT - 1 - end - if self.refresh_count == self.FULL_REFRESH_COUNT - 1 then + if force_patial_refresh then + self.refresh_type = 1 + elseif force_full_refresh or self.refresh_count == self.FULL_REFRESH_COUNT - 1 then self.refresh_type = 0 else self.refresh_type = 1 end - -- refresh FB - Screen:refresh(self.refresh_type) -- TODO: refresh explicitly only repainted area - -- increase refresh_count only when full refresh is requested or performed - local refresh_increment = (request_full_refresh or self.refresh_type == 0) and 1 or 0 - self.refresh_count = (self.refresh_count + refresh_increment)%self.FULL_REFRESH_COUNT - -- reset refresh_type - self.refresh_type = 1 + --self.waveform_mode = self.fast_refresh and WAVEFORM_MODE_A2 or WAVEFORM_MODE_GC16 + if self.update_region_func then + local update_region = self.update_region_func() + Screen:refresh(self.refresh_type, self.waveform_mode, + update_region.x, update_region.y, + update_region.w, update_region.h) + else + Screen:refresh(self.refresh_type, self.waveform_mode) + end + if self.refresh_type == 0 then + self.refresh_count = 0 + elseif not force_patial_refresh and not force_full_refresh then + self.refresh_count = (self.refresh_count + 1)%self.FULL_REFRESH_COUNT + end + -- reset waveform_mode to WAVEFORM_MODE_GC16 + self.waveform_mode = WAVEFORM_MODE_GC16 + self.update_region_func = nil end self:checkTasks() diff --git a/koreader-base b/koreader-base index d45c0ac4b..fa55acc48 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit d45c0ac4b1f4801e193d0bc9a6c3759989dec7c2 +Subproject commit fa55acc48b7e48a957ad3b82dd591a9bf91eb645