2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00

remove redundancy: new framebuffer supports rotation, multi-bpp

We can get rid of shadow blitbuffers. Screen.bb is now fb.bb.
All bpp conversion is now done by the blitbuffer abstraction layer.
Rotation mechanism is adapted to this.
This commit is contained in:
HW 2013-11-26 16:01:38 +01:00
parent 0efa0dd067
commit 9d3c27117d

View File

@ -29,10 +29,8 @@ Codes for rotation modes:
local Screen = { local Screen = {
width = 0,
height = 0,
native_rotation_mode = nil,
cur_rotation_mode = 0, cur_rotation_mode = 0,
native_rotation_mode = nil,
bb = nil, bb = nil,
saved_bb = nil, saved_bb = nil,
@ -43,19 +41,10 @@ local Screen = {
} }
function Screen:init() function Screen:init()
-- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW self.bb = self.fb.bb
self.width, self.height = self.fb:getSize() -- asking the framebuffer for orientation is error prone,
-- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be -- so we do this simple heuristic (for now)
-- (self.width / 2) if self:getWidth() > self:getHeight() then
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
if self.width > self.height then
-- For another unknown strange reason, self.fb:getOrientation always
-- return 0 in KPW, even though we are in landscape mode.
-- Seems like the native framework change framebuffer on the fly when
-- starting booklet. Starting KPV from ssh and KPVBooklet will get
-- different framebuffer height and width.
--
--self.native_rotation_mode = self.fb:getOrientation()
self.native_rotation_mode = 1 self.native_rotation_mode = 1
else else
self.native_rotation_mode = 0 self.native_rotation_mode = 0
@ -63,50 +52,20 @@ function Screen:init()
self.cur_rotation_mode = self.native_rotation_mode self.cur_rotation_mode = self.native_rotation_mode
end end
function Screen:refresh(refesh_type, waveform_mode, x, y, w, h) function Screen:refresh(refresh_type, waveform_mode, x, y, w, h)
if x then x = x < 0 and 0 or math.floor(x) end self.fb:refresh(refresh_type, waveform_mode, x, y, w, h)
if y then y = y < 0 and 0 or math.floor(y) end
if w then w = w + x > self.width and self.width - x or math.ceil(w) end
if h then h = h + y > self.height and self.height - y or math.ceil(h) end
if self.native_rotation_mode == self.cur_rotation_mode then
self.fb.bb:blitFrom(self.bb, 0, 0, 0, 0, self.width, self.height)
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 1 then
self.fb.bb:blitFromRotate(self.bb, 270)
if x and y and w and h then
x, y = y, self.width - w - x
w, h = h, w
end
elseif self.native_rotation_mode == 0 and self.cur_rotation_mode == 3 then
self.fb.bb:blitFromRotate(self.bb, 90)
if x and y and w and h then
x, y = self.height - h - y, x
w, h = h, w
end
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 0 then
self.fb.bb:blitFromRotate(self.bb, 90)
if x and y and w and h then
x, y = self.height - h - y, x
w, h = h, w
end
elseif self.native_rotation_mode == 1 and self.cur_rotation_mode == 3 then
self.fb.bb:blitFromRotate(self.bb, 180)
if x and y and w and h then
x, y = self.width - w - x, self.height - h - y
end
end
self.fb:refresh(refesh_type, waveform_mode, x, y, w, h)
end end
function Screen:getSize() function Screen:getSize()
return Geom:new{w = self.width, h = self.height} return Geom:new{w = self.bb:getWidth(), h = self.bb:getHeight()}
end end
function Screen:getWidth() function Screen:getWidth()
return self.width return self.bb:getWidth()
end end
function Screen:getHeight() function Screen:getHeight()
return self.height return self.bb:getHeight()
end end
function Screen:getDPI() function Screen:getDPI()
@ -131,21 +90,12 @@ function Screen:rescaleByDPI(px)
return math.ceil(px * 167/self:getDPI()) return math.ceil(px * 167/self:getDPI())
end end
function Screen:getPitch()
return self.fb:getPitch()
end
function Screen:getNativeRotationMode()
-- in EMU mode, you will always get 0 from getOrientation()
return self.fb:getOrientation()
end
function Screen:getRotationMode() function Screen:getRotationMode()
return self.cur_rotation_mode return self.cur_rotation_mode
end end
function Screen:getScreenMode() function Screen:getScreenMode()
if self.width > self.height then if self:getWidth() > self:getHeight() then
return "landscape" return "landscape"
else else
return "portrait" return "portrait"
@ -153,17 +103,8 @@ function Screen:getScreenMode()
end end
function Screen:setRotationMode(mode) function Screen:setRotationMode(mode)
if mode > 3 or mode < 0 then self.fb.bb:rotateAbsolute(-90 * (mode - self.native_rotation_mode))
return
end
-- mode 0 and mode 2 has the same width and height, so do mode 1 and 3
if (self.cur_rotation_mode % 2) ~= (mode % 2) then
self.width, self.height = self.height, self.width
end
self.cur_rotation_mode = mode self.cur_rotation_mode = mode
self.bb:free()
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
end end
function Screen:setScreenMode(mode) function Screen:setScreenMode(mode)
@ -184,17 +125,19 @@ function Screen:saveCurrentBB()
local width, height = self:getWidth(), self:getHeight() local width, height = self:getWidth(), self:getHeight()
if not self.saved_bb then if not self.saved_bb then
self.saved_bb = Blitbuffer.new(width, height, self.width/2) self.saved_bb = Blitbuffer.new(width, height)
end end
if self.saved_bb:getWidth() ~= width then if self.saved_bb:getWidth() ~= width then
self.saved_bb:free() self.saved_bb:free()
self.saved_bb = Blitbuffer.new(width, height, self.width/2) self.saved_bb = Blitbuffer.new(width, height)
end end
self.saved_bb:blitFullFrom(self.bb) self.saved_bb:blitFullFrom(self.bb)
end end
function Screen:restoreFromSavedBB() function Screen:restoreFromSavedBB()
self:restoreFromBB(self.saved_bb) self:restoreFromBB(self.saved_bb)
-- free data
self.saved_bb = nil
end end
function Screen:getCurrentScreenBB() function Screen:getCurrentScreenBB()