os/graphics/m3g/m3gcore11/inc/m3g_interface.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: M3G interface class internal interface
    15 *
    16 */
    17 
    18 #ifndef __M3G_INTERFACE_H__
    19 #define __M3G_INTERFACE_H__
    20 
    21 /*!
    22  * \internal
    23  * \file
    24  * \brief M3G interface class internal interface
    25  */
    26 
    27 typedef struct M3GInterfaceImpl Interface;
    28 
    29 /*--------------------------------------------------------------------
    30  * Memory allocation functions
    31  *------------------------------------------------------------------*/
    32 
    33 #if !defined(M3G_DEBUG_HEAP_TRACKING)
    34 
    35 static /*@only@*//*@null@*/ void* m3gAlloc(/*@in@*/ Interface *m3g,
    36                                            M3Gsize bytes);
    37 
    38 static /*@only@*//*@null@*/ void* m3gAllocZ(/*@in@*/ Interface *m3g,
    39                                             M3Gsize bytes);
    40 
    41 static void m3gFree(/*@in@*/ Interface *m3g,
    42                     /*@only@*//*@out@*//*@null@*/ void *ptr);
    43 
    44 static /*@only@*//*@null@*/ M3GMemObject m3gAllocObject(Interface *m3g,
    45                                                         M3Gsize bytes);
    46 static void m3gFreeObject(Interface *m3g,
    47                           /*@only@*//*@out@*//*@null@*/ M3GMemObject handle);
    48 
    49 #define m3gMarkObject(p)
    50 #define m3gIsObject(p) (M3G_FALSE)
    51 #define m3gUnmarkObject(p)
    52 
    53 #endif /* !M3G_DEBUG_HEAP_TRACKING */
    54 
    55 #if 0
    56 static void m3gRecycle(Interface *m3g, void *ptr, M3Gsize bytes);
    57 #endif
    58 
    59 static M3Gbool m3gGetColorMaskWorkaround(Interface *m3g);
    60 static M3Gbool m3gGetTwoSidedLightingWorkaround(Interface *m3g);
    61 
    62 /*--------------------------------------------------------------------
    63  * Debug memory allocation functions
    64  *------------------------------------------------------------------*/
    65 
    66 #if defined(M3G_DEBUG_HEAP_TRACKING)
    67 
    68 static /*@only@*//*@null@*/ void* m3gDebugAlloc(
    69     /*@in@*/ Interface *m3g, M3Gsize bytes, const char *file, int line);
    70 
    71 static /*@only@*//*@null@*/ void* m3gDebugAllocZ(
    72     /*@in@*/ Interface *m3g, M3Gsize bytes, const char *file, int line);
    73 
    74 static void m3gDebugFree(/*@in@*/ Interface *m3g,
    75                          /*@only@*//*@out@*//*@null@*/ void *ptr,
    76                          const char *file, int line);
    77 
    78 static /*@only@*//*@null@*/ M3GMemObject m3gDebugAllocObject(
    79     Interface *m3g, M3Gsize bytes, const char *file, int line);
    80 
    81 static void m3gDebugFreeObject(
    82     Interface *m3g, /*@only@*//*@out@*//*@null@*/ M3GMemObject handle,
    83     const char *file, int line);
    84 
    85 #define m3gAlloc(m3g, bytes) \
    86     m3gDebugAlloc(m3g, bytes, __FILE__, __LINE__)
    87 #define m3gAllocZ(m3g, bytes) \
    88     m3gDebugAllocZ(m3g, bytes, __FILE__, __LINE__)
    89 
    90 #define m3gAllocObject(m3g, bytes) \
    91     m3gDebugAllocObject(m3g, bytes, __FILE__, __LINE__)
    92 
    93 #define m3gFree(m3g, ptr)       m3gDebugFree(m3g, ptr, __FILE__, __LINE__)
    94 #define m3gFreeObject(m3g, obj) m3gDebugFreeObject(m3g, obj, __FILE__, __LINE__)
    95 
    96 static void m3gMarkObject(void *ptr);
    97 static M3Gbool m3gIsObject(const void *ptr);
    98 static void m3gUnmarkObject(void *ptr);
    99     
   100 #endif /* M3G_DEBUG_HEAP_TRACKING */
   101 
   102 /*----------------------------------------------------------------------
   103  * Profiling
   104  *--------------------------------------------------------------------*/
   105 
   106 #if defined(M3G_ENABLE_PROFILING)
   107 
   108 static void m3gIncStat(Interface *m3g, M3Gstatistic stat, M3Gint increment);
   109 static void m3gResetStat(Interface *m3g, M3Gstatistic stat);
   110 static void m3gUpdateMemoryPeakCounter(Interface *m3g);
   111 static void m3gLogMemoryPeakCounter(const Interface *m3g);
   112 static void m3gLogProfileCounters(Interface *m3g);
   113 extern void m3gBeginProfile(int stat);
   114 extern int m3gEndProfile(int stat);
   115 extern void m3gCleanupProfile(void);
   116 #define M3G_BEGIN_PROFILE(m3g, stat) m3gBeginProfile(stat);
   117 #define M3G_END_PROFILE(m3g, stat)   m3gIncStat(m3g, stat, m3gEndProfile(stat));
   118 
   119 #else
   120 
   121 #define m3gIncStat(m3g, stat, increment) (M3G_UNREF(m3g), M3G_UNREF(stat), M3G_UNREF(increment))
   122 #define m3gResetStat(m3g, stat)         (M3G_UNREF(m3g), M3G_UNREF(stat))
   123 #define m3gUpdateMemoryPeakCounter(m3g) (M3G_UNREF(m3g))
   124 #define m3gLogMemoryPeakCounter(m3g)    (M3G_UNREF(m3g))
   125 #define m3gLogProfileCounters(m3g)      (M3G_UNREF(m3g))
   126 #define m3gCleanupProfile()
   127 #define M3G_BEGIN_PROFILE(m3g, stat)    (M3G_UNREF(m3g), M3G_UNREF(stat))
   128 #define M3G_END_PROFILE(m3g, stat)      (M3G_UNREF(m3g), M3G_UNREF(stat))
   129 #endif
   130 
   131 /*--------------------------------------------------------------------
   132  * Other internal functions
   133  *------------------------------------------------------------------*/
   134 
   135 static void     m3gAddChildObject(Interface *m3g, Object *obj);
   136 static void     m3gDelChildObject(Interface *m3g, Object *obj);
   137 
   138 #include "m3g_array.h"
   139 static void     m3gGetObjectsWithClassID(Interface *m3g, M3GClass classID, PointerArray* objects);
   140 
   141 #if !defined(M3G_NGL_TEXTURE_API)
   142 static void     m3gDeleteGLTextures(Interface *m3g, M3Gsizei n, M3Guint *t);
   143 static void     m3gCollectGLObjects(Interface *m3g);
   144 #else
   145 #   define m3gCollectGLObjects(a)
   146 #endif
   147 
   148 static void*    m3gAllocTemp(Interface *m3g, M3Gsizei bytes);
   149 static void     m3gFreeTemp(Interface *m3g);
   150 
   151 static void*    m3gMapObject    (Interface *m3g, M3GMemObject handle);
   152 static void     m3gUnmapObject  (Interface *m3g, M3GMemObject handle);
   153 
   154 static void     m3gGarbageCollectAll            (Interface *m3g);
   155 
   156 #include "m3g_tcache.h"
   157 static TCache *m3gGetTransformCache(Interface *m3g);
   158 
   159 #if defined(M3G_NGL_CONTEXT_API)
   160 static void *m3gGetExternalFB(Interface *m3g, M3Guint userTarget);
   161 static void m3gReleaseExternalFB(Interface *m3g, M3Guint userTarget);
   162 static void m3gSignalTargetRelease(Interface *m3g, M3Guint userTarget);
   163 #endif /* M3G_NGL_CONTEXT_API */
   164 
   165 #if defined(M3G_DEBUG)
   166 static void m3gDebugRaiseError(/*@in@*/ Interface *m3g,
   167                                M3Genum error,
   168                                const char *filename,
   169                                int line);
   170 #define m3gRaiseError(m3g, error) \
   171     m3gDebugRaiseError(m3g, error, __FILE__, __LINE__)
   172 #else
   173 static void m3gRaiseError(/*@in@*/ Interface *m3g, M3Genum error);
   174 #endif /* M3G_DEBUG */
   175 
   176 #ifdef M3G_NATIVE_LOADER
   177 static M3GError m3gErrorRaised(const Interface *m3g);
   178 static m3gErrorHandler *m3gSetErrorHandler(Interface *m3g, m3gErrorHandler *errorHandler);
   179 #endif
   180 
   181 /* Memory locking only affects assertions in debug builds, so let's
   182  * disable it in non-debug ones for a bit of extra performance */
   183 
   184 #if defined(M3G_DEBUG)
   185 #define m3gLockMemory(a) m3gDebugLockMemory((a), __FILE__, __LINE__)
   186 static void    m3gDebugLockMemory(Interface *interface, const char *file, int line);
   187 static void    m3gUnlockMemory  (Interface *interface);
   188 static M3Gbool m3gMemoryLocked  (Interface *interface);
   189 #else
   190 #   define m3gLockMemory(a)   ((void)(a))
   191 #   define m3gUnlockMemory(a) ((void)(a))
   192 #   define m3gMemoryLocked(a) (M3G_FALSE)
   193 #endif
   194 
   195 #if defined(M3G_NGL_CONTEXT_API) && !defined(M3G_NGL_TEXTURE_API)
   196 #   define M3G_ASSERT_NO_LOCK(interface)
   197 #else
   198 #   define M3G_ASSERT_NO_LOCK(interface) M3G_ASSERT(!m3gMemoryLocked(interface))
   199 #endif
   200 
   201 static void m3gInitializeGL(Interface *interface);
   202 static void m3gShutdownGL(Interface *interface);
   203 
   204 /* Self-validation */
   205 
   206 #if defined(M3G_DEBUG)
   207 /*@notfunction@*/
   208 #   define M3G_VALIDATE_MEMBLOCK(ptr) m3gValidateMemory(ptr)
   209 static void m3gValidateMemory(const void *ptr);
   210 /*@notfunction@*/
   211 #   define M3G_VALIDATE_INTERFACE(m3g) m3gValidateInterface(m3g)
   212 static void m3gValidateInterface(const Interface *m3g);
   213 
   214 #else
   215 #   define M3G_VALIDATE_MEMBLOCK(ptr)
   216 #   define M3G_VALIDATE_INTERFACE(m3g)
   217 #endif
   218 
   219 #endif /*__M3G_INTERFACE_H__*/