d2d1: Implement ellipse drawing.

Currently the ellipse is approximated with quadratic Bézier curves.

Signed-off-by: Giovanni Mascellani <gio@debian.org>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Giovanni Mascellani 2020-01-28 16:17:45 +03:30 committed by Alexandre Julliard
parent f04bcb2d1b
commit aec8701399
3 changed files with 306 additions and 3 deletions

View File

@ -465,6 +465,10 @@ struct d2d_geometry
union
{
struct
{
D2D1_ELLIPSE ellipse;
} ellipse;
struct
{
ID2D1GeometrySink ID2D1GeometrySink_iface;
@ -501,6 +505,8 @@ struct d2d_geometry
} u;
};
HRESULT d2d_ellipse_geometry_init(struct d2d_geometry *geometry,
ID2D1Factory *factory, const D2D1_ELLIPSE *ellipse) DECLSPEC_HIDDEN;
void d2d_path_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory) DECLSPEC_HIDDEN;
HRESULT d2d_rectangle_geometry_init(struct d2d_geometry *geometry,
ID2D1Factory *factory, const D2D1_RECT_F *rect) DECLSPEC_HIDDEN;
@ -636,4 +642,12 @@ static inline const char *debug_d2d_rounded_rect(const D2D1_ROUNDED_RECT *rounde
rounded_rect->rect.right, rounded_rect->rect.bottom, rounded_rect->radiusX, rounded_rect->radiusY);
}
static inline const char *debug_d2d_ellipse(const D2D1_ELLIPSE *ellipse)
{
if (!ellipse)
return "(null)";
return wine_dbg_sprintf("(%.8e, %.8e)[%.8e, %.8e]",
ellipse->point.x, ellipse->point.y, ellipse->radiusX, ellipse->radiusY);
}
#endif /* __WINE_D2D1_PRIVATE_H */

View File

@ -178,9 +178,25 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateRoundedRectangleGeometry(ID2D
static HRESULT STDMETHODCALLTYPE d2d_factory_CreateEllipseGeometry(ID2D1Factory2 *iface,
const D2D1_ELLIPSE *ellipse, ID2D1EllipseGeometry **geometry)
{
FIXME("iface %p, ellipse %p, geometry %p stub!\n", iface, ellipse, geometry);
struct d2d_geometry *object;
HRESULT hr;
return E_NOTIMPL;
TRACE("iface %p, ellipse %s, geometry %p.\n", iface, debug_d2d_ellipse(ellipse), geometry);
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
if (FAILED(hr = d2d_ellipse_geometry_init(object, (ID2D1Factory *)iface, ellipse)))
{
WARN("Failed to initialize ellipse geometry, hr %#x.\n", hr);
heap_free(object);
return hr;
}
TRACE("Created ellipse geometry %p.\n", object);
*geometry = (ID2D1EllipseGeometry *)&object->ID2D1Geometry_iface;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGeometryGroup(ID2D1Factory2 *iface,

View File

@ -3524,6 +3524,278 @@ void d2d_path_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory
geometry->u.path.bounds.bottom = -FLT_MAX;
}
static inline struct d2d_geometry *impl_from_ID2D1EllipseGeometry(ID2D1EllipseGeometry *iface)
{
return CONTAINING_RECORD(iface, struct d2d_geometry, ID2D1Geometry_iface);
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_QueryInterface(ID2D1EllipseGeometry *iface,
REFIID iid, void **out)
{
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
if (IsEqualGUID(iid, &IID_ID2D1EllipseGeometry)
|| IsEqualGUID(iid, &IID_ID2D1Geometry)
|| IsEqualGUID(iid, &IID_ID2D1Resource)
|| IsEqualGUID(iid, &IID_IUnknown))
{
ID2D1EllipseGeometry_AddRef(iface);
*out = iface;
return S_OK;
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
*out = NULL;
return E_NOINTERFACE;
}
static ULONG STDMETHODCALLTYPE d2d_ellipse_geometry_AddRef(ID2D1EllipseGeometry *iface)
{
struct d2d_geometry *geometry = impl_from_ID2D1EllipseGeometry(iface);
ULONG refcount = InterlockedIncrement(&geometry->refcount);
TRACE("%p increasing refcount to %u.\n", iface, refcount);
return refcount;
}
static ULONG STDMETHODCALLTYPE d2d_ellipse_geometry_Release(ID2D1EllipseGeometry *iface)
{
struct d2d_geometry *geometry = impl_from_ID2D1EllipseGeometry(iface);
ULONG refcount = InterlockedDecrement(&geometry->refcount);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
if (!refcount)
{
d2d_geometry_cleanup(geometry);
heap_free(geometry);
}
return refcount;
}
static void STDMETHODCALLTYPE d2d_ellipse_geometry_GetFactory(ID2D1EllipseGeometry *iface, ID2D1Factory **factory)
{
struct d2d_geometry *geometry = impl_from_ID2D1EllipseGeometry(iface);
TRACE("iface %p, factory %p.\n", iface, factory);
ID2D1Factory_AddRef(*factory = geometry->factory);
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_GetBounds(ID2D1EllipseGeometry *iface,
const D2D1_MATRIX_3X2_F *transform, D2D1_RECT_F *bounds)
{
FIXME("iface %p, transform %p, bounds %p stub!\n", iface, transform, bounds);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_GetWidenedBounds(ID2D1EllipseGeometry *iface,
float stroke_width, ID2D1StrokeStyle *stroke_style, const D2D1_MATRIX_3X2_F *transform,
float tolerance, D2D1_RECT_F *bounds)
{
FIXME("iface %p, stroke_width %.8e, stroke_style %p, transform %p, tolerance %.8e, bounds %p stub!\n",
iface, stroke_width, stroke_style, transform, tolerance, bounds);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_StrokeContainsPoint(ID2D1EllipseGeometry *iface,
D2D1_POINT_2F point, float stroke_width, ID2D1StrokeStyle *stroke_style, const D2D1_MATRIX_3X2_F *transform,
float tolerance, BOOL *contains)
{
FIXME("iface %p, point %s, stroke_width %.8e, stroke_style %p, transform %p, tolerance %.8e, contains %p stub!\n",
iface, debug_d2d_point_2f(&point), stroke_width, stroke_style, transform, tolerance, contains);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_FillContainsPoint(ID2D1EllipseGeometry *iface,
D2D1_POINT_2F point, const D2D1_MATRIX_3X2_F *transform, float tolerance, BOOL *contains)
{
FIXME("iface %p, point %s, transform %p, tolerance %.8e, contains %p stub!\n",
iface, debug_d2d_point_2f(&point), transform, tolerance, contains);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_CompareWithGeometry(ID2D1EllipseGeometry *iface,
ID2D1Geometry *geometry, const D2D1_MATRIX_3X2_F *transform, float tolerance, D2D1_GEOMETRY_RELATION *relation)
{
FIXME("iface %p, geometry %p, transform %p, tolerance %.8e, relation %p stub!\n",
iface, geometry, transform, tolerance, relation);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_Simplify(ID2D1EllipseGeometry *iface,
D2D1_GEOMETRY_SIMPLIFICATION_OPTION option, const D2D1_MATRIX_3X2_F *transform, float tolerance,
ID2D1SimplifiedGeometrySink *sink)
{
FIXME("iface %p, option %#x, transform %p, tolerance %.8e, sink %p stub!\n",
iface, option, transform, tolerance, sink);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_Tessellate(ID2D1EllipseGeometry *iface,
const D2D1_MATRIX_3X2_F *transform, float tolerance, ID2D1TessellationSink *sink)
{
FIXME("iface %p, transform %p, tolerance %.8e, sink %p stub!\n", iface, transform, tolerance, sink);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_CombineWithGeometry(ID2D1EllipseGeometry *iface,
ID2D1Geometry *geometry, D2D1_COMBINE_MODE combine_mode, const D2D1_MATRIX_3X2_F *transform,
float tolerance, ID2D1SimplifiedGeometrySink *sink)
{
FIXME("iface %p, geometry %p, combine_mode %#x, transform %p, tolerance %.8e, sink %p stub!\n",
iface, geometry, combine_mode, transform, tolerance, sink);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_Outline(ID2D1EllipseGeometry *iface,
const D2D1_MATRIX_3X2_F *transform, float tolerance, ID2D1SimplifiedGeometrySink *sink)
{
FIXME("iface %p, transform %p, tolerance %.8e, sink %p stub!\n", iface, transform, tolerance, sink);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_ComputeArea(ID2D1EllipseGeometry *iface,
const D2D1_MATRIX_3X2_F *transform, float tolerance, float *area)
{
FIXME("iface %p, transform %p, tolerance %.8e, area %p stub!\n", iface, transform, tolerance, area);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_ComputeLength(ID2D1EllipseGeometry *iface,
const D2D1_MATRIX_3X2_F *transform, float tolerance, float *length)
{
FIXME("iface %p, transform %p, tolerance %.8e, length %p stub!\n", iface, transform, tolerance, length);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_ComputePointAtLength(ID2D1EllipseGeometry *iface,
float length, const D2D1_MATRIX_3X2_F *transform, float tolerance, D2D1_POINT_2F *point,
D2D1_POINT_2F *tangent)
{
FIXME("iface %p, length %.8e, transform %p, tolerance %.8e, point %p, tangent %p stub!\n",
iface, length, transform, tolerance, point, tangent);
return E_NOTIMPL;
}
static HRESULT STDMETHODCALLTYPE d2d_ellipse_geometry_Widen(ID2D1EllipseGeometry *iface, float stroke_width,
ID2D1StrokeStyle *stroke_style, const D2D1_MATRIX_3X2_F *transform, float tolerance,
ID2D1SimplifiedGeometrySink *sink)
{
FIXME("iface %p, stroke_width %.8e, stroke_style %p, transform %p, tolerance %.8e, sink %p stub!\n",
iface, stroke_width, stroke_style, transform, tolerance, sink);
return E_NOTIMPL;
}
static void STDMETHODCALLTYPE d2d_ellipse_geometry_GetRoundedRect(ID2D1EllipseGeometry *iface, D2D1_ELLIPSE *ellipse)
{
struct d2d_geometry *geometry = impl_from_ID2D1EllipseGeometry(iface);
TRACE("iface %p, ellipse %p.\n", iface, ellipse);
*ellipse = geometry->u.ellipse.ellipse;
}
static const struct ID2D1EllipseGeometryVtbl d2d_ellipse_geometry_vtbl =
{
d2d_ellipse_geometry_QueryInterface,
d2d_ellipse_geometry_AddRef,
d2d_ellipse_geometry_Release,
d2d_ellipse_geometry_GetFactory,
d2d_ellipse_geometry_GetBounds,
d2d_ellipse_geometry_GetWidenedBounds,
d2d_ellipse_geometry_StrokeContainsPoint,
d2d_ellipse_geometry_FillContainsPoint,
d2d_ellipse_geometry_CompareWithGeometry,
d2d_ellipse_geometry_Simplify,
d2d_ellipse_geometry_Tessellate,
d2d_ellipse_geometry_CombineWithGeometry,
d2d_ellipse_geometry_Outline,
d2d_ellipse_geometry_ComputeArea,
d2d_ellipse_geometry_ComputeLength,
d2d_ellipse_geometry_ComputePointAtLength,
d2d_ellipse_geometry_Widen,
d2d_ellipse_geometry_GetRoundedRect,
};
HRESULT d2d_ellipse_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory, const D2D1_ELLIPSE *ellipse)
{
D2D1_POINT_2F *v, v1, v2, v3, v4;
struct d2d_face *f;
float l, r, t, b;
d2d_geometry_init(geometry, factory, &identity, (ID2D1GeometryVtbl *)&d2d_ellipse_geometry_vtbl);
geometry->u.ellipse.ellipse = *ellipse;
if (!(geometry->fill.vertices = heap_alloc(4 * sizeof(*geometry->fill.vertices))))
goto fail;
if (!d2d_array_reserve((void **)&geometry->fill.faces,
&geometry->fill.faces_size, 2, sizeof(*geometry->fill.faces)))
goto fail;
l = ellipse->point.x - ellipse->radiusX;
r = ellipse->point.x + ellipse->radiusX;
t = ellipse->point.y - ellipse->radiusY;
b = ellipse->point.y + ellipse->radiusY;
d2d_point_set(&v1, r, t);
d2d_point_set(&v2, r, b);
d2d_point_set(&v3, l, b);
d2d_point_set(&v4, l, t);
v = geometry->fill.vertices;
d2d_point_set(&v[0], ellipse->point.x, t);
d2d_point_set(&v[1], r, ellipse->point.y);
d2d_point_set(&v[2], ellipse->point.x, b);
d2d_point_set(&v[3], l, ellipse->point.y);
geometry->fill.vertex_count = 4;
f = geometry->fill.faces;
d2d_face_set(&f[0], 0, 3, 2);
d2d_face_set(&f[1], 0, 2, 1);
geometry->fill.face_count = 2;
if (!d2d_geometry_fill_add_arc_triangle(geometry, &v[0], &v1, &v[1]))
goto fail;
if (!d2d_geometry_fill_add_arc_triangle(geometry, &v[1], &v2, &v[2]))
goto fail;
if (!d2d_geometry_fill_add_arc_triangle(geometry, &v[2], &v3, &v[3]))
goto fail;
if (!d2d_geometry_fill_add_arc_triangle(geometry, &v[3], &v4, &v[0]))
goto fail;
if (!d2d_geometry_outline_add_arc_quadrant(geometry, &v[0], &v1, &v[1]))
goto fail;
if (!d2d_geometry_outline_add_arc_quadrant(geometry, &v[1], &v2, &v[2]))
goto fail;
if (!d2d_geometry_outline_add_arc_quadrant(geometry, &v[2], &v3, &v[3]))
goto fail;
if (!d2d_geometry_outline_add_arc_quadrant(geometry, &v[3], &v4, &v[0]))
goto fail;
return S_OK;
fail:
d2d_geometry_cleanup(geometry);
return E_OUTOFMEMORY;
}
static inline struct d2d_geometry *impl_from_ID2D1RectangleGeometry(ID2D1RectangleGeometry *iface)
{
return CONTAINING_RECORD(iface, struct d2d_geometry, ID2D1Geometry_iface);
@ -4707,7 +4979,8 @@ struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface)
{
if (!iface)
return NULL;
assert(iface->lpVtbl == (const ID2D1GeometryVtbl *)&d2d_path_geometry_vtbl
assert(iface->lpVtbl == (const ID2D1GeometryVtbl *)&d2d_ellipse_geometry_vtbl
|| iface->lpVtbl == (const ID2D1GeometryVtbl *)&d2d_path_geometry_vtbl
|| iface->lpVtbl == (const ID2D1GeometryVtbl *)&d2d_rectangle_geometry_vtbl
|| iface->lpVtbl == (const ID2D1GeometryVtbl *)&d2d_rounded_rectangle_geometry_vtbl
|| iface->lpVtbl == (const ID2D1GeometryVtbl *)&d2d_transformed_geometry_vtbl