skia2/modules/sksg/include/SkSGRenderNode.h
Florin Malita ef26fcb13f [sksg] Fix image filter content inval rect tracking
Image filters cannot let descendent damage pass through, as they may
transform their inputs arbitrarily.

Introduce the notion of "damage override" SG nodes (nodes which block
descendent damage and replace it with their own), and update
ImageFilterEffect to opt in for this behavior.

Also make InvalidationController damage dispatch optional (such that we
don't accumulate inval rects unnecessarily).

TBR=
Change-Id: Ie9f7d32ecdcc77dbe6ea009aed9ce269b3649a04
Reviewed-on: https://skia-review.googlesource.com/c/191005
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2019-02-10 21:43:20 +00:00

103 lines
2.9 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.
*/
#ifndef SkSGRenderNode_DEFINED
#define SkSGRenderNode_DEFINED
#include "SkSGNode.h"
#include "SkColorFilter.h"
class SkCanvas;
class SkImageFilter;
class SkPaint;
namespace sksg {
/**
* Base class for nodes which can render to a canvas.
*/
class RenderNode : public Node {
protected:
struct RenderContext;
public:
// Render the node and its descendants to the canvas.
void render(SkCanvas*, const RenderContext* = nullptr) const;
protected:
explicit RenderNode(uint32_t inval_traits = 0);
virtual void onRender(SkCanvas*, const RenderContext*) const = 0;
// Paint property overrides.
// These are deferred until we can determine whether they can be applied to the individual
// draw paints, or whether they require content isolation (applied to a layer).
struct RenderContext {
sk_sp<SkColorFilter> fColorFilter;
float fOpacity = 1;
// Returns true if the paint was modified.
bool modulatePaint(SkPaint*) const;
};
class ScopedRenderContext final {
public:
ScopedRenderContext(SkCanvas*, const RenderContext*);
~ScopedRenderContext();
ScopedRenderContext(ScopedRenderContext&& that) { *this = std::move(that); }
ScopedRenderContext& operator=(ScopedRenderContext&& that) {
fCanvas = that.fCanvas;
fCtx = std::move(that.fCtx);
fRestoreCount = that.fRestoreCount;
// scope ownership is being transferred
that.fRestoreCount = -1;
return *this;
}
operator const RenderContext* () const { return &fCtx; }
// Add (cumulative) paint overrides to a render node sub-DAG.
ScopedRenderContext&& modulateOpacity(float opacity);
ScopedRenderContext&& modulateColorFilter(sk_sp<SkColorFilter>);
// Force content isolation for a node sub-DAG by applying the RenderContext
// overrides via a layer.
ScopedRenderContext&& setIsolation(const SkRect& bounds, bool do_isolate);
// Similarly, force content isolation by applying the RenderContext overrides and
// an image filter via a single layer.
ScopedRenderContext&& setFilterIsolation(const SkRect& bounds, sk_sp<SkImageFilter>);
private:
// stack-only
void* operator new(size_t) = delete;
void* operator new(size_t, void*) = delete;
// Scopes cannot be copied.
ScopedRenderContext(const ScopedRenderContext&) = delete;
ScopedRenderContext& operator=(const ScopedRenderContext&) = delete;
SkCanvas* fCanvas;
RenderContext fCtx;
int fRestoreCount;
};
private:
friend class ImageFilterEffect;
typedef Node INHERITED;
};
} // namespace sksg
#endif // SkSGRenderNode_DEFINED