2013-10-22 15:11:31 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2013-10-22 18:51:29 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-22 15:11:31 +00:00
|
|
|
|
|
|
|
-- Blitbuffer
|
|
|
|
-- einkfb
|
|
|
|
|
|
|
|
--[[
|
|
|
|
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 = {
|
2014-03-13 13:52:43 +00:00
|
|
|
cur_rotation_mode = 0,
|
|
|
|
native_rotation_mode = nil,
|
|
|
|
blitbuffer_rotation_mode = 0,
|
2013-10-22 15:11:31 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
bb = nil,
|
|
|
|
saved_bb = nil,
|
2013-10-22 15:11:31 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
fb = einkfb.open("/dev/fb0"),
|
|
|
|
-- will be set upon loading by Device class:
|
|
|
|
device = nil,
|
2013-10-22 15:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Screen:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
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)
|
|
|
|
if self:getWidth() > self:getHeight() then
|
|
|
|
self.native_rotation_mode = 1
|
|
|
|
else
|
|
|
|
self.native_rotation_mode = 0
|
|
|
|
end
|
|
|
|
self.cur_rotation_mode = self.native_rotation_mode
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
2013-11-26 15:01:38 +00:00
|
|
|
function Screen:refresh(refresh_type, waveform_mode, x, y, w, h)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.fb:refresh(refresh_type, waveform_mode, x, y, w, h)
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getSize()
|
2014-03-13 13:52:43 +00:00
|
|
|
return Geom:new{w = self.bb:getWidth(), h = self.bb:getHeight()}
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getWidth()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.bb:getWidth()
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getHeight()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.bb:getHeight()
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getDPI()
|
2014-03-30 11:44:31 +00:00
|
|
|
if self.dpi ~= nil then return self.dpi end
|
|
|
|
local model = self.device:getModel()
|
|
|
|
if model == "KindlePaperWhite" or model == "KindlePaperWhite2"
|
|
|
|
or model == "Kobo_kraken" or model == "Kobo_phoenix" then
|
|
|
|
self.dpi = 212
|
|
|
|
elseif model == "Kobo_dragon" then
|
|
|
|
self.dpi = 265
|
|
|
|
elseif model == "Kobo_pixie" then
|
|
|
|
self.dpi = 200
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2014-03-30 11:44:31 +00:00
|
|
|
self.dpi = 167
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-03-30 11:44:31 +00:00
|
|
|
return self.dpi
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:scaleByDPI(px)
|
2014-03-13 13:52:43 +00:00
|
|
|
return math.floor(px * self:getDPI()/167)
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:rescaleByDPI(px)
|
2014-03-13 13:52:43 +00:00
|
|
|
return math.ceil(px * 167/self:getDPI())
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getRotationMode()
|
2014-03-13 13:52:43 +00:00
|
|
|
return self.cur_rotation_mode
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getScreenMode()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self:getWidth() > self:getHeight() then
|
|
|
|
return "landscape"
|
|
|
|
else
|
|
|
|
return "portrait"
|
|
|
|
end
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:setRotationMode(mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.fb.bb:rotateAbsolute(-90 * (mode - self.native_rotation_mode - self.blitbuffer_rotation_mode))
|
|
|
|
self.cur_rotation_mode = mode
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:setScreenMode(mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:saveCurrentBB()
|
2014-03-13 13:52:43 +00:00
|
|
|
local width, height = self:getWidth(), self:getHeight()
|
2013-10-22 15:11:31 +00:00
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
if not self.saved_bb then
|
|
|
|
self.saved_bb = Blitbuffer.new(width, height)
|
|
|
|
end
|
|
|
|
if self.saved_bb:getWidth() ~= width then
|
|
|
|
self.saved_bb:free()
|
|
|
|
self.saved_bb = Blitbuffer.new(width, height)
|
|
|
|
end
|
|
|
|
self.saved_bb:blitFullFrom(self.bb)
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:restoreFromSavedBB()
|
2014-03-13 13:52:43 +00:00
|
|
|
self:restoreFromBB(self.saved_bb)
|
|
|
|
-- free data
|
|
|
|
self.saved_bb = nil
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:getCurrentScreenBB()
|
2014-03-13 13:52:43 +00:00
|
|
|
local bb = Blitbuffer.new(self:getWidth(), self:getHeight())
|
|
|
|
bb:blitFullFrom(self.bb)
|
|
|
|
return bb
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function Screen:restoreFromBB(bb)
|
2014-03-13 13:52:43 +00:00
|
|
|
if bb then
|
|
|
|
self.bb:blitFullFrom(bb)
|
|
|
|
else
|
|
|
|
DEBUG("Got nil bb in restoreFromSavedBB!")
|
|
|
|
end
|
2013-10-22 15:11:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return Screen
|