]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbwindow.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbwindow.c
1 /* $XConsortium: cfbwindow.c,v 5.22 94/04/17 20:29:07 dpw Exp $ */
2 /***********************************************************
3
4 Copyright (c) 1987  X Consortium
5
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:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
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.
22
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.
26
27
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29
30                         All Rights Reserved
31
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.  
39
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.
47
48 ******************************************************************/
49
50 #include "X.h"
51 #include "scrnintstr.h"
52 #include "windowstr.h"
53 #include "cfb.h"
54 #include "mistruct.h"
55 #include "regionstr.h"
56 #include "cfbmskbits.h"
57
58 extern WindowPtr *WindowTable;
59
60 Bool
61 cfbCreateWindow(pWin)
62     WindowPtr pWin;
63 {
64     cfbPrivWin *pPrivWin;
65
66     pPrivWin = cfbGetWindowPrivate(pWin);
67     pPrivWin->pRotatedBorder = NullPixmap;
68     pPrivWin->pRotatedBackground = NullPixmap;
69     pPrivWin->fastBackground = FALSE;
70     pPrivWin->fastBorder = FALSE;
71     pPrivWin->oldRotate.x = 0;
72     pPrivWin->oldRotate.y = 0;
73
74 #ifdef PIXMAP_PER_WINDOW
75     /* Setup pointer to Screen pixmap */
76     pWin->devPrivates[frameWindowPrivateIndex].ptr =
77         (pointer) cfbGetScreenPixmap(pWin->drawable.pScreen);
78 #endif
79
80     return TRUE;
81 }
82
83 Bool
84 cfbDestroyWindow(pWin)
85     WindowPtr pWin;
86 {
87     cfbPrivWin *pPrivWin;
88
89     pPrivWin = cfbGetWindowPrivate(pWin);
90
91     if (pPrivWin->pRotatedBorder)
92         (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBorder);
93     if (pPrivWin->pRotatedBackground)
94         (*pWin->drawable.pScreen->DestroyPixmap)(pPrivWin->pRotatedBackground);
95     return(TRUE);
96 }
97
98 /*ARGSUSED*/
99 Bool
100 cfbMapWindow(pWindow)
101     WindowPtr pWindow;
102 {
103     return(TRUE);
104 }
105
106 /* (x, y) is the upper left corner of the window on the screen 
107    do we really need to pass this?  (is it a;ready in pWin->absCorner?)
108    we only do the rotation for pixmaps that are 32 bits wide (padded
109 or otherwise.)
110    cfbChangeWindowAttributes() has already put a copy of the pixmap
111 in pPrivWin->pRotated*
112 */
113 /*ARGSUSED*/
114 Bool
115 cfbPositionWindow(pWin, x, y)
116     WindowPtr pWin;
117     int x, y;
118 {
119     cfbPrivWin *pPrivWin;
120     int setxy = 0;
121
122     pPrivWin = cfbGetWindowPrivate(pWin);
123     if (pWin->backgroundState == BackgroundPixmap && pPrivWin->fastBackground)
124     {
125         cfbXRotatePixmap(pPrivWin->pRotatedBackground,
126                       pWin->drawable.x - pPrivWin->oldRotate.x);
127         cfbYRotatePixmap(pPrivWin->pRotatedBackground,
128                       pWin->drawable.y - pPrivWin->oldRotate.y);
129         setxy = 1;
130     }
131
132     if (!pWin->borderIsPixel && pPrivWin->fastBorder)
133     {
134         while (pWin->backgroundState == ParentRelative)
135             pWin = pWin->parent;
136         cfbXRotatePixmap(pPrivWin->pRotatedBorder,
137                       pWin->drawable.x - pPrivWin->oldRotate.x);
138         cfbYRotatePixmap(pPrivWin->pRotatedBorder,
139                       pWin->drawable.y - pPrivWin->oldRotate.y);
140         setxy = 1;
141     }
142     if (setxy)
143     {
144         pPrivWin->oldRotate.x = pWin->drawable.x;
145         pPrivWin->oldRotate.y = pWin->drawable.y;
146     }
147     return (TRUE);
148 }
149
150 /*ARGSUSED*/
151 Bool
152 cfbUnmapWindow(pWindow)
153     WindowPtr pWindow;
154 {
155     return (TRUE);
156 }
157
158 /* UNCLEAN!
159    this code calls the bitblt helper code directly.
160
161    cfbCopyWindow copies only the parts of the destination that are
162 visible in the source.
163 */
164
165
166 void 
167 cfbCopyWindow(pWin, ptOldOrg, prgnSrc)
168     WindowPtr pWin;
169     DDXPointRec ptOldOrg;
170     RegionPtr prgnSrc;
171 {
172     DDXPointPtr pptSrc;
173     register DDXPointPtr ppt;
174     RegionRec rgnDst;
175     register BoxPtr pbox;
176     register int dx, dy;
177     register int i, nbox;
178     WindowPtr pwinRoot;
179
180     pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
181
182     REGION_INIT(pWin->drawable.pScreen, &rgnDst, NullBox, 0);
183
184     dx = ptOldOrg.x - pWin->drawable.x;
185     dy = ptOldOrg.y - pWin->drawable.y;
186     REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
187     REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
188
189     pbox = REGION_RECTS(&rgnDst);
190     nbox = REGION_NUM_RECTS(&rgnDst);
191     if(!nbox || !(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
192     {
193         REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
194         return;
195     }
196     ppt = pptSrc;
197
198     for (i = nbox; --i >= 0; ppt++, pbox++)
199     {
200         ppt->x = pbox->x1 + dx;
201         ppt->y = pbox->y1 + dy;
202     }
203
204     cfbDoBitbltCopy((DrawablePtr)pwinRoot, (DrawablePtr)pwinRoot,
205                 GXcopy, &rgnDst, pptSrc, ~0L);
206     DEALLOCATE_LOCAL(pptSrc);
207     REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
208 }
209
210
211
212 /* swap in correct PaintWindow* routine.  If we can use a fast output
213 routine (i.e. the pixmap is paddable to 32 bits), also pre-rotate a copy
214 of it in devPrivates[cfbWindowPrivateIndex].ptr.
215 */
216 Bool
217 cfbChangeWindowAttributes(pWin, mask)
218     WindowPtr pWin;
219     unsigned long mask;
220 {
221     register unsigned long index;
222     register cfbPrivWin *pPrivWin;
223     int width;
224     WindowPtr   pBgWin;
225
226     pPrivWin = cfbGetWindowPrivate(pWin);
227
228     /*
229      * When background state changes from ParentRelative and
230      * we had previously rotated the fast border pixmap to match
231      * the parent relative origin, rerotate to match window
232      */
233     if (mask & (CWBackPixmap | CWBackPixel) &&
234         pWin->backgroundState != ParentRelative &&
235         pPrivWin->fastBorder &&
236         (pPrivWin->oldRotate.x != pWin->drawable.x ||
237          pPrivWin->oldRotate.y != pWin->drawable.y))
238     {
239         cfbXRotatePixmap(pPrivWin->pRotatedBorder,
240                       pWin->drawable.x - pPrivWin->oldRotate.x);
241         cfbYRotatePixmap(pPrivWin->pRotatedBorder,
242                       pWin->drawable.y - pPrivWin->oldRotate.y);
243         pPrivWin->oldRotate.x = pWin->drawable.x;
244         pPrivWin->oldRotate.y = pWin->drawable.y;
245     }
246     while(mask)
247     {
248         index = lowbit (mask);
249         mask &= ~index;
250         switch(index)
251         {
252         case CWBackPixmap:
253             if (pWin->backgroundState == None)
254             {
255                 pPrivWin->fastBackground = FALSE;
256             }
257             else if (pWin->backgroundState == ParentRelative)
258             {
259                 pPrivWin->fastBackground = FALSE;
260                 /* Rotate border to match parent origin */
261                 if (pPrivWin->pRotatedBorder) {
262                     for (pBgWin = pWin->parent;
263                          pBgWin->backgroundState == ParentRelative;
264                          pBgWin = pBgWin->parent);
265                     cfbXRotatePixmap(pPrivWin->pRotatedBorder,
266                                   pBgWin->drawable.x - pPrivWin->oldRotate.x);
267                     cfbYRotatePixmap(pPrivWin->pRotatedBorder,
268                                   pBgWin->drawable.y - pPrivWin->oldRotate.y);
269                     pPrivWin->oldRotate.x = pBgWin->drawable.x;
270                     pPrivWin->oldRotate.y = pBgWin->drawable.y;
271                 }
272             }
273             else if (((width = (pWin->background.pixmap->drawable.width * PSZ))
274                       <= PGSZ) && !(width & (width - 1)))
275             {
276                 cfbCopyRotatePixmap(pWin->background.pixmap,
277                                     &pPrivWin->pRotatedBackground,
278                                     pWin->drawable.x,
279                                     pWin->drawable.y);
280                 if (pPrivWin->pRotatedBackground)
281                 {
282                     pPrivWin->fastBackground = TRUE;
283                     pPrivWin->oldRotate.x = pWin->drawable.x;
284                     pPrivWin->oldRotate.y = pWin->drawable.y;
285                 }
286                 else
287                 {
288                     pPrivWin->fastBackground = FALSE;
289                 }
290             }
291             else
292             {
293                 pPrivWin->fastBackground = FALSE;
294             }
295             break;
296
297         case CWBackPixel:
298             pPrivWin->fastBackground = FALSE;
299             break;
300
301         case CWBorderPixmap:
302             if (((width = (pWin->border.pixmap->drawable.width * PSZ)) <= PGSZ) &&
303                 !(width & (width - 1)))
304             {
305                 for (pBgWin = pWin;
306                      pBgWin->backgroundState == ParentRelative;
307                      pBgWin = pBgWin->parent);
308                 cfbCopyRotatePixmap(pWin->border.pixmap,
309                                     &pPrivWin->pRotatedBorder,
310                                     pBgWin->drawable.x,
311                                     pBgWin->drawable.y);
312                 if (pPrivWin->pRotatedBorder)
313                 {
314                     pPrivWin->fastBorder = TRUE;
315                     pPrivWin->oldRotate.x = pBgWin->drawable.x;
316                     pPrivWin->oldRotate.y = pBgWin->drawable.y;
317                 }
318                 else
319                 {
320                     pPrivWin->fastBorder = FALSE;
321                 }
322             }
323             else
324             {
325                 pPrivWin->fastBorder = FALSE;
326             }
327             break;
328          case CWBorderPixel:
329             pPrivWin->fastBorder = FALSE;
330             break;
331         }
332     }
333     return (TRUE);
334 }
335