]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/dix/pixmap.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / dix / pixmap.c
1 /* $XConsortium: pixmap.c /main/4 1996/08/12 22:04:49 dpw $ */
2 /* $XFree86: xc/programs/Xserver/dix/pixmap.c,v 3.1 1996/12/23 06:29:47 dawes Exp $ */
3 /*
4
5 Copyright (c) 1993  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
30
31 */
32
33 #include "X.h"
34 #include "scrnintstr.h"
35 #include "misc.h"
36 #include "os.h"
37 #include "windowstr.h"
38 #include "resource.h"
39 #include "dixstruct.h"
40 #include "gcstruct.h"
41 #include "servermd.h"
42 #include "site.h"
43
44
45 /*
46  *  Scratch pixmap management and device independent pixmap allocation
47  *  function.
48  */
49
50
51 /* callable by ddx */
52 PixmapPtr
53 GetScratchPixmapHeader(pScreen, width, height, depth, bitsPerPixel, devKind,
54                        pPixData)
55     ScreenPtr   pScreen;
56     int         width;
57     int         height;
58     int         depth;
59     int         bitsPerPixel;
60     int         devKind;
61     pointer     pPixData;
62 {
63     PixmapPtr pPixmap = pScreen->pScratchPixmap;
64
65     if (pPixmap)
66         pScreen->pScratchPixmap = NULL;
67     else
68         /* width and height of 0 means don't allocate any pixmap data */
69         pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth);
70
71     if (pPixmap)
72         if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
73                                            bitsPerPixel, devKind, pPixData))
74             return pPixmap;
75     return NullPixmap;
76 }
77
78
79 /* callable by ddx */
80 void
81 FreeScratchPixmapHeader(pPixmap)
82     PixmapPtr pPixmap;
83 {
84     if (pPixmap)
85     {
86         ScreenPtr pScreen = pPixmap->drawable.pScreen;
87
88         pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
89         if (pScreen->pScratchPixmap)
90             (*pScreen->DestroyPixmap)(pPixmap);
91         else
92             pScreen->pScratchPixmap = pPixmap;
93     }
94 }
95
96
97 Bool
98 CreateScratchPixmapsForScreen(scrnum)
99     int scrnum;
100 {
101     /* let it be created on first use */
102     screenInfo.screens[scrnum]->pScratchPixmap = NULL;
103     return TRUE;
104 }
105
106
107 void
108 FreeScratchPixmapsForScreen(scrnum)
109     int scrnum;
110 {
111     FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
112 }
113
114
115 /* callable by ddx */
116 PixmapPtr
117 AllocatePixmap(pScreen, pixDataSize)
118     ScreenPtr pScreen;
119     int pixDataSize;
120 {
121     PixmapPtr pPixmap;
122 #ifdef PIXPRIV
123     char *ptr;
124     DevUnion *ppriv;
125     unsigned *sizes;
126     unsigned size;
127     int i;
128
129     pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize);
130     if (!pPixmap)
131         return NullPixmap;
132     ppriv = (DevUnion *)(pPixmap + 1);
133     pPixmap->devPrivates = ppriv;
134     sizes = pScreen->PixmapPrivateSizes;
135     ptr = (char *)(ppriv + pScreen->PixmapPrivateLen);
136     for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++)
137     {
138         if ((size = *sizes) != 0)
139         {
140             ppriv->ptr = (pointer)ptr;
141             ptr += size;
142         }
143         else
144             ppriv->ptr = (pointer)NULL;
145     }
146 #else
147     pPixmap = (PixmapPtr)xalloc(sizeof(PixmapRec) + pixDataSize);
148 #endif
149     return pPixmap;
150 }