| 647 | |
| 648 | |
| 649 | int multiThreadTest(int nThreads) |
| 650 | { |
| 651 | EGLint cfgAttribs[] = { EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, |
| 652 | EGL_NONE }, nc = 0; |
| 653 | EGLConfig config = 0; |
| 654 | XVisualInfo *vis = NULL; |
| 655 | Display *dpy = NULL; |
| 656 | EGLDisplay edpy = 0; |
| 657 | Window windows[MAXTHREADS]; |
| 658 | TestThread *testThreads[MAXTHREADS]; Thread *threads[MAXTHREADS]; |
| 659 | XSetWindowAttributes swa; |
| 660 | int i, retval = 1; |
| 661 | |
| 662 | if(nThreads == 0) return 1; |
| 663 | for(i = 0; i < nThreads; i++) |
| 664 | { |
| 665 | windows[i] = 0; testThreads[i] = NULL; threads[i] = NULL; |
| 666 | } |
| 667 | #ifdef USEHELGRIND |
| 668 | ANNOTATE_BENIGN_RACE_SIZED(&deadYet, sizeof(bool), ); |
| 669 | #endif |
| 670 | |
| 671 | printf("Multithreaded rendering test (%d threads)\n\n", nThreads); |
| 672 | |
| 673 | try |
| 674 | { |
| 675 | if(!(dpy = XOpenDisplay(0))) THROW("Could not open display"); |
| 676 | |
| 677 | if((edpy = eglGetDisplay(dpy)) == EGL_NO_DISPLAY) |
| 678 | THROW_EGL("eglGetDisplay()"); |
| 679 | if(!eglInitialize(edpy, NULL, NULL)) |
| 680 | THROW_EGL("eglInitialize()"); |
| 681 | |
| 682 | if(!eglChooseConfig(edpy, cfgAttribs, &config, 1, &nc)) |
| 683 | THROW_EGL("eglChooseConfig()"); |
| 684 | if(!(vis = getVisualFromConfig(dpy, DefaultScreen(dpy), edpy, config))) |
| 685 | THROW("Could not find a suitable visual"); |
| 686 | |
| 687 | Window root = RootWindow(dpy, DefaultScreen(dpy)); |
| 688 | swa.colormap = XCreateColormap(dpy, root, vis->visual, AllocNone); |
| 689 | swa.border_pixel = 0; |
| 690 | swa.event_mask = StructureNotifyMask | ExposureMask; |
| 691 | for(i = 0; i < nThreads; i++) |
| 692 | { |
| 693 | int winX = (i % 10) * 100, winY = (i / 10) * 120; |
| 694 | if((windows[i] = XCreateWindow(dpy, root, winX, winY, 100, 100, 0, |
| 695 | vis->depth, InputOutput, vis->visual, |
| 696 | CWBorderPixel | CWColormap | CWEventMask, &swa)) == 0) |
| 697 | THROW("Could not create window"); |
| 698 | XMapWindow(dpy, windows[i]); |
| 699 | XMoveResizeWindow(dpy, windows[i], winX, winY, 100, 100); |
| 700 | } |
| 701 | XSync(dpy, False); |
| 702 | XFree(vis); vis = NULL; |
| 703 | |
| 704 | for(i = 0; i < nThreads; i++) |
| 705 | { |
| 706 | testThreads[i] = new TestThread(i, dpy, windows[i], edpy); |
no test coverage detected