First import
[xorg_rtime.git] / xorg-server-1.4 / mfb / mfbwindow.c
blobb138d580555944a1784a63a43f783b6a67afda69
1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright 1987, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 All Rights Reserved
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
47 ******************************************************************/
49 #ifdef HAVE_DIX_CONFIG_H
50 #include <dix-config.h>
51 #endif
53 #include <stdlib.h>
55 #include <X11/X.h>
56 #include "scrnintstr.h"
57 #include "windowstr.h"
58 #include "mfb.h"
59 #include "mistruct.h"
60 #include "regionstr.h"
61 #include "maskbits.h"
63 Bool
64 mfbCreateWindow(pWin)
65 register WindowPtr pWin;
67 register mfbPrivWin *pPrivWin;
69 pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
70 pPrivWin->pRotatedBorder = NullPixmap;
71 pPrivWin->pRotatedBackground = NullPixmap;
72 pPrivWin->fastBackground = FALSE;
73 pPrivWin->fastBorder = FALSE;
75 return (TRUE);
78 /* This always returns true, because Xfree can't fail. It might be possible
79 * on some devices for Destroy to fail */
80 Bool
81 mfbDestroyWindow(pWin)
82 WindowPtr pWin;
84 register mfbPrivWin *pPrivWin;
86 pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
88 if (pPrivWin->pRotatedBorder)
89 (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
90 if (pPrivWin->pRotatedBackground)
91 (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
92 return (TRUE);
95 /*ARGSUSED*/
96 Bool mfbMapWindow(pWindow)
97 WindowPtr pWindow;
99 return (TRUE);
102 /* (x, y) is the upper left corner of the window on the screen
103 do we really need to pass this? (is it a;ready in pWin->absCorner?)
104 we only do the rotation for pixmaps that are 32 bits wide (padded
105 or otherwise.)
106 mfbChangeWindowAttributes() has already put a copy of the pixmap
107 in pPrivWin->pRotated*
110 /*ARGSUSED*/
111 Bool
112 mfbPositionWindow(pWin, x, y)
113 register WindowPtr pWin;
114 int x, y;
116 register mfbPrivWin *pPrivWin;
117 int reset = 0;
119 pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
120 if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
122 mfbXRotatePixmap(pPrivWin->pRotatedBackground,
123 pWin->drawable.x - pPrivWin->oldRotate.x);
124 mfbYRotatePixmap(pPrivWin->pRotatedBackground,
125 pWin->drawable.y - pPrivWin->oldRotate.y);
126 reset = 1;
129 if (!pWin->borderIsPixel && pPrivWin->fastBorder)
131 while (pWin->backgroundState == ParentRelative)
132 pWin = pWin->parent;
133 mfbXRotatePixmap(pPrivWin->pRotatedBorder,
134 pWin->drawable.x - pPrivWin->oldRotate.x);
135 mfbYRotatePixmap(pPrivWin->pRotatedBorder,
136 pWin->drawable.y - pPrivWin->oldRotate.y);
137 reset = 1;
139 if (reset)
141 pPrivWin->oldRotate.x = pWin->drawable.x;
142 pPrivWin->oldRotate.y = pWin->drawable.y;
145 /* This is the "wrong" fix to the right problem, but it doesn't really
146 * cost very much. When the window is moved, we need to invalidate any
147 * RotatedPixmap that exists in any GC currently validated against this
148 * window.
150 pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
152 /* Again, we have no failure modes indicated by any of the routines
153 * we've called, so we have to assume it worked */
154 return (TRUE);
157 /*ARGSUSED*/
158 Bool
159 mfbUnmapWindow(pWindow)
160 WindowPtr pWindow;
162 return (TRUE);
165 /* UNCLEAN!
166 this code calls the bitblt helper code directly.
168 mfbCopyWindow copies only the parts of the destination that are
169 visible in the source.
173 void
174 mfbCopyWindow(pWin, ptOldOrg, prgnSrc)
175 WindowPtr pWin;
176 DDXPointRec ptOldOrg;
177 RegionPtr prgnSrc;
179 DDXPointPtr pptSrc;
180 register DDXPointPtr ppt;
181 RegionPtr prgnDst;
182 register BoxPtr pbox;
183 register int dx, dy;
184 register int i, nbox;
185 WindowPtr pwinRoot;
187 pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
189 prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
191 dx = ptOldOrg.x - pWin->drawable.x;
192 dy = ptOldOrg.y - pWin->drawable.y;
193 REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
194 REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
195 prgnSrc);
197 pbox = REGION_RECTS(prgnDst);
198 nbox = REGION_NUM_RECTS(prgnDst);
199 if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
200 return;
201 ppt = pptSrc;
203 for (i=nbox; --i >= 0; ppt++, pbox++)
205 ppt->x = pbox->x1 + dx;
206 ppt->y = pbox->y1 + dy;
209 mfbDoBitblt((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
210 GXcopy, prgnDst, pptSrc);
211 DEALLOCATE_LOCAL(pptSrc);
212 REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
217 /* swap in correct PaintWindow* routine. If we can use a fast output
218 routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
219 of it in devPrivate.
221 Bool
222 mfbChangeWindowAttributes(pWin, mask)
223 register WindowPtr pWin;
224 register unsigned long mask;
226 register unsigned long index;
227 register mfbPrivWin *pPrivWin;
228 WindowPtr pBgWin;
230 pPrivWin = (mfbPrivWin *)(pWin->devPrivates[mfbWindowPrivateIndex].ptr);
232 * When background state changes from ParentRelative and
233 * we had previously rotated the fast border pixmap to match
234 * the parent relative origin, rerotate to match window
236 if (mask & (CWBackPixmap | CWBackPixel) &&
237 pWin->backgroundState != ParentRelative &&
238 pPrivWin->fastBorder &&
239 (pPrivWin->oldRotate.x != pWin->drawable.x ||
240 pPrivWin->oldRotate.y != pWin->drawable.y))
242 mfbXRotatePixmap(pPrivWin->pRotatedBorder,
243 pWin->drawable.x - pPrivWin->oldRotate.x);
244 mfbYRotatePixmap(pPrivWin->pRotatedBorder,
245 pWin->drawable.y - pPrivWin->oldRotate.y);
246 pPrivWin->oldRotate.x = pWin->drawable.x;
247 pPrivWin->oldRotate.y = pWin->drawable.y;
249 while(mask)
251 index = lowbit (mask);
252 mask &= ~index;
253 switch(index)
255 case CWBackPixmap:
256 if (pWin->backgroundState == None)
258 pPrivWin->fastBackground = FALSE;
260 else if (pWin->backgroundState == ParentRelative)
262 pPrivWin->fastBackground = FALSE;
263 /* Rotate border to match parent origin */
264 if (pPrivWin->pRotatedBorder) {
265 for (pBgWin = pWin->parent;
266 pBgWin->backgroundState == ParentRelative;
267 pBgWin = pBgWin->parent);
268 mfbXRotatePixmap(pPrivWin->pRotatedBorder,
269 pBgWin->drawable.x - pPrivWin->oldRotate.x);
270 mfbYRotatePixmap(pPrivWin->pRotatedBorder,
271 pBgWin->drawable.y - pPrivWin->oldRotate.y);
272 pPrivWin->oldRotate.x = pBgWin->drawable.x;
273 pPrivWin->oldRotate.y = pBgWin->drawable.y;
276 else if ((pWin->background.pixmap->drawable.width <= PPW) &&
277 !(pWin->background.pixmap->drawable.width &
278 (pWin->background.pixmap->drawable.width - 1)))
280 mfbCopyRotatePixmap(pWin->background.pixmap,
281 &pPrivWin->pRotatedBackground,
282 pWin->drawable.x,
283 pWin->drawable.y);
284 if (pPrivWin->pRotatedBackground)
286 pPrivWin->fastBackground = TRUE;
287 pPrivWin->oldRotate.x = pWin->drawable.x;
288 pPrivWin->oldRotate.y = pWin->drawable.y;
290 else
292 pPrivWin->fastBackground = FALSE;
295 else
297 pPrivWin->fastBackground = FALSE;
299 break;
301 case CWBackPixel:
302 pPrivWin->fastBackground = FALSE;
303 break;
305 case CWBorderPixmap:
306 if ((pWin->border.pixmap->drawable.width <= PPW) &&
307 !(pWin->border.pixmap->drawable.width &
308 (pWin->border.pixmap->drawable.width - 1)))
310 for (pBgWin = pWin;
311 pBgWin->backgroundState == ParentRelative;
312 pBgWin = pBgWin->parent);
313 mfbCopyRotatePixmap(pWin->border.pixmap,
314 &pPrivWin->pRotatedBorder,
315 pBgWin->drawable.x,
316 pBgWin->drawable.y);
317 if (pPrivWin->pRotatedBorder)
319 pPrivWin->fastBorder = TRUE;
320 pPrivWin->oldRotate.x = pBgWin->drawable.x;
321 pPrivWin->oldRotate.y = pBgWin->drawable.y;
323 else
325 pPrivWin->fastBorder = FALSE;
328 else
330 pPrivWin->fastBorder = FALSE;
332 break;
333 case CWBorderPixel:
334 pPrivWin->fastBorder = FALSE;
335 break;
338 /* Again, we have no failure modes indicated by any of the routines
339 * we've called, so we have to assume it worked */
340 return (TRUE);