Пример #1
0
sraRegion *sraRgnBBox(const sraRegion *src) {
  int xmin=((unsigned int)(int)-1)>>1,ymin=xmin,xmax=1-xmin,ymax=xmax;
  sraSpan *vcurr, *hcurr;

  if(!src)
    return sraRgnCreate();

  vcurr = ((sraSpanList*)src)->front._next;
  while (vcurr != &(((sraSpanList*)src)->back)) {
    if(vcurr->start<ymin)
      ymin=vcurr->start;
    if(vcurr->end>ymax)
      ymax=vcurr->end;
    
    hcurr = vcurr->subspan->front._next;
    while (hcurr != &(vcurr->subspan->back)) {
      if(hcurr->start<xmin)
	xmin=hcurr->start;
      if(hcurr->end>xmax)
	xmax=hcurr->end;
      hcurr = hcurr->_next;
    }

    vcurr = vcurr->_next;
  }

  if(xmax<xmin || ymax<ymin)
    return sraRgnCreate();

  return sraRgnCreateRect(xmin,ymin,xmax,ymax);
}
Пример #2
0
void initialize_xdamage(void) {
	sraRegionPtr *ptr;
	int i, nreg;

	if (! xdamage_present) {
		use_xdamage = 0;
	}
	if (xdamage_regions)  {
		ptr = xdamage_regions;
		while (*ptr != NULL) {
			sraRgnDestroy(*ptr);
			ptr++;
		}
		free(xdamage_regions);
		xdamage_regions = NULL;
	}
	if (use_xdamage) {
		nreg = (xdamage_memory * NSCAN) + 2;
		xdamage_regions = (sraRegionPtr *)
		    malloc(nreg * sizeof(sraRegionPtr));
		for (i = 0; i < nreg; i++) {
			ptr = xdamage_regions+i;
			if (i == nreg - 1) {
				*ptr = NULL;
			} else {
				*ptr = sraRgnCreate();
				sraRgnMakeEmpty(*ptr);
			}
		}
		/* set so will be 0 in first collect_xdamage call */
		xdamage_ticker = -1;
	}
}
Пример #3
0
VNCServer::Client::Client(int id,const std::wstring &name,VNCServer* server)
{
	//Store id and name
	this->id = id;
	this->name.assign(name);
	//Store server
	this->server = server;

	//Not reseted
	reset = false;
	//Not freezed
	freeze = false;

	//No websocket yet
	this->ws = NULL;

	//Get server screen
	rfbScreenInfo* screen = server->GetScreenInfo();

	//Create client
	cl = (rfbClientRec*)calloc(sizeof(rfbClientRec),1);

	cl->screen = screen;
	cl->sock = 1;			//Dummy value to allow updatiing
	cl->viewOnly = TRUE;
	/* setup pseudo scaling */
	cl->scaledScreen = screen;
	cl->scaledScreen->scaledScreenRefCount++;

	//Allocate size for name
	cl->host = (char*) malloc(64);
	//Print id
	snprintf(cl->host,64,"%d",id);

	rfbResetStats(cl);
	cl->clientData = this;
	cl->clientGoneHook = rfbDoNothingWithClient;

	cl->state = _rfbClientRec::RFB_PROTOCOL_VERSION;

	cl->reverseConnection = FALSE;
	cl->readyForSetColourMapEntries = FALSE;
	cl->useCopyRect = FALSE;
	cl->preferredEncoding = -1;
	cl->correMaxWidth = 48;
	cl->correMaxHeight = 48;
#ifdef LIBVNCSERVER_HAVE_LIBZ
	cl->zrleData = NULL;
#endif

	cl->copyRegion = sraRgnCreate();
	cl->copyDX = 0;
	cl->copyDY = 0;

	cl->modifiedRegion = NULL;

	INIT_MUTEX(cl->updateMutex);
	INIT_COND(cl->updateCond);

	cl->requestedRegion = sraRgnCreate();

	cl->format = cl->screen->serverFormat;
	cl->translateFn = rfbTranslateNone;
	cl->translateLookupTable = NULL;

	//Add to list
	cl->refCount = 0;
	cl->next = screen->clientHead;
	cl->prev = NULL;
	if (screen->clientHead)
		screen->clientHead->prev = cl;

	screen->clientHead = cl;

#if defined(LIBVNCSERVER_HAVE_LIBZ) || defined(LIBVNCSERVER_HAVE_LIBPNG)
	cl->tightQualityLevel = 1;//-1;
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
	cl->tightCompressLevel = 9;//TIGHT_DEFAULT_COMPRESSION;
	cl->turboSubsampLevel = TURBO_DEFAULT_SUBSAMP;
	for (int i = 0; i < 4; i++)
		cl->zsActive[i] = FALSE;
#endif
#endif

	cl->fileTransfer.fd = -1;

	cl->enableCursorShapeUpdates = FALSE;
	cl->enableCursorPosUpdates = FALSE;
	cl->useRichCursorEncoding = FALSE;
	cl->enableLastRectEncoding = FALSE;
	cl->enableKeyboardLedState = FALSE;
	cl->enableSupportedMessages = FALSE;
	cl->enableSupportedEncodings = FALSE;
	cl->enableServerIdentity = FALSE;
	cl->lastKeyboardLedState = -1;
	cl->cursorX = screen->cursorX;
	cl->cursorY = screen->cursorY;
	cl->useNewFBSize = FALSE;

#ifdef LIBVNCSERVER_HAVE_LIBZ
	cl->compStreamInited = FALSE;
	cl->compStream.total_in = 0;
	cl->compStream.total_out = 0;
	cl->compStream.zalloc = Z_NULL;
	cl->compStream.zfree = Z_NULL;
	cl->compStream.opaque = Z_NULL;

	cl->zlibCompressLevel = 5;
#endif

	cl->progressiveSliceY = 0;
	cl->extensions = NULL;
	cl->lastPtrX = -1;
}
Пример #4
0
int xdamage_hint_skip(int y) {
	static sraRegionPtr scanline = NULL;
	static sraRegionPtr tmpl_y = NULL;
	int fast_tmpl = 1;
	sraRegionPtr reg, tmpl;
	int ret, i, n, nreg;
#ifndef NO_NCACHE
	static int ncache_no_skip = 0;
	static double last_ncache_no_skip = 0.0;
	static double last_ncache_no_skip_long = 0.0, ncache_fac = 0.25;
#endif

	if (! xdamage_present || ! use_xdamage) {
		return 0;	/* cannot skip */
	}
	if (! xdamage_regions) {
		return 0;	/* cannot skip */
	}

	if (! scanline) {
		/* keep it around to avoid malloc etc, recreate */
		scanline = sraRgnCreate();
	}
	if (! tmpl_y) {
		tmpl_y = sraRgnCreateRect(0, 0, dpy_x, 1);
	}

	nreg = (xdamage_memory * NSCAN) + 1;

#ifndef NO_NCACHE
	if (ncache > 0) {
		if (ncache_no_skip == 0) {
			double now = g_now;
			if (now > last_ncache_no_skip + 8.0) {
				ncache_no_skip = 1;
			} else if (now < last_bs_restore + 0.5) {
				ncache_no_skip = 1;
			} else if (now < last_su_restore + 0.5) {
				ncache_no_skip = 1;
			} else if (now < last_copyrect + 0.5) {
				ncache_no_skip = 1;
			}
			if (ncache_no_skip) {
				last_ncache_no_skip = dnow();
				if (now > last_ncache_no_skip_long + 60.0) {
					ncache_fac = 2.0;
					last_ncache_no_skip_long = now;
				} else {
					ncache_fac = 0.25;
				}
				return 0;
			}
		} else {
			if (ncache_no_skip++ >= ncache_fac*nreg + 4) {
				ncache_no_skip = 0;
			} else {
				return 0;
			}
		}
	}
#endif

	if (fast_tmpl) {
		sraRgnOffset(tmpl_y, 0, y);
		tmpl = tmpl_y;
	} else {
		tmpl = sraRgnCreateRect(0, y, dpy_x, y+1);
	}

	ret = 1;
	for (i=0; i<nreg; i++) {
		/* go back thru the history starting at most recent */
		n = (xdamage_ticker + nreg - i) % nreg;
		reg = xdamage_regions[n];  
		if (reg == NULL) {
			continue;
		}
		if (sraRgnEmpty(reg)) {
			/* checking for emptiness is very fast */
			continue;
		}
		sraRgnMakeEmpty(scanline);
		sraRgnOr(scanline, tmpl);
		if (sraRgnAnd(scanline, reg)) {
			ret = 0;
			break;
		}
	}
	if (fast_tmpl) {
		sraRgnOffset(tmpl_y, 0, -y);
	} else {
		sraRgnDestroy(tmpl);
	}
if (0) fprintf(stderr, "xdamage_hint_skip: %d -> %d\n", y, ret);

	return ret;
}