Commit 287f751a authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d2d1: Implement bitmap brush support for d2d_d3d_render_target_FillRectangle().

parent 7df055f1
......@@ -65,7 +65,10 @@ static ULONG STDMETHODCALLTYPE d2d_bitmap_Release(ID2D1Bitmap *iface)
TRACE("%p increasing refcount to %u.\n", iface, refcount);
if (!refcount)
{
ID3D10ShaderResourceView_Release(bitmap->view);
HeapFree(GetProcessHeap(), 0, bitmap);
}
return refcount;
}
......@@ -156,14 +159,48 @@ static const struct ID2D1BitmapVtbl d2d_bitmap_vtbl =
d2d_bitmap_CopyFromMemory,
};
void d2d_bitmap_init(struct d2d_bitmap *bitmap, D2D1_SIZE_U size, const void *src_data,
UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc)
HRESULT d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_d3d_render_target *render_target,
D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc)
{
D3D10_SUBRESOURCE_DATA resource_data;
D3D10_TEXTURE2D_DESC texture_desc;
ID3D10Texture2D *texture;
HRESULT hr;
FIXME("Ignoring bitmap properties.\n");
bitmap->ID2D1Bitmap_iface.lpVtbl = &d2d_bitmap_vtbl;
bitmap->refcount = 1;
texture_desc.Width = size.width;
texture_desc.Height = size.height;
texture_desc.MipLevels = 1;
texture_desc.ArraySize = 1;
texture_desc.Format = desc->pixelFormat.format;
texture_desc.SampleDesc.Count = 1;
texture_desc.SampleDesc.Quality = 0;
texture_desc.Usage = D3D10_USAGE_DEFAULT;
texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
texture_desc.CPUAccessFlags = 0;
texture_desc.MiscFlags = 0;
resource_data.pSysMem = src_data;
resource_data.SysMemPitch = pitch;
if (FAILED(hr = ID3D10Device_CreateTexture2D(render_target->device, &texture_desc, &resource_data, &texture)))
{
ERR("Failed to create texture, hr %#x.\n", hr);
return hr;
}
hr = ID3D10Device_CreateShaderResourceView(render_target->device, (ID3D10Resource *)texture, NULL, &bitmap->view);
ID3D10Texture2D_Release(texture);
if (FAILED(hr))
{
ERR("Failed to create view, hr %#x.\n", hr);
return hr;
}
bitmap->pixel_size = size;
bitmap->dpi_x = desc->dpiX;
bitmap->dpi_y = desc->dpiY;
......@@ -173,4 +210,14 @@ void d2d_bitmap_init(struct d2d_bitmap *bitmap, D2D1_SIZE_U size, const void *sr
bitmap->dpi_x = 96.0f;
bitmap->dpi_y = 96.0f;
}
return S_OK;
}
struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface)
{
if (!iface)
return NULL;
assert(iface->lpVtbl == &d2d_bitmap_vtbl);
return CONTAINING_RECORD(iface, struct d2d_bitmap, ID2D1Bitmap_iface);
}
......@@ -498,7 +498,10 @@ static ULONG STDMETHODCALLTYPE d2d_bitmap_brush_Release(ID2D1BitmapBrush *iface)
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
if (!refcount)
{
ID3D10SamplerState_Release(brush->u.bitmap.sampler_state);
HeapFree(GetProcessHeap(), 0, brush);
}
return refcount;
}
......@@ -616,13 +619,40 @@ static const struct ID2D1BitmapBrushVtbl d2d_bitmap_brush_vtbl =
d2d_bitmap_brush_GetBitmap,
};
void d2d_bitmap_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target, const ID2D1Bitmap *bitmap,
HRESULT d2d_bitmap_brush_init(struct d2d_brush *brush, struct d2d_d3d_render_target *render_target, ID2D1Bitmap *bitmap,
const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc)
{
D3D10_SAMPLER_DESC sampler_desc;
HRESULT hr;
FIXME("Ignoring brush properties.\n");
d2d_brush_init(brush, render_target, D2D_BRUSH_TYPE_BITMAP, brush_desc,
(ID2D1BrushVtbl *)&d2d_bitmap_brush_vtbl);
d2d_brush_init(brush, &render_target->ID2D1RenderTarget_iface, D2D_BRUSH_TYPE_BITMAP,
brush_desc, (ID2D1BrushVtbl *)&d2d_bitmap_brush_vtbl);
brush->u.bitmap.bitmap = unsafe_impl_from_ID2D1Bitmap(bitmap);
sampler_desc.Filter = D3D10_FILTER_MIN_MAG_MIP_POINT;
sampler_desc.AddressU = D3D10_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressV = D3D10_TEXTURE_ADDRESS_CLAMP;
sampler_desc.AddressW = D3D10_TEXTURE_ADDRESS_CLAMP;
sampler_desc.MipLODBias = 0.0f;
sampler_desc.MaxAnisotropy = 0;
sampler_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
sampler_desc.BorderColor[0] = 0.0f;
sampler_desc.BorderColor[1] = 0.0f;
sampler_desc.BorderColor[2] = 0.0f;
sampler_desc.BorderColor[3] = 0.0f;
sampler_desc.MinLOD = 0.0f;
sampler_desc.MaxLOD = 0.0f;
if (FAILED(hr = ID3D10Device_CreateSamplerState(render_target->device,
&sampler_desc, &brush->u.bitmap.sampler_state)))
{
ERR("Failed to create sampler state, hr %#x.\n", hr);
return hr;
}
return S_OK;
}
struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface)
......@@ -634,3 +664,12 @@ struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface)
|| iface->lpVtbl == (const ID2D1BrushVtbl *)&d2d_bitmap_brush_vtbl);
return CONTAINING_RECORD(iface, struct d2d_brush, ID2D1Brush_iface);
}
void d2d_brush_bind_resources(struct d2d_brush *brush, ID3D10Device *device)
{
if (brush->type == D2D_BRUSH_TYPE_BITMAP)
{
ID3D10Device_PSSetShaderResources(device, 0, 1, &brush->u.bitmap.bitmap->view);
ID3D10Device_PSSetSamplers(device, 0, 1, &brush->u.bitmap.sampler_state);
}
}
......@@ -61,6 +61,7 @@ struct d2d_d3d_render_target
ID3D10BlendState *bs;
ID3D10PixelShader *rect_solid_ps;
ID3D10PixelShader *rect_bitmap_ps;
D2D1_SIZE_U pixel_size;
D2D1_MATRIX_3X2_F transform;
......@@ -118,6 +119,11 @@ struct d2d_brush
{
D2D1_COLOR_F color;
} solid;
struct
{
struct d2d_bitmap *bitmap;
ID3D10SamplerState *sampler_state;
} bitmap;
} u;
};
......@@ -126,9 +132,10 @@ void d2d_solid_color_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *rend
void d2d_linear_gradient_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target,
const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
ID2D1GradientStopCollection *gradient) DECLSPEC_HIDDEN;
void d2d_bitmap_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target,
const ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
HRESULT d2d_bitmap_brush_init(struct d2d_brush *brush, struct d2d_d3d_render_target *render_target,
ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
const D2D1_BRUSH_PROPERTIES *brush_desc) DECLSPEC_HIDDEN;
void d2d_brush_bind_resources(struct d2d_brush *brush, ID3D10Device *device) DECLSPEC_HIDDEN;
struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface) DECLSPEC_HIDDEN;
struct d2d_stroke_style
......@@ -153,12 +160,14 @@ struct d2d_bitmap
ID2D1Bitmap ID2D1Bitmap_iface;
LONG refcount;
ID3D10ShaderResourceView *view;
D2D1_SIZE_U pixel_size;
float dpi_x;
float dpi_y;
};
void d2d_bitmap_init(struct d2d_bitmap *bitmap, D2D1_SIZE_U size, const void *src_data,
UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc) DECLSPEC_HIDDEN;
HRESULT d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_d3d_render_target *render_target,
D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc) DECLSPEC_HIDDEN;
struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface) DECLSPEC_HIDDEN;
#endif /* __WINE_D2D1_PRIVATE_H */
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