| 1712 | |
| 1713 | |
| 1714 | int multiThreadTest(int nThreads) |
| 1715 | { |
| 1716 | int glxattribs[] = { GLX_DOUBLEBUFFER, GLX_RGBA, GLX_RED_SIZE, 8, |
| 1717 | GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, None }; |
| 1718 | XVisualInfo *vis = NULL; |
| 1719 | Display *dpy = NULL; Window windows[MAXTHREADS]; |
| 1720 | GLXContext contexts[MAXTHREADS]; |
| 1721 | TestThread *testThreads[MAXTHREADS]; Thread *threads[MAXTHREADS]; |
| 1722 | XSetWindowAttributes swa; |
| 1723 | int i, retval = 1; |
| 1724 | |
| 1725 | if(nThreads == 0) return 1; |
| 1726 | for(i = 0; i < nThreads; i++) |
| 1727 | { |
| 1728 | windows[i] = 0; contexts[i] = 0; testThreads[i] = NULL; |
| 1729 | threads[i] = NULL; |
| 1730 | } |
| 1731 | #ifdef USEHELGRIND |
| 1732 | ANNOTATE_BENIGN_RACE_SIZED(&deadYet, sizeof(bool), ); |
| 1733 | #endif |
| 1734 | |
| 1735 | printf("Multithreaded rendering test (%d threads)\n\n", nThreads); |
| 1736 | |
| 1737 | try |
| 1738 | { |
| 1739 | if(!(dpy = XOpenDisplay(0))) THROW("Could not open display"); |
| 1740 | |
| 1741 | if((vis = glXChooseVisual(dpy, DefaultScreen(dpy), glxattribs)) == NULL) |
| 1742 | THROW("Could not find a suitable visual"); |
| 1743 | Window root = RootWindow(dpy, DefaultScreen(dpy)); |
| 1744 | swa.colormap = XCreateColormap(dpy, root, vis->visual, AllocNone); |
| 1745 | swa.border_pixel = 0; |
| 1746 | swa.event_mask = StructureNotifyMask | ExposureMask; |
| 1747 | for(i = 0; i < nThreads; i++) |
| 1748 | { |
| 1749 | int winX = (i % 10) * 100, winY = (i / 10) * 120; |
| 1750 | if((windows[i] = XCreateWindow(dpy, root, winX, winY, 100, 100, 0, |
| 1751 | vis->depth, InputOutput, vis->visual, |
| 1752 | CWBorderPixel | CWColormap | CWEventMask, &swa)) == 0) |
| 1753 | THROW("Could not create window"); |
| 1754 | XMapWindow(dpy, windows[i]); |
| 1755 | if(!(contexts[i] = glXCreateContext(dpy, vis, NULL, True))) |
| 1756 | THROW("Could not establish GLX context"); |
| 1757 | XMoveResizeWindow(dpy, windows[i], winX, winY, 100, 100); |
| 1758 | } |
| 1759 | XSync(dpy, False); |
| 1760 | XFree(vis); vis = NULL; |
| 1761 | |
| 1762 | for(i = 0; i < nThreads; i++) |
| 1763 | { |
| 1764 | testThreads[i] = new TestThread(i, dpy, windows[i], contexts[i]); |
| 1765 | threads[i] = new Thread(testThreads[i]); |
| 1766 | if(!testThreads[i] || !threads[i]) |
| 1767 | PRERROR1("Could not create thread %d", i); |
| 1768 | threads[i]->start(); |
| 1769 | } |
| 1770 | printf("Phase 1\n"); |
| 1771 | for(i = 0; i < nThreads; i++) |
no test coverage detected