Flutter Engine
The Flutter Engine
SkSGClipEffect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 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
9
11#include "include/core/SkPath.h"
15
16class SkMatrix;
17struct SkPoint;
18
19namespace sksg {
20class InvalidationController;
21
23 : INHERITED(std::move(child))
24 , fClipNode(std::move(clip))
25 , fAntiAlias(aa)
26 , fForceClip(force_clip) {
27 this->observeInval(fClipNode);
28}
29
31 this->unobserveInval(fClipNode);
32}
33
34void ClipEffect::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
35 SkAutoCanvasRestore acr(canvas, !fNoop);
36 if (!fNoop) {
37 fClipNode->clip(canvas, fAntiAlias);
38 }
39
40 this->INHERITED::onRender(canvas, ctx);
41}
42
44 return fClipNode->contains(p) ? this->INHERITED::onNodeAt(p) : nullptr;
45}
46
48 SkASSERT(this->hasInval());
49
50 const auto clipBounds = fClipNode->revalidate(ic, ctm);
51 auto childBounds = this->INHERITED::onRevalidate(ic, ctm);
52
53 // When the child node is fully contained within the clip, it is usually safe to elide.
54 // An exception is clip-dependent sizing for saveLayer buffers, where the clip is always
55 // significant. For those cases, we provide a mechanism to disable elision.
56 fNoop = !fForceClip && fClipNode->asPath().conservativelyContainsRect(childBounds);
57
58 return childBounds.intersect(clipBounds) ? childBounds : SkRect::MakeEmpty();
59}
60
61} // namespace sksg
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
~ClipEffect() override
void onRender(SkCanvas *, const RenderContext *) const override
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
ClipEffect(sk_sp< RenderNode >, sk_sp< GeometryNode >, bool aa, bool force_clip)
const RenderNode * onNodeAt(const SkPoint &) const override
const RenderNode * onNodeAt(const SkPoint &) const override
void onRender(SkCanvas *, const RenderContext *) const override
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
void observeInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:61
void unobserveInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:84
bool hasInval() const
Definition: SkSGNode.h:60
Definition: Skottie.h:32
Definition: ref_ptr.h:256
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595