void draw(SkCanvas* canvas) { SkPaint paint; SkPath path; paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(4); path.moveTo(0, 0); path.arcTo({20, 20, 120, 120}, -90, 90, false); canvas->drawPath(path, paint); path.rewind(); path.arcTo({120, 20, 220, 120}, -90, 90, false); canvas->drawPath(path, paint); path.rewind(); path.moveTo(0, 0); path.arcTo({20, 120, 120, 220}, -90, 90, true); canvas->drawPath(path, paint); }
void SkPathStroker::finishContour(bool close, bool currIsLine) { if (fSegmentCount > 0) { SkPoint pt; if (close) { fJoiner(&fOuter, &fInner, fPrevUnitNormal, fPrevPt, fFirstUnitNormal, fRadius, fInvMiterLimit, fPrevIsLine, currIsLine); fOuter.close(); // now add fInner as its own contour fInner.getLastPt(&pt); fOuter.moveTo(pt.fX, pt.fY); fOuter.reversePathTo(fInner); fOuter.close(); } else { // add caps to start and end // cap the end fInner.getLastPt(&pt); fCapper(&fOuter, fPrevPt, fPrevNormal, pt, currIsLine ? &fInner : NULL); fOuter.reversePathTo(fInner); // cap the start fCapper(&fOuter, fFirstPt, -fFirstNormal, fFirstOuterPt, fPrevIsLine ? &fInner : NULL); fOuter.close(); } } // since we may re-use fInner, we rewind instead of reset, to save on // reallocating its internal storage. fInner.rewind(); fSegmentCount = -1; }
void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkXfermode::Mode mode, const SkPaint& paint) { SkPath path; path.setIsVolatile(true); for (int i = 0; i < count; ++i) { SkPoint quad[4]; xform[i].toQuad(tex[i].width(), tex[i].height(), quad); SkMatrix localM; localM.setRSXform(xform[i]); localM.preTranslate(-tex[i].left(), -tex[i].top()); SkPaint pnt(paint); sk_sp<SkShader> shader = atlas->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &localM); if (!shader) { break; } pnt.setShader(std::move(shader)); if (colors) { pnt.setColorFilter(SkColorFilter::MakeModeFilter(colors[i], mode)); } path.rewind(); path.addPoly(quad, 4, true); path.setConvexity(SkPath::kConvex_Convexity); this->drawPath(draw, path, pnt, nullptr, true); } }
void SkSVGDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint) { SkPath path; switch (mode) { // todo case SkCanvas::kPoints_PointMode: SkDebugf("unsupported operation: drawPoints(kPoints_PointMode)\n"); break; case SkCanvas::kLines_PointMode: count -= 1; for (size_t i = 0; i < count; i += 2) { path.rewind(); path.moveTo(pts[i]); path.lineTo(pts[i+1]); AutoElement elem("path", fWriter, fResourceBucket, draw, paint); elem.addPathAttributes(path); } break; case SkCanvas::kPolygon_PointMode: if (count > 1) { path.addPoly(pts, SkToInt(count), false); path.moveTo(pts[0]); AutoElement elem("path", fWriter, fResourceBucket, draw, paint); elem.addPathAttributes(path); } break; } }
void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkXfermode::Mode mode, const SkPaint& paint) { SkPath path; path.setIsVolatile(true); for (int i = 0; i < count; ++i) { SkPoint quad[4]; xform[i].toQuad(tex[i].width(), tex[i].height(), quad); SkMatrix localM; localM.setRSXform(xform[i]); localM.preTranslate(-tex[i].left(), -tex[i].top()); SkPaint pnt(paint); pnt.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &localM))->unref(); if (colors && colors[i] != SK_ColorWHITE) { SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[i], mode)); pnt.setColorFilter(cf); } path.rewind(); path.addPoly(quad, 4, true); path.setConvexity(SkPath::kConvex_Convexity); this->drawPath(draw, path, pnt, NULL, true); } }
void onDraw(int loops, SkCanvas*) override { SkPath dst; for (int i = 0; i < loops; ++i) { SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); fPE->filterPath(&dst, fPath, &rec, nullptr); dst.rewind(); } }
static void _update_path(mbe_t *mbe) { SkPath *path = mbe->path; SkPath *subpath = mbe->subpath; SkMatrix canvas_matrix; SkPoint point; MB_MATRIX_2_SKMATRIX(canvas_matrix, mbe->states->matrix); path->addPath(*subpath, canvas_matrix); subpath->getLastPt(&point); subpath->rewind(); subpath->moveTo(point); }
void mbe_stroke(mbe_t *canvas) { SkPath *path = canvas->path; SkPaint *paint = canvas->paint; ASSERT(ptn); ASSERT(path); ASSERT(paint); if(!canvas->subpath->isEmpty()) _update_path(canvas); _prepare_paint(canvas, SkPaint::kStroke_Style); canvas->canvas->drawPath(*path, *paint); _finish_paint(canvas); path->rewind(); canvas->subpath->rewind(); }