revamped some files

This commit is contained in:
JosePereira 2012-06-11 20:08:17 +01:00
parent ef3118c763
commit a3403ab062
14 changed files with 969 additions and 585 deletions

View File

@ -1,94 +1,76 @@
LOCAL_PATH:= $(call my-dir) LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm LIBVNCSERVER_ROOT:=./LibVNCServer-0.9.9
local_c_flags += -Wall -O3 -DLIBVNCSERVER_WITH_WEBSOCKETS -DLIBVNCSERVER_HAVE_LIBPNG LIBVNCSERVER_SRC_FILES:= \
$(LIBVNCSERVER_ROOT)/libvncserver/main.c \
$(LIBVNCSERVER_ROOT)/libvncserver/rfbserver.c \
$(LIBVNCSERVER_ROOT)/libvncserver/rfbregion.c \
$(LIBVNCSERVER_ROOT)/libvncserver/auth.c \
$(LIBVNCSERVER_ROOT)/libvncserver/sockets.c \
$(LIBVNCSERVER_ROOT)/libvncserver/stats.c \
$(LIBVNCSERVER_ROOT)/libvncserver/corre.c \
$(LIBVNCSERVER_ROOT)/libvncserver/rfbssl_openssl.c \
$(LIBVNCSERVER_ROOT)/libvncserver/rfbcrypto_openssl.c \
$(LIBVNCSERVER_ROOT)/libvncserver/hextile.c \
$(LIBVNCSERVER_ROOT)/libvncserver/rre.c \
$(LIBVNCSERVER_ROOT)/libvncserver/translate.c \
$(LIBVNCSERVER_ROOT)/libvncserver/cutpaste.c \
$(LIBVNCSERVER_ROOT)/libvncserver/httpd.c \
$(LIBVNCSERVER_ROOT)/libvncserver/cursor.c \
$(LIBVNCSERVER_ROOT)/libvncserver/font.c \
$(LIBVNCSERVER_ROOT)/libvncserver/draw.c \
$(LIBVNCSERVER_ROOT)/libvncserver/websockets.c \
$(LIBVNCSERVER_ROOT)/libvncserver/selbox.c \
$(LIBVNCSERVER_ROOT)/libvncserver/cargs.c \
$(LIBVNCSERVER_ROOT)/libvncserver/ultra.c \
$(LIBVNCSERVER_ROOT)/libvncserver/scale.c \
$(LIBVNCSERVER_ROOT)/libvncserver/zlib.c \
$(LIBVNCSERVER_ROOT)/libvncserver/zrle.c \
$(LIBVNCSERVER_ROOT)/libvncserver/zrleoutstream.c \
$(LIBVNCSERVER_ROOT)/libvncserver/zrlepalettehelper.c \
$(LIBVNCSERVER_ROOT)/libvncserver/tight.c \
$(LIBVNCSERVER_ROOT)/common/d3des.c \
$(LIBVNCSERVER_ROOT)/common/vncauth.c \
$(LIBVNCSERVER_ROOT)/common/minilzo.c \
$(LIBVNCSERVER_ROOT)/common/zywrletemplate.c \
$(LIBVNCSERVER_ROOT)/common/turbojpeg.c
local_src_files:= \ LOCAL_CFLAGS += -Wall \
input.c \ -O3 \
gui.c \ -DLIBVNCSERVER_WITH_WEBSOCKETS \
adb_method.c \ -DLIBVNCSERVER_HAVE_LIBPNG
framebuffer_method.c \
suinput.c \
droidvncserver.c \
gralloc_method.c \
libvncserver/libvncserver/scale.c \
libvncserver/libvncserver/main.c \
libvncserver/libvncserver/rfbserver.c \
libvncserver/libvncserver/rfbregion.c \
libvncserver/libvncserver/auth.c \
libvncserver/libvncserver/sockets.c \
libvncserver/libvncserver/stats.c \
libvncserver/libvncserver/corre.c \
libvncserver/libvncserver/hextile.c \
libvncserver/libvncserver/rre.c \
libvncserver/libvncserver/translate.c \
libvncserver/libvncserver/cutpaste.c \
libvncserver/libvncserver/httpd.c \
libvncserver/libvncserver/cursor.c \
libvncserver/libvncserver/font.c \
libvncserver/libvncserver/draw.c \
libvncserver/libvncserver/selbox.c \
libvncserver/libvncserver/minilzo.c \
libvncserver/libvncserver/vncauth.c \
libvncserver/libvncserver/d3des.c \
libvncserver/libvncserver/md5.c \
libvncserver/libvncserver/cargs.c \
libvncserver/libvncserver/ultra.c \
libvncserver/libvncserver/zlib.c \
libvncserver/libvncserver/zrle.c \
libvncserver/libvncserver/zrleoutstream.c \
libvncserver/libvncserver/zrlepalettehelper.c \
libvncserver/libvncserver/tight.c \
libvncserver/libvncserver/zywrletemplate.c \
libvncserver/libvncserver/websockets.c
ginger_up := displaybinder.cpp LOCAL_LDLIBS += -llog -lz -ldl
local_c_includes := \ LOCAL_SRC_FILES += \
$(LOCAL_PATH) \ $(LIBVNCSERVER_SRC_FILES)\
$(LOCAL_PATH)/libvncserver/libvncserver \ droidvncserver.c \
$(LOCAL_PATH)/libvncserver \ gui.c \
$(LOCAL_PATH)/libvncserver/common \ inputMethods/input.c \
$(LOCAL_PATH)/../../zlib \ screenMethods/adb.c \
$(LOCAL_PATH)/../../jpeg \ screenMethods/framebuffer.c \
$(LOCAL_PATH)/../../openssl/include \ screenMethods/gralloc.c \
$(LOCAL_PATH)/../../libpng \ screenMethods/flinger.c \
suinput/suinput.c
#######################################
# target LOCAL_C_INCLUDES += \
include $(CLEAR_VARS) $(LOCAL_PATH) \
LOCAL_SRC_FILES += $(local_src_files) $(LOCAL_PATH)/screenMethods \
LOCAL_CFLAGS += $(local_c_flags) -DANDROID_FROYO $(LOCAL_PATH)/inputMethods \
LOCAL_C_INCLUDES += $(local_c_includes) $(LOCAL_PATH)/suinput \
$(LOCAL_PATH)/../libpng \
$(LOCAL_PATH)/../jpeg \
$(LOCAL_PATH)/../openssl/include \
$(LOCAL_PATH)/$(LIBVNCSERVER_ROOT)/libvncserver \
$(LOCAL_PATH)/$(LIBVNCSERVER_ROOT)/common \
$(LOCAL_PATH)/$(LIBVNCSERVER_ROOT)/rfb \
$(LOCAL_PATH)/$(LIBVNCSERVER_ROOT)/ \
$(LOCAL_PATH)/../../nativeMethods/
LOCAL_STATIC_LIBRARIES := libjpeg libpng libssl_static libcrypto_static
LOCAL_MODULE:= androidvncserver_froyo LOCAL_MODULE:= androidvncserver
LOCAL_MODULE_TAGS:= optional
LOCAL_STATIC_LIBRARIES := libcutils libz libpng jpeg
LOCAL_SHARED_LIBRARIES := libcrypto libssl libhardware
include $(BUILD_EXECUTABLE)
#######################################
# target
include $(CLEAR_VARS)
LOCAL_SRC_FILES += $(local_src_files) $(ginger_up)
LOCAL_CFLAGS += $(local_c_flags)
LOCAL_C_INCLUDES += $(local_c_includes)
LOCAL_MODULE:= androidvncserver_gingerup
LOCAL_MODULE_TAGS:= optional
LOCAL_STATIC_LIBRARIES := libcutils libz libpng jpeg
LOCAL_SHARED_LIBRARIES := libcrypto libssl libhardware libsurfaceflinger_client libui
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)

View File

@ -18,62 +18,61 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "common.h" #include "common.h"
#include "framebuffer_method.h" #include "framebuffer.h"
#include "gralloc_method.h" #include "adb.h"
#include "adb_method.h"
#include "gui.h" #include "gui.h"
#include "input.h" #include "input.h"
#include "displaybinder.h" #include "flinger.h"
#include "gralloc.h"
#include "libvncserver/scale.h"
#include "rfb/rfb.h"
#include "rfb/keysym.h"
#include "suinput.h"
#define CONCAT2(a,b) a##b #define CONCAT2(a,b) a##b
#define CONCAT2E(a,b) CONCAT2(a,b) #define CONCAT2E(a,b) CONCAT2(a,b)
#define CONCAT3(a,b,c) a##b##c #define CONCAT3(a,b,c) a##b##c
#define CONCAT3E(a,b,c) CONCAT3(a,b,c) #define CONCAT3E(a,b,c) CONCAT3(a,b,c)
char VNC_PASSWORD[256] = ""; char VNC_PASSWORD[256] = "";
int VNC_PORT=5901;
/* Android already has 5900 bound natively in some devices. */ /* Android already has 5900 bound natively in some devices. */
int VNC_PORT=5901;
unsigned int *cmpbuf; unsigned int *cmpbuf;
unsigned int *vncbuf; unsigned int *vncbuf;
static rfbScreenInfoPtr vncscr; static rfbScreenInfoPtr vncscr;
int idle=0,standby=0, rotation=0,scaling=100; uint32_t idle = 0;
char *rhost=NULL; uint32_t standby = 0;
int rport=5500; uint16_t rotation = 0;
uint16_t scaling = 100;
//reverse connection
char *rhost = NULL;
int rport = 5500;
void (*update_screen)(void)=NULL; void (*update_screen)(void)=NULL;
enum method_type {AUTO,FRAMEBUFFER,ADB,GRALLOC enum method_type {AUTO,FRAMEBUFFER,ADB,GRALLOC,FLINGER};
#ifndef ANDROID_FROYO
,GINGERBREAD};
#else
};
#endif
enum method_type method=AUTO; enum method_type method=AUTO;
#define PIXEL_TO_VIRTUALPIXEL_FB(i,j) ((j+scrinfo.yoffset)*scrinfo.xres_virtual+i+scrinfo.xoffset) #define PIXEL_TO_VIRTUALPIXEL_FB(i,j) ((j+scrinfo.yoffset)*scrinfo.xres_virtual+i+scrinfo.xoffset)
#define PIXEL_TO_VIRTUALPIXEL(i,j) ((j*displayInfo.width)+i) #define PIXEL_TO_VIRTUALPIXEL(i,j) ((j*screenformat.width)+i)
#define OUT 8 #define OUT 8
#include "update_screen.c" #include "updateScreen.c"
#undef OUT #undef OUT
#define OUT 16 #define OUT 16
#include "update_screen.c" #include "updateScreen.c"
#undef OUT #undef OUT
// #define OUT 24
// #include "update_screen.c"
// #undef OUT
#define OUT 32 #define OUT 32
#include "update_screen.c" #include "updateScreen.c"
#undef OUT #undef OUT
inline int getCurrentRotation() inline int getCurrentRotation()
@ -83,12 +82,12 @@ inline int getCurrentRotation()
inline int isIdle() inline int isIdle()
{ {
return idle; return idle;
} }
void setIdle(int i) void setIdle(int i)
{ {
idle=i; idle=i;
} }
ClientGoneHookPtr clientGone(rfbClientPtr cl) ClientGoneHookPtr clientGone(rfbClientPtr cl)
@ -103,7 +102,7 @@ rfbNewClientHookPtr clientHook(rfbClientPtr cl)
{ {
rfbScalingSetup(cl, vncscr->width*scaling/100.0, vncscr->height*scaling/100.0); rfbScalingSetup(cl, vncscr->width*scaling/100.0, vncscr->height*scaling/100.0);
L("Scaling to w=%d h=%d\n",(int)(vncscr->width*scaling/100.0), (int)(vncscr->height*scaling/100.0)); L("Scaling to w=%d h=%d\n",(int)(vncscr->width*scaling/100.0), (int)(vncscr->height*scaling/100.0));
// rfbSendNewScaleSize(cl); //rfbSendNewScaleSize(cl);
} }
cl->clientGoneHook=(ClientGoneHookPtr)clientGone; cl->clientGoneHook=(ClientGoneHookPtr)clientGone;
@ -116,7 +115,7 @@ rfbNewClientHookPtr clientHook(rfbClientPtr cl)
strcat(msg,"\n"); strcat(msg,"\n");
sendMsgToGui(msg); sendMsgToGui(msg);
free (msg); free (msg);
return RFB_CLIENT_ACCEPT; return RFB_CLIENT_ACCEPT;
} }
@ -140,374 +139,321 @@ void sendServerStarted(){
void sendServerStopped() void sendServerStopped()
{ {
sendMsgToGui("~SERVERSTOPPED|\n"); sendMsgToGui("~SERVERSTOPPED|\n");
} }
void initVncServer(int argc, char **argv) void initVncServer(int argc, char **argv)
{ {
vncbuf = calloc(displayInfo.width * displayInfo.height, displayInfo.bpp/CHAR_BIT);
cmpbuf = calloc(displayInfo.width * displayInfo.height, displayInfo.bpp/CHAR_BIT);
assert(vncbuf != NULL);
assert(cmpbuf != NULL);
if (rotation==0 || rotation==180) vncbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT);
vncscr = rfbGetScreen(&argc, argv, displayInfo.width , displayInfo.height, 0 /* not used */ , 3, displayInfo.bpp/CHAR_BIT); cmpbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT);
else
vncscr = rfbGetScreen(&argc, argv, displayInfo.height, displayInfo.width, 0 /* not used */ , 3, displayInfo.bpp/CHAR_BIT);
assert(vncscr != NULL);
vncscr->desktopName = "Android";
vncscr->frameBuffer =(char *)vncbuf;
assert(vncbuf != NULL);
vncscr->port = VNC_PORT; assert(cmpbuf != NULL);
vncscr->kbdAddEvent = keyEvent;
vncscr->ptrAddEvent = ptrEvent;
vncscr->newClientHook = (rfbNewClientHookPtr)clientHook;
vncscr->setXCutText = CutText; if (rotation==0 || rotation==180)
vncscr = rfbGetScreen(&argc, argv, screenformat.width , screenformat.height, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT);
if (strcmp(VNC_PASSWORD,"")!=0) else
{ vncscr = rfbGetScreen(&argc, argv, screenformat.height, screenformat.width, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT);
char **passwords = (char **)malloc(2 * sizeof(char **));
passwords[0] = VNC_PASSWORD;
passwords[1] = NULL;
vncscr->authPasswdData = passwords;
vncscr->passwordCheck = rfbCheckPasswordByList;
}
vncscr->httpDir="/data/data/org.onaips.vnc/files/"; assert(vncscr != NULL);
vncscr->sslcertfile="self.pem";
vncscr->desktopName = "Android";
vncscr->serverFormat.redShift=displayInfo.red_offset; vncscr->frameBuffer =(char *)vncbuf;
vncscr->serverFormat.greenShift=displayInfo.green_offset; vncscr->port = VNC_PORT;
vncscr->serverFormat.blueShift=displayInfo.blue_offset; vncscr->kbdAddEvent = keyEvent;
vncscr->ptrAddEvent = ptrEvent;
vncscr->serverFormat.redMax=((1<<displayInfo.red_length)-1); vncscr->newClientHook = (rfbNewClientHookPtr)clientHook;
vncscr->serverFormat.greenMax=((1<<displayInfo.green_length)-1); vncscr->setXCutText = CutText;
vncscr->serverFormat.blueMax=((1<<displayInfo.blue_length)-1);
if (strcmp(VNC_PASSWORD,"")!=0)
vncscr->serverFormat.bitsPerPixel=displayInfo.bpp; {
char **passwords = (char **)malloc(2 * sizeof(char **));
vncscr->alwaysShared = TRUE; passwords[0] = VNC_PASSWORD;
vncscr->handleEventsEagerly = TRUE; passwords[1] = NULL;
vncscr->deferUpdateTime = 5; vncscr->authPasswdData = passwords;
vncscr->passwordCheck = rfbCheckPasswordByList;
}
vncscr->httpDir="/data/data/org.onaips.vnc/files/";
vncscr->sslcertfile="self.pem";
vncscr->serverFormat.redShift = screenformat.redShift;
vncscr->serverFormat.greenShift = screenformat.greenShift;
vncscr->serverFormat.blueShift = screenformat.blueShift;
vncscr->serverFormat.redMax = (( 1 << screenformat.redMax) -1);
vncscr->serverFormat.greenMax = (( 1 << screenformat.greenMax) -1);
vncscr->serverFormat.blueMax = (( 1 << screenformat.blueMax) -1);
vncscr->serverFormat.bitsPerPixel = screenformat.bitsPerPixel;
vncscr->alwaysShared = TRUE;
vncscr->handleEventsEagerly = TRUE;
vncscr->deferUpdateTime = 5;
rfbInitServer(vncscr);
rfbInitServer(vncscr);
//assign update_screen depending on bpp //assign update_screen depending on bpp
if (vncscr->serverFormat.bitsPerPixel == 32) if (vncscr->serverFormat.bitsPerPixel == 32)
update_screen=&CONCAT2E(update_screen_,32); update_screen=&CONCAT2E(update_screen_,32);
// else if (vncscr->serverFormat.bitsPerPixel == 24)
// update_screen=&CONCAT2E(update_screen_,24);
else if (vncscr->serverFormat.bitsPerPixel == 16) else if (vncscr->serverFormat.bitsPerPixel == 16)
update_screen=&CONCAT2E(update_screen_,16); update_screen=&CONCAT2E(update_screen_,16);
else if (vncscr->serverFormat.bitsPerPixel == 8) else if (vncscr->serverFormat.bitsPerPixel == 8)
update_screen=&CONCAT2E(update_screen_,8); update_screen=&CONCAT2E(update_screen_,8);
else { else {
L("Unsupported pixel depth: %d\n", L("Unsupported pixel depth: %d\n",
vncscr->serverFormat.bitsPerPixel); vncscr->serverFormat.bitsPerPixel);
sendMsgToGui("~SHOW|Unsupported pixel depth, please send bug report.\n"); sendMsgToGui("~SHOW|Unsupported pixel depth, please send bug report.\n");
return; return;
} }
/* Mark as dirty since we haven't sent any updates at all yet. */
/* Mark as dirty since we haven't sent any updates at all yet. */ rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height);
}
rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height);
}
void rotate(int value) void rotate(int value)
{ {
L("rotate()");
if (value==-1 ||
((value==90 || value==270) && (rotation==0 || rotation==180)) ||
((value==0 || value==180) && (rotation==90 || rotation==270)))
{
int h=vncscr->height;
int w=vncscr->width;
vncscr->width = h;
vncscr->paddedWidthInBytes = h * displayInfo.bpp / CHAR_BIT;
vncscr->height = w;
{ L("rotate()");
rfbClientIteratorPtr iterator;
rfbClientPtr cl; if (value == -1 ||
iterator = rfbGetClientIterator(vncscr); ((value == 90 || value == 270) && (rotation == 0 || rotation == 180)) ||
while ((cl = rfbClientIteratorNext(iterator)) != NULL) ((value == 0 || value == 180) && (rotation == 90 || rotation == 270))) {
cl->newFBSizePending = 1; int h = vncscr->height;
} int w = vncscr->width;
vncscr->width = h;
vncscr->paddedWidthInBytes = h * screenformat.bitsPerPixel / CHAR_BIT;
vncscr->height = w;
rfbClientIteratorPtr iterator;
rfbClientPtr cl;
iterator = rfbGetClientIterator(vncscr);
while ((cl = rfbClientIteratorNext(iterator)) != NULL)
cl->newFBSizePending = 1;
}
if (value == -1) {
rotation += 90;
rotation %= 360;
} else {
rotation = value;
} }
if (value==-1)
{
rotation+=90;
rotation=rotation%360;
}
else
{
rotation=value;
}
rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height); rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height);
} }
void close_app() void close_app()
{ {
L("Cleaning up...\n"); L("Cleaning up...\n");
cleanupFramebuffer(); if (method == FRAMEBUFFER)
cleanupInput(); closeFB();
sendServerStopped(); else if (method == ADB)
unbindIPCserver(); closeADB();
exit(0); /* normal exit status */ else if (method == GRALLOC)
closeGralloc();
else if (method == FLINGER)
closeFlinger();
cleanupInput();
sendServerStopped();
unbindIPCserver();
exit(0); /* normal exit status */
} }
void extractReverseHostPort(char *str) void extractReverseHostPort(char *str)
{ {
int len=strlen(str); int len = strlen(str);
char *p; char *p;
/* copy in to host */ /* copy in to host */
rhost = (char *) malloc(len+1); rhost = (char *) malloc(len+1);
if (! rhost) { if (! rhost) {
L("reverse_connect: could not malloc string %d\n", len); L("reverse_connect: could not malloc string %d\n", len);
exit(-1); exit(-1);
} }
strncpy(rhost, str, len); strncpy(rhost, str, len);
rhost[len] = '\0'; rhost[len] = '\0';
/* extract port, if any */ /* extract port, if any */
if ((p = strrchr(rhost, ':')) != NULL) { if ((p = strrchr(rhost, ':')) != NULL) {
rport = atoi(p+1); rport = atoi(p+1);
if (rport < 0) { if (rport < 0) {
rport = -rport; rport = -rport;
} else if (rport < 20) { } else if (rport < 20) {
rport = 5500 + rport; rport = 5500 + rport;
} }
*p = '\0'; *p = '\0';
} }
}
void initGrabberMethod()
{
if (method == AUTO) {
L("No grabber method selected, auto-detecting...\n");
if (initFlinger() != -1)
method = FLINGER;
else if (initGralloc()!=-1)
method = GRALLOC;
else if (initFB() != -1) {
method = FRAMEBUFFER;
} else if (initADB() != -1) {
method = ADB;
readBufferADB();
}
} else if (method == FRAMEBUFFER)
initFB();
else if (method == ADB) {
initADB();
readBufferADB();
} else if (method == GRALLOC)
initGralloc();
else if (method == FLINGER)
initFlinger();
} }
void printUsage(char **argv) void printUsage(char **argv)
{ {
L("\nandroidvncserver [parameters]\n" L("\nandroidvncserver [parameters]\n"
"-f <device>\t- Framebuffer device (only with -m fb, default is /dev/graphics/fb0)\n" "-f <device>\t- Framebuffer device (only with -m fb, default is /dev/graphics/fb0)\n"
"-h\t\t- Print this help\n" "-h\t\t- Print this help\n"
"-m <method>\t- Display grabber method\n\tfb: framebuffer\n\tgb: gingerbread+ devices\n\tadb: slower, but should be compatible with all devices\n" "-m <method>\t- Display grabber method\n\tfb: framebuffer\n\tgb: gingerbread+ devices\n\tadb: slower, but should be compatible with all devices\n"
"-p <password>\t- Password to access server\n" "-p <password>\t- Password to access server\n"
"-r <rotation>\t- Screen rotation (degrees) (0,90,180,270)\n" "-r <rotation>\t- Screen rotation (degrees) (0,90,180,270)\n"
"-R <host:port>\t- Host for reverse connection\n" "-R <host:port>\t- Host for reverse connection\n"
"-s <scale>\t- Scale percentage (20,30,50,100,150)\n\n" ); "-s <scale>\t- Scale percentage (20,30,50,100,150)\n\n" );
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
signal(SIGINT, close_app);//pipe signals //pipe signals
signal(SIGKILL, close_app); signal(SIGINT, close_app);
signal(SIGILL, close_app); signal(SIGKILL, close_app);
signal(SIGILL, close_app);
if(argc > 1)
{
int i=1;
int r;
while(i < argc)
{
if(*argv[i] == '-')
{
switch(*(argv[i] + 1))
{
case 'h':
printUsage(argv);
exit(0);
break;
case 'p':
i++;
strcpy(VNC_PASSWORD,argv[i]);
break;
case 'f':
i++;
setFramebufferDevice(argv[i]);
break;
case 'P':
i++;
VNC_PORT=atoi(argv[i]);
break;
case 'r':
i++;
r=atoi(argv[i]);
if (r==0 || r==90 || r==180 || r==270)
rotation=r;
L("rotating to %d degrees\n",rotation);
break;
case 's':
i++;
r=atoi(argv[i]);
if (r>=1 && r <= 150)
scaling=r;
else
scaling=100;
L("scaling to %d percent\n",scaling);
break;
case 'm':
i++;
if (strcmp(argv[i],"adb")==0)
{
method=ADB;
L("ADB display grabber selected\n");
}
else if (strcmp(argv[i],"fb")==0)
{
method=FRAMEBUFFER;
L("Framebuffer display grabber selected\n");
}
else if (strcmp(argv[i],"gralloc")==0)
{
method=GRALLOC;
L("Gralloc display grabber selected\n");
}
#ifndef ANDROID_FROYO
else if (strcmp(argv[i],"gingerbread")==0)
{
method=GINGERBREAD;
L("Gingerbread display grabber selected\n");
}
#endif
else
{
L("Grab method \"%s\" not found, reverting to default.\n",argv[i]);
}
break;
case 'R':
i++;
extractReverseHostPort(argv[i]);
break;
}
}
i++;
}
}
L("Initializing grabber method...\n");
if (method==AUTO)
{
L("No grabber method selected, auto-detecting...");
do
{
#ifndef ANDROID_FROYO
if (initGingerbreadMethod()!=-1)
method=GINGERBREAD;
else
#endif
if (init_gralloc()!=-1)
method=GRALLOC;
else if (initFramebuffer()!=-1) if(argc > 1) {
method=FRAMEBUFFER; int i=1;
else if (initADB()!=-1) int r;
{ while(i < argc) {
method=ADB; if(*argv[i] == '-') {
updateADBFrame(); switch(*(argv[i] + 1)) {
} case 'h':
break; printUsage(argv);
} exit(0);
while (0); break;
} case 'p':
else if (method==FRAMEBUFFER) i++;
initFramebuffer(); strcpy(VNC_PASSWORD,argv[i]);
else if (method==ADB) break;
{ case 'f':
initADB(); i++;
updateADBFrame(); FB_setDevice(argv[i]);
} break;
else if (method==GRALLOC) case 'P':
init_gralloc(); i++;
#ifndef ANDROID_FROYO VNC_PORT=atoi(argv[i]);
else if (method==GINGERBREAD) break;
initGingerbreadMethod(); case 'r':
#endif i++;
r = atoi(argv[i]);
if (r==0 || r==90 || r==180 || r==270)
rotation = r;
L("rotating to %d degrees\n",rotation);
break;
case 's':
i++;
r=atoi(argv[i]);
if (r >= 1 && r <= 150)
scaling = r;
else
scaling = 100;
L("scaling to %d%%\n",scaling);
break;
case 'R':
i++;
extractReverseHostPort(argv[i]);
break;
case 'm':
i++;
if (!strcmp(argv[i],"adb")){
method = ADB;
L("ADB display grabber selected\n");
} else if (!strcmp(argv[i],"fb")) {
method = FRAMEBUFFER;
L("Framebuffer display grabber selected\n");
} else if (!strcmp(argv[i],"gralloc")) {
method = GRALLOC;
L("Gralloc display grabber selected\n");
} else if (!strcmp(argv[i],"flinger")) {
method = FLINGER;
L("Flinger display grabber selected\n");
} else {
L("Grab method \"%s\" not found, sticking with auto-detection.\n",argv[i]);
}
break;
}
}
i++;
}
}
L("Initializing grabber method...\n");
initGrabberMethod();
L("Initializing virtual keyboard and touch device...\n"); L("Initializing virtual keyboard and touch device...\n");
initInput(); initInput();
L("Initializing VNC server:\n"); L("Initializing VNC server:\n");
L(" width: %d\n", (int)displayInfo.width); L(" width: %d\n", (int)screenformat.width);
L(" height: %d\n", (int)displayInfo.height); L(" height: %d\n", (int)screenformat.height);
L(" bpp: %d\n", (int)displayInfo.bpp); L(" bpp: %d\n", (int)screenformat.bitsPerPixel);
L(" port: %d\n", (int)VNC_PORT); L(" port: %d\n", (int)VNC_PORT);
L("Colourmap_rgba=%d:%d:%d:%d lenght=%d:%d:%d:%d\n",displayInfo.red_offset,displayInfo.green_offset,displayInfo.blue_offset,displayInfo.alpha_offset, L("Colourmap_rgba=%d:%d:%d:%d lenght=%d:%d:%d:%d\n", screenformat.redShift, screenformat.greenShift, screenformat.blueShift,screenformat.alphaShift,
displayInfo.red_length,displayInfo.green_length,displayInfo.blue_length,displayInfo.alpha_length); screenformat.redMax,screenformat.greenMax,screenformat.blueMax,screenformat.alphaMax);
initVncServer(argc, argv); initVncServer(argc, argv);
bindIPCserver(); bindIPCserver();
sendServerStarted(); sendServerStarted();
if (rhost) {
rfbClientPtr cl;
cl = rfbReverseConnection(vncscr, rhost, rport);
if (cl == NULL) {
char *str=malloc(255*sizeof(char));
sprintf(str,"~SHOW|Couldn't connect to remote host:\n%s\n",rhost);
if (rhost) L("Couldn't connect to remote host: %s\n",rhost);
{ sendMsgToGui(str);
rfbClientPtr cl; free(str);
cl = rfbReverseConnection(vncscr, rhost, rport); } else {
if (cl == NULL) cl->onHold = FALSE;
{ rfbStartOnHoldClient(cl);
char *str=malloc(255*sizeof(char)); }
sprintf(str,"~SHOW|Couldn't connect to remote host:\n%s\n",rhost);
L("Couldn't connect to remote host: %s\n",rhost);
sendMsgToGui(str);
free(str);
}
else
{
cl->onHold = FALSE;
rfbStartOnHoldClient(cl);
}
} }
rfbRunEventLoop(vncscr,-1,TRUE); rfbRunEventLoop(vncscr,-1,TRUE);
while (1) while (1) {
{ usleep(300000*(standby/2.0));
usleep(300000*(standby/2.0));
if (idle)
standby++;
else
standby=2;
if (vncscr->clientHead == NULL) if (idle)
continue; standby++;
else
standby=2;
update_screen();
}
if (vncscr->clientHead == NULL)
continue;
update_screen();
}
close_app(); close_app();
} }

View File

@ -17,7 +17,10 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
//this file implements a simple IPC connection with the Java GUI
#include "gui.h" #include "gui.h"
#include "common.h"
#define SOCKET_ERROR -1 #define SOCKET_ERROR -1
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
@ -25,75 +28,67 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
int hServerSocket; /* handle to socket */ int hServerSocket; /* handle to socket */
struct sockaddr_in Address; /* Internet socket address stuct */ struct sockaddr_in Address; /* Internet socket address stuct */
int nAddressSize=sizeof(struct sockaddr_in); int nAddressSize = sizeof(struct sockaddr_in);
char pBuffer[BUFFER_SIZE]; char pBuffer[BUFFER_SIZE];
static int nHostPort; static int nHostPort;
int sendMsgToGui(char *buffer) int sendMsgToGui(char *buffer)
{ {
int sock, n; int sock, n;
unsigned int length; unsigned int length;
struct sockaddr_in server; struct sockaddr_in server;
sock= socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) perror("socket");
bzero(&server,sizeof(server)); sock = socket(AF_INET, SOCK_DGRAM, 0);
server.sin_family = AF_INET; if (sock < 0) perror("socket");
server.sin_addr.s_addr=inet_addr("127.0.0.1");
server.sin_port = htons(13131);
length=sizeof(struct sockaddr_in);
n=sendto(sock,buffer, bzero(&server,sizeof(server));
strlen(buffer),0,(struct sockaddr *)&server,length); server.sin_family = AF_INET;
if (n < 0) perror("Sendto"); server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_port = htons(DEFAULT_IPC_RECV_PORT);
// L("Sent %s\n",buffer); length = sizeof(struct sockaddr_in);
// n = recvfrom(sock,buffer,256,0,(struct sockaddr *)&from, &length);
// if (n < 0) error("recvfrom"); n = sendto(sock,buffer,strlen(buffer),0,(struct sockaddr *)&server,length);
// write(1,"Got an ack: ",12); if (n < 0) perror("Sendto");
// write(1,buffer,n);
close(sock);
close(sock); return 0;
return 0;
} }
int bindIPCserver() int bindIPCserver()
{ {
nHostPort=13132; nHostPort=DEFAULT_IPC_SEND_PORT;
L("Starting IPC connection..."); L("Starting IPC connection...");
/* make a socket */ /* make a socket */
hServerSocket=socket(AF_INET,SOCK_DGRAM,0); hServerSocket=socket(AF_INET,SOCK_DGRAM,0);
if(hServerSocket == SOCKET_ERROR) if(hServerSocket == SOCKET_ERROR) {
{ L("Error creating socket\n");
L("\nCould not make a socket\n"); return 0;
return 0; }
}
/* fill address struct */ /* fill address struct */
Address.sin_addr.s_addr=INADDR_ANY; Address.sin_addr.s_addr=INADDR_ANY;
Address.sin_port=htons(nHostPort); Address.sin_port=htons(nHostPort);
Address.sin_family=AF_INET; Address.sin_family=AF_INET;
/* bind to a port */ /* bind to a port */
if(bind(hServerSocket,(struct sockaddr*)&Address,sizeof(Address)) == SOCKET_ERROR) if(bind(hServerSocket,(struct sockaddr*)&Address,sizeof(Address)) == SOCKET_ERROR)
{ {
L("\nCould not connect to IPC gui, another daemon already running?\n"); L("\nCould not connect to IPC gui, another daemon already running?\n");
sendMsgToGui("~SHOW|Could not connect to IPC gui, another daemon already running?\n"); sendMsgToGui("~SHOW|Could not connect to IPC gui, another daemon already running?\n");
exit(-1); exit(-1);
} }
L("binded to port %d\n",nHostPort); L("binded to port %d\n",nHostPort);
pthread_t thread;
pthread_create( &thread,NULL,handle_connections,NULL);
pthread_t thread;
pthread_create( &thread,NULL,handle_connections,NULL);
return 1; return 1;
} }
@ -101,31 +96,31 @@ int bindIPCserver()
void *handle_connections() void *handle_connections()
{ {
L("\nWaiting for a connection\n"); L("\nWaiting for a connection\n");
struct sockaddr_in from; struct sockaddr_in from;
int fromlen = sizeof(struct sockaddr_in); int fromlen = sizeof(struct sockaddr_in);
int n; int n;
while (1) { while (1) {
n = recvfrom(hServerSocket,pBuffer,BUFFER_SIZE,0,(struct sockaddr *)&from,&fromlen); n = recvfrom(hServerSocket,pBuffer,BUFFER_SIZE,0,(struct sockaddr *)&from,&fromlen);
if (n < 0) perror("recvfrom"); if (n < 0) perror("recvfrom");
L("Recebido: %s\n",pBuffer); L("Recebido: %s\n",pBuffer);
if (strstr(pBuffer,"~PING|")!=NULL) if (strstr(pBuffer,"~PING|")!=NULL)
{ {
char *resp="~PONG|"; char *resp="~PONG|";
n = sendto(hServerSocket,resp,strlen(resp), n = sendto(hServerSocket,resp,strlen(resp),
0,(struct sockaddr *)&from,fromlen); 0,(struct sockaddr *)&from,fromlen);
if (n < 0) perror("sendto"); if (n < 0) perror("sendto");
} }
else if (strstr(pBuffer,"~KILL|")!=NULL) else if (strstr(pBuffer,"~KILL|")!=NULL)
close_app(); close_app();
} }
} }
void unbindIPCserver() void unbindIPCserver()
{ {
close(hServerSocket); close(hServerSocket);
} }

View File

@ -22,7 +22,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "common.h" #include "common.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#define DEFAULT_IPC_RECV_PORT 13131
#define DEFAULT_IPC_SEND_PORT 13132
#define SOCK_PATH "org.onaips.vnc.gui" //TODO put IPC working on unix sockets
int sendMsgToGui(char *msg); int sendMsgToGui(char *msg);

View File

@ -22,10 +22,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "common.h" #include "common.h"
#include "gui.h" #include "gui.h"
#include "rfb/rfb.h"
#include "suinput.h"
#define BUS_VIRTUAL 0x06 #define BUS_VIRTUAL 0x06
void initInput(); void initInput();
int keysym2scancode(rfbBool down, rfbKeySym c, rfbClientPtr cl, int *sh, int *alt); int keysym2scancode(rfbBool down, rfbKeySym c, rfbClientPtr cl, int *sh, int *alt);
void transformTouchCoordinates(int *x, int *y,int,int); void transformTouchCoordinates(int *x, int *y,int,int);

View File

@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#include "common.h" #include "common.h"
#define A_CNXN 0x4e584e43 #define A_CNXN 0x4e584e43
@ -44,6 +43,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#define DDMS_RAWIMAGE_VERSION 1 #define DDMS_RAWIMAGE_VERSION 1
#define DDMS_RAWIMAGE_VERSION 1
struct _message {
unsigned int command; /* command identifier constant */
unsigned int arg0; /* first argument */
unsigned int arg1; /* second argument */
unsigned int data_length; /* length of payload (0 is allowed) */
unsigned int data_crc32; /* crc32 of data payload */
unsigned int magic; /* command ^ 0xffffffff */
} __attribute__((packed));
char connect_string[] = { char connect_string[] = {
0x43, 0x4e, 0x58, 0x4e, 0x00, 0x00, 0x00, 0x01, 0x43, 0x4e, 0x58, 0x4e, 0x00, 0x00, 0x00, 0x01,
0x00, 0x10, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
@ -63,6 +73,8 @@ struct fbinfo *fb_info;
struct _message *message,*okay_message; struct _message *message,*okay_message;
int sockfd; int sockfd;
unsigned int *adbbuf = NULL;
ssize_t write_socket(int fd, const void *buf, size_t count) ssize_t write_socket(int fd, const void *buf, size_t count)
{ {
int n = write(fd,buf,count); int n = write(fd,buf,count);
@ -88,7 +100,7 @@ void read_socket(int fd, void *buf, size_t count)
} }
} }
void send_connect_string() void send_connect_string(void)
{ {
write_socket(sockfd,connect_string,sizeof(connect_string)); write_socket(sockfd,connect_string,sizeof(connect_string));
read_socket(sockfd,message,sizeof(struct _message)); read_socket(sockfd,message,sizeof(struct _message));
@ -100,9 +112,9 @@ void send_connect_string()
read_socket(sockfd,message,message->data_length); read_socket(sockfd,message,message->data_length);
} }
void send_framebuffer_string(); void send_framebuffer_string(void);
int initADB() int initADB(void)
{ {
L("--Initializing adb access method--\n"); L("--Initializing adb access method--\n");
pid_t pid; pid_t pid;
@ -121,7 +133,7 @@ int initADB()
system("killall adbd"); system("killall adbd");
system("setprop service.adb.tcp.port -1"); system("setprop service.adb.tcp.port -1");
system("/sbin/adbd"); system("/sbin/adbd");
return; exit(0);
break; break;
} }
@ -168,7 +180,7 @@ return 0;
void send_framebuffer_string()//returns the fb struct size from adb void send_framebuffer_string(void)//returns the fb struct size from adb
{ {
int n; int n;
char *buffer=NULL; char *buffer=NULL;
@ -203,6 +215,8 @@ void send_framebuffer_string()//returns the fb struct size from adb
buffer=(char*)malloc(sizeof(char)*message->data_length); buffer=(char*)malloc(sizeof(char)*message->data_length);
struct fbinfo displayInfo;
read_socket(sockfd,&displayInfo,sizeof(struct fbinfo)); read_socket(sockfd,&displayInfo,sizeof(struct fbinfo));
// L("sizeof(struct fbinfo)=%d\n",sizeof(struct fbinfo)); // L("sizeof(struct fbinfo)=%d\n",sizeof(struct fbinfo));
@ -215,9 +229,21 @@ void send_framebuffer_string()//returns the fb struct size from adb
if (adbbuf==NULL) if (adbbuf==NULL)
adbbuf=(unsigned int*)malloc(displayInfo.size); adbbuf=(unsigned int*)malloc(displayInfo.size);
screenformat.bitsPerPixel = displayInfo.bpp;
screenformat.width = displayInfo.width;
screenformat.height = displayInfo.height;
screenformat.redMax = displayInfo.red_length;
screenformat.greenMax = displayInfo.green_length;
screenformat.blueMax = displayInfo.blue_length;
screenformat.alphaMax = displayInfo.alpha_length;
screenformat.redShift = displayInfo.red_offset;
screenformat.greenShift = displayInfo.green_offset;
screenformat.blueShift = displayInfo.blue_offset;
screenformat.alphaShift = displayInfo.alpha_offset;
screenformat.size = displayInfo.size;
} }
void updateADBFrame() unsigned int *readBufferADB(void)
{ {
int n=0; int n=0;
int count=0; int count=0;
@ -258,6 +284,12 @@ void updateADBFrame()
// if (resp!=A_OKAY) // if (resp!=A_OKAY)
// error("bad OKAY response"); // error("bad OKAY response");
return adbbuf;
}
void closeADB()
{
close(sockfd);
} }
// test start point // test start point

View File

@ -20,47 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef ADB_CONNECT_METHOD #ifndef ADB_CONNECT_METHOD
#define ADB_CONNECT_METHOD #define ADB_CONNECT_METHOD
#include <stdio.h> int initADB(void);
#include <stdlib.h> unsigned int *readBufferADB(void);
#include <unistd.h> void closeADB(void);
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
// #include <cutils/properties.h>
#include "common.h"
#define A_CNXN 0x4e584e43
#define A_OKAY 0x59414b4f
#define A_CLSE 0x45534c43
#define A_WRTE 0x45545257
#define DDMS_RAWIMAGE_VERSION 1
struct _message {
unsigned int command; /* command identifier constant */
unsigned int arg0; /* first argument */
unsigned int arg1; /* second argument */
unsigned int data_length; /* length of payload (0 is allowed) */
unsigned int data_crc32; /* crc32 of data payload */
unsigned int magic; /* command ^ 0xffffffff */
} __attribute__((packed));
// void error(const char *msg);
// ssize_t write_socket(int fd, const void *buf, size_t count);
// ssize_t read_socket(int fd, void *buf, size_t count);
// void send_connect_string();
int initADB();
void updateADBFrame();
unsigned int *adbbuf;
#endif #endif

View File

@ -0,0 +1,107 @@
/*
droid vnc server - Android VNC server
Copyright (C) 2011 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <dlfcn.h>
#include "flinger.h"
#include "common.h"
void *flinger_lib = NULL;
close_fn_type close_flinger = NULL;
readfb_fn_type readfb_flinger = NULL;
getscreenformat_fn_type getscreenformat_flinger = NULL;
int initFlinger(void)
{
L("--Loading flinger native lib--\n");
flinger_lib = dlopen("/data/libdvnc_flinger_sdk14.so", RTLD_NOW);
if(flinger_lib == NULL) {
L("Couldnt load library! Error string: %s\n",dlerror());
return -1;
}
init_fn_type init_flinger = dlsym(flinger_lib,"init_flinger");
if(init_flinger == NULL) {
L("Couldn't load init_flinger! Error string: %s\n",dlerror());
return -1;
}
close_flinger = dlsym(flinger_lib,"close_flinger");
if(close_flinger == NULL) {
L("Couldn't load close_flinger! Error string: %s\n",dlerror());
return -1;
}
readfb_flinger = dlsym(flinger_lib,"readfb_flinger");
if(readfb_flinger == NULL) {
L("Couldn't load readfb_flinger! Error string: %s\n",dlerror());
return -1;
}
getscreenformat_flinger = dlsym(flinger_lib,"getscreenformat_flinger");
if(getscreenformat_flinger == NULL) {
L("Couldn't load get_screenformat! Error string: %s\n",dlerror());
return -1;
}
int ret = init_flinger();
if (ret == -1) {
L("flinger method not supported by this device!\n");
return -1;
}
screenformat = getScreenFormatFlinger();
if ( screenformat.width <= 0 ) {
L("Error: I have received a bad screen size from flinger.\n");
return -1;
}
if ( readBufferFlinger() == NULL) {
L("Error: Could not read surfaceflinger buffer!\n");
return -1;
}
return 0;
}
screenFormat getScreenFormatFlinger(void)
{
screenFormat f;
if (getscreenformat_flinger)
f = getscreenformat_flinger();
return f;
}
void closeFlinger(void)
{
if (close_flinger)
close_flinger();
if (flinger_lib)
dlclose(flinger_lib);
}
unsigned char *readBufferFlinger(void)
{
if (readfb_flinger)
return readfb_flinger();
return NULL;
}

View File

@ -0,0 +1,30 @@
/*
droid vnc server - Android VNC server
Copyright (C) 2009 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef FLINGER_H
#define FLINGER_H
#include "screenFormat.h"
int initFlinger(void);
void closeFlinger(void);
unsigned char *readBufferFlinger(void);
screenFormat getScreenFormatFlinger(void);
#endif

View File

@ -21,21 +21,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "framebuffer.h" #include "framebuffer.h"
#include "common.h"
#include "gui.h" #include "gui.h"
int fbfd = -1; int fbfd = -1;
unsigned int *fbmmap;
char framebuffer_device[256] = "/dev/graphics/fb0"; char framebuffer_device[256] = "/dev/graphics/fb0";
struct fb_var_screeninfo scrinfo;
struct fb_fix_screeninfo fscrinfo;
void setFramebufferDevice(char *s) void FB_setDevice(char *s)
{ {
strcpy(framebuffer_device,s); strcpy(framebuffer_device,s);
} }
int initFramebuffer(void) void update_fb_info(void)
{
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &scrinfo) != 0) {
L("ioctl error\n");
sendMsgToGui("~SHOW|Framebuffer ioctl error, please try out other display grab method\n");
exit(EXIT_FAILURE);
}
}
int initFB(void)
{ {
L("--Initializing framebuffer access method--\n"); L("--Initializing framebuffer access method--\n");
@ -67,11 +77,10 @@ int initFramebuffer(void)
size = scrinfo.yres * 2; size = scrinfo.yres * 2;
} }
if ((scrinfo.bits_per_pixel == 24)) {// && (fscrinfo.line_length/scrinfo.xres_virtual==CHAR_BIT*4)) if ((scrinfo.bits_per_pixel == 24)) {
scrinfo.bits_per_pixel = 32; scrinfo.bits_per_pixel = 32;
L("24-bit XRGB display detected\n");
L("24-bit XRGB display detected\n"); }
}
size_t fbSize = roundUpToPageSize(fscrinfo.line_length * size); size_t fbSize = roundUpToPageSize(fscrinfo.line_length * size);
@ -83,37 +92,38 @@ int initFramebuffer(void)
return -1; return -1;
} }
displayInfo.bpp = scrinfo.bits_per_pixel; screenformat.bitsPerPixel = scrinfo.bits_per_pixel;
displayInfo.size = scrinfo.xres * scrinfo.yres * scrinfo.bits_per_pixel / CHAR_BIT; screenformat.size = scrinfo.xres * scrinfo.yres * scrinfo.bits_per_pixel / CHAR_BIT;
displayInfo.width = scrinfo.xres; screenformat.width = scrinfo.xres;
displayInfo.height = scrinfo.yres; screenformat.height = scrinfo.yres;
displayInfo.red_offset = scrinfo.red.offset; screenformat.redShift = scrinfo.red.offset;
displayInfo.red_length = scrinfo.red.length; screenformat.redMax = scrinfo.red.length;
displayInfo.green_offset = scrinfo.green.offset; screenformat.greenShift = scrinfo.green.offset;
displayInfo.green_length = scrinfo.green.length; screenformat.greenMax = scrinfo.green.length;
displayInfo.blue_offset = scrinfo.blue.offset; screenformat.blueShift = scrinfo.blue.offset;
displayInfo.blue_length = scrinfo.blue.length; screenformat.blueMax = scrinfo.blue.length;
displayInfo.alpha_offset = scrinfo.transp.offset; screenformat.alphaShift = scrinfo.transp.offset;
displayInfo.alpha_length = scrinfo.transp.length; screenformat.alphaMax = scrinfo.transp.length;
return 1; return 1;
} }
void cleanupFramebuffer(void) void closeFB(void)
{ {
if(fbfd != -1) if(fbfd != -1)
close(fbfd); close(fbfd);
} }
void update_fb_info() struct fb_var_screeninfo FB_getscrinfo(void)
{ {
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &scrinfo) != 0) { return scrinfo;
L("ioctl error\n"); }
sendMsgToGui("~SHOW|Framebuffer ioctl error, please try out other display grab method\n");
exit(EXIT_FAILURE);
}
}
unsigned int *readBufferFB(void)
{
update_fb_info();
return fbmmap;
}
inline int roundUpToPageSize(int x) { inline int roundUpToPageSize(int x) {
return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);

View File

@ -22,15 +22,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "common.h" #include "common.h"
unsigned int *fbmmap; int initFB(void);
void closeFB(void);
unsigned int *readBufferFB(void);
void FB_setDevice(char *);
struct fb_var_screeninfo FB_getscrinfo(void);
struct fb_var_screeninfo scrinfo; #endif
struct fb_fix_screeninfo fscrinfo;
int initFramebuffer(void);
void cleanupFramebuffer(void);
void update_fb_info();
int roundUpToPageSize(int x);
void setFramebufferDevice(char *);
#endif

View File

@ -0,0 +1,103 @@
/*
droid vnc server - Android VNC server
Copyright (C) 2011 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <dlfcn.h>
#include "gralloc.h"
#include "common.h"
void *gralloc_lib = NULL;
close_fn_type close_gralloc = NULL;
readfb_fn_type readfb_gralloc = NULL;
getscreenformat_fn_type getscreenformat_gralloc = NULL;
int initGralloc(void)
{
L("--Loading gralloc native lib--\n");
gralloc_lib = dlopen("/data/libdvnc_gralloc_sdk14.so", RTLD_NOW);
if(gralloc_lib == NULL) {
L("Couldnt load library! Error string: %s\n",dlerror());
return -1;
}
init_fn_type init_gralloc = dlsym(gralloc_lib,"init_gralloc");
if(init_gralloc == NULL) {
L("Couldn't load init_gralloc! Error string: %s\n",dlerror());
return -1;
}
close_gralloc = dlsym(gralloc_lib,"close_gralloc");
if(close_gralloc == NULL) {
L("Couldn't load close_gralloc! Error string: %s\n",dlerror());
return -1;
}
readfb_gralloc = dlsym(gralloc_lib,"readfb_gralloc");
if(readfb_gralloc == NULL) {
L("Couldn't load readfb_gralloc! Error string: %s\n",dlerror());
return -1;
}
getscreenformat_gralloc = dlsym(gralloc_lib,"getscreenformat_gralloc");
if(getscreenformat_gralloc == NULL) {
L("Couldn't load get_screenformat! Error string: %s\n",dlerror());
return -1;
}
int ret = init_gralloc();
if (ret == -1) {
L("Gralloc method not supported by this device!\n");
return -1;
}
screenformat = getScreenFormatGralloc();
if ( screenformat.width <= 0 ) {
L("Error: I have received a bad screen size from gralloc.\n");
return -1;
}
return 0;
}
screenFormat getScreenFormatGralloc(void)
{
screenFormat f;
if (getscreenformat_gralloc)
f = getscreenformat_gralloc();
return f;
}
void closeGralloc(void)
{
if (close_gralloc)
close_gralloc();
if (gralloc_lib)
dlclose(gralloc_lib);
}
unsigned char *readBufferGralloc(void)
{
if (readfb_gralloc)
return readfb_gralloc();
return NULL;
}

View File

@ -0,0 +1,30 @@
/*
droid vnc server - Android VNC server
Copyright (C) 2009 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _GRALLOC_H
#define _GRALLOC_H
#include "screenFormat.h"
int initGralloc(void);
void closeGralloc(void);
unsigned char *readBufferGralloc(void);
screenFormat getScreenFormatGralloc(void);
#endif

183
jni/vnc/updateScreen.c Executable file
View File

@ -0,0 +1,183 @@
/*
droid VNC server - a vnc server for android
Copyright (C) 2011 Jose Pereira <onaips@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define OUT_T CONCAT3E(uint,OUT,_t)
#define FUNCTION CONCAT2E(update_screen_,OUT)
void FUNCTION(void)
{
int i,j;
int offset=0,pixelToVirtual;
OUT_T* a;
OUT_T* b=0;
struct fb_var_screeninfo scrinfo; //we'll need this to detect double FB on framebuffer
if (method==FRAMEBUFFER) {
scrinfo = FB_getscrinfo();
b = (OUT_T*) readBufferFB();
}
else if (method==ADB)
b = (OUT_T*) readBufferADB();
else if (method==GRALLOC)
b = (OUT_T*) readBufferGralloc();
else if (method==FLINGER)
b = (OUT_T*) readBufferFlinger();
a = (OUT_T*)cmpbuf;
int max_x=-1,max_y=-1, min_x=99999, min_y=99999;
int h;
idle=1;
if (rotation==0) {
for (j = 0; j < vncscr->height; j++) {
for (i = 0; i < vncscr->width; i++) {
offset = j * vncscr->width;
if (method==FRAMEBUFFER)
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL_FB(i,j);
else
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL(i,j);
if (a[i + offset]!=b[pixelToVirtual]) {
a[i + offset]=b[pixelToVirtual];
if (i>max_x)
max_x=i;
if (i<min_x)
min_x=i;
if (j>max_y)
max_y=j;
if (j<min_y)
min_y=j;
idle=0;
}
}
}
}
else if (rotation==90) {
for (j = 0; j < vncscr->width; j++) {
for (i = 0; i < vncscr->height; i++) {
offset = i * vncscr->width;
if (method==FRAMEBUFFER)
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL_FB(i,j);
else
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL(i,j);
if (a[(vncscr->width - 1 - j + offset)] != b[pixelToVirtual])
{
a[(vncscr->width - 1 - j + offset)] = b[pixelToVirtual];
if (i>max_y)
max_y=i;
if (i<min_y)
min_y=i;
h=vncscr->width-j;
if (h < min_x)
min_x=vncscr->width-j;
if (h > max_x)
max_x=vncscr->width-j;
idle=0;
}
}
}
}
else if (rotation==180) {
for (j = 0; j < vncscr->height; j++) {
for (i = 0; i < vncscr->width; i++) {
offset = (vncscr->height - 1 - j) * vncscr->width;
if (method==FRAMEBUFFER)
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL_FB(i,j);
else
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL(i,j);
if (a[((vncscr->width - 1 - i) + offset )]!=b[pixelToVirtual]) {
a[((vncscr->width - 1 - i) + offset )]=b[pixelToVirtual];
if (i>max_x)
max_x=i;
if (i<min_x)
min_x=i;
h=vncscr->height-j;
if (h < min_y)
min_y=vncscr->height-j;
if (h > max_y)
max_y=vncscr->height-j;
idle=0;
}
}
}
}
else if (rotation==270) {
for (j = 0; j < vncscr->width; j++) {
for (i = 0; i < vncscr->height; i++) {
offset = (vncscr->height - 1 - i) * vncscr->width;
if (method==FRAMEBUFFER)
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL_FB(i,j);
else
pixelToVirtual = PIXEL_TO_VIRTUALPIXEL(i,j);
if(a[j + offset] != b[pixelToVirtual]) {
a[j + offset] = b[pixelToVirtual];
if (i>max_y)
max_y=i;
if (i<min_y)
min_y=i;
if (j < min_x)
min_x=j;
if (j > max_x)
max_x=j;
idle=0;
}
}
}
}
if (!idle) {
memcpy(vncbuf,a,screenformat.width*screenformat.height*screenformat.bitsPerPixel/CHAR_BIT);
min_x--;
min_x--;
max_x++;
max_y++;
// L("Changed x(%d-%d) y(%d-%d)\n",min_x,max_x,min_y,max_y);
rfbMarkRectAsModified(vncscr, min_x, min_y, max_x, max_y);
}
}