os/graphics/m3g/m3gcore11/inc/m3g_object.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: M3G base object class internal interface
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
#ifndef __M3G_OBJECT_H__
sl@0
    19
#define __M3G_OBJECT_H__
sl@0
    20
sl@0
    21
/*!
sl@0
    22
 * \internal
sl@0
    23
 * \file
sl@0
    24
 * \brief M3G base object class internal interface
sl@0
    25
 *
sl@0
    26
 * The fundamental feature of the object model is that each object
sl@0
    27
 * instance structure includes the base class structure as its first
sl@0
    28
 * member.  Consequently, pointers to derived classes can be resolved
sl@0
    29
 * to pointers to base classes by simple casts, and things such as
sl@0
    30
 * virtual function pointers can be found at a fixed offset regardless
sl@0
    31
 * of the actual class of the object being dealt with.
sl@0
    32
 *
sl@0
    33
 * The per-class virtual function tables are laid out similarly to the
sl@0
    34
 * class structures, with the base class table preceding the derived
sl@0
    35
 * class table in memory. Currently, virtual function tables are
sl@0
    36
 * constructed by hand, but they are only needed for non-abstract
sl@0
    37
 * classes.
sl@0
    38
 */
sl@0
    39
sl@0
    40
#include "m3g_interface.h"
sl@0
    41
#include "m3g_array.h"
sl@0
    42
sl@0
    43
/*----------------------------------------------------------------------
sl@0
    44
 * Object class definition
sl@0
    45
 *--------------------------------------------------------------------*/
sl@0
    46
sl@0
    47
typedef M3Gint  (*m3gApplyAnimationFuncPtr)     (Object *self, M3Gint time);
sl@0
    48
typedef M3Gbool (*m3gIsCompatibleFuncPtr)       (M3Gint property);
sl@0
    49
typedef void    (*m3gUpdatePropertyFuncPtr)     (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
sl@0
    50
typedef M3Gint  (*m3gGetReferencesFuncPtr)      (Object *self, Object **references);
sl@0
    51
typedef Object* (*m3gFindFuncPtr)               (Object *self, M3Gint userID);
sl@0
    52
typedef M3Gbool (*m3gDuplicateFuncPtr)          (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
sl@0
    53
sl@0
    54
typedef void    (*m3gDestroyFuncPtr)            (Object *obj);
sl@0
    55
sl@0
    56
/*!
sl@0
    57
 * \internal
sl@0
    58
 * \brief Object class virtual functions
sl@0
    59
 */
sl@0
    60
typedef struct
sl@0
    61
{
sl@0
    62
    m3gApplyAnimationFuncPtr    applyAnimation;
sl@0
    63
    m3gIsCompatibleFuncPtr      isCompatible;
sl@0
    64
    m3gUpdatePropertyFuncPtr    updateProperty;
sl@0
    65
    m3gGetReferencesFuncPtr     getReferences;
sl@0
    66
    m3gFindFuncPtr              find;
sl@0
    67
    m3gDuplicateFuncPtr         duplicate;
sl@0
    68
    m3gDestroyFuncPtr           destroy;
sl@0
    69
} ObjectVFTable;
sl@0
    70
sl@0
    71
/*!
sl@0
    72
 * \internal
sl@0
    73
 * \brief Internal object structure
sl@0
    74
 *
sl@0
    75
 * \note Part of this is JSR-184 Object3D related and doesn't apply to
sl@0
    76
 * all native objects; namely, RenderContext does not use animation
sl@0
    77
 * tracks for anything
sl@0
    78
 */
sl@0
    79
struct M3GObjectImpl
sl@0
    80
{
sl@0
    81
    /*! \internal \brief Pointer to the interface that created this object */
sl@0
    82
    Interface *interface;
sl@0
    83
    
sl@0
    84
    /*!
sl@0
    85
     * \internal
sl@0
    86
     * \brief Class ID (as in M3GClass)
sl@0
    87
     *
sl@0
    88
     * This is used to resolve the virtual function table pointer,
sl@0
    89
     * among other things
sl@0
    90
     */
sl@0
    91
    M3Guint classID  :  8;
sl@0
    92
sl@0
    93
    /*! \internal \brief Reference count */
sl@0
    94
    M3Guint refCount : 24;
sl@0
    95
    
sl@0
    96
    /*! \internal \brief Table for animation tracks */
sl@0
    97
    PointerArray *animTracks;
sl@0
    98
    
sl@0
    99
    M3Gint userID;
sl@0
   100
};
sl@0
   101
sl@0
   102
sl@0
   103
/* Some compile-time sanity checks... */
sl@0
   104
sl@0
   105
M3G_CT_ASSERT(M3G_CLASS_WORLD <= 255);
sl@0
   106
//M3G_CT_ASSERT(sizeof(Object) == 16);
sl@0
   107
sl@0
   108
sl@0
   109
/* Self-validation */
sl@0
   110
#if defined(M3G_DEBUG)
sl@0
   111
/*@notfunction@*/
sl@0
   112
#   define M3G_VALIDATE_OBJECT(obj)   m3gValidateObject(obj)
sl@0
   113
static void m3gValidateObject(const void *pObj);
sl@0
   114
sl@0
   115
#else
sl@0
   116
#   define M3G_VALIDATE_OBJECT(obj)
sl@0
   117
#endif
sl@0
   118
sl@0
   119
/*!
sl@0
   120
 * \internal
sl@0
   121
 * \brief Returns the interface of any M3GObject-derived object
sl@0
   122
 */
sl@0
   123
/*@notfunction@*/
sl@0
   124
#define M3G_INTERFACE(obj) (((const Object *)(obj))->interface)
sl@0
   125
sl@0
   126
/*!
sl@0
   127
 * \internal
sl@0
   128
 * \brief Returns the class ID of any M3GObject-derived object
sl@0
   129
 */
sl@0
   130
/*@notfunction@*/
sl@0
   131
#define M3G_CLASS(obj) ((M3GClass)(((const Object *)(obj))->classID))
sl@0
   132
sl@0
   133
/*!
sl@0
   134
 * \internal
sl@0
   135
 * \brief Virtual function call macro
sl@0
   136
 *
sl@0
   137
 * \param className     name of class
sl@0
   138
 * \param pObj          pointer to object instance
sl@0
   139
 * \param funcName      name of function to call
sl@0
   140
 *
sl@0
   141
 */
sl@0
   142
/*@notfunction@*/
sl@0
   143
#define M3G_VFUNC(className, pObj, funcName) \
sl@0
   144
    (((className##VFTable*)m3gGetVFTable((Object*)(pObj)))->funcName)
sl@0
   145
sl@0
   146
static M3G_INLINE const ObjectVFTable *m3gGetVFTable(const Object *obj);
sl@0
   147
sl@0
   148
/*--------------------------------------------------------------------
sl@0
   149
 * Constructor
sl@0
   150
 *------------------------------------------------------------------*/
sl@0
   151
sl@0
   152
static void m3gInitObject(Object *object,
sl@0
   153
                          Interface *interface,
sl@0
   154
                          M3GClass classID);
sl@0
   155
sl@0
   156
/*-------------------------------------------------------------------
sl@0
   157
 * Internal functions
sl@0
   158
 *-----------------------------------------------------------------*/
sl@0
   159
sl@0
   160
/*! \internal \brief Nicer form for the \c find virtual function */
sl@0
   161
static M3G_INLINE Object *m3gFindID(Object *obj, M3Gint userID)
sl@0
   162
{
sl@0
   163
    return M3G_VFUNC(Object, obj, find)(obj, userID);
sl@0
   164
}
sl@0
   165
sl@0
   166
/* Reference handling */
sl@0
   167
static void m3gSetRef(Object **ref, Object *obj);
sl@0
   168
#define M3G_ASSIGN_REF(ref, value) m3gSetRef((Object**)&(ref), (Object*) value)
sl@0
   169
sl@0
   170
/* Virtual functions */
sl@0
   171
static M3Gint   m3gObjectApplyAnimation (Object *self, M3Gint time);
sl@0
   172
static M3Gbool  m3gObjectIsCompatible   (M3Gint property);
sl@0
   173
static void     m3gObjectUpdateProperty (Object *self, M3Gint property, M3Gint valueSize, const M3Gfloat *value);
sl@0
   174
static M3Gint   m3gObjectDoGetReferences(Object *self, Object **references);
sl@0
   175
static Object*  m3gObjectFindID         (Object *self, M3Gint userID);
sl@0
   176
static M3Gbool  m3gObjectDuplicate      (const Object *original, Object **clone, Object **pairs, M3Gint *numPairs);
sl@0
   177
static void     m3gDestroyObject        (Object *object);
sl@0
   178
sl@0
   179
#if defined(M3G_LOGLEVEL)
sl@0
   180
static const char *m3gClassName(M3GClass classID);
sl@0
   181
#else
sl@0
   182
/*lint -save -e607 this is intentional */
sl@0
   183
#   define m3gClassName(id) " ## id ## "
sl@0
   184
/*lint -restore */
sl@0
   185
#endif
sl@0
   186
sl@0
   187
#endif /*__M3G_OBJECT_H__*/