DXGL r94 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r93‎ | r94 | r95 >
Date:02:53, 31 January 2012
Author:admin
Status:new
Tags:
Comment:
Verify a few pointers
Add 15, 16, 24, and 32-bit RGB surface pixelformats
Modified paths:
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)

Diff [purge]

Index: ddraw/ddraw.cpp
@@ -35,6 +35,21 @@
3636 int vsyncstatus;
3737 bool ddenabled = false;
3838
 39+bool IsBadReadPointer(void *ptr)
 40+{
 41+ char a;
 42+ try
 43+ {
 44+ a = *(char*)ptr;
 45+ if(a == *(char*)ptr) return false;
 46+ else return true;
 47+ }
 48+ catch(...)
 49+ {
 50+ return true;
 51+ }
 52+}
 53+
3954 DDRAW_API void WINAPI AcquireDDThreadLock()
4055 {
4156 // FIXME: Add thread lock
@@ -155,6 +170,7 @@
156171
157172 HRESULT WINAPI DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback, LPVOID lpContext)
158173 {
 174+ if(IsBadReadPointer(lpCallback)) return DDERR_INVALIDPARAMS;
159175 LPVOID context[2];
160176 context[0] = (LPVOID) lpCallback;
161177 context[1] = lpContext;
@@ -170,6 +186,7 @@
171187
172188 HRESULT WINAPI DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback, LPVOID lpContext)
173189 {
 190+ if(IsBadReadPointer(lpCallback)) return DDERR_INVALIDPARAMS;
174191 LPVOID context[2];
175192 context[0] = (LPVOID) lpCallback;
176193 context[1] = lpContext;
@@ -189,6 +206,7 @@
190207
191208 HRESULT WINAPI DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags)
192209 {
 210+ if(IsBadReadPointer(lpCallback)) return DDERR_INVALIDPARAMS;
193211 LPVOID context[2];
194212 context[0] = (LPVOID) lpCallback;
195213 context[1] = lpContext;
@@ -212,6 +230,7 @@
213231
214232 HRESULT WINAPI DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback, LPVOID lpContext, DWORD dwFlags)
215233 {
 234+ if(IsBadReadPointer(lpCallback)) return DDERR_INVALIDPARAMS;
216235 int *monitors = NULL;
217236 GUID guid;
218237 MONITORINFOEXW monitorinfo;
@@ -255,7 +274,7 @@
256275 }
257276 DDRAW_API HANDLE WINAPI GetOLEThunkData(int i1)
258277 {
259 - FIXME("GetOleThunkData: stub\n");
 278+ DEBUG("GetOleThunkData: stub\n");
260279 return 0;
261280 }
262281 DDRAW_API HRESULT WINAPI GlobalGetSurfaceFromDC(LPDIRECTDRAW7 lpDD, HDC hdc, LPDIRECTDRAWSURFACE7 *lpDDS)
Index: ddraw/ddraw.vcxproj
@@ -84,6 +84,7 @@
8585 <PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;_USRDLL;DDRAW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
8686 <AdditionalIncludeDirectories>../include;../glew/glew-1.6.0/include</AdditionalIncludeDirectories>
8787 <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
 88+ <ExceptionHandling>Async</ExceptionHandling>
8889 </ClCompile>
8990 <Link>
9091 <SubSystem>Windows</SubSystem>
@@ -100,6 +101,7 @@
101102 <PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;_USRDLL;DDRAW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
102103 <AdditionalIncludeDirectories>../include;../glew/glew-1.6.0/include</AdditionalIncludeDirectories>
103104 <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
 105+ <ExceptionHandling>Async</ExceptionHandling>
104106 </ClCompile>
105107 <Link>
106108 <SubSystem>Windows</SubSystem>
@@ -121,6 +123,7 @@
122124 <PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;_USRDLL;DDRAW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
123125 <AdditionalIncludeDirectories>../include;../glew/glew-1.6.0/include</AdditionalIncludeDirectories>
124126 <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
 127+ <ExceptionHandling>Async</ExceptionHandling>
125128 </ClCompile>
126129 <Link>
127130 <SubSystem>Windows</SubSystem>
@@ -142,6 +145,7 @@
143146 <PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;_USRDLL;DDRAW_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
144147 <AdditionalIncludeDirectories>../include;../glew/glew-1.6.0/include</AdditionalIncludeDirectories>
145148 <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
 149+ <ExceptionHandling>Async</ExceptionHandling>
146150 </ClCompile>
147151 <Link>
148152 <SubSystem>Windows</SubSystem>
Index: ddraw/glDirectDraw.cpp
@@ -548,6 +548,10 @@
549549
550550 glDirectDraw7::glDirectDraw7()
551551 {
 552+ glD3D7 = NULL;
 553+ clippers = NULL;
 554+ surfaces = NULL;
 555+ renderer = NULL;
552556 initialized = false;
553557 devid.liDriverVersion.QuadPart = DXGLVERQWORD;
554558 refcount = 1;
@@ -701,6 +705,7 @@
702706 }
703707 HRESULT WINAPI glDirectDraw7::CreateSurface(LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPDIRECTDRAWSURFACE7 FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
704708 {
 709+ if(!lpDDSurfaceDesc2) return DDERR_INVALIDPARAMS;
705710 if(primary && (lpDDSurfaceDesc2->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) && (renderer->hRC == primary->hRC) )
706711 {
707712 if(primarylost)
@@ -899,7 +904,7 @@
900905 }
901906 HRESULT WINAPI glDirectDraw7::GetVerticalBlankStatus(LPBOOL lpbIsInVB)
902907 {
903 - FIXME("IDirectDraw::GetVerticalBlankStatis: stub\n");
 908+ FIXME("IDirectDraw::GetVerticalBlankStatus: stub\n");
904909 ERR(DDERR_GENERIC);
905910 }
906911 HRESULT WINAPI glDirectDraw7::Initialize(GUID FAR *lpGUID)
@@ -1513,6 +1518,7 @@
15141519 }
15151520 HRESULT WINAPI glDirectDraw2::CreateSurface(LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR *lplpDDSurface, IUnknown FAR *pUnkOuter)
15161521 {
 1522+ if(!lplpDDSurface) return DDERR_INVALIDPARAMS;
15171523 LPDIRECTDRAWSURFACE7 lpDDS7;
15181524 HRESULT err = glDD7->CreateSurface((LPDDSURFACEDESC2)lpDDSurfaceDesc,&lpDDS7,pUnkOuter);
15191525 if(err == DD_OK)
Index: ddraw/glDirectDrawSurface.cpp
@@ -235,12 +235,57 @@
236236 ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth);
237237 break;
238238 case 16:
239 - FIXME("Support 16 bit pixelformat");
 239+ if((ddsd.ddpfPixelFormat.dwRBitMask == 0x7C00) && (ddsd.ddpfPixelFormat.dwGBitMask == 0x3E0)
 240+ && (ddsd.ddpfPixelFormat.dwBBitMask == 0x1F))
 241+ {
 242+ texformat = GL_BGRA;
 243+ texformat2 = GL_UNSIGNED_SHORT_1_5_5_5_REV;
 244+ if(dxglcfg.texformat) texformat3 = GL_RGB5_A1;
 245+ else texformat3 = GL_RGBA8;
 246+ }
 247+ else // fixme: support more formats
 248+ {
 249+ texformat = GL_RGB;
 250+ texformat2 = GL_UNSIGNED_SHORT_5_6_5;
 251+ if(dxglcfg.texformat) texformat3 = GL_RGB;
 252+ else texformat3 = GL_RGBA8;
 253+ }
 254+ ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*2);
 255+ break;
240256 case 24:
241 - FIXME("Support 24 bit pixelformat");
 257+ if((ddsd.ddpfPixelFormat.dwRBitMask == 0xFF0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0xFF00)
 258+ && (ddsd.ddpfPixelFormat.dwBBitMask == 0xFF))
 259+ {
 260+ texformat = GL_BGR;
 261+ texformat2 = GL_UNSIGNED_BYTE;
 262+ if(dxglcfg.texformat) texformat3 = GL_RGB8;
 263+ else texformat3 = GL_RGBA8;
 264+ }
 265+ else // fixme: support more formats
 266+ {
 267+ texformat = GL_RGB;
 268+ texformat2 = GL_UNSIGNED_BYTE;
 269+ if(dxglcfg.texformat) texformat3 = GL_RGB8;
 270+ else texformat3 = GL_RGBA8;
 271+ }
 272+ ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*3);
 273+ break;
242274 case 32:
243275 default:
244 - FIXME("Support 32 bit pixelformat");
 276+ if((ddsd.ddpfPixelFormat.dwRBitMask == 0xFF0000) && (ddsd.ddpfPixelFormat.dwGBitMask == 0xFF00)
 277+ && (ddsd.ddpfPixelFormat.dwBBitMask == 0xFF))
 278+ {
 279+ texformat = GL_BGRA;
 280+ texformat2 = GL_UNSIGNED_BYTE;
 281+ texformat3 = GL_RGBA8;
 282+ }
 283+ else // fixme: support more formats
 284+ {
 285+ texformat = GL_RGBA;
 286+ texformat2 = GL_UNSIGNED_BYTE;
 287+ texformat3 = GL_RGBA8;
 288+ }
 289+ ddsd.lPitch = NextMultipleOfWord(ddsd.dwWidth*4);
245290 }
246291 }
247292 else if(ddsd.ddpfPixelFormat.dwFlags & DDPF_ZBUFFER)