blob: b8e28f728631d1f66619312a2963107c468572af [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 "SkSGGroup.h"
9
10namespace sksg {
11
12Group::Group() {}
13
14Group::~Group() {
15 for (const auto& child : fChildren) {
16 child->removeInvalReceiver(this);
17 }
18}
19
20void Group::addChild(sk_sp<RenderNode> node) {
21 // should we allow duplicates?
22 for (const auto& child : fChildren) {
23 if (child == node) {
24 return;
25 }
26 }
27
28 node->addInvalReceiver(this);
29 fChildren.push_back(std::move(node));
30}
31
32void Group::removeChild(const sk_sp<RenderNode>& node) {
33 int origCount = fChildren.count();
34 for (int i = 0; i < origCount; ++i) {
35 if (fChildren[i] == node) {
36 fChildren.removeShuffle(i);
37 node->removeInvalReceiver(this);
38 break;
39 }
40 }
41 SkASSERT(fChildren.count() == origCount - 1);
42}
43
44void Group::onRender(SkCanvas* canvas) const {
45 for (const auto& child : fChildren) {
46 child->render(canvas);
47 }
48}
49
50void Group::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
51 for (const auto& child : fChildren) {
52 child->revalidate(ic, ctm);
53 }
54}
55
56} // namespace sksg