d2d1: Take the world transform into account when calculating the bitmap brush texcoord transform.

This commit is contained in:
Henri Verbeet 2015-04-15 11:07:13 +02:00 committed by Alexandre Julliard
parent aad0ab8101
commit a7b2f5e889
1 changed files with 44 additions and 21 deletions

View File

@ -32,6 +32,18 @@ struct d2d_draw_text_layout_ctx
D2D1_DRAW_TEXT_OPTIONS options;
};
static void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b)
{
D2D_MATRIX_3X2_F tmp = *a;
a->_11 = tmp._11 * b->_11 + tmp._12 * b->_21;
a->_12 = tmp._11 * b->_12 + tmp._12 * b->_22;
a->_21 = tmp._21 * b->_11 + tmp._22 * b->_21;
a->_22 = tmp._21 * b->_12 + tmp._22 * b->_22;
a->_31 = tmp._31 * b->_11 + tmp._32 * b->_21 + b->_31;
a->_32 = tmp._31 * b->_12 + tmp._32 * b->_22 + b->_32;
}
static void d2d_point_transform(D2D1_POINT_2F *dst, const D2D1_MATRIX_3X2_F *matrix, float x, float y)
{
dst->x = x * matrix->_11 + y * matrix->_21 + matrix->_31;
@ -543,7 +555,7 @@ static void STDMETHODCALLTYPE d2d_d3d_render_target_FillRectangle(ID2D1RenderTar
{
float _11, _21, _31, pad0;
float _12, _22, _32, pad1;
} transform, transform_inverse;
} transform;
TRACE("iface %p, rect %p, brush %p.\n", iface, rect, brush);
@ -598,38 +610,49 @@ static void STDMETHODCALLTYPE d2d_d3d_render_target_FillRectangle(ID2D1RenderTar
if (brush_impl->type == D2D_BRUSH_TYPE_BITMAP)
{
struct d2d_bitmap *bitmap = brush_impl->u.bitmap.bitmap;
float rt_scale, rt_bitmap_scale, d;
D2D_MATRIX_3X2_F w, b;
float dpi_scale, d;
ps = render_target->rect_bitmap_ps;
/* Scale for dpi. */
w = render_target->drawing_state.transform;
dpi_scale = render_target->dpi_x / 96.0f;
w._11 *= dpi_scale;
w._21 *= dpi_scale;
w._31 *= dpi_scale;
dpi_scale = render_target->dpi_y / 96.0f;
w._12 *= dpi_scale;
w._22 *= dpi_scale;
w._32 *= dpi_scale;
/* Scale for bitmap size and dpi. */
rt_scale = render_target->dpi_x / 96.0f;
rt_bitmap_scale = bitmap->pixel_size.width * (bitmap->dpi_x / 96.0f) * rt_scale;
transform._11 = brush_impl->transform._11 * rt_bitmap_scale;
transform._21 = brush_impl->transform._21 * rt_bitmap_scale;
transform._31 = brush_impl->transform._31 * rt_scale;
rt_scale = render_target->dpi_y / 96.0f;
rt_bitmap_scale = bitmap->pixel_size.height * (bitmap->dpi_y / 96.0f) * rt_scale;
transform._12 = brush_impl->transform._12 * rt_bitmap_scale;
transform._22 = brush_impl->transform._22 * rt_bitmap_scale;
transform._32 = brush_impl->transform._32 * rt_scale;
b = brush_impl->transform;
dpi_scale = bitmap->pixel_size.width * (bitmap->dpi_x / 96.0f);
b._11 *= dpi_scale;
b._21 *= dpi_scale;
dpi_scale = bitmap->pixel_size.height * (bitmap->dpi_y / 96.0f);
b._12 *= dpi_scale;
b._22 *= dpi_scale;
d2d_matrix_multiply(&b, &w);
/* Invert the matrix. (Because the matrix is applied to the sampling
* coordinates. I.e., to scale the bitmap by 2 we need to divide the
* coordinates by 2.) */
d = transform._11 * transform._22 - transform._21 * transform._12;
d = b._11 * b._22 - b._21 * b._12;
if (d != 0.0f)
{
transform_inverse._11 = transform._22 / d;
transform_inverse._21 = -transform._21 / d;
transform_inverse._31 = (transform._21 * transform._32 - transform._31 * transform._22) / d;
transform_inverse._12 = -transform._12 / d;
transform_inverse._22 = transform._11 / d;
transform_inverse._32 = -(transform._11 * transform._32 - transform._31 * transform._12) / d;
transform._11 = b._22 / d;
transform._21 = -b._21 / d;
transform._31 = (b._21 * b._32 - b._31 * b._22) / d;
transform._12 = -b._12 / d;
transform._22 = b._11 / d;
transform._32 = -(b._11 * b._32 - b._31 * b._12) / d;
}
buffer_desc.ByteWidth = sizeof(transform_inverse);
buffer_data.pSysMem = &transform_inverse;
buffer_desc.ByteWidth = sizeof(transform);
buffer_data.pSysMem = &transform;
}
else
{