1 /*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "modules/sksg/include/SkSGPath.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPaint.h"
12 #include "src/core/SkRectPriv.h"
13
14 namespace sksg {
15
Path(const SkPath & path)16 Path::Path(const SkPath& path) : fPath(path) {}
17
onClip(SkCanvas * canvas,bool antiAlias) const18 void Path::onClip(SkCanvas* canvas, bool antiAlias) const {
19 canvas->clipPath(fPath, SkClipOp::kIntersect, antiAlias);
20 }
21
onDraw(SkCanvas * canvas,const SkPaint & paint) const22 void Path::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
23 canvas->drawPath(fPath, paint);
24 }
25
onContains(const SkPoint & p) const26 bool Path::onContains(const SkPoint& p) const {
27 return fPath.contains(p.x(), p.y());
28 }
29
onRevalidate(InvalidationController *,const SkMatrix &)30 SkRect Path::onRevalidate(InvalidationController*, const SkMatrix&) {
31 SkASSERT(this->hasInval());
32
33 const auto ft = fPath.getFillType();
34 return (ft == SkPathFillType::kWinding || ft == SkPathFillType::kEvenOdd)
35 // "Containing" fills have finite bounds.
36 ? fPath.computeTightBounds()
37 // Inverse fills are "infinite".
38 : SkRectPriv::MakeLargeS32();
39 }
40
onAsPath() const41 SkPath Path::onAsPath() const {
42 return fPath;
43 }
44
45 } // namespace sksg
46