• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "SkSGTransform.h"
12 #include "SkSGTransformPriv.h"
13 
14 namespace sksg {
15 
GeometryTransform(sk_sp<GeometryNode> child,sk_sp<Transform> transform)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 
~GeometryTransform()23 GeometryTransform::~GeometryTransform() {
24     this->unobserveInval(fChild);
25     this->unobserveInval(fTransform);
26 }
27 
onClip(SkCanvas * canvas,bool antiAlias) const28 void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const {
29     canvas->clipPath(fTransformedPath, SkClipOp::kIntersect, antiAlias);
30 }
31 
onDraw(SkCanvas * canvas,const SkPaint & paint) const32 void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
33     canvas->drawPath(fTransformedPath, paint);
34 }
35 
onRevalidate(InvalidationController * ic,const SkMatrix & ctm)36 SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
37     SkASSERT(this->hasInval());
38 
39     // We don't care about matrix reval results.
40     fTransform->revalidate(ic, ctm);
41     const auto m = TransformPriv::As<SkMatrix>(fTransform);
42 
43     auto bounds = fChild->revalidate(ic, ctm);
44     fTransformedPath = fChild->asPath();
45     fTransformedPath.transform(m);
46     fTransformedPath.shrinkToFit();
47 
48     m.mapRect(&bounds);
49     return  bounds;
50 }
51 
onAsPath() const52 SkPath GeometryTransform::onAsPath() const {
53     return fTransformedPath;
54 }
55 
56 } // namespace sksg
57