[OPENGL32] Fix usage of TEB members.
[reactos.git] / dll / opengl / opengl32 / opengl32.h
index ea2ea2c..32b4f35 100644 (file)
 #include <winddi.h>
 #include <GL/gl.h>
 
+#ifndef OPENGL32_USE_TLS
+#include <pstypes.h>
+#endif
+
 #include <wine/debug.h>
 
 #include "icd.h"
 
+/* *$%$£^§! headers inclusion */
+static __inline
+BOOLEAN
+RemoveEntryList(
+    _In_ PLIST_ENTRY Entry)
+{
+    PLIST_ENTRY OldFlink;
+    PLIST_ENTRY OldBlink;
+
+    OldFlink = Entry->Flink;
+    OldBlink = Entry->Blink;
+    OldFlink->Blink = OldBlink;
+    OldBlink->Flink = OldFlink;
+    return (OldFlink == OldBlink);
+}
+
+static __inline
+VOID
+InsertTailList(
+    _In_ PLIST_ENTRY ListHead,
+    _In_ PLIST_ENTRY Entry
+)
+{
+    PLIST_ENTRY OldBlink;
+    OldBlink = ListHead->Blink;
+    Entry->Flink = ListHead;
+    Entry->Blink = OldBlink;
+    OldBlink->Flink = Entry;
+    ListHead->Blink = Entry;
+}
+
+
+static __inline
+VOID
+InitializeListHead(
+    _Inout_ PLIST_ENTRY ListHead
+)
+{
+    ListHead->Flink = ListHead->Blink = ListHead;
+}
+
+extern LIST_ENTRY ContextListHead;
+
 struct wgl_context
 {
     DWORD magic;
     volatile LONG lock;
 
+    LIST_ENTRY ListEntry;
+
     DHGLRC dhglrc;
     struct ICD_Data* icd_data;
     INT pixelformat;
@@ -59,104 +108,78 @@ struct wgl_dc_data
     struct wgl_dc_data* next;
 };
 
-#ifdef OPENGL32_USE_TLS
-extern DWORD OglTlsIndex;
+/* Clean up functions */
+void IntDeleteAllContexts(void);
+void IntDeleteAllICDs(void);
 
-struct Opengl32_ThreadData
+FORCEINLINE
+const GLDISPATCHTABLE*
+IntGetCurrentDispatchTable(void)
 {
-    const GLDISPATCHTABLE* glDispatchTable;
-    HGLRC hglrc;
-    HDC hdc;
-    struct wgl_dc_data* dc_data;
-    PVOID* icdData;
-};
-C_ASSERT(FIELD_OFFSET(struct Opengl32_ThreadData, glDispatchTable) == 0);
+    return (GLDISPATCHTABLE*)NtCurrentTeb()->glTable;
+}
 
-static inline
+FORCEINLINE
+void
+IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
+{
+    NtCurrentTeb()->glTable = (void*)table;
+}
+
+FORCEINLINE
 void
 IntMakeCurrent(HGLRC hglrc, HDC hdc, struct wgl_dc_data* dc_data)
 {
-    struct Opengl32_ThreadData* thread_data = TlsGetValue(OglTlsIndex);
+    TEB* CurrentTeb = NtCurrentTeb();
 
-    thread_data->hglrc = hglrc;
-    thread_data->hdc = hdc;
-    thread_data->dc_data = dc_data;
+    CurrentTeb->glCurrentRC = hglrc;
+    CurrentTeb->glReserved2 = hdc;
+    CurrentTeb->glSectionInfo = dc_data;
 }
 
-static inline
+FORCEINLINE
 HGLRC
 IntGetCurrentRC(void)
 {
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    return data->hglrc;
-}
-
-static inline
-DHGLRC
-IntGetCurrentDHGLRC(void)
-{
-    struct wgl_context* ctx = (struct wgl_context*)IntGetCurrentRC();
-    if(!ctx) return NULL;
-    return ctx->dhglrc;
+    return NtCurrentTeb()->glCurrentRC;
 }
 
-static inline
+FORCEINLINE
 HDC
 IntGetCurrentDC(void)
 {
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    return data->hdc;
+    return NtCurrentTeb()->glReserved2;
 }
 
 static inline
 struct wgl_dc_data*
 IntGetCurrentDcData(void)
 {
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    return data->dc_data;
+    return NtCurrentTeb()->glSectionInfo;
 }
 
-static inline
-const GLDISPATCHTABLE *
-IntGetCurrentDispatchTable(void)
-{
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    return data->glDispatchTable;
-}
-
-static inline
-void
-IntSetCurrentDispatchTable(const GLDISPATCHTABLE* table)
-{
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    data->glDispatchTable = table;
-}
-
-static inline
+FORCEINLINE
 void
 IntSetCurrentICDPrivate(void* value)
 {
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    data->icdData = value;
+    NtCurrentTeb()->glContext = value;
 }
 
-static inline
+FORCEINLINE
 void*
 IntGetCurrentICDPrivate(void)
 {
-    struct Opengl32_ThreadData* data = TlsGetValue(OglTlsIndex);
-    return data->icdData;
+    return (void*)NtCurrentTeb()->glContext;
 }
 
-
-#else
-static inline
-const GLDISPATCHTABLE*
-IntGetCurrentDispatchTable(void)
+FORCEINLINE
+DHGLRC
+IntGetCurrentDHGLRC(void)
 {
-    return (GLDISPATCHTABLE*)NtCurrentTeb()->glTable;
+    struct wgl_context* ctx = (struct wgl_context*)IntGetCurrentRC();
+    if(!ctx) return NULL;
+    return ctx->dhglrc;
 }
-#endif // defined(OPENGL32_USE_TLS)
 
 /* Software implementation functions */
 INT sw_DescribePixelFormat(HDC hdc, INT format, UINT size, PIXELFORMATDESCRIPTOR* descr);