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 \ LOCAL_LDLIBS += -llog -lz -ldl
LOCAL_SRC_FILES += \
$(LIBVNCSERVER_SRC_FILES)\
droidvncserver.c \ droidvncserver.c \
gralloc_method.c \ gui.c \
libvncserver/libvncserver/scale.c \ inputMethods/input.c \
libvncserver/libvncserver/main.c \ screenMethods/adb.c \
libvncserver/libvncserver/rfbserver.c \ screenMethods/framebuffer.c \
libvncserver/libvncserver/rfbregion.c \ screenMethods/gralloc.c \
libvncserver/libvncserver/auth.c \ screenMethods/flinger.c \
libvncserver/libvncserver/sockets.c \ suinput/suinput.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_C_INCLUDES += \
local_c_includes := \
$(LOCAL_PATH) \ $(LOCAL_PATH) \
$(LOCAL_PATH)/libvncserver/libvncserver \ $(LOCAL_PATH)/screenMethods \
$(LOCAL_PATH)/libvncserver \ $(LOCAL_PATH)/inputMethods \
$(LOCAL_PATH)/libvncserver/common \ $(LOCAL_PATH)/suinput \
$(LOCAL_PATH)/../../zlib \ $(LOCAL_PATH)/../libpng \
$(LOCAL_PATH)/../../jpeg \ $(LOCAL_PATH)/../jpeg \
$(LOCAL_PATH)/../../openssl/include \ $(LOCAL_PATH)/../openssl/include \
$(LOCAL_PATH)/../../libpng \ $(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
# target LOCAL_MODULE:= androidvncserver
include $(CLEAR_VARS)
LOCAL_SRC_FILES += $(local_src_files)
LOCAL_CFLAGS += $(local_c_flags) -DANDROID_FROYO
LOCAL_C_INCLUDES += $(local_c_includes)
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
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)

View File

@ -18,13 +18,18 @@ 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
@ -32,48 +37,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#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;
uint32_t standby = 0;
uint16_t rotation = 0;
uint16_t scaling = 100;
//reverse connection
char *rhost = NULL; char *rhost = NULL;
int rport = 5500; 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()
@ -146,33 +145,25 @@ void sendServerStopped()
void initVncServer(int argc, char **argv) void initVncServer(int argc, char **argv)
{ {
vncbuf = calloc(displayInfo.width * displayInfo.height, displayInfo.bpp/CHAR_BIT); vncbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT);
cmpbuf = calloc(displayInfo.width * displayInfo.height, displayInfo.bpp/CHAR_BIT); cmpbuf = calloc(screenformat.width * screenformat.height, screenformat.bitsPerPixel/CHAR_BIT);
assert(vncbuf != NULL); assert(vncbuf != NULL);
assert(cmpbuf != NULL); assert(cmpbuf != NULL);
if (rotation==0 || rotation==180) if (rotation==0 || rotation==180)
vncscr = rfbGetScreen(&argc, argv, displayInfo.width , displayInfo.height, 0 /* not used */ , 3, displayInfo.bpp/CHAR_BIT); vncscr = rfbGetScreen(&argc, argv, screenformat.width , screenformat.height, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT);
else else
vncscr = rfbGetScreen(&argc, argv, displayInfo.height, displayInfo.width, 0 /* not used */ , 3, displayInfo.bpp/CHAR_BIT); vncscr = rfbGetScreen(&argc, argv, screenformat.height, screenformat.width, 0 /* not used */ , 3, screenformat.bitsPerPixel/CHAR_BIT);
assert(vncscr != NULL); assert(vncscr != NULL);
vncscr->desktopName = "Android"; vncscr->desktopName = "Android";
vncscr->frameBuffer =(char *)vncbuf; vncscr->frameBuffer =(char *)vncbuf;
vncscr->port = VNC_PORT; vncscr->port = VNC_PORT;
vncscr->kbdAddEvent = keyEvent; vncscr->kbdAddEvent = keyEvent;
vncscr->ptrAddEvent = ptrEvent; vncscr->ptrAddEvent = ptrEvent;
vncscr->newClientHook = (rfbNewClientHookPtr)clientHook; vncscr->newClientHook = (rfbNewClientHookPtr)clientHook;
vncscr->setXCutText = CutText; vncscr->setXCutText = CutText;
if (strcmp(VNC_PASSWORD,"")!=0) if (strcmp(VNC_PASSWORD,"")!=0)
@ -184,19 +175,18 @@ void initVncServer(int argc, char **argv)
vncscr->passwordCheck = rfbCheckPasswordByList; vncscr->passwordCheck = rfbCheckPasswordByList;
} }
vncscr->httpDir="/data/data/org.onaips.vnc/files/"; vncscr->httpDir="/data/data/org.onaips.vnc/files/";
vncscr->sslcertfile="self.pem"; vncscr->sslcertfile="self.pem";
vncscr->serverFormat.redShift=displayInfo.red_offset; vncscr->serverFormat.redShift = screenformat.redShift;
vncscr->serverFormat.greenShift=displayInfo.green_offset; vncscr->serverFormat.greenShift = screenformat.greenShift;
vncscr->serverFormat.blueShift=displayInfo.blue_offset; vncscr->serverFormat.blueShift = screenformat.blueShift;
vncscr->serverFormat.redMax=((1<<displayInfo.red_length)-1); vncscr->serverFormat.redMax = (( 1 << screenformat.redMax) -1);
vncscr->serverFormat.greenMax=((1<<displayInfo.green_length)-1); vncscr->serverFormat.greenMax = (( 1 << screenformat.greenMax) -1);
vncscr->serverFormat.blueMax=((1<<displayInfo.blue_length)-1); vncscr->serverFormat.blueMax = (( 1 << screenformat.blueMax) -1);
vncscr->serverFormat.bitsPerPixel=displayInfo.bpp; vncscr->serverFormat.bitsPerPixel = screenformat.bitsPerPixel;
vncscr->alwaysShared = TRUE; vncscr->alwaysShared = TRUE;
vncscr->handleEventsEagerly = TRUE; vncscr->handleEventsEagerly = TRUE;
@ -205,11 +195,8 @@ void initVncServer(int argc, char **argv)
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)
@ -222,9 +209,7 @@ void initVncServer(int argc, char **argv)
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);
} }
@ -235,46 +220,46 @@ void rotate(int value)
L("rotate()"); L("rotate()");
if (value == -1 || if (value == -1 ||
((value == 90 || value == 270) && (rotation == 0 || rotation == 180)) || ((value == 90 || value == 270) && (rotation == 0 || rotation == 180)) ||
((value==0 || value==180) && (rotation==90 || rotation==270))) ((value == 0 || value == 180) && (rotation == 90 || rotation == 270))) {
{
int h = vncscr->height; int h = vncscr->height;
int w = vncscr->width; int w = vncscr->width;
vncscr->width = h; vncscr->width = h;
vncscr->paddedWidthInBytes = h * displayInfo.bpp / CHAR_BIT; vncscr->paddedWidthInBytes = h * screenformat.bitsPerPixel / CHAR_BIT;
vncscr->height = w; vncscr->height = w;
{
rfbClientIteratorPtr iterator; rfbClientIteratorPtr iterator;
rfbClientPtr cl; rfbClientPtr cl;
iterator = rfbGetClientIterator(vncscr); iterator = rfbGetClientIterator(vncscr);
while ((cl = rfbClientIteratorNext(iterator)) != NULL) while ((cl = rfbClientIteratorNext(iterator)) != NULL)
cl->newFBSizePending = 1; cl->newFBSizePending = 1;
} }
}
if (value==-1) if (value == -1) {
{
rotation += 90; rotation += 90;
rotation=rotation%360; rotation %= 360;
} } else {
else
{
rotation = value; 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)
closeFB();
else if (method == ADB)
closeADB();
else if (method == GRALLOC)
closeGralloc();
else if (method == FLINGER)
closeFlinger();
cleanupInput(); cleanupInput();
sendServerStopped(); sendServerStopped();
unbindIPCserver(); unbindIPCserver();
@ -307,6 +292,31 @@ void extractReverseHostPort(char *str)
} }
} }
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"
@ -322,20 +332,17 @@ void printUsage(char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
signal(SIGINT, close_app);//pipe signals //pipe signals
signal(SIGINT, close_app);
signal(SIGKILL, close_app); signal(SIGKILL, close_app);
signal(SIGILL, close_app); signal(SIGILL, close_app);
if(argc > 1) if(argc > 1) {
{
int i=1; int i=1;
int r; int r;
while(i < argc) while(i < argc) {
{ if(*argv[i] == '-') {
if(*argv[i] == '-') switch(*(argv[i] + 1)) {
{
switch(*(argv[i] + 1))
{
case 'h': case 'h':
printUsage(argv); printUsage(argv);
exit(0); exit(0);
@ -346,7 +353,7 @@ int main(int argc, char **argv)
break; break;
case 'f': case 'f':
i++; i++;
setFramebufferDevice(argv[i]); FB_setDevice(argv[i]);
break; break;
case 'P': case 'P':
i++; i++;
@ -366,41 +373,30 @@ int main(int argc, char **argv)
scaling = r; scaling = r;
else else
scaling = 100; scaling = 100;
L("scaling to %d percent\n",scaling); L("scaling to %d%%\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; break;
case 'R': case 'R':
i++; i++;
extractReverseHostPort(argv[i]); extractReverseHostPort(argv[i]);
break; 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++; i++;
@ -408,80 +404,37 @@ int main(int argc, char **argv)
} }
L("Initializing grabber method...\n"); L("Initializing grabber method...\n");
initGrabberMethod();
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)
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
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) {
if (rhost)
{
rfbClientPtr cl; rfbClientPtr cl;
cl = rfbReverseConnection(vncscr, rhost, rport); cl = rfbReverseConnection(vncscr, rhost, rport);
if (cl == NULL) if (cl == NULL) {
{
char *str=malloc(255*sizeof(char)); char *str=malloc(255*sizeof(char));
sprintf(str,"~SHOW|Couldn't connect to remote host:\n%s\n",rhost); sprintf(str,"~SHOW|Couldn't connect to remote host:\n%s\n",rhost);
L("Couldn't connect to remote host: %s\n",rhost); L("Couldn't connect to remote host: %s\n",rhost);
sendMsgToGui(str); sendMsgToGui(str);
free(str); free(str);
} } else {
else
{
cl->onHold = FALSE; cl->onHold = FALSE;
rfbStartOnHoldClient(cl); rfbStartOnHoldClient(cl);
} }
@ -489,11 +442,9 @@ int main(int argc, char **argv)
rfbRunEventLoop(vncscr,-1,TRUE); rfbRunEventLoop(vncscr,-1,TRUE);
while (1) while (1) {
{
usleep(300000*(standby/2.0)); usleep(300000*(standby/2.0));
if (idle) if (idle)
standby++; standby++;
else else
@ -502,12 +453,7 @@ int main(int argc, char **argv)
if (vncscr->clientHead == NULL) if (vncscr->clientHead == NULL)
continue; continue;
update_screen(); 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
@ -41,35 +44,27 @@ int sendMsgToGui(char *buffer)
bzero(&server,sizeof(server)); bzero(&server,sizeof(server));
server.sin_family = AF_INET; server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr("127.0.0.1"); server.sin_addr.s_addr = inet_addr("127.0.0.1");
server.sin_port = htons(13131); server.sin_port = htons(DEFAULT_IPC_RECV_PORT);
length = sizeof(struct sockaddr_in); length = sizeof(struct sockaddr_in);
n=sendto(sock,buffer, n = sendto(sock,buffer,strlen(buffer),0,(struct sockaddr *)&server,length);
strlen(buffer),0,(struct sockaddr *)&server,length);
if (n < 0) perror("Sendto"); 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); 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;
} }

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,9 +77,8 @@ 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");
} }
@ -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);
struct fb_var_screeninfo scrinfo; unsigned int *readBufferFB(void);
struct fb_fix_screeninfo fscrinfo; void FB_setDevice(char *);
struct fb_var_screeninfo FB_getscrinfo(void);
int initFramebuffer(void);
void cleanupFramebuffer(void);
void update_fb_info();
int roundUpToPageSize(int x);
void setFramebufferDevice(char *);
#endif #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);
}
}