sl@0: /* sl@0: * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: M3G interface class internal interface sl@0: * sl@0: */ sl@0: sl@0: #ifndef __M3G_INTERFACE_H__ sl@0: #define __M3G_INTERFACE_H__ sl@0: sl@0: /*! sl@0: * \internal sl@0: * \file sl@0: * \brief M3G interface class internal interface sl@0: */ sl@0: sl@0: typedef struct M3GInterfaceImpl Interface; sl@0: sl@0: /*-------------------------------------------------------------------- sl@0: * Memory allocation functions sl@0: *------------------------------------------------------------------*/ sl@0: sl@0: #if !defined(M3G_DEBUG_HEAP_TRACKING) sl@0: sl@0: static /*@only@*//*@null@*/ void* m3gAlloc(/*@in@*/ Interface *m3g, sl@0: M3Gsize bytes); sl@0: sl@0: static /*@only@*//*@null@*/ void* m3gAllocZ(/*@in@*/ Interface *m3g, sl@0: M3Gsize bytes); sl@0: sl@0: static void m3gFree(/*@in@*/ Interface *m3g, sl@0: /*@only@*//*@out@*//*@null@*/ void *ptr); sl@0: sl@0: static /*@only@*//*@null@*/ M3GMemObject m3gAllocObject(Interface *m3g, sl@0: M3Gsize bytes); sl@0: static void m3gFreeObject(Interface *m3g, sl@0: /*@only@*//*@out@*//*@null@*/ M3GMemObject handle); sl@0: sl@0: #define m3gMarkObject(p) sl@0: #define m3gIsObject(p) (M3G_FALSE) sl@0: #define m3gUnmarkObject(p) sl@0: sl@0: #endif /* !M3G_DEBUG_HEAP_TRACKING */ sl@0: sl@0: #if 0 sl@0: static void m3gRecycle(Interface *m3g, void *ptr, M3Gsize bytes); sl@0: #endif sl@0: sl@0: static M3Gbool m3gGetColorMaskWorkaround(Interface *m3g); sl@0: static M3Gbool m3gGetTwoSidedLightingWorkaround(Interface *m3g); sl@0: sl@0: /*-------------------------------------------------------------------- sl@0: * Debug memory allocation functions sl@0: *------------------------------------------------------------------*/ sl@0: sl@0: #if defined(M3G_DEBUG_HEAP_TRACKING) sl@0: sl@0: static /*@only@*//*@null@*/ void* m3gDebugAlloc( sl@0: /*@in@*/ Interface *m3g, M3Gsize bytes, const char *file, int line); sl@0: sl@0: static /*@only@*//*@null@*/ void* m3gDebugAllocZ( sl@0: /*@in@*/ Interface *m3g, M3Gsize bytes, const char *file, int line); sl@0: sl@0: static void m3gDebugFree(/*@in@*/ Interface *m3g, sl@0: /*@only@*//*@out@*//*@null@*/ void *ptr, sl@0: const char *file, int line); sl@0: sl@0: static /*@only@*//*@null@*/ M3GMemObject m3gDebugAllocObject( sl@0: Interface *m3g, M3Gsize bytes, const char *file, int line); sl@0: sl@0: static void m3gDebugFreeObject( sl@0: Interface *m3g, /*@only@*//*@out@*//*@null@*/ M3GMemObject handle, sl@0: const char *file, int line); sl@0: sl@0: #define m3gAlloc(m3g, bytes) \ sl@0: m3gDebugAlloc(m3g, bytes, __FILE__, __LINE__) sl@0: #define m3gAllocZ(m3g, bytes) \ sl@0: m3gDebugAllocZ(m3g, bytes, __FILE__, __LINE__) sl@0: sl@0: #define m3gAllocObject(m3g, bytes) \ sl@0: m3gDebugAllocObject(m3g, bytes, __FILE__, __LINE__) sl@0: sl@0: #define m3gFree(m3g, ptr) m3gDebugFree(m3g, ptr, __FILE__, __LINE__) sl@0: #define m3gFreeObject(m3g, obj) m3gDebugFreeObject(m3g, obj, __FILE__, __LINE__) sl@0: sl@0: static void m3gMarkObject(void *ptr); sl@0: static M3Gbool m3gIsObject(const void *ptr); sl@0: static void m3gUnmarkObject(void *ptr); sl@0: sl@0: #endif /* M3G_DEBUG_HEAP_TRACKING */ sl@0: sl@0: /*---------------------------------------------------------------------- sl@0: * Profiling sl@0: *--------------------------------------------------------------------*/ sl@0: sl@0: #if defined(M3G_ENABLE_PROFILING) sl@0: sl@0: static void m3gIncStat(Interface *m3g, M3Gstatistic stat, M3Gint increment); sl@0: static void m3gResetStat(Interface *m3g, M3Gstatistic stat); sl@0: static void m3gUpdateMemoryPeakCounter(Interface *m3g); sl@0: static void m3gLogMemoryPeakCounter(const Interface *m3g); sl@0: static void m3gLogProfileCounters(Interface *m3g); sl@0: extern void m3gBeginProfile(int stat); sl@0: extern int m3gEndProfile(int stat); sl@0: extern void m3gCleanupProfile(void); sl@0: #define M3G_BEGIN_PROFILE(m3g, stat) m3gBeginProfile(stat); sl@0: #define M3G_END_PROFILE(m3g, stat) m3gIncStat(m3g, stat, m3gEndProfile(stat)); sl@0: sl@0: #else sl@0: sl@0: #define m3gIncStat(m3g, stat, increment) (M3G_UNREF(m3g), M3G_UNREF(stat), M3G_UNREF(increment)) sl@0: #define m3gResetStat(m3g, stat) (M3G_UNREF(m3g), M3G_UNREF(stat)) sl@0: #define m3gUpdateMemoryPeakCounter(m3g) (M3G_UNREF(m3g)) sl@0: #define m3gLogMemoryPeakCounter(m3g) (M3G_UNREF(m3g)) sl@0: #define m3gLogProfileCounters(m3g) (M3G_UNREF(m3g)) sl@0: #define m3gCleanupProfile() sl@0: #define M3G_BEGIN_PROFILE(m3g, stat) (M3G_UNREF(m3g), M3G_UNREF(stat)) sl@0: #define M3G_END_PROFILE(m3g, stat) (M3G_UNREF(m3g), M3G_UNREF(stat)) sl@0: #endif sl@0: sl@0: /*-------------------------------------------------------------------- sl@0: * Other internal functions sl@0: *------------------------------------------------------------------*/ sl@0: sl@0: static void m3gAddChildObject(Interface *m3g, Object *obj); sl@0: static void m3gDelChildObject(Interface *m3g, Object *obj); sl@0: sl@0: #include "m3g_array.h" sl@0: static void m3gGetObjectsWithClassID(Interface *m3g, M3GClass classID, PointerArray* objects); sl@0: sl@0: #if !defined(M3G_NGL_TEXTURE_API) sl@0: static void m3gDeleteGLTextures(Interface *m3g, M3Gsizei n, M3Guint *t); sl@0: static void m3gCollectGLObjects(Interface *m3g); sl@0: #else sl@0: # define m3gCollectGLObjects(a) sl@0: #endif sl@0: sl@0: static void* m3gAllocTemp(Interface *m3g, M3Gsizei bytes); sl@0: static void m3gFreeTemp(Interface *m3g); sl@0: sl@0: static void* m3gMapObject (Interface *m3g, M3GMemObject handle); sl@0: static void m3gUnmapObject (Interface *m3g, M3GMemObject handle); sl@0: sl@0: static void m3gGarbageCollectAll (Interface *m3g); sl@0: sl@0: #include "m3g_tcache.h" sl@0: static TCache *m3gGetTransformCache(Interface *m3g); sl@0: sl@0: #if defined(M3G_NGL_CONTEXT_API) sl@0: static void *m3gGetExternalFB(Interface *m3g, M3Guint userTarget); sl@0: static void m3gReleaseExternalFB(Interface *m3g, M3Guint userTarget); sl@0: static void m3gSignalTargetRelease(Interface *m3g, M3Guint userTarget); sl@0: #endif /* M3G_NGL_CONTEXT_API */ sl@0: sl@0: #if defined(M3G_DEBUG) sl@0: static void m3gDebugRaiseError(/*@in@*/ Interface *m3g, sl@0: M3Genum error, sl@0: const char *filename, sl@0: int line); sl@0: #define m3gRaiseError(m3g, error) \ sl@0: m3gDebugRaiseError(m3g, error, __FILE__, __LINE__) sl@0: #else sl@0: static void m3gRaiseError(/*@in@*/ Interface *m3g, M3Genum error); sl@0: #endif /* M3G_DEBUG */ sl@0: sl@0: #ifdef M3G_NATIVE_LOADER sl@0: static M3GError m3gErrorRaised(const Interface *m3g); sl@0: static m3gErrorHandler *m3gSetErrorHandler(Interface *m3g, m3gErrorHandler *errorHandler); sl@0: #endif sl@0: sl@0: /* Memory locking only affects assertions in debug builds, so let's sl@0: * disable it in non-debug ones for a bit of extra performance */ sl@0: sl@0: #if defined(M3G_DEBUG) sl@0: #define m3gLockMemory(a) m3gDebugLockMemory((a), __FILE__, __LINE__) sl@0: static void m3gDebugLockMemory(Interface *interface, const char *file, int line); sl@0: static void m3gUnlockMemory (Interface *interface); sl@0: static M3Gbool m3gMemoryLocked (Interface *interface); sl@0: #else sl@0: # define m3gLockMemory(a) ((void)(a)) sl@0: # define m3gUnlockMemory(a) ((void)(a)) sl@0: # define m3gMemoryLocked(a) (M3G_FALSE) sl@0: #endif sl@0: sl@0: #if defined(M3G_NGL_CONTEXT_API) && !defined(M3G_NGL_TEXTURE_API) sl@0: # define M3G_ASSERT_NO_LOCK(interface) sl@0: #else sl@0: # define M3G_ASSERT_NO_LOCK(interface) M3G_ASSERT(!m3gMemoryLocked(interface)) sl@0: #endif sl@0: sl@0: static void m3gInitializeGL(Interface *interface); sl@0: static void m3gShutdownGL(Interface *interface); sl@0: sl@0: /* Self-validation */ sl@0: sl@0: #if defined(M3G_DEBUG) sl@0: /*@notfunction@*/ sl@0: # define M3G_VALIDATE_MEMBLOCK(ptr) m3gValidateMemory(ptr) sl@0: static void m3gValidateMemory(const void *ptr); sl@0: /*@notfunction@*/ sl@0: # define M3G_VALIDATE_INTERFACE(m3g) m3gValidateInterface(m3g) sl@0: static void m3gValidateInterface(const Interface *m3g); sl@0: sl@0: #else sl@0: # define M3G_VALIDATE_MEMBLOCK(ptr) sl@0: # define M3G_VALIDATE_INTERFACE(m3g) sl@0: #endif sl@0: sl@0: #endif /*__M3G_INTERFACE_H__*/