Merge pull request #370 from hwhw/native-framebuffer

FFI framebuffer implementation adaptions
This commit is contained in:
Huang Xin
2013-11-26 08:33:12 -08:00
4 changed files with 28 additions and 85 deletions

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()

View File

@@ -575,7 +575,7 @@ function GestureDetector:adjustGesCoordinate(ges)
if Screen.cur_rotation_mode == 1 then
-- in landscape mode rotated 270
if ges.pos then
ges.pos.x, ges.pos.y = (Screen.width - ges.pos.y), (ges.pos.x)
ges.pos.x, ges.pos.y = (Screen:getWidth() - ges.pos.y), (ges.pos.x)
end
if ges.ges == "swipe" or ges.ges == "pan"
or ges.ges == "two_finger_swipe"
@@ -612,7 +612,7 @@ function GestureDetector:adjustGesCoordinate(ges)
elseif Screen.cur_rotation_mode == 3 then
-- in landscape mode rotated 90
if ges.pos then
ges.pos.x, ges.pos.y = (ges.pos.y), (Screen.height - ges.pos.x)
ges.pos.x, ges.pos.y = (ges.pos.y), (Screen:getHeight() - ges.pos.x)
end
if ges.ges == "swipe" or ges.ges == "pan"
or ges.ges == "two_finger_swipe"

View File

@@ -328,10 +328,10 @@ function Input:init()
ev.code = ABS_X
-- We always have to substract from the physical x,
-- regardless of the orientation
if (Screen.width<Screen.height) then
ev.value = Screen.width - ev.value
if (Screen:getWidth()<Screen:getHeight()) then
ev.value = Screen:getWidth() - ev.value
else
ev.value = Screen.height - ev.value
ev.value = Screen:getHeight() - ev.value
end
end
-- same thing for multitouch events (phoenix)
@@ -341,10 +341,10 @@ function Input:init()
ev.code = ABS_MT_POSITION_X
-- We always have to substract from the physical x,
-- regardless of the orientation
if (Screen.width<Screen.height) then
ev.value = Screen.width - ev.value
if (Screen:getWidth()<Screen:getHeight()) then
ev.value = Screen:getWidth() - ev.value
else
ev.value = Screen.height - ev.value
ev.value = Screen:getHeight() - ev.value
end
end
end
@@ -357,10 +357,10 @@ function Input:init()
if ev.code == ABS_X then
-- We always have to substract from the physical x,
-- regardless of the orientation
if (Screen.width<Screen.height) then
ev.value = Screen.width - ev.value
if (Screen:getWidth()<Screen:getHeight()) then
ev.value = Screen:getWidth() - ev.value
else
ev.value = Screen.height - ev.value
ev.value = Screen:getHeight() - ev.value
end
end
return ev