SkCanvas: Helpers for draw{Point,Line,Circle}

Change-Id: Ie9c7d3b8f01aee435563b23b7d27f098f07dd287
Reviewed-on: https://skia-review.googlesource.com/16909
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2017-05-15 13:35:35 -04:00 committed by Skia Commit-Bot
parent 03d1e59bda
commit 23e474cb73
13 changed files with 34 additions and 25 deletions

View File

@ -68,7 +68,7 @@ void SkSVGLine::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
SkPoint p0, p1; SkPoint p0, p1;
std::tie(p0, p1) = this->resolve(lctx); std::tie(p0, p1) = this->resolve(lctx);
canvas->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint); canvas->drawLine(p0, p1, paint);
} }
SkPath SkSVGLine::onAsPath(const SkSVGRenderContext& ctx) const { SkPath SkSVGLine::onAsPath(const SkSVGRenderContext& ctx) const {

View File

@ -103,7 +103,7 @@ protected:
SkScalar arcLen = rad * R; SkScalar arcLen = rad * R;
SkPoint pos; SkPoint pos;
if (meas.getPosTan(arcLen, &pos, nullptr)) { if (meas.getPosTan(arcLen, &pos, nullptr)) {
canvas->drawLine(0, 0, pos.x(), pos.y(), measPaint); canvas->drawLine({0, 0}, pos, measPaint);
} }
} }
} }

View File

@ -160,9 +160,9 @@ protected:
SkPaint ctrlPtPaint; SkPaint ctrlPtPaint;
ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); ctrlPtPaint.setColor(rand.nextU() | 0xFF000000);
canvas->drawCircle(controlPts[0].fX, controlPts[0].fY, 8.f, ctrlPtPaint); canvas->drawCircle(controlPts[0], 8.f, ctrlPtPaint);
for (int i = 1; i < 4; ++i) { for (int i = 1; i < 4; ++i) {
canvas->drawCircle(controlPts[i].fX, controlPts[i].fY, 6.f, ctrlPtPaint); canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
} }
SkPaint polyPaint; SkPaint polyPaint;
@ -178,7 +178,7 @@ protected:
SkPoint* pts = chopped + 3 * c; SkPoint* pts = chopped + 3 * c;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
canvas->drawCircle(pts[i].fX, pts[i].fY, 3.f, choppedPtPaint); canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
} }
SkRect bounds; SkRect bounds;
@ -299,7 +299,7 @@ protected:
SkPaint ctrlPtPaint; SkPaint ctrlPtPaint;
ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); ctrlPtPaint.setColor(rand.nextU() | 0xFF000000);
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
canvas->drawCircle(controlPts[i].fX, controlPts[i].fY, 6.f, ctrlPtPaint); canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
} }
SkPaint polyPaint; SkPaint polyPaint;
@ -314,7 +314,7 @@ protected:
for (int c = 0; c < cnt; ++c) { for (int c = 0; c < cnt; ++c) {
SkPoint* pts = dst[c].fPts; SkPoint* pts = dst[c].fPts;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
canvas->drawCircle(pts[i].fX, pts[i].fY, 3.f, choppedPtPaint); canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
} }
SkRect bounds; SkRect bounds;
@ -516,7 +516,7 @@ protected:
SkPaint ctrlPtPaint; SkPaint ctrlPtPaint;
ctrlPtPaint.setColor(rand.nextU() | 0xFF000000); ctrlPtPaint.setColor(rand.nextU() | 0xFF000000);
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
canvas->drawCircle(controlPts[i].fX, controlPts[i].fY, 6.f, ctrlPtPaint); canvas->drawCircle(controlPts[i], 6.f, ctrlPtPaint);
} }
SkPaint polyPaint; SkPaint polyPaint;
@ -532,7 +532,7 @@ protected:
SkPoint* pts = chopped + 2 * c; SkPoint* pts = chopped + 2 * c;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
canvas->drawCircle(pts[i].fX, pts[i].fY, 3.f, choppedPtPaint); canvas->drawCircle(pts[i], 3.f, choppedPtPaint);
} }
SkRect bounds; SkRect bounds;

View File

@ -150,7 +150,7 @@ protected:
SkPaint giantPaint; SkPaint giantPaint;
giantPaint.setAntiAlias(true); giantPaint.setAntiAlias(true);
giantPaint.setColor(0x80808080); giantPaint.setColor(0x80808080);
canvas->drawCircle(giantCenter.fX, giantCenter.fY, giantRadius, giantPaint); canvas->drawCircle(giantCenter, giantRadius, giantPaint);
SkRandom rand; SkRandom rand;
canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1); canvas->translate(20 * SK_Scalar1, 20 * SK_Scalar1);

View File

@ -140,7 +140,7 @@ DEF_SIMPLE_GM(arccirclegap, canvas, 250, 250) {
SkPaint paint; SkPaint paint;
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style); paint.setStyle(SkPaint::kStroke_Style);
canvas->drawCircle(c.fX, c.fY, radius, paint); canvas->drawCircle(c, radius, paint);
SkPath path; SkPath path;
path.moveTo(288.88884710654133f, -280.26680862609f); path.moveTo(288.88884710654133f, -280.26680862609f);
path.arcTo(0, 0, -39.00216443306411f, 400.6058925796476f, radius); path.arcTo(0, 0, -39.00216443306411f, 400.6058925796476f, radius);
@ -156,7 +156,7 @@ DEF_SIMPLE_GM(largecircle, canvas, 250, 250) {
SkPaint paint; SkPaint paint;
paint.setAntiAlias(true); paint.setAntiAlias(true);
paint.setStyle(SkPaint::kStroke_Style); paint.setStyle(SkPaint::kStroke_Style);
canvas->drawCircle(c.fX, c.fY, radius, paint); canvas->drawCircle(c, radius, paint);
} }
DEF_SIMPLE_GM(crbug_640176, canvas, 250, 250) { DEF_SIMPLE_GM(crbug_640176, canvas, 250, 250) {

View File

@ -115,7 +115,7 @@ protected:
rot.postTranslate(3.f, 0); rot.postTranslate(3.f, 0);
for (int i = 0; i < 12; ++i) { for (int i = 0; i < 12; ++i) {
hairPaint.setColor(GetColor(&colorRandom)); hairPaint.setColor(GetColor(&colorRandom));
canvas->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, hairPaint); canvas->drawLine(pts[0], pts[1], hairPaint);
rot.mapPoints(pts, 2); rot.mapPoints(pts, 2);
} }
} }

View File

@ -84,7 +84,7 @@ private:
surface->getCanvas()->drawRect(border, paint); surface->getCanvas()->drawRect(border, paint);
paint.setColor(SK_ColorBLACK); paint.setColor(SK_ColorBLACK);
surface->getCanvas()->drawLine(start.x(), start.y(), end.x(), end.y(), paint); surface->getCanvas()->drawLine(start, end, paint);
paint.reset(); paint.reset();
paint.setColor(color); paint.setColor(color);

View File

@ -614,6 +614,9 @@ public:
/** Helper method for drawing a single point. See drawPoints() for more details. /** Helper method for drawing a single point. See drawPoints() for more details.
*/ */
void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint); void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
void drawPoint(SkPoint p, const SkPaint& paint) {
this->drawPoint(p.x(), p.y(), paint);
}
/** Draw a line segment with the specified start and stop x,y coordinates, /** Draw a line segment with the specified start and stop x,y coordinates,
using the specified paint. NOTE: since a line is always "framed", the using the specified paint. NOTE: since a line is always "framed", the
@ -625,6 +628,9 @@ public:
@param paint The paint used to draw the line @param paint The paint used to draw the line
*/ */
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint); void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint);
void drawLine(SkPoint p0, SkPoint p1, const SkPaint& paint) {
this->drawLine(p0.x(), p0.y(), p1.x(), p1.y(), paint);
}
/** Draw the specified rectangle using the specified paint. The rectangle /** Draw the specified rectangle using the specified paint. The rectangle
will be filled or stroked based on the Style in the paint. will be filled or stroked based on the Style in the paint.
@ -681,6 +687,9 @@ public:
@param paint The paint used to draw the circle @param paint The paint used to draw the circle
*/ */
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint); void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
void drawCircle(SkPoint center, SkScalar radius, const SkPaint& paint) {
this->drawCircle(center.x(), center.y(), radius, paint);
}
/** Draw the specified arc, which will be scaled to fit inside the /** Draw the specified arc, which will be scaled to fit inside the
specified oval. Sweep angles are not treated as modulo 360 and thus can specified oval. Sweep angles are not treated as modulo 360 and thus can

View File

@ -1056,15 +1056,15 @@ public:
SkVector bisect = { (lastV.fX + nextV.fX) / 2, (lastV.fY + nextV.fY) / 2 }; SkVector bisect = { (lastV.fX + nextV.fX) / 2, (lastV.fY + nextV.fY) / 2 };
bisect.setLength(fWidthControl.fValLo * 2); bisect.setLength(fWidthControl.fValLo * 2);
if (fBisectButton.enabled()) { if (fBisectButton.enabled()) {
canvas->drawLine(pt.fX, pt.fY, pt.fX + bisect.fX, pt.fY + bisect.fY, fSkeletonPaint); canvas->drawLine(pt, pt + bisect, fSkeletonPaint);
} }
lastV.setLength(fWidthControl.fValLo); lastV.setLength(fWidthControl.fValLo);
if (fBisectButton.enabled()) { if (fBisectButton.enabled()) {
canvas->drawLine(pt.fX, pt.fY, pt.fX - lastV.fY, pt.fY + lastV.fX, fSkeletonPaint); canvas->drawLine(pt, {pt.fX - lastV.fY, pt.fY + lastV.fX}, fSkeletonPaint);
} }
nextV.setLength(fWidthControl.fValLo); nextV.setLength(fWidthControl.fValLo);
if (fBisectButton.enabled()) { if (fBisectButton.enabled()) {
canvas->drawLine(pt.fX, pt.fY, pt.fX + nextV.fY, pt.fY - nextV.fX, fSkeletonPaint); canvas->drawLine(pt, {pt.fX + nextV.fY, pt.fY - nextV.fX}, fSkeletonPaint);
} }
if (fJoinButton.enabled()) { if (fJoinButton.enabled()) {
SkScalar r = fWidthControl.fValLo; SkScalar r = fWidthControl.fValLo;
@ -1117,8 +1117,8 @@ public:
SkPoint maxPt = SkEvalQuadAt(pts, t); SkPoint maxPt = SkEvalQuadAt(pts, t);
SkVector tangent = SkEvalQuadTangentAt(pts, t); SkVector tangent = SkEvalQuadTangentAt(pts, t);
tangent.setLength(fWidthControl.fValLo * 2); tangent.setLength(fWidthControl.fValLo * 2);
canvas->drawLine(maxPt.fX, maxPt.fY, canvas->drawLine(maxPt, {maxPt.fX + tangent.fY, maxPt.fY - tangent.fX},
maxPt.fX + tangent.fY, maxPt.fY - tangent.fX, fSkeletonPaint); fSkeletonPaint);
} }
} break; } break;
case SkPath::kConic_Verb: case SkPath::kConic_Verb:
@ -1163,8 +1163,8 @@ public:
SkVector tangent; SkVector tangent;
SkEvalCubicAt(pts, tMax[tIndex], &maxPt, &tangent, NULL); SkEvalCubicAt(pts, tMax[tIndex], &maxPt, &tangent, NULL);
tangent.setLength(fWidthControl.fValLo * 2); tangent.setLength(fWidthControl.fValLo * 2);
canvas->drawLine(maxPt.fX, maxPt.fY, canvas->drawLine(maxPt, {maxPt.fX + tangent.fY, maxPt.fY - tangent.fX},
maxPt.fX + tangent.fY, maxPt.fY - tangent.fX, fSkeletonPaint); fSkeletonPaint);
} }
} break; } break;
case SkPath::kClose_Verb: case SkPath::kClose_Verb:

View File

@ -402,7 +402,7 @@ protected:
paint.setStyle(SkPaint::kStroke_Style); paint.setStyle(SkPaint::kStroke_Style);
paint.setBlendMode(SkBlendMode::kXor); paint.setBlendMode(SkBlendMode::kXor);
paint.setColorFilter(lightingFilter); paint.setColorFilter(lightingFilter);
canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green canvas->drawLine(start, stop, paint); // should not be green
paint.setBlendMode(SkBlendMode::kSrcOver); paint.setBlendMode(SkBlendMode::kSrcOver);
paint.setColorFilter(nullptr); paint.setColorFilter(nullptr);

View File

@ -261,7 +261,7 @@ void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) {
r.inset(SK_Scalar1/3, SK_Scalar1/3); r.inset(SK_Scalar1/3, SK_Scalar1/3);
fMinSurface->getCanvas()->clipRect(r, kIntersect_SkClipOp, true); fMinSurface->getCanvas()->clipRect(r, kIntersect_SkClipOp, true);
} }
fMinSurface->getCanvas()->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, paint); fMinSurface->getCanvas()->drawLine(pts[0], pts[1], paint);
if (fUseClip) { if (fUseClip) {
fMinSurface->getCanvas()->restore(); fMinSurface->getCanvas()->restore();
} }

View File

@ -77,7 +77,7 @@ static void line_proc(SkCanvas* canvas, const SkPaint& paint,
for (int i = 0; i < 400; i++) { for (int i = 0; i < 400; i++) {
generate_pts(pts, N, WIDTH, HEIGHT); generate_pts(pts, N, WIDTH, HEIGHT);
canvas->drawLine(pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY, paint); canvas->drawLine(pts[0], pts[1], paint);
if (!check_bitmap_margin(bm, MARGIN)) { if (!check_bitmap_margin(bm, MARGIN)) {
SkDebugf("---- hairline failure (%g %g) (%g %g)\n", SkDebugf("---- hairline failure (%g %g) (%g %g)\n",
pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY); pts[0].fX, pts[0].fY, pts[1].fX, pts[1].fY);

View File

@ -202,7 +202,7 @@ protected:
const int j = (i + 1) % N; const int j = (i + 1) % N;
p.setColor(fEdgeColor[i]); p.setColor(fEdgeColor[i]);
p.setAlpha(0x88); p.setAlpha(0x88);
canvas->drawLine(fPoly[i].x(), fPoly[i].y(), fPoly[j].x(), fPoly[j].y(), p); canvas->drawLine(fPoly[i], fPoly[j], p);
} }
p.setStyle(SkPaint::kFill_Style); p.setStyle(SkPaint::kFill_Style);