aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/glx/indirect.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/xwin/glx/indirect.c')
-rw-r--r--xorg-server/hw/xwin/glx/indirect.c373
1 files changed, 267 insertions, 106 deletions
diff --git a/xorg-server/hw/xwin/glx/indirect.c b/xorg-server/hw/xwin/glx/indirect.c
index a5ea854b3..7247992dc 100644
--- a/xorg-server/hw/xwin/glx/indirect.c
+++ b/xorg-server/hw/xwin/glx/indirect.c
@@ -79,6 +79,11 @@
#include <winpriv.h>
#include <wgl_ext_api.h>
+#include "win.h"
+#include <winmsg.h>
+
+extern Bool g_fXdmcpEnabled;
+extern Bool g_fNativeGl;
#define NUM_ELEMENTS(x) (sizeof(x)/ sizeof(x[1]))
@@ -95,15 +100,17 @@ typedef struct __GLXWinConfig GLXWinConfig;
struct __GLXWinContext {
__GLXcontext base;
HGLRC ctx; /* Windows GL Context */
+ HDC hDC; /* Windows device context */
+ HDC hreadDC; /* Windows device read context */
__GLXWinContext *shareContext; /* Context with which we will share display lists and textures */
HWND hwnd; /* For detecting when HWND has changed */
+ HWND hreadwnd;
};
struct __GLXWinDrawable
{
__GLXdrawable base;
__GLXWinContext *drawContext;
- __GLXWinContext *readContext;
/* If this drawable is GLX_DRAWABLE_PBUFFER */
HPBUFFERARB hPbuffer;
@@ -130,7 +137,9 @@ struct __GLXWinScreen
/* wrapped screen functions */
RealizeWindowProcPtr RealizeWindow;
UnrealizeWindowProcPtr UnrealizeWindow;
+ DestroyWindowProcPtr DestroyWindow;
CopyWindowProcPtr CopyWindow;
+ PositionWindowProcPtr PositionWindow;
};
struct __GLXWinConfig
@@ -144,12 +153,34 @@ struct __GLXWinConfig
* Various debug helpers
*/
-#define GLWIN_DEBUG_HWND(hwnd) \
- if (glxWinDebugSettings.dumpHWND) { \
- char buffer[1024]; \
- if (GetWindowText(hwnd, buffer, sizeof(buffer))==0) *buffer=0; \
- GLWIN_DEBUG_MSG("Got HWND %p for window '%s'", hwnd, buffer); \
- }
+#ifdef _DEBUG
+void GLWIN_DEBUG_HWND(HWND hwnd)
+{
+ if (glxWinDebugSettings.dumpHWND)
+ {
+ char buffer[1024];
+ RECT Rect;
+ HDC hDc=GetDC(hwnd);
+
+ if (GetWindowText(hwnd, buffer, sizeof(buffer))==0) *buffer=0;
+ GetWindowRect(hwnd,&Rect);
+
+ GLWIN_DEBUG_MSG("Got HWND %p (hdc %p) for window '%s' (%d,%d,%d,%d)", hwnd, hDc, buffer, Rect.left, Rect.top, Rect.right, Rect.bottom);
+ ReleaseDC(hwnd,hDc);
+ }
+}
+
+void GLWIN_HDC_DEBUG_MSG(const char *Message, HDC hDc, HWND hwnd)
+{
+ char buffer[1024];
+ RECT Rect;
+
+ if (GetWindowText(hwnd, buffer, sizeof(buffer))==0) *buffer=0;
+ GetWindowRect(hwnd,&Rect);
+
+ GLWIN_DEBUG_MSG("Got HDC %p (hwnd %p) for window '%s' (%d,%d,%d,%d)", hDc, hwnd, buffer, Rect.left, Rect.top, Rect.right, Rect.bottom);
+
+}
glxWinDebugSettingsRec glxWinDebugSettings = { 0, 0, 0, 0, 0, 0};
@@ -197,18 +228,24 @@ static void glxWinInitDebugSettings(void)
glxWinDebugSettings.enableWGLcallTrace = 1;
}
}
+#endif
static
const char *glxWinErrorMessage(void)
{
static char errorbuffer[1024];
+ DWORD Error=GetLastError();
+ int offset;
+
+ sprintf(errorbuffer, "%p ",Error);
+ offset=strlen(errorbuffer);
if (!FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
- GetLastError(),
+ Error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR) &errorbuffer,
+ (LPTSTR) &errorbuffer[offset],
sizeof(errorbuffer),
NULL ))
{
@@ -223,6 +260,8 @@ const char *glxWinErrorMessage(void)
static void pfdOut(const PIXELFORMATDESCRIPTOR *pfd);
+#ifdef _DEBUG
+
#define DUMP_PFD_FLAG(flag) \
if (pfd->dwFlags & flag) { \
ErrorF("%s%s", pipesym, #flag); \
@@ -367,6 +406,7 @@ fbConfigsDump(unsigned int n, __GLXconfig *c)
c = c->next;
}
}
+#endif
/* ---------------------------------------------------------------------- */
/*
@@ -385,9 +425,11 @@ static __GLXdrawable *glxWinCreateDrawable(__GLXscreen *screen,
static Bool glxWinRealizeWindow(WindowPtr pWin);
static Bool glxWinUnrealizeWindow(WindowPtr pWin);
+static Bool glxWinDestroyWindow(WindowPtr pWin);
static void glxWinCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
+static Bool glxWinPositionWindow(WindowPtr pWindow, int x, int y);
-static HDC glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd);
+static HDC glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HWND *hwnd);
static void glxWinReleaseDC(HWND hwnd, HDC hdc, __GLXWinDrawable *draw);
static void glxWinCreateConfigs(HDC dc, glxWinScreen *screen);
@@ -409,7 +451,8 @@ __GLXprovider __glXWGLProvider = {
void
glxWinPushNativeProvider(void)
{
- GlxPushProvider(&__glXWGLProvider);
+ if (g_fNativeGl)
+ GlxPushProvider(&__glXWGLProvider);
}
/* ---------------------------------------------------------------------- */
@@ -436,6 +479,16 @@ glxWinScreenSwapInterval(__GLXdrawable *drawable, int interval)
return ret;
}
+static LRESULT CALLBACK GlxWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ if (uMsg== WM_NCHITTEST)
+ {
+ return HTTRANSPARENT;
+ }
+ else
+ return DefWindowProc(hwnd, uMsg, wParam, lParam);
+}
+
/*
Report the extensions split and formatted to avoid overflowing a line
*/
@@ -456,7 +509,7 @@ glxLogExtensions(const char *prefix, const char *extensions)
strncpy (str, extensions, strlen(extensions));
strl = strtok(str, " ");
- ErrorF("%s%s", prefix, strl);
+ winDebug("%s%s", prefix, strl);
length = strlen(prefix) + strlen(strl);
while (1)
@@ -466,20 +519,20 @@ glxLogExtensions(const char *prefix, const char *extensions)
if (length + strlen(strl) + 1 > 120)
{
- ErrorF("\n%s",prefix);
+ winDebug("\n%s",prefix);
length = strlen(prefix);
}
else
{
- ErrorF(" ");
+ winDebug(" ");
length++;
}
- ErrorF("%s", strl);
+ winDebug("%s", strl);
length = length + strlen(strl);
}
- ErrorF("\n");
+ winDebug("\n");
xfree(str);
}
@@ -497,7 +550,9 @@ glxWinScreenProbe(ScreenPtr pScreen)
GLWIN_DEBUG_MSG("glxWinScreenProbe");
+#ifdef _DEBUG
glxWinInitDebugSettings();
+#endif
if (pScreen == NULL)
return NULL;
@@ -520,27 +575,31 @@ glxWinScreenProbe(ScreenPtr pScreen)
pScreen->UnrealizeWindow = glxWinUnrealizeWindow;
screen->CopyWindow = pScreen->CopyWindow;
pScreen->CopyWindow = glxWinCopyWindow;
+ screen->PositionWindow = pScreen->PositionWindow;
+ pScreen->PositionWindow = glxWinPositionWindow;
+ screen->DestroyWindow = pScreen->DestroyWindow;
+ pScreen->DestroyWindow = glxWinDestroyWindow;
/* Dump out some useful information about the native renderer */
// create window class
-#define WIN_GL_TEST_WINDOW_CLASS "XWinGLTest"
{
static wATOM glTestWndClass = 0;
if (glTestWndClass == 0)
{
WNDCLASSEX wc;
+ glTestWndClass=1;
wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = DefWindowProc;
+ wc.style = CS_OWNDC ;
+ wc.lpfnWndProc = GlxWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = 0;
wc.hCursor = 0;
- wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+ wc.hbrBackground = 0;
wc.lpszMenuName = NULL;
- wc.lpszClassName = WIN_GL_TEST_WINDOW_CLASS;
+ wc.lpszClassName = WIN_GL_WINDOW_CLASS;
wc.hIconSm = 0;
RegisterClassEx (&wc);
}
@@ -548,7 +607,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
// create an invisible window for a scratch DC
hwnd = CreateWindowExA(0,
- WIN_GL_TEST_WINDOW_CLASS,
+ WIN_GL_WINDOW_CLASS,
"XWin GL Renderer Capabilities Test Window",
0, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);
if (hwnd == NULL)
@@ -565,9 +624,9 @@ glxWinScreenProbe(ScreenPtr pScreen)
// (but we need to have a current context for them to be resolvable)
wglResolveExtensionProcs();
- ErrorF("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION));
- ErrorF("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
- ErrorF("GL_RENDERER: %s\n", glGetStringWrapperNonstatic(GL_RENDERER));
+ winDebug("GL_VERSION: %s\n", glGetStringWrapperNonstatic(GL_VERSION));
+ winDebug("GL_VENDOR: %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
+ winDebug("GL_RENDERER: %s\n", glGetStringWrapperNonstatic(GL_RENDERER));
gl_extensions = (const char *)glGetStringWrapperNonstatic(GL_EXTENSIONS);
glxLogExtensions("GL_EXTENSIONS: ", gl_extensions);
wgl_extensions = wglGetExtensionsStringARBWrapper(hdc);
@@ -673,8 +732,10 @@ glxWinScreenProbe(ScreenPtr pScreen)
__glXScreenInit(&screen->base, pScreen);
+#ifdef _DEBUG
// dump out fbConfigs now fbConfigIds and visualIDs have been assigned
fbConfigsDump(screen->base.numFBConfigs, screen->base.fbconfigs);
+#endif
// Override the GL extensions string set by __glXScreenInit()
screen->base.GLextensions = xstrdup(gl_extensions);
@@ -740,6 +801,7 @@ glxWinRealizeWindow(WindowPtr pWin)
Bool result;
ScreenPtr pScreen = pWin->drawable.pScreen;
glxWinScreen *screenPriv = (glxWinScreen *) glxGetScreen(pScreen);
+ winWindowPriv(pWin);
GLWIN_DEBUG_MSG("glxWinRealizeWindow");
@@ -747,7 +809,12 @@ glxWinRealizeWindow(WindowPtr pWin)
pScreen->RealizeWindow = screenPriv->RealizeWindow;
result = pScreen->RealizeWindow(pWin);
pScreen->RealizeWindow = glxWinRealizeWindow;
-
+
+ // Check if ze need to move the window\n
+ if (pWinPriv->GlCtxWnd && pWinPriv->hWnd)
+ {
+ ShowWindow(pWinPriv->hWnd,SW_SHOW);
+ }
return result;
}
@@ -783,14 +850,41 @@ glxWinCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
pScreen->CopyWindow = screenPriv->CopyWindow;
pScreen->CopyWindow(pWindow, ptOldOrg, prgnSrc);
pScreen->CopyWindow = glxWinCopyWindow;
+
+}
+
+static Bool
+glxWinPositionWindow(WindowPtr pWin, int x, int y)
+{
+ Bool result;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ glxWinScreen *screenPriv = (glxWinScreen *) glxGetScreen(pScreen);
+ winWindowPriv(pWin);
+
+ pScreen->PositionWindow = screenPriv->PositionWindow;
+ result = pScreen->PositionWindow(pWin, x, y);
+ pScreen->PositionWindow = glxWinPositionWindow;
+
+ if (pWinPriv->GlCtxWnd && pWinPriv->hWnd)
+ {
+ MoveWindow(pWinPriv->hWnd,
+ pWin->drawable.x,
+ pWin->drawable.y,
+ pWin->drawable.width,
+ pWin->drawable.height,
+ FALSE);
+ }
+ return result;
}
+
static Bool
glxWinUnrealizeWindow(WindowPtr pWin)
{
Bool result;
ScreenPtr pScreen = pWin->drawable.pScreen;
glxWinScreen *screenPriv = (glxWinScreen *)glxGetScreen(pScreen);
+ winWindowPriv(pWin);
GLWIN_DEBUG_MSG("glxWinUnrealizeWindow");
@@ -798,6 +892,45 @@ glxWinUnrealizeWindow(WindowPtr pWin)
result = pScreen->UnrealizeWindow(pWin);
pScreen->UnrealizeWindow = glxWinUnrealizeWindow;
+ if (pWinPriv->GlCtxWnd && pWinPriv->hWnd)
+ ShowWindow(pWinPriv->hWnd,SW_HIDE);
+
+ return result;
+}
+
+static Bool
+glxWinDestroyWindow(WindowPtr pWin)
+{
+ Bool result;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ glxWinScreen *screenPriv = (glxWinScreen *)glxGetScreen(pScreen);
+ winWindowPriv(pWin);
+
+ GLWIN_DEBUG_MSG("glxWinDestroyWindow");
+
+ if (pWinPriv->GlCtxWnd && pWinPriv->hWnd)
+ {
+ __GLXWinDrawable *pGlxDraw;
+
+ dixLookupResourceByType((pointer) &pGlxDraw, pWin->drawable.id, __glXDrawableRes, NullClient, DixUnknownAccess);
+
+ if (pGlxDraw && pGlxDraw->drawContext)
+ {
+ if (pGlxDraw->drawContext->hwnd!=pWinPriv->hWnd)
+ ErrorF("Wrong assumption\n");
+ glxWinReleaseDC(pGlxDraw->drawContext->hwnd, pGlxDraw->drawContext->hDC, pGlxDraw);
+ pGlxDraw->drawContext->hDC=NULL;
+ pGlxDraw->drawContext->hwnd=NULL;
+ }
+ DestroyWindow(pWinPriv->hWnd);
+ pWinPriv->hWnd=NULL;
+ pWinPriv->GlCtxWnd=0;
+ }
+
+ pScreen->DestroyWindow = screenPriv->DestroyWindow;
+ result = pScreen->DestroyWindow(pWin);
+ pScreen->DestroyWindow = glxWinDestroyWindow;
+
return result;
}
@@ -809,8 +942,6 @@ glxWinUnrealizeWindow(WindowPtr pWin)
static GLboolean
glxWinDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base)
{
- HDC dc;
- HWND hwnd;
BOOL ret;
__GLXWinDrawable *draw = (__GLXWinDrawable *)base;
@@ -829,13 +960,7 @@ glxWinDrawableSwapBuffers(ClientPtr client, __GLXdrawable *base)
*/
assert((draw->drawContext->base.drawPriv == NULL) || (draw->drawContext->base.drawPriv == base));
- dc = glxWinMakeDC(draw->drawContext, draw, &dc, &hwnd);
- if (dc == NULL)
- return GL_FALSE;
-
- ret = wglSwapLayerBuffers(dc, WGL_SWAP_MAIN_PLANE);
-
- glxWinReleaseDC(hwnd, dc, draw);
+ ret = SwapBuffers(draw->drawContext->hDC);
if (!ret)
{
@@ -910,13 +1035,11 @@ glxWinCreateDrawable(__GLXscreen *screen,
{
__GLXWinDrawable *glxPriv;
- glxPriv = xalloc(sizeof *glxPriv);
+ glxPriv = xcalloc(1,sizeof(*glxPriv));
if (glxPriv == NULL)
return NULL;
- memset(glxPriv, 0, sizeof *glxPriv);
-
if(!__glXDrawableInit(&glxPriv->base, screen, pDraw, type, drawId, conf)) {
xfree(glxPriv);
return NULL;
@@ -983,7 +1106,7 @@ glxWinSetPixelFormat(__GLXWinContext *gc, HDC hdc, int bppOverride, int drawable
__GLXconfig *config = gc->base.config;
GLXWinConfig *winConfig = (GLXWinConfig *)config;
-
+
GLWIN_DEBUG_MSG("glxWinSetPixelFormat: pixelFormatIndex %d", winConfig->pixelFormatIndex);
/*
@@ -1027,7 +1150,7 @@ glxWinSetPixelFormat(__GLXWinContext *gc, HDC hdc, int bppOverride, int drawable
{
PIXELFORMATDESCRIPTOR pfd;
int pixelFormat;
-
+
/* convert fbConfig to PFD */
if (fbConfigToPixelFormat(gc->base.config, &pfd, drawableTypeOverride))
{
@@ -1035,8 +1158,10 @@ glxWinSetPixelFormat(__GLXWinContext *gc, HDC hdc, int bppOverride, int drawable
return;
}
- if (glxWinDebugSettings.dumpPFD)
+#ifdef _DEBUG
+ if (glxWinDebugSettings.dumpPFD)
pfdOut(&pfd);
+#endif
if (bppOverride)
{
@@ -1081,9 +1206,9 @@ glxWinSetPixelFormat(__GLXWinContext *gc, HDC hdc, int bppOverride, int drawable
}
static HDC
-glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd)
+glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HWND *hwnd)
{
- *hdc = NULL;
+ HDC hdc = NULL;
*hwnd = NULL;
if (draw == NULL)
@@ -1115,38 +1240,53 @@ glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd)
return NULL;
}
- *hdc = GetDC(winInfo.hwnd);
+ hdc = GetDC(winInfo.hwnd);
- if (*hdc == NULL)
- ErrorF("GetDC error: %s\n", glxWinErrorMessage());
+ if (hdc == NULL)
+ ErrorF("GetDC error: %s: hwnd %x, gc %p, gc->ctx %p ,gc->hwnd %p\n", glxWinErrorMessage(), winInfo.hwnd, gc, gc->ctx, gc->hwnd);
- /* Check if the hwnd has changed... */
- if (winInfo.hwnd != gc->hwnd)
- {
- if (glxWinDebugSettings.enableTrace)
- GLWIN_DEBUG_HWND(winInfo.hwnd);
-
- GLWIN_TRACE_MSG("for context %p (native ctx %p), hWnd changed from %p to %p", gc, gc->ctx, gc->hwnd, winInfo.hwnd);
- gc->hwnd = winInfo.hwnd;
+ if (gc->hDC)
+ {
+ glxWinReleaseDC(gc->hwnd, gc->hDC, draw);
+ gc->hDC=NULL;
+ }
+#ifdef _DEBUG
+ if (glxWinDebugSettings.enableTrace)
+ GLWIN_DEBUG_HWND(winInfo.hwnd);
+ GLWIN_TRACE_MSG("for context %p (native ctx %p), hWnd changed from %p to %p", gc, gc->ctx, gc->hwnd, winInfo.hwnd);
+#endif
+ gc->hwnd = winInfo.hwnd;
+
+ /* Check if we need to set the pixelformat */
+ {
+ winWindowPriv(pWin);
+ if (!pWinPriv->PixelFormatSet)
+ {
+ pWinPriv->PixelFormatSet=TRUE;
/* We must select a pixelformat, but SetPixelFormat can only be called once for a window... */
- glxWinSetPixelFormat(gc, *hdc, 0, GLX_WINDOW_BIT);
+ glxWinSetPixelFormat(gc, hdc, 0, GLX_WINDOW_BIT);
}
+ }
}
break;
case GLX_DRAWABLE_PBUFFER:
{
- *hdc = wglGetPbufferDCARBWrapper(draw->hPbuffer);
+ hdc = wglGetPbufferDCARBWrapper(draw->hPbuffer);
- if (*hdc == NULL)
+ if (hdc == NULL)
ErrorF("GetDC (pbuffer) error: %s\n", glxWinErrorMessage());
}
break;
case GLX_DRAWABLE_PIXMAP:
{
- *hdc = draw->dibDC;
+ hdc = draw->dibDC;
+#ifdef _DEBUG
+ if (glxWinDebugSettings.dumpDC)
+ GLWIN_DEBUG_MSG("Got PIXMAP HDC %p for window %p", hdc, *hwnd);
+#endif
}
break;
@@ -1156,10 +1296,12 @@ glxWinMakeDC(__GLXWinContext *gc, __GLXWinDrawable *draw, HDC *hdc, HWND *hwnd)
}
}
+#ifdef _DEBUG
if (glxWinDebugSettings.dumpDC)
- GLWIN_DEBUG_MSG("Got HDC %p", *hdc);
+ GLWIN_HDC_DEBUG_MSG("Got HDC %p for window %p", hdc, *hwnd);
+#endif
- return *hdc;
+ return hdc;
}
static void
@@ -1202,7 +1344,6 @@ glxWinReleaseDC(HWND hwnd, HDC hdc,__GLXWinDrawable *draw)
static void
glxWinDeferredCreateContext(__GLXWinContext *gc, __GLXWinDrawable *draw)
{
- HDC dc;
HWND hwnd;
GLWIN_DEBUG_MSG("glxWinDeferredCreateContext: attach context %p to drawable %p", gc, draw);
@@ -1337,12 +1478,14 @@ glxWinDeferredCreateContext(__GLXWinContext *gc, __GLXWinDrawable *draw)
}
}
- dc = glxWinMakeDC(gc, draw, &dc, &hwnd);
- gc->ctx = wglCreateContext(dc);
- glxWinReleaseDC(hwnd, dc, draw);
+ gc->hDC = glxWinMakeDC(gc, draw, &hwnd);
+ gc->ctx = wglCreateContext(gc->hDC);
if (gc->ctx == NULL)
{
+ glxWinReleaseDC(hwnd, gc->hDC, draw);
+ gc->hDC=0;
+
ErrorF("wglCreateContext error: %s\n", glxWinErrorMessage());
return;
}
@@ -1373,23 +1516,20 @@ glxWinContextMakeCurrent(__GLXcontext *base)
{
__GLXWinContext *gc = (__GLXWinContext *)base;
BOOL ret;
- HDC drawDC;
- HDC readDC = NULL;
- __GLXdrawable *drawPriv;
- __GLXdrawable *readPriv = NULL;
- HWND hDrawWnd;
- HWND hReadWnd;
+ __GLXWinDrawable *drawPriv;
+#ifdef _DEBUG
GLWIN_TRACE_MSG("glxWinContextMakeCurrent context %p (native ctx %p)", gc, gc->ctx);
glWinCallDelta();
+#endif
/* Keep a note of the last active context in the drawable */
- drawPriv = gc->base.drawPriv;
- ((__GLXWinDrawable *)drawPriv)->drawContext = gc;
+ drawPriv = (__GLXWinDrawable *)gc->base.drawPriv;
+ drawPriv->drawContext = gc;
if (gc->ctx == NULL)
{
- glxWinDeferredCreateContext(gc, (__GLXWinDrawable *)drawPriv);
+ glxWinDeferredCreateContext(gc, drawPriv);
}
if (gc->ctx == NULL)
@@ -1398,13 +1538,6 @@ glxWinContextMakeCurrent(__GLXcontext *base)
return FALSE;
}
- drawDC = glxWinMakeDC(gc, (__GLXWinDrawable *)drawPriv, &drawDC, &hDrawWnd);
- if (drawDC == NULL)
- {
- ErrorF("glxWinMakeDC failed for drawDC\n");
- return FALSE;
- }
-
if ((gc->base.readPriv != NULL) && (gc->base.readPriv != gc->base.drawPriv))
{
// XXX: should only occur with WGL_ARB_make_current_read
@@ -1413,16 +1546,14 @@ glxWinContextMakeCurrent(__GLXcontext *base)
use the wglMakeContextCurrent extension to make the context current drawing
to one DC and reading from the other
*/
- readPriv = gc->base.readPriv;
- readDC = glxWinMakeDC(gc, (__GLXWinDrawable *)readPriv, &readDC, &hReadWnd);
- if (readDC == NULL)
+ gc->hreadDC = glxWinMakeDC(gc, (__GLXWinDrawable *)gc->base.readPriv, &gc->hreadwnd);
+ if (gc->hreadDC == NULL)
{
ErrorF("glxWinMakeDC failed for readDC\n");
- glxWinReleaseDC(hDrawWnd, drawDC, (__GLXWinDrawable *)drawPriv);
return FALSE;
}
- ret = wglMakeContextCurrentARBWrapper(drawDC, readDC, gc->ctx);
+ ret = wglMakeContextCurrentARBWrapper(gc->hDC, gc->hreadDC, gc->ctx);
if (!ret)
{
ErrorF("wglMakeContextCurrentARBWrapper error: %s\n", glxWinErrorMessage());
@@ -1431,40 +1562,63 @@ glxWinContextMakeCurrent(__GLXcontext *base)
else
{
/* Otherwise, just use wglMakeCurrent */
- ret = wglMakeCurrent(drawDC, gc->ctx);
+ if (!gc->hDC)
+ {
+ /* It probably has been release by loseCurrent, so create it again */
+ gc->hDC = glxWinMakeDC(gc, drawPriv, &gc->hwnd);
+ }
+ ret = wglMakeCurrent(gc->hDC, gc->ctx);
if (!ret)
{
- ErrorF("wglMakeCurrent error: %s\n", glxWinErrorMessage());
+ DWORD ErrorCode=GetLastError();
+ ErrorF("wglMakeCurrent error: %x dc %p ctx %p\n", ErrorCode,gc->hDC,gc->ctx);
+ if (!ErrorCode)
+ {
+ ErrorF("Error code was 0, assuming no error.\n");
+ ret=TRUE;
+ }
}
}
// apparently make current could fail if the context is current in a different thread,
// but that shouldn't be able to happen in the current server...
- glxWinReleaseDC(hDrawWnd, drawDC, (__GLXWinDrawable *)drawPriv);
- if (readDC)
- glxWinReleaseDC(hReadWnd, readDC, (__GLXWinDrawable *)readPriv);
-
return ret;
}
static int
glxWinContextLoseCurrent(__GLXcontext *base)
{
- BOOL ret;
+ BOOL ret=TRUE;
__GLXWinContext *gc = (__GLXWinContext *)base;
+#ifdef _DEBUG
GLWIN_TRACE_MSG("glxWinContextLoseCurrent context %p (native ctx %p)", gc, gc->ctx);
glWinCallDelta();
+#endif
- ret = wglMakeCurrent(NULL, NULL); /* We don't need a DC when setting no current context */
- if (!ret)
- ErrorF("glxWinContextLoseCurrent error: %s\n", glxWinErrorMessage());
- __glXLastContext = NULL; /* Mesa does this; why? */
- // __glXFlushContextCache()
+ if (wglGetCurrentContext()==gc->ctx)
+ {
+ /* Only do this when we are sure we are currently the active, otherwise we are deactivating the wrong one (this is happening!!!) */
+ ret = wglMakeCurrent(NULL, NULL);
+ if (!ret)
+ ErrorF("glxWinContextLoseCurrent error: %s\n", glxWinErrorMessage());
+ }
+ else
+ {
+ return FALSE;
+ }
+
+ /* Since drawPriv is going to be set to zero in the context, we have to release the DC to */
+ if (gc->hDC && gc->base.drawPriv) glxWinReleaseDC(gc->hwnd, gc->hDC, (__GLXWinDrawable *)gc->base.drawPriv);
+ if (gc->hreadDC && gc->base.readPriv) glxWinReleaseDC(gc->hreadwnd, gc->hreadDC, (__GLXWinDrawable *)gc->base.readPriv);
+ gc->hDC=NULL;
+ gc->hreadDC=NULL;
+
+ base->isCurrent=FALSE; /* It looks like glx is not doing this */
- return TRUE;
+ return ret;
}
static int
@@ -1503,18 +1657,20 @@ glxWinContextDestroy(__GLXcontext *base)
if (gc->ctx)
{
+ BOOL ret;
/* It's bad style to delete the context while it's still current */
if (wglGetCurrentContext() == gc->ctx)
{
wglMakeCurrent(NULL, NULL);
}
- {
- BOOL ret = wglDeleteContext(gc->ctx);
- if (!ret)
- ErrorF("wglDeleteContext error: %s\n", glxWinErrorMessage());
- }
-
+ ret = wglDeleteContext(gc->ctx);
+ if (!ret)
+ ErrorF("wglDeleteContext error: %s\n", glxWinErrorMessage());
+ if (gc->base.drawPriv && gc->hDC) glxWinReleaseDC(gc->hwnd, gc->hDC, (__GLXWinDrawable *)gc->base.drawPriv);
+ if (gc->base.readPriv && gc->hreadDC) glxWinReleaseDC(gc->hreadwnd, gc->hreadDC, (__GLXWinDrawable *)gc->base.readPriv);
+ gc->hDC=NULL;
+ gc->hreadDC=NULL;
gc->ctx = NULL;
}
@@ -1552,7 +1708,7 @@ glxWinCreateContext(__GLXscreen *screen,
context->base.pGlxScreen = screen;
// actual native GL context creation is deferred until attach()
- context->ctx = NULL;
+ //context->ctx = NULL; already done with memset
context->shareContext = shareContext;
glWinSetupDispatchTable();
@@ -1777,8 +1933,10 @@ glxWinCreateConfigs(HDC hdc, glxWinScreen *screen)
break;
}
+#ifdef _DEBUG
if (glxWinDebugSettings.dumpPFD)
pfdOut(&pfd);
+#endif
if (!(pfd.dwFlags & (PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP)) || !(pfd.dwFlags & PFD_SUPPORT_OPENGL))
{
@@ -2049,7 +2207,10 @@ glxWinCreateConfigsExt(HDC hdc, glxWinScreen *screen)
/* fill in configs */
for (i = 0; i < numConfigs; i++)
{
- int values[num_attrs];
+ int sizevalues=num_attrs*sizeof(int);
+ int *values=(int*)_alloca(sizevalues);
+
+ memset(values,0,sizevalues);
c = &(result[i]);
c->base.next = NULL;