[ros-diffs] [gbrunmar] 32542: * Implemented IDirect3D::CheckDeviceFormatConversion() * Replaced all LocalAlloc() with HeapAlloc() and LocalFree() with HeapFree() on recommendation from GreatLord

gbrunmar at svn.reactos.org gbrunmar at svn.reactos.org
Sun Mar 9 12:32:47 CET 2008


Author: gbrunmar
Date: Sun Mar  2 15:12:24 2008
New Revision: 32542

URL: http://svn.reactos.org/svn/reactos?rev=3D32542&view=3Drev
Log:
* Implemented IDirect3D::CheckDeviceFormatConversion()
* Replaced all LocalAlloc() with HeapAlloc() and LocalFree() with HeapFree(=
) on recommendation from GreatLord

Modified:
    trunk/reactos/dll/directx/d3d9/adapter.c
    trunk/reactos/dll/directx/d3d9/d3d9_create.c
    trunk/reactos/dll/directx/d3d9/d3d9_helpers.c
    trunk/reactos/dll/directx/d3d9/d3d9_impl.c
    trunk/reactos/dll/directx/d3d9/d3d9_private.h
    trunk/reactos/dll/directx/d3d9/format.c
    trunk/reactos/dll/directx/d3d9/format.h

Modified: trunk/reactos/dll/directx/d3d9/adapter.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/adap=
ter.c?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/adapter.c (original)
+++ trunk/reactos/dll/directx/d3d9/adapter.c Sun Mar  2 15:12:24 2008
@@ -86,7 +86,7 @@
     if (DriverFileSize > 0)
     {
         VS_FIXEDFILEINFO* FixedFileInfo =3D NULL;
-        LPVOID pBlock =3D LocalAlloc(LMEM_ZEROINIT, DriverFileSize);
+        LPVOID pBlock =3D HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Dr=
iverFileSize);
 =

         if (TRUE =3D=3D GetFileVersionInfoA(pIdentifier->Driver, 0, Driver=
FileSize, pBlock))
         {
@@ -97,7 +97,7 @@
             }
         }
 =

-        LocalFree(pBlock);
+        HeapFree(GetProcessHeap(), 0, pBlock);
     }
 =

     if (bIsWow64)
@@ -292,7 +292,7 @@
         return Format;
     }
 =

-    pBitmapInfo =3D LocalAlloc(LMEM_ZEROINIT, sizeof(BITMAPINFOHEADER) + 4=
 * sizeof(RGBQUAD));
+    pBitmapInfo =3D HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(B=
ITMAPINFOHEADER) + 4 * sizeof(RGBQUAD));
     if (NULL =3D=3D pBitmapInfo)
     {
         DeleteObject(hBitmap);
@@ -316,7 +316,7 @@
         }
     }
 =

-    LocalFree(pBitmapInfo);
+    HeapFree(GetProcessHeap(), 0, pBitmapInfo);
     DeleteObject(hBitmap);
     DeleteDC(hDC);
 =


Modified: trunk/reactos/dll/directx/d3d9/d3d9_create.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9=
_create.c?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/d3d9_create.c (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_create.c Sun Mar  2 15:12:24 2008
@@ -65,7 +65,7 @@
     if (NULL =3D=3D (hDC =3D CreateDCA(NULL, pDisplayAdapter->szDeviceName=
, NULL, NULL)))
         return FALSE;
 =

-    pDeviceData =3D LocalAlloc(LMEM_ZEROINIT, sizeof(D3D9_DEVICEDATA));
+    pDeviceData =3D HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D=
3D9_DEVICEDATA));
     if (NULL =3D=3D pDeviceData)
     {
         DPRINT1("Out of memory, could not initialize Direct3D adapter");

Modified: trunk/reactos/dll/directx/d3d9/d3d9_helpers.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9=
_helpers.c?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/d3d9_helpers.c (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_helpers.c Sun Mar  2 15:12:24 2008
@@ -64,7 +64,7 @@
 =

     dwSize +=3D MEM_ALIGNMENT;
 =

-    AlignedPtr =3D (CHAR *)LocalAlloc(LMEM_ZEROINIT, dwSize);
+    AlignedPtr =3D (CHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, d=
wSize);
 =

     if (AlignedPtr =3D=3D 0)
         return DDERR_OUTOFMEMORY;
@@ -91,5 +91,5 @@
 =

     NonAlignedPtr -=3D *(AlignedPtr - 1);
 =

-    LocalFree(NonAlignedPtr);
+    HeapFree(GetProcessHeap(), 0, NonAlignedPtr);
 }

Modified: trunk/reactos/dll/directx/d3d9/d3d9_impl.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9=
_impl.c?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/d3d9_impl.c (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_impl.c Sun Mar  2 15:12:24 2008
@@ -640,12 +640,79 @@
     return D3D_OK;
 }
 =

+
+/*++
+* @name IDirect3D9::CheckDeviceFormatConversion
+* @implemented
+*
+* The function IDirect3D9Impl_CheckDeviceFormatConversion checks if a spec=
ific D3DFORMAT
+* can be converted to another on the specified display adapter.
+*
+* @param LPDIRECT3D iface
+* Pointer to the IDirect3D object returned from Direct3DCreate9()
+*
+* @param UINT Adapter
+* Adapter index to get information about. D3DADAPTER_DEFAULT is the primar=
y display.
+* The maximum value for this is the value returned by IDirect3D::GetAdapte=
rCount().
+*
+* @param D3DDEVTYPE DeviceType
+* One of the D3DDEVTYPE enum members. Only D3DDEVTYPE_HAL can potentially =
return D3D_OK.
+*
+* @param D3DFORMAT SourceFormat
+* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display =
adapter mode to be converted from.
+*
+* @param D3DFORMAT TargetFormat
+* One of the D3DFORMAT enum members except D3DFMT_UNKNOWN for the display =
adapter mode to be converted to.
+*
+* @return HRESULT
+* If the SourceFormat can be converted to the TargetFormat, the method ret=
urns D3D_OK.
+* If the SourceFormat can NOT be converted to the TargetFormat, the method=
 returns D3DERR_NOTAVAILABLE.
+* If Adapter is out of range, DeviceType is invalid,
+* SourceFormat or TargetFormat is invalid, the method returns D3DERR_INVAL=
IDCALL.
+*
+*/
 static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3=
D9 iface, UINT Adapter, D3DDEVTYPE DeviceType,
                                                                  D3DFORMAT=
 SourceFormat, D3DFORMAT TargetFormat)
 {
-    UNIMPLEMENTED
-
-    return D3D_OK;
+    HRESULT hResult;
+    LPDIRECT3D9_INT This =3D impl_from_IDirect3D9(iface);
+    LOCK_D3D9();
+
+    if (Adapter >=3D This->NumDisplayAdapters)
+    {
+        DPRINT1("Invalid Adapter number specified");
+        UNLOCK_D3D9();
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (DeviceType !=3D D3DDEVTYPE_HAL &&
+        DeviceType !=3D D3DDEVTYPE_REF &&
+        DeviceType !=3D D3DDEVTYPE_SW)
+    {
+        DPRINT1("Invalid DeviceType specified");
+        UNLOCK_D3D9();
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (SourceFormat =3D=3D D3DFMT_UNKNOWN ||
+        TargetFormat =3D=3D D3DFMT_UNKNOWN)
+    {
+        DPRINT1("Invalid D3DFORMAT specified");
+        UNLOCK_D3D9();
+        return D3DERR_NOTAVAILABLE;
+    }
+
+    if (DeviceType =3D=3D D3DDEVTYPE_HAL)
+    {
+        hResult =3D CheckDeviceFormatConversion(&This->DisplayAdapters[Ada=
pter].DriverCaps, SourceFormat, TargetFormat);
+    }
+    else
+    {
+        hResult =3D D3DERR_NOTAVAILABLE;
+    }
+
+    UNLOCK_D3D9();
+    return hResult;
 }
 =

 =


Modified: trunk/reactos/dll/directx/d3d9/d3d9_private.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9=
_private.h?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/d3d9_private.h (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_private.h Sun Mar  2 15:12:24 2008
@@ -89,7 +89,7 @@
 /* 0x0220 */    CHAR szDeviceName[CCHDEVICENAME];
 /* 0x0240 */    HDC hDC;
 /* 0x0244 */    GUID DisplayGuid;
-/* 0x0254 */    LPDWORD pUnknown0254; //D3D9_Unknown6BC_INT* pUnknown6BC; =
 // hDirectDrawLocal =

+/* 0x0254 */    LPDWORD pUnknown0254; //D3D9_Unknown6BC_INT* pUnknown6BC;
 /* 0x0258 */    D3DDEVTYPE DeviceType;
 /* 0x025c */    HMODULE hD3DRefDll;
 /* 0x0260 */    DWORD unknown0152;
@@ -103,7 +103,7 @@
 /* 0x0118 */    BOOL bInUseFlag;
 /* 0x011c */    DWORD MasterAdapterIndex;
 /* 0x0120 */    DWORD AdapterIndexInGroup;
-/* 0x0124 */    DWORD NumAdaptersInGroup;    /* 0x00000001 */
+/* 0x0124 */    DWORD NumAdaptersInGroup;
 /* 0x0128 */    DWORD NumSupportedD3DFormats;
 /* 0x012c */    DWORD NumSupportedD3DExtendedFormats;
 /* 0x0130 */    D3DDISPLAYMODE* pSupportedD3DFormats;
@@ -116,7 +116,7 @@
 =

 typedef struct _tagDIRECT3D9_INT_
 {
-/* 0x0000 */    struct IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 functoions =
table */
+/* 0x0000 */    struct IDirect3D9Vtbl *lpVtbl; /* LPDIRECTD3D9 function ta=
ble */
 /* 0x0004 */    CRITICAL_SECTION d3d9_cs;
 /* 0x001c */    DWORD unknown000007;    /* 0x00000001 */
 /* 0x0020 */    DWORD dwProcessId;

Modified: trunk/reactos/dll/directx/d3d9/format.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/form=
at.c?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/format.c (original)
+++ trunk/reactos/dll/directx/d3d9/format.c Sun Mar  2 15:12:24 2008
@@ -31,6 +31,20 @@
 BOOL IsMultiElementFormat(D3DFORMAT Format)
 {
     return (Format =3D=3D D3DFMT_MULTI2_ARGB8);
+}
+
+BOOL IsFourCCFormat(D3DFORMAT Format)
+{
+    CHAR* cFormat =3D (CHAR*)&Format;
+    if (isalnum(cFormat[0]) &&
+        isalnum(cFormat[1]) &&
+        isalnum(cFormat[2]) &&
+        isalnum(cFormat[3]))
+    {
+        return TRUE;
+    }
+
+    return FALSE;
 }
 =

 BOOL IsSupportedFormatOp(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT DisplayF=
ormat, DWORD FormatOp)
@@ -321,3 +335,47 @@
 =

     return D3DERR_NOTAVAILABLE;
 }
+
+HRESULT CheckDeviceFormatConversion(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORM=
AT SourceFormat, D3DFORMAT TargetFormat)
+{
+    D3DFORMAT NonAlphaSourceFormat;
+    D3DFORMAT NonAlphaTargetFormat;
+
+    NonAlphaSourceFormat =3D RemoveAlphaChannel(SourceFormat);
+    NonAlphaTargetFormat =3D RemoveAlphaChannel(TargetFormat);
+
+    if (NonAlphaSourceFormat =3D=3D NonAlphaTargetFormat)
+    {
+        return D3D_OK;
+    }
+
+    if (FALSE =3D=3D IsFourCCFormat(SourceFormat))
+    {
+        switch (SourceFormat)
+        {
+        case D3DFMT_A8R8G8B8:
+        case D3DFMT_X8R8G8B8:
+        case D3DFMT_R5G6B5:
+        case D3DFMT_X1R5G5B5:
+        case D3DFMT_A1R5G5B5:
+        case D3DFMT_A2R10G10B10:
+            /* Do nothing, valid SourceFormat */
+            break;
+
+        default:
+            return D3DERR_NOTAVAILABLE;
+        }
+    }
+    else if (pDriverCaps->DriverCaps9.DevCaps2 =3D=3D 0)
+    {
+        return D3D_OK;
+    }
+
+    if (FALSE =3D=3D IsSupportedFormatOp(pDriverCaps, SourceFormat, D3DFOR=
MAT_OP_CONVERT_TO_ARGB) ||
+        FALSE =3D=3D IsSupportedFormatOp(pDriverCaps, TargetFormat, D3DFOR=
MAT_MEMBEROFGROUP_ARGB))
+    {
+        return D3DERR_NOTAVAILABLE;
+    }
+
+    return D3D_OK;
+}

Modified: trunk/reactos/dll/directx/d3d9/format.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/form=
at.h?rev=3D32542&r1=3D32541&r2=3D32542&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/reactos/dll/directx/d3d9/format.h (original)
+++ trunk/reactos/dll/directx/d3d9/format.h Sun Mar  2 15:12:24 2008
@@ -33,4 +33,6 @@
 =

 HRESULT CheckDeviceFormat(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORMAT Adapter=
Format, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat);
 =

+HRESULT CheckDeviceFormatConversion(LPD3D9_DRIVERCAPS pDriverCaps, D3DFORM=
AT SourceFormat, D3DFORMAT TargetFormat);
+
 #endif // _FORMAT_H_




More information about the Ros-diffs mailing list