Florin Malita | 4aa4441 | 2017-12-19 12:21:02 -0500 | [diff] [blame] | 1 | /* |
| 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 Malita | 2a2dfcb | 2017-12-28 19:24:07 -0500 | [diff] [blame] | 11 | #include "SkSGInvalidationController.h" |
Florin Malita | 4aa4441 | 2017-12-19 12:21:02 -0500 | [diff] [blame] | 12 | #include "SkSGPaintNode.h" |
| 13 | |
| 14 | namespace sksg { |
| 15 | |
| 16 | Draw::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 | |
| 23 | Draw::~Draw() { |
| 24 | fGeometry->removeInvalReceiver(this); |
| 25 | fPaint->removeInvalReceiver(this); |
| 26 | } |
| 27 | |
| 28 | void Draw::onRender(SkCanvas* canvas) const { |
| 29 | fGeometry->draw(canvas, fPaint->makePaint()); |
| 30 | } |
| 31 | |
Florin Malita | c14f144 | 2018-01-05 11:32:31 -0500 | [diff] [blame] | 32 | SkRect Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { |
Florin Malita | c75e240 | 2018-01-03 16:17:29 -0500 | [diff] [blame] | 33 | SkASSERT(this->hasInval()); |
Florin Malita | 4aa4441 | 2017-12-19 12:21:02 -0500 | [diff] [blame] | 34 | |
Florin Malita | 0401e7e | 2018-01-10 14:00:32 -0500 | [diff] [blame^] | 35 | auto bounds = fGeometry->revalidate(ic, ctm); |
Florin Malita | 4aa4441 | 2017-12-19 12:21:02 -0500 | [diff] [blame] | 36 | fPaint->revalidate(ic, ctm); |
Florin Malita | 2a2dfcb | 2017-12-28 19:24:07 -0500 | [diff] [blame] | 37 | |
Florin Malita | 0401e7e | 2018-01-10 14:00:32 -0500 | [diff] [blame^] | 38 | const auto& paint = fPaint->makePaint(); |
| 39 | SkASSERT(paint.canComputeFastBounds()); |
| 40 | |
| 41 | return paint.computeFastBounds(bounds, &bounds); |
Florin Malita | 4aa4441 | 2017-12-19 12:21:02 -0500 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | } // namespace sksg |