From 9d3c27117d7f425d7b43dd25a4446b0c81bc2f18 Mon Sep 17 00:00:00 2001 From: HW Date: Tue, 26 Nov 2013 16:01:38 +0100 Subject: [PATCH 1/3] 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. --- frontend/ui/device/screen.lua | 89 +++++++---------------------------- 1 file changed, 16 insertions(+), 73 deletions(-) diff --git a/frontend/ui/device/screen.lua b/frontend/ui/device/screen.lua index 81a82f47a..8045eb2c6 100644 --- a/frontend/ui/device/screen.lua +++ b/frontend/ui/device/screen.lua @@ -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() From 11bb9009fa74a20f1cf1eee27df46a1c290bf26e Mon Sep 17 00:00:00 2001 From: HW Date: Tue, 26 Nov 2013 16:04:20 +0100 Subject: [PATCH 2/3] replace Screen.width/Screen.height with accessor methods Screen.width and Screen.height are now gone, use the methods getWidth() and getHeight() to get the relevant data. They will take blitbuffer/framebuffer rotation into account. --- frontend/ui/gesturedetector.lua | 4 ++-- frontend/ui/input.lua | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frontend/ui/gesturedetector.lua b/frontend/ui/gesturedetector.lua index 1086ab555..cfe0e8b5a 100644 --- a/frontend/ui/gesturedetector.lua +++ b/frontend/ui/gesturedetector.lua @@ -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" diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index 0c9955523..ba2a9d84d 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -330,10 +330,10 @@ function Input:init() ev.code = ABS_X -- We always have to substract from the physical x, -- regardless of the orientation - if (Screen.width Date: Tue, 26 Nov 2013 17:06:03 +0100 Subject: [PATCH 3/3] update koreader-base This will need https://github.com/koreader/koreader-base/pull/96 to be applied first --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index 4380c5b0a..3c80d60ef 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 4380c5b0acd976cd919c25e8e9a9787c22dbfda1 +Subproject commit 3c80d60ef8df2265295216e194912392194d96cf