Store GL context in the TEB

Mike Hearn mike at plan99.net
Mon Mar 20 10:55:06 CST 2006


Mike Hearn <mike at plan99.net>
Optimize thunks by storing GL context in the thread environment block

diff --git a/dlls/opengl32/Makefile.in b/dlls/opengl32/Makefile.in
index aceb302..b900d17 100644
--- a/dlls/opengl32/Makefile.in
+++ b/dlls/opengl32/Makefile.in
@@ -4,7 +4,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = opengl32.dll
 IMPORTLIB = libopengl32.$(IMPLIBEXT)
-IMPORTS   = user32 gdi32 advapi32 kernel32
+IMPORTS   = user32 gdi32 advapi32 kernel32 ntdll
 EXTRAINCL = @X_CFLAGS@
 EXTRALIBS = @X_LIBS@ @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ @OPENGL_LIBS@
 
diff --git a/dlls/opengl32/opengl_ext.h b/dlls/opengl32/opengl_ext.h
diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index 56c8ad1..71f7511 100644
--- a/dlls/opengl32/wgl.c
+++ b/dlls/opengl32/wgl.c
@@ -31,6 +31,8 @@
 #include "winerror.h"
 #include "winreg.h"
 #include "wingdi.h"
+#include "winternl.h"
+#include "winnt.h"
 
 #include "wgl_ext.h"
 #include "opengl_ext.h"
@@ -82,6 +84,7 @@ typedef struct wine_glcontext {
   XVisualInfo *vis;
   GLXFBConfig fb_conf;
   GLXContext ctx;
+  BOOL do_escape;
   struct wine_glcontext *next;
   struct wine_glcontext *prev;
 } Wine_GLContext;
@@ -96,18 +99,13 @@ static inline Wine_GLContext *get_contex
 
 void enter_gl(void)
 {
-    GLXContext gl_ctx;
-    Wine_GLContext *ctx;
-    enum x11drv_escape_codes escape = X11DRV_SYNC_PIXMAP;
-
-    wine_tsx11_lock_ptr();
-    gl_ctx = glXGetCurrentContext();
-    if(!gl_ctx) return;
-    ctx = get_context_from_GLXContext(gl_ctx);
-    wine_tsx11_unlock_ptr(); /* unlock before calling GDI apis */
-
-    if(ctx && GetObjectType(ctx->hdc) == OBJ_MEMDC)
-        ExtEscape(ctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL);
+    Wine_GLContext *curctx = (Wine_GLContext *) NtCurrentTeb()->glContext;
+    
+    if (curctx && curctx->do_escape)
+    {
+        enum x11drv_escape_codes escape = X11DRV_SYNC_PIXMAP;
+        ExtEscape(curctx->hdc, X11DRV_ESCAPE, sizeof(escape), (LPCSTR)&escape, 0, NULL);
+    }
 
     wine_tsx11_lock_ptr();
     return;
@@ -541,6 +539,7 @@ BOOL WINAPI wglMakeCurrent(HDC hdc,
   ENTER_GL();
   if (hglrc == NULL) {
       ret = glXMakeCurrent(default_display, None, NULL);
+      NtCurrentTeb()->glContext = NULL;
   } else {
       Wine_GLContext *ctx = (Wine_GLContext *) hglrc;
       Drawable drawable = get_drawable( hdc );
@@ -571,8 +570,12 @@ BOOL WINAPI wglMakeCurrent(HDC hdc,
       }
       TRACE(" make current for dis %p, drawable %p, ctx %p\n", ctx->display, (void*) drawable, ctx->ctx);
       ret = glXMakeCurrent(ctx->display, drawable, ctx->ctx);
+      NtCurrentTeb()->glContext = ctx;
       if(ret && type == OBJ_MEMDC)
+      {
+          ctx->do_escape = TRUE;
           glDrawBuffer(GL_FRONT_LEFT);
+      }
   }
   LEAVE_GL();
   TRACE(" returning %s\n", (ret ? "True" : "False"));





More information about the wine-patches mailing list