Skip to content

Commit

Permalink
build ubuntu-touch target
Browse files Browse the repository at this point in the history
  • Loading branch information
chrox committed Oct 3, 2015
1 parent 773db3f commit 5d2ad62
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ $(K2PDFOPT_LIB) $(LEPTONICA_LIB) $(TESSERACT_LIB): $(PNG_LIB) $(ZLIB)
# our own Lua/C/C++ interfacing:

libs: \
$(if $(or $(EMULATE_READER),$(ANDROID),$(WIN32)),,$(OUTPUT_DIR)/libs/libkoreader-input.so) \
$(if $(or $(SDL),$(ANDROID)),,$(OUTPUT_DIR)/libs/libkoreader-input.so) \
$(OUTPUT_DIR)/libs/libkoreader-lfs.so \
$(if $(ANDROID),,$(OUTPUT_DIR)/libs/libkoreader-djvu.so) \
$(OUTPUT_DIR)/libs/libkoreader-cre.so \
Expand Down
32 changes: 22 additions & 10 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,27 @@ else ifeq ($(TARGET), kindle-legacy)
export LEGACY=1
else ifeq ($(TARGET), kobo)
CHOST?=arm-linux-gnueabihf
else ifeq ($(TARGET), ubuntu-touch)
CHOST?=arm-linux-gnueabihf
export SDL=1
export UBUNTUTOUCH=1
else ifeq ($(TARGET), android)
export ANDROID=1
export PATH:=$(CURDIR)/$(ANDROID_TOOLCHAIN)/bin:$(PATH)
export SYSROOT=$(NDK)/platforms/android-9/arch-arm
export ANDROID=1
export PATH:=$(CURDIR)/$(ANDROID_TOOLCHAIN)/bin:$(PATH)
export SYSROOT=$(NDK)/platforms/android-9/arch-arm
CHOST?=arm-linux-androideabi
else ifeq ($(TARGET), win32)
CHOST?=i686-w64-mingw32
export WIN32=1
CHOST?=i686-w64-mingw32
export WIN32=1
export SDL=1
else ifeq ($(TARGET), pocketbook)
CHOST?=arm-obreey-linux-gnueabi
export LEGACY=1
export POCKETBOOK=1
export PATH:=$(CURDIR)/$(POCKETBOOK_TOOLCHAIN)/bin:$(PATH)
export SYSROOT=$(CURDIR)/$(POCKETBOOK_TOOLCHAIN)/arm-obreey-linux-gnueabi/sysroot
CHOST?=arm-obreey-linux-gnueabi
export LEGACY=1
export POCKETBOOK=1
export PATH:=$(CURDIR)/$(POCKETBOOK_TOOLCHAIN)/bin:$(PATH)
export SYSROOT=$(CURDIR)/$(POCKETBOOK_TOOLCHAIN)/arm-obreey-linux-gnueabi/sysroot
else
export SDL=1
endif

# unknown device
Expand Down Expand Up @@ -151,6 +158,11 @@ ifeq ($(TARGET), kobo)
ARM_ARCH+=-mfloat-abi=hard
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
else ifeq ($(TARGET), ubuntu-touch)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=hard
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
else ifeq ($(TARGET), kindle)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
Expand Down
57 changes: 44 additions & 13 deletions ffi/SDL2_0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ function S.open()
error("cannot initialize SDL")
end

S.w = tonumber(os.getenv("EMULATE_READER_W")) or 600
S.h = tonumber(os.getenv("EMULATE_READER_H")) or 800
local full_screen = os.getenv("SDL_FULLSCREEN")
if full_screen then
local mode = ffi.new("struct SDL_DisplayMode")
if SDL.SDL_GetCurrentDisplayMode(0, mode) ~= 0 then
error("cannot get current display mode")
end
S.w, S.h = mode.w, mode.h
else
S.w = tonumber(os.getenv("EMULATE_READER_W")) or 600
S.h = tonumber(os.getenv("EMULATE_READER_H")) or 800
end

-- set up screen (window)
S.screen = SDL.SDL_CreateWindow("KoReader",
SDL.SDL_WINDOWPOS_UNDEFINED,
SDL.SDL_WINDOWPOS_UNDEFINED,
S.w, S.h, 0)
S.w, S.h, full_screen and 1 or 0)

S.renderer = SDL.SDL_CreateRenderer(S.screen, -1, 0)
S.texture = SDL.SDL_CreateTexture(S.renderer,
Expand Down Expand Up @@ -107,27 +116,49 @@ function S.waitForEvent(usecs)
genEmuEvent(ffi.C.EV_KEY, event.key.keysym.scancode, 1)
elseif event.type == SDL.SDL_KEYUP then
genEmuEvent(ffi.C.EV_KEY, event.key.keysym.scancode, 0)
elseif event.type == SDL.SDL_MOUSEMOTION then
elseif event.type == SDL.SDL_MOUSEMOTION
or event.type == SDL.SDL_FINGERMOTION then
local is_finger = event.type == SDL.SDL_FINGERMOTION
if is_in_touch then
if event.motion.xrel ~= 0 then
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X, event.button.x)
end
if event.motion.yrel ~= 0 then
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y, event.button.y)
if is_finger then
if event.tfinger.dx ~= 0 then
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X,
event.tfinger.x * S.w)
end
if event.tfinger.dy ~= 0 then
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y,
event.tfinger.y * S.h)
end
else
if event.motion.xrel ~= 0 then
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X,
event.button.x)
end
if event.motion.yrel ~= 0 then
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y,
event.button.y)
end
end
genEmuEvent(ffi.C.EV_SYN, ffi.C.SYN_REPORT, 0)
end
elseif event.type == SDL.SDL_MOUSEBUTTONUP then
elseif event.type == SDL.SDL_MOUSEBUTTONUP
or event.type == SDL.SDL_FINGERUP then
is_in_touch = false;
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_TRACKING_ID, -1)
genEmuEvent(ffi.C.EV_SYN, ffi.C.SYN_REPORT, 0)
elseif event.type == SDL.SDL_MOUSEBUTTONDOWN then
elseif event.type == SDL.SDL_MOUSEBUTTONDOWN
or event.type == SDL.SDL_FINGERDOWN then
local is_finger = event.type == SDL.SDL_FINGERDOWN
-- use mouse click to simulate single tap
is_in_touch = true
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_TRACKING_ID, 0)
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X, event.button.x)
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y, event.button.y)
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_X,
is_finger and event.tfinger.x * S.w or event.button.x)
genEmuEvent(ffi.C.EV_ABS, ffi.C.ABS_MT_POSITION_Y,
is_finger and event.tfinger.y * S.h or event.button.y)
genEmuEvent(ffi.C.EV_SYN, ffi.C.SYN_REPORT, 0)
elseif event.type == SDL.SDL_MULTIGESTURE then
-- TODO: multi-touch support
elseif event.type == SDL.SDL_QUIT then
error("application forced to quit")
end
Expand Down
19 changes: 14 additions & 5 deletions ffi/SDL2_0_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ typedef short unsigned int Uint16;
typedef short int Sint16;
typedef unsigned char Uint8;
typedef signed char Sint8;
typedef int64_t Sint64;
struct SDL_Keysym {
enum {
SDL_SCANCODE_UNKNOWN = 0,
Expand Down Expand Up @@ -450,6 +451,13 @@ struct SDL_UserEvent {
void *data1;
void *data2;
};
struct SDL_DisplayMode {
unsigned int format;
int w;
int h;
int refresh_rate;
void *data;
};
struct SDL_SysWMEvent {
unsigned int type;
unsigned int timestamp;
Expand All @@ -458,8 +466,8 @@ struct SDL_SysWMEvent {
struct SDL_TouchFingerEvent {
unsigned int type;
unsigned int timestamp;
long int touchId;
long int fingerId;
Sint64 touchId;
Sint64 fingerId;
float x;
float y;
float dx;
Expand All @@ -469,7 +477,7 @@ struct SDL_TouchFingerEvent {
struct SDL_MultiGestureEvent {
unsigned int type;
unsigned int timestamp;
long int touchId;
Sint64 touchId;
float dTheta;
float dDist;
float x;
Expand All @@ -480,8 +488,8 @@ struct SDL_MultiGestureEvent {
struct SDL_DollarGestureEvent {
unsigned int type;
unsigned int timestamp;
long int touchId;
long int gestureId;
Sint64 touchId;
Sint64 gestureId;
unsigned int numFingers;
float error;
float x;
Expand Down Expand Up @@ -541,6 +549,7 @@ int SDL_WaitEventTimeout(union SDL_Event *, int) __attribute__((visibility("defa
int SDL_PollEvent(union SDL_Event *) __attribute__((visibility("default")));
unsigned int SDL_GetTicks(void) __attribute__((visibility("default")));
void SDL_Delay(unsigned int) __attribute__((visibility("default")));
int SDL_GetCurrentDisplayMode(int, struct SDL_DisplayMode*) __attribute__((visibility("default")));
struct SDL_Window *SDL_CreateWindow(const char *, int, int, int, int, unsigned int) __attribute__((visibility("default")));
struct SDL_Renderer *SDL_CreateRenderer(struct SDL_Window *, int, unsigned int) __attribute__((visibility("default")));
int SDL_CreateWindowAndRenderer(int, int, unsigned int, struct SDL_Window **, struct SDL_Renderer **) __attribute__((visibility("default")));
Expand Down
2 changes: 1 addition & 1 deletion ffi/input.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local util = require("ffi/util")

if util.isEmulated() then
if util.isSDL() then
if util.haveSDL2() then
return require("ffi/input_SDL2_0")
else
Expand Down
22 changes: 18 additions & 4 deletions ffi/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ function util.multiByteToUTF8(str, codepage)
end
end

function util.isEmulated()
return (ffi.arch ~= "arm")
end

function util.isWindows()
return ffi.os == "Windows"
end
Expand All @@ -170,19 +166,37 @@ local isAndroid = nil
function util.isAndroid()
if isAndroid == nil then
isAndroid = pcall(require, "android")
else
isAndroid = false
end
return isAndroid
end

local haveSDL1 = nil
local haveSDL2 = nil

function util.haveSDL1()
if haveSDL1 == nil then
haveSDL1 = pcall(ffi.load, "SDL")
end
return haveSDL1
end

function util.haveSDL2()
if haveSDL2 == nil then
haveSDL2 = pcall(ffi.load, "SDL2")
end
return haveSDL2
end

local isSDL = nil
function util.isSDL()
if isSDL == nil then
isSDL = util.haveSDL2() or util.haveSDL1()
end
return isSDL
end

function util.idiv(a, b)
q = a/b
return (q > 0) and math.floor(q) or math.ceil(q)
Expand Down

0 comments on commit 5d2ad62

Please sign in to comment.