2
0
mirror of https://github.com/koreader/koreader synced 2024-11-16 06:12:56 +00:00

Implements Kindle screen rotate on emulator

Conflicts:

	einkfb.c
This commit is contained in:
kai771 2012-11-16 22:21:59 +01:00 committed by Qingping Hou
parent f2f299cd09
commit 77a322f45f

View File

@ -15,7 +15,6 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/mman.h> #include <sys/mman.h>
@ -24,6 +23,11 @@
#include "einkfb.h" #include "einkfb.h"
#ifdef EMULATE_READER
int emu_w = EMULATE_READER_W;
int emu_h = EMULATE_READER_H;
#endif
static int openFrameBuffer(lua_State *L) { static int openFrameBuffer(lua_State *L) {
const char *fb_device = luaL_checkstring(L, 1); const char *fb_device = luaL_checkstring(L, 1);
FBInfo *fb = (FBInfo*) lua_newuserdata(L, sizeof(FBInfo)); FBInfo *fb = (FBInfo*) lua_newuserdata(L, sizeof(FBInfo));
@ -114,14 +118,14 @@ static int openFrameBuffer(lua_State *L) {
if(SDL_Init(SDL_INIT_VIDEO) < 0) { if(SDL_Init(SDL_INIT_VIDEO) < 0) {
return luaL_error(L, "cannot initialize SDL."); return luaL_error(L, "cannot initialize SDL.");
} }
if(!(fb->screen = SDL_SetVideoMode(EMULATE_READER_W, EMULATE_READER_H, 32, SDL_HWSURFACE))) { if(!(fb->screen = SDL_SetVideoMode(emu_w, emu_h, 32, SDL_HWSURFACE))) {
return luaL_error(L, "can't get video surface %dx%d for 32bpp.", return luaL_error(L, "can't get video surface %dx%d for 32bpp.",
EMULATE_READER_W, EMULATE_READER_H); emu_w, emu_h);
} }
fb->vinfo.xres = EMULATE_READER_W; fb->vinfo.xres = emu_w;
fb->vinfo.yres = EMULATE_READER_H; fb->vinfo.yres = emu_h;
fb->buf->pitch = (EMULATE_READER_W + 1) / 2; fb->buf->pitch = (emu_w + 1) / 2;
fb->buf->data = calloc(fb->buf->pitch * EMULATE_READER_H, sizeof(char)); fb->buf->data = calloc(fb->buf->pitch * emu_h, sizeof(char));
if(fb->buf->data == NULL) { if(fb->buf->data == NULL) {
return luaL_error(L, "cannot get framebuffer emu memory"); return luaL_error(L, "cannot get framebuffer emu memory");
} }
@ -342,7 +346,6 @@ static int einkUpdate(lua_State *L) {
/* NOTICE!!! You must close and reopen framebuffer after called this method. /* NOTICE!!! You must close and reopen framebuffer after called this method.
* Otherwise, screen resolution will not be updated! */ * Otherwise, screen resolution will not be updated! */
static int einkSetOrientation(lua_State *L) { static int einkSetOrientation(lua_State *L) {
#ifndef EMULATE_READER
FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb"); FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb");
int mode = luaL_optint(L, 2, 0); int mode = luaL_optint(L, 2, 0);
@ -367,12 +370,22 @@ static int einkSetOrientation(lua_State *L) {
* +--------------+ * +--------------+
* 0 * 0
* */ * */
#ifndef EMULATE_READER
if (mode == 1) if (mode == 1)
mode = 2; mode = 2;
else if (mode == 2) else if (mode == 2)
mode = 1; mode = 1;
ioctl(fb->fd, FBIO_EINK_SET_DISPLAY_ORIENTATION, mode); ioctl(fb->fd, FBIO_EINK_SET_DISPLAY_ORIENTATION, mode);
#else
if (mode == 0 || mode == 2) {
emu_w = EMULATE_READER_W;
emu_h = EMULATE_READER_H;
}
else if (mode == 1 || mode == 3) {
emu_w = EMULATE_READER_H;
emu_h = EMULATE_READER_W;
}
#endif #endif
return 0; return 0;
} }
@ -390,6 +403,9 @@ static int einkGetOrientation(lua_State *L) {
mode = 1; mode = 1;
else if (mode == 1) else if (mode == 1)
mode = 2; mode = 2;
#else
if (emu_w == EMULATE_READER_H || emu_h == EMULATE_READER_W)
mode = 1;
#endif #endif
lua_pushinteger(L, mode); lua_pushinteger(L, mode);
return 1; return 1;