Re: [PATCH 3/5] d3d11: Implement d3d11_device_CreateTexture2D().
On 28 August 2015 at 00:39, Józef Kucia <jkucia(a)codeweavers.com> wrote:
+static inline struct d3d10_texture2d *impl_from_ID3D11Texture2D(ID3D11Texture2D *iface) +{ + return CONTAINING_RECORD(iface, struct d3d10_texture2d, ID3D11Texture2D_iface); +} + We usually try to keep these in the file that contains the interface implementation, texture.c in this case. We do make the occasional exception though.
+ object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + if (!object) You could just do "if (!(object = HeapAlloc(...)))" here, but it doesn't matter that much.
@@ -2006,15 +2025,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *ifa { struct d3d_device *device = impl_from_ID3D10Device(iface); D3D11_TEXTURE2D_DESC d3d11_desc; + ID3D11Texture2D *d3d11_texture; struct d3d10_texture2d *object; HRESULT hr;
TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); - if (!object) - return E_OUTOFMEMORY; - d3d11_desc.Width = desc->Width; d3d11_desc.Height = desc->Height; d3d11_desc.MipLevels = desc->MipLevels; @@ -2026,16 +2042,14 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *ifa d3d11_desc.CPUAccessFlags = d3d11_cpu_access_flags_from_d3d10_cpu_access_flags(desc->CPUAccessFlags); d3d11_desc.MiscFlags = d3d11_resource_misc_flags_from_d3d10_resource_misc_flags(desc->MiscFlags);
- if (FAILED(hr = d3d10_texture2d_init(object, device, &d3d11_desc, data))) - { - WARN("Failed to initialize texture, hr %#x.\n", hr); - HeapFree(GetProcessHeap(), 0, object); + if (FAILED(hr = d3d11_device_CreateTexture2D(&device->ID3D11Device_iface, &d3d11_desc, + (const D3D11_SUBRESOURCE_DATA *)data, &d3d11_texture))) return hr; - }
+ object = impl_from_ID3D11Texture2D(d3d11_texture); *texture = &object->ID3D10Texture2D_iface;
- TRACE("Created ID3D10Texture2D %p\n", object); + TRACE("Created ID3D10Texture2D %p.\n", object);
return S_OK; } This change doesn't really seem worth it. You do save a couple of lines by avoiding the memory allocation, but you need to make impl_from_ID3D11Texture2D() available outside of texture.c to do it. You could create a d3d_texture2d_create() function similar to e.g. d3d9_swapchain_create() in d3d9 and avoid the duplication that way, but it may not make much of a difference in line count. Up to you.
participants (1)
-
Henri Verbeet