ReactOS  0.4.13-dev-241-g63286c6
d3d9_helpers.c File Reference
#include <d3d9.h>
#include "d3d9_helpers.h"
#include <stdio.h>
#include <ddraw.h>
#include <debug.h>
Include dependency graph for d3d9_helpers.c:

Go to the source code of this file.

Macros

#define MEM_ALIGNMENT   0x20
 

Functions

BOOL ReadRegistryValue (IN DWORD ValueType, IN LPCSTR ValueName, OUT LPBYTE DataBuffer, IN OUT LPDWORD DataBufferSize)
 
HRESULT SafeFormatString (OUT LPSTR Buffer, IN DWORD BufferSize, IN LPCSTR FormatString,...)
 
HRESULT SafeCopyString (OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
 
HRESULT SafeAppendString (IN OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
 
HRESULT AlignedAlloc (IN OUT LPVOID *ppObject, IN SIZE_T dwSize)
 
VOID AlignedFree (IN OUT LPVOID pObject)
 

Variables

static LPCSTR D3D9_DebugRegPath = "Software\\Microsoft\\Direct3D"
 

Macro Definition Documentation

◆ MEM_ALIGNMENT

#define MEM_ALIGNMENT   0x20

Definition at line 15 of file d3d9_helpers.c.

Function Documentation

◆ AlignedAlloc()

HRESULT AlignedAlloc ( IN OUT LPVOID ppObject,
IN SIZE_T  dwSize 
)

Definition at line 95 of file d3d9_helpers.c.

96 {
97  ULONG_PTR AddressOffset;
98  ULONG AlignedMask = MEM_ALIGNMENT - 1;
99  CHAR *AlignedPtr;
100  ULONG_PTR *AlignedOffsetPtr;
101 
102  if (ppObject == 0)
103  return DDERR_INVALIDPARAMS;
104 
105  if (dwSize == 0)
106  {
107  *ppObject = NULL;
108  return S_OK;
109  }
110 
112 
113  AlignedPtr = (CHAR *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
114 
115  if (AlignedPtr == 0)
116  return DDERR_OUTOFMEMORY;
117 
118  AddressOffset = MEM_ALIGNMENT - ((ULONG_PTR)AlignedPtr & AlignedMask);
119 
120  AlignedPtr += AddressOffset;
121 
122  AlignedOffsetPtr = (ULONG_PTR *)(AlignedPtr - sizeof(ULONG));
123  *AlignedOffsetPtr = AddressOffset;
124 
125  *ppObject = (ULONG_PTR *)AlignedPtr;
126 
127  return S_OK;
128 }
#define MEM_ALIGNMENT
Definition: d3d9_helpers.c:15
char CHAR
Definition: xmlstorage.h:175
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define S_OK
Definition: intsafe.h:59
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79

Referenced by CreateD3D9(), CreateD3D9Cursor(), CreateD3D9HalDevice(), CreateD3D9MipMap(), CreateDirect3DSwapChain9(), InitD3D9BaseDevice(), and InitD3D9ResourceManager().

◆ AlignedFree()

VOID AlignedFree ( IN OUT LPVOID  pObject)

Definition at line 130 of file d3d9_helpers.c.

131 {
132  CHAR *NonAlignedPtr = pObject;
133  ULONG_PTR *AlignedPtr = pObject;
134 
135  if (pObject == 0)
136  return;
137 
138  NonAlignedPtr -= *(AlignedPtr - 1);
139 
140  HeapFree(GetProcessHeap(), 0, NonAlignedPtr);
141 }
char CHAR
Definition: xmlstorage.h:175
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define GetProcessHeap()
Definition: compat.h:395
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by CreateD3D9(), CreateD3D9HalDevice(), D3D9BaseObject_Destroy(), IDirect3D9Impl_Release(), and IDirect3DDevice9Base_Release().

◆ ReadRegistryValue()

BOOL ReadRegistryValue ( IN DWORD  ValueType,
IN LPCSTR  ValueName,
OUT LPBYTE  DataBuffer,
IN OUT LPDWORD  DataBufferSize 
)

Definition at line 19 of file d3d9_helpers.c.

20 {
21  HKEY hKey;
22  DWORD Type;
23  LONG Ret;
24 
26  return FALSE;
27 
28  Ret = RegQueryValueExA(hKey, ValueName, 0, &Type, DataBuffer, DataBufferSize);
29 
30  RegCloseKey(hKey);
31 
32  if (ERROR_SUCCESS != Ret)
33  return FALSE;
34 
35  if (Type != ValueType)
36  return FALSE;
37 
38  return TRUE;
39 }
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4041
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4000
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3346
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
long LONG
Definition: pedump.c:60
static LPCSTR D3D9_DebugRegPath
Definition: d3d9_helpers.c:17
unsigned long DWORD
Definition: ntddk_ex.h:95
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by CreateInternalDeviceData(), Direct3DCreate9(), CRegistryFolder::FormatContentsForDisplay(), and GetD3D9DriverInfo().

◆ SafeAppendString()

HRESULT SafeAppendString ( IN OUT LPSTR  Dst,
IN DWORD  DstSize,
IN LPCSTR  Src 
)

Definition at line 83 of file d3d9_helpers.c.

84 {
85  size_t CurrentDstLength;
86 
87  if (Dst == NULL || DstSize == 0)
88  return DDERR_INVALIDPARAMS;
89 
90  CurrentDstLength = strlen(Dst);
91 
92  return SafeCopyString(Dst + CurrentDstLength, DstSize - CurrentDstLength, Src);
93 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
HRESULT SafeCopyString(OUT LPSTR Dst, IN DWORD DstSize, IN LPCSTR Src)
Definition: d3d9_helpers.c:61
smooth NULL
Definition: ftsmooth.c:416
#define Dst
Definition: mesh.h:153
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79

Referenced by GetDriverName().

◆ SafeCopyString()

HRESULT SafeCopyString ( OUT LPSTR  Dst,
IN DWORD  DstSize,
IN LPCSTR  Src 
)

Definition at line 61 of file d3d9_helpers.c.

62 {
64 
65  if (Dst == NULL || DstSize == 0 || Src == NULL)
66  return DDERR_INVALIDPARAMS;
67 
68  while (*Src != '\0' && DstSize > 0)
69  {
70  *Dst++ = *Src++;
71  --DstSize;
72  }
73 
74  if (DstSize == 0)
75  {
76  --Dst;
77  hr = DDERR_GENERIC;
78  }
79 
80  return hr;
81 }
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
smooth NULL
Definition: ftsmooth.c:416
#define DDERR_GENERIC
Definition: ddraw.h:72
LONG HRESULT
Definition: typedefs.h:77
#define Dst
Definition: mesh.h:153
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79

Referenced by CreateInternalDeviceData(), and SafeAppendString().

◆ SafeFormatString()

HRESULT SafeFormatString ( OUT LPSTR  Buffer,
IN DWORD  BufferSize,
IN LPCSTR  FormatString,
  ... 
)

Definition at line 41 of file d3d9_helpers.c.

42 {
44  va_list vargs;
45 
46  if (BufferSize == 0)
47  return DDERR_INVALIDPARAMS;
48 
49  va_start(vargs, FormatString);
51  va_end(vargs);
52 
54  return DDERR_GENERIC;
55 
56  Buffer[BufferSize-1] = '\0';
57 
58  return ERROR_SUCCESS;
59 }
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesWritten
Definition: fltkernel.h:1293
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:48
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
#define DDERR_GENERIC
Definition: ddraw.h:72
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define _vsnprintf
Definition: xmlstorage.h:202
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79

Referenced by Direct3DCreate9().

Variable Documentation

◆ D3D9_DebugRegPath

LPCSTR D3D9_DebugRegPath = "Software\\Microsoft\\Direct3D"
static

Definition at line 17 of file d3d9_helpers.c.

Referenced by ReadRegistryValue().