os/graphics/graphicscomposition/openwfcompositionengine/common/include/owfobject.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/common/include/owfobject.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,106 @@
     1.4 +/* Copyright (c) 2009 The Khronos Group Inc.
     1.5 + *
     1.6 + * Permission is hereby granted, free of charge, to any person obtaining a
     1.7 + * copy of this software and/or associated documentation files (the
     1.8 + * "Materials"), to deal in the Materials without restriction, including
     1.9 + * without limitation the rights to use, copy, modify, merge, publish,
    1.10 + * distribute, sublicense, and/or sell copies of the Materials, and to
    1.11 + * permit persons to whom the Materials are furnished to do so, subject to
    1.12 + * the following conditions:
    1.13 + *
    1.14 + * The above copyright notice and this permission notice shall be included
    1.15 + * in all copies or substantial portions of the Materials.
    1.16 + *
    1.17 + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.18 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.19 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.20 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.21 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.22 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.23 + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    1.24 + */
    1.25 +
    1.26 +#ifndef OWFOBJECT_H_
    1.27 +#define OWFOBJECT_H_
    1.28 +
    1.29 +#include <stdlib.h>
    1.30 +
    1.31 +#include "owftypes.h"
    1.32 +#include "owfdebug.h"
    1.33 +
    1.34 +
    1.35 +#ifdef __cplusplus
    1.36 +extern "C"
    1.37 +{
    1.38 +#endif
    1.39 +
    1.40 +
    1.41 +typedef void (*DESTRUCTOR)(void*);
    1.42 +typedef void (*CONSTRUCTOR)(void*);
    1.43 +
    1.44 +typedef struct {
    1.45 +    const char*             type;
    1.46 +    DESTRUCTOR              destructor;
    1.47 +    OWFuint32               referenceCount;
    1.48 +    void*                   payload;
    1.49 +} OWF_OBJECT;
    1.50 +
    1.51 +#define TYPE(x)             "" # x "_type"
    1.52 +
    1.53 +/*! returns field offset within structure */
    1.54 +#define FOFF(x,y)           ((OWFuint32) &(((x*) 0x1000)->y) - 0x1000)
    1.55 +
    1.56 +/*! returns pointer to wrapper object which holds object x */
    1.57 +#define _O(x)               ((OWF_OBJECT*) ((OWFuint32)(x) -\
    1.58 +                                           FOFF(OWF_OBJECT,payload)))
    1.59 +
    1.60 +/*! create new object instance */
    1.61 +#define CREATE(x)           (x*) OWF_Object_Construct(sizeof(x), TYPE(x), \
    1.62 +                                                      & x##_Ctor, & x##_Dtor)
    1.63 +
    1.64 +#define REFCOUNT(x)         ((x) ? _O(x)->referenceCount : 0xFFFFFFFF)
    1.65 +
    1.66 +/*! get the type of the contained object  */
    1.67 +#define TYPEOF(x)           (_O(x)->type)
    1.68 +
    1.69 +/*! increment object reference count  */
    1.70 +#define ADDREF(x,y) \
    1.71 +    if (y) {\
    1.72 +         _O(y)->referenceCount++; \
    1.73 +         DPRINT(("ADDREF: ref count of %s(%p) is now %d\n", TYPEOF(y), y, \
    1.74 +                 REFCOUNT(y)));\
    1.75 +    }\
    1.76 +    x = y;
    1.77 +
    1.78 +/*! decrement object reference count, call destructor if count reaches zero  */
    1.79 +#define REMREF(x) \
    1.80 +    if (x) {\
    1.81 +        --_O(x)->referenceCount; \
    1.82 +        DPRINT(("REMREF: ref count of %s(%p) is now %d\n", TYPEOF(x), x, \
    1.83 +                REFCOUNT(x))); \
    1.84 +        if (0 == _O(x)->referenceCount) {\
    1.85 +            if (_O(x)->destructor) {\
    1.86 +                _O(x)->destructor(x);\
    1.87 +            }\
    1.88 +            xfree(_O(x));\
    1.89 +        }\
    1.90 +        x = NULL;\
    1.91 +    }
    1.92 +
    1.93 +#define DESTROY(x) \
    1.94 +    REMREF(x); \
    1.95 +    x = NULL;
    1.96 +
    1.97 +OWF_API_CALL void*
    1.98 +OWF_Object_Construct(size_t size,
    1.99 +                     const char* type,
   1.100 +                     CONSTRUCTOR ctor,
   1.101 +                     DESTRUCTOR dtor);
   1.102 +
   1.103 +
   1.104 +#ifdef __cplusplus
   1.105 +}
   1.106 +#endif
   1.107 +
   1.108 +
   1.109 +#endif /* OWFOBJECT_H_ */