From aec7594af5ae8117f65673f4c4b1738ccea16425 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 2 May 2019 04:27:48 +0200 Subject: [PATCH] Blacklist the C BB on devices where it cannot be used (#4989) Either at all, or because it would impose reduced functionality. Meaning: * On 4bpp fb, because those are completely unsupported by the C BB * On 24bpp fb, because it has limited support for that target format (no alpha blending). * On 8bpp Linux eInk fb with an inverted palette (that's basically only the K4 ;)). * On Linux eInk devices w/ no HW inversion support, as that would render NightMode inoperable. That last point means that it's currently *always* blacklisted on PocketBook, because I don't have a PB device, so I don't know how safe HW inversion would be, meaning none of them are marked as being HW invert capable. (I was a tiny bit hasty with https://github.com/koreader/koreader-base/pull/912 ;).) --- base | 2 +- frontend/device/generic/device.lua | 1 + frontend/device/kindle/device.lua | 35 +++++++++++++++++++++++++++ frontend/device/kobo/device.lua | 22 +++++++++++++++++ frontend/device/pocketbook/device.lua | 24 ++++++++++++++++++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/base b/base index b525cb490..531e4bc68 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit b525cb490ea83e1c4be2eed9e4a2e165fa03c32e +Subproject commit 531e4bc685f099716170849a10c67dd5966c9e3a diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 67a74b3ec..f253ef9b2 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -34,6 +34,7 @@ local Device = { hasEinkScreen = yes, canHWDither = no, canHWInvert = no, + canUseCBB = yes, -- The C BB maintains a 1:1 feature parity with the Lua BB, except that is has NO support for BB4, and limited support for BBRGB24 hasColorScreen = no, hasBGRFrameBuffer = no, canToggleGSensor = no, diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 0eb446de5..a162dc5b5 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -202,6 +202,24 @@ function Kindle:ambientBrightnessLevel() return 4 end +-- Make sure the C BB cannot be used on devices with a 4bpp fb +function Kindle:blacklistCBB() + local ffi = require("ffi") + local dummy = require("ffi/posix_h") + local C = ffi.C + + -- As well as on those than can't do HW inversion, as otherwise NightMode would be ineffective. + if not self:canUseCBB() or not self:canHWInvert() then + logger.info("Blacklisting the C BB on this device") + if ffi.os == "Windows" then + C._putenv("KO_NO_CBB=true") + else + C.setenv("KO_NO_CBB", "true", 1) + end + -- Enforce the global setting, too, so the Dev menu is accurate... + G_reader_settings:saveSetting("dev_no_c_blitter", true) + end +end local Kindle2 = Kindle:new{ model = "Kindle2", @@ -209,6 +227,7 @@ local Kindle2 = Kindle:new{ hasKeys = yes, hasDPad = yes, canHWInvert = no, + canUseCBB = no, -- 4bpp } local KindleDXG = Kindle:new{ @@ -217,6 +236,7 @@ local KindleDXG = Kindle:new{ hasKeys = yes, hasDPad = yes, canHWInvert = no, + canUseCBB = no, -- 4bpp } local Kindle3 = Kindle:new{ @@ -225,6 +245,7 @@ local Kindle3 = Kindle:new{ hasKeys = yes, hasDPad = yes, canHWInvert = no, + canUseCBB = no, -- 4bpp } local Kindle4 = Kindle:new{ @@ -232,6 +253,8 @@ local Kindle4 = Kindle:new{ hasKeys = yes, hasDPad = yes, canHWInvert = no, + -- NOTE: It could *technically* use the C BB, as it's running @ 8bpp, but it's expecting an inverted palette... + canUseCBB = no, } local KindleTouch = Kindle:new{ @@ -319,6 +342,9 @@ local KindlePaperWhite4 = Kindle:new{ } function Kindle2:init() + -- Blacklist the C BB before the first BB require... + self:blacklistCBB() + self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = logger.dbg} self.powerd = require("device/kindle/powerd"):new{ device = self, @@ -334,6 +360,9 @@ function Kindle2:init() end function KindleDXG:init() + -- Blacklist the C BB before the first BB require... + self:blacklistCBB() + self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = logger.dbg} self.powerd = require("device/kindle/powerd"):new{ device = self, @@ -350,6 +379,9 @@ function KindleDXG:init() end function Kindle3:init() + -- Blacklist the C BB before the first BB require... + self:blacklistCBB() + self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = logger.dbg} self.powerd = require("device/kindle/powerd"):new{ device = self, @@ -367,6 +399,9 @@ function Kindle3:init() end function Kindle4:init() + -- Blacklist the C BB before the first BB require... + self:blacklistCBB() + self.screen = require("ffi/framebuffer_einkfb"):new{device = self, debug = logger.dbg} self.powerd = require("device/kindle/powerd"):new{ device = self, diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 192ec4a4a..bcce79e85 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -249,7 +249,29 @@ probeEvEpochTime = function(self, ev) end end +-- Make sure the C BB cannot be used on devices with unsafe HW inversion, as otherwise NightMode would be ineffective. +function Kobo:blacklistCBB() + local ffi = require("ffi") + local dummy = require("ffi/posix_h") + local C = ffi.C + + -- NOTE: canUseCBB is never no on Kobo ;). + if not self:canUseCBB() or not self:canHWInvert() then + logger.info("Blacklisting the C BB on this device") + if ffi.os == "Windows" then + C._putenv("KO_NO_CBB=true") + else + C.setenv("KO_NO_CBB", "true", 1) + end + -- Enforce the global setting, too, so the Dev menu is accurate... + G_reader_settings:saveSetting("dev_no_c_blitter", true) + end +end + function Kobo:init() + -- Blacklist the C BB before the first BB require... + self:blacklistCBB() + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg} if self.screen.fb_bpp == 32 then -- Ensure we decode images properly, as our framebuffer is BGRA... diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index e02a1b163..a32cd4c7d 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -62,7 +62,30 @@ local PocketBook = Generic:new{ hasWifiToggle = yes, } +-- Make sure the C BB cannot be used on devices with a 24bpp fb +function PocketBook:blacklistCBB() + local dummy = require("ffi/posix_h") + local C = ffi.C + + -- As well as on those than can't do HW inversion, as otherwise NightMode would be ineffective. + -- FIXME: Either relax the HWInvert check, or actually enable HWInvert on PB if it's safe and it works, + -- as, currently, no PB device is marked as canHWInvert, so, the C BB is essentially *always* blacklisted. + if not self:canUseCBB() or not self:canHWInvert() then + logger.info("Blacklisting the C BB on this device") + if ffi.os == "Windows" then + C._putenv("KO_NO_CBB=true") + else + C.setenv("KO_NO_CBB", "true", 1) + end + -- Enforce the global setting, too, so the Dev menu is accurate... + G_reader_settings:saveSetting("dev_no_c_blitter", true) + end +end + function PocketBook:init() + -- Blacklist the C BB before the first BB require... + self:blacklistCBB() + self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg} self.powerd = require("device/pocketbook/powerd"):new{device = self} self.input = require("device/input"):new{ @@ -292,6 +315,7 @@ local PocketBookColorLux = PocketBook:new{ hasFrontlight = yes, hasColorScreen = yes, has3BytesWideFrameBuffer = yes, + canUseCBB = no, -- 24bpp isAlwaysPortrait = no, emu_events_dev = "/var/dev/shm/emu_events", }