Initial commit
[xorg_rtime.git] / xorg-server-1.4 / afb / afbwindow.c
bloba4a1602bcd437a7c8d4af4cb7533b66bb1fa7ebc
1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 All Rights Reserved
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the name of Digital not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 SOFTWARE.
48 ******************************************************************/
50 #ifdef HAVE_DIX_CONFIG_H
51 #include <dix-config.h>
52 #endif
54 #include <stdlib.h>
56 #include <X11/X.h>
57 #include "scrnintstr.h"
58 #include "windowstr.h"
59 #include "afb.h"
60 #include "mistruct.h"
61 #include "regionstr.h"
62 #include "maskbits.h"
64 Bool
65 afbCreateWindow(pWin)
66 register WindowPtr pWin;
68 register afbPrivWin *pPrivWin;
70 pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
71 pPrivWin->pRotatedBorder = NullPixmap;
72 pPrivWin->pRotatedBackground = NullPixmap;
73 pPrivWin->fastBackground = FALSE;
74 pPrivWin->fastBorder = FALSE;
75 #ifdef PIXMAP_PER_WINDOW
76 pWin->devPrivates[frameWindowPrivateIndex].ptr =
77 pWin->pDrawable.pScreen->devPrivates[afbScreenPrivateIndex].ptr;
78 #endif
80 return (TRUE);
83 /* This always returns true, because Xfree can't fail. It might be possible
84 * on some devices for Destroy to fail */
85 Bool
86 afbDestroyWindow(pWin)
87 WindowPtr pWin;
89 register afbPrivWin *pPrivWin;
91 pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
93 if (pPrivWin->pRotatedBorder)
94 (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
95 if (pPrivWin->pRotatedBackground)
96 (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
98 return (TRUE);
101 /*ARGSUSED*/
102 Bool
103 afbMapWindow(pWindow)
104 WindowPtr pWindow;
106 return (TRUE);
109 /* (x, y) is the upper left corner of the window on the screen
110 do we really need to pass this? (is it a;ready in pWin->absCorner?)
111 we only do the rotation for pixmaps that are 32 bits wide (padded
112 or otherwise.)
113 afbChangeWindowAttributes() has already put a copy of the pixmap
114 in pPrivWin->pRotated*
117 /*ARGSUSED*/
118 Bool
119 afbPositionWindow(pWin, x, y)
120 WindowPtr pWin;
121 int x, y;
123 register afbPrivWin *pPrivWin;
124 int reset = 0;
126 pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
127 if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground) {
128 afbXRotatePixmap(pPrivWin->pRotatedBackground,
129 pWin->drawable.x - pPrivWin->oldRotate.x);
130 afbYRotatePixmap(pPrivWin->pRotatedBackground,
131 pWin->drawable.y - pPrivWin->oldRotate.y);
132 reset = 1;
135 if (!pWin->borderIsPixel && pPrivWin->fastBorder) {
136 while (pWin->backgroundState == ParentRelative)
137 pWin = pWin->parent;
138 afbXRotatePixmap(pPrivWin->pRotatedBorder,
139 pWin->drawable.x - pPrivWin->oldRotate.x);
140 afbYRotatePixmap(pPrivWin->pRotatedBorder,
141 pWin->drawable.y - pPrivWin->oldRotate.y);
142 reset = 1;
144 if (reset) {
145 pPrivWin->oldRotate.x = pWin->drawable.x;
146 pPrivWin->oldRotate.y = pWin->drawable.y;
149 /* This is the "wrong" fix to the right problem, but it doesn't really
150 * cost very much. When the window is moved, we need to invalidate any
151 * RotatedPixmap that exists in any GC currently validated against this
152 * window.
154 pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
156 /* Again, we have no failure modes indicated by any of the routines
157 * we've called, so we have to assume it worked */
158 return (TRUE);
161 /*ARGSUSED*/
162 Bool
163 afbUnmapWindow(pWindow)
164 WindowPtr pWindow;
166 return (TRUE);
169 /* UNCLEAN!
170 this code calls the bitblt helper code directly.
172 afbCopyWindow copies only the parts of the destination that are
173 visible in the source.
177 void
178 afbCopyWindow(pWin, ptOldOrg, prgnSrc)
179 WindowPtr pWin;
180 DDXPointRec ptOldOrg;
181 RegionPtr prgnSrc;
183 DDXPointPtr pptSrc;
184 register DDXPointPtr ppt;
185 RegionPtr prgnDst;
186 register BoxPtr pbox;
187 register int dx, dy;
188 register int i, nbox;
189 WindowPtr pwinRoot;
191 pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
193 prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
195 dx = ptOldOrg.x - pWin->drawable.x;
196 dy = ptOldOrg.y - pWin->drawable.y;
197 REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
198 REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
199 prgnSrc);
201 pbox = REGION_RECTS(prgnDst);
202 nbox = REGION_NUM_RECTS(prgnDst);
203 if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
204 return;
205 ppt = pptSrc;
207 for (i=nbox; --i >= 0; ppt++, pbox++) {
208 ppt->x = pbox->x1 + dx;
209 ppt->y = pbox->y1 + dy;
212 afbDoBitblt((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot, GXcopy, prgnDst,
213 pptSrc, ~0);
214 DEALLOCATE_LOCAL(pptSrc);
215 REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
220 /* swap in correct PaintWindow* routine. If we can use a fast output
221 routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
222 of it in devPrivate.
224 Bool
225 afbChangeWindowAttributes(pWin, mask)
226 register WindowPtr pWin;
227 register unsigned long mask;
229 register unsigned long index;
230 register afbPrivWin *pPrivWin;
231 WindowPtr pBgWin;
233 pPrivWin = (afbPrivWin *)(pWin->devPrivates[afbWindowPrivateIndex].ptr);
235 * When background state changes from ParentRelative and
236 * we had previously rotated the fast border pixmap to match
237 * the parent relative origin, rerotate to match window
239 if (mask & (CWBackPixmap | CWBackPixel) &&
240 pWin->backgroundState != ParentRelative && pPrivWin->fastBorder &&
241 (pPrivWin->oldRotate.x != pWin->drawable.x ||
242 pPrivWin->oldRotate.y != pWin->drawable.y)) {
243 afbXRotatePixmap(pPrivWin->pRotatedBorder,
244 pWin->drawable.x - pPrivWin->oldRotate.x);
245 afbYRotatePixmap(pPrivWin->pRotatedBorder,
246 pWin->drawable.y - pPrivWin->oldRotate.y);
247 pPrivWin->oldRotate.x = pWin->drawable.x;
248 pPrivWin->oldRotate.y = pWin->drawable.y;
250 while(mask) {
251 index = lowbit (mask);
252 mask &= ~index;
253 switch(index) {
254 case CWBackPixmap:
255 if (pWin->backgroundState == None)
256 pPrivWin->fastBackground = FALSE;
257 else if (pWin->backgroundState == ParentRelative) {
258 pPrivWin->fastBackground = FALSE;
259 /* Rotate border to match parent origin */
260 if (pPrivWin->pRotatedBorder) {
261 for (pBgWin = pWin->parent;
262 pBgWin->backgroundState == ParentRelative;
263 pBgWin = pBgWin->parent);
264 afbXRotatePixmap(pPrivWin->pRotatedBorder,
265 pBgWin->drawable.x - pPrivWin->oldRotate.x);
266 afbYRotatePixmap(pPrivWin->pRotatedBorder,
267 pBgWin->drawable.y - pPrivWin->oldRotate.y);
268 pPrivWin->oldRotate.x = pBgWin->drawable.x;
269 pPrivWin->oldRotate.y = pBgWin->drawable.y;
271 } else if ((pWin->background.pixmap->drawable.width <= PPW) &&
272 !(pWin->background.pixmap->drawable.width &
273 (pWin->background.pixmap->drawable.width - 1))) {
274 afbCopyRotatePixmap(pWin->background.pixmap,
275 &pPrivWin->pRotatedBackground,
276 pWin->drawable.x, pWin->drawable.y);
277 if (pPrivWin->pRotatedBackground) {
278 pPrivWin->fastBackground = TRUE;
279 pPrivWin->oldRotate.x = pWin->drawable.x;
280 pPrivWin->oldRotate.y = pWin->drawable.y;
281 } else
282 pPrivWin->fastBackground = FALSE;
283 } else
284 pPrivWin->fastBackground = FALSE;
285 break;
287 case CWBackPixel:
288 pPrivWin->fastBackground = FALSE;
289 break;
291 case CWBorderPixmap:
292 if ((pWin->border.pixmap->drawable.width <= PPW) &&
293 !(pWin->border.pixmap->drawable.width &
294 (pWin->border.pixmap->drawable.width - 1))) {
295 for (pBgWin = pWin;
296 pBgWin->backgroundState == ParentRelative;
297 pBgWin = pBgWin->parent);
298 afbCopyRotatePixmap(pWin->border.pixmap,
299 &pPrivWin->pRotatedBorder,
300 pBgWin->drawable.x, pBgWin->drawable.y);
301 if (pPrivWin->pRotatedBorder) {
302 pPrivWin->fastBorder = TRUE;
303 pPrivWin->oldRotate.x = pBgWin->drawable.x;
304 pPrivWin->oldRotate.y = pBgWin->drawable.y;
305 } else
306 pPrivWin->fastBorder = FALSE;
307 } else
308 pPrivWin->fastBorder = FALSE;
309 break;
310 case CWBorderPixel:
311 pPrivWin->fastBorder = FALSE;
312 break;
315 /* Again, we have no failure modes indicated by any of the routines
316 * we've called, so we have to assume it worked */
317 return (TRUE);