Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: src/core/SkStrokeRec.cpp

Issue 1928133002: Unify implementations of stroking radius calculations (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: use makeOutset Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPaint.cpp ('k') | src/gpu/batches/GrTessellatingPathRenderer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkStrokeRec.cpp
diff --git a/src/core/SkStrokeRec.cpp b/src/core/SkStrokeRec.cpp
index 6aed573418c3b4fc34629344aa7389085faa1fb2..f3cca1653f046a3d75713fed16fcfcfa9401f2a5 100644
--- a/src/core/SkStrokeRec.cpp
+++ b/src/core/SkStrokeRec.cpp
@@ -134,3 +134,31 @@ void SkStrokeRec::applyToPaint(SkPaint* paint) const {
paint->setStrokeCap((SkPaint::Cap)fCap);
paint->setStrokeJoin((SkPaint::Join)fJoin);
}
+
+static inline SkScalar get_inflation_bounds(SkPaint::Join join,
+ SkScalar strokeWidth,
+ SkScalar miterLimit) {
+ if (strokeWidth < 0) { // fill
+ return 0;
+ } else if (0 == strokeWidth) {
+ return SK_Scalar1;
+ }
+ // since we're stroked, outset the rect by the radius (and join type)
+ SkScalar radius = SkScalarHalf(strokeWidth);
+ if (SkPaint::kMiter_Join == join) {
+ if (miterLimit > SK_Scalar1) {
+ radius = SkScalarMul(miterLimit, radius);
+ }
+ }
+ return radius;
+}
+
+SkScalar SkStrokeRec::getInflationRadius() const {
+ return get_inflation_bounds((SkPaint::Join)fJoin, fWidth, fMiterLimit);
+}
+
+SkScalar SkStrokeRec::GetInflationRadius(const SkPaint& paint, SkPaint::Style style) {
+ SkScalar width = SkPaint::kFill_Style == style ? -SK_Scalar1 : paint.getStrokeWidth();
+ return get_inflation_bounds(paint.getStrokeJoin(), width, paint.getStrokeMiter());
+
+}
« no previous file with comments | « src/core/SkPaint.cpp ('k') | src/gpu/batches/GrTessellatingPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698