[1/6] d3dx9: Introduce helper functions to operate on constant handles.
Józef Kucia
joseph.kucia at gmail.com
Tue Aug 14 04:42:30 CDT 2012
---
dlls/d3dx9_36/shader.c | 31 ++++++++++++++++++++++---------
1 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c
index e0229f6..0e6b071 100644
--- a/dlls/d3dx9_36/shader.c
+++ b/dlls/d3dx9_36/shader.c
@@ -657,6 +657,21 @@ static DWORD calc_bytes(D3DXCONSTANT_DESC *desc)
return 4 * desc->Elements * desc->Rows * desc->Columns;
}
+static inline int is_constant_handle(D3DXHANDLE handle)
+{
+ return !((UINT_PTR)handle >> 16);
+}
+
+static inline ctab_constant *constant_from_handle(struct ID3DXConstantTableImpl *table, D3DXHANDLE handle)
+{
+ return &table->constants[(UINT_PTR)handle - 1];
+}
+
+static inline D3DXHANDLE handle_from_constant_index(UINT index)
+{
+ return (D3DXHANDLE)(DWORD_PTR)(index + 1);
+}
+
/*** IUnknown methods ***/
static HRESULT WINAPI ID3DXConstantTableImpl_QueryInterface(ID3DXConstantTable *iface, REFIID riid, void **out)
{
@@ -747,17 +762,15 @@ static HRESULT WINAPI ID3DXConstantTableImpl_GetConstantDesc(ID3DXConstantTable
return D3DERR_INVALIDCALL;
/* Applications can pass the name of the constant in place of the handle */
- if (!((UINT_PTR)constant >> 16))
- constant_info = &This->constants[(UINT_PTR)constant - 1];
- else
+ if (!is_constant_handle(constant))
{
- D3DXHANDLE c = ID3DXConstantTable_GetConstantByName(iface, NULL, constant);
- if (!c)
+ constant = ID3DXConstantTable_GetConstantByName(iface, NULL, constant);
+ if (!constant)
return D3DERR_INVALIDCALL;
-
- constant_info = &This->constants[(UINT_PTR)c - 1];
}
+ constant_info = constant_from_handle(This, constant);
+
if (desc)
*desc = constant_info->desc;
if (count)
@@ -800,7 +813,7 @@ static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstant(ID3DXConstantTable *
if (index >= This->desc.Constants)
return NULL;
- return (D3DXHANDLE)(DWORD_PTR)(index + 1);
+ return handle_from_constant_index(index);
}
static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantTable *iface, D3DXHANDLE constant, LPCSTR name)
@@ -821,7 +834,7 @@ static D3DXHANDLE WINAPI ID3DXConstantTableImpl_GetConstantByName(ID3DXConstantT
for (i = 0; i < This->desc.Constants; i++)
if (!strcmp(This->constants[i].desc.Name, name))
- return (D3DXHANDLE)(DWORD_PTR)(i + 1);
+ return handle_from_constant_index(i);
return NULL;
}
--
1.7.8.6
More information about the wine-patches
mailing list