1/***************************************************************************** 2Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. 3 4 All Rights Reserved 5 6Permission to use, copy, modify, and distribute this software and its 7documentation for any purpose and without fee is hereby granted, 8provided that the above copyright notice appear in all copies and that 9both that copyright notice and this permission notice appear in 10supporting documentation, and that the name of Digital not be 11used in advertising or publicity pertaining to distribution of the 12software without specific, written prior permission. 13 14DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 16DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 17ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 18WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 19ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20SOFTWARE. 21 22******************************************************************************/ 23 24#include "x11perf.h" 25 26static Window *parents; 27static Window *isolates; 28static int childrows, childcolumns, childwindows; 29static int parentrows, parentcolumns, parentwindows; 30static int parentwidth, parentheight; 31static Window popup; 32 33static void 34ComputeSizes(XParms xp, Parms p) 35{ 36 childwindows = p->objects; 37 childrows = (childwindows + MAXCOLS - 1) / MAXCOLS; 38 childcolumns = (childrows > 1 ? MAXCOLS : childwindows); 39 40 parentwidth = (CHILDSIZE+CHILDSPACE) * childcolumns; 41 parentheight = (CHILDSIZE+CHILDSPACE) * childrows; 42} 43 44int 45CreateParents(XParms xp, Parms p, int64_t reps) 46{ 47 ComputeSizes(xp, p); 48 49 parentcolumns = WIDTH / parentwidth; 50 parentrows = HEIGHT / parentheight; 51 parentwindows = parentcolumns * parentrows; /* Max reps we can fit */ 52 53 if (parentwindows > reps) { 54 parentwindows = reps; 55 } 56 57 /* We will do parentwindows sets of childwindows, in order to get better 58 timing accuracy. Creating 4 windows at a millisecond apiece or so 59 is a bit faster than the 60 Hz clock. */ 60 isolates = malloc(parentwindows * sizeof(Window)); 61 parents = malloc(parentwindows * sizeof(Window)); 62 63 /* 64 * Create isolation windows for the parents, and then the parents 65 * themselves. These isolation windows ensure that parent and children 66 * windows created/mapped in DoWins and DoWin2 all see the same local 67 * environment...the parent is an only child, and each parent contains 68 * the number of children we are trying to get benchmarks on. 69 */ 70 71 for (int i = 0; i != parentwindows; i++) { 72 isolates[i] = XCreateSimpleWindow(xp->d, xp->w, 73 (i/parentrows)*parentwidth, (i%parentrows)*parentheight, 74 parentwidth, parentheight, 0, xp->background, xp->background); 75 parents[i] = XCreateSimpleWindow(xp->d, isolates[i], 76 0, 0, parentwidth, parentheight, 0, xp->background, xp->background); 77 } 78 79 XMapSubwindows(xp->d, xp->w); 80 return parentwindows; 81} /* CreateParents */ 82 83 84void 85MapParents(XParms xp, Parms p, int64_t reps) 86{ 87 for (int i = 0; i != parentwindows; i++) { 88 XMapWindow(xp->d, parents[i]); 89 } 90} 91 92void 93MapParentsCleanup(XParms xp, Parms p) 94{ 95 for (int i = 0; i != parentwindows; i++) { 96 XMapWindow(xp->d, parents[i]); 97 } 98} 99 100 101int 102InitCreate(XParms xp, Parms p, int64_t reps) 103{ 104 reps = CreateParents(xp, p, reps); 105 MapParents(xp, p, reps); 106 return reps; 107} 108 109static void 110CreateChildGroup(XParms xp, Parms p, Window parent) 111{ 112 for (int j = 0; j != childwindows; j++) { 113 (void) XCreateSimpleWindow (xp->d, parent, 114 (CHILDSIZE+CHILDSPACE) * (j/childrows) + CHILDSPACE/2, 115 (CHILDSIZE+CHILDSPACE) * (j%childrows) + CHILDSPACE/2, 116 CHILDSIZE, CHILDSIZE, 0, xp->background, xp->foreground); 117 } 118 119 if (p->special) 120 XMapSubwindows (xp->d, parent); 121} 122 123void 124CreateChildren(XParms xp, Parms p, int64_t reps) 125{ 126 for (int i = 0; i != parentwindows; i++) { 127 CreateChildGroup(xp, p, parents[i]); 128 } /* end i */ 129} 130 131void 132DestroyChildren(XParms xp, Parms p) 133{ 134 for (int i = 0; i != parentwindows; i++) { 135 XDestroySubwindows(xp->d, parents[i]); 136 } 137} 138 139void 140EndCreate(XParms xp, Parms p) 141{ 142 XDestroySubwindows(xp->d, xp->w); 143 free(parents); 144 free(isolates); 145} 146 147 148int 149InitMap(XParms xp, Parms p, int64_t reps) 150{ 151 reps = CreateParents(xp, p, reps); 152 CreateChildren(xp, p, reps); 153 return reps; 154} 155 156void 157UnmapParents(XParms xp, Parms p, int64_t reps) 158{ 159 for (int i = 0; i != parentwindows; i++) { 160 XUnmapWindow(xp->d, parents[i]); 161 } 162} 163 164void 165UnmapParentsCleanup(XParms xp, Parms p) 166{ 167 for (int i = 0; i != parentwindows; i++) { 168 XUnmapWindow(xp->d, parents[i]); 169 } 170} 171 172int 173InitDestroy(XParms xp, Parms p, int64_t reps) 174{ 175 reps = CreateParents(xp, p, reps); 176 CreateChildren(xp, p, reps); 177 MapParents(xp, p, reps); 178 return reps; 179} 180 181void 182DestroyParents(XParms xp, Parms p, int64_t reps) 183{ 184 for (int i = 0; i != parentwindows; i++) { 185 XDestroyWindow(xp->d, parents[i]); 186 } 187} 188 189 190void 191RenewParents(XParms xp, Parms p) 192{ 193 for (int i = 0; i != parentwindows; i++) { 194 parents[i] = XCreateSimpleWindow(xp->d, isolates[i], 195 0, 0, parentwidth, parentheight, 0, xp->background, xp->background); 196 } 197 CreateChildren(xp, p, parentwindows); 198 MapParents(xp, p, parentwindows); 199} 200 201int 202InitPopups(XParms xp, Parms p, int64_t reps) 203{ 204#ifdef CHILDROOT 205 XWindowAttributes xwa; 206#endif 207 XSetWindowAttributes xswa; 208 Window isolate; 209 210#ifdef CHILDROOT 211 ComputeSizes(xp, p); 212 CreateChildGroup(xp, p, xp->w); 213 214 /* Now create simple window to pop up over children */ 215 (void) XGetWindowAttributes(xp->d, xp->w, &xwa); 216 xswa.override_redirect = True; 217 popup = XCreateSimpleWindow ( 218 xp->d, DefaultRootWindow(xp->d), 219 xwa.x + xwa.border_width, xwa.y + xwa.border_width, 220 parentwidth, parentheight, 221 0, xp->foreground, xp->foreground); 222#else 223 isolate = XCreateSimpleWindow( 224 xp->d, xp->w, 0, 0, WIDTH, HEIGHT, 225 0, xp->background, xp->background); 226 227 ComputeSizes(xp, p); 228 CreateChildGroup(xp, p, isolate); 229 XMapWindow(xp->d, isolate); 230 231 /* Now create simple window to pop up over children */ 232 xswa.override_redirect = True; 233 popup = XCreateSimpleWindow ( 234 xp->d, xp->w, 0, 0, 235 parentwidth, parentheight, 236 0, xp->foreground, xp->foreground); 237#endif 238 XChangeWindowAttributes (xp->d, popup, CWOverrideRedirect, &xswa); 239 return reps; 240} 241 242void 243DoPopUps(XParms xp, Parms p, int64_t reps) 244{ 245 for (int i = 0; i != reps; i++) { 246 XMapWindow(xp->d, popup); 247 XUnmapWindow(xp->d, popup); 248 CheckAbort (); 249 } 250} 251 252void 253EndPopups(XParms xp, Parms p) 254{ 255 XDestroySubwindows(xp->d, xp->w); 256#ifdef CHILDROOT 257 XDestroyWindow(xp->d, popup); 258#endif 259} 260 261