2018-01-07 13:54:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkSGTrimEffect.h"
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
2018-03-07 21:37:38 +00:00
|
|
|
#include "SkStrokeRec.h"
|
2018-03-13 21:52:41 +00:00
|
|
|
#include "SkTrimPathEffect.h"
|
2018-01-07 13:54:24 +00:00
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
TrimEffect::TrimEffect(sk_sp<GeometryNode> child)
|
|
|
|
: fChild(std::move(child)) {
|
2018-01-22 15:19:28 +00:00
|
|
|
this->observeInval(fChild);
|
2018-01-07 13:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrimEffect::~TrimEffect() {
|
2018-01-22 15:19:28 +00:00
|
|
|
this->unobserveInval(fChild);
|
2018-01-07 13:54:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 21:31:14 +00:00
|
|
|
void TrimEffect::onClip(SkCanvas* canvas, bool antiAlias) const {
|
2018-03-07 21:37:38 +00:00
|
|
|
canvas->clipPath(fTrimmedPath, SkClipOp::kIntersect, antiAlias);
|
2018-01-29 21:31:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-07 13:54:24 +00:00
|
|
|
void TrimEffect::onDraw(SkCanvas* canvas, const SkPaint& paint) const {
|
|
|
|
SkASSERT(!paint.getPathEffect());
|
|
|
|
|
2018-03-07 21:37:38 +00:00
|
|
|
canvas->drawPath(fTrimmedPath, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPath TrimEffect::onAsPath() const {
|
|
|
|
return fTrimmedPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRect TrimEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
|
|
|
|
SkASSERT(this->hasInval());
|
|
|
|
|
|
|
|
const auto childbounds = fChild->revalidate(ic, ctm);
|
2018-03-13 21:52:41 +00:00
|
|
|
const auto path = fChild->asPath();
|
2018-03-07 21:37:38 +00:00
|
|
|
|
2018-03-22 16:20:02 +00:00
|
|
|
if (auto trim = SkTrimPathEffect::Make(fStart, fStop, fMode)) {
|
2018-03-13 21:52:41 +00:00
|
|
|
fTrimmedPath.reset();
|
|
|
|
SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle);
|
|
|
|
SkAssertResult(trim->filterPath(&fTrimmedPath, path, &rec, &childbounds));
|
|
|
|
} else {
|
|
|
|
fTrimmedPath = path;
|
2018-03-07 21:37:38 +00:00
|
|
|
}
|
2018-01-07 13:54:24 +00:00
|
|
|
|
2018-03-07 21:37:38 +00:00
|
|
|
return fTrimmedPath.computeTightBounds();
|
2018-01-07 13:54:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sksg
|