forked from koreader/koreader-base
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify framebuffer dpi handling (koreader#843)
- Loading branch information
Showing
4 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |