Update contrib.
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: M3G interface class internal interface
18 #ifndef __M3G_INTERFACE_H__
19 #define __M3G_INTERFACE_H__
24 * \brief M3G interface class internal interface
27 typedef struct M3GInterfaceImpl Interface;
29 /*--------------------------------------------------------------------
30 * Memory allocation functions
31 *------------------------------------------------------------------*/
33 #if !defined(M3G_DEBUG_HEAP_TRACKING)
35 static /*@only@*//*@null@*/ void* m3gAlloc(/*@in@*/ Interface *m3g,
38 static /*@only@*//*@null@*/ void* m3gAllocZ(/*@in@*/ Interface *m3g,
41 static void m3gFree(/*@in@*/ Interface *m3g,
42 /*@only@*//*@out@*//*@null@*/ void *ptr);
44 static /*@only@*//*@null@*/ M3GMemObject m3gAllocObject(Interface *m3g,
46 static void m3gFreeObject(Interface *m3g,
47 /*@only@*//*@out@*//*@null@*/ M3GMemObject handle);
49 #define m3gMarkObject(p)
50 #define m3gIsObject(p) (M3G_FALSE)
51 #define m3gUnmarkObject(p)
53 #endif /* !M3G_DEBUG_HEAP_TRACKING */
56 static void m3gRecycle(Interface *m3g, void *ptr, M3Gsize bytes);
59 static M3Gbool m3gGetColorMaskWorkaround(Interface *m3g);
60 static M3Gbool m3gGetTwoSidedLightingWorkaround(Interface *m3g);
62 /*--------------------------------------------------------------------
63 * Debug memory allocation functions
64 *------------------------------------------------------------------*/
66 #if defined(M3G_DEBUG_HEAP_TRACKING)
68 static /*@only@*//*@null@*/ void* m3gDebugAlloc(
69 /*@in@*/ Interface *m3g, M3Gsize bytes, const char *file, int line);
71 static /*@only@*//*@null@*/ void* m3gDebugAllocZ(
72 /*@in@*/ Interface *m3g, M3Gsize bytes, const char *file, int line);
74 static void m3gDebugFree(/*@in@*/ Interface *m3g,
75 /*@only@*//*@out@*//*@null@*/ void *ptr,
76 const char *file, int line);
78 static /*@only@*//*@null@*/ M3GMemObject m3gDebugAllocObject(
79 Interface *m3g, M3Gsize bytes, const char *file, int line);
81 static void m3gDebugFreeObject(
82 Interface *m3g, /*@only@*//*@out@*//*@null@*/ M3GMemObject handle,
83 const char *file, int line);
85 #define m3gAlloc(m3g, bytes) \
86 m3gDebugAlloc(m3g, bytes, __FILE__, __LINE__)
87 #define m3gAllocZ(m3g, bytes) \
88 m3gDebugAllocZ(m3g, bytes, __FILE__, __LINE__)
90 #define m3gAllocObject(m3g, bytes) \
91 m3gDebugAllocObject(m3g, bytes, __FILE__, __LINE__)
93 #define m3gFree(m3g, ptr) m3gDebugFree(m3g, ptr, __FILE__, __LINE__)
94 #define m3gFreeObject(m3g, obj) m3gDebugFreeObject(m3g, obj, __FILE__, __LINE__)
96 static void m3gMarkObject(void *ptr);
97 static M3Gbool m3gIsObject(const void *ptr);
98 static void m3gUnmarkObject(void *ptr);
100 #endif /* M3G_DEBUG_HEAP_TRACKING */
102 /*----------------------------------------------------------------------
104 *--------------------------------------------------------------------*/
106 #if defined(M3G_ENABLE_PROFILING)
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));
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))
131 /*--------------------------------------------------------------------
132 * Other internal functions
133 *------------------------------------------------------------------*/
135 static void m3gAddChildObject(Interface *m3g, Object *obj);
136 static void m3gDelChildObject(Interface *m3g, Object *obj);
138 #include "m3g_array.h"
139 static void m3gGetObjectsWithClassID(Interface *m3g, M3GClass classID, PointerArray* objects);
141 #if !defined(M3G_NGL_TEXTURE_API)
142 static void m3gDeleteGLTextures(Interface *m3g, M3Gsizei n, M3Guint *t);
143 static void m3gCollectGLObjects(Interface *m3g);
145 # define m3gCollectGLObjects(a)
148 static void* m3gAllocTemp(Interface *m3g, M3Gsizei bytes);
149 static void m3gFreeTemp(Interface *m3g);
151 static void* m3gMapObject (Interface *m3g, M3GMemObject handle);
152 static void m3gUnmapObject (Interface *m3g, M3GMemObject handle);
154 static void m3gGarbageCollectAll (Interface *m3g);
156 #include "m3g_tcache.h"
157 static TCache *m3gGetTransformCache(Interface *m3g);
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 */
165 #if defined(M3G_DEBUG)
166 static void m3gDebugRaiseError(/*@in@*/ Interface *m3g,
168 const char *filename,
170 #define m3gRaiseError(m3g, error) \
171 m3gDebugRaiseError(m3g, error, __FILE__, __LINE__)
173 static void m3gRaiseError(/*@in@*/ Interface *m3g, M3Genum error);
174 #endif /* M3G_DEBUG */
176 #ifdef M3G_NATIVE_LOADER
177 static M3GError m3gErrorRaised(const Interface *m3g);
178 static m3gErrorHandler *m3gSetErrorHandler(Interface *m3g, m3gErrorHandler *errorHandler);
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 */
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);
190 # define m3gLockMemory(a) ((void)(a))
191 # define m3gUnlockMemory(a) ((void)(a))
192 # define m3gMemoryLocked(a) (M3G_FALSE)
195 #if defined(M3G_NGL_CONTEXT_API) && !defined(M3G_NGL_TEXTURE_API)
196 # define M3G_ASSERT_NO_LOCK(interface)
198 # define M3G_ASSERT_NO_LOCK(interface) M3G_ASSERT(!m3gMemoryLocked(interface))
201 static void m3gInitializeGL(Interface *interface);
202 static void m3gShutdownGL(Interface *interface);
204 /* Self-validation */
206 #if defined(M3G_DEBUG)
208 # define M3G_VALIDATE_MEMBLOCK(ptr) m3gValidateMemory(ptr)
209 static void m3gValidateMemory(const void *ptr);
211 # define M3G_VALIDATE_INTERFACE(m3g) m3gValidateInterface(m3g)
212 static void m3gValidateInterface(const Interface *m3g);
215 # define M3G_VALIDATE_MEMBLOCK(ptr)
216 # define M3G_VALIDATE_INTERFACE(m3g)
219 #endif /*__M3G_INTERFACE_H__*/