d2d1: Accept ID3D11Resource in d2d_bitmap_init.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49395
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-06-24 09:35:32 +02:00 committed by Alexandre Julliard
parent af64b4c119
commit 00fea26962
1 changed files with 13 additions and 31 deletions

View File

@ -279,20 +279,20 @@ static BOOL format_supported(const D2D1_PIXEL_FORMAT *format)
} }
static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context *context, static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context *context,
ID3D10Resource *d3d10_resource, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc) ID3D11Resource *resource, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc)
{ {
ID3D11Resource *resource; ID3D10Resource *d3d10_resource;
ID3D11Device *d3d_device; ID3D11Device *d3d_device;
HRESULT hr; HRESULT hr;
if (FAILED(hr = ID3D10Resource_QueryInterface(d3d10_resource, &IID_ID3D11Resource, (void **)&resource))) if (FAILED(hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D10Resource, (void **)&d3d10_resource)))
WARN("Failed to query ID3D11Resource interface, hr %#x.\n", hr); WARN("Failed to query ID3D10Resource interface, hr %#x.\n", hr);
bitmap->ID2D1Bitmap1_iface.lpVtbl = &d2d_bitmap_vtbl; bitmap->ID2D1Bitmap1_iface.lpVtbl = &d2d_bitmap_vtbl;
bitmap->refcount = 1; bitmap->refcount = 1;
ID2D1Factory_AddRef(bitmap->factory = context->factory); ID2D1Factory_AddRef(bitmap->factory = context->factory);
ID3D10Resource_AddRef(bitmap->resource = d3d10_resource); ID3D11Resource_AddRef(bitmap->d3d11_resource = resource);
bitmap->d3d11_resource = resource; bitmap->resource = d3d10_resource;
bitmap->pixel_size = size; bitmap->pixel_size = size;
bitmap->format = desc->pixelFormat; bitmap->format = desc->pixelFormat;
bitmap->dpi_x = desc->dpiX; bitmap->dpi_x = desc->dpiX;
@ -336,7 +336,6 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size,
D2D1_BITMAP_PROPERTIES1 bitmap_desc; D2D1_BITMAP_PROPERTIES1 bitmap_desc;
D3D11_TEXTURE2D_DESC texture_desc; D3D11_TEXTURE2D_DESC texture_desc;
ID3D11Texture2D *texture; ID3D11Texture2D *texture;
ID3D10Resource *resource;
HRESULT hr; HRESULT hr;
if (!format_supported(&desc->pixelFormat)) if (!format_supported(&desc->pixelFormat))
@ -388,20 +387,12 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size,
return hr; return hr;
} }
if (FAILED(hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Resource, (void **)&resource)))
{
ERR("Failed to query ID3D10Resource interface, hr %#x.\n", hr);
ID3D11Texture2D_Release(texture);
return hr;
}
if ((*bitmap = heap_alloc_zero(sizeof(**bitmap)))) if ((*bitmap = heap_alloc_zero(sizeof(**bitmap))))
{ {
d2d_bitmap_init(*bitmap, context, resource, size, desc); d2d_bitmap_init(*bitmap, context, (ID3D11Resource *)texture, size, desc);
TRACE("Created bitmap %p.\n", *bitmap); TRACE("Created bitmap %p.\n", *bitmap);
} }
ID3D11Texture2D_Release(texture); ID3D11Texture2D_Release(texture);
ID3D10Resource_Release(resource);
return *bitmap ? S_OK : E_OUTOFMEMORY; return *bitmap ? S_OK : E_OUTOFMEMORY;
} }
@ -455,7 +446,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
goto failed; goto failed;
} }
d2d_bitmap_init(*bitmap, context, src_impl->resource, src_impl->pixel_size, desc); d2d_bitmap_init(*bitmap, context, src_impl->d3d11_resource, src_impl->pixel_size, desc);
TRACE("Created bitmap %p.\n", *bitmap); TRACE("Created bitmap %p.\n", *bitmap);
failed: failed:
@ -467,7 +458,6 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
DXGI_SURFACE_DESC surface_desc; DXGI_SURFACE_DESC surface_desc;
IDXGISurface *surface = data; IDXGISurface *surface = data;
ID3D11Resource *resource; ID3D11Resource *resource;
ID3D10Resource *d3d10_resource;
D2D1_SIZE_U pixel_size; D2D1_SIZE_U pixel_size;
ID3D11Device *device; ID3D11Device *device;
HRESULT hr; HRESULT hr;
@ -478,25 +468,17 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
return E_FAIL; return E_FAIL;
} }
if (FAILED(hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D10Resource, (void **)&d3d10_resource)))
{
ERR("Failed to query ID3D10Resource interface, hr %#x.\n", hr);
ID3D11Resource_Release(resource);
return hr;
}
ID3D11Resource_GetDevice(resource, &device); ID3D11Resource_GetDevice(resource, &device);
ID3D11Resource_Release(resource);
ID3D11Device_Release(device); ID3D11Device_Release(device);
if (device != (ID3D11Device *)context->d3d11_device) if (device != (ID3D11Device *)context->d3d11_device)
{ {
ID3D10Resource_Release(d3d10_resource); ID3D11Resource_Release(resource);
return D2DERR_UNSUPPORTED_OPERATION; return D2DERR_UNSUPPORTED_OPERATION;
} }
if (!(*bitmap = heap_alloc_zero(sizeof(**bitmap)))) if (!(*bitmap = heap_alloc_zero(sizeof(**bitmap))))
{ {
ID3D10Resource_Release(d3d10_resource); ID3D11Resource_Release(resource);
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
} }
@ -504,7 +486,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc))) if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc)))
{ {
WARN("Failed to get surface desc, hr %#x.\n", hr); WARN("Failed to get surface desc, hr %#x.\n", hr);
ID3D10Resource_Release(d3d10_resource); ID3D11Resource_Release(resource);
return hr; return hr;
} }
@ -531,8 +513,8 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
pixel_size.width = surface_desc.Width; pixel_size.width = surface_desc.Width;
pixel_size.height = surface_desc.Height; pixel_size.height = surface_desc.Height;
d2d_bitmap_init(*bitmap, context, d3d10_resource, pixel_size, &d); d2d_bitmap_init(*bitmap, context, resource, pixel_size, &d);
ID3D10Resource_Release(d3d10_resource); ID3D11Resource_Release(resource);
TRACE("Created bitmap %p.\n", *bitmap); TRACE("Created bitmap %p.\n", *bitmap);
return S_OK; return S_OK;