From a3403ab062a7b3bfff33a5d20cabf6c7132894f1 Mon Sep 17 00:00:00 2001 From: JosePereira Date: Mon, 11 Jun 2012 20:08:17 +0100 Subject: [PATCH] revamped some files --- jni/vnc/Android.mk | 146 +++---- jni/vnc/droidvncserver.c | 626 +++++++++++++--------------- jni/vnc/gui.c | 137 +++--- jni/vnc/gui.h | 8 + jni/vnc/inputMethods/input.h | 6 +- jni/vnc/screenMethods/adb.c | 46 +- jni/vnc/screenMethods/adb.h | 45 +- jni/vnc/screenMethods/flinger.c | 107 +++++ jni/vnc/screenMethods/flinger.h | 30 ++ jni/vnc/screenMethods/framebuffer.c | 70 ++-- jni/vnc/screenMethods/framebuffer.h | 17 +- jni/vnc/screenMethods/gralloc.c | 103 +++++ jni/vnc/screenMethods/gralloc.h | 30 ++ jni/vnc/updateScreen.c | 183 ++++++++ 14 files changed, 969 insertions(+), 585 deletions(-) create mode 100644 jni/vnc/screenMethods/flinger.c create mode 100644 jni/vnc/screenMethods/flinger.h create mode 100644 jni/vnc/screenMethods/gralloc.c create mode 100644 jni/vnc/screenMethods/gralloc.h create mode 100755 jni/vnc/updateScreen.c diff --git a/jni/vnc/Android.mk b/jni/vnc/Android.mk index 828f71c..e8785fb 100755 --- a/jni/vnc/Android.mk +++ b/jni/vnc/Android.mk @@ -1,94 +1,76 @@ - - LOCAL_PATH:= $(call my-dir) 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:= \ - input.c \ - gui.c \ - adb_method.c \ - 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 +LOCAL_CFLAGS += -Wall \ + -O3 \ + -DLIBVNCSERVER_WITH_WEBSOCKETS \ + -DLIBVNCSERVER_HAVE_LIBPNG -ginger_up := displaybinder.cpp - +LOCAL_LDLIBS += -llog -lz -ldl -local_c_includes := \ - $(LOCAL_PATH) \ - $(LOCAL_PATH)/libvncserver/libvncserver \ - $(LOCAL_PATH)/libvncserver \ - $(LOCAL_PATH)/libvncserver/common \ - $(LOCAL_PATH)/../../zlib \ - $(LOCAL_PATH)/../../jpeg \ - $(LOCAL_PATH)/../../openssl/include \ - $(LOCAL_PATH)/../../libpng \ - -####################################### +LOCAL_SRC_FILES += \ + $(LIBVNCSERVER_SRC_FILES)\ + droidvncserver.c \ + gui.c \ + inputMethods/input.c \ + screenMethods/adb.c \ + screenMethods/framebuffer.c \ + screenMethods/gralloc.c \ + screenMethods/flinger.c \ + suinput/suinput.c -# target -include $(CLEAR_VARS) -LOCAL_SRC_FILES += $(local_src_files) -LOCAL_CFLAGS += $(local_c_flags) -DANDROID_FROYO -LOCAL_C_INCLUDES += $(local_c_includes) +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH) \ + $(LOCAL_PATH)/screenMethods \ + $(LOCAL_PATH)/inputMethods \ + $(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_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 +LOCAL_MODULE:= androidvncserver include $(BUILD_EXECUTABLE) diff --git a/jni/vnc/droidvncserver.c b/jni/vnc/droidvncserver.c index 7778ce9..fc70d78 100755 --- a/jni/vnc/droidvncserver.c +++ b/jni/vnc/droidvncserver.c @@ -18,62 +18,61 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "common.h" -#include "framebuffer_method.h" -#include "gralloc_method.h" -#include "adb_method.h" +#include "framebuffer.h" +#include "adb.h" #include "gui.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 CONCAT2E(a,b) CONCAT2(a,b) #define CONCAT3(a,b,c) a##b##c #define CONCAT3E(a,b,c) CONCAT3(a,b,c) - char VNC_PASSWORD[256] = ""; -int VNC_PORT=5901; /* Android already has 5900 bound natively in some devices. */ - +int VNC_PORT=5901; unsigned int *cmpbuf; unsigned int *vncbuf; static rfbScreenInfoPtr vncscr; -int idle=0,standby=0, rotation=0,scaling=100; -char *rhost=NULL; -int rport=5500; +uint32_t idle = 0; +uint32_t standby = 0; +uint16_t rotation = 0; +uint16_t scaling = 100; + +//reverse connection +char *rhost = NULL; +int rport = 5500; + void (*update_screen)(void)=NULL; -enum method_type {AUTO,FRAMEBUFFER,ADB,GRALLOC -#ifndef ANDROID_FROYO -,GINGERBREAD}; -#else -}; -#endif - +enum method_type {AUTO,FRAMEBUFFER,ADB,GRALLOC,FLINGER}; 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(i,j) ((j*displayInfo.width)+i) +#define PIXEL_TO_VIRTUALPIXEL(i,j) ((j*screenformat.width)+i) #define OUT 8 -#include "update_screen.c" +#include "updateScreen.c" #undef OUT #define OUT 16 -#include "update_screen.c" +#include "updateScreen.c" #undef OUT -// #define OUT 24 -// #include "update_screen.c" -// #undef OUT - #define OUT 32 -#include "update_screen.c" +#include "updateScreen.c" #undef OUT inline int getCurrentRotation() @@ -83,12 +82,12 @@ inline int getCurrentRotation() inline int isIdle() { - return idle; + return idle; } void setIdle(int i) { - idle=i; + idle=i; } ClientGoneHookPtr clientGone(rfbClientPtr cl) @@ -103,7 +102,7 @@ rfbNewClientHookPtr clientHook(rfbClientPtr cl) { 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)); -// rfbSendNewScaleSize(cl); + //rfbSendNewScaleSize(cl); } cl->clientGoneHook=(ClientGoneHookPtr)clientGone; @@ -116,7 +115,7 @@ rfbNewClientHookPtr clientHook(rfbClientPtr cl) strcat(msg,"\n"); sendMsgToGui(msg); free (msg); - + return RFB_CLIENT_ACCEPT; } @@ -140,374 +139,321 @@ void sendServerStarted(){ void sendServerStopped() { - sendMsgToGui("~SERVERSTOPPED|\n"); + sendMsgToGui("~SERVERSTOPPED|\n"); } 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) - vncscr = rfbGetScreen(&argc, argv, displayInfo.width , displayInfo.height, 0 /* not used */ , 3, displayInfo.bpp/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; + vncbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT); + cmpbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT); - - vncscr->port = VNC_PORT; - - vncscr->kbdAddEvent = keyEvent; - vncscr->ptrAddEvent = ptrEvent; - vncscr->newClientHook = (rfbNewClientHookPtr)clientHook; + assert(vncbuf != NULL); + assert(cmpbuf != NULL); - vncscr->setXCutText = CutText; - - if (strcmp(VNC_PASSWORD,"")!=0) - { - char **passwords = (char **)malloc(2 * sizeof(char **)); - passwords[0] = VNC_PASSWORD; - passwords[1] = NULL; - vncscr->authPasswdData = passwords; - vncscr->passwordCheck = rfbCheckPasswordByList; - } - + if (rotation==0 || rotation==180) + vncscr = rfbGetScreen(&argc, argv, screenformat.width , screenformat.height, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT); + else + vncscr = rfbGetScreen(&argc, argv, screenformat.height, screenformat.width, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT); - vncscr->httpDir="/data/data/org.onaips.vnc/files/"; - vncscr->sslcertfile="self.pem"; - - vncscr->serverFormat.redShift=displayInfo.red_offset; - vncscr->serverFormat.greenShift=displayInfo.green_offset; - vncscr->serverFormat.blueShift=displayInfo.blue_offset; - - vncscr->serverFormat.redMax=((1<serverFormat.greenMax=((1<serverFormat.blueMax=((1<serverFormat.bitsPerPixel=displayInfo.bpp; - - vncscr->alwaysShared = TRUE; - vncscr->handleEventsEagerly = TRUE; - vncscr->deferUpdateTime = 5; + assert(vncscr != NULL); + + vncscr->desktopName = "Android"; + vncscr->frameBuffer =(char *)vncbuf; + vncscr->port = VNC_PORT; + vncscr->kbdAddEvent = keyEvent; + vncscr->ptrAddEvent = ptrEvent; + vncscr->newClientHook = (rfbNewClientHookPtr)clientHook; + vncscr->setXCutText = CutText; + + if (strcmp(VNC_PASSWORD,"")!=0) + { + 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/"; + 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 - if (vncscr->serverFormat.bitsPerPixel == 32) - update_screen=&CONCAT2E(update_screen_,32); -// else if (vncscr->serverFormat.bitsPerPixel == 24) -// update_screen=&CONCAT2E(update_screen_,24); + update_screen=&CONCAT2E(update_screen_,32); else if (vncscr->serverFormat.bitsPerPixel == 16) - update_screen=&CONCAT2E(update_screen_,16); + update_screen=&CONCAT2E(update_screen_,16); else if (vncscr->serverFormat.bitsPerPixel == 8) - update_screen=&CONCAT2E(update_screen_,8); + update_screen=&CONCAT2E(update_screen_,8); else { - L("Unsupported pixel depth: %d\n", - vncscr->serverFormat.bitsPerPixel); - - sendMsgToGui("~SHOW|Unsupported pixel depth, please send bug report.\n"); - return; - } - - - /* Mark as dirty since we haven't sent any updates at all yet. */ - - rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height); -} + L("Unsupported pixel depth: %d\n", + vncscr->serverFormat.bitsPerPixel); + + sendMsgToGui("~SHOW|Unsupported pixel depth, please send bug report.\n"); + return; + } + + /* Mark as dirty since we haven't sent any updates at all yet. */ + rfbMarkRectAsModified(vncscr, 0, 0, vncscr->width, vncscr->height); + } + - 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; - { - rfbClientIteratorPtr iterator; - rfbClientPtr cl; - iterator = rfbGetClientIterator(vncscr); - while ((cl = rfbClientIteratorNext(iterator)) != NULL) - cl->newFBSizePending = 1; - } + 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 * 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); - } void close_app() { - L("Cleaning up...\n"); - cleanupFramebuffer(); - cleanupInput(); - sendServerStopped(); - unbindIPCserver(); - exit(0); /* normal exit status */ + L("Cleaning up...\n"); + if (method == FRAMEBUFFER) + closeFB(); + else if (method == ADB) + closeADB(); + else if (method == GRALLOC) + closeGralloc(); + else if (method == FLINGER) + closeFlinger(); + + cleanupInput(); + sendServerStopped(); + unbindIPCserver(); + exit(0); /* normal exit status */ } void extractReverseHostPort(char *str) { - int len=strlen(str); + int len = strlen(str); char *p; - /* copy in to host */ - rhost = (char *) malloc(len+1); - if (! rhost) { - L("reverse_connect: could not malloc string %d\n", len); - exit(-1); - } - strncpy(rhost, str, len); - rhost[len] = '\0'; + /* copy in to host */ + rhost = (char *) malloc(len+1); + if (! rhost) { + L("reverse_connect: could not malloc string %d\n", len); + exit(-1); + } + strncpy(rhost, str, len); + rhost[len] = '\0'; - /* extract port, if any */ - if ((p = strrchr(rhost, ':')) != NULL) { - rport = atoi(p+1); - if (rport < 0) { - rport = -rport; - } else if (rport < 20) { - rport = 5500 + rport; - } - *p = '\0'; - } + /* extract port, if any */ + if ((p = strrchr(rhost, ':')) != NULL) { + rport = atoi(p+1); + if (rport < 0) { + rport = -rport; + } else if (rport < 20) { + rport = 5500 + rport; + } + *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) { - L("\nandroidvncserver [parameters]\n" - "-f \t- Framebuffer device (only with -m fb, default is /dev/graphics/fb0)\n" - "-h\t\t- Print this help\n" - "-m \t- Display grabber method\n\tfb: framebuffer\n\tgb: gingerbread+ devices\n\tadb: slower, but should be compatible with all devices\n" - "-p \t- Password to access server\n" - "-r \t- Screen rotation (degrees) (0,90,180,270)\n" - "-R \t- Host for reverse connection\n" - "-s \t- Scale percentage (20,30,50,100,150)\n\n" ); + L("\nandroidvncserver [parameters]\n" + "-f \t- Framebuffer device (only with -m fb, default is /dev/graphics/fb0)\n" + "-h\t\t- Print this help\n" + "-m \t- Display grabber method\n\tfb: framebuffer\n\tgb: gingerbread+ devices\n\tadb: slower, but should be compatible with all devices\n" + "-p \t- Password to access server\n" + "-r \t- Screen rotation (degrees) (0,90,180,270)\n" + "-R \t- Host for reverse connection\n" + "-s \t- Scale percentage (20,30,50,100,150)\n\n" ); } int main(int argc, char **argv) { - signal(SIGINT, close_app);//pipe signals - 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; + //pipe signals + signal(SIGINT, close_app); + signal(SIGKILL, close_app); + signal(SIGILL, close_app); - else if (initFramebuffer()!=-1) - method=FRAMEBUFFER; - else if (initADB()!=-1) - { - method=ADB; - updateADBFrame(); - } - break; - } - while (0); - } - else if (method==FRAMEBUFFER) - initFramebuffer(); - else if (method==ADB) - { - initADB(); - updateADBFrame(); - } - else if (method==GRALLOC) - init_gralloc(); - #ifndef ANDROID_FROYO - else if (method==GINGERBREAD) - initGingerbreadMethod(); - #endif + 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++; + FB_setDevice(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%%\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"); initInput(); - + L("Initializing VNC server:\n"); - L(" width: %d\n", (int)displayInfo.width); - L(" height: %d\n", (int)displayInfo.height); - L(" bpp: %d\n", (int)displayInfo.bpp); + L(" width: %d\n", (int)screenformat.width); + L(" height: %d\n", (int)screenformat.height); + L(" bpp: %d\n", (int)screenformat.bitsPerPixel); 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, - displayInfo.red_length,displayInfo.green_length,displayInfo.blue_length,displayInfo.alpha_length); - + + + L("Colourmap_rgba=%d:%d:%d:%d lenght=%d:%d:%d:%d\n", screenformat.redShift, screenformat.greenShift, screenformat.blueShift,screenformat.alphaShift, + screenformat.redMax,screenformat.greenMax,screenformat.blueMax,screenformat.alphaMax); + initVncServer(argc, argv); - + bindIPCserver(); 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) - { - 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); - - L("Couldn't connect to remote host: %s\n",rhost); - sendMsgToGui(str); - free(str); - } - else - { - cl->onHold = FALSE; - rfbStartOnHoldClient(cl); - } + L("Couldn't connect to remote host: %s\n",rhost); + sendMsgToGui(str); + free(str); + } else { + cl->onHold = FALSE; + rfbStartOnHoldClient(cl); + } } rfbRunEventLoop(vncscr,-1,TRUE); - while (1) - { - usleep(300000*(standby/2.0)); - - - if (idle) - standby++; - else - standby=2; + while (1) { + usleep(300000*(standby/2.0)); - if (vncscr->clientHead == NULL) - continue; - - - update_screen(); - } + if (idle) + standby++; + else + standby=2; + if (vncscr->clientHead == NULL) + continue; + + update_screen(); + } close_app(); -} - - - \ No newline at end of file + } diff --git a/jni/vnc/gui.c b/jni/vnc/gui.c index 526e3c3..9ca5a3e 100755 --- a/jni/vnc/gui.c +++ b/jni/vnc/gui.c @@ -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 */ +//this file implements a simple IPC connection with the Java GUI + #include "gui.h" +#include "common.h" #define SOCKET_ERROR -1 #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 */ struct sockaddr_in Address; /* Internet socket address stuct */ -int nAddressSize=sizeof(struct sockaddr_in); +int nAddressSize = sizeof(struct sockaddr_in); char pBuffer[BUFFER_SIZE]; static int nHostPort; int sendMsgToGui(char *buffer) { - int sock, n; - unsigned int length; - struct sockaddr_in server; - - sock= socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) perror("socket"); + int sock, n; + unsigned int length; + struct sockaddr_in server; - bzero(&server,sizeof(server)); - server.sin_family = AF_INET; - server.sin_addr.s_addr=inet_addr("127.0.0.1"); - server.sin_port = htons(13131); - length=sizeof(struct sockaddr_in); + sock = socket(AF_INET, SOCK_DGRAM, 0); + if (sock < 0) perror("socket"); - n=sendto(sock,buffer, - strlen(buffer),0,(struct sockaddr *)&server,length); - if (n < 0) perror("Sendto"); - -// L("Sent %s\n",buffer); -// n = recvfrom(sock,buffer,256,0,(struct sockaddr *)&from, &length); -// if (n < 0) error("recvfrom"); -// write(1,"Got an ack: ",12); -// write(1,buffer,n); - - close(sock); - return 0; + bzero(&server,sizeof(server)); + server.sin_family = AF_INET; + server.sin_addr.s_addr = inet_addr("127.0.0.1"); + server.sin_port = htons(DEFAULT_IPC_RECV_PORT); + length = sizeof(struct sockaddr_in); + + n = sendto(sock,buffer,strlen(buffer),0,(struct sockaddr *)&server,length); + if (n < 0) perror("Sendto"); + + close(sock); + return 0; } - + int bindIPCserver() { - nHostPort=13132; + nHostPort=DEFAULT_IPC_SEND_PORT; - L("Starting IPC connection..."); + L("Starting IPC connection..."); - /* make a socket */ - hServerSocket=socket(AF_INET,SOCK_DGRAM,0); + /* make a socket */ + hServerSocket=socket(AF_INET,SOCK_DGRAM,0); - if(hServerSocket == SOCKET_ERROR) - { - L("\nCould not make a socket\n"); - return 0; - } + if(hServerSocket == SOCKET_ERROR) { + L("Error creating socket\n"); + return 0; + } - /* fill address struct */ - Address.sin_addr.s_addr=INADDR_ANY; - Address.sin_port=htons(nHostPort); - Address.sin_family=AF_INET; + /* fill address struct */ + Address.sin_addr.s_addr=INADDR_ANY; + Address.sin_port=htons(nHostPort); + Address.sin_family=AF_INET; - /* bind to a port */ - if(bind(hServerSocket,(struct sockaddr*)&Address,sizeof(Address)) == SOCKET_ERROR) - { - 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"); + /* bind to a port */ + if(bind(hServerSocket,(struct sockaddr*)&Address,sizeof(Address)) == SOCKET_ERROR) + { + 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"); - 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; } @@ -101,31 +96,31 @@ int bindIPCserver() void *handle_connections() { - L("\nWaiting for a connection\n"); - struct sockaddr_in from; - int fromlen = sizeof(struct sockaddr_in); - int n; - - while (1) { - n = recvfrom(hServerSocket,pBuffer,BUFFER_SIZE,0,(struct sockaddr *)&from,&fromlen); - if (n < 0) perror("recvfrom"); - - L("Recebido: %s\n",pBuffer); - - if (strstr(pBuffer,"~PING|")!=NULL) - { - char *resp="~PONG|"; - n = sendto(hServerSocket,resp,strlen(resp), - 0,(struct sockaddr *)&from,fromlen); - if (n < 0) perror("sendto"); - } - else if (strstr(pBuffer,"~KILL|")!=NULL) - close_app(); - } + L("\nWaiting for a connection\n"); + struct sockaddr_in from; + int fromlen = sizeof(struct sockaddr_in); + int n; + + while (1) { + n = recvfrom(hServerSocket,pBuffer,BUFFER_SIZE,0,(struct sockaddr *)&from,&fromlen); + if (n < 0) perror("recvfrom"); + + L("Recebido: %s\n",pBuffer); + + if (strstr(pBuffer,"~PING|")!=NULL) + { + char *resp="~PONG|"; + n = sendto(hServerSocket,resp,strlen(resp), + 0,(struct sockaddr *)&from,fromlen); + if (n < 0) perror("sendto"); + } + else if (strstr(pBuffer,"~KILL|")!=NULL) + close_app(); + } } void unbindIPCserver() { close(hServerSocket); -} \ No newline at end of file +} diff --git a/jni/vnc/gui.h b/jni/vnc/gui.h index bc9452f..c40423c 100755 --- a/jni/vnc/gui.h +++ b/jni/vnc/gui.h @@ -22,7 +22,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "common.h" +#include +#include +#include +#include +#include +#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); diff --git a/jni/vnc/inputMethods/input.h b/jni/vnc/inputMethods/input.h index e7ce5b9..a716b4c 100755 --- a/jni/vnc/inputMethods/input.h +++ b/jni/vnc/inputMethods/input.h @@ -22,10 +22,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "common.h" #include "gui.h" + +#include "rfb/rfb.h" +#include "suinput.h" + #define BUS_VIRTUAL 0x06 - - void initInput(); int keysym2scancode(rfbBool down, rfbKeySym c, rfbClientPtr cl, int *sh, int *alt); void transformTouchCoordinates(int *x, int *y,int,int); diff --git a/jni/vnc/screenMethods/adb.c b/jni/vnc/screenMethods/adb.c index 29e1f05..6a3c625 100755 --- a/jni/vnc/screenMethods/adb.c +++ b/jni/vnc/screenMethods/adb.c @@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include - #include "common.h" #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 + +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[] = { 0x43, 0x4e, 0x58, 0x4e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, @@ -63,6 +73,8 @@ struct fbinfo *fb_info; struct _message *message,*okay_message; int sockfd; +unsigned int *adbbuf = NULL; + ssize_t write_socket(int fd, const void *buf, size_t 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)); read_socket(sockfd,message,sizeof(struct _message)); @@ -100,9 +112,9 @@ void send_connect_string() 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"); pid_t pid; @@ -121,7 +133,7 @@ int initADB() system("killall adbd"); system("setprop service.adb.tcp.port -1"); system("/sbin/adbd"); - return; + exit(0); 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; 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); + struct fbinfo displayInfo; + read_socket(sockfd,&displayInfo,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) 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 count=0; @@ -258,6 +284,12 @@ void updateADBFrame() // if (resp!=A_OKAY) // error("bad OKAY response"); + return adbbuf; +} + +void closeADB() +{ + close(sockfd); } // test start point diff --git a/jni/vnc/screenMethods/adb.h b/jni/vnc/screenMethods/adb.h index 68631b0..8c85782 100755 --- a/jni/vnc/screenMethods/adb.h +++ b/jni/vnc/screenMethods/adb.h @@ -20,47 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #ifndef ADB_CONNECT_METHOD #define ADB_CONNECT_METHOD -#include -#include -#include -#include -#include -#include -#include -#include -// #include - -#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; +int initADB(void); +unsigned int *readBufferADB(void); +void closeADB(void); #endif diff --git a/jni/vnc/screenMethods/flinger.c b/jni/vnc/screenMethods/flinger.c new file mode 100644 index 0000000..2d787b7 --- /dev/null +++ b/jni/vnc/screenMethods/flinger.c @@ -0,0 +1,107 @@ +/* +droid vnc server - Android VNC server +Copyright (C) 2011 Jose Pereira + +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 + +#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; +} + diff --git a/jni/vnc/screenMethods/flinger.h b/jni/vnc/screenMethods/flinger.h new file mode 100644 index 0000000..c32baec --- /dev/null +++ b/jni/vnc/screenMethods/flinger.h @@ -0,0 +1,30 @@ +/* +droid vnc server - Android VNC server +Copyright (C) 2009 Jose Pereira + +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 diff --git a/jni/vnc/screenMethods/framebuffer.c b/jni/vnc/screenMethods/framebuffer.c index ebf35bd..a8b0c2d 100755 --- a/jni/vnc/screenMethods/framebuffer.c +++ b/jni/vnc/screenMethods/framebuffer.c @@ -21,21 +21,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "framebuffer.h" -#include "common.h" #include "gui.h" int fbfd = -1; - +unsigned int *fbmmap; 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); } -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"); @@ -67,11 +77,10 @@ int initFramebuffer(void) size = scrinfo.yres * 2; } - if ((scrinfo.bits_per_pixel == 24)) {// && (fscrinfo.line_length/scrinfo.xres_virtual==CHAR_BIT*4)) - scrinfo.bits_per_pixel = 32; - - L("24-bit XRGB display detected\n"); - } + if ((scrinfo.bits_per_pixel == 24)) { + scrinfo.bits_per_pixel = 32; + L("24-bit XRGB display detected\n"); + } size_t fbSize = roundUpToPageSize(fscrinfo.line_length * size); @@ -83,37 +92,38 @@ int initFramebuffer(void) return -1; } - displayInfo.bpp = scrinfo.bits_per_pixel; - displayInfo.size = scrinfo.xres * scrinfo.yres * scrinfo.bits_per_pixel / CHAR_BIT; - displayInfo.width = scrinfo.xres; - displayInfo.height = scrinfo.yres; - displayInfo.red_offset = scrinfo.red.offset; - displayInfo.red_length = scrinfo.red.length; - displayInfo.green_offset = scrinfo.green.offset; - displayInfo.green_length = scrinfo.green.length; - displayInfo.blue_offset = scrinfo.blue.offset; - displayInfo.blue_length = scrinfo.blue.length; - displayInfo.alpha_offset = scrinfo.transp.offset; - displayInfo.alpha_length = scrinfo.transp.length; + screenformat.bitsPerPixel = scrinfo.bits_per_pixel; + screenformat.size = scrinfo.xres * scrinfo.yres * scrinfo.bits_per_pixel / CHAR_BIT; + screenformat.width = scrinfo.xres; + screenformat.height = scrinfo.yres; + screenformat.redShift = scrinfo.red.offset; + screenformat.redMax = scrinfo.red.length; + screenformat.greenShift = scrinfo.green.offset; + screenformat.greenMax = scrinfo.green.length; + screenformat.blueShift = scrinfo.blue.offset; + screenformat.blueMax = scrinfo.blue.length; + screenformat.alphaShift = scrinfo.transp.offset; + screenformat.alphaMax = scrinfo.transp.length; return 1; } -void cleanupFramebuffer(void) +void closeFB(void) { if(fbfd != -1) close(fbfd); } -void update_fb_info() -{ - 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); - } -} +struct fb_var_screeninfo FB_getscrinfo(void) +{ + return scrinfo; +} +unsigned int *readBufferFB(void) +{ + update_fb_info(); + return fbmmap; +} inline int roundUpToPageSize(int x) { return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); diff --git a/jni/vnc/screenMethods/framebuffer.h b/jni/vnc/screenMethods/framebuffer.h index 859f256..cf093f4 100755 --- a/jni/vnc/screenMethods/framebuffer.h +++ b/jni/vnc/screenMethods/framebuffer.h @@ -22,15 +22,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #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; -struct fb_fix_screeninfo fscrinfo; - -int initFramebuffer(void); -void cleanupFramebuffer(void); -void update_fb_info(); -int roundUpToPageSize(int x); -void setFramebufferDevice(char *); - -#endif \ No newline at end of file +#endif diff --git a/jni/vnc/screenMethods/gralloc.c b/jni/vnc/screenMethods/gralloc.c new file mode 100644 index 0000000..8f58d4b --- /dev/null +++ b/jni/vnc/screenMethods/gralloc.c @@ -0,0 +1,103 @@ +/* +droid vnc server - Android VNC server +Copyright (C) 2011 Jose Pereira + +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 + +#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; +} + diff --git a/jni/vnc/screenMethods/gralloc.h b/jni/vnc/screenMethods/gralloc.h new file mode 100644 index 0000000..557716b --- /dev/null +++ b/jni/vnc/screenMethods/gralloc.h @@ -0,0 +1,30 @@ +/* +droid vnc server - Android VNC server +Copyright (C) 2009 Jose Pereira + +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 diff --git a/jni/vnc/updateScreen.c b/jni/vnc/updateScreen.c new file mode 100755 index 0000000..412cd47 --- /dev/null +++ b/jni/vnc/updateScreen.c @@ -0,0 +1,183 @@ +/* +droid VNC server - a vnc server for android +Copyright (C) 2011 Jose Pereira + +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 (imax_y) + max_y=j; + if (jwidth; 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 (iwidth-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 (iheight-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 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); + } +} + + +