d2d1: Implement d2d_d3d_render_target_Clear().
This is of course a fairly naive initial implementation. We'd probably want to batch up drawing operations, and only execute them on EndDraw() or Flush() to reduce state setup overhead.
This commit is contained in:
parent
92a1ede37f
commit
e2c7b442a1
|
@ -1,6 +1,6 @@
|
|||
MODULE = d2d1.dll
|
||||
IMPORTLIB = d2d1
|
||||
IMPORTS = uuid
|
||||
IMPORTS = d3d10_1 dxguid uuid
|
||||
|
||||
C_SRCS = \
|
||||
brush.c \
|
||||
|
|
|
@ -29,6 +29,16 @@ struct d2d_d3d_render_target
|
|||
ID2D1RenderTarget ID2D1RenderTarget_iface;
|
||||
LONG refcount;
|
||||
|
||||
ID3D10Device *device;
|
||||
ID3D10RenderTargetView *view;
|
||||
ID3D10StateBlock *stateblock;
|
||||
|
||||
ID3D10InputLayout *clear_il;
|
||||
unsigned int clear_vb_stride;
|
||||
ID3D10Buffer *clear_vb;
|
||||
ID3D10VertexShader *clear_vs;
|
||||
ID3D10PixelShader *clear_ps;
|
||||
|
||||
D2D1_SIZE_U pixel_size;
|
||||
D2D1_MATRIX_3X2_F transform;
|
||||
float dpi_x;
|
||||
|
|
|
@ -65,7 +65,16 @@ static ULONG STDMETHODCALLTYPE d2d_d3d_render_target_Release(ID2D1RenderTarget *
|
|||
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
||||
|
||||
if (!refcount)
|
||||
{
|
||||
ID3D10RenderTargetView_Release(render_target->view);
|
||||
ID3D10PixelShader_Release(render_target->clear_ps);
|
||||
ID3D10VertexShader_Release(render_target->clear_vs);
|
||||
ID3D10Buffer_Release(render_target->clear_vb);
|
||||
ID3D10InputLayout_Release(render_target->clear_il);
|
||||
render_target->stateblock->lpVtbl->Release(render_target->stateblock);
|
||||
ID3D10Device_Release(render_target->device);
|
||||
HeapFree(GetProcessHeap(), 0, render_target);
|
||||
}
|
||||
|
||||
return refcount;
|
||||
}
|
||||
|
@ -429,7 +438,65 @@ static void STDMETHODCALLTYPE d2d_d3d_render_target_PopAxisAlignedClip(ID2D1Rend
|
|||
|
||||
static void STDMETHODCALLTYPE d2d_d3d_render_target_Clear(ID2D1RenderTarget *iface, const D2D1_COLOR_F *color)
|
||||
{
|
||||
FIXME("iface %p, color %p stub!\n", iface, color);
|
||||
struct d2d_d3d_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
|
||||
D3D10_SUBRESOURCE_DATA buffer_data;
|
||||
D3D10_BUFFER_DESC buffer_desc;
|
||||
unsigned int offset;
|
||||
D3D10_VIEWPORT vp;
|
||||
ID3D10Buffer *cb;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("iface %p, color %p.\n", iface, color);
|
||||
|
||||
buffer_desc.ByteWidth = sizeof(*color);
|
||||
buffer_desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
buffer_desc.BindFlags = D3D10_BIND_CONSTANT_BUFFER;
|
||||
buffer_desc.CPUAccessFlags = 0;
|
||||
buffer_desc.MiscFlags = 0;
|
||||
|
||||
buffer_data.pSysMem = color;
|
||||
buffer_data.SysMemPitch = 0;
|
||||
buffer_data.SysMemSlicePitch = 0;
|
||||
|
||||
if (FAILED(hr = ID3D10Device_CreateBuffer(render_target->device, &buffer_desc, &buffer_data, &cb)))
|
||||
{
|
||||
WARN("Failed to create constant buffer, hr %#x.\n", hr);
|
||||
return;
|
||||
}
|
||||
|
||||
vp.TopLeftX = 0;
|
||||
vp.TopLeftY = 0;
|
||||
vp.Width = render_target->pixel_size.width;
|
||||
vp.Height = render_target->pixel_size.height;
|
||||
vp.MinDepth = 0.0f;
|
||||
vp.MaxDepth = 1.0f;
|
||||
|
||||
if (FAILED(hr = render_target->stateblock->lpVtbl->Capture(render_target->stateblock)))
|
||||
{
|
||||
WARN("Failed to capture stateblock, hr %#x.\n", hr);
|
||||
ID3D10Buffer_Release(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
ID3D10Device_ClearState(render_target->device);
|
||||
|
||||
ID3D10Device_IASetInputLayout(render_target->device, render_target->clear_il);
|
||||
ID3D10Device_IASetPrimitiveTopology(render_target->device, D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
||||
offset = 0;
|
||||
ID3D10Device_IASetVertexBuffers(render_target->device, 0, 1,
|
||||
&render_target->clear_vb, &render_target->clear_vb_stride, &offset);
|
||||
ID3D10Device_VSSetShader(render_target->device, render_target->clear_vs);
|
||||
ID3D10Device_PSSetConstantBuffers(render_target->device, 0, 1, &cb);
|
||||
ID3D10Device_PSSetShader(render_target->device, render_target->clear_ps);
|
||||
ID3D10Device_RSSetViewports(render_target->device, 1, &vp);
|
||||
ID3D10Device_OMSetRenderTargets(render_target->device, 1, &render_target->view, NULL);
|
||||
|
||||
ID3D10Device_Draw(render_target->device, 4, 0);
|
||||
|
||||
if (FAILED(hr = render_target->stateblock->lpVtbl->Apply(render_target->stateblock)))
|
||||
WARN("Failed to apply stateblock, hr %#x.\n", hr);
|
||||
|
||||
ID3D10Buffer_Release(cb);
|
||||
}
|
||||
|
||||
static void STDMETHODCALLTYPE d2d_d3d_render_target_BeginDraw(ID2D1RenderTarget *iface)
|
||||
|
@ -587,9 +654,76 @@ static const struct ID2D1RenderTargetVtbl d2d_d3d_render_target_vtbl =
|
|||
HRESULT d2d_d3d_render_target_init(struct d2d_d3d_render_target *render_target, ID2D1Factory *factory,
|
||||
IDXGISurface *surface, const D2D1_RENDER_TARGET_PROPERTIES *desc)
|
||||
{
|
||||
D3D10_SUBRESOURCE_DATA buffer_data;
|
||||
D3D10_STATE_BLOCK_MASK state_mask;
|
||||
DXGI_SURFACE_DESC surface_desc;
|
||||
D3D10_BUFFER_DESC buffer_desc;
|
||||
ID3D10Resource *resource;
|
||||
HRESULT hr;
|
||||
|
||||
static const D3D10_INPUT_ELEMENT_DESC clear_il_desc[] =
|
||||
{
|
||||
{"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
|
||||
};
|
||||
static const DWORD clear_vs_code[] =
|
||||
{
|
||||
/* float4 main(float4 position : POSITION) : SV_POSITION
|
||||
* {
|
||||
* return position;
|
||||
* } */
|
||||
0x43425844, 0x1fa8c27f, 0x52d2f21d, 0xc196fdb7, 0x376f283a, 0x00000001, 0x000001b4, 0x00000005,
|
||||
0x00000034, 0x0000008c, 0x000000c0, 0x000000f4, 0x00000138, 0x46454452, 0x00000050, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x0000001c, 0xfffe0400, 0x00000100, 0x0000001c, 0x7263694d, 0x666f736f,
|
||||
0x52282074, 0x4c482029, 0x53204c53, 0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e,
|
||||
0x30303239, 0x3336312e, 0xab003438, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
|
||||
0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
|
||||
0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
|
||||
0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
|
||||
0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
|
||||
0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453, 0x00000074,
|
||||
0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
};
|
||||
static const DWORD clear_ps_code[] =
|
||||
{
|
||||
/* float4 color;
|
||||
*
|
||||
* float4 main(float4 position : SV_POSITION) : SV_Target
|
||||
* {
|
||||
* return color;
|
||||
* } */
|
||||
0x43425844, 0xecd3cc9d, 0x0025bc77, 0x7a333165, 0x5b04c7e4, 0x00000001, 0x0000022c, 0x00000005,
|
||||
0x00000034, 0x00000100, 0x00000134, 0x00000168, 0x000001b0, 0x46454452, 0x000000c4, 0x00000001,
|
||||
0x00000048, 0x00000001, 0x0000001c, 0xffff0400, 0x00000100, 0x00000090, 0x0000003c, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x6f6c4724, 0x736c6162,
|
||||
0xababab00, 0x0000003c, 0x00000001, 0x00000060, 0x00000010, 0x00000000, 0x00000000, 0x00000078,
|
||||
0x00000000, 0x00000010, 0x00000002, 0x00000080, 0x00000000, 0x6f6c6f63, 0xabab0072, 0x00030001,
|
||||
0x00040001, 0x00000000, 0x00000000, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53,
|
||||
0x65646168, 0x6f432072, 0x6c69706d, 0x39207265, 0x2e30332e, 0x30303239, 0x3336312e, 0xab003438,
|
||||
0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
|
||||
0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001,
|
||||
0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
|
||||
0x65677261, 0xabab0074, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059, 0x00208e46,
|
||||
0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2, 0x00000000,
|
||||
0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x54415453, 0x00000074, 0x00000002, 0x00000000,
|
||||
0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000,
|
||||
};
|
||||
static const struct
|
||||
{
|
||||
float x, y;
|
||||
}
|
||||
clear_quad[] =
|
||||
{
|
||||
{-1.0f, -1.0f},
|
||||
{-1.0f, 1.0f},
|
||||
{ 1.0f, -1.0f},
|
||||
{ 1.0f, 1.0f},
|
||||
};
|
||||
static const D2D1_MATRIX_3X2_F identity =
|
||||
{
|
||||
1.0f, 0.0f,
|
||||
|
@ -602,10 +736,82 @@ HRESULT d2d_d3d_render_target_init(struct d2d_d3d_render_target *render_target,
|
|||
render_target->ID2D1RenderTarget_iface.lpVtbl = &d2d_d3d_render_target_vtbl;
|
||||
render_target->refcount = 1;
|
||||
|
||||
if (FAILED(hr = IDXGISurface_GetDevice(surface, &IID_ID3D10Device, (void **)&render_target->device)))
|
||||
{
|
||||
WARN("Failed to get device interface, hr %#x.\n", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
if (FAILED(hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Resource, (void **)&resource)))
|
||||
{
|
||||
WARN("Failed to get ID3D10Resource interface, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
hr = ID3D10Device_CreateRenderTargetView(render_target->device, resource, NULL, &render_target->view);
|
||||
ID3D10Resource_Release(resource);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to create rendertarget view, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FAILED(hr = D3D10StateBlockMaskEnableAll(&state_mask)))
|
||||
{
|
||||
WARN("Failed to create stateblock mask, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FAILED(hr = D3D10CreateStateBlock(render_target->device, &state_mask, &render_target->stateblock)))
|
||||
{
|
||||
WARN("Failed to create stateblock, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FAILED(hr = ID3D10Device_CreateInputLayout(render_target->device, clear_il_desc,
|
||||
sizeof(clear_il_desc) / sizeof(*clear_il_desc), clear_vs_code, sizeof(clear_vs_code),
|
||||
&render_target->clear_il)))
|
||||
{
|
||||
WARN("Failed to create clear input layout, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
buffer_desc.ByteWidth = sizeof(clear_quad);
|
||||
buffer_desc.Usage = D3D10_USAGE_DEFAULT;
|
||||
buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
|
||||
buffer_desc.CPUAccessFlags = 0;
|
||||
buffer_desc.MiscFlags = 0;
|
||||
|
||||
buffer_data.pSysMem = clear_quad;
|
||||
buffer_data.SysMemPitch = 0;
|
||||
buffer_data.SysMemSlicePitch = 0;
|
||||
|
||||
render_target->clear_vb_stride = sizeof(*clear_quad);
|
||||
if (FAILED(hr = ID3D10Device_CreateBuffer(render_target->device,
|
||||
&buffer_desc, &buffer_data, &render_target->clear_vb)))
|
||||
{
|
||||
WARN("Failed to create clear vertex buffer, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FAILED(hr = ID3D10Device_CreateVertexShader(render_target->device,
|
||||
clear_vs_code, sizeof(clear_vs_code), &render_target->clear_vs)))
|
||||
{
|
||||
WARN("Failed to create clear vertex shader, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FAILED(hr = ID3D10Device_CreatePixelShader(render_target->device,
|
||||
clear_ps_code, sizeof(clear_ps_code), &render_target->clear_ps)))
|
||||
{
|
||||
WARN("Failed to create clear pixel shader, hr %#x.\n", hr);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc)))
|
||||
{
|
||||
WARN("Failed to get surface desc, hr %#x.\n", hr);
|
||||
return hr;
|
||||
goto err;
|
||||
}
|
||||
|
||||
render_target->pixel_size.width = surface_desc.Width;
|
||||
|
@ -621,4 +827,21 @@ HRESULT d2d_d3d_render_target_init(struct d2d_d3d_render_target *render_target,
|
|||
}
|
||||
|
||||
return S_OK;
|
||||
|
||||
err:
|
||||
if (render_target->view)
|
||||
ID3D10RenderTargetView_Release(render_target->view);
|
||||
if (render_target->clear_ps)
|
||||
ID3D10PixelShader_Release(render_target->clear_ps);
|
||||
if (render_target->clear_vs)
|
||||
ID3D10VertexShader_Release(render_target->clear_vs);
|
||||
if (render_target->clear_vb)
|
||||
ID3D10Buffer_Release(render_target->clear_vb);
|
||||
if (render_target->clear_il)
|
||||
ID3D10InputLayout_Release(render_target->clear_il);
|
||||
if (render_target->stateblock)
|
||||
render_target->stateblock->lpVtbl->Release(render_target->stateblock);
|
||||
if (render_target->device)
|
||||
ID3D10Device_Release(render_target->device);
|
||||
return hr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue