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 | |
| 14 | GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix) |
| 15 | : fChild(std::move(child)) |
| 16 | , fMatrix(std::move(matrix)) { |
Florin Malita | 3ba3fa7 | 2018-01-22 10:19:28 -0500 | [diff] [blame^] | 17 | this->observeInval(fChild); |
| 18 | this->observeInval(fMatrix); |
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); |
| 23 | this->unobserveInval(fMatrix); |
Florin Malita | 16d0ad0 | 2018-01-19 15:07:29 -0500 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
| 27 | SkASSERT(this->hasInval()); |
| 28 | |
| 29 | // We don't care about matrix reval results. |
| 30 | fMatrix->revalidate(ic, ctm); |
| 31 | const auto& m = fMatrix->getMatrix(); |
| 32 | |
| 33 | auto bounds = fChild->revalidate(ic, ctm); |
| 34 | fTransformed = fChild->asPath(); |
| 35 | fTransformed.transform(m); |
| 36 | |
| 37 | m.mapRect(&bounds); |
| 38 | return bounds; |
| 39 | } |
| 40 | |
| 41 | SkPath GeometryTransform::onAsPath() const { |
| 42 | return fTransformed; |
| 43 | } |
| 44 | |
| 45 | void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const { |
| 46 | canvas->drawPath(fTransformed, paint); |
| 47 | } |
| 48 | |
| 49 | } // namespace sksg |