skia2/experimental/sksg/SkSGGroup.cpp
Florin Malita 0ebf4192f1 [sksg] More inval fiddling
Node subclasses can now control whether their bounds (changes)
contribute to damage.

Tristate:

  * Default:   The node bounds contribute to damage if the node itself was
               invalidated, observing hasSelfInval().  This is the default
               behavior.

  * ForceSelf: The node bounds contribute to damage, regardless of
               hasSelfInval().  Used for domain-boundary nodes (e.g. Draw),
               which gate blocked fragments (e.g. geometry, paint nodes).

  * BlockSelf: The node bounds do not contribute to damage, regardless of
               hasSelfInval().  Used for nodes which do not contribute
               damage directly (e.g. paints, geometry).

TBR=
Change-Id: I7c941c7ea12e14b008d846ec13108e66e34dbc73
Reviewed-on: https://skia-review.googlesource.com/91104
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2018-01-05 00:42:14 +00:00

67 lines
1.4 KiB
C++

/*
* 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 "SkSGGroup.h"
namespace sksg {
Group::Group() {}
Group::~Group() {
for (const auto& child : fChildren) {
child->removeInvalReceiver(this);
}
}
void Group::addChild(sk_sp<RenderNode> node) {
// should we allow duplicates?
for (const auto& child : fChildren) {
if (child == node) {
return;
}
}
node->addInvalReceiver(this);
fChildren.push_back(std::move(node));
this->invalidateSelf();
}
void Group::removeChild(const sk_sp<RenderNode>& node) {
int origCount = fChildren.count();
for (int i = 0; i < origCount; ++i) {
if (fChildren[i] == node) {
fChildren.removeShuffle(i);
node->removeInvalReceiver(this);
break;
}
}
SkASSERT(fChildren.count() == origCount - 1);
this->invalidateSelf();
}
void Group::onRender(SkCanvas* canvas) const {
for (const auto& child : fChildren) {
child->render(canvas);
}
}
Node::RevalidationResult Group::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) {
SkASSERT(this->hasInval());
RevalidationResult result = { SkRect::MakeEmpty(), Damage::kDefault };
for (const auto& child : fChildren) {
result.fBounds.join(child->revalidate(ic, ctm));
}
return result;
}
} // namespace sksg