blob: 33c73a5b2b2d982bf51a4b0e9e11ec158d0b28a2 [file] [log] [blame]
Florin Malita4aa44412017-12-19 12:21:02 -05001/*
2 * Copyright 2017 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 "SkSGDraw.h"
9
10#include "SkSGGeometryNode.h"
Florin Malita2a2dfcb2017-12-28 19:24:07 -050011#include "SkSGInvalidationController.h"
Florin Malita4aa44412017-12-19 12:21:02 -050012#include "SkSGPaintNode.h"
13
14namespace sksg {
15
16Draw::Draw(sk_sp<GeometryNode> geometry, sk_sp<PaintNode> paint)
17 : fGeometry(std::move(geometry))
18 , fPaint(std::move(paint)) {
19 fGeometry->addInvalReceiver(this);
20 fPaint->addInvalReceiver(this);
21}
22
23Draw::~Draw() {
24 fGeometry->removeInvalReceiver(this);
25 fPaint->removeInvalReceiver(this);
26}
27
28void Draw::onRender(SkCanvas* canvas) const {
Florin Malita73964152018-01-21 10:26:46 -050029 const auto& paint = fPaint->makePaint();
30 const auto skipDraw = paint.nothingToDraw() ||
31 (paint.getStyle() == SkPaint::kStroke_Style && paint.getStrokeWidth() <= 0);
32
33 if (!skipDraw) {
34 fGeometry->draw(canvas, paint);
35 }
Florin Malita4aa44412017-12-19 12:21:02 -050036}
37
Florin Malitac14f1442018-01-05 11:32:31 -050038SkRect Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
Florin Malitac75e2402018-01-03 16:17:29 -050039 SkASSERT(this->hasInval());
Florin Malita4aa44412017-12-19 12:21:02 -050040
Florin Malita0401e7e2018-01-10 14:00:32 -050041 auto bounds = fGeometry->revalidate(ic, ctm);
Florin Malita4aa44412017-12-19 12:21:02 -050042 fPaint->revalidate(ic, ctm);
Florin Malita2a2dfcb2017-12-28 19:24:07 -050043
Florin Malita0401e7e2018-01-10 14:00:32 -050044 const auto& paint = fPaint->makePaint();
45 SkASSERT(paint.canComputeFastBounds());
46
47 return paint.computeFastBounds(bounds, &bounds);
Florin Malita4aa44412017-12-19 12:21:02 -050048}
49
50} // namespace sksg