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