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
GeometryTransform(sk_sp<GeometryNode> child,sk_sp<Matrix> matrix)14 GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix)
15 : fChild(std::move(child))
16 , fMatrix(std::move(matrix)) {
17 this->observeInval(fChild);
18 this->observeInval(fMatrix);
19 }
20
~GeometryTransform()21 GeometryTransform::~GeometryTransform() {
22 this->unobserveInval(fChild);
23 this->unobserveInval(fMatrix);
24 }
25
onClip(SkCanvas * canvas,bool antiAlias) const26 void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const {
27 canvas->clipPath(fTransformed, SkClipOp::kIntersect, antiAlias);
28 }
29
onDraw(SkCanvas * canvas,const SkPaint & paint) const30 void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
31 canvas->drawPath(fTransformed, paint);
32 }
33
onRevalidate(InvalidationController * ic,const SkMatrix & ctm)34 SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
35 SkASSERT(this->hasInval());
36
37 // We don't care about matrix reval results.
38 fMatrix->revalidate(ic, ctm);
39 const auto& m = fMatrix->getMatrix();
40
41 auto bounds = fChild->revalidate(ic, ctm);
42 fTransformed = fChild->asPath();
43 fTransformed.transform(m);
44
45 m.mapRect(&bounds);
46 return bounds;
47 }
48
onAsPath() const49 SkPath GeometryTransform::onAsPath() const {
50 return fTransformed;
51 }
52
53 } // namespace sksg
54