xserver-multidpi/dix/privates.c

395 lines
8.6 KiB
C
Raw Normal View History

2003-11-14 16:54:54 +01:00
/* $Xorg: privates.c,v 1.4 2001/02/09 02:04:40 xorgcvs Exp $ */
/* $XdotOrg: xc/programs/Xserver/dix/privates.c,v 1.6 2005/05/22 01:12:49 alanc Exp $ */
2003-11-14 16:54:54 +01:00
/*
Copyright 1993, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from The Open Group.
*/
2004-04-23 21:54:30 +02:00
/* $XFree86: xc/programs/Xserver/dix/privates.c,v 3.7 2001/01/17 22:36:44 dawes Exp $ */
2003-11-14 16:54:54 +01:00
#include <X11/X.h>
2003-11-14 16:54:54 +01:00
#include "scrnintstr.h"
#include <X11/misc.h>
#include <X11/os.h>
2003-11-14 16:54:54 +01:00
#include "windowstr.h"
#include "resource.h"
#include "dixstruct.h"
#include "gcstruct.h"
#include "colormapst.h"
#include "servermd.h"
#include "site.h"
#include "inputstr.h"
2003-11-14 16:54:54 +01:00
/*
* See the Wrappers and devPrivates section in "Definition of the
* Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
* for information on how to use devPrivates.
*/
/*
* client private machinery
*/
static int clientPrivateCount;
int clientPrivateLen;
unsigned *clientPrivateSizes;
unsigned totalClientSize;
void
ResetClientPrivates()
{
clientPrivateCount = 0;
clientPrivateLen = 0;
xfree(clientPrivateSizes);
clientPrivateSizes = (unsigned *)NULL;
2003-11-14 17:49:22 +01:00
totalClientSize =
((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
2003-11-14 16:54:54 +01:00
}
int
AllocateClientPrivateIndex()
{
return clientPrivateCount++;
}
Bool
AllocateClientPrivate(int index2, unsigned amount)
2003-11-14 16:54:54 +01:00
{
unsigned oldamount;
2003-11-14 17:49:22 +01:00
/* Round up sizes for proper alignment */
amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
if (index2 >= clientPrivateLen)
2003-11-14 16:54:54 +01:00
{
unsigned *nsizes;
nsizes = (unsigned *)xrealloc(clientPrivateSizes,
2003-11-14 17:49:22 +01:00
(index2 + 1) * sizeof(unsigned));
2003-11-14 16:54:54 +01:00
if (!nsizes)
return FALSE;
2003-11-14 17:49:22 +01:00
while (clientPrivateLen <= index2)
2003-11-14 16:54:54 +01:00
{
nsizes[clientPrivateLen++] = 0;
totalClientSize += sizeof(DevUnion);
}
clientPrivateSizes = nsizes;
}
2003-11-14 17:49:22 +01:00
oldamount = clientPrivateSizes[index2];
2003-11-14 16:54:54 +01:00
if (amount > oldamount)
{
2003-11-14 17:49:22 +01:00
clientPrivateSizes[index2] = amount;
2003-11-14 16:54:54 +01:00
totalClientSize += (amount - oldamount);
}
return TRUE;
}
/*
* screen private machinery
*/
int screenPrivateCount;
void
ResetScreenPrivates()
{
screenPrivateCount = 0;
}
/* this can be called after some screens have been created,
* so we have to worry about resizing existing devPrivates
*/
int
AllocateScreenPrivateIndex()
{
2003-11-14 17:49:22 +01:00
int idx;
2003-11-14 16:54:54 +01:00
int i;
ScreenPtr pScreen;
DevUnion *nprivs;
2003-11-14 17:49:22 +01:00
idx = screenPrivateCount++;
2003-11-14 16:54:54 +01:00
for (i = 0; i < screenInfo.numScreens; i++)
{
pScreen = screenInfo.screens[i];
nprivs = (DevUnion *)xrealloc(pScreen->devPrivates,
screenPrivateCount * sizeof(DevUnion));
if (!nprivs)
{
screenPrivateCount--;
return -1;
}
2003-11-14 17:49:22 +01:00
/* Zero the new private */
bzero(&nprivs[idx], sizeof(DevUnion));
2003-11-14 16:54:54 +01:00
pScreen->devPrivates = nprivs;
}
2003-11-14 17:49:22 +01:00
return idx;
2003-11-14 16:54:54 +01:00
}
/*
* window private machinery
*/
static int windowPrivateCount;
void
ResetWindowPrivates()
{
windowPrivateCount = 0;
}
int
AllocateWindowPrivateIndex()
{
return windowPrivateCount++;
}
Bool
AllocateWindowPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
2003-11-14 16:54:54 +01:00
{
unsigned oldamount;
2003-11-14 17:49:22 +01:00
/* Round up sizes for proper alignment */
amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
if (index2 >= pScreen->WindowPrivateLen)
2003-11-14 16:54:54 +01:00
{
unsigned *nsizes;
nsizes = (unsigned *)xrealloc(pScreen->WindowPrivateSizes,
2003-11-14 17:49:22 +01:00
(index2 + 1) * sizeof(unsigned));
2003-11-14 16:54:54 +01:00
if (!nsizes)
return FALSE;
2003-11-14 17:49:22 +01:00
while (pScreen->WindowPrivateLen <= index2)
2003-11-14 16:54:54 +01:00
{
nsizes[pScreen->WindowPrivateLen++] = 0;
pScreen->totalWindowSize += sizeof(DevUnion);
}
pScreen->WindowPrivateSizes = nsizes;
}
2003-11-14 17:49:22 +01:00
oldamount = pScreen->WindowPrivateSizes[index2];
2003-11-14 16:54:54 +01:00
if (amount > oldamount)
{
2003-11-14 17:49:22 +01:00
pScreen->WindowPrivateSizes[index2] = amount;
2003-11-14 16:54:54 +01:00
pScreen->totalWindowSize += (amount - oldamount);
}
return TRUE;
}
/*
* gc private machinery
*/
static int gcPrivateCount;
void
ResetGCPrivates()
{
gcPrivateCount = 0;
}
int
AllocateGCPrivateIndex()
{
return gcPrivateCount++;
}
Bool
AllocateGCPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
2003-11-14 16:54:54 +01:00
{
unsigned oldamount;
2003-11-14 17:49:22 +01:00
/* Round up sizes for proper alignment */
amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
if (index2 >= pScreen->GCPrivateLen)
2003-11-14 16:54:54 +01:00
{
unsigned *nsizes;
nsizes = (unsigned *)xrealloc(pScreen->GCPrivateSizes,
2003-11-14 17:49:22 +01:00
(index2 + 1) * sizeof(unsigned));
2003-11-14 16:54:54 +01:00
if (!nsizes)
return FALSE;
2003-11-14 17:49:22 +01:00
while (pScreen->GCPrivateLen <= index2)
2003-11-14 16:54:54 +01:00
{
nsizes[pScreen->GCPrivateLen++] = 0;
pScreen->totalGCSize += sizeof(DevUnion);
}
pScreen->GCPrivateSizes = nsizes;
}
2003-11-14 17:49:22 +01:00
oldamount = pScreen->GCPrivateSizes[index2];
2003-11-14 16:54:54 +01:00
if (amount > oldamount)
{
2003-11-14 17:49:22 +01:00
pScreen->GCPrivateSizes[index2] = amount;
2003-11-14 16:54:54 +01:00
pScreen->totalGCSize += (amount - oldamount);
}
return TRUE;
}
/*
* pixmap private machinery
*/
#ifdef PIXPRIV
static int pixmapPrivateCount;
void
ResetPixmapPrivates()
{
pixmapPrivateCount = 0;
}
int
AllocatePixmapPrivateIndex()
{
return pixmapPrivateCount++;
}
Bool
AllocatePixmapPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
2003-11-14 16:54:54 +01:00
{
unsigned oldamount;
2003-11-14 17:49:22 +01:00
/* Round up sizes for proper alignment */
amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
if (index2 >= pScreen->PixmapPrivateLen)
2003-11-14 16:54:54 +01:00
{
unsigned *nsizes;
nsizes = (unsigned *)xrealloc(pScreen->PixmapPrivateSizes,
2003-11-14 17:49:22 +01:00
(index2 + 1) * sizeof(unsigned));
2003-11-14 16:54:54 +01:00
if (!nsizes)
return FALSE;
2003-11-14 17:49:22 +01:00
while (pScreen->PixmapPrivateLen <= index2)
2003-11-14 16:54:54 +01:00
{
nsizes[pScreen->PixmapPrivateLen++] = 0;
pScreen->totalPixmapSize += sizeof(DevUnion);
}
pScreen->PixmapPrivateSizes = nsizes;
}
2003-11-14 17:49:22 +01:00
oldamount = pScreen->PixmapPrivateSizes[index2];
2003-11-14 16:54:54 +01:00
if (amount > oldamount)
{
2003-11-14 17:49:22 +01:00
pScreen->PixmapPrivateSizes[index2] = amount;
2003-11-14 16:54:54 +01:00
pScreen->totalPixmapSize += (amount - oldamount);
}
2003-11-14 17:49:22 +01:00
pScreen->totalPixmapSize = BitmapBytePad(pScreen->totalPixmapSize * 8);
2003-11-14 16:54:54 +01:00
return TRUE;
}
#endif
/*
* colormap private machinery
*/
int colormapPrivateCount;
void
ResetColormapPrivates()
{
colormapPrivateCount = 0;
}
int
AllocateColormapPrivateIndex (InitCmapPrivFunc initPrivFunc)
2003-11-14 16:54:54 +01:00
{
int index;
int i;
ColormapPtr pColormap;
DevUnion *privs;
index = colormapPrivateCount++;
for (i = 0; i < screenInfo.numScreens; i++)
{
/*
* AllocateColormapPrivateIndex may be called after the
* default colormap has been created on each screen!
*
* We must resize the devPrivates array for the default
* colormap on each screen, making room for this new private.
* We also call the initialization function 'initPrivFunc' on
* the new private allocated for each default colormap.
*/
ScreenPtr pScreen = screenInfo.screens[i];
pColormap = (ColormapPtr) LookupIDByType (
pScreen->defColormap, RT_COLORMAP);
2003-11-14 17:49:22 +01:00
if (pColormap)
2003-11-14 16:54:54 +01:00
{
2003-11-14 17:49:22 +01:00
privs = (DevUnion *) xrealloc (pColormap->devPrivates,
colormapPrivateCount * sizeof(DevUnion));
pColormap->devPrivates = privs;
if (!privs || !(*initPrivFunc)(pColormap,index))
2003-11-14 17:49:22 +01:00
{
colormapPrivateCount--;
return -1;
}
2003-11-14 16:54:54 +01:00
}
}
return index;
}
/*
* device private machinery
*/
static int devicePrivateIndex = 0;
int
AllocateDevicePrivateIndex()
{
return devicePrivateIndex++;
}
Bool
AllocateDevicePrivate(DeviceIntPtr device, int index)
{
if (device->nPrivates < ++index) {
DevUnion *nprivs = (DevUnion *) xrealloc(device->devPrivates,
index * sizeof(DevUnion));
if (!nprivs)
return FALSE;
device->devPrivates = nprivs;
bzero(&nprivs[device->nPrivates], sizeof(DevUnion)
* (index - device->nPrivates));
device->nPrivates = index;
return TRUE;
} else {
return TRUE;
}
}
void
ResetDevicePrivateIndex(void)
{
devicePrivateIndex = 0;
}