From 63af71188ad537ed1ef5da2545b51731c314d791 Mon Sep 17 00:00:00 2001 From: Hans-Werner Hilse Date: Thu, 20 Nov 2014 20:24:02 +0100 Subject: [PATCH] refactor refresh Lots of the device-related distinction wandered into base/ffi/framebuffer_. This eases the refresh logic in UI manager, which basically only decides what kind of refresh to trigger. The device specific configuration in the framebuffer driver decides how to realize that whish. screen.lua is gone, in its place is now the framebuffer driver. The device abstraction decides what framebuffer driver to load. --- frontend/device/android/device.lua | 2 +- frontend/device/emulator/device.lua | 20 ++- frontend/device/generic/device.lua | 2 +- frontend/device/kindle/device.lua | 18 +- frontend/device/kobo/device.lua | 2 +- frontend/device/screen.lua | 246 ---------------------------- frontend/ui/uimanager.lua | 198 +++++----------------- 7 files changed, 63 insertions(+), 425 deletions(-) delete mode 100644 frontend/device/screen.lua diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index a75a40f49..c17a80e0f 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -12,7 +12,7 @@ local Device = Generic:new{ } function Device:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_android"):new{device = self} self.powerd = require("device/android/powerd"):new{device = self} self.input = require("device/input"):new{ device = self, diff --git a/frontend/device/emulator/device.lua b/frontend/device/emulator/device.lua index 5c536a7b7..7001fa357 100644 --- a/frontend/device/emulator/device.lua +++ b/frontend/device/emulator/device.lua @@ -13,13 +13,19 @@ local Device = Generic:new{ } function Device:init() - self.screen = require("device/screen"):new{device = self} - self.input = require("device/input"):new{ - device = self, - event_map = util.haveSDL2() - and require("device/emulator/event_map_sdl2") - or require("device/emulator/event_map_sdl"), - } + if util.haveSDL2() then + self.screen = require("ffi/framebuffer_SDL2_0"):new{device = self} + self.input = require("device/input"):new{ + device = self, + event_map = require("device/emulator/event_map_sdl2"), + } + else + self.screen = require("ffi/framebuffer_SDL1_2"):new{device = self} + self.input = require("device/input"):new{ + device = self, + event_map = require("device/emulator/event_map_sdl"), + } + end Generic.init(self) end diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index aef2bc734..fc3b15616 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -40,7 +40,7 @@ end function Device:init() if not self.screen then - self.screen = require("device/screen"):new{device = self} + error("screen/framebuffer must be implemented") end if not self.input then self.input = require("device/input"):new{device = self} diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 7758c5f50..fcb933065 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -69,7 +69,7 @@ local KindleVoyage = Kindle:new{ } function Kindle2:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_einkfb"):new{device = self} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_keyboard"), @@ -79,7 +79,7 @@ function Kindle2:init() end function KindleDXG:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_einkfb"):new{device = self} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_keyboard"), @@ -90,7 +90,7 @@ function KindleDXG:init() end function Kindle3:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_einkfb"):new{device = self} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_keyboard"), @@ -101,7 +101,7 @@ function Kindle3:init() end function Kindle4:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_einkfb"):new{device = self} self.input = require("device/input"):new{ device = self, event_map = require("device/kindle/event_map_kindle4"), @@ -114,7 +114,7 @@ end local ABS_MT_POSITION_X = 53 local ABS_MT_POSITION_Y = 54 function KindleTouch:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self} self.powerd = require("device/kindle/powerd"):new{ device = self, batt_capacity_file = "/sys/devices/system/yoshi_battery/yoshi_battery0/battery_capacity", @@ -138,7 +138,7 @@ function KindleTouch:init() end function KindlePaperWhite:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/devices/system/fl_tps6116x/fl_tps6116x0/fl_intensity", @@ -153,7 +153,7 @@ function KindlePaperWhite:init() end function KindlePaperWhite2:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/class/backlight/max77696-bl/brightness", @@ -168,7 +168,7 @@ function KindlePaperWhite2:init() end function KindleBasic:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self} self.powerd = require("device/kindle/powerd"):new{ device = self, batt_capacity_file = "/sys/devices/system/wario_battery/wario_battery0/battery_capacity", @@ -183,7 +183,7 @@ function KindleBasic:init() end function KindleVoyage:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self} self.powerd = require("device/kindle/powerd"):new{ device = self, fl_intensity_file = "/sys/class/backlight/max77696-bl/brightness", diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index cd54e6ed5..452b2c9c1 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -58,7 +58,7 @@ local KoboPhoenix = Kobo:new{ } function Kobo:init() - self.screen = require("device/screen"):new{device = self} + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self} self.powerd = require("device/kobo/powerd"):new{device = self} self.input = require("device/input"):new{ device = self, diff --git a/frontend/device/screen.lua b/frontend/device/screen.lua deleted file mode 100644 index ce09557b7..000000000 --- a/frontend/device/screen.lua +++ /dev/null @@ -1,246 +0,0 @@ -local Blitbuffer = require("ffi/blitbuffer") -local einkfb = require("ffi/framebuffer") -local Geom = require("ui/geometry") -local util = require("ffi/util") -local DEBUG = require("dbg") - ---[[ -Codes for rotation modes: - -1 for no rotation, -2 for landscape with bottom on the right side of screen, etc. - - 2 - +--------------+ - | +----------+ | - | | | | - | | Freedom! | | - | | | | - | | | | - 3 | | | | 1 - | | | | - | | | | - | +----------+ | - | | - | | - +--------------+ - 0 ---]] - - -local Screen = { - cur_rotation_mode = 0, - native_rotation_mode = nil, - blitbuffer_rotation_mode = 0, - - bb = nil, - saved_bb = nil, - - screen_size = Geom:new(), - viewport = nil, - - fb = einkfb.open("/dev/fb0"), - -- will be set upon loading by Device class: - device = nil, -} - -function Screen:new(o) - local o = o or {} - setmetatable(o, self) - self.__index = self - if o.init then o:init() end - return o -end - -function Screen:init() - self.bb = self.fb.bb - self.blitbuffer_rotation_mode = self.bb:getRotation() - -- asking the framebuffer for orientation is error prone, - -- so we do this simple heuristic (for now) - self.screen_size.w = self.bb:getWidth() - self.screen_size.h = self.bb:getHeight() - if self.screen_size.w > self.screen_size.h then - self.native_rotation_mode = 1 - self.screen_size.w, self.screen_size.h = self.screen_size.h, self.screen_size.w - else - self.native_rotation_mode = 0 - end - self.cur_rotation_mode = self.native_rotation_mode -end - ---[[ -set a rectangle that represents the area of the screen we are working on ---]] -function Screen:setViewport(viewport) - self.viewport = self.screen_size:intersect(viewport) - self.bb = self.fb.bb:viewport( - self.viewport.x, self.viewport.y, - self.viewport.w, self.viewport.h) -end - -function Screen:refresh(refresh_type, waveform_mode, wait_for_marker, x, y, w, h) - if self.viewport and x and y then - --[[ - we need to adapt the coordinates when we have a viewport. - this adaptation depends on the rotation: - - 0,0 fb.w - +---+---------------------------+---+ - | |v.y v.y| | - |v.x| |vx2| - +---+---------------------------+---+ - | | v.w | | - | | | | - | | | | - | |v.h (viewport) | | - | | | | fb.h - | | | | - | | | | - | | | | - +---+---------------------------+---+ - |v.x| |vx2| - | |vy2 vy2| | - +---+---------------------------+---+ - - The viewport offset v.y/v.x only applies when rotation is 0 degrees. - For other rotations (0,0 is in one of the other edges), we need to - recalculate the offsets. - --]] - - local vx2 = self.screen_size.w - (self.viewport.x + self.viewport.w) - local vy2 = self.screen_size.h - (self.viewport.y + self.viewport.h) - - if self.cur_rotation_mode == 0 then - -- (0,0) is at top left of screen - x = x + self.viewport.x - y = y + self.viewport.y - elseif self.cur_rotation_mode == 1 then - -- (0,0) is at bottom left of screen - x = x + vy2 - y = y + self.viewport.x - elseif self.cur_rotation_mode == 2 then - -- (0,0) is at bottom right of screen - x = x + vx2 - y = y + vy2 - else - -- (0,0) is at top right of screen - x = x + self.viewport.y - y = y + vx2 - end - end - self.fb:refresh(refresh_type, waveform_mode, wait_for_marker, x, y, w, h) -end - -function Screen:getSize() - return Geom:new{w = self.bb:getWidth(), h = self.bb:getHeight()} -end - -function Screen:getWidth() - return self.bb:getWidth() -end - -function Screen:getScreenWidth() - return self.screen_size.w -end - -function Screen:getScreenHeight() - return self.screen_size.h -end - -function Screen:getHeight() - return self.bb:getHeight() -end - -function Screen:getDPI() - if self.dpi == nil then - self.dpi = G_reader_settings:readSetting("screen_dpi") - end - if self.dpi == nil then - self.dpi = self.device.display_dpi - end - if self.dpi == nil then - self.dpi = 160 - end - return self.dpi -end - -function Screen:setDPI(dpi) - G_reader_settings:saveSetting("screen_dpi", dpi) -end - -function Screen:scaleByDPI(px) - local dpi = self:getDPI() - -- larger screen needs larger scale - local size_scale = math.min(self:getWidth(), self:getHeight())/dpi/3.6 - -- scaled positive px should also be positive - return math.ceil(px * size_scale * dpi/167) -end - -function Screen:getRotationMode() - return self.cur_rotation_mode -end - -function Screen:getScreenMode() - if self:getWidth() > self:getHeight() then - return "landscape" - else - return "portrait" - end -end - -function Screen:setRotationMode(mode) - self.bb:rotateAbsolute(-90 * (mode - self.native_rotation_mode - self.blitbuffer_rotation_mode)) - if self.viewport then - self.fb.bb:setRotation(self.bb:getRotation()) - end - self.cur_rotation_mode = mode -end - -function Screen:setScreenMode(mode) - if mode == "portrait" then - if self.cur_rotation_mode ~= 0 then - self:setRotationMode(0) - end - elseif mode == "landscape" then - if self.cur_rotation_mode == 0 or self.cur_rotation_mode == 2 then - self:setRotationMode(DLANDSCAPE_CLOCKWISE_ROTATION and 1 or 3) - elseif self.cur_rotation_mode == 1 or self.cur_rotation_mode == 3 then - self:setRotationMode((self.cur_rotation_mode + 2) % 4) - end - end -end - -function Screen:toggleNightMode() - self.bb:invert() - if self.viewport then - -- invert and blank out the full framebuffer when we are working on a viewport - self.fb.bb:invert() - self.fb.bb:fill(Blitbuffer.COLOR_WHITE) - end -end - -function Screen:saveCurrentBB() - if self.saved_bb then self.saved_bb:free() end - self.saved_bb = self.bb:copy() -end - -function Screen:restoreFromSavedBB() - if self.saved_bb then - self.bb:blitFullFrom(self.saved_bb) - -- free data - self.saved_bb:free() - self.saved_bb = nil - end -end - -function Screen:shot(filename) - DEBUG("write PNG file", filename) - self.bb:writePNG(filename) -end - -function Screen:close() - DEBUG("close screen framebuffer") - self.fb:close() -end - -return Screen diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 24f8670d2..46ff49a04 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -6,52 +6,8 @@ local util = require("ffi/util") local DEBUG = require("dbg") local _ = require("gettext") --- cf. koreader-base/ffi-cdecl/include/mxcfb-kindle.h (UPDATE_MODE_* applies to Kobo, too) -local UPDATE_MODE_PARTIAL = 0x0 -local UPDATE_MODE_FULL = 0x1 - --- Kindle waveform update modes -local WAVEFORM_MODE_INIT = 0x0 -- Screen goes to white (clears) -local WAVEFORM_MODE_DU = 0x1 -- Grey->white/grey->black -local WAVEFORM_MODE_GC16 = 0x2 -- High fidelity (flashing) -local WAVEFORM_MODE_GC4 = WAVEFORM_MODE_GC16 -- For compatibility -local WAVEFORM_MODE_GC16_FAST = 0x3 -- Medium fidelity -local WAVEFORM_MODE_A2 = 0x4 -- Faster but even lower fidelity -local WAVEFORM_MODE_GL16 = 0x5 -- High fidelity from white transition -local WAVEFORM_MODE_GL16_FAST = 0x6 -- Medium fidelity from white transition --- Kindle FW >= 5.3 -local WAVEFORM_MODE_DU4 = 0x7 -- Medium fidelity 4 level of gray direct update --- Kindle PW2 -local WAVEFORM_MODE_REAGL = 0x8 -- Ghost compensation waveform -local WAVEFORM_MODE_REAGLD = 0x9 -- Ghost compensation waveform with dithering --- Kindle Basic/Kindle Voyage -local WAVEFORM_MODE_GL4 = 0xA -- 2-bit from white transition --- TODO: Use me in night mode on those devices? -local WAVEFORM_MODE_GL16_INV = 0xB -- High fidelity for black transition - --- Kobo waveform update modes -local NTX_WFM_MODE_INIT = 0x0 -- WAVEFORM_MODE_INIT -local NTX_WFM_MODE_DU = 0x1 -- WAVEFORM_MODE_DU -local NTX_WFM_MODE_GC16 = 0x2 -- WAVEFORM_MODE_GC16 -local NTX_WFM_MODE_GC4 = 0x3 -- WAVEFORM_MODE_GC4 -local NTX_WFM_MODE_A2 = 0x4 -- WAVEFORM_MODE_A2 -local NTX_WFM_MODE_GL16 = 0x5 -- WAVEFORM_MODE_GL16 -local NTX_WFM_MODE_GLR16 = 0x6 -- WAVEFORM_MODE_REAGL -local NTX_WFM_MODE_GLD16 = 0x7 -- WAVEFORM_MODE_REAGLD - --- Common -local WAVEFORM_MODE_AUTO = 0x101 - - -- there is only one instance of this local UIManager = { - default_refresh_type = UPDATE_MODE_PARTIAL, - default_waveform_mode = WAVEFORM_MODE_GC16, -- high fidelity waveform - fast_waveform_mode = WAVEFORM_MODE_A2, - full_refresh_waveform_mode = WAVEFORM_MODE_GC16, - partial_refresh_waveform_mode = WAVEFORM_MODE_GC16, - wait_for_every_marker = false, - wait_for_ui_markers = false, -- force to repaint all the widget is stack, will be reset to false -- after each ui loop repaint_all = false, @@ -114,29 +70,6 @@ function UIManager:init() if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then Device:getPowerDevice():setIntensity( math.max( math.min(KOBO_LIGHT_ON_START,100) ,0) ) end - -- Emulate the stock reader's refresh behavior... - self.full_refresh_waveform_mode = NTX_WFM_MODE_GC16 - -- Request REAGLD waveform mode on devices that support it (Aura & H2O) - if Device.model == "Kobo_phoenix" or Device.model == "Kobo_dahlia" then - self.partial_refresh_waveform_mode = NTX_WFM_MODE_GLD16 - -- Since Kobo doesn't have MXCFB_WAIT_FOR_UPDATE_SUBMISSION, enabling this currently has no effect :). - self.wait_for_every_marker = true - -- NOTE: The H2O appears to be the odd duck out... Nickel uses AUTO for PARTIAL updates instead of asking for REAGLD specifically... - -- If we try to ask for FULL REAGLD updates, like on the Aura and the PW2, we get a black flash! - -- The driver appears to be using some custom Kobo logic (that they only enable in their producttion build?) altering the behavior of AUTO to favor REAGL modes... - -- Long story short: do the same as nickel: use AUTO, and hope for the best... - if Device.model == "Kobo_dahlia" then - self.partial_refresh_waveform_mode = WAVEFORM_MODE_AUTO - end - else - -- Let the driver handle it on those models (asking for NTX_WFM_MODE_GL16 appears to be a very bad idea, #1146) - self.partial_refresh_waveform_mode = WAVEFORM_MODE_AUTO - self.wait_for_every_marker = false - -- NOTE: Let's see if a bit of waiting works around potential timing issues on Kobos when doing *UI* refreshes in fast succession. (Not a concern on Kindle, where we have MXCFB_WAIT_FOR_UPDATE_SUBMISSION). - self.wait_for_ui_markers = true - end - -- Let the driver decide what to do with PARTIAL UI updates... - self.default_waveform_mode = WAVEFORM_MODE_AUTO elseif Device:isKindle() then self.event_handlers["IntoSS"] = function() self:sendEvent(Event:new("FlushSettings")) @@ -153,35 +86,6 @@ function UIManager:init() Device:usbPlugOut() self:sendEvent(Event:new("NotCharging")) end - -- Emulate the stock reader's refresh behavior... - --[[ - NOTE: For ref, on a Touch (debugPaint & a patched strace are your friend!): - UI: flash: GC16_FAST, non-flash: AUTO (prefers GC16_FAST) - Reader: When flash: if to/from img: GC16, else GC16_FAST; when non-flash: AUTO (seems to prefer GL16_FAST); Waiting for marker only on flash - On a PW2: - UI: flash: GC16_FAST, non-flash: AUTO (prefers GC16_FAST) - Reader: When flash: if to/from img: GC16, else GC16_FAST; when non-flash: REAGL (w/ UPDATE_MODE_FULL!); Always waits for marker - Note that the bottom status bar region is refreshed separately, right after the screen, as a PARTIAL, AUTO (GC16_FAST) update, and it's this marker that's waited after... - Non flash lasts longer (dual timeout: 14pgs / 7mins). - --]] - -- We don't really have an easy way to know if we're refreshing the UI, or a page, or if said page contains an image, so go with the highest fidelity option - -- We spend much more time in the reader than the UI, and our UI isn't very graphic anyway, so we'll follow the reader's behaviour above all - self.full_refresh_waveform_mode = WAVEFORM_MODE_GC16 - -- Request REAGL waveform mode on devices that support it (PW2, KT2, KV) [FIXME: Is that actually true of the KT2?] - if Device.model == "KindlePaperWhite2" or Device.model == "KindleBasic" or Device.model == "KindleVoyage" then - self.partial_refresh_waveform_mode = WAVEFORM_MODE_REAGL - -- We need to wait for every update marker when using REAGL waveform modes. That mostly means we always use MXCFB_WAIT_FOR_UPDATE_SUBMISSION. - self.wait_for_every_marker = true - else - self.partial_refresh_waveform_mode = WAVEFORM_MODE_GL16_FAST - -- NOTE: Or we could go back to what KOReader did before fa55acc in koreader-base, which was also to use AUTO ;). - -- That said, we *should* be making more or less the same decisions as AUTO on our own, if I followed things correctly... - --self.partial_refresh_waveform_mode = WAVEFORM_MODE_AUTO - -- Only wait for update markers on FULL updates - self.wait_for_every_marker = false - end - -- Default to GC16_FAST (will be used for PARTIAL UI updates) - self.default_waveform_mode = WAVEFORM_MODE_GC16_FAST end end @@ -217,6 +121,7 @@ function UIManager:close(widget) return end DEBUG("close widget", widget.id) + -- TODO: Why do we the following? Input.disable_double_tap = DGESDETECT_DISABLE_DOUBLE_TAP local dirty = false for i = #self._window_stack, 1, -1 do @@ -383,105 +288,78 @@ end -- repaint dirty widgets function UIManager:repaint() + -- flag in which we will record if we did any repaints at all + -- will trigger a refresh if set. local dirty = false - local request_full_refresh = false - local force_full_refresh = false - local force_partial_refresh = false + + -- we use this to record requests for certain refresh types + -- TODO: fix this, see below + local force_full_refresh = self.full_refresh + self.full_refresh = false + + local force_partial_refresh = self.partial_refresh + self.partial_refresh = false + local force_fast_refresh = false + for _, widget in ipairs(self._window_stack) do -- paint if repaint_all is request -- paint also if current widget or any widget underneath is dirty if self.repaint_all or dirty or self._dirty[widget.widget] then widget.widget:paintTo(Screen.bb, widget.x, widget.y) - if self._dirty[widget.widget] == "auto" then - -- Most likely a 'reader' refresh. 'request' in the sense once we hit our FULL_REFRESH_COUNT ;). - request_full_refresh = true - end + -- self._dirty[widget.widget] may also be "auto" if self._dirty[widget.widget] == "full" then force_full_refresh = true - end - if self._dirty[widget.widget] == "partial" then + elseif self._dirty[widget.widget] == "partial" then force_partial_refresh = true - end - if self._dirty[widget.widget] == "fast" then + elseif self._dirty[widget.widget] == "fast" then force_fast_refresh = true end + -- and remove from list after painting self._dirty[widget.widget] = nil + -- trigger repaint dirty = true end end - - if self.full_refresh then - dirty = true - force_full_refresh = true - end - - if self.partial_refresh then - dirty = true - force_partial_refresh = true - end - self.repaint_all = false - self.full_refresh = false - self.partial_refresh = false - local refresh_type = self.default_refresh_type - local waveform_mode = self.default_waveform_mode - local wait_for_marker = self.wait_for_every_marker if dirty then - if force_partial_refresh or force_fast_refresh or self.update_regions_func then - refresh_type = UPDATE_MODE_PARTIAL - -- Override wait_for_marker if we need to enable the Kobo timing workaround on UI refreshes - if self.wait_for_ui_markers then - wait_for_marker = true - end + -- select proper refresh mode + -- TODO: fix this. We should probably do separate refreshes + -- by regional refreshes (e.g. fast refresh, some partial refreshes) + -- and full-screen full refresh + local refresh + + if force_fast_refresh then + refresh = Screen.refreshFast + elseif force_partial_refresh then + refresh = Screen.refreshPartial elseif force_full_refresh or self.refresh_count == self.FULL_REFRESH_COUNT - 1 then - refresh_type = UPDATE_MODE_FULL - end - -- Handle the waveform mode selection... - if refresh_type == UPDATE_MODE_FULL then - waveform_mode = self.full_refresh_waveform_mode + refresh = Screen.refreshFull + -- a full refresh will reset the counter which leads to an automatic full refresh + self.refresh_count = 0 else - waveform_mode = self.partial_refresh_waveform_mode - end - if force_fast_refresh then - waveform_mode = self.fast_waveform_mode - -- FIXME: Should we also avoid doing an MXCFB_WAIT_FOR_UPDATE_SUBMISSION for this update? - --wait_for_marker = false - end - -- If the device is REAGL-aware, we're specifically asking for a REAGL update, and we're doing a PARTIAL *reader* refresh, apply some trickery to match the stock reader's behavior - -- (On most device, REAGL updates are always FULL, but there's no black flash. On devices where this isn't the case [H2O], we're letting the driver do the job by using AUTO). - if not force_partial_refresh and not force_fast_refresh and refresh_type == UPDATE_MODE_PARTIAL and (waveform_mode == WAVEFORM_MODE_REAGL or waveform_mode == NTX_WFM_MODE_GLD16) then - refresh_type = UPDATE_MODE_FULL - end - -- On the other hand, if we asked for a PARTIAL *UI* refresh, fall back to the default waveform mode, which is tailored per-device to hopefully be more appropriate in this instance than the one we use in the reader. - if force_partial_refresh then - -- NOTE: Using default_waveform_mode might seem counter-intuitive when we have partial_refresh_waveform_mode, but partial_refresh_waveform_mode is mostly there as a means to flag REAGL-aware devices ;). - -- Here, we're actually interested in handling PARTIAL, regional (be it properly flagged or not) updates, and not the PARTIAL updates from the reader that actually refresh the whole screen (i.e., those between black flashes). - waveform_mode = self.default_waveform_mode + -- default + refresh = Screen.refreshPartial + -- increment refresh counter in this case + self.refresh_count = (self.refresh_count + 1) % self.FULL_REFRESH_COUNT end + if self.update_regions_func then local update_regions = self.update_regions_func() for _, update_region in ipairs(update_regions) do -- in some rare cases update region has 1 pixel offset - Screen:refresh(refresh_type, waveform_mode, wait_for_marker, + refresh(Screen, refresh_type, waveform_mode, wait_for_marker, update_region.x-1, update_region.y-1, update_region.w+2, update_region.h+2) end else - Screen:refresh(refresh_type, waveform_mode, wait_for_marker) - end - -- REAGL refreshes are always FULL (but without a black flash), but we want to keep our black flash timeout working, so don't reset the counter on FULL REAGL refreshes... - if refresh_type == UPDATE_MODE_FULL and waveform_mode ~= WAVEFORM_MODE_REAGL and waveform_mode ~= NTX_WFM_MODE_GLD16 then - self.refresh_count = 0 - elseif not force_partial_refresh and not force_full_refresh and not self.update_regions_func then - self.refresh_count = (self.refresh_count + 1)%self.FULL_REFRESH_COUNT + refresh(Screen, refresh_type, waveform_mode, wait_for_marker) end end - self.update_regions_func = nil end -- this is the main loop of the UI controller