blob: 91367d48d692a139e89008eee7271feb400e9d57 [file] [log] [blame]
Florin Malita16d0ad02018-01-19 15:07:29 -05001/*
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
12namespace sksg {
13
14GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix)
15 : fChild(std::move(child))
16 , fMatrix(std::move(matrix)) {
Florin Malita3ba3fa72018-01-22 10:19:28 -050017 this->observeInval(fChild);
18 this->observeInval(fMatrix);
Florin Malita16d0ad02018-01-19 15:07:29 -050019}
20
21GeometryTransform::~GeometryTransform() {
Florin Malita3ba3fa72018-01-22 10:19:28 -050022 this->unobserveInval(fChild);
23 this->unobserveInval(fMatrix);
Florin Malita16d0ad02018-01-19 15:07:29 -050024}
25
26SkRect 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
41SkPath GeometryTransform::onAsPath() const {
42 return fTransformed;
43}
44
45void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
46 canvas->drawPath(fTransformed, paint);
47}
48
49} // namespace sksg