1 | /* |
2 | * Copyright 2018 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/SkSGGeometryTransform.h" |
9 | |
10 | #include "include/core/SkCanvas.h" |
11 | #include "modules/sksg/include/SkSGTransform.h" |
12 | #include "modules/sksg/src/SkSGTransformPriv.h" |
13 | |
14 | namespace sksg { |
15 | |
16 | GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Transform> transform) |
17 | : fChild(std::move(child)) |
18 | , fTransform(std::move(transform)) { |
19 | this->observeInval(fChild); |
20 | this->observeInval(fTransform); |
21 | } |
22 | |
23 | GeometryTransform::~GeometryTransform() { |
24 | this->unobserveInval(fChild); |
25 | this->unobserveInval(fTransform); |
26 | } |
27 | |
28 | void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const { |
29 | canvas->clipPath(fTransformedPath, SkClipOp::kIntersect, antiAlias); |
30 | } |
31 | |
32 | void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const { |
33 | canvas->drawPath(fTransformedPath, paint); |
34 | } |
35 | |
36 | bool GeometryTransform::onContains(const SkPoint& p) const { |
37 | return fTransformedPath.contains(p.x(), p.y()); |
38 | } |
39 | |
40 | SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
41 | SkASSERT(this->hasInval()); |
42 | |
43 | // We don't care about matrix reval results. |
44 | fTransform->revalidate(ic, ctm); |
45 | const auto m = TransformPriv::As<SkMatrix>(fTransform); |
46 | |
47 | auto bounds = fChild->revalidate(ic, ctm); |
48 | fTransformedPath = fChild->asPath(); |
49 | fTransformedPath.transform(m); |
50 | fTransformedPath.shrinkToFit(); |
51 | |
52 | m.mapRect(&bounds); |
53 | return bounds; |
54 | } |
55 | |
56 | SkPath GeometryTransform::onAsPath() const { |
57 | return fTransformedPath; |
58 | } |
59 | |
60 | } // namespace sksg |
61 | |