diff --git a/.luacheckrc b/.luacheckrc index 6738b088d..0b66404cf 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -4,10 +4,6 @@ std = "luajit" -- ignore implicit self self = false -globals = { - "G_reader_settings", -} - read_globals = { "DLANDSCAPE_CLOCKWISE_ROTATION", "lfs", diff --git a/ffi/framebuffer.lua b/ffi/framebuffer.lua index 0206e9ed6..a8c7614bd 100644 --- a/ffi/framebuffer.lua +++ b/ffi/framebuffer.lua @@ -254,12 +254,12 @@ function fb:getScreenHeight() return self.screen_size.h end -local screen_dpi_override - function fb:getDPI() - if self.dpi ~= nil then return self.dpi end + if self.dpi ~= nil then + return self.dpi + end - self.dpi = EMULATE_READER_DPI or screen_dpi_override + self.dpi = EMULATE_READER_DPI if self.dpi == nil and self.device then self.dpi = self.device.display_dpi @@ -273,7 +273,6 @@ function fb:getDPI() end function fb:setDPI(dpi) - screen_dpi_override = dpi self.dpi = dpi end diff --git a/ffi/framebuffer_dummy.lua b/ffi/framebuffer_dummy.lua new file mode 100644 index 000000000..0d2ae142e --- /dev/null +++ b/ffi/framebuffer_dummy.lua @@ -0,0 +1,63 @@ +local BB = require("ffi/blitbuffer") + +local framebuffer = {} + +function framebuffer:init() + self.bb = BB.new(600, 800) + self.bb:fill(BB.COLOR_WHITE) + + framebuffer.parent.init(self) +end + +function framebuffer:resize(w, h) +end + +function framebuffer:_newBB(w, h) + local rotation + local inverse + + if self.bb then + rotation = self.bb:getRotation() + inverse = self.bb:getInverse() == 1 + self.bb:free() + end + if self.invert_bb then self.invert_bb:free() end + + -- we present this buffer to the outside + local bb = BB.new(w, h, BB.TYPE_BBRGB32) + local flash = os.getenv("EMULATE_READER_FLASH") + if flash then + -- in refresh emulation mode, we use a shadow blitbuffer + -- and blit refresh areas from it. + self.bb = BB.new(w, h, BB.TYPE_BBRGB32) + else + self.bb = bb + end + self.invert_bb = BB.new(w, h, BB.TYPE_BBRGB32) + + if rotation then + self.bb:setRotation(rotation) + end + + -- reinit inverse mode on resize + if inverse then + self.bb:invert() + end +end + +function framebuffer:_render(bb, x, y, w, h) +end + +function framebuffer:refreshFullImp(x, y, w, h) +end + +function framebuffer:setWindowTitle(new_title) +end + +function framebuffer:setWindowIcon(icon) +end + +function framebuffer:close() +end + +return require("ffi/framebuffer"):extend(framebuffer) diff --git a/spec/unit/framebuffer_spec.lua b/spec/unit/framebuffer_spec.lua new file mode 100644 index 000000000..5d7365f32 --- /dev/null +++ b/spec/unit/framebuffer_spec.lua @@ -0,0 +1,30 @@ +describe("Framebuffer unit tests", function() + local fb + + setup(function() + fb = require("ffi/framebuffer_dummy"):new{ + dummy = true, + device = { + device_dpi = 167, + } + } + end) + + it("should set & update DPI", function() + assert.are.equals(160, fb:getDPI()) + + fb:setDPI(120) + assert.are.equals(120, fb:getDPI()) + + fb:setDPI(60) + assert.are.equals(60, fb:getDPI()) + end) + + it("should scale by DPI", function() + fb:setDPI(167) + assert.are.equals(30, fb:scaleBySize(30)) + + fb:setDPI(167 * 3) + assert.are.equals(60, fb:scaleBySize(30)) + end) +end)