pixmap.c revision 05b261ec
105b261ecSmrg/*
205b261ecSmrg
305b261ecSmrgCopyright 1993, 1998  The Open Group
405b261ecSmrg
505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its
605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that
705b261ecSmrgthe above copyright notice appear in all copies and that both that
805b261ecSmrgcopyright notice and this permission notice appear in supporting
905b261ecSmrgdocumentation.
1005b261ecSmrg
1105b261ecSmrgThe above copyright notice and this permission notice shall be included
1205b261ecSmrgin all copies or substantial portions of the Software.
1305b261ecSmrg
1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1505b261ecSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1605b261ecSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1705b261ecSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
1805b261ecSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1905b261ecSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2005b261ecSmrgOTHER DEALINGS IN THE SOFTWARE.
2105b261ecSmrg
2205b261ecSmrgExcept as contained in this notice, the name of The Open Group shall
2305b261ecSmrgnot be used in advertising or otherwise to promote the sale, use or
2405b261ecSmrgother dealings in this Software without prior written authorization
2505b261ecSmrgfrom The Open Group.
2605b261ecSmrg
2705b261ecSmrg*/
2805b261ecSmrg
2905b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
3005b261ecSmrg#include <dix-config.h>
3105b261ecSmrg#endif
3205b261ecSmrg
3305b261ecSmrg#include <X11/X.h>
3405b261ecSmrg#include "scrnintstr.h"
3505b261ecSmrg#include "misc.h"
3605b261ecSmrg#include "os.h"
3705b261ecSmrg#include "windowstr.h"
3805b261ecSmrg#include "resource.h"
3905b261ecSmrg#include "dixstruct.h"
4005b261ecSmrg#include "gcstruct.h"
4105b261ecSmrg#include "servermd.h"
4205b261ecSmrg#include "site.h"
4305b261ecSmrg
4405b261ecSmrg
4505b261ecSmrg/*
4605b261ecSmrg *  Scratch pixmap management and device independent pixmap allocation
4705b261ecSmrg *  function.
4805b261ecSmrg */
4905b261ecSmrg
5005b261ecSmrg
5105b261ecSmrg/* callable by ddx */
5205b261ecSmrg_X_EXPORT PixmapPtr
5305b261ecSmrgGetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth,
5405b261ecSmrg                       int bitsPerPixel, int devKind, pointer pPixData)
5505b261ecSmrg{
5605b261ecSmrg    PixmapPtr pPixmap = pScreen->pScratchPixmap;
5705b261ecSmrg
5805b261ecSmrg    if (pPixmap)
5905b261ecSmrg	pScreen->pScratchPixmap = NULL;
6005b261ecSmrg    else
6105b261ecSmrg	/* width and height of 0 means don't allocate any pixmap data */
6205b261ecSmrg	pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth);
6305b261ecSmrg
6405b261ecSmrg    if (pPixmap) {
6505b261ecSmrg	if ((*pScreen->ModifyPixmapHeader)(pPixmap, width, height, depth,
6605b261ecSmrg					   bitsPerPixel, devKind, pPixData))
6705b261ecSmrg	    return pPixmap;
6805b261ecSmrg	(*pScreen->DestroyPixmap)(pPixmap);
6905b261ecSmrg    }
7005b261ecSmrg    return NullPixmap;
7105b261ecSmrg}
7205b261ecSmrg
7305b261ecSmrg
7405b261ecSmrg/* callable by ddx */
7505b261ecSmrg_X_EXPORT void
7605b261ecSmrgFreeScratchPixmapHeader(PixmapPtr pPixmap)
7705b261ecSmrg{
7805b261ecSmrg    if (pPixmap)
7905b261ecSmrg    {
8005b261ecSmrg	ScreenPtr pScreen = pPixmap->drawable.pScreen;
8105b261ecSmrg
8205b261ecSmrg	pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
8305b261ecSmrg	if (pScreen->pScratchPixmap)
8405b261ecSmrg	    (*pScreen->DestroyPixmap)(pPixmap);
8505b261ecSmrg	else
8605b261ecSmrg	    pScreen->pScratchPixmap = pPixmap;
8705b261ecSmrg    }
8805b261ecSmrg}
8905b261ecSmrg
9005b261ecSmrg
9105b261ecSmrgBool
9205b261ecSmrgCreateScratchPixmapsForScreen(int scrnum)
9305b261ecSmrg{
9405b261ecSmrg    /* let it be created on first use */
9505b261ecSmrg    screenInfo.screens[scrnum]->pScratchPixmap = NULL;
9605b261ecSmrg    return TRUE;
9705b261ecSmrg}
9805b261ecSmrg
9905b261ecSmrg
10005b261ecSmrgvoid
10105b261ecSmrgFreeScratchPixmapsForScreen(int scrnum)
10205b261ecSmrg{
10305b261ecSmrg    FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
10405b261ecSmrg}
10505b261ecSmrg
10605b261ecSmrg
10705b261ecSmrg/* callable by ddx */
10805b261ecSmrg_X_EXPORT PixmapPtr
10905b261ecSmrgAllocatePixmap(ScreenPtr pScreen, int pixDataSize)
11005b261ecSmrg{
11105b261ecSmrg    PixmapPtr pPixmap;
11205b261ecSmrg    char *ptr;
11305b261ecSmrg    DevUnion *ppriv;
11405b261ecSmrg    unsigned *sizes;
11505b261ecSmrg    unsigned size;
11605b261ecSmrg    int i;
11705b261ecSmrg
11805b261ecSmrg    if (pScreen->totalPixmapSize > ((size_t)-1) - pixDataSize)
11905b261ecSmrg	return NullPixmap;
12005b261ecSmrg
12105b261ecSmrg    pPixmap = (PixmapPtr)xalloc(pScreen->totalPixmapSize + pixDataSize);
12205b261ecSmrg    if (!pPixmap)
12305b261ecSmrg	return NullPixmap;
12405b261ecSmrg    ppriv = (DevUnion *)(pPixmap + 1);
12505b261ecSmrg    pPixmap->devPrivates = ppriv;
12605b261ecSmrg    sizes = pScreen->PixmapPrivateSizes;
12705b261ecSmrg    ptr = (char *)(ppriv + pScreen->PixmapPrivateLen);
12805b261ecSmrg    for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++)
12905b261ecSmrg    {
13005b261ecSmrg        if ((size = *sizes) != 0)
13105b261ecSmrg        {
13205b261ecSmrg	    ppriv->ptr = (pointer)ptr;
13305b261ecSmrg	    ptr += size;
13405b261ecSmrg        }
13505b261ecSmrg        else
13605b261ecSmrg	    ppriv->ptr = (pointer)NULL;
13705b261ecSmrg    }
13805b261ecSmrg
13905b261ecSmrg#ifdef _XSERVER64
14005b261ecSmrg    if (pPixmap) {
14105b261ecSmrg	pPixmap->drawable.pad0 = 0;
14205b261ecSmrg	pPixmap->drawable.pad1 = 0;
14305b261ecSmrg    }
14405b261ecSmrg#endif
14505b261ecSmrg
14605b261ecSmrg    return pPixmap;
14705b261ecSmrg}
148