aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/include/privates.h
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2010-06-11 12:14:52 +0000
committermarha <marha@users.sourceforge.net>2010-06-11 12:14:52 +0000
commit4c61bf84b11e26e6f22648668c95ea760a379163 (patch)
tree0ac762ab2815eae283dded7447ad7cb5a54b926a /xorg-server/include/privates.h
parente1dabd2ce8be0d70c6c15353b58de256129dfd1f (diff)
downloadvcxsrv-4c61bf84b11e26e6f22648668c95ea760a379163.tar.gz
vcxsrv-4c61bf84b11e26e6f22648668c95ea760a379163.tar.bz2
vcxsrv-4c61bf84b11e26e6f22648668c95ea760a379163.zip
xserver git update 11/6/2010
Diffstat (limited to 'xorg-server/include/privates.h')
-rw-r--r--xorg-server/include/privates.h268
1 files changed, 200 insertions, 68 deletions
diff --git a/xorg-server/include/privates.h b/xorg-server/include/privates.h
index cbb08887f..2774776ab 100644
--- a/xorg-server/include/privates.h
+++ b/xorg-server/include/privates.h
@@ -12,125 +12,257 @@ 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 offset;
+ int size;
+ Bool initialized;
+ Bool allocated;
+ DevPrivateType type;
+ struct _DevPrivateKeyRec *next;
+} 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);
/*
- * Look up a private pointer.
+ * Check whether a private key has been registered
+ */
+static inline Bool
+dixPrivateKeyRegistered(DevPrivateKey key)
+{
+ return key->initialized;
+}
+
+/*
+ * Allocate a new private key.
*
- * If no value is currently associated with 'key' in 'privates', then
- * dixLookupPrivate calls dixAllocatePrivate and returns the resulting
- * associated value.
+ * This manages the storage of the key object itself, freeing it when the
+ * privates system is restarted at server reset time. All other keys
+ * are expected to be statically allocated as the privates must be
+ * reset after all objects have been freed
+ */
+extern _X_EXPORT DevPrivateKey
+dixCreatePrivateKey(DevPrivateType type, unsigned size);
+
+/*
+ * Get the address of the private storage.
*
- * dixLookupPrivate returns NULL if a memory allocation fails.
+ * For keys with pre-defined storage, this gets the base of that storage
+ * Otherwise, it returns the place where the private pointer is stored.
*/
-extern _X_EXPORT pointer
-dixLookupPrivate(PrivateRec **privates, const DevPrivateKey key);
+static inline void *
+dixGetPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
+{
+ assert(key->initialized);
+ return (char *) (*privates) + key->offset;
+}
/*
- * Look up the address of a private pointer. If 'key' is not associated with a
- * value in 'privates', then dixLookupPrivateAddr calls dixAllocatePrivate and
- * returns a pointer to the resulting associated value.
+ * Fetch a private pointer stored in the object
*
- * dixLookupPrivateAddr returns NULL if 'key' was not previously associated in
- * 'privates' and a memory allocation fails.
+ * Returns the pointer stored with dixSetPrivate.
+ * This must only be used with keys that have
+ * no pre-defined storage
*/
-extern _X_EXPORT pointer *
-dixLookupPrivateAddr(PrivateRec **privates, const DevPrivateKey key);
+static inline void *
+dixGetPrivate(PrivatePtr *privates, const DevPrivateKey key)
+{
+ assert (key->size == 0);
+ return *(void **) dixGetPrivateAddr(privates, key);
+}
/*
* Associate 'val' with 'key' in 'privates' so that later calls to
* dixLookupPrivate(privates, key) will return 'val'.
+ */
+static inline void
+dixSetPrivate(PrivatePtr *privates, const DevPrivateKey key, pointer val)
+{
+ assert (key->size == 0);
+ *(pointer *) dixGetPrivateAddr(privates, key) = val;
+}
+
+#include "dix.h"
+#include "resource.h"
+
+/*
+ * Lookup a pointer to the private record.
*
- * dixSetPrivate returns FALSE 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 int
-dixSetPrivate(PrivateRec **privates, const DevPrivateKey key, pointer val);
+static inline pointer
+dixLookupPrivate(PrivatePtr *privates, const DevPrivateKey key)
+{
+ if (key->size)
+ return dixGetPrivateAddr(privates, key);
+ else
+ return dixGetPrivate(privates, key);
+}
+
+/*
+ * Look up the address of the pointer to the storage
+ *
+ * This returns the place where the private pointer is stored,
+ * which is only valid for privates without predefined storage.
+ */
+static inline pointer *
+dixLookupPrivateAddr(PrivatePtr *privates, const DevPrivateKey key)
+{
+ assert (key->size == 0);
+ return dixGetPrivateAddr(privates, key);
+}
/*
- * Unassociates all keys from 'privates' and frees all private data automatically
- * allocated via dixRequestPrivate.
+ * Allocates private data separately from main object.
+ *
+ * For objects created during server initialization, this allows those
+ * privates to be re-allocated as new private keys are registered.
+ *
+ * This includes screens, the serverClient, default colormaps and
+ * extensions entries.
+ */
+extern _X_EXPORT Bool
+dixAllocatePrivates(PrivatePtr *privates, DevPrivateType type);
+
+/*
+ * Frees separately allocated private data
*/
extern _X_EXPORT void
-dixFreePrivates(PrivateRec *privates);
+dixFreePrivates(PrivatePtr privates, DevPrivateType type);
/*
- * Resets the privates subsystem. dixResetPrivates is called from the main loop
- * before each server generation. This function must only be called by main().
+ * Initialize privates by zeroing them
*/
-extern _X_EXPORT int
-dixResetPrivates(void);
+extern _X_EXPORT void
+_dixInitPrivates(PrivatePtr *privates, void *addr, DevPrivateType type);
+
+#define dixInitPrivates(o, v, type) _dixInitPrivates(&(o)->devPrivates, (v), type);
/*
- * These next two functions are necessary because the position of
- * the devPrivates field varies by structure and calling code might
- * only know the resource type, not the structure definition.
+ * Clean up privates
*/
+extern _X_EXPORT void
+_dixFiniPrivates(PrivatePtr privates, DevPrivateType type);
+
+#define dixFiniPrivates(o,t) _dixFiniPrivates((o)->devPrivates,t)
/*
- * Looks up the offset where the devPrivates field is located.
- * Returns -1 if no offset has been registered for the resource type.
+ * Allocates private data at object creation time. Required
+ * for almost all objects, except for the list described
+ * above for dixAllocatePrivates.
+ */
+extern _X_EXPORT void *
+_dixAllocateObjectWithPrivates(unsigned size, unsigned clear, unsigned offset, DevPrivateType type);
+
+#define dixAllocateObjectWithPrivates(t, type) (t *) _dixAllocateObjectWithPrivates(sizeof(t), sizeof(t), offsetof(t, devPrivates), type)
+
+extern _X_EXPORT void
+_dixFreeObjectWithPrivates(void *object, PrivatePtr privates, DevPrivateType type);
+
+#define dixFreeObjectWithPrivates(o,t) _dixFreeObjectWithPrivates(o, (o)->devPrivates, t)
+
+/*
+ * Return size of privates for the specified type
*/
extern _X_EXPORT int
-dixLookupPrivateOffset(RESTYPE type);
+dixPrivatesSize(DevPrivateType type);
+
+/*
+ * Dump out private stats to ErrorF
+ */
+extern 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 void
+dixResetPrivates(void);
/*
- * Specifies the offset where the devPrivates field is located.
- * A negative value indicates no devPrivates field is available.
+ * Looks up the offset where the devPrivates field is located.
+ *
+ * Returns -1 if the specified resource has no dev privates.
+ * The position of the devPrivates field varies by structure
+ * and calling code might only know the resource type, not the
+ * structure definition.
*/
extern _X_EXPORT int
-dixRegisterPrivateOffset(RESTYPE type, int offset);
+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 */