[ Pobierz całość w formacie PDF ]
.y = 0.3; coords[3].z = 0.5;PEXPolyline(dpy, ren, PEXOCRender, 4, coords);PEXEndRendering(dpy, win, ren);XFlush(dpy); /* important */}void quitBtn( Widget w, void *p, void *pp){exit(0);}void drawBtn( Widget w, XmDrawingAreaCallbackStruct *sp,XtPointer *client_data){Dimension wd, ht;PEXRenderer *rp;if (sp == NULL) return;switch(sp->reason){case XmCR_EXPOSE:if (sp->event->xexpose.count == 0){rp = (PEXRenderer *)client_data;doSamplePEX(XtDisplay(w), XtWindow(w), *rp);}break;case XmCR_INPUT:break;}}intpexInit(Display *dpy, PEXExtensionInfo **pexparms){int err;char errorMsg[PEXErrorStringLength+1];PEXExtensionInfo *pex_info;err = PEXInitialize(dpy, pexparms,PEXErrorStringLength, errorMsg);if (err) return False;pex_info = (PEXExtensionInfo *)(*pexparms);if( (pex_info->subset_info & PEXImmediateMode) ||((pex_info->subset_info & 0xffff) == PEXCompleteImplementation)){return True;}return False;}int main(int argc, char *argv[]){Widget parent;XtAppContext app_context;int cp_size;int cp_argc;int cp_argv;int status;int screen;int depth;int fore;int bkg;int n;Arg wars[20];Visual *visual;Colormap colormap;XStandardColormap std_cmp;PEXRendererAttributes pex_attr;Display *dpy;PEXExtensionInfo *pexParms;PEXRenderer ren;Widget mainw;Widget filemenu;Widget menubar;Widget exitBtn;Widget drawme;XtToolkitInitialize();app_context = XtCreateApplicationContext();cp_argc = argc;cp_size = argc * (sizeof(char *));cp_argv = (char **)XtMalloc(cp_size);memcpy(cp_argv, argv, cp_size);dpy = XtOpenDisplay(app_context, NULL, NULL,"pexSample", NULL, 0, &argc, argv);if (dpy == (Display *) NULL)bailout("Cannot open display");status = pexInit(dpy,&pexParms);if (status == False) bailout("Cannot use PEX");screen = DefaultScreen(dpy);visual = DefaultVisual(dpy, screen);depth = DefaultDepth(dpy,screen);status = GetStdColormap(dpy, screen, visual, depth, &std_cmp);colormap = std_cmp.colormap;bkg = BlackPixel(dpy,screen);fore = WhitePixel(dpy,screen);n = 0;XtSetArg(wars[n], XmNvisual, visual); n++;XtSetArg(wars[n], XmNdepth, depth); n++;XtSetArg(wars[n], XmNcolormap, colormap); n++;XtSetArg(wars[n], XmNbackground, bkg); n++;XtSetArg(wars[n], XmNborderColor, fore); n++;XtSetArg(wars[n], XmNargc, cp_argc); n++;XtSetArg(wars[n], XmNargv,cp_argv); n++;XtSetArg(wars[n], XmNallowResize, True); n++;XtSetArg(wars[n], XmNmappedWhenManaged, False); n++;XtSetArg(wars[n], XmNwidth, 300); n++;XtSetArg(wars[n], XmNheight, 300); n++;parent = XtAppCreateShell(NULL,"pexSample",applicationShellWidgetClass, dpy, wars, n);n = 0;mainw = XmCreateMainWindow(parent, "mainwindow", wars, n);n = 0;XtSetArg(wars[n], XmNresizePolicy, XmRESIZE_ANY); n++;XtSetArg(wars[n], XmNbackground, bkg); n++;XtSetArg(wars[n], XmNborderColor, fore); n++;drawme = XmCreateDrawingArea(mainw, "da", wars, n);XtAddCallback(drawme, XmNexposeCallback,(XtCallbackProc)drawBtn, (XtPointer) &ren);XtAddCallback(drawme, XmNinputCallback,(XtCallbackProc)drawBtn, (XtPointer) &ren);XtAddCallback(drawme, XmNresizeCallback,(XtCallbackProc)drawBtn, (XtPointer) &ren);XtManageChild(drawme);XtManageChild(mainw);XtRealizeWidget(parent);pex_set_color_approx(dpy,XtWindow(drawme), &std_cmp, &pex_attr);XtMapWidget(parent);ren = PEXCreateRenderer(XtDisplay(mainw), XtWindow(drawme),PEXRAColorApproxTable, &pex_attr);if (ren == 0) {printf("\n Bad renderer \n"); exit (1);}XtAppMainLoop(app_context);return(0);}A few points to note about Listing 55.2 are that the immediate mode was used for rendering on the screen.PEX-SI provides no support for double buffering.This is a serious bug because lack of double buffering hinders performance.Even worse, the PEX-SI API assumes that the client desires an XClearArea on the window before each frame is drawn.This causes unnecessary flickering while the screen is cleared and redrawn on all primitive drawing calls.What should have been done wasto provide an end-of-render procedure hook, with the default hook installed to do a clear area function call.Individual vendors (because of market pressure) have provided their own solutions to the double buffering problem.(Most PHIGS workstations do double buffering.If you do immediate mode you get single buffering along with the PEX-SI's XClearArea call.)A final word about adding too many features in an X server.The more you add to the X server, the more memory it chews up in your system.Unless you absolutely require PEX (or other) support, do not add it to your X server, especially if RAM is 8MB orless.The PEX support for Linux added about 420KB on my system, which is not a lot, but it does start adding up.Also, the overhead of PEX applications tend to make my 8MB, 486/33 somewhat slow when running PEX demos, which leads me to believe that PEX onLinux with less than 16MB is not worth the hassle.If you are serious about PEX on Linux, get a faster machine and put gobs of memory on it.The performance improved very dramatically on a 486/66 with 32MB of RAM.Where To Look for More InformationIf you would like more information and examples of source code for PEX, check out these FTP sites:export.lcs.mit.edu in /R5contrib/contrib-R5fixes has several tar files of source code for PHIGS and PEX including a 3-D drawing program.http://www.x.org is a good place to start looking for more information on X.SummaryThis chapter has been a whirlwind tour of PEX.The topic of PEX could be a book in itself.In fact, there are several texts available that go into excruciating detail about PEX.You should have learned the following information from this chapter:How to create a new X server with your specifications.Building your own server with LinkKit is far easier than trying to re-create the entire X distribution.There are fewer memory requirements, and the build takes up less disk space and time tocompile and link.How to install the new server.The LinkKit does this for you automatically and gives you options to clean your directories, and so on.How to check for the extensions in the current server.How to interface Motif with PEX.The trade-offs of having too many extensions in X server, such as loss of memory and speed for added functionality.Where to look for more information about PEX and Linux
[ Pobierz całość w formacie PDF ]