~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to dix/pixmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

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