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 committed 2013-11-26 16:01:38 +01:00
1 parent 0efa0dd067
commit 9d3c27117d
1 file changed
+16 -73
+16 -73
View File
@@ -29,10 +29,8 @@ Codes for rotation modes:
local Screen = {
width = 0,
height = 0,
native_rotation_mode = nil,
cur_rotation_mode = 0,
native_rotation_mode = nil,
bb = nil,
saved_bb = nil,
@@ -43,19 +41,10 @@ local Screen = {
}
function Screen:init()
-- for unknown strange reason, pitch*2 is 10 px more than screen width in KPW
self.width, self.height = self.fb:getSize()
-- Blitbuffer still uses inverted 4bpp bitmap, so pitch should be
-- (self.width / 2)
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.bb = self.fb.bb
-- 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
@@ -63,50 +52,20 @@ function Screen:init()
self.cur_rotation_mode = self.native_rotation_mode
end
function Screen:refresh(refesh_type, waveform_mode, x, y, w, h)
if x then x = x < 0 and 0 or math.floor(x) end
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)
function Screen:refresh(refresh_type, waveform_mode, x, y, w, h)
self.fb:refresh(refresh_type, waveform_mode, x, y, w, h)
end
function Screen:getSize()
return Geom:new{w = self.width, h = self.height}
return Geom:new{w = self.bb:getWidth(), h = self.bb:getHeight()}
end
function Screen:getWidth()
return self.width
return self.bb:getWidth()
end
function Screen:getHeight()
return self.height
return self.bb:getHeight()
end
function Screen:getDPI()
@@ -131,21 +90,12 @@ function Screen:rescaleByDPI(px)
return math.ceil(px * 167/self:getDPI())
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()
return self.cur_rotation_mode
end
function Screen:getScreenMode()
if self.width > self.height then
if self:getWidth() > self:getHeight() then
return "landscape"
else
return "portrait"
@@ -153,17 +103,8 @@ function Screen:getScreenMode()
end
function Screen:setRotationMode(mode)
if mode > 3 or mode < 0 then
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.fb.bb:rotateAbsolute(-90 * (mode - self.native_rotation_mode))
self.cur_rotation_mode = mode
self.bb:free()
self.bb = Blitbuffer.new(self.width, self.height, self.width/2)
end
function Screen:setScreenMode(mode)
@@ -184,17 +125,19 @@ function Screen:saveCurrentBB()
local width, height = self:getWidth(), self:getHeight()
if not self.saved_bb then
self.saved_bb = Blitbuffer.new(width, height, self.width/2)
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, self.width/2)
self.saved_bb = Blitbuffer.new(width, height)
end
self.saved_bb:blitFullFrom(self.bb)
end
function Screen:restoreFromSavedBB()
self:restoreFromBB(self.saved_bb)
-- free data
self.saved_bb = nil
end
function Screen:getCurrentScreenBB()