d2d1: Implement d2d_rectangle_geometry_GetBounds().
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
bc47dc3f41
commit
2485305b55
|
@ -449,4 +449,16 @@ static inline void d2d_point_transform(D2D1_POINT_2F *dst, const D2D1_MATRIX_3X2
|
|||
dst->y = x * matrix->_12 + y * matrix->_22 + matrix->_32;
|
||||
}
|
||||
|
||||
static inline void d2d_rect_expand(D2D1_RECT_F *dst, const D2D1_POINT_2F *point)
|
||||
{
|
||||
if (point->x < dst->left)
|
||||
dst->left = point->x;
|
||||
if (point->x > dst->right)
|
||||
dst->right = point->x;
|
||||
if (point->y < dst->top)
|
||||
dst->top = point->y;
|
||||
if (point->y > dst->bottom)
|
||||
dst->bottom = point->y;
|
||||
}
|
||||
|
||||
#endif /* __WINE_D2D1_PRIVATE_H */
|
||||
|
|
|
@ -510,18 +510,6 @@ static BOOL d2d_array_reserve(void **elements, size_t *capacity, size_t element_
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void d2d_figure_update_bounds(struct d2d_figure *figure, D2D1_POINT_2F vertex)
|
||||
{
|
||||
if (vertex.x < figure->bounds.left)
|
||||
figure->bounds.left = vertex.x;
|
||||
if (vertex.x > figure->bounds.right)
|
||||
figure->bounds.right = vertex.x;
|
||||
if (vertex.y < figure->bounds.top)
|
||||
figure->bounds.top = vertex.y;
|
||||
if (vertex.y > figure->bounds.bottom)
|
||||
figure->bounds.bottom = vertex.y;
|
||||
}
|
||||
|
||||
static BOOL d2d_figure_insert_vertex(struct d2d_figure *figure, size_t idx, D2D1_POINT_2F vertex)
|
||||
{
|
||||
if (!d2d_array_reserve((void **)&figure->vertices, &figure->vertices_size,
|
||||
|
@ -544,7 +532,7 @@ static BOOL d2d_figure_insert_vertex(struct d2d_figure *figure, size_t idx, D2D1
|
|||
(figure->vertex_count - idx) * sizeof(*figure->vertex_types));
|
||||
figure->vertices[idx] = vertex;
|
||||
figure->vertex_types[idx] = D2D_VERTEX_TYPE_NONE;
|
||||
d2d_figure_update_bounds(figure, vertex);
|
||||
d2d_rect_expand(&figure->bounds, &vertex);
|
||||
++figure->vertex_count;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -573,7 +561,7 @@ static BOOL d2d_figure_add_vertex(struct d2d_figure *figure, D2D1_POINT_2F verte
|
|||
|
||||
figure->vertices[figure->vertex_count] = vertex;
|
||||
figure->vertex_types[figure->vertex_count] = D2D_VERTEX_TYPE_NONE;
|
||||
d2d_figure_update_bounds(figure, vertex);
|
||||
d2d_rect_expand(&figure->bounds, &vertex);
|
||||
++figure->vertex_count;
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -2756,9 +2744,34 @@ static void STDMETHODCALLTYPE d2d_rectangle_geometry_GetFactory(ID2D1RectangleGe
|
|||
static HRESULT STDMETHODCALLTYPE d2d_rectangle_geometry_GetBounds(ID2D1RectangleGeometry *iface,
|
||||
const D2D1_MATRIX_3X2_F *transform, D2D1_RECT_F *bounds)
|
||||
{
|
||||
FIXME("iface %p, transform %p, bounds %p stub!\n", iface, transform, bounds);
|
||||
struct d2d_geometry *geometry = impl_from_ID2D1RectangleGeometry(iface);
|
||||
D2D1_RECT_F *rect;
|
||||
D2D1_POINT_2F p;
|
||||
|
||||
return E_NOTIMPL;
|
||||
TRACE("iface %p, transform %p, bounds %p.\n", iface, transform, bounds);
|
||||
|
||||
rect = &geometry->u.rectangle.rect;
|
||||
if (!transform)
|
||||
{
|
||||
*bounds = *rect;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
bounds->left = FLT_MAX;
|
||||
bounds->top = FLT_MAX;
|
||||
bounds->right = -FLT_MAX;
|
||||
bounds->bottom = -FLT_MAX;
|
||||
|
||||
d2d_point_transform(&p, transform, rect->left, rect->top);
|
||||
d2d_rect_expand(bounds, &p);
|
||||
d2d_point_transform(&p, transform, rect->left, rect->bottom);
|
||||
d2d_rect_expand(bounds, &p);
|
||||
d2d_point_transform(&p, transform, rect->right, rect->bottom);
|
||||
d2d_rect_expand(bounds, &p);
|
||||
d2d_point_transform(&p, transform, rect->right, rect->top);
|
||||
d2d_rect_expand(bounds, &p);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE d2d_rectangle_geometry_GetWidenedBounds(ID2D1RectangleGeometry *iface,
|
||||
|
|
|
@ -49,18 +49,6 @@ static ID2D1Brush *d2d_draw_get_text_brush(struct d2d_draw_text_layout_ctx *cont
|
|||
return context->brush;
|
||||
}
|
||||
|
||||
static void d2d_rect_expand(D2D1_RECT_F *dst, const D2D1_POINT_2F *point)
|
||||
{
|
||||
if (point->x < dst->left)
|
||||
dst->left = point->x;
|
||||
if (point->y < dst->top)
|
||||
dst->top = point->y;
|
||||
if (point->x > dst->right)
|
||||
dst->right = point->x;
|
||||
if (point->y > dst->bottom)
|
||||
dst->bottom = point->y;
|
||||
}
|
||||
|
||||
static void d2d_rect_intersect(D2D1_RECT_F *dst, const D2D1_RECT_F *src)
|
||||
{
|
||||
if (src->left > dst->left)
|
||||
|
|
|
@ -169,6 +169,14 @@ static BOOL compare_float(float f, float g, unsigned int ulps)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL compare_rect(const D2D1_RECT_F *rect, float left, float top, float right, float bottom, unsigned int ulps)
|
||||
{
|
||||
return compare_float(rect->left, left, ulps)
|
||||
&& compare_float(rect->top, top, ulps)
|
||||
&& compare_float(rect->right, right, ulps)
|
||||
&& compare_float(rect->bottom, bottom, ulps);
|
||||
}
|
||||
|
||||
static BOOL compare_sha1(void *data, unsigned int pitch, unsigned int bpp,
|
||||
unsigned int w, unsigned int h, const char *ref_sha1)
|
||||
{
|
||||
|
@ -1831,11 +1839,13 @@ static void test_path_geometry(void)
|
|||
static void test_rectangle_geometry(void)
|
||||
{
|
||||
ID2D1RectangleGeometry *geometry;
|
||||
D2D1_MATRIX_3X2_F matrix;
|
||||
D2D1_RECT_F rect, rect2;
|
||||
ID2D1Factory *factory;
|
||||
D2D1_POINT_2F point;
|
||||
BOOL contains;
|
||||
HRESULT hr;
|
||||
BOOL match;
|
||||
|
||||
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **)&factory);
|
||||
ok(SUCCEEDED(hr), "Failed to create factory, hr %#x.\n", hr);
|
||||
|
@ -1844,7 +1854,8 @@ static void test_rectangle_geometry(void)
|
|||
hr = ID2D1Factory_CreateRectangleGeometry(factory, &rect, &geometry);
|
||||
ok(SUCCEEDED(hr), "Failed to create geometry, hr %#x.\n", hr);
|
||||
ID2D1RectangleGeometry_GetRect(geometry, &rect2);
|
||||
ok(!memcmp(&rect, &rect2, sizeof(rect)), "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
match = compare_rect(&rect2, 0.0f, 0.0f, 0.0f, 0.0f, 0);
|
||||
ok(match, "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect2.left, rect2.top, rect2.right, rect2.bottom);
|
||||
ID2D1RectangleGeometry_Release(geometry);
|
||||
|
||||
|
@ -1852,7 +1863,8 @@ static void test_rectangle_geometry(void)
|
|||
hr = ID2D1Factory_CreateRectangleGeometry(factory, &rect, &geometry);
|
||||
ok(SUCCEEDED(hr), "Failed to create geometry, hr %#x.\n", hr);
|
||||
ID2D1RectangleGeometry_GetRect(geometry, &rect2);
|
||||
ok(!memcmp(&rect, &rect2, sizeof(rect)), "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
match = compare_rect(&rect2, 50.0f, 0.0f, 40.0f, 100.0f, 0);
|
||||
ok(match, "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect2.left, rect2.top, rect2.right, rect2.bottom);
|
||||
ID2D1RectangleGeometry_Release(geometry);
|
||||
|
||||
|
@ -1860,7 +1872,8 @@ static void test_rectangle_geometry(void)
|
|||
hr = ID2D1Factory_CreateRectangleGeometry(factory, &rect, &geometry);
|
||||
ok(SUCCEEDED(hr), "Failed to create geometry, hr %#x.\n", hr);
|
||||
ID2D1RectangleGeometry_GetRect(geometry, &rect2);
|
||||
ok(!memcmp(&rect, &rect2, sizeof(rect)), "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
match = compare_rect(&rect2, 0.0f, 100.0f, 40.0f, 50.0f, 0);
|
||||
ok(match, "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect2.left, rect2.top, rect2.right, rect2.bottom);
|
||||
ID2D1RectangleGeometry_Release(geometry);
|
||||
|
||||
|
@ -1868,7 +1881,8 @@ static void test_rectangle_geometry(void)
|
|||
hr = ID2D1Factory_CreateRectangleGeometry(factory, &rect, &geometry);
|
||||
ok(SUCCEEDED(hr), "Failed to create geometry, hr %#x.\n", hr);
|
||||
ID2D1RectangleGeometry_GetRect(geometry, &rect2);
|
||||
ok(!memcmp(&rect, &rect2, sizeof(rect)), "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
match = compare_rect(&rect2, 50.0f, 100.0f, 40.0f, 50.0f, 0);
|
||||
ok(match, "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect2.left, rect2.top, rect2.right, rect2.bottom);
|
||||
ID2D1RectangleGeometry_Release(geometry);
|
||||
|
||||
|
@ -1915,6 +1929,41 @@ static void test_rectangle_geometry(void)
|
|||
ok(SUCCEEDED(hr), "FillContainsPoint() failed, hr %#x.\n", hr);
|
||||
ok(!!contains, "Got wrong hit test result %d.\n", contains);
|
||||
|
||||
/* Test GetBounds(). */
|
||||
hr = ID2D1RectangleGeometry_GetBounds(geometry, NULL, &rect);
|
||||
ok(SUCCEEDED(hr), "Failed to get bounds.\n");
|
||||
match = compare_rect(&rect, 0.0f, 0.0f, 10.0f, 20.0f, 0);
|
||||
ok(match, "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect.left, rect.top, rect.right, rect.bottom);
|
||||
|
||||
set_matrix_identity(&matrix);
|
||||
translate_matrix(&matrix, 20.0f, 30.0f);
|
||||
scale_matrix(&matrix, 3.0f, 2.0f);
|
||||
rotate_matrix(&matrix, M_PI / -5.0f);
|
||||
hr = ID2D1RectangleGeometry_GetBounds(geometry, &matrix, &rect);
|
||||
ok(SUCCEEDED(hr), "Failed to get bounds.\n");
|
||||
match = compare_rect(&rect, 2.00000000e+01f, 1.82442951e+01f, 7.95376282e+01f, 6.23606796e+01f, 0);
|
||||
ok(match, "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect.left, rect.top, rect.right, rect.bottom);
|
||||
|
||||
set_matrix_identity(&matrix);
|
||||
translate_matrix(&matrix, 25.0f, 15.0f);
|
||||
scale_matrix(&matrix, 0.0f, 2.0f);
|
||||
hr = ID2D1RectangleGeometry_GetBounds(geometry, &matrix, &rect);
|
||||
ok(SUCCEEDED(hr), "Failed to get bounds.\n");
|
||||
match = compare_rect(&rect, 25.0f, 15.0f, 25.0f, 55.0f, 0);
|
||||
ok(match, "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect.left, rect.top, rect.right, rect.bottom);
|
||||
|
||||
set_matrix_identity(&matrix);
|
||||
translate_matrix(&matrix, 30.0f, 45.0f);
|
||||
scale_matrix(&matrix, 0.5f, 0.0f);
|
||||
hr = ID2D1RectangleGeometry_GetBounds(geometry, &matrix, &rect);
|
||||
ok(SUCCEEDED(hr), "Failed to get bounds.\n");
|
||||
match = compare_rect(&rect, 30.0f, 45.0f, 35.0f, 45.0f, 0);
|
||||
ok(match, "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}.\n",
|
||||
rect.left, rect.top, rect.right, rect.bottom);
|
||||
|
||||
ID2D1RectangleGeometry_Release(geometry);
|
||||
|
||||
ID2D1Factory_Release(factory);
|
||||
|
|
Loading…
Reference in New Issue