DXGL r87 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r86‎ | r87 | r88 >
Date:01:36, 25 January 2012
Author:admin
Status:new
Tags:
Comment:
Clean up DDraw surfaces when IDirectDraw object is deleted.
Begin adding threading support
Modified paths:
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDraw.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glThread.cpp (added) (history)
  • /ddraw/glThread.h (added) (history)

Diff [purge]

Index: ddraw/ddraw.vcxproj
@@ -171,6 +171,7 @@
172172 <ClInclude Include="glDirectDrawPalette.h" />
173173 <ClInclude Include="glDirectDrawSurface.h" />
174174 <ClInclude Include="glExtensions.h" />
 175+ <ClInclude Include="glThread.h" />
175176 <ClInclude Include="glutil.h" />
176177 <ClInclude Include="include\d3d.h" />
177178 <ClInclude Include="include\d3dcaps.h" />
@@ -213,6 +214,7 @@
214215 <ClCompile Include="glDirectDrawPalette.cpp" />
215216 <ClCompile Include="glDirectDrawSurface.cpp" />
216217 <ClCompile Include="glExtensions.cpp" />
 218+ <ClCompile Include="glThread.cpp" />
217219 <ClCompile Include="glutil.cpp" />
218220 <ClCompile Include="precomp.cpp">
219221 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">Create</PrecompiledHeader>
Index: ddraw/ddraw.vcxproj.filters
@@ -92,6 +92,9 @@
9393 <ClInclude Include="shadergen.h">
9494 <Filter>Header Files</Filter>
9595 </ClInclude>
 96+ <ClInclude Include="glThread.h">
 97+ <Filter>Header Files</Filter>
 98+ </ClInclude>
9699 </ItemGroup>
97100 <ItemGroup>
98101 <ClCompile Include="ddraw.cpp">
@@ -145,6 +148,9 @@
146149 <ClCompile Include="shadergen.cpp">
147150 <Filter>Source Files</Filter>
148151 </ClCompile>
 152+ <ClCompile Include="glThread.cpp">
 153+ <Filter>Source Files</Filter>
 154+ </ClCompile>
149155 </ItemGroup>
150156 <ItemGroup>
151157 <ResourceCompile Include="ddraw.rc">
Index: ddraw/glDirectDraw.cpp
@@ -578,7 +578,11 @@
579579 }
580580 if(surfaces)
581581 {
582 -
 582+ for(int i = 0; i < surfacecount; i++)
 583+ {
 584+ if(surfaces[i]) delete surfaces[i];
 585+ surfaces[i] = NULL;
 586+ }
583587 free(surfaces);
584588 }
585589 DeleteGL();
@@ -1544,6 +1548,12 @@
15451549 if(hrender) *hrender = hRenderWnd;
15461550 }
15471551
 1552+void glDirectDraw7::DeleteSurface(glDirectDrawSurface7 *surface)
 1553+{
 1554+ for(int i = 0; i < surfacecount; i++)
 1555+ if(surfaces[i] == surface) surfaces[i] = NULL;
 1556+}
 1557+
15481558 // DDRAW1 wrapper
15491559 glDirectDraw1::glDirectDraw1(glDirectDraw7 *gl_DD7)
15501560 {
Index: ddraw/glDirectDraw.h
@@ -105,6 +105,7 @@
106106 DWORD primaryx,primaryy,primaryrefresh,primarybpp;
107107 bool GetFullscreen(){return fullscreen;};
108108 void GetHandles(HWND *hwnd, HWND *hrender);
 109+ void DeleteSurface(glDirectDrawSurface7 *surface);
109110 glDirectDrawSurface7 *primary;
110111 bool hasHWnd;
111112 DIB dib;
Index: ddraw/glDirectDrawSurface.cpp
@@ -480,7 +480,6 @@
481481 else *error = DDERR_INVALIDPARAMS;
482482 }
483483 }
484 - //ddInterface->AddRef();
485484 }
486485 glDirectDrawSurface7::~glDirectDrawSurface7()
487486 {
@@ -496,7 +495,7 @@
497496 if(buffer) free(buffer);
498497 if(bigbuffer) free(bigbuffer);
499498 if(zbuffer) zbuffer->Release();
500 - ddInterface->Release();
 499+ ddInterface->DeleteSurface(this);
501500 }
502501 HRESULT WINAPI glDirectDrawSurface7::QueryInterface(REFIID riid, void** ppvObj)
503502 {
Index: ddraw/glThread.cpp
@@ -0,0 +1,19 @@
 2+// DXGL
 3+// Copyright (C) 2012 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+#include "glThread.h"
\ No newline at end of file
Index: ddraw/glThread.h
@@ -0,0 +1,31 @@
 2+// DXGL
 3+// Copyright (C) 2012 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#ifndef _GLTHREAD_H
 20+#define _GLTHREAD_H
 21+
 22+class glThread
 23+{
 24+public:
 25+ glThread(int width, int height, int bpp, bool fullscreen, HWND hWnd, glDirectDraw7 *glDD7);
 26+ ~glThread();
 27+ void ThreadEntry(void *entry);
 28+private:
 29+ glDirectDraw7 *ddInterface;
 30+};
 31+
 32+#endif //_GLTHREAD_H
\ No newline at end of file