First import
[xorg_rtime.git] / xorg-server-1.4 / dix / pixmap.c
blobc280a3b94cc8b630bc1b39dfb9693d8d59e9749c
1 /*
3 Copyright 1993, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
25 from The Open Group.
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
31 #endif
33 #include <X11/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"
46 * Scratch pixmap management and device independent pixmap allocation
47 * function.
51 /* callable by ddx */
52 _X_EXPORT PixmapPtr
53 GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth,
54 int bitsPerPixel, int devKind, pointer pPixData)
56 PixmapPtr pPixmap = pScreen->pScratchPixmap;
58 if (pPixmap)
59 pScreen->pScratchPixmap = NULL;
60 else
61 /* width and height of 0 means don't allocate any pixmap data */
62 pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth);
64 if (pPixmap) {
65 if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
66 bitsPerPixel, devKind, pPixData))
67 return pPixmap;
68 (*pScreen->DestroyPixmap)(pPixmap);
70 return NullPixmap;
74 /* callable by ddx */
75 _X_EXPORT void
76 FreeScratchPixmapHeader(PixmapPtr pPixmap)
78 if (pPixmap)
80 ScreenPtr pScreen = pPixmap->drawable.pScreen;
82 pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
83 if (pScreen->pScratchPixmap)
84 (*pScreen->DestroyPixmap)(pPixmap);
85 else
86 pScreen->pScratchPixmap = pPixmap;
91 Bool
92 CreateScratchPixmapsForScreen(int scrnum)
94 /* let it be created on first use */
95 screenInfo.screens[scrnum]->pScratchPixmap = NULL;
96 return TRUE;
100 void
101 FreeScratchPixmapsForScreen(int scrnum)
103 FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
107 /* callable by ddx */
108 _X_EXPORT PixmapPtr
109 AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
111 PixmapPtr pPixmap;
112 char *ptr;
113 DevUnion *ppriv;
114 unsigned *sizes;
115 unsigned size;
116 int i;
118 if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
119 return NullPixmap;
121 pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize);
122 if (!pPixmap)
123 return NullPixmap;
124 ppriv = (DevUnion *)(pPixmap + 1);
125 pPixmap->devPrivates = ppriv;
126 sizes = pScreen->PixmapPrivateSizes;
127 ptr = (char *)(ppriv + pScreen->PixmapPrivateLen);
128 for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++)
130 if ((size = *sizes) != 0)
132 ppriv->ptr = (pointer)ptr;
133 ptr += size;
135 else
136 ppriv->ptr = (pointer)NULL;
139 #ifdef _XSERVER64
140 if (pPixmap) {
141 pPixmap->drawable.pad0 = 0;
142 pPixmap->drawable.pad1 = 0;
144 #endif
146 return pPixmap;