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