DXGL r492 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r491‎ | r492 | r493 >
Date:17:08, 17 August 2014
Author:admin
Status:new
Tags:
Comment:
Add EnumSurfaces and DuplicateSurface.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -895,9 +895,16 @@
896896 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
897897 if(!lpDDSurface) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
898898 if(!lplpDupDDSurface) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
899 - FIXME("IDirectDraw::DuplicateSurface: stub\n");
900 - TRACE_EXIT(23,DDERR_GENERIC);
901 - ERR(DDERR_GENERIC);
 899+ DDSURFACEDESC2 ddsd;
 900+ HRESULT ret;
 901+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 902+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 903+ lpDDSurface->GetSurfaceDesc(&ddsd);
 904+ ret = CreateSurface(&ddsd, lplpDupDDSurface, NULL);
 905+ if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
 906+ ret = (*lplpDupDDSurface)->Blt(NULL, lpDDSurface, NULL, 0, NULL);
 907+ TRACE_EXIT(23, ret);
 908+ return ret;
902909 }
903910 HRESULT WINAPI glDirectDraw7::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2, LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpEnumModesCallback)
904911 {
@@ -908,16 +915,95 @@
909916 TRACE_EXIT(23,ret);
910917 return ret;
911918 }
 919+
 920+HRESULT WINAPI EnumSurfacesCallback1(LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 lpDDSD2, LPVOID lpContext)
 921+{
 922+ LPVOID *lplpContext = (LPVOID*)lpContext;
 923+ LPDDENUMSURFACESCALLBACK callback = (LPDDENUMSURFACESCALLBACK)lplpContext[0];
 924+ LPVOID context = (LPVOID)lplpContext[1];
 925+ LPDIRECTDRAWSURFACE dds1;
 926+ DDSURFACEDESC ddsd;
 927+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
 928+ ddsd.dwSize = sizeof(DDSURFACEDESC);
 929+ lpDDSurface->QueryInterface(IID_IDirectDrawSurface, (void**)&dds1);
 930+ lpDDSurface->Release();
 931+ dds1->GetSurfaceDesc(&ddsd);
 932+ return callback(dds1, &ddsd, context);
 933+}
 934+HRESULT WINAPI EnumSurfacesCallback2(LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 lpDDSD2, LPVOID lpContext)
 935+{
 936+ LPVOID *lplpContext = (LPVOID*)lpContext;
 937+ LPDDENUMSURFACESCALLBACK2 callback = (LPDDENUMSURFACESCALLBACK2)lplpContext[0];
 938+ LPVOID context = (LPVOID)lplpContext[1];
 939+ LPDIRECTDRAWSURFACE4 dds4;
 940+ DDSURFACEDESC2 ddsd;
 941+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 942+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 943+ lpDDSurface->QueryInterface(IID_IDirectDrawSurface4, (void**)&dds4);
 944+ lpDDSurface->Release();
 945+ dds4->GetSurfaceDesc(&ddsd);
 946+ return callback(dds4, &ddsd, context);
 947+}
 948+
912949 HRESULT WINAPI glDirectDraw7::EnumSurfaces(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSD2, LPVOID lpContext, LPDDENUMSURFACESCALLBACK7 lpEnumSurfacesCallback)
913950 {
 951+ int i;
 952+ BOOL match;
 953+ HRESULT ret;
 954+ LPDIRECTDRAWSURFACE7 surface;
 955+ DDSURFACEDESC2 ddsd;
 956+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 957+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
914958 TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDSD2,14,lpContext,14,lpEnumSurfacesCallback);
915959 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
916 - if(!lpDDSD2) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 960+ if(!lpDDSD2 && !(dwFlags & DDENUMSURFACES_ALL)) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
917961 if(!lpEnumSurfacesCallback) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
918962 if(dwFlags & 0xFFFFFFE0) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
919 - FIXME("IDirectDraw::EnumSurfaces: stub\n");
920 - TRACE_EXIT(23,DDERR_GENERIC);
921 - ERR(DDERR_GENERIC);
 963+ if ((dwFlags & DDENUMSURFACES_CANBECREATED) && (dwFlags & DDENUMSURFACES_DOESEXIST)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 964+ if (!(dwFlags & DDENUMSURFACES_CANBECREATED) && !(dwFlags & DDENUMSURFACES_DOESEXIST)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 965+ if ((dwFlags & DDENUMSURFACES_CANBECREATED) && !(dwFlags & DDENUMSURFACES_MATCH)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 966+ if ((dwFlags & DDENUMSURFACES_ALL) && (dwFlags & DDENUMSURFACES_MATCH)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 967+ if ((dwFlags & DDENUMSURFACES_ALL) && (dwFlags & DDENUMSURFACES_NOMATCH)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 968+ if ((dwFlags & DDENUMSURFACES_MATCH) && (dwFlags & DDENUMSURFACES_NOMATCH)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 969+ if (dwFlags & DDENUMSURFACES_CANBECREATED)
 970+ {
 971+ // create surface
 972+ ret = CreateSurface(lpDDSD2, &surface, NULL);
 973+ if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
 974+ surface->GetSurfaceDesc(&ddsd);
 975+ lpEnumSurfacesCallback(surface, &ddsd, lpContext);
 976+ TRACE_EXIT(23, DD_OK);
 977+ return DD_OK;
 978+ }
 979+ else
 980+ {
 981+ for (i = 0; i < surfacecount; i++)
 982+ {
 983+ if (surfaces[i])
 984+ {
 985+ if (dwFlags & DDENUMSURFACES_ALL) match = TRUE;
 986+ if (dwFlags & DDENUMSURFACES_MATCH)
 987+ {
 988+ if (!memcmp(&surfaces[i]->ddsd, lpDDSD2, sizeof(DDSURFACEDESC2))) match = TRUE;
 989+ else match = FALSE;
 990+ }
 991+ if (dwFlags & DDENUMSURFACES_NOMATCH)
 992+ {
 993+ if (memcmp(&surfaces[i]->ddsd, lpDDSD2, sizeof(DDSURFACEDESC2))) match = TRUE;
 994+ else match = FALSE;
 995+ }
 996+ if (match)
 997+ {
 998+ surfaces[i]->AddRef();
 999+ surfaces[i]->GetSurfaceDesc(&ddsd);
 1000+ ret = lpEnumSurfacesCallback(surfaces[i], &ddsd, lpContext);
 1001+ if (ret == DDENUMRET_CANCEL) break;
 1002+ }
 1003+ }
 1004+ }
 1005+ }
 1006+ TRACE_EXIT(23,DD_OK);
 1007+ return DD_OK;
9221008 }
9231009 HRESULT WINAPI glDirectDraw7::FlipToGDISurface()
9241010 {
@@ -1888,10 +1974,19 @@
18891975 HRESULT WINAPI glDirectDraw1::DuplicateSurface(LPDIRECTDRAWSURFACE lpDDSurface, LPDIRECTDRAWSURFACE FAR *lplpDupDDSurface)
18901976 {
18911977 TRACE_ENTER(3,14,this,14,lpDDSurface,14,lplpDupDDSurface);
1892 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1893 - FIXME("glDirectDraw1::DuplicateSurface: stub\n");
1894 - TRACE_EXIT(23,DDERR_GENERIC);
1895 - ERR(DDERR_GENERIC);
 1978+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 1979+ if (!lpDDSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1980+ if (!lplpDupDDSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 1981+ DDSURFACEDESC ddsd;
 1982+ HRESULT ret;
 1983+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
 1984+ ddsd.dwSize = sizeof(DDSURFACEDESC);
 1985+ lpDDSurface->GetSurfaceDesc(&ddsd);
 1986+ ret = CreateSurface(&ddsd, lplpDupDDSurface, NULL);
 1987+ if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
 1988+ ret = (*lplpDupDDSurface)->Blt(NULL, lpDDSurface, NULL, 0, NULL);
 1989+ TRACE_EXIT(23, ret);
 1990+ return ret;
18961991 }
18971992 HRESULT WINAPI glDirectDraw1::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback)
18981993 {
@@ -1903,9 +1998,16 @@
19041999 {
19052000 TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDSD,14,lpContext,14,lpEnumSurfacesCallback);
19062001 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
1907 - FIXME("glDirectDraw1::EnumSurfaces: stub\n");
1908 - TRACE_EXIT(23,DDERR_GENERIC);
1909 - ERR(DDERR_GENERIC);
 2002+ if (!lpDDSD)TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2003+ if (lpDDSD->dwSize != sizeof(DDSURFACEDESC)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2004+ LPVOID context[2];
 2005+ context[0] = lpEnumSurfacesCallback;
 2006+ context[1] = lpContext;
 2007+ DDSURFACEDESC2 ddsd;
 2008+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2009+ memcpy(&ddsd, lpDDSD, sizeof(DDSURFACEDESC));
 2010+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2011+ TRACE_RET(HRESULT, 23, glDD7->EnumSurfaces(dwFlags, &ddsd, context, EnumSurfacesCallback1));
19102012 }
19112013 HRESULT WINAPI glDirectDraw1::FlipToGDISurface()
19122014 {
@@ -2075,10 +2177,19 @@
20762178 HRESULT WINAPI glDirectDraw2::DuplicateSurface(LPDIRECTDRAWSURFACE lpDDSurface, LPDIRECTDRAWSURFACE FAR *lplpDupDDSurface)
20772179 {
20782180 TRACE_ENTER(3,14,this,14,lpDDSurface,14,lplpDupDDSurface);
2079 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2080 - FIXME("glDirectDraw2::DuplicateSurface: stub\n");
2081 - TRACE_EXIT(23,DDERR_GENERIC);
2082 - ERR(DDERR_GENERIC);
 2181+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2182+ if (!lpDDSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2183+ if (!lplpDupDDSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2184+ DDSURFACEDESC ddsd;
 2185+ HRESULT ret;
 2186+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
 2187+ ddsd.dwSize = sizeof(DDSURFACEDESC);
 2188+ lpDDSurface->GetSurfaceDesc(&ddsd);
 2189+ ret = CreateSurface(&ddsd, lplpDupDDSurface, NULL);
 2190+ if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
 2191+ ret = (*lplpDupDDSurface)->Blt(NULL, lpDDSurface, NULL, 0, NULL);
 2192+ TRACE_EXIT(23, ret);
 2193+ return ret;
20832194 }
20842195 HRESULT WINAPI glDirectDraw2::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK lpEnumModesCallback)
20852196 {
@@ -2090,9 +2201,16 @@
20912202 {
20922203 TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDSD,14,lpContext,14,lpEnumSurfacesCallback);
20932204 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2094 - FIXME("glDirectDraw2::EnumSurfaces: stub\n");
2095 - TRACE_EXIT(23,DDERR_GENERIC);
2096 - ERR(DDERR_GENERIC);
 2205+ if (!lpDDSD)TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2206+ if (lpDDSD->dwSize != sizeof(DDSURFACEDESC)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2207+ LPVOID context[2];
 2208+ context[0] = lpEnumSurfacesCallback;
 2209+ context[1] = lpContext;
 2210+ DDSURFACEDESC2 ddsd;
 2211+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2212+ memcpy(&ddsd, lpDDSD, sizeof(DDSURFACEDESC));
 2213+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2214+ TRACE_RET(HRESULT, 23, glDD7->EnumSurfaces(dwFlags, &ddsd, context, EnumSurfacesCallback1));
20972215 }
20982216 HRESULT WINAPI glDirectDraw2::FlipToGDISurface()
20992217 {
@@ -2286,10 +2404,19 @@
22872405 HRESULT WINAPI glDirectDraw4::DuplicateSurface(LPDIRECTDRAWSURFACE4 lpDDSurface, LPDIRECTDRAWSURFACE4 FAR *lplpDupDDSurface)
22882406 {
22892407 TRACE_ENTER(3,14,this,14,lpDDSurface,14,lplpDupDDSurface);
2290 - if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2291 - FIXME("glDirectDraw4::DuplicateSurface: stub\n");
2292 - TRACE_EXIT(23,DDERR_GENERIC);
2293 - ERR(DDERR_GENERIC);
 2408+ if (!this) TRACE_RET(HRESULT, 23, DDERR_INVALIDOBJECT);
 2409+ if (!lpDDSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2410+ if (!lplpDupDDSurface) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2411+ DDSURFACEDESC2 ddsd;
 2412+ HRESULT ret;
 2413+ ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
 2414+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 2415+ lpDDSurface->GetSurfaceDesc(&ddsd);
 2416+ ret = CreateSurface(&ddsd, lplpDupDDSurface, NULL);
 2417+ if (ret != DD_OK) TRACE_RET(HRESULT, 23, ret);
 2418+ ret = (*lplpDupDDSurface)->Blt(NULL, lpDDSurface, NULL, 0, NULL);
 2419+ TRACE_EXIT(23, ret);
 2420+ return ret;
22942421 }
22952422 HRESULT WINAPI glDirectDraw4::EnumDisplayModes(DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc, LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpEnumModesCallback)
22962423 {
@@ -2301,9 +2428,12 @@
23022429 {
23032430 TRACE_ENTER(5,14,this,9,dwFlags,14,lpDDSD,14,lpContext,14,lpEnumSurfacesCallback);
23042431 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
2305 - FIXME("glDirectDraw4::EnumSurfaces: stub\n");
2306 - TRACE_EXIT(23,DDERR_GENERIC);
2307 - ERR(DDERR_GENERIC);
 2432+ if (!lpDDSD)TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2433+ if (lpDDSD->dwSize != sizeof(DDSURFACEDESC)) TRACE_RET(HRESULT, 23, DDERR_INVALIDPARAMS);
 2434+ LPVOID context[2];
 2435+ context[0] = lpEnumSurfacesCallback;
 2436+ context[1] = lpContext;
 2437+ TRACE_RET(HRESULT, 23, glDD7->EnumSurfaces(dwFlags, lpDDSD, context, EnumSurfacesCallback2));
23082438 }
23092439 HRESULT WINAPI glDirectDraw4::FlipToGDISurface()
23102440 {