From b20e4f29cd4efbb31dd410322dcd6293e8b11553 Mon Sep 17 00:00:00 2001 From: Kamil Hornicek Date: Mon, 14 Jun 2010 13:11:51 +0000 Subject: [PATCH] [OPENGL32] Fixes for ICD reference counting. By Jerome Gardou See issue #5257 for more details. svn path=/trunk/; revision=47780 --- reactos/dll/win32/opengl32/opengl32.c | 6 +----- reactos/dll/win32/opengl32/wgl.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/reactos/dll/win32/opengl32/opengl32.c b/reactos/dll/win32/opengl32/opengl32.c index 2dd3312a9ff..cf460079bee 100644 --- a/reactos/dll/win32/opengl32/opengl32.c +++ b/reactos/dll/win32/opengl32/opengl32.c @@ -472,8 +472,6 @@ OPENGL32_LoadICD( LPCWSTR driver ) { if (!_wcsicmp( driver, icd->driver_name )) /* found */ { - icd->refcount++; - /* release mutex */ if (!ReleaseMutex( OPENGL32_processdata.driver_mutex )) DBGPRINT( "Error: ReleaseMutex() failed (%d)", GetLastError() ); @@ -484,8 +482,6 @@ OPENGL32_LoadICD( LPCWSTR driver ) /* not found - try to load */ icd = OPENGL32_LoadDriver( driver ); - if (icd != NULL) - icd->refcount = 1; /* release mutex */ if (!ReleaseMutex( OPENGL32_processdata.driver_mutex )) @@ -513,7 +509,7 @@ OPENGL32_UnloadICD( GLDRIVERDATA *icd ) return FALSE; /* FIXME: do we have to expect such an error and handle it? */ } - if (--icd->refcount == 0) + if (icd->refcount == 0) ret = OPENGL32_UnloadDriver( icd ); /* release mutex */ diff --git a/reactos/dll/win32/opengl32/wgl.c b/reactos/dll/win32/opengl32/wgl.c index 953305b894d..aadf186e9ac 100644 --- a/reactos/dll/win32/opengl32/wgl.c +++ b/reactos/dll/win32/opengl32/wgl.c @@ -27,7 +27,6 @@ typedef struct _OPENGL_INFO WCHAR DriverName[256]; /*!< Driver name */ } OPENGL_INFO, *POPENGL_INFO; - /*! \brief Append OpenGL Rendering Context (GLRC) to list * * \param glrc [IN] Pointer to GLRC to append to list @@ -179,8 +178,11 @@ BOOL ROSGL_DeleteContext( GLRC *glrc ) { /* unload icd */ - if (glrc->icd != NULL) + if ((glrc->icd != NULL) && (!InterlockedDecrement((LONG*)&glrc->icd->refcount))) + { + /* This is the last context, remove the ICD*/ ROSGL_DeleteDCDataForICD( glrc->icd ); + } /* remove from list */ ROSGL_RemoveContext( glrc ); @@ -413,7 +415,7 @@ ROSGL_ICDForHDC( HDC hdc ) NULL) != NULL) { /* Too bad, somebody else was faster... */ - OPENGL32_UnloadICD(drvdata); + DBGTRACE("ICD is already set!\n"); } } } @@ -686,6 +688,9 @@ rosglCreateLayerContext( HDC hdc, int layer ) /* FIXME: fallback? */ return NULL; } + /* Don't forget to refcount it, icd will be released when last context is deleted */ + InterlockedIncrement((LONG*)&icd->refcount); + /* create context */ if (icd->DrvCreateLayerContext != NULL)