-
Notifications
You must be signed in to change notification settings - Fork 104
/
framebuffer_android.lua
55 lines (44 loc) · 1.69 KB
/
framebuffer_android.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local ffi = require("ffi")
local android = require("android")
local BB = require("ffi/blitbuffer")
local framebuffer = {}
function framebuffer:init()
-- we present this buffer to the outside
self.bb = BB.new(android.screen.width, android.screen.height, BB.TYPE_BBRGB32)
-- TODO: should we better use these?
-- android.lib.ANativeWindow_getWidth(window)
-- android.lib.ANativeWindow_getHeight(window)
self.bb:fill(BB.COLOR_WHITE)
self:refreshFull()
framebuffer.parent.init(self)
end
function framebuffer:refreshFullImp()
if android.app.window == nil then
android.LOGW("cannot blit: no window")
return
end
local buffer = ffi.new("ANativeWindow_Buffer[1]")
if android.lib.ANativeWindow_lock(android.app.window, buffer, nil) < 0 then
android.LOGW("Unable to lock window buffer")
return
end
local bb = nil
if buffer[0].format == ffi.C.WINDOW_FORMAT_RGBA_8888
or buffer[0].format == ffi.C.WINDOW_FORMAT_RGBX_8888
then
bb = BB.new(buffer[0].width, buffer[0].height, BB.TYPE_BBRGB32, buffer[0].bits, buffer[0].stride*4)
elseif buffer[0].format == ffi.C.WINDOW_FORMAT_RGB_565 then
bb = BB.new(buffer[0].width, buffer[0].height, BB.TYPE_BBRGB16, buffer[0].bits, buffer[0].stride*2)
else
android.LOGE("unsupported window format!")
end
if bb then
local ext_bb = self.full_bb or self.bb
bb:setInverse(ext_bb:getInverse())
-- adapt to possible rotation changes
bb:setRotation(ext_bb:getRotation())
bb:blitFrom(ext_bb)
end
android.lib.ANativeWindow_unlockAndPost(android.app.window);
end
return require("ffi/framebuffer"):extend(framebuffer)