Skip to content

Commit

Permalink
Merge pull request #96 from hwhw/ffi-framebuffer-native
Browse files Browse the repository at this point in the history
FFI interface for Linux framebuffer (eink-oriented for now)
  • Loading branch information
chrox committed Nov 26, 2013
2 parents f9cfbf7 + 3c80d60 commit 3aef382
Show file tree
Hide file tree
Showing 23 changed files with 1,055 additions and 741 deletions.
13 changes: 0 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ libs: \
$(OUTPUT_DIR)/libs/libkoreader-luagettext.so \
$(OUTPUT_DIR)/libs/libkoreader-kobolight.so \
$(OUTPUT_DIR)/libs/libkoreader-input.so \
$(OUTPUT_DIR)/libs/libkoreader-einkfb.so \
$(OUTPUT_DIR)/libs/libkoreader-drawcontext.so \
$(OUTPUT_DIR)/libs/libkoreader-blitbuffer.so \
$(OUTPUT_DIR)/libs/libkoreader-lfs.so \
$(OUTPUT_DIR)/libs/libkoreader-koptcontext.so \
$(OUTPUT_DIR)/libs/libkoreader-pic.so \
Expand All @@ -205,16 +202,6 @@ $(OUTPUT_DIR)/libs/libkoreader-input.so: input.c \
$(CC) $(DYNLIB_CFLAGS) $(EMU_CFLAGS) \
-o $@ $< $(POPEN_NOSHELL_LIB) $(EMU_LDFLAGS)

$(OUTPUT_DIR)/libs/libkoreader-einkfb.so: einkfb.c
$(CC) -Iinclude/ $(DYNLIB_CFLAGS) $(EMU_CFLAGS)\
-o $@ $< $(EMU_LDFLAGS)

$(OUTPUT_DIR)/libs/libkoreader-drawcontext.so: drawcontext.c
$(CC) $(DYNLIB_CFLAGS) -o $@ $<

$(OUTPUT_DIR)/libs/libkoreader-blitbuffer.so: blitbuffer.c
$(CC) $(DYNLIB_CFLAGS) -o $@ $<

$(OUTPUT_DIR)/libs/libkoreader-lfs.so: luafilesystem/src/lfs.c
$(CC) $(DYNLIB_CFLAGS) -o $@ $<

Expand Down
4 changes: 2 additions & 2 deletions djvu.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static int openPage(lua_State *L) {
/* get page size after zoomed */
static int getPageSize(lua_State *L) {
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
DrawContext *dc = (DrawContext*) lua_topointer(L, 2);

lua_pushnumber(L, dc->zoom * page->info.width);
lua_pushnumber(L, dc->zoom * page->info.height);
Expand Down Expand Up @@ -665,7 +665,7 @@ static int drawReflowedPage(lua_State *L) {

static int drawPage(lua_State *L) {
DjvuPage *page = (DjvuPage*) luaL_checkudata(L, 1, "djvupage");
DrawContext *dc = (DrawContext*) luaL_checkudata(L, 2, "drawcontext");
DrawContext *dc = (DrawContext*) lua_topointer(L, 2);
BlitBuffer *bb = (BlitBuffer*) lua_topointer(L, 3);
ddjvu_render_mode_t djvu_render_mode = (int) luaL_checkint(L, 6);
unsigned char adjusted_low[16], adjusted_high[16];
Expand Down
117 changes: 0 additions & 117 deletions drawcontext.c

This file was deleted.

5 changes: 0 additions & 5 deletions drawcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#ifndef _DRAWCONTEXT_H
#define _DRAWCONTEXT_H

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

typedef struct DrawContext {
int rotate;
double zoom;
Expand All @@ -30,6 +26,5 @@ typedef struct DrawContext {
int offset_y;
} DrawContext;

int luaopen_drawcontext(lua_State *L);
#endif

File renamed without changes.
File renamed without changes.
21 changes: 17 additions & 4 deletions include/mxcfb.h → ffi-cdecl/include/mxcfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* from Kindle 5.3.0 firmware. Thanks to eureka@mobileread.
* http://www.mobileread.com/forums/showpost.php?p=2337118&postcount=818
*
* - Modified so that Kobo specifics are now in separately named structs
*
* The code contained herein is licensed under the GNU Lesser General
* Public License. You may obtain a copy of the GNU Lesser General
Expand Down Expand Up @@ -108,10 +109,14 @@ struct mxcfb_rect {
#define FB_TEMP_AUTO_UPDATE_DISABLE -1

struct mxcfb_alt_buffer_data {
#ifdef KOBO_PLATFORM
__u32 phys_addr;
__u32 width; /* width of entire buffer */
__u32 height; /* height of entire buffer */
struct mxcfb_rect alt_update_region; /* region within buffer to update */
};
struct mxcfb_alt_buffer_data_kobo {
/* virt_addr is not included in amazon's source */
void *virt_addr;
#endif
__u32 phys_addr;
__u32 width; /* width of entire buffer */
__u32 height; /* height of entire buffer */
Expand All @@ -123,16 +128,24 @@ struct mxcfb_update_data {
__u32 waveform_mode;
__u32 update_mode;
__u32 update_marker;
#ifndef KOBO_PLATFORM
/* these two fields have been added by amazon */
__u32 hist_bw_waveform_mode;
__u32 hist_gray_waveform_mode;
#endif
int temp;
uint flags;
struct mxcfb_alt_buffer_data alt_buffer_data;
};
typedef struct mxcfb_update_data mxcfb_update_data;
struct mxcfb_update_data_kobo {
struct mxcfb_rect update_region;
__u32 waveform_mode;
__u32 update_mode;
__u32 update_marker;
int temp;
uint flags;
struct mxcfb_alt_buffer_data_kobo alt_buffer_data;
};
typedef struct mxcfb_update_data mxcfb_update_data_kobo;

/* this is only used in kindle firmware 5.0, later version (5.1) has changed
* the struct to mxcfb_update_data (see above) */
Expand Down
45 changes: 45 additions & 0 deletions ffi-cdecl/linux_fb_decl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// standard Linux framebuffer headers
#include <linux/fb.h>

#include <linux/ioctl.h>
// specialized eink framebuffer headers
typedef unsigned int u_int;
typedef unsigned long u_long;
#include "include/einkfb.h"
typedef unsigned int uint;
#include "include/mxcfb.h"

#include "cdecl.h"

cdecl_const(FBIOGET_FSCREENINFO)
cdecl_const(FBIOGET_VSCREENINFO)

cdecl_const(FB_TYPE_PACKED_PIXELS)

cdecl_struct(fb_bitfield)
cdecl_struct(fb_fix_screeninfo)
cdecl_struct(fb_var_screeninfo)

// einkfb:

cdecl_enum(fx_type)
cdecl_struct(update_area_t)
cdecl_enum(orientation_t)

cdecl_enum(einkfb_events_t)
cdecl_struct(einkfb_event_t)

cdecl_const(FBIO_EINK_UPDATE_DISPLAY)
cdecl_const(FBIO_EINK_UPDATE_DISPLAY_AREA)
cdecl_const(FBIO_EINK_SET_DISPLAY_ORIENTATION)
cdecl_const(FBIO_EINK_GET_DISPLAY_ORIENTATION)

// mxcfb:

cdecl_struct(mxcfb_rect)
cdecl_struct(mxcfb_alt_buffer_data)
cdecl_struct(mxcfb_alt_buffer_data_kobo)
cdecl_struct(mxcfb_update_data)
cdecl_struct(mxcfb_update_data_kobo)

cdecl_const(MXCFB_SEND_UPDATE)
73 changes: 73 additions & 0 deletions ffi-cdecl/posix_decl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <sys/mman.h>
#include <stropts.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <poll.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "cdecl.h"

cdecl_type(size_t)
cdecl_type(off_t)

cdecl_struct(timeval)
cdecl_struct(statvfs)

cdecl_func(pipe)
cdecl_func(fork)
cdecl_func(dup)
cdecl_func(dup2)

cdecl_const(O_RDWR)
cdecl_const(O_RDONLY)
cdecl_const(O_NONBLOCK)
cdecl_func(open)
cdecl_func(close)
cdecl_func(fcntl)
cdecl_func(execl)
cdecl_func(execlp)
cdecl_func(execv)
cdecl_func(execvp)
cdecl_func(write)
cdecl_func(read)
cdecl_func(kill)
cdecl_func(waitpid)

cdecl_struct(pollfd)
cdecl_const(POLLIN)
cdecl_const(POLLOUT)
cdecl_const(POLLERR)
cdecl_const(POLLHUP)
cdecl_func(poll)

cdecl_const(PROT_READ)
cdecl_const(PROT_WRITE)
cdecl_const(MAP_SHARED)
cdecl_const(MAP_FAILED)
cdecl_func(mmap)

cdecl_func(ioctl)
cdecl_func(sleep)
cdecl_func(usleep)
cdecl_func(statvfs)
cdecl_func(gettimeofday)
cdecl_func(realpath)

cdecl_func(malloc)
cdecl_func(free)

cdecl_func(strdup)
cdecl_func(strndup)

cdecl_func(fopen)
cdecl_func(fclose)
cdecl_func(printf)
cdecl_func(sprintf)
cdecl_func(fprintf)
cdecl_func(fputc)
Loading

0 comments on commit 3aef382

Please sign in to comment.