2017-12-19 17:21:02 +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 "SkSGDraw.h"
|
|
|
|
|
|
|
|
#include "SkSGGeometryNode.h"
|
2017-12-29 00:24:07 +00:00
|
|
|
#include "SkSGInvalidationController.h"
|
2017-12-19 17:21:02 +00:00
|
|
|
#include "SkSGPaintNode.h"
|
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
Draw::Draw(sk_sp<GeometryNode> geometry, sk_sp<PaintNode> paint)
|
|
|
|
: fGeometry(std::move(geometry))
|
|
|
|
, fPaint(std::move(paint)) {
|
2018-01-22 15:19:28 +00:00
|
|
|
this->observeInval(fGeometry);
|
|
|
|
this->observeInval(fPaint);
|
2017-12-19 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Draw::~Draw() {
|
2018-01-22 15:19:28 +00:00
|
|
|
this->unobserveInval(fGeometry);
|
|
|
|
this->unobserveInval(fPaint);
|
2017-12-19 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Draw::onRender(SkCanvas* canvas) const {
|
2018-01-21 15:26:46 +00:00
|
|
|
const auto& paint = fPaint->makePaint();
|
|
|
|
const auto skipDraw = paint.nothingToDraw() ||
|
|
|
|
(paint.getStyle() == SkPaint::kStroke_Style && paint.getStrokeWidth() <= 0);
|
|
|
|
|
|
|
|
if (!skipDraw) {
|
|
|
|
fGeometry->draw(canvas, paint);
|
|
|
|
}
|
2017-12-19 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 16:32:31 +00:00
|
|
|
SkRect Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
|
2018-01-03 21:17:29 +00:00
|
|
|
SkASSERT(this->hasInval());
|
2017-12-19 17:21:02 +00:00
|
|
|
|
2018-01-10 19:00:32 +00:00
|
|
|
auto bounds = fGeometry->revalidate(ic, ctm);
|
2017-12-19 17:21:02 +00:00
|
|
|
fPaint->revalidate(ic, ctm);
|
2017-12-29 00:24:07 +00:00
|
|
|
|
2018-01-10 19:00:32 +00:00
|
|
|
const auto& paint = fPaint->makePaint();
|
|
|
|
SkASSERT(paint.canComputeFastBounds());
|
|
|
|
|
|
|
|
return paint.computeFastBounds(bounds, &bounds);
|
2017-12-19 17:21:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace sksg
|