Bug 1839474 - Add support for directly stroking circles to DrawTarget. r=lsalzman

D2D has a more efficient path when asked to stroke circles
vs. circular paths. This will let us use that.

Differential Revision: https://phabricator.services.mozilla.com/D181545
This commit is contained in:
Jeff Muizelaar 2023-06-20 19:28:48 +00:00
Родитель ec7ac1b850
Коммит 2c84305426
3 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -1544,6 +1544,18 @@ class DrawTarget : public external::AtomicRefCounted<DrawTarget> {
const StrokeOptions& aStrokeOptions = StrokeOptions(),
const DrawOptions& aOptions = DrawOptions()) = 0;
/**
* Stroke a circle on the DrawTarget with a certain source pattern.
*
* @param aCircle the parameters of the circle
* @param aPattern Pattern that forms the source of this stroking operation
* @param aOptions Options that are applied to this operation
*/
virtual void StrokeCircle(
const Point& aOrigin, float radius, const Pattern& aPattern,
const StrokeOptions& aStrokeOptions = StrokeOptions(),
const DrawOptions& aOptions = DrawOptions());
/**
* Stroke a path on the draw target with a certain source pattern.
*

Просмотреть файл

@ -179,6 +179,14 @@ void DrawTarget::FillRoundedRect(const RoundedRect& aRect,
Fill(path, aPattern, aOptions);
}
void DrawTarget::StrokeCircle(const Point& aOrigin, float radius,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,
const DrawOptions& aOptions) {
RefPtr<Path> path = MakePathForCircle(*this, aOrigin, radius);
Stroke(path, aPattern, aStrokeOptions, aOptions);
}
void DrawTarget::StrokeGlyphs(ScaledFont* aFont, const GlyphBuffer& aBuffer,
const Pattern& aPattern,
const StrokeOptions& aStrokeOptions,

Просмотреть файл

@ -258,6 +258,15 @@ inline already_AddRefed<Path> MakePathForEllipse(const DrawTarget& aDrawTarget,
return builder->Finish();
}
inline already_AddRefed<Path> MakePathForCircle(const DrawTarget& aDrawTarget,
const Point& aCenter,
float aRadius) {
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
builder->Arc(aCenter, aRadius, 0.0f, Float(2.0 * M_PI));
builder->Close();
return builder->Finish();
}
/**
* If aDrawTarget's transform only contains a translation, and if this line is
* a horizontal or vertical line, this function will snap the line's vertices