Index: ddraw/common.h |
— | — | @@ -104,6 +104,8 @@ |
105 | 105 | #define NextMultipleOfWord NextMultipleOf4
|
106 | 106 | #endif
|
107 | 107 |
|
| 108 | +extern CRITICAL_SECTION dll_cs;
|
| 109 | +
|
108 | 110 | #include "trace.h"
|
109 | 111 |
|
110 | 112 | #include "../cfgmgr/cfgmgr.h"
|
Index: ddraw/ddraw.cpp |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | #include <tlhelp32.h>
|
31 | 31 |
|
32 | 32 | DXGLCFG dxglcfg;
|
33 | | -bool gllock = false;
|
| 33 | +DWORD gllock = 0;
|
34 | 34 | HMODULE sysddraw = NULL;
|
35 | 35 | HRESULT (WINAPI *sysddrawcreate)(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter) = NULL;
|
36 | 36 |
|
— | — | @@ -36,9 +36,6 @@ |
37 | 37 | const GUID device_template =
|
38 | 38 | { 0x9ff8900, 0x8c4a, 0x4ba4, { 0xbf, 0x29, 0x56, 0x50, 0x4a, 0xf, 0x3b, 0xb3 } };
|
39 | 39 |
|
40 | | -DWORD timer;
|
41 | | -int vsyncstatus;
|
42 | | -glDirectDraw7 *dxglinterface = NULL;
|
43 | 40 |
|
44 | 41 | void InitGL(int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7)
|
45 | 42 | {
|
— | — | @@ -159,6 +156,7 @@ |
160 | 157 | {
|
161 | 158 | TRACE_ENTER(3,24,lpGUID,14,lplpDD,14,pUnkOuter);
|
162 | 159 | if(!lplpDD) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
|
| 160 | + EnterCriticalSection(&dll_cs);
|
163 | 161 | HRESULT ret;
|
164 | 162 | if(gllock || IsCallerOpenGL(_ReturnAddress()))
|
165 | 163 | {
|
— | — | @@ -170,6 +168,7 @@ |
171 | 169 | sysddraw = LoadLibraryA(buffer);
|
172 | 170 | if(!sysddraw)
|
173 | 171 | {
|
| 172 | + LeaveCriticalSection(&dll_cs);
|
174 | 173 | TRACE_EXIT(23,DDERR_GENERIC);
|
175 | 174 | ERR(DDERR_GENERIC);
|
176 | 175 | }
|
— | — | @@ -179,20 +178,17 @@ |
180 | 179 | sysddrawcreate = (HRESULT(WINAPI *)(GUID FAR*,LPDIRECTDRAW FAR*, IUnknown FAR*))GetProcAddress(sysddraw,"DirectDrawCreate");
|
181 | 180 | if(!sysddrawcreate)
|
182 | 181 | {
|
183 | | - TRACE_EXIT(23,DDERR_GENERIC);
|
| 182 | + LeaveCriticalSection(&dll_cs);
|
| 183 | + TRACE_EXIT(23, DDERR_GENERIC);
|
184 | 184 | ERR(DDERR_GENERIC);
|
185 | 185 | }
|
186 | 186 | }
|
187 | 187 | ret = sysddrawcreate(lpGUID,lplpDD,pUnkOuter);
|
188 | 188 | TRACE_VAR("*lplpDD",14,*lplpDD);
|
189 | | - TRACE_EXIT(23,ret);
|
| 189 | + LeaveCriticalSection(&dll_cs);
|
| 190 | + TRACE_EXIT(23, ret);
|
190 | 191 | return ret;
|
191 | 192 | }
|
192 | | - if(dxglinterface)
|
193 | | - {
|
194 | | - TRACE_EXIT(23,DDERR_DIRECTDRAWALREADYCREATED);
|
195 | | - return DDERR_DIRECTDRAWALREADYCREATED;
|
196 | | - }
|
197 | 193 | GetCurrentConfig(&dxglcfg,false);
|
198 | 194 | glDirectDraw7 *myddraw7;
|
199 | 195 | glDirectDraw1 *myddraw;
|
— | — | @@ -202,7 +198,8 @@ |
203 | 199 | if(error != DD_OK)
|
204 | 200 | {
|
205 | 201 | delete myddraw7;
|
206 | | - TRACE_EXIT(23,error);
|
| 202 | + LeaveCriticalSection(&dll_cs);
|
| 203 | + TRACE_EXIT(23, error);
|
207 | 204 | return error;
|
208 | 205 | }
|
209 | 206 | myddraw7->QueryInterface(IID_IDirectDraw,(VOID**)&myddraw);
|
— | — | @@ -209,7 +206,8 @@ |
210 | 207 | myddraw7->Release();
|
211 | 208 | *lplpDD = (LPDIRECTDRAW)myddraw;
|
212 | 209 | TRACE_VAR("*lplpDD",14,*lplpDD);
|
213 | | - TRACE_EXIT(23,error);
|
| 210 | + LeaveCriticalSection(&dll_cs);
|
| 211 | + TRACE_EXIT(23, error);
|
214 | 212 | return error;
|
215 | 213 | }
|
216 | 214 |
|
— | — | @@ -261,11 +259,6 @@ |
262 | 260 | {
|
263 | 261 | TRACE_ENTER(4,24,lpGUID,14,lplpDD,24,&iid,14,pUnkOuter);
|
264 | 262 | if(!lplpDD) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
|
265 | | - if(dxglinterface)
|
266 | | - {
|
267 | | - TRACE_EXIT(23,DDERR_DIRECTDRAWALREADYCREATED);
|
268 | | - return DDERR_DIRECTDRAWALREADYCREATED;
|
269 | | - }
|
270 | 263 | GetCurrentConfig(&dxglcfg,false);
|
271 | 264 | glDirectDraw7 *myddraw;
|
272 | 265 | HRESULT error;
|
Index: ddraw/ddraw.h |
— | — | @@ -57,13 +57,10 @@ |
58 | 58 | DDRAW_API BOOL IsDXGLDDraw();
|
59 | 59 |
|
60 | 60 | extern DXGLCFG dxglcfg;
|
61 | | -extern bool gllock;
|
| 61 | +extern DWORD gllock;
|
62 | 62 | extern const GUID device_template;
|
63 | | -extern DWORD timer;
|
64 | | -extern int vsyncstatus;
|
65 | 63 | class glRenderer;
|
66 | 64 | class glDirectDraw7;
|
67 | | -extern glDirectDraw7 *dxglinterface;
|
68 | 65 | void InitGL(int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7);
|
69 | 66 |
|
70 | 67 | #endif //_DDRAW_PRIVATE_H |
\ No newline at end of file |
Index: ddraw/dllmain.cpp |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | #include "common.h"
|
20 | 20 | #include "ddraw.h"
|
21 | 21 | ATOM WindowClass = NULL;
|
| 22 | +CRITICAL_SECTION dll_cs;
|
22 | 23 | BOOL APIENTRY DllMain( HMODULE hModule,
|
23 | 24 | DWORD ul_reason_for_call,
|
24 | 25 | LPVOID lpReserved
|
— | — | @@ -26,6 +27,7 @@ |
27 | 28 | switch (ul_reason_for_call)
|
28 | 29 | {
|
29 | 30 | case DLL_PROCESS_ATTACH:
|
| 31 | + InitializeCriticalSection(&dll_cs);
|
30 | 32 | GetCurrentConfig(&dxglcfg, true);
|
31 | 33 | break;
|
32 | 34 | case DLL_THREAD_ATTACH:
|
Index: ddraw/glDirectDraw.cpp |
— | — | @@ -572,7 +572,6 @@ |
573 | 573 | glDirectDraw7::glDirectDraw7(GUID FAR* lpGUID, IUnknown FAR* pUnkOuter)
|
574 | 574 | {
|
575 | 575 | TRACE_ENTER(3,14,this,24,lpGUID,14,pUnkOuter);
|
576 | | - dxglinterface = this;
|
577 | 576 | initialized = false;
|
578 | 577 | if(((ULONG_PTR)lpGUID > 2) && IsBadReadPointer(lpGUID))
|
579 | 578 | {
|
— | — | @@ -608,7 +607,6 @@ |
609 | 608 | glDirectDraw7::~glDirectDraw7()
|
610 | 609 | {
|
611 | 610 | TRACE_ENTER(1,14,this);
|
612 | | - dxglinterface = NULL;
|
613 | 611 | if(initialized)
|
614 | 612 | {
|
615 | 613 | if(glD3D7) glD3D7->Release();
|
Index: ddraw/glDirectDraw.h |
— | — | @@ -107,6 +107,7 @@ |
108 | 108 | DEVMODE oldmode;
|
109 | 109 | bool initialized;
|
110 | 110 | glDirect3D7 *glD3D7;
|
| 111 | + DWORD timer;
|
111 | 112 | };
|
112 | 113 |
|
113 | 114 | class glDirectDraw1 : public IDirectDraw
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -738,6 +738,7 @@ |
739 | 739 | */
|
740 | 740 | BOOL glRenderer::_InitGL(int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND hWnd, glDirectDraw7 *glDD7)
|
741 | 741 | {
|
| 742 | + EnterCriticalSection(&dll_cs);
|
742 | 743 | ddInterface = glDD7;
|
743 | 744 | if(hRC)
|
744 | 745 | {
|
— | — | @@ -753,11 +754,13 @@ |
754 | 755 | pfd.iPixelType = PFD_TYPE_RGBA;
|
755 | 756 | pfd.cColorBits = bpp;
|
756 | 757 | pfd.iLayerType = PFD_MAIN_PLANE;
|
757 | | - gllock = true;
|
| 758 | + InterlockedIncrement(&gllock);
|
758 | 759 | hDC = GetDC(RenderWnd->GetHWnd());
|
759 | 760 | if(!hDC)
|
760 | 761 | {
|
761 | 762 | DEBUG("glRenderer::InitGL: Can not create hDC\n");
|
| 763 | + InterlockedDecrement(&gllock);
|
| 764 | + LeaveCriticalSection(&dll_cs);
|
762 | 765 | return FALSE;
|
763 | 766 | }
|
764 | 767 | pf = ChoosePixelFormat(hDC,&pfd);
|
— | — | @@ -764,6 +767,8 @@ |
765 | 768 | if(!pf)
|
766 | 769 | {
|
767 | 770 | DEBUG("glRenderer::InitGL: Can not get pixelformat\n");
|
| 771 | + InterlockedDecrement(&gllock);
|
| 772 | + LeaveCriticalSection(&dll_cs);
|
768 | 773 | return FALSE;
|
769 | 774 | }
|
770 | 775 | if(!SetPixelFormat(hDC,pf,&pfd))
|
— | — | @@ -772,7 +777,8 @@ |
773 | 778 | if(!hRC)
|
774 | 779 | {
|
775 | 780 | DEBUG("glRenderer::InitGL: Can not create GL context\n");
|
776 | | - gllock = false;
|
| 781 | + InterlockedDecrement(&gllock);
|
| 782 | + LeaveCriticalSection(&dll_cs);
|
777 | 783 | return FALSE;
|
778 | 784 | }
|
779 | 785 | if(!wglMakeCurrent(hDC,hRC))
|
— | — | @@ -782,10 +788,12 @@ |
783 | 789 | hRC = NULL;
|
784 | 790 | ReleaseDC(RenderWnd->GetHWnd(),hDC);
|
785 | 791 | hDC = NULL;
|
786 | | - gllock = false;
|
| 792 | + InterlockedDecrement(&gllock);
|
| 793 | + LeaveCriticalSection(&dll_cs);
|
787 | 794 | return FALSE;
|
788 | 795 | }
|
789 | | - gllock = false;
|
| 796 | + InterlockedDecrement(&gllock);
|
| 797 | + LeaveCriticalSection(&dll_cs);
|
790 | 798 | ext = new glExtensions();
|
791 | 799 | util = new glUtil(ext);
|
792 | 800 | _SetSwap(1);
|
— | — | @@ -1298,13 +1306,14 @@ |
1299 | 1307 | {
|
1300 | 1308 | if(newwnd != hWnd)
|
1301 | 1309 | {
|
1302 | | - wglMakeCurrent(NULL,NULL);
|
| 1310 | + EnterCriticalSection(&dll_cs);
|
| 1311 | + wglMakeCurrent(NULL, NULL);
|
1303 | 1312 | ReleaseDC(hWnd,hDC);
|
1304 | 1313 | delete RenderWnd;
|
1305 | 1314 | RenderWnd = new glRenderWindow(width,height,fullscreen,newwnd,ddInterface);
|
1306 | 1315 | PIXELFORMATDESCRIPTOR pfd;
|
1307 | 1316 | GLuint pf;
|
1308 | | - gllock = true;
|
| 1317 | + InterlockedIncrement(&gllock);
|
1309 | 1318 | ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
|
1310 | 1319 | pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
1311 | 1320 | pfd.nVersion = 1;
|
— | — | @@ -1322,7 +1331,8 @@ |
1323 | 1332 | DEBUG("glRenderer::SetWnd: Can not set pixelformat\n");
|
1324 | 1333 | if(!wglMakeCurrent(hDC,hRC))
|
1325 | 1334 | DEBUG("glRenderer::SetWnd: Can not activate GL context\n");
|
1326 | | - gllock = false;
|
| 1335 | + InterlockedDecrement(&gllock);
|
| 1336 | + LeaveCriticalSection(&dll_cs);
|
1327 | 1337 | _SetSwap(1);
|
1328 | 1338 | SwapBuffers(hDC);
|
1329 | 1339 | timer.Calibrate(height, frequency);
|