Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 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 "SkSGGeometryTransform.h" |
| 9 | |
| 10 | #include "SkCanvas.h" |
| 11 | |
| 12 | namespace sksg { |
| 13 | |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 14 | GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Transform> transform) |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 15 | : fChild(std::move(child)) |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 16 | , fTransform(std::move(transform)) { |
Florin Malita | 3ba3fa7 | 2018-01-22 10:19:28 -0500 | [diff] [blame] | 17 | this->observeInval(fChild); |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 18 | this->observeInval(fTransform); |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | GeometryTransform::~GeometryTransform() { |
Florin Malita | 3ba3fa7 | 2018-01-22 10:19:28 -0500 | [diff] [blame] | 22 | this->unobserveInval(fChild); |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 23 | this->unobserveInval(fTransform); |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 24 | } |
| 25 | |
Florin Malita | 38ea40e | 2018-01-29 16:31:14 -0500 | [diff] [blame] | 26 | void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const { |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 27 | canvas->clipPath(fTransformedPath, SkClipOp::kIntersect, antiAlias); |
Florin Malita | 38ea40e | 2018-01-29 16:31:14 -0500 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const { |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 31 | canvas->drawPath(fTransformedPath, paint); |
Florin Malita | 38ea40e | 2018-01-29 16:31:14 -0500 | [diff] [blame] | 32 | } |
| 33 | |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 34 | SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
| 35 | SkASSERT(this->hasInval()); |
| 36 | |
| 37 | // We don't care about matrix reval results. |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 38 | fTransform->revalidate(ic, ctm); |
| 39 | const auto m = fTransform->asMatrix(); |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 40 | |
| 41 | auto bounds = fChild->revalidate(ic, ctm); |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 42 | fTransformedPath = fChild->asPath(); |
| 43 | fTransformedPath.transform(m); |
| 44 | fTransformedPath.shrinkToFit(); |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 45 | |
| 46 | m.mapRect(&bounds); |
| 47 | return bounds; |
| 48 | } |
| 49 | |
| 50 | SkPath GeometryTransform::onAsPath() const { |
Florin Malita | 919e209 | 2019-01-09 15:37:57 -0500 | [diff] [blame^] | 51 | return fTransformedPath; |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 52 | } |
| 53 | |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 54 | } // namespace sksg |