Commit 31808b08 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d2d1: Implement GetDevice() for device context.

parent 7c4f85ed
......@@ -330,14 +330,14 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size,
resource_data.pSysMem = src_data;
resource_data.SysMemPitch = pitch;
if (FAILED(hr = ID3D10Device_CreateTexture2D(context->device, &texture_desc,
if (FAILED(hr = ID3D10Device_CreateTexture2D(context->d3d_device, &texture_desc,
src_data ? &resource_data : NULL, &texture)))
{
ERR("Failed to create texture, hr %#x.\n", hr);
return hr;
}
hr = ID3D10Device_CreateShaderResourceView(context->device, (ID3D10Resource *)texture, NULL, &view);
hr = ID3D10Device_CreateShaderResourceView(context->d3d_device, (ID3D10Resource *)texture, NULL, &view);
ID3D10Texture2D_Release(texture);
if (FAILED(hr))
{
......@@ -375,7 +375,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
ID3D10ShaderResourceView_GetDevice(src_impl->view, &device);
ID3D10Device_Release(device);
if (device != context->device)
if (device != context->d3d_device)
{
hr = D2DERR_UNSUPPORTED_OPERATION;
goto failed;
......@@ -430,13 +430,13 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
ID3D10Resource_GetDevice(resource, &device);
ID3D10Device_Release(device);
if (device != context->device)
if (device != context->d3d_device)
{
ID3D10Resource_Release(resource);
return D2DERR_UNSUPPORTED_OPERATION;
}
hr = ID3D10Device_CreateShaderResourceView(context->device, resource, NULL, &view);
hr = ID3D10Device_CreateShaderResourceView(context->d3d_device, resource, NULL, &view);
ID3D10Resource_Release(resource);
if (FAILED(hr))
{
......
......@@ -795,7 +795,7 @@ HRESULT d2d_bitmap_render_target_init(struct d2d_bitmap_render_target *render_ta
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
if (FAILED(hr = ID3D10Device_CreateTexture2D(parent_target->device, &texture_desc, NULL, &texture)))
if (FAILED(hr = ID3D10Device_CreateTexture2D(parent_target->d3d_device, &texture_desc, NULL, &texture)))
{
WARN("Failed to create texture, hr %#x.\n", hr);
return hr;
......@@ -809,7 +809,7 @@ HRESULT d2d_bitmap_render_target_init(struct d2d_bitmap_render_target *render_ta
return hr;
}
if (FAILED(hr = d2d_d3d_create_render_target(parent_target->factory, dxgi_surface,
if (FAILED(hr = d2d_d3d_create_render_target(parent_target->device, dxgi_surface,
(IUnknown *)&render_target->ID2D1BitmapRenderTarget_iface,
parent_target->ops ? &d2d_bitmap_render_target_ops : NULL,
&dxgi_rt_desc, (void **)&render_target->dxgi_inner)))
......
......@@ -1288,7 +1288,7 @@ HRESULT d2d_brush_get_ps_cb(struct d2d_brush *brush, struct d2d_brush *opacity_b
buffer_data.SysMemPitch = 0;
buffer_data.SysMemSlicePitch = 0;
if (FAILED(hr = ID3D10Device_CreateBuffer(render_target->device, &buffer_desc, &buffer_data, ps_cb)))
if (FAILED(hr = ID3D10Device_CreateBuffer(render_target->d3d_device, &buffer_desc, &buffer_data, ps_cb)))
ERR("Failed to create constant buffer, hr %#x.\n", hr);
return hr;
......
......@@ -134,7 +134,8 @@ struct d2d_device_context
const struct d2d_device_context_ops *ops;
ID2D1Factory *factory;
ID3D10Device *device;
ID2D1Device *device;
ID3D10Device *d3d_device;
ID3D10RenderTargetView *view;
ID3D10StateBlock *stateblock;
struct d2d_shape_resources shape_resources[D2D_SHAPE_TYPE_COUNT];
......@@ -155,7 +156,7 @@ struct d2d_device_context
struct d2d_clip_stack clip_stack;
};
HRESULT d2d_d3d_create_render_target(ID2D1Factory *factory, IDXGISurface *surface, IUnknown *outer_unknown,
HRESULT d2d_d3d_create_render_target(ID2D1Device *device, IDXGISurface *surface, IUnknown *outer_unknown,
const struct d2d_device_context_ops *ops, const D2D1_RENDER_TARGET_PROPERTIES *desc,
void **render_target) DECLSPEC_HIDDEN;
HRESULT d2d_d3d_render_target_create_rtv(ID2D1RenderTarget *render_target, IDXGISurface1 *surface) DECLSPEC_HIDDEN;
......@@ -181,8 +182,8 @@ struct d2d_wic_render_target
unsigned int bpp;
};
HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory *factory,
ID3D10Device1 *device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory1 *factory,
ID3D10Device1 *d3d_device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
struct d2d_dc_render_target
{
......@@ -197,8 +198,8 @@ struct d2d_dc_render_target
HDC hdc;
};
HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory *factory,
ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory1 *factory,
ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
struct d2d_hwnd_render_target
{
......@@ -212,8 +213,8 @@ struct d2d_hwnd_render_target
HWND hwnd;
};
HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory *factory,
ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory1 *factory,
ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_desc) DECLSPEC_HIDDEN;
struct d2d_bitmap_render_target
......
......@@ -813,11 +813,13 @@ static const struct d2d_device_context_ops d2d_dc_render_target_ops =
d2d_dc_render_target_present,
};
HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory *factory,
ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc)
HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory1 *factory,
ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc)
{
D3D10_TEXTURE2D_DESC texture_desc;
ID3D10Texture2D *texture;
IDXGIDevice *dxgi_device;
ID2D1Device *device;
HRESULT hr;
render_target->ID2D1DCRenderTarget_iface.lpVtbl = &d2d_dc_render_target_vtbl;
......@@ -852,7 +854,7 @@ HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
if (FAILED(hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &texture)))
if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &texture)))
{
WARN("Failed to create texture, hr %#x.\n", hr);
return hr;
......@@ -866,9 +868,25 @@ HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID
return hr;
}
if (FAILED(hr = d2d_d3d_create_render_target(factory, (IDXGISurface *)render_target->dxgi_surface,
if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
{
WARN("Failed to get DXGI device interface, hr %#x.\n", hr);
return hr;
}
hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device);
IDXGIDevice_Release(dxgi_device);
if (FAILED(hr))
{
WARN("Failed to create D2D device, hr %#x.\n", hr);
return hr;
}
hr = d2d_d3d_create_render_target(device, (IDXGISurface *)render_target->dxgi_surface,
(IUnknown *)&render_target->ID2D1DCRenderTarget_iface, &d2d_dc_render_target_ops,
desc, (void **)&render_target->dxgi_inner)))
desc, (void **)&render_target->dxgi_inner);
ID2D1Device_Release(device);
if (FAILED(hr))
{
WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
IDXGISurface1_Release(render_target->dxgi_surface);
......
......@@ -300,7 +300,7 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateWicBitmapRenderTarget(ID2D1Fa
return hr;
}
if (FAILED(hr = d2d_wic_render_target_init(object, (ID2D1Factory *)iface, device, target, desc)))
if (FAILED(hr = d2d_wic_render_target_init(object, iface, device, target, desc)))
{
WARN("Failed to initialize render target, hr %#x.\n", hr);
heap_free(object);
......@@ -330,7 +330,7 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
if (FAILED(hr = d2d_hwnd_render_target_init(object, (ID2D1Factory *)iface, device, desc, hwnd_rt_desc)))
if (FAILED(hr = d2d_hwnd_render_target_init(object, iface, device, desc, hwnd_rt_desc)))
{
WARN("Failed to initialize render target, hr %#x.\n", hr);
heap_free(object);
......@@ -346,9 +346,29 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateHwndRenderTarget(ID2D1Factory
static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDxgiSurfaceRenderTarget(ID2D1Factory1 *iface,
IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target)
{
IDXGIDevice *dxgi_device;
ID2D1Device *device;
HRESULT hr;
TRACE("iface %p, surface %p, desc %p, render_target %p.\n", iface, surface, desc, render_target);
return d2d_d3d_create_render_target((ID2D1Factory *)iface, surface, NULL, NULL, desc, (void **)render_target);
if (FAILED(hr = IDXGISurface_GetDevice(surface, &IID_IDXGIDevice, (void **)&dxgi_device)))
{
WARN("Failed to get DXGI device, hr %#x.\n", hr);
return hr;
}
hr = ID2D1Factory1_CreateDevice(iface, dxgi_device, &device);
IDXGIDevice_Release(dxgi_device);
if (FAILED(hr))
{
WARN("Failed to create D2D device, hr %#x.\n", hr);
return hr;
}
hr = d2d_d3d_create_render_target(device, surface, NULL, NULL, desc, (void **)render_target);
ID2D1Device_Release(device);
return hr;
}
static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory1 *iface,
......@@ -367,7 +387,7 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory1
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
if (FAILED(hr = d2d_dc_render_target_init(object, (ID2D1Factory *)iface, device, desc)))
if (FAILED(hr = d2d_dc_render_target_init(object, iface, device, desc)))
{
WARN("Failed to initialize render target, hr %#x.\n", hr);
heap_free(object);
......
......@@ -776,8 +776,8 @@ static const struct d2d_device_context_ops d2d_hwnd_render_target_ops =
d2d_hwnd_render_target_present,
};
HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory *factory,
ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory1 *factory,
ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc)
{
D2D1_RENDER_TARGET_PROPERTIES dxgi_rt_desc;
......@@ -786,6 +786,7 @@ HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target
IDXGIFactory *dxgi_factory;
IDXGISurface *dxgi_surface;
IDXGIDevice *dxgi_device;
ID2D1Device *device;
HRESULT hr;
if (!IsWindow(hwnd_rt_desc->hwnd))
......@@ -795,7 +796,7 @@ HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target
render_target->hwnd = hwnd_rt_desc->hwnd;
render_target->sync_interval = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_IMMEDIATELY ? 0 : 1;
if (FAILED(hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device)))
if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
{
WARN("Failed to get IDXGIDevice interface, hr %#x.\n", hr);
return hr;
......@@ -819,7 +820,7 @@ HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target
dxgi_rt_desc = *desc;
if (dxgi_rt_desc.dpiX == 0.0f && dxgi_rt_desc.dpiY == 0.0f)
ID2D1Factory_GetDesktopDpi(factory, &dxgi_rt_desc.dpiX, &dxgi_rt_desc.dpiY);
ID2D1Factory1_GetDesktopDpi(factory, &dxgi_rt_desc.dpiX, &dxgi_rt_desc.dpiY);
if (dxgi_rt_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
{
......@@ -844,7 +845,7 @@ HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target
DXGI_SWAP_EFFECT_SEQUENTIAL : DXGI_SWAP_EFFECT_DISCARD;
swapchain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
hr = IDXGIFactory_CreateSwapChain(dxgi_factory, (IUnknown *)device, &swapchain_desc, &render_target->swapchain);
hr = IDXGIFactory_CreateSwapChain(dxgi_factory, (IUnknown *)d3d_device, &swapchain_desc, &render_target->swapchain);
IDXGIFactory_Release(dxgi_factory);
if (FAILED(hr))
{
......@@ -860,10 +861,30 @@ HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target
}
render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
hr = d2d_d3d_create_render_target(factory, dxgi_surface,
if (FAILED(hr = IDXGISurface_GetDevice(dxgi_surface, &IID_IDXGIDevice, (void **)&dxgi_device)))
{
WARN("Failed to get DXGI device, hr %#X.\n", hr);
IDXGISurface_Release(dxgi_surface);
IDXGISwapChain_Release(render_target->swapchain);
return hr;
}
hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device);
IDXGIDevice_Release(dxgi_device);
if (FAILED(hr))
{
WARN("Failed to create D2D device, hr %#X.\n", hr);
IDXGISurface_Release(dxgi_surface);
IDXGISwapChain_Release(render_target->swapchain);
return hr;
}
hr = d2d_d3d_create_render_target(device, dxgi_surface,
(IUnknown *)&render_target->ID2D1HwndRenderTarget_iface, &d2d_hwnd_render_target_ops,
&dxgi_rt_desc, (void **)&render_target->dxgi_inner);
IDXGISurface_Release(dxgi_surface);
ID2D1Device_Release(device);
if (FAILED(hr))
{
WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
......
......@@ -6772,7 +6772,7 @@ static void check_rt_bitmap_surface_(unsigned int line, ID2D1RenderTarget *rt, B
/* Pixel format is not defined until target is set, for DC target it's specified on creation. */
if (target || dc_rt)
{
ID2D1Device *device = NULL, *device2 = NULL;
ID2D1Device *device, *device2;
ID2D1DeviceContext *context2;
ID2D1DeviceContext_GetDevice(context, &device);
......@@ -6787,10 +6787,8 @@ static void check_rt_bitmap_surface_(unsigned int line, ID2D1RenderTarget *rt, B
ID2D1DeviceContext_GetDevice(context2, &device2);
ok_(__FILE__, line)(device == device2, "Unexpected device.\n");
if (device)
ID2D1Device_Release(device);
if (device2)
ID2D1Device_Release(device2);
ID2D1Device_Release(device);
ID2D1Device_Release(device2);
ID2D1DeviceContext_Release(context2);
......
......@@ -152,11 +152,13 @@ static const struct d2d_device_context_ops d2d_wic_render_target_ops =
d2d_wic_render_target_present,
};
HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory *factory,
ID3D10Device1 *device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc)
HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory1 *factory,
ID3D10Device1 *d3d_device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc)
{
D3D10_TEXTURE2D_DESC texture_desc;
ID3D10Texture2D *texture;
IDXGIDevice *dxgi_device;
ID2D1Device *device;
HRESULT hr;
render_target->IUnknown_iface.lpVtbl = &d2d_wic_render_target_vtbl;
......@@ -214,7 +216,7 @@ HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target,
texture_desc.MiscFlags = desc->usage & D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE ?
D3D10_RESOURCE_MISC_GDI_COMPATIBLE : 0;
if (FAILED(hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &texture)))
if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &texture)))
{
WARN("Failed to create texture, hr %#x.\n", hr);
return hr;
......@@ -233,16 +235,33 @@ HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target,
texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
texture_desc.MiscFlags = 0;
if (FAILED(hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &render_target->readback_texture)))
if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &render_target->readback_texture)))
{
WARN("Failed to create readback texture, hr %#x.\n", hr);
IDXGISurface_Release(render_target->dxgi_surface);
return hr;
}
if (FAILED(hr = d2d_d3d_create_render_target(factory, render_target->dxgi_surface,
&render_target->IUnknown_iface, &d2d_wic_render_target_ops,
desc, (void **)&render_target->dxgi_inner)))
if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
{
WARN("Failed to get DXGI device, hr %#x.\n", hr);
IDXGISurface_Release(render_target->dxgi_surface);
return hr;
}
hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device);
IDXGIDevice_Release(dxgi_device);
if (FAILED(hr))
{
WARN("Failed to create D2D device, hr %#x.\n", hr);
IDXGISurface_Release(render_target->dxgi_surface);
return hr;
}
hr = d2d_d3d_create_render_target(device, render_target->dxgi_surface, &render_target->IUnknown_iface,
&d2d_wic_render_target_ops, desc, (void **)&render_target->dxgi_inner);
ID2D1Device_Release(device);
if (FAILED(hr))
{
WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
ID3D10Texture2D_Release(render_target->readback_texture);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment