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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-07-03 09:02:09 +02:00
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2005-04-20 14:25:48 +02:00
|
|
|
#include <X11/X.h>
|
2007-03-01 21:00:02 +01:00
|
|
|
#include <stddef.h>
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "scrnintstr.h"
|
2005-07-03 10:53:54 +02:00
|
|
|
#include "misc.h"
|
|
|
|
#include "os.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "windowstr.h"
|
|
|
|
#include "resource.h"
|
2007-02-23 19:20:43 +01:00
|
|
|
#include "privates.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "gcstruct.h"
|
|
|
|
#include "colormapst.h"
|
|
|
|
#include "servermd.h"
|
|
|
|
#include "site.h"
|
2005-05-22 03:12:49 +02:00
|
|
|
#include "inputstr.h"
|
2006-08-01 01:35:08 +02:00
|
|
|
#include "extnsionst.h"
|
2003-11-14 16:54:54 +01:00
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
typedef struct _PrivateDesc {
|
|
|
|
devprivate_key_t *key;
|
2007-02-23 19:20:43 +01:00
|
|
|
unsigned size;
|
|
|
|
CallbackListPtr initfuncs;
|
|
|
|
CallbackListPtr deletefuncs;
|
2007-03-01 21:00:02 +01:00
|
|
|
struct _PrivateDesc *next;
|
|
|
|
} PrivateDescRec;
|
2007-02-23 19:20:43 +01:00
|
|
|
|
|
|
|
/* list of all allocated privates */
|
2007-03-01 21:00:02 +01:00
|
|
|
static PrivateDescRec *items = NULL;
|
|
|
|
|
|
|
|
static _X_INLINE PrivateDescRec *
|
|
|
|
findItem(devprivate_key_t *const key)
|
|
|
|
{
|
|
|
|
PrivateDescRec *item = items;
|
|
|
|
while (item) {
|
|
|
|
if (item->key == key)
|
|
|
|
return item;
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-08 18:13:18 +01:00
|
|
|
* Request pre-allocated space.
|
2007-02-23 19:20:43 +01:00
|
|
|
*/
|
|
|
|
_X_EXPORT int
|
2007-03-08 18:13:18 +01:00
|
|
|
dixRequestPrivate(devprivate_key_t *const key, unsigned size)
|
2007-02-23 19:20:43 +01:00
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
PrivateDescRec *item = findItem(key);
|
|
|
|
if (item) {
|
|
|
|
if (size > item->size)
|
|
|
|
item->size = size;
|
|
|
|
} else {
|
|
|
|
item = (PrivateDescRec *)xalloc(sizeof(PrivateDescRec));
|
|
|
|
if (!item)
|
|
|
|
return FALSE;
|
|
|
|
memset(item, 0, sizeof(PrivateDescRec));
|
|
|
|
|
|
|
|
/* add privates descriptor */
|
|
|
|
item->key = key;
|
|
|
|
item->size = size;
|
|
|
|
item->next = items;
|
|
|
|
items = item;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-02-23 19:20:43 +01:00
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
/*
|
|
|
|
* Allocate a private and attach it to an existing object.
|
|
|
|
*/
|
|
|
|
_X_EXPORT pointer *
|
|
|
|
dixAllocatePrivate(PrivateRec **privates, devprivate_key_t *const key)
|
|
|
|
{
|
|
|
|
PrivateDescRec *item = findItem(key);
|
|
|
|
PrivateRec *ptr;
|
|
|
|
unsigned size = sizeof(PrivateRec);
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
size += item->size;
|
2007-02-23 19:20:43 +01:00
|
|
|
|
2007-04-03 20:06:02 +02:00
|
|
|
ptr = (PrivateRec *)xcalloc(size, 1);
|
2007-03-01 21:00:02 +01:00
|
|
|
if (!ptr)
|
|
|
|
return NULL;
|
|
|
|
ptr->key = key;
|
|
|
|
ptr->value = (size > sizeof(PrivateRec)) ? (ptr + 1) : NULL;
|
|
|
|
ptr->next = *privates;
|
|
|
|
*privates = ptr;
|
2007-02-23 19:20:43 +01:00
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
/* call any init funcs and return */
|
|
|
|
if (item) {
|
2007-03-08 18:14:30 +01:00
|
|
|
PrivateCallbackRec calldata = { key, &ptr->value };
|
2007-03-01 21:00:02 +01:00
|
|
|
CallCallbacks(&item->initfuncs, &calldata);
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
2007-03-01 21:00:02 +01:00
|
|
|
return &ptr->value;
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-01 21:00:02 +01:00
|
|
|
* Called to free privates at object deletion time.
|
2007-02-23 19:20:43 +01:00
|
|
|
*/
|
2007-03-01 21:00:02 +01:00
|
|
|
_X_EXPORT void
|
|
|
|
dixFreePrivates(PrivateRec *privates)
|
2007-02-23 19:20:43 +01:00
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
PrivateRec *ptr, *next;
|
|
|
|
PrivateDescRec *item;
|
2007-02-23 19:20:43 +01:00
|
|
|
PrivateCallbackRec calldata;
|
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
/* first pass calls the delete callbacks */
|
|
|
|
for (ptr = privates; ptr; ptr = ptr->next) {
|
|
|
|
item = findItem(ptr->key);
|
|
|
|
if (item) {
|
|
|
|
calldata.key = ptr->key;
|
2007-03-08 18:14:30 +01:00
|
|
|
calldata.value = &ptr->value;
|
2007-03-01 21:00:02 +01:00
|
|
|
CallCallbacks(&item->deletefuncs, &calldata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* second pass frees the memory */
|
|
|
|
ptr = privates;
|
2007-02-23 19:20:43 +01:00
|
|
|
while (ptr) {
|
2007-03-08 18:13:18 +01:00
|
|
|
next = ptr->next;
|
|
|
|
xfree(ptr);
|
|
|
|
ptr = next;
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback registration
|
|
|
|
*/
|
|
|
|
_X_EXPORT int
|
2007-03-01 21:00:02 +01:00
|
|
|
dixRegisterPrivateInitFunc(devprivate_key_t *const key,
|
2007-02-23 19:20:43 +01:00
|
|
|
CallbackProcPtr callback, pointer data)
|
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
PrivateDescRec *item = findItem(key);
|
2007-03-08 18:13:18 +01:00
|
|
|
if (!item) {
|
|
|
|
if (!dixRequestPrivate(key, 0))
|
|
|
|
return FALSE;
|
|
|
|
item = findItem(key);
|
|
|
|
}
|
2007-03-01 21:00:02 +01:00
|
|
|
return AddCallback(&item->initfuncs, callback, data);
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_X_EXPORT int
|
2007-03-01 21:00:02 +01:00
|
|
|
dixRegisterPrivateDeleteFunc(devprivate_key_t *const key,
|
2007-02-23 19:20:43 +01:00
|
|
|
CallbackProcPtr callback, pointer data)
|
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
PrivateDescRec *item = findItem(key);
|
2007-03-08 18:13:18 +01:00
|
|
|
if (!item) {
|
|
|
|
if (!dixRequestPrivate(key, 0))
|
|
|
|
return FALSE;
|
|
|
|
item = findItem(key);
|
|
|
|
}
|
2007-03-01 21:00:02 +01:00
|
|
|
return AddCallback(&item->deletefuncs, callback, data);
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
/* Table of devPrivates offsets */
|
|
|
|
static unsigned *offsets = NULL;
|
|
|
|
static unsigned offsetsSize = 0;
|
2007-02-23 19:20:43 +01:00
|
|
|
|
|
|
|
/*
|
2007-03-01 21:00:02 +01:00
|
|
|
* Specify where the devPrivates field is located in a structure type
|
2007-02-23 19:20:43 +01:00
|
|
|
*/
|
2007-03-01 21:00:02 +01:00
|
|
|
_X_EXPORT int
|
|
|
|
dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
|
2007-02-23 19:20:43 +01:00
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
type = type & TypeMask;
|
|
|
|
|
|
|
|
/* resize offsets table if necessary */
|
|
|
|
while (type >= offsetsSize) {
|
2007-03-08 18:13:36 +01:00
|
|
|
unsigned i = offsetsSize * 2 * sizeof(int);
|
|
|
|
offsets = (unsigned *)xrealloc(offsets, i);
|
2007-03-01 21:00:02 +01:00
|
|
|
if (!offsets) {
|
|
|
|
offsetsSize = 0;
|
2007-02-23 19:20:43 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2007-03-08 18:13:36 +01:00
|
|
|
for (i=offsetsSize; i < 2*offsetsSize; i++)
|
|
|
|
offsets[i] = -1;
|
2007-03-01 21:00:02 +01:00
|
|
|
offsetsSize *= 2;
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
2007-03-01 21:00:02 +01:00
|
|
|
|
|
|
|
offsets[type] = offset;
|
2007-02-23 19:20:43 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-08 18:13:36 +01:00
|
|
|
_X_EXPORT int
|
2007-03-01 21:00:02 +01:00
|
|
|
dixLookupPrivateOffset(RESTYPE type)
|
2007-02-23 19:20:43 +01:00
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
type = type & TypeMask;
|
|
|
|
assert(type < offsetsSize);
|
|
|
|
return offsets[type];
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
2007-03-01 21:00:02 +01:00
|
|
|
|
2007-02-23 19:20:43 +01:00
|
|
|
/*
|
2007-03-01 21:00:02 +01:00
|
|
|
* Called from the main loop to reset the subsystem.
|
2007-02-23 19:20:43 +01:00
|
|
|
*/
|
2007-03-07 17:22:42 +01:00
|
|
|
static int ResetExtensionPrivates(void);
|
|
|
|
static int ResetClientPrivates(void);
|
2007-03-07 15:57:02 +01:00
|
|
|
static void ResetScreenPrivates(void);
|
|
|
|
static void ResetWindowPrivates(void);
|
|
|
|
static void ResetGCPrivates(void);
|
|
|
|
static void ResetPixmapPrivates(void);
|
|
|
|
static void ResetColormapPrivates(void);
|
|
|
|
static void ResetDevicePrivateIndex(void);
|
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
int
|
|
|
|
dixResetPrivates(void)
|
2007-02-23 19:20:43 +01:00
|
|
|
{
|
2007-03-01 21:00:02 +01:00
|
|
|
PrivateDescRec *next;
|
2007-03-08 18:13:36 +01:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
/* reset internal structures */
|
2007-03-01 21:00:02 +01:00
|
|
|
while (items) {
|
|
|
|
next = items->next;
|
|
|
|
xfree(items);
|
|
|
|
items = next;
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
2007-03-01 21:00:02 +01:00
|
|
|
if (offsets)
|
|
|
|
xfree(offsets);
|
|
|
|
offsetsSize = 16;
|
|
|
|
offsets = (unsigned *)xalloc(offsetsSize * sizeof(unsigned));
|
|
|
|
if (!offsets)
|
|
|
|
return FALSE;
|
2007-03-08 18:13:36 +01:00
|
|
|
for (i=0; i < offsetsSize; i++)
|
|
|
|
offsets[i] = -1;
|
2007-02-23 19:20:43 +01:00
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
/* reset legacy devPrivates support */
|
2007-03-07 17:22:42 +01:00
|
|
|
if (!ResetExtensionPrivates() || !ResetClientPrivates())
|
|
|
|
return FALSE;
|
2007-03-07 15:57:02 +01:00
|
|
|
ResetScreenPrivates();
|
|
|
|
ResetWindowPrivates();
|
|
|
|
ResetGCPrivates();
|
|
|
|
ResetPixmapPrivates();
|
|
|
|
ResetColormapPrivates();
|
|
|
|
ResetDevicePrivateIndex();
|
|
|
|
|
2007-03-01 21:00:02 +01:00
|
|
|
/* register basic resource offsets */
|
2007-03-07 17:22:42 +01:00
|
|
|
return dixRegisterPrivateOffset(RT_WINDOW,
|
|
|
|
offsetof(WindowRec, devPrivates)) &&
|
|
|
|
dixRegisterPrivateOffset(RT_PIXMAP,
|
|
|
|
offsetof(PixmapRec, devPrivates)) &&
|
|
|
|
dixRegisterPrivateOffset(RT_GC,
|
|
|
|
offsetof(GC, devPrivates)) &&
|
|
|
|
dixRegisterPrivateOffset(RT_COLORMAP,
|
|
|
|
offsetof(ColormapRec, devPrivates));
|
2007-02-23 19:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Following is the old devPrivates support. These functions and variables
|
|
|
|
* are deprecated, and should no longer be used.
|
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2006-08-01 01:35:08 +02:00
|
|
|
/*
|
|
|
|
* extension private machinery
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int extensionPrivateCount;
|
|
|
|
int extensionPrivateLen;
|
|
|
|
unsigned *extensionPrivateSizes;
|
|
|
|
unsigned totalExtensionSize;
|
|
|
|
|
2007-03-07 17:22:42 +01:00
|
|
|
static int
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetExtensionPrivates(void)
|
2006-08-01 01:35:08 +02:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
extensionPrivateCount = 1;
|
|
|
|
extensionPrivateLen = 1;
|
2006-08-01 01:35:08 +02:00
|
|
|
xfree(extensionPrivateSizes);
|
2007-04-05 18:12:58 +02:00
|
|
|
extensionPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
|
2007-03-07 17:22:42 +01:00
|
|
|
if (!extensionPrivateSizes)
|
|
|
|
return FALSE;
|
|
|
|
totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
|
|
|
|
return TRUE;
|
2006-08-01 01:35:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocateExtensionPrivateIndex(void)
|
2006-08-01 01:35:08 +02:00
|
|
|
{
|
|
|
|
return extensionPrivateCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
_X_EXPORT Bool
|
|
|
|
AllocateExtensionPrivate(int index2, unsigned amount)
|
|
|
|
{
|
|
|
|
unsigned oldamount;
|
|
|
|
|
|
|
|
/* Round up sizes for proper alignment */
|
|
|
|
amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
|
|
|
|
|
|
|
|
if (index2 >= extensionPrivateLen)
|
|
|
|
{
|
|
|
|
unsigned *nsizes;
|
|
|
|
nsizes = (unsigned *)xrealloc(extensionPrivateSizes,
|
|
|
|
(index2 + 1) * sizeof(unsigned));
|
|
|
|
if (!nsizes)
|
|
|
|
return FALSE;
|
|
|
|
while (extensionPrivateLen <= index2)
|
|
|
|
{
|
|
|
|
nsizes[extensionPrivateLen++] = 0;
|
|
|
|
totalExtensionSize += sizeof(DevUnion);
|
|
|
|
}
|
|
|
|
extensionPrivateSizes = nsizes;
|
|
|
|
}
|
|
|
|
oldamount = extensionPrivateSizes[index2];
|
|
|
|
if (amount > oldamount)
|
|
|
|
{
|
|
|
|
extensionPrivateSizes[index2] = amount;
|
|
|
|
totalExtensionSize += (amount - oldamount);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-11-14 16:54:54 +01:00
|
|
|
/*
|
|
|
|
* client private machinery
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int clientPrivateCount;
|
|
|
|
int clientPrivateLen;
|
|
|
|
unsigned *clientPrivateSizes;
|
|
|
|
unsigned totalClientSize;
|
|
|
|
|
2007-03-07 17:22:42 +01:00
|
|
|
static int
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetClientPrivates(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
clientPrivateCount = 1;
|
|
|
|
clientPrivateLen = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
xfree(clientPrivateSizes);
|
2007-04-05 18:12:58 +02:00
|
|
|
clientPrivateSizes = (unsigned *)xcalloc(1, sizeof(unsigned));
|
2007-03-07 17:22:42 +01:00
|
|
|
if (!clientPrivateSizes)
|
|
|
|
return FALSE;
|
|
|
|
totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
|
|
|
|
return TRUE;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocateClientPrivateIndex(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
return clientPrivateCount++;
|
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT Bool
|
2005-03-08 00:02:59 +01:00
|
|
|
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;
|
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
static void
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetScreenPrivates(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
screenPrivateCount = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this can be called after some screens have been created,
|
|
|
|
* so we have to worry about resizing existing devPrivates
|
|
|
|
*/
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocateScreenPrivateIndex(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
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;
|
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
static void
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetWindowPrivates(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
windowPrivateCount = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocateWindowPrivateIndex(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
return windowPrivateCount++;
|
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT Bool
|
2007-03-08 08:20:19 +01:00
|
|
|
AllocateWindowPrivate(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;
|
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
static void
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetGCPrivates(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
gcPrivateCount = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocateGCPrivateIndex(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
return gcPrivateCount++;
|
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT Bool
|
2007-03-08 08:20:19 +01:00
|
|
|
AllocateGCPrivate(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
|
|
|
|
*/
|
|
|
|
static int pixmapPrivateCount;
|
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
static void
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetPixmapPrivates(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
pixmapPrivateCount = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocatePixmapPrivateIndex(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
|
|
|
return pixmapPrivateCount++;
|
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT Bool
|
2007-03-08 08:20:19 +01:00
|
|
|
AllocatePixmapPrivate(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* colormap private machinery
|
|
|
|
*/
|
|
|
|
|
|
|
|
int colormapPrivateCount;
|
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
static void
|
2007-04-09 23:33:15 +02:00
|
|
|
ResetColormapPrivates(void)
|
2003-11-14 16:54:54 +01:00
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
colormapPrivateCount = 1;
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2005-03-08 00:02:59 +01:00
|
|
|
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));
|
2005-09-05 09:40:50 +02:00
|
|
|
if (!privs) {
|
|
|
|
colormapPrivateCount--;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bzero(&privs[index], sizeof(DevUnion));
|
2003-11-14 17:49:22 +01:00
|
|
|
pColormap->devPrivates = privs;
|
2005-09-05 09:40:50 +02:00
|
|
|
if (!(*initPrivFunc)(pColormap,index))
|
2003-11-14 17:49:22 +01:00
|
|
|
{
|
|
|
|
colormapPrivateCount--;
|
|
|
|
return -1;
|
|
|
|
}
|
2003-11-14 16:54:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
2005-05-22 03:12:49 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* device private machinery
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int devicePrivateIndex = 0;
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT int
|
2007-04-09 23:33:15 +02:00
|
|
|
AllocateDevicePrivateIndex(void)
|
2005-05-22 03:12:49 +02:00
|
|
|
{
|
|
|
|
return devicePrivateIndex++;
|
|
|
|
}
|
|
|
|
|
2006-02-15 21:44:13 +01:00
|
|
|
_X_EXPORT Bool
|
2005-05-22 03:12:49 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 15:57:02 +01:00
|
|
|
static void
|
2005-05-22 03:12:49 +02:00
|
|
|
ResetDevicePrivateIndex(void)
|
|
|
|
{
|
2007-03-07 17:22:42 +01:00
|
|
|
devicePrivateIndex = 1;
|
2005-05-22 03:12:49 +02:00
|
|
|
}
|