Commit 8d8429b4 authored by dscho's avatar dscho

tile modus now near perfect (shm's better though)

parent 45a6c8f5
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
Display *dpy = 0; Display *dpy = 0;
int window; int window;
int c=0,blockLength = 32; int c=0,blockLength = 32;
int tileX=0,tileY=0,tileWidth=32,tileHeight=32,dontTile=True; int tileX=0,tileY=0,tileWidth=32,tileHeight=32*2,dontTile=True;
Bool gotInput = FALSE; Bool gotInput = FALSE;
Bool disconnectAfterFirstClient = TRUE; Bool disconnectAfterFirstClient = TRUE;
...@@ -193,16 +193,17 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b,int rowstride,int x,int y,i ...@@ -193,16 +193,17 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b,int rowstride,int x,int y,i
{ {
Bool changed; Bool changed;
int i,j,k,l1,l2,x1,y1; int i,j,k,l1,l2,x1,y1;
int bpp=s->bitsPerPixel/8;
for(j=0;j<height;j+=blockLength) for(j=0;j<height;j+=blockLength)
for(i=0;i<width;i+=blockLength) { for(i=0;i<width;i+=blockLength) {
y1=j+blockLength; if(y1>height) y1=height; y1=j+blockLength; if(y1>height) y1=height;
x1=i+blockLength; if(x1>width) x1=width; x1=i+blockLength; if(x1>width) x1=width;
y1*=rowstride; y1*=rowstride;
x1*=s->bitsPerPixel/8; x1*=bpp;
changed=FALSE; changed=FALSE;
for(l1=j*rowstride,l2=j*s->paddedWidthInBytes;l1<y1;l1+=rowstride,l2+=s->paddedWidthInBytes) for(l1=j*rowstride,l2=(j+y)*s->paddedWidthInBytes+x*bpp;l1<y1;l1+=rowstride,l2+=s->paddedWidthInBytes)
for(k=i*s->bitsPerPixel/8;k<x1;k++) for(k=i*bpp;k<x1;k++)
if(s->frameBuffer[l2+k]!=b[l1+k]) { if(s->frameBuffer[l2+k]!=b[l1+k]) {
// fprintf(stderr,"changed: %d, %d\n",k,l); // fprintf(stderr,"changed: %d, %d\n",k,l);
changed=TRUE; changed=TRUE;
...@@ -210,8 +211,8 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b,int rowstride,int x,int y,i ...@@ -210,8 +211,8 @@ void checkForImageUpdates(rfbScreenInfoPtr s,char *b,int rowstride,int x,int y,i
} }
if(changed) { if(changed) {
changed_p: changed_p:
for(l1+=i*s->bitsPerPixel/8,l2+=i*s->bitsPerPixel/8;l1<y1;l1+=rowstride,l2+=s->paddedWidthInBytes) for(l1+=i*bpp,l2+=i*bpp;l1<y1;l1+=rowstride,l2+=s->paddedWidthInBytes)
memcpy(/*b+l,*/s->frameBuffer+l2,b+l1,x1-i*s->bitsPerPixel/8); memcpy(/*b+l,*/s->frameBuffer+l2,b+l1,x1-i*bpp);
rfbMarkRectAsModified(s,x+i,y+j,x+i+blockLength,y+j+blockLength); rfbMarkRectAsModified(s,x+i,y+j,x+i+blockLength,y+j+blockLength);
} }
} }
...@@ -221,11 +222,12 @@ int probeX=0,probeY=0; ...@@ -221,11 +222,12 @@ int probeX=0,probeY=0;
void probeScreen(rfbScreenInfoPtr s,int xscreen) void probeScreen(rfbScreenInfoPtr s,int xscreen)
{ {
int i,j,pixel, int i,j,pixel,i1,j1,
bpp=s->rfbServerFormat.bitsPerPixel/8,mask=(1<<bpp)-1, bpp=s->rfbServerFormat.bitsPerPixel/8,mask=(1<<bpp)-1,
rstride=s->paddedWidthInBytes; rstride=s->paddedWidthInBytes;
XImage* im; XImage* im;
//fprintf(stderr,"/%d,%d",probeX,probeY);
#if 0
probeX++; probeX++;
if(probeX>=tileWidth) { if(probeX>=tileWidth) {
probeX=0; probeX=0;
...@@ -233,17 +235,24 @@ void probeScreen(rfbScreenInfoPtr s,int xscreen) ...@@ -233,17 +235,24 @@ void probeScreen(rfbScreenInfoPtr s,int xscreen)
if(probeY>=tileHeight) if(probeY>=tileHeight)
probeY=0; probeY=0;
} }
#else
probeX=(rand()%tileWidth);
probeY=(rand()%tileHeight);
#endif
for(j=probeY;j<s->height;j+=tileHeight) for(j=probeY;j<s->height;j+=tileHeight)
for(i=probeX;i<s->width;i+=tileWidth) { for(i=0/*probeX*/;i<s->width;i+=tileWidth) {
im=XGetImage(dpy,window,i,j,1,1,AllPlanes,ZPixmap); im=XGetImage(dpy,window,i,j,tileWidth/*1*/,1,AllPlanes,ZPixmap);
pixel=XGetPixel(im,0,0); /* for(i1=0;i1<bpp && im->data[i1]==(s->frameBuffer+i*bpp+j*rstride)[i1];i1++);
XDestroyImage(im); if(i1<bpp) { */
if(!memcmp(&pixel,s->frameBuffer+i*bpp+j*rstride,bpp)) { if(memcmp(im->data,s->frameBuffer+i*bpp+j*rstride,tileWidth*bpp)) {
/* do update */ /* do update */
int i1,j1,x=i-probeX,w=(x+tileWidth>s->width)?s->width-x:tileWidth, int x=i/*-probeX*/,w=(x+tileWidth>s->width)?s->width-x:tileWidth,
y=j-probeY,h=(y+tileHeight>s->height)?s->height-y:tileHeight; y=j-probeY,h=(y+tileHeight>s->height)?s->height-y:tileHeight;
XDestroyImage(im);
//getImage(bpp,dpy,xscreen,&im,x,y,w,h); //getImage(bpp,dpy,xscreen,&im,x,y,w,h);
//fprintf(stderr,"GetImage(%d,%d,%d,%d)",x,y,w,h);
im = XGetImage(dpy,window,x,y,w,h,AllPlanes,ZPixmap ); im = XGetImage(dpy,window,x,y,w,h,AllPlanes,ZPixmap );
for(j1=0;j1<h;j1++) for(j1=0;j1<h;j1++)
memcpy(s->frameBuffer+x*bpp+(y+j1)*rstride, memcpy(s->frameBuffer+x*bpp+(y+j1)*rstride,
...@@ -254,7 +263,9 @@ void probeScreen(rfbScreenInfoPtr s,int xscreen) ...@@ -254,7 +263,9 @@ void probeScreen(rfbScreenInfoPtr s,int xscreen)
//memcpy(s->frameBuffer+i*bpp+j*rstride,&pixel,bpp); //memcpy(s->frameBuffer+i*bpp+j*rstride,&pixel,bpp);
rfbMarkRectAsModified(s,x,y,x+w,y+h); rfbMarkRectAsModified(s,x,y,x+w,y+h);
//fprintf(stderr,"%d:%d:%x\n",i,j,pixel); //fprintf(stderr,"%d:%d:%x\n",i,j,pixel);
} //fprintf(stderr,"*");
} else
XDestroyImage(im);
} }
} }
...@@ -269,7 +280,7 @@ int main(int argc,char** argv) ...@@ -269,7 +280,7 @@ int main(int argc,char** argv)
int xscreen,i; int xscreen,i;
rfbScreenInfoPtr screen; rfbScreenInfoPtr screen;
int maxMsecsToConnect = 5000; /* a maximum of 5 seconds to connect */ int maxMsecsToConnect = 5000; /* a maximum of 5 seconds to connect */
int updateCounter = 20; /* about every 50 ms a screen update should be made. */ int updateCounter; /* about every 50 ms a screen update should be made. */
for(i=argc-1;i>0;i--) for(i=argc-1;i>0;i--)
if(i<argc-1 && strcmp(argv[i],"-display")==0) { if(i<argc-1 && strcmp(argv[i],"-display")==0) {
...@@ -279,16 +290,20 @@ int main(int argc,char** argv) ...@@ -279,16 +290,20 @@ int main(int argc,char** argv)
fprintf(stderr,"Couldn't connect to display \"%s\".\n",argv[i+1]); fprintf(stderr,"Couldn't connect to display \"%s\".\n",argv[i+1]);
exit(1); exit(1);
} }
} else if(strcmp(argv[i],"-noshm")==0) {
useSHM = FALSE;
} else if(strcmp(argv[i],"-runforever")==0) {
disconnectAfterFirstClient = FALSE;
} else if(i<argc-1 && strcmp(argv[i],"-wait4client")==0) { } else if(i<argc-1 && strcmp(argv[i],"-wait4client")==0) {
maxMsecsToConnect = atoi(argv[i+1]); maxMsecsToConnect = atoi(argv[i+1]);
} else if(i<argc-1 && strcmp(argv[i],"-update")==0) { } else if(i<argc-1 && strcmp(argv[i],"-update")==0) {
updateCounter = atoi(argv[i+1]); updateCounter = atoi(argv[i+1]);
} else if(strcmp(argv[i],"-noshm")==0) {
useSHM = FALSE;
} else if(strcmp(argv[i],"-runforever")==0) {
disconnectAfterFirstClient = FALSE;
} else if(strcmp(argv[i],"-tile")==0) {
dontTile=False;
} }
updateCounter = dontTile?20:1;
if(dpy==0) if(dpy==0)
dpy = XOpenDisplay(""); dpy = XOpenDisplay("");
if(dpy==0) { if(dpy==0) {
...@@ -388,42 +403,45 @@ int main(int argc,char** argv) ...@@ -388,42 +403,45 @@ int main(int argc,char** argv)
rfbProcessEvents(screen,-1); rfbProcessEvents(screen,-1);
#if 1 if(dontTile) {
probeScreen(screen,xscreen); if(gotInput) {
#else gotInput = FALSE;
if(gotInput) { c=updateCounter;
gotInput = FALSE; } else if(screen->rfbClientHead && c++>updateCounter) {
c=updateCounter; c=0;
} else if(screen->rfbClientHead && c++>updateCounter) { //fprintf(stderr,"*");
c=0; if(!useSHM)
//fprintf(stderr,"*"); framebufferImage->f.destroy_image(framebufferImage);
if(!useSHM) if(dontTile) {
framebufferImage->f.destroy_image(framebufferImage); getImage(screen->rfbServerFormat.bitsPerPixel,dpy,xscreen,&framebufferImage,0,0,screen->width,screen->height);
if(dontTile) { checkForImageUpdates(screen,framebufferImage->data,framebufferImage->bytes_per_line,
getImage(screen->rfbServerFormat.bitsPerPixel,dpy,xscreen,&framebufferImage,0,0,screen->width,screen->height); 0,0,screen->width,screen->height);
checkForImageUpdates(screen,framebufferImage->data,framebufferImage->bytes_per_line, } else {
0,0,screen->width,screen->height); /* old tile code. Eventually to be removed (TODO) */
} else { char isRightEdge = tileX+tileWidth>=screen->width;
char isRightEdge = tileX+tileWidth>=screen->width; char isLowerEdge = tileY+tileHeight>=screen->height;
char isLowerEdge = tileY+tileHeight>=screen->height; getImage(screen->rfbServerFormat.bitsPerPixel,dpy,xscreen,&framebufferImage,tileX,tileY,
getImage(screen->rfbServerFormat.bitsPerPixel,dpy,xscreen,&framebufferImage,tileX,tileY, isRightEdge?screen->width-tileX:tileWidth,
isRightEdge?screen->width-tileX:tileWidth, isLowerEdge?screen->height-tileY:tileHeight);
isLowerEdge?screen->height-tileY:tileHeight); checkForImageUpdates(screen,framebufferImage->data,framebufferImage->bytes_per_line,
checkForImageUpdates(screen,framebufferImage->data,framebufferImage->bytes_per_line, tileX,tileY,
tileX,tileY, isRightEdge?screen->width-tileX:tileWidth,
isRightEdge?screen->width-tileX:tileWidth, isLowerEdge?screen->height-tileY:tileHeight);
isLowerEdge?screen->height-tileY:tileHeight); if(isRightEdge) {
if(isRightEdge) { tileX=0;
tileX=0; if(isLowerEdge)
if(isLowerEdge) tileY=0;
tileY=0; else
else tileY+=tileHeight;
tileY+=tileHeight; } else
} else tileX+=tileWidth;
tileX+=tileWidth; }
} }
} else if(c++>updateCounter) {
c=0;
probeScreen(screen,xscreen);
} }
#endif
#ifdef WRITE_SNAPS #ifdef WRITE_SNAPS
{ {
int i,j,r,g,b; int i,j,r,g,b;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment