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/SkClipOp.h"
12 #include "include/core/SkPathTypes.h"
13 #include "include/core/SkPoint.h"
14 #include "include/private/base/SkAssert.h"
15 #include "src/core/SkRectPriv.h"
16
17 class SkMatrix;
18
19 namespace sksg {
20
Path(const SkPath & path)21 Path::Path(const SkPath& path) : fPath(path) {}
22
onClip(SkCanvas * canvas,bool antiAlias) const23 void Path::onClip(SkCanvas* canvas, bool antiAlias) const {
24 canvas->clipPath(fPath, SkClipOp::kIntersect, antiAlias);
25 }
26
onDraw(SkCanvas * canvas,const SkPaint & paint) const27 void Path::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
28 canvas->drawPath(fPath, paint);
29 }
30
onContains(const SkPoint & p) const31 bool Path::onContains(const SkPoint& p) const {
32 return fPath.contains(p.x(), p.y());
33 }
34
onRevalidate(InvalidationController *,const SkMatrix &)35 SkRect Path::onRevalidate(InvalidationController*, const SkMatrix&) {
36 SkASSERT(this->hasInval());
37
38 const auto ft = fPath.getFillType();
39 return (ft == SkPathFillType::kWinding || ft == SkPathFillType::kEvenOdd)
40 // "Containing" fills have finite bounds.
41 ? fPath.computeTightBounds()
42 // Inverse fills are "infinite".
43 : SkRectPriv::MakeLargeS32();
44 }
45
onAsPath() const46 SkPath Path::onAsPath() const {
47 return fPath;
48 }
49
50 } // namespace sksg
51