|
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); |
|
136 static void m3gDelChildObject(Interface *m3g); |
|
137 |
|
138 #if !defined(M3G_NGL_TEXTURE_API) |
|
139 static void m3gDeleteGLTextures(Interface *m3g, M3Gsizei n, M3Guint *t); |
|
140 static void m3gCollectGLObjects(Interface *m3g); |
|
141 #else |
|
142 # define m3gCollectGLObjects(a) |
|
143 #endif |
|
144 |
|
145 static void* m3gAllocTemp(Interface *m3g, M3Gsizei bytes); |
|
146 static void m3gFreeTemp(Interface *m3g); |
|
147 |
|
148 static void* m3gMapObject (Interface *m3g, M3GMemObject handle); |
|
149 static void m3gUnmapObject (Interface *m3g, M3GMemObject handle); |
|
150 |
|
151 static void m3gGarbageCollectAll (Interface *m3g); |
|
152 |
|
153 #include "m3g_tcache.h" |
|
154 static TCache *m3gGetTransformCache(Interface *m3g); |
|
155 |
|
156 #if defined(M3G_NGL_CONTEXT_API) |
|
157 static void *m3gGetExternalFB(Interface *m3g, M3Guint userTarget); |
|
158 static void m3gReleaseExternalFB(Interface *m3g, M3Guint userTarget); |
|
159 static void m3gSignalTargetRelease(Interface *m3g, M3Guint userTarget); |
|
160 #endif /* M3G_NGL_CONTEXT_API */ |
|
161 |
|
162 #if defined(M3G_DEBUG) |
|
163 static void m3gDebugRaiseError(/*@in@*/ Interface *m3g, |
|
164 M3Genum error, |
|
165 const char *filename, |
|
166 int line); |
|
167 #define m3gRaiseError(m3g, error) \ |
|
168 m3gDebugRaiseError(m3g, error, __FILE__, __LINE__) |
|
169 #else |
|
170 static void m3gRaiseError(/*@in@*/ Interface *m3g, M3Genum error); |
|
171 #endif /* M3G_DEBUG */ |
|
172 |
|
173 #ifdef M3G_NATIVE_LOADER |
|
174 static M3GError m3gErrorRaised(const Interface *m3g); |
|
175 static m3gErrorHandler *m3gSetErrorHandler(Interface *m3g, m3gErrorHandler *errorHandler); |
|
176 #endif |
|
177 |
|
178 /* Memory locking only affects assertions in debug builds, so let's |
|
179 * disable it in non-debug ones for a bit of extra performance */ |
|
180 |
|
181 #if defined(M3G_DEBUG) |
|
182 #define m3gLockMemory(a) m3gDebugLockMemory((a), __FILE__, __LINE__) |
|
183 static void m3gDebugLockMemory(Interface *interface, const char *file, int line); |
|
184 static void m3gUnlockMemory (Interface *interface); |
|
185 static M3Gbool m3gMemoryLocked (Interface *interface); |
|
186 #else |
|
187 # define m3gLockMemory(a) ((void)(a)) |
|
188 # define m3gUnlockMemory(a) ((void)(a)) |
|
189 # define m3gMemoryLocked(a) (M3G_FALSE) |
|
190 #endif |
|
191 |
|
192 #if defined(M3G_NGL_CONTEXT_API) && !defined(M3G_NGL_TEXTURE_API) |
|
193 # define M3G_ASSERT_NO_LOCK(interface) |
|
194 #else |
|
195 # define M3G_ASSERT_NO_LOCK(interface) M3G_ASSERT(!m3gMemoryLocked(interface)) |
|
196 #endif |
|
197 |
|
198 static void m3gInitializeGL(Interface *interface); |
|
199 static void m3gShutdownGL(Interface *interface); |
|
200 |
|
201 /* Self-validation */ |
|
202 |
|
203 #if defined(M3G_DEBUG) |
|
204 /*@notfunction@*/ |
|
205 # define M3G_VALIDATE_MEMBLOCK(ptr) m3gValidateMemory(ptr) |
|
206 static void m3gValidateMemory(const void *ptr); |
|
207 /*@notfunction@*/ |
|
208 # define M3G_VALIDATE_INTERFACE(m3g) m3gValidateInterface(m3g) |
|
209 static void m3gValidateInterface(const Interface *m3g); |
|
210 |
|
211 #else |
|
212 # define M3G_VALIDATE_MEMBLOCK(ptr) |
|
213 # define M3G_VALIDATE_INTERFACE(m3g) |
|
214 #endif |
|
215 |
|
216 #endif /*__M3G_INTERFACE_H__*/ |