do_windows.c revision 736a7e2c
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, int reps) 46{ 47 int i; 48 49 ComputeSizes(xp, p); 50 51 parentcolumns = WIDTH / parentwidth; 52 parentrows = HEIGHT / parentheight; 53 parentwindows = parentcolumns * parentrows; /* Max reps we can fit */ 54 55 if (parentwindows > reps) { 56 parentwindows = reps; 57 } 58 59 /* We will do parentwindows sets of childwindows, in order to get better 60 timing accuracy. Creating 4 windows at a millisecond apiece or so 61 is a bit faster than the 60 Hz clock. */ 62 isolates = (Window *)malloc(parentwindows * sizeof(Window)); 63 parents = (Window *)malloc(parentwindows * sizeof(Window)); 64 65 /* 66 * Create isolation windows for the parents, and then the parents 67 * themselves. These isolation windows ensure that parent and children 68 * windows created/mapped in DoWins and DoWin2 all see the same local 69 * environment...the parent is an only child, and each parent contains 70 * the number of children we are trying to get benchmarks on. 71 */ 72 73 for (i = 0; i != parentwindows; i++) { 74 isolates[i] = XCreateSimpleWindow(xp->d, xp->w, 75 (i/parentrows)*parentwidth, (i%parentrows)*parentheight, 76 parentwidth, parentheight, 0, xp->background, xp->background); 77 parents[i] = XCreateSimpleWindow(xp->d, isolates[i], 78 0, 0, parentwidth, parentheight, 0, xp->background, xp->background); 79 } 80 81 XMapSubwindows(xp->d, xp->w); 82 return parentwindows; 83} /* CreateParents */ 84 85 86void 87MapParents(XParms xp, Parms p, int reps) 88{ 89 int i; 90 91 for (i = 0; i != parentwindows; i++) { 92 XMapWindow(xp->d, parents[i]); 93 } 94} 95 96void 97MapParentsCleanup(XParms xp, Parms p) 98{ 99 int i; 100 101 for (i = 0; i != parentwindows; i++) { 102 XMapWindow(xp->d, parents[i]); 103 } 104} 105 106 107int 108InitCreate(XParms xp, Parms p, int reps) 109{ 110 reps = CreateParents(xp, p, reps); 111 MapParents(xp, p, reps); 112 return reps; 113} 114 115static void 116CreateChildGroup(XParms xp, Parms p, Window parent) 117{ 118 int j; 119 120 for (j = 0; j != childwindows; j++) { 121 (void) XCreateSimpleWindow (xp->d, parent, 122 (CHILDSIZE+CHILDSPACE) * (j/childrows) + CHILDSPACE/2, 123 (CHILDSIZE+CHILDSPACE) * (j%childrows) + CHILDSPACE/2, 124 CHILDSIZE, CHILDSIZE, 0, xp->background, xp->foreground); 125 } 126 127 if (p->special) 128 XMapSubwindows (xp->d, parent); 129} 130 131void 132CreateChildren(XParms xp, Parms p, int reps) 133{ 134 int i; 135 136 for (i = 0; i != parentwindows; i++) { 137 CreateChildGroup(xp, p, parents[i]); 138 } /* end i */ 139} 140 141void 142DestroyChildren(XParms xp, Parms p) 143{ 144 int i; 145 146 for (i = 0; i != parentwindows; i++) { 147 XDestroySubwindows(xp->d, parents[i]); 148 } 149} 150 151void 152EndCreate(XParms xp, Parms p) 153{ 154 XDestroySubwindows(xp->d, xp->w); 155 free(parents); 156 free(isolates); 157} 158 159 160int 161InitMap(XParms xp, Parms p, int reps) 162{ 163 reps = CreateParents(xp, p, reps); 164 CreateChildren(xp, p, reps); 165 return reps; 166} 167 168void 169UnmapParents(XParms xp, Parms p, int reps) 170{ 171 int i; 172 173 for (i = 0; i != parentwindows; i++) { 174 XUnmapWindow(xp->d, parents[i]); 175 } 176} 177 178void 179UnmapParentsCleanup(XParms xp, Parms p) 180{ 181 int i; 182 183 for (i = 0; i != parentwindows; i++) { 184 XUnmapWindow(xp->d, parents[i]); 185 } 186} 187 188int 189InitDestroy(XParms xp, Parms p, int reps) 190{ 191 reps = CreateParents(xp, p, reps); 192 CreateChildren(xp, p, reps); 193 MapParents(xp, p, reps); 194 return reps; 195} 196 197void 198DestroyParents(XParms xp, Parms p, int reps) 199{ 200 int i; 201 202 for (i = 0; i != parentwindows; i++) { 203 XDestroyWindow(xp->d, parents[i]); 204 } 205} 206 207 208void 209RenewParents(XParms xp, Parms p) 210{ 211 int i; 212 213 for (i = 0; i != parentwindows; i++) { 214 parents[i] = XCreateSimpleWindow(xp->d, isolates[i], 215 0, 0, parentwidth, parentheight, 0, xp->background, xp->background); 216 } 217 CreateChildren(xp, p, parentwindows); 218 MapParents(xp, p, parentwindows); 219} 220 221int 222InitPopups(XParms xp, Parms p, int reps) 223{ 224#ifdef CHILDROOT 225 XWindowAttributes xwa; 226#endif 227 XSetWindowAttributes xswa; 228 Window isolate; 229 230#ifdef CHILDROOT 231 ComputeSizes(xp, p); 232 CreateChildGroup(xp, p, xp->w); 233 234 /* Now create simple window to pop up over children */ 235 (void) XGetWindowAttributes(xp->d, xp->w, &xwa); 236 xswa.override_redirect = True; 237 popup = XCreateSimpleWindow ( 238 xp->d, DefaultRootWindow(xp->d), 239 xwa.x + xwa.border_width, xwa.y + xwa.border_width, 240 parentwidth, parentheight, 241 0, xp->foreground, xp->foreground); 242#else 243 isolate = XCreateSimpleWindow( 244 xp->d, xp->w, 0, 0, WIDTH, HEIGHT, 245 0, xp->background, xp->background); 246 247 ComputeSizes(xp, p); 248 CreateChildGroup(xp, p, isolate); 249 XMapWindow(xp->d, isolate); 250 251 /* Now create simple window to pop up over children */ 252 xswa.override_redirect = True; 253 popup = XCreateSimpleWindow ( 254 xp->d, xp->w, 0, 0, 255 parentwidth, parentheight, 256 0, xp->foreground, xp->foreground); 257#endif 258 XChangeWindowAttributes (xp->d, popup, CWOverrideRedirect, &xswa); 259 return reps; 260} 261 262void 263DoPopUps(XParms xp, Parms p, int reps) 264{ 265 int i; 266 for (i = 0; i != reps; i++) { 267 XMapWindow(xp->d, popup); 268 XUnmapWindow(xp->d, popup); 269 CheckAbort (); 270 } 271} 272 273void 274EndPopups(XParms xp, Parms p) 275{ 276 XDestroySubwindows(xp->d, xp->w); 277#ifdef CHILDROOT 278 XDestroyWindow(xp->d, popup); 279#endif 280} 281 282