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