wined3d: Add a separate function for palette initialization.

This commit is contained in:
Henri Verbeet 2010-04-13 20:46:25 +02:00 committed by Alexandre Julliard
parent d1d8c81439
commit ab80e9739c
3 changed files with 49 additions and 26 deletions

View File

@ -1360,35 +1360,27 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreatePalette(IWineD3DDevice *iface, DW
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface; IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
IWineD3DPaletteImpl *object; IWineD3DPaletteImpl *object;
HRESULT hr; HRESULT hr;
TRACE("(%p)->(%x, %p, %p, %p)\n", This, Flags, PalEnt, Palette, Parent);
/* Create the new object */ TRACE("iface %p, flags %#x, entries %p, palette %p, parent %p.\n",
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DPaletteImpl)); iface, Flags, PalEnt, Palette, Parent);
if(!object) {
ERR("Out of memory when allocating memory for a IWineD3DPalette implementation\n"); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
{
ERR("Failed to allocate palette memory.\n");
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
object->lpVtbl = &IWineD3DPalette_Vtbl; hr = wined3d_palette_init(object, This, Flags, PalEnt, Parent);
object->ref = 1; if (FAILED(hr))
object->Flags = Flags; {
object->parent = Parent; WARN("Failed to initialize palette, hr %#x.\n", hr);
object->device = This; HeapFree(GetProcessHeap(), 0, object);
object->palNumEntries = IWineD3DPaletteImpl_Size(Flags);
object->hpal = CreatePalette((const LOGPALETTE*)&(object->palVersion));
if(!object->hpal) {
HeapFree( GetProcessHeap(), 0, object);
return E_OUTOFMEMORY;
}
hr = IWineD3DPalette_SetEntries((IWineD3DPalette *) object, 0, 0, IWineD3DPaletteImpl_Size(Flags), PalEnt);
if(FAILED(hr)) {
IWineD3DPalette_Release((IWineD3DPalette *) object);
return hr; return hr;
} }
*Palette = (IWineD3DPalette *) object; TRACE("Created palette %p.\n", object);
*Palette = (IWineD3DPalette *)object;
return WINED3D_OK; return WINED3D_OK;
} }

View File

@ -74,7 +74,8 @@ static ULONG WINAPI IWineD3DPaletteImpl_Release(IWineD3DPalette *iface) {
} }
/* Not called from the vtable */ /* Not called from the vtable */
DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) { static DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags)
{
switch (dwFlags & SIZE_BITS) { switch (dwFlags & SIZE_BITS) {
case WINEDDPCAPS_1BIT: return 2; case WINEDDPCAPS_1BIT: return 2;
case WINEDDPCAPS_2BIT: return 4; case WINEDDPCAPS_2BIT: return 4;
@ -183,7 +184,7 @@ static HRESULT WINAPI IWineD3DPaletteImpl_GetParent(IWineD3DPalette *iface, IUn
return WINED3D_OK; return WINED3D_OK;
} }
const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl = static const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
{ {
/*** IUnknown ***/ /*** IUnknown ***/
IWineD3DPaletteImpl_QueryInterface, IWineD3DPaletteImpl_QueryInterface,
@ -195,3 +196,33 @@ const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl =
IWineD3DPaletteImpl_GetCaps, IWineD3DPaletteImpl_GetCaps,
IWineD3DPaletteImpl_SetEntries IWineD3DPaletteImpl_SetEntries
}; };
HRESULT wined3d_palette_init(IWineD3DPaletteImpl *palette, IWineD3DDeviceImpl *device,
DWORD flags, const PALETTEENTRY *entries, IUnknown *parent)
{
HRESULT hr;
palette->lpVtbl = &IWineD3DPalette_Vtbl;
palette->ref = 1;
palette->parent = parent;
palette->device = device;
palette->Flags = flags;
palette->palNumEntries = IWineD3DPaletteImpl_Size(flags);
palette->hpal = CreatePalette((const LOGPALETTE *)&palette->palVersion);
if (!palette->hpal)
{
WARN("Failed to create palette.\n");
return E_FAIL;
}
hr = IWineD3DPalette_SetEntries((IWineD3DPalette *)palette, 0, 0, IWineD3DPaletteImpl_Size(flags), entries);
if (FAILED(hr))
{
WARN("Failed to set palette entries, hr %#x.\n", hr);
DeleteObject(palette->hpal);
return hr;
}
return WINED3D_OK;
}

View File

@ -2966,8 +2966,8 @@ struct IWineD3DPaletteImpl {
DWORD Flags; DWORD Flags;
}; };
extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl DECLSPEC_HIDDEN; HRESULT wined3d_palette_init(IWineD3DPaletteImpl *palette, IWineD3DDeviceImpl *device,
DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) DECLSPEC_HIDDEN; DWORD flags, const PALETTEENTRY *entries, IUnknown *parent) DECLSPEC_HIDDEN;
/* DirectDraw utility functions */ /* DirectDraw utility functions */
extern WINED3DFORMAT pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN; extern WINED3DFORMAT pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;