Exemplo n.º 1
0
//////////////////////////////////////////////////////////////////////
// Main
//////////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
	int i;

	fprintf(stderr, "\n%s v%s (Build %s)\n\n", bench_name, __VERSION, __BUILD);

	if(argc>1) for(i=1; i<argc; i++)
	{
		if(!stricmp(argv[i], "-checkdb"))
		{
			checkdb=1;
			fprintf(stderr, "Checking double buffering.  Watch for flashing to indicate that it is\n");
			fprintf(stderr, "not enabled.  Performance will be sub-optimal.\n");
		}
		if(!stricmp(argv[i], "-noshm"))
		{
			doshm=0;
		}
		if(!stricmp(argv[i], "-verbose"))
		{
			fbx_printwarnings(stderr);
		}
	}

	try {

	#ifdef FBXWIN32

	WNDCLASSEX wndclass;  MSG msg;
	wndclass.cbSize = sizeof(WNDCLASSEX);
	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WndProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hInstance = GetModuleHandle(NULL);
	wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = bench_name;
	wndclass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
	tryw32(RegisterClassEx(&wndclass));
	width=GetSystemMetrics(SM_CXSCREEN);
	height=GetSystemMetrics(SM_CYSCREEN);

	#else

	if(!XInitThreads()) {fprintf(stderr, "ERROR: Could not initialize Xlib thread safety\n");  exit(1);}
	XSetErrorHandler(xhandler);
	if(!(wh.dpy=XOpenDisplay(0))) {fprintf(stderr, "Could not open display %s\n", XDisplayName(0));  exit(1);}
	width=DisplayWidth(wh.dpy, DefaultScreen(wh.dpy));
	height=DisplayHeight(wh.dpy, DefaultScreen(wh.dpy));

	#endif

	if(width<MIN_SCREEN_WIDTH && height<MIN_SCREEN_HEIGHT)
	{
		fprintf(stderr, "ERROR: Please switch to a screen resolution of at least %d x %d.\n", MIN_SCREEN_WIDTH, MIN_SCREEN_HEIGHT);
		exit(1);
	}
	width=WIDTH;
	height=HEIGHT;

	#ifdef FBXWIN32

	int bw=GetSystemMetrics(SM_CXFIXEDFRAME)*2;
	int bh=GetSystemMetrics(SM_CYFIXEDFRAME)*2+GetSystemMetrics(SM_CYCAPTION);
	tryw32(wh=CreateWindowEx(0, bench_name, bench_name, WS_OVERLAPPED |
		WS_SYSMENU | WS_CAPTION | WS_VISIBLE, 0,  0, width+bw, height+bh, NULL,
		NULL, GetModuleHandle(NULL), NULL));
	UpdateWindow(wh);
	BOOL ret;
	while(1)
	{
		if((ret=GetMessage(&msg, NULL, 0, 0))==-1) _throww32();
		else if(ret==0) break;
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (int)msg.wParam;

	#else

	XVisualInfo vtemp, *v=NULL;  int n=0;
	XSetWindowAttributes swa;
	Window root=DefaultRootWindow(wh.dpy);

	vtemp.depth=24;  vtemp.c_class=TrueColor;
	if((v=XGetVisualInfo(wh.dpy, VisualDepthMask|VisualClassMask, &vtemp, &n))!=NULL && n!=0)
	{
		swa.colormap=XCreateColormap(wh.dpy, root, v->visual, AllocNone);
		swa.border_pixel=0;
		swa.event_mask=0;
		errifnot(wh.win=XCreateWindow(wh.dpy, root, 0, 0, width, height, 0,
			v->depth, InputOutput, v->visual, CWBorderPixel|CWColormap|CWEventMask,
			&swa));
		errifnot(XMapRaised(wh.dpy, wh.win));
		XSync(wh.dpy, False);
		display();
		XDestroyWindow(wh.dpy, wh.win);
		XFree(v);  v=NULL;
	}
	else fprintf(stderr, "No RGB visuals available.  Skipping those tests.\n\n");

	vtemp.depth=8;  vtemp.c_class=PseudoColor;
	if((v=XGetVisualInfo(wh.dpy, VisualDepthMask|VisualClassMask, &vtemp, &n))!=NULL && n!=0)
	{
		swa.colormap=XCreateColormap(wh.dpy, root, v->visual, AllocAll);
		swa.border_pixel=0;
		swa.event_mask=0;
    XColor xc[32];  int i;
		errifnot(v->colormap_size==256);
		for(i=0; i<32; i++)
		{
			xc[i].red=(i<16? i*16:255)<<8;
			xc[i].green=(i<16? i*16:255-(i-16)*16)<<8;
			xc[i].blue=(i<16? 255:255-(i-16)*16)<<8;
			xc[i].flags = DoRed | DoGreen | DoBlue;
			xc[i].pixel=i;
		}
		XStoreColors(wh.dpy, swa.colormap, xc, 32);
		errifnot(wh.win=XCreateWindow(wh.dpy, root, 0, 0, width, height, 0,
			v->depth, InputOutput, v->visual, CWBorderPixel|CWColormap|CWEventMask,
			&swa));
		errifnot(XMapRaised(wh.dpy, wh.win));
		XSync(wh.dpy, False);
		display();
		XDestroyWindow(wh.dpy, wh.win);
		XFreeColormap(wh.dpy, swa.colormap);
		XFree(v);  v=NULL;
	}
	else fprintf(stderr, "No Pseudocolor visuals available.  Skipping those tests.\n\n");

	return 0;

	#endif

	} catch(rrerror &e) {fprintf(stderr, "%s\n", e.getMessage());}
}
Exemplo n.º 2
0
void RRPlugin::sendvgl(rrdisplayclient *rrdpy, GLint drawbuf, bool spoillast,
                       int compress, int qual, int subsamp, bool block)
{

#if 0
   while(block && !rrdpy->frameready())
   {
      fprintf(stderr, "pause "); fflush(stderr);
      usleep(100000);
   }
#else
    (void)block;
#endif

    osgViewer::GraphicsWindow *win = coVRConfig::instance()->windows[0].window;
    int x, y, w, h;
    win->getWindowRectangle(x, y, w, h);

    if (spoillast && fconfig.spoil && !rrdpy->frameready())
        return;
    rrframe *b;
    int flags = RRBMP_BOTTOMUP, format = GL_RGB;
#ifdef GL_BGR_EXT
    if (littleendian() && compress != RRCOMP_RGB)
    {
        format = GL_BGR_EXT;
        flags |= RRBMP_BGR;
    }
#endif
    if (m_cudaReadBack && m_cudapinnedmemory)
        flags |= RRBMP_CUDAALLOC;
    errifnot(b = rrdpy->getbitmap(w, h, 3, flags,
                                  false /*stereo*/, fconfig.spoil));

    GLint buf = drawbuf;

    //b->_h.winid=_win;
    b->_h.dpynum = 0;
    b->_h.winid = 0;
    b->_h.framew = b->_h.width;
    b->_h.frameh = b->_h.height;
    b->_h.x = 0;
    b->_h.y = 0;
    b->_h.qual = qual;
    b->_h.subsamp = subsamp;
    b->_h.compress = (unsigned char)compress;

    double start = 0.;
    if (benchmark)
        start = cover->currentTime();
    double bpp = 4.;
#ifdef HAVE_CUDA
    if (m_cudaReadBack)
    {
        int hs = tjMCUWidth[jpegsub(subsamp)] / 8;
        int vs = tjMCUHeight[jpegsub(subsamp)] / 8;
        if (fconfig.compress == RRCOMP_YUV2JPEG)
        {
            m_cudaReadBack->readpixelsyuv(0, 0, b->_h.framew, b->_pitch, b->_h.frameh, format,
                                          b->_pixelsize, b->_bits, buf, hs, vs);
            bpp = 1. + 2. / hs / vs;
        }
        else
            m_cudaReadBack->readpixels(0, 0, b->_h.framew, b->_pitch, b->_h.frameh, format,
                                       b->_pixelsize, b->_bits, buf);
    }
    else
#endif
        readpixels(0, 0, b->_h.framew, b->_pitch, b->_h.frameh, format,
                   b->_pixelsize, b->_bits, buf);
    double dur = 0.;
    if (benchmark)
        dur = cover->currentTime() - start;
    double pix = b->_h.framew * b->_h.frameh;
    double bytes = pix * bpp;
    if (benchmark)
        fprintf(stderr, "%fs: %f mpix/s, %f gb/s (cuda=%d, yuv=%d)\n",
                dur,
                pix / dur / 1e6, bytes / dur / (1024 * 1024 * 1024),
                m_cudaReadBack != NULL, fconfig.compress == RRCOMP_YUV2JPEG);
    //b->_h.winid=_win;
    b->_h.dpynum = 0;
    b->_h.winid = 0;
    b->_h.framew = b->_h.width;
    b->_h.frameh = b->_h.height;
    b->_h.x = 0;
    b->_h.y = 0;
    b->_h.qual = qual;
    b->_h.subsamp = subsamp;
    b->_h.compress = (unsigned char)compress;

    if (m_sendThread)
    {
        m_sendThread->send(rrdpy, b);
    }
    else
        rrdpy->sendframe(b);
}