2018-01-19 20:07:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkSGGeometryTransform.h"
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix)
|
|
|
|
: fChild(std::move(child))
|
|
|
|
, fMatrix(std::move(matrix)) {
|
2018-01-22 15:19:28 +00:00
|
|
|
this->observeInval(fChild);
|
|
|
|
this->observeInval(fMatrix);
|
2018-01-19 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GeometryTransform::~GeometryTransform() {
|
2018-01-22 15:19:28 +00:00
|
|
|
this->unobserveInval(fChild);
|
|
|
|
this->unobserveInval(fMatrix);
|
2018-01-19 20:07:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 21:31:14 +00:00
|
|
|
void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const {
|
|
|
|
canvas->clipPath(fTransformed, SkClipOp::kIntersect, antiAlias);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
|
|
|
|
canvas->drawPath(fTransformed, paint);
|
|
|
|
}
|
|
|
|
|
2018-01-19 20:07:29 +00:00
|
|
|
SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
|
|
|
|
SkASSERT(this->hasInval());
|
|
|
|
|
|
|
|
// We don't care about matrix reval results.
|
|
|
|
fMatrix->revalidate(ic, ctm);
|
|
|
|
const auto& m = fMatrix->getMatrix();
|
|
|
|
|
|
|
|
auto bounds = fChild->revalidate(ic, ctm);
|
|
|
|
fTransformed = fChild->asPath();
|
|
|
|
fTransformed.transform(m);
|
|
|
|
|
|
|
|
m.mapRect(&bounds);
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPath GeometryTransform::onAsPath() const {
|
|
|
|
return fTransformed;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sksg
|