blob: efeee0577d208dafc30b5d67c681dfecd794a6d0 [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 {
29 fGeometry->draw(canvas, fPaint->makePaint());
30}
31
Florin Malitac14f1442018-01-05 11:32:31 -050032SkRect Draw::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
Florin Malitac75e2402018-01-03 16:17:29 -050033 SkASSERT(this->hasInval());
Florin Malita4aa44412017-12-19 12:21:02 -050034
Florin Malita0ebf4192018-01-04 19:21:58 -050035 // TODO: adjust bounds for paint
Florin Malitac75e2402018-01-03 16:17:29 -050036 const auto bounds = fGeometry->revalidate(ic, ctm);
Florin Malita4aa44412017-12-19 12:21:02 -050037 fPaint->revalidate(ic, ctm);
Florin Malita2a2dfcb2017-12-28 19:24:07 -050038
Florin Malitac14f1442018-01-05 11:32:31 -050039 return bounds;
Florin Malita4aa44412017-12-19 12:21:02 -050040}
41
42} // namespace sksg