summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2010-04-26 17:22:21 -0700
committerKeith Packard <keithp@keithp.com>2010-06-05 19:23:03 -0700
commitfaeebead7bfcc78535757ca7acc1faf7554c03b7 (patch)
tree1a8f13a3b1ae968011efb9679bc3ed79a29020be /include
parentc865a24401f06bcf1347d8b41f736a066ab25693 (diff)
Change the devPrivates API to require dixRegisterPrivateKey
This patch only changes the API, not the implementation of the devPrivates infrastructure. This will permit a new devPrivates implementation to be layed into the server without requiring simultaneous changes in every devPrivates user. Signed-off-by: Keith Packard <keithp@keithp.com> Tested-by: Tiago Vignatti <tiago.vignatti@nokia.com>
Diffstat (limited to 'include')
-rw-r--r--include/cursor.h3
-rw-r--r--include/cursorstr.h4
-rw-r--r--include/pixmap.h3
-rw-r--r--include/privates.h190
-rw-r--r--include/xkbsrv.h4
5 files changed, 150 insertions, 54 deletions
diff --git a/include/cursor.h b/include/cursor.h
index dadedfd1d..59978d4ca 100644
--- a/include/cursor.h
+++ b/include/cursor.h
@@ -51,6 +51,7 @@ SOFTWARE.
#include "misc.h"
#include "screenint.h"
#include "window.h"
+#include "privates.h"
#define NullCursor ((CursorPtr)NULL)
@@ -62,7 +63,7 @@ struct _DeviceIntRec;
typedef struct _Cursor *CursorPtr;
typedef struct _CursorMetric *CursorMetricPtr;
-extern _X_EXPORT int cursorScreenDevPriv[MAXSCREENS];
+extern _X_EXPORT DevPrivateKeyRec cursorScreenDevPriv[MAXSCREENS];
#define CursorScreenKey(pScreen) (cursorScreenDevPriv + (pScreen)->myNum)
extern _X_EXPORT CursorPtr rootCursor;
diff --git a/include/cursorstr.h b/include/cursorstr.h
index 3ff56e2bf..6a4d0db52 100644
--- a/include/cursorstr.h
+++ b/include/cursorstr.h
@@ -70,6 +70,8 @@ typedef struct _CursorBits {
#endif
} CursorBits, *CursorBitsPtr;
+#define CURSOR_BITS_SIZE (sizeof(CursorBits) + dixPrivatesSize(PRIVATE_CURSOR_BITS))
+
typedef struct _Cursor {
CursorBitsPtr bits;
unsigned short foreRed, foreGreen, foreBlue; /* device-independent color */
@@ -83,6 +85,8 @@ typedef struct _Cursor {
#endif
} CursorRec;
+#define CURSOR_REC_SIZE (sizeof(CursorRec) + dixPrivatesSize(PRIVATE_CURSOR))
+
typedef struct _CursorMetric {
unsigned short width, height, xhot, yhot;
} CursorMetricRec;
diff --git a/include/pixmap.h b/include/pixmap.h
index 55a9c818a..5cf42d1fb 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -115,4 +115,7 @@ extern _X_EXPORT PixmapPtr AllocatePixmap(
ScreenPtr /*pScreen*/,
int /*pixDataSize*/);
+extern _X_EXPORT void FreePixmap(
+ PixmapPtr /*pPixmap*/);
+
#endif /* PIXMAP_H */
diff --git a/include/privates.h b/include/privates.h
index 72f4d4028..9412fd613 100644
--- a/include/privates.h
+++ b/include/privates.h
@@ -12,66 +12,109 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef PRIVATES_H
#define PRIVATES_H 1
-#include "dix.h"
-#include "resource.h"
+#include <X11/Xdefs.h>
+#include <X11/Xosdefs.h>
+#include <X11/Xfuncproto.h>
+#include "misc.h"
/*****************************************************************
* STUFF FOR PRIVATES
*****************************************************************/
-typedef int *DevPrivateKey;
-struct _Private;
-typedef struct _Private PrivateRec;
+typedef struct _Private PrivateRec, *PrivatePtr;
+
+typedef enum {
+ /* XSELinux uses the same private keys for numerous objects */
+ PRIVATE_XSELINUX,
+
+ /* Otherwise, you get a private in just the requested structure
+ */
+ /* These can have objects created before all of the keys are registered */
+ PRIVATE_SCREEN,
+ PRIVATE_EXTENSION,
+ PRIVATE_COLORMAP,
+
+ /* These cannot have any objects before all relevant keys are registered */
+ PRIVATE_DEVICE,
+ PRIVATE_CLIENT,
+ PRIVATE_PROPERTY,
+ PRIVATE_SELECTION,
+ PRIVATE_WINDOW,
+ PRIVATE_PIXMAP,
+ PRIVATE_GC,
+ PRIVATE_CURSOR,
+ PRIVATE_CURSOR_BITS,
+
+ /* extension privates */
+ PRIVATE_DBE_WINDOW,
+ PRIVATE_DAMAGE,
+ PRIVATE_GLYPH,
+ PRIVATE_GLYPHSET,
+ PRIVATE_PICTURE,
+
+ /* last private type */
+ PRIVATE_LAST,
+} DevPrivateType;
+
+typedef struct _DevPrivateKeyRec {
+ int key;
+} DevPrivateKeyRec, *DevPrivateKey;
/*
- * Request pre-allocated private space for your driver/module. This function
- * increases the amount of space allocated automatically when dixLookupPrivate
- * is called on a PrivateRec that does not yet have a value associated with
- * 'key'.
- *
- * This function will only increase the reserved size: if a size was previously
- * requested, then dixRequestPrivate causes later calls to dixLookupPrivate to
- * allocate the maximum of the old size and 'size'. Requested sizes are reset
- * to 0 by dixResetPrivates, which is called before each server generation.
- *
- * If dixRequestPrivate is not called with a nonzero size for 'key', then the
- * module responsible for 'key' must manage the associated pointer itself with
- * dixSetPrivate.
- *
- * dixRequestPrivate returns FALSE if it cannot store the requested size.
+ * Let drivers know how to initialize private keys
*/
-extern _X_EXPORT int
-dixRequestPrivate(const DevPrivateKey key, unsigned size);
+
+#define HAS_DEVPRIVATEKEYREC 1
+#define HAS_DIXREGISTERPRIVATEKEY 1
/*
- * Allocates space for an association of 'key' with a value in 'privates'.
+ * Register a new private index for the private type.
*
- * If a nonzero size was requested with dixRequestPrivate, then
- * dixAllocatePrivate also allocates the requested amount of memory and
- * associates the pointer to that memory with 'key' in 'privates'. The
- * allocated memory is initialized to zero. This memory can only be freed by
- * dixFreePrivates.
+ * This initializes the specified key and optionally requests pre-allocated
+ * private space for your driver/module. If you request no extra space, you
+ * may set and get a single pointer value using this private key. Otherwise,
+ * you can get the address of the extra space and store whatever data you like
+ * there.
*
- * If dixRequestPrivate was never called with a nonzero size, then
- * dixAllocatePrivate associates NULL with 'key' in 'privates'.
+ * You may call dixRegisterPrivate more than once on the same key, but the
+ * size and type must match or the server will abort.
*
- * dixAllocatePrivate returns a pointer to the value associated with 'key' in
- * 'privates', unless a memory allocation fails, in which case it returns NULL.
+ * dixRegisterPrivateIndex returns FALSE if it fails to allocate memory
+ * during its operation.
*/
-extern _X_EXPORT pointer *
-dixAllocatePrivate(PrivateRec **privates, const DevPrivateKey key);
+extern _X_EXPORT Bool
+dixRegisterPrivateKey(DevPrivateKey key, DevPrivateType type, unsigned size);
+
+/*
+ * Check whether a private key has been registered
+ */
+static inline Bool
+dixPrivateKeyRegistered(DevPrivateKey key)
+{
+ return key->key != 0;
+}
/*
- * Look up a private pointer.
+ * Associate 'val' with 'key' in 'privates' so that later calls to
+ * dixLookupPrivate(privates, key) will return 'val'.
*
- * If no value is currently associated with 'key' in 'privates', then
- * dixLookupPrivate calls dixAllocatePrivate and returns the resulting
- * associated value.
+ * dixSetPrivate returns FALSE if a memory allocation fails.
+ */
+extern _X_EXPORT int
+dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val);
+
+#include "dix.h"
+#include "resource.h"
+
+/*
+ * Lookup a pointer to the private record.
*
- * dixLookupPrivate returns NULL if a memory allocation fails.
+ * For privates with defined storage, return the address of the
+ * storage. For privates without defined storage, return the pointer
+ * contents
*/
extern _X_EXPORT pointer
-dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
+dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key);
/*
* Look up the address of a private pointer. If 'key' is not associated with a
@@ -82,29 +125,72 @@ dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
* 'privates' and a memory allocation fails.
*/
extern _X_EXPORT pointer *
-dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key);
+dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key);
/*
- * Associate 'val' with 'key' in 'privates' so that later calls to
- * dixLookupPrivate(privates, key) will return 'val'.
- *
- * dixSetPrivate returns FALSE if a memory allocation fails.
+ * Allocates private data separately from main object (clients and colormaps)
*/
-extern _X_EXPORT int
-dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val);
+static inline Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type) { *privates = NULL; return TRUE; }
/*
- * Unassociates all keys from 'privates' and frees all private data automatically
- * allocated via dixRequestPrivate.
+ * Frees separately allocated private data (screens and clients)
*/
extern _X_EXPORT void
-dixFreePrivates(PrivateRec *privates);
+dixFreePrivates(PrivatePtr privates, DevPrivateType type);
+
+/*
+ * Initialize privates by zeroing them
+ */
+static inline void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type) { *privates = NULL; }
+
+#define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
+
+/*
+ * Clean up privates
+ */
+static inline void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type) { dixFreePrivates(privates, type); }
+
+#define dixFiniPrivates(o,t) _dixFiniPrivates((o)->devPrivates,t)
+
+/*
+ * Allocates private data at object creation time. Required
+ * for all objects other than ScreenRecs.
+ */
+static inline void *
+_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type) {
+ return calloc(size, 1);
+}
+
+#define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
+
+static inline void
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type) {
+ dixFreePrivates(privates, type);
+ free(object);
+}
+
+#define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
+
+/*
+ * Return size of privates for the specified type
+ */
+static inline int
+dixPrivatesSize(DevPrivateType type) { return 0; }
+
+/*
+ * Dump out private stats to ErrorF
+ */
+void
+dixPrivateUsage(void);
/*
* Resets the privates subsystem. dixResetPrivates is called from the main loop
* before each server generation. This function must only be called by main().
*/
-extern _X_EXPORT int
+extern _X_EXPORT void
dixResetPrivates(void);
/*
@@ -121,6 +207,6 @@ dixLookupPrivateOffset(RESTYPE type);
* Convenience macro for adding an offset to an object pointer
* when making a call to one of the devPrivates functions
*/
-#define DEVPRIV_AT(ptr, offset) ((PrivateRec **)((char *)ptr + offset))
+#define DEVPRIV_AT(ptr, offset) ((PrivatePtr *)((char *)(ptr) + offset))
#endif /* PRIVATES_H */
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index b3a831919..7c92f6491 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -275,7 +275,9 @@ typedef struct
device->public.realInputProc = oldprocs->realInputProc; \
device->unwrapProc = oldprocs->unwrapProc;
-extern DevPrivateKey xkbDevicePrivateKey;
+extern _X_EXPORT DevPrivateKeyRec xkbDevicePrivateKeyRec;
+#define xkbDevicePrivateKey (&xkbDevicePrivateKeyRec)
+
#define XKBDEVICEINFO(dev) ((xkbDeviceInfoPtr)dixLookupPrivate(&(dev)->devPrivates, xkbDevicePrivateKey))
extern void xkbUnwrapProc(DeviceIntPtr, DeviceHandleProc, pointer);