Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
FilterRegionContext.h File Reference
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdint>
#include <limits>
#include <optional>
#include <utility>
#include <variant>
#include <vector>
#include "donner/base/MathUtils.h"
#include "donner/base/RcString.h"
#include "donner/base/SmallVector.h"
#include "donner/base/Transform.h"
#include "donner/svg/components/animation/AnimationValueSampler.h"
#include "donner/svg/components/filter/FilterGraph.h"
Include dependency graph for FilterRegionContext.h:

Classes

struct  donner::svg::FilterInputMargin
 Input a filter layer's capture must include beyond each output pixel, in device pixels. More...
struct  donner::svg::FilterInputMarginBuilder
 Accumulates each primitive's input reach in device pixels, converting lengths with the same helpers and bounds the filter executors use. Each primitive's reach rounds up to whole pixels before the chain adds them: morphology radii round to the nearest pixel, blur kernels round up, and a fractional offset reads the whole pixels on both sides of its shift. More...
struct  donner::svg::TransformedShadowGraphs
 The shadow executed on the filter-aligned raster and its merge with the untouched capture. More...
struct  donner::svg::FilterInputBuffer
 Filter input raster layout relative to a viewport. Raster texel (0, 0) lies at viewport pixel (-offsetX, -offsetY). More...
struct  donner::svg::FilterInputAxis
 One axis of a FilterInputBuffer. More...
struct  donner::svg::FilterRegionSample
 Resolved clipping bounds and optional un-clipped animated geometry, in user coordinates. More...
struct  donner::svg::FilterRegionContext
 Per-invocation filter coordinates and subregion history, independent of GPU resources. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.
namespace  donner::svg
 Donner SVG library, which can load, manipulate and render SVG files.

Functions

double donner::svg::BoundedPositiveFilterPixels (double value)
 Clamp a finite nonnegative radius to the filter-work bound.
double donner::svg::BoundedSignedFilterPixels (double value)
 Clamp a finite offset to the filter-work bound.
double donner::svg::BoundedFilterOffsetPixels (double value)
 Clamp a device offset to the filter-work bound, treating an offset within a millionth of a pixel of a whole pixel as that whole pixel: unit conversions leave such residue on offsets authored as whole pixels, and resampling by it would only soften their edges.
size_t donner::svg::FilterInputSlotCount (const components::FilterNode &node)
 The number of inputs a primitive reads through the filter attribute surface. feComposite, feBlend and feDisplacementMap each take a second input (in2); feMerge is variadic and reads exactly the list it was built with, and every other primitive reads at most one input. The cap of two is deliberate rather than a lower bound: those primitives never sample a third input, so an extra entry a caller appends must not widen the node's subregion either.
components::FilterInput donner::svg::FilterInputOrDefault (const components::FilterNode &node, size_t index)
 The input in slot index, or the default for a slot the graph left empty. A slot the graph never populated is an unspecified in/in2 attribute, and both resolve the same way: to the preceding primitive's result, which is SourceGraphic only when this node is the first primitive in the filter. Falling back to the node's own first input instead would silently composite, blend, or displace a buffer against itself.
double donner::svg::FilterDeviceScaleX (const Transform2d &transform)
 Device scale of the filter X axis.
double donner::svg::FilterDeviceScaleY (const Transform2d &transform, double scaleX)
 Device scale of the filter Y axis.
double donner::svg::FilterLengthInPixels (double value, double bound, double scale, bool objectBounds)
 Resolve an effect length in device pixels.
Vector2d donner::svg::FilterOffsetInPixels (Vector2d offset, Vector2d bounds, bool objectBounds, const Transform2d &transform)
 Resolve a filter offset vector in device coordinates.
std::optional< size_t > donner::svg::PrecedingResultIndex (const components::FilterGraph &graph, size_t index, const RcString &name)
 Index of the closest node before index whose result is name, the node a reference to that name resolves to, or std::nullopt when no earlier node defines it.
const components::FilterNode * donner::svg::FilterFirstInputNode (const components::FilterGraph &graph, size_t index)
 The node a primitive's first input names, or nullptr when it reads a standard input.
Vector2d donner::svg::FilterDeviceAxisScale (const Transform2d &deviceFromFilter)
 Device pixels per filter user unit along each axis.
Vector2d donner::svg::TransformedPathLocalScale (const Transform2d &deviceFromFilter)
 Scale of the transformed path's local raster, clamped to at least one pixel per user unit.
bool donner::svg::IsBlurFilterNode (const components::FilterNode &node)
 Whether node is a Gaussian blur or drop shadow.
bool donner::svg::OnlyCapturedFilterInputs (const components::FilterNode &node)
 Whether node depends only on captured source pixels or results in its graph.
bool donner::svg::IsTransformedBlurPathNode (const components::FilterNode &node)
 Whether node may run on the transformed path's local raster: a blur, drop shadow, offset or merge without a primitive subregion whose standard inputs are SourceGraphic or SourceAlpha. Any named input is admitted, including forward or missing references, which the same executor resolves as it does on the device raster.
bool donner::svg::IsBlurringNode (const components::FilterNode &node, const Vector2d &deviceScale)
 Whether node is a Gaussian blur meeting kMinimumBlurringDeviationPixels on both axes.
bool donner::svg::FilterInputIsBlurred (const components::FilterGraph &graph, const std::vector< bool > &blurred, const components::FilterInput &input, size_t index)
 Whether input input of node index carries only blurred content, given blurred for the nodes before it: a standard input, an unresolved name or a forward reference does not.
bool donner::svg::IsShadowColorNode (const components::FilterNode &node)
 Whether node fills the shadow color or masks a flood with blurred alpha.
bool donner::svg::IsBlurredShadowColor (const components::FilterGraph &graph, const std::vector< bool > &blurred, size_t index)
 Whether the color input of an In composite is a flood and its mask was blurred.
size_t donner::svg::BlurPathInputCount (const components::FilterNode &node, bool omitForeground)
 Input slots contributing to a blur analysis. A shadow split leaves its foreground off-raster.
bool donner::svg::FilterOutputIsBlurred (const components::FilterGraph &graph, const Vector2d &deviceScale, bool splitShadow=false)
 Whether every path from SourceGraphic or SourceAlpha to the output of graph passes through a Gaussian blur (IsBlurringNode).
bool donner::svg::IsLinearBlurChain (const components::FilterGraph &graph)
 Whether graph is a chain of blurs, drop shadows and offsets in which each node reads only the previous result, the first reading SourceGraphic, with no named results.
bool donner::svg::IsEligibleForTransformedBlurPath (const components::FilterGraph &graph, const Transform2d &deviceFromFilter)
 Whether graph may run on the transformed path's local raster, whose axes are the filter's user axes scaled to device resolution, so a blur keeps its user-space shape under rotation or skew.
bool donner::svg::GraphHasAnisotropicBlur (const components::FilterGraph &graph)
 Whether any blur or drop shadow of graph has unequal X and Y deviations.
bool donner::svg::ShouldUseTransformedBlurPath (const components::FilterGraph &graph, const Transform2d &deviceFromFilter)
 Whether an eligible graph must use the local raster: always under skew, and under rotation when a blur is anisotropic, since a device-axis blur cannot reproduce either shape.
std::optional< components::FilterStandardInput > donner::svg::SharpShadowSource (const components::FilterInput &input)
 Return the standard source preserved as a sharp foreground, when input selects one.
std::optional< components::FilterStandardInput > donner::svg::ShadowMergeForeground (const components::FilterGraph &graph, const Vector2d &deviceScale)
 Return the sharp layer above the blurred input layers of a shadow merge.
std::optional< components::FilterStandardInput > donner::svg::TransformedShadowForeground (const components::FilterGraph &graph, const Transform2d &deviceFromFilter)
 Identify the sharp foreground of a transformed drop shadow or shadow merge.
std::optional< components::FilterStandardInput > donner::svg::ApplicableTransformedShadow (const components::FilterGraph &graph, const Transform2d &deviceFromFilter, bool deviceFallbackFits)
 Return the sharp foreground when the transformed split can use the ordinary device fallback.
TransformedShadowGraphs donner::svg::SplitTransformedShadow (const components::FilterGraph &graph, components::FilterStandardInput foreground)
 Split an eligible shadow into two graphs. BackgroundImage in the merge is the projected shadow texture supplied by the renderer, independent of the document's backdrop.
bool donner::svg::UsesTransformedBlurPath (const components::FilterGraph &graph, const std::optional< Box2d > &filterRegion, const Transform2d &deviceFromFilter, bool fullExecutionFits)
 Whether a filter runs on the transformed path's local raster, the one decision both renderers share.
Transform2d donner::svg::FilterRasterFromDevice (const Transform2d &deviceFromFilter, Vector2d paddedOrigin, Vector2d scale)
 Map device pixels onto the filter-aligned raster, including its input padding.
bool donner::svg::CanCaptureFilterSourceLocally (const components::FilterGraph &graph, const Transform2d &deviceFromFilter)
 Whether the already-admitted local raster can receive SourceGraphic directly. Only wholly blurred outputs use this path, because a sharp branch still needs device coverage.
double donner::svg::ComputeTransformedBlurPadding (const components::FilterGraph &graph)
 User-space padding of the local raster: 3 sigma + 1 for the largest blur deviation.
Vector2d donner::svg::FinishFilterReach (Vector2d reach)
 Finish a device reach: one more pixel covers rounding at the reach's edge.
FilterInputMargin donner::svg::ComputeFilterSamplingReach (const components::FilterGraph &graph, const Transform2d &deviceFromFilter)
 Conservatively measure how far beyond each output pixel a filter graph reads its raster. Every primitive counts, including those fed only by generators: feFlood, feImage and feTurbulence produce output only over the raster, so a later blur or tile still needs the raster to extend past the viewport. Reaches add up, since chained primitives compound.
FilterInputMargin donner::svg::ComputeFilterInputMargin (const components::FilterGraph &graph, const Transform2d &deviceFromFilter)
 The input margin a filter layer's capture gets: the graph's sampling reach, or none when the capture must stay viewport-aligned (see components::FilterGraph::keepsViewportAlignedCapture and feTurbulence).
int donner::svg::FilterInputExtension (double beyond, double needed)
 Pixels to extend a filter input raster past one viewport edge.
FilterInputAxis donner::svg::LayoutFilterInputAxis (std::pair< double, double > region, double reach, std::optional< std::pair< double, double > > capture, int viewport)
 Lay out one raster axis.
FilterInputBuffer donner::svg::ComputeFilterInputBuffer (const components::FilterGraph &graph, const std::optional< Box2d > &filterRegion, const Transform2d &deviceFromFilter, int viewportWidth, int viewportHeight)
 Lay out the input raster for a filter layer over a viewportWidth by viewportHeight surface. Primitives that read input away from the output position need the filtered content just past the viewport, so the raster extends by the graph's input margin wherever the filter region extends past the viewport, up to the whole region for a graph with unbounded reach. Each axis stays within the surface dimension limit; a layout over the pixel limit falls back to the viewport. Renderers also fall back to the viewport when the larger raster would not fit the frame's filter budgets.
bool donner::svg::FilterGraphReadsRasterEdges (const components::FilterGraph &graph)
 Whether a primitive of graph extends its input at the raster edge, duplicating or wrapping edge pixels, so the raster must end exactly where its content does.
bool donner::svg::IsFiniteBox (const Box2d &box)
 Whether every coordinate of box is finite.
double donner::svg::FirstPixelCenterAtOrBeyond (double edge)
 The first device pixel index whose center lies at or beyond the continuous edge.
std::optional< Box2d > donner::svg::IntersectFilterBoxes (const Box2d &a, const Box2d &b)
 The overlap of a and b, or std::nullopt when they share no area.
std::optional< Box2d > donner::svg::FilterInputRasterBox (const FilterInputMargin &margin, const Box2d &region, const Box2d &visible, const Transform2d &deviceFromFilter)
 Device pixels a filter layer's input must cover for the visible part of its device region: the visible part expanded by the graph's reach, or the whole region for a graph that can read anywhere, plus any tile source, clipped back to the region.
std::optional< FilterInputBuffer > donner::svg::PixelAlignedFilterRaster (const Box2d &box, bool exactEdges)
 The pixel-aligned raster over box, its size rounded up to the layout granularity unless exactEdges, or std::nullopt past the surface limits.
FilterInputBuffer donner::svg::ComputeRegionFilterInputBuffer (const components::FilterGraph &graph, const std::optional< Box2d > &filterRegion, const Transform2d &deviceFromFilter, int viewportWidth, int viewportHeight)
 Lay out the input raster for a filter layer over only the part of its filter region that can affect what a viewportWidth by viewportHeight surface shows.
bool donner::svg::FilterRegionShowsNothing (const Box2d &filterRegion, const Transform2d &deviceFromFilter, int viewportWidth, int viewportHeight)
 Whether a filter region shows nothing on a viewportWidth by viewportHeight surface: it lies wholly outside it, so the layer's result is invisible and need not be captured or run.
std::optional< Transform2d > donner::svg::FiniteFilterInverse (const Transform2d &deviceFromFilter)
 Invert only finite, nonsingular transforms whose inverse remains finite.

Variables

constexpr double donner::svg::kMinimumBlurringDeviationPixels = 1.0
 The minimum Gaussian deviation along each filter axis that can cover the local raster's resampling footprint in device pixels.
constexpr int donner::svg::kFilterInputBufferGranularity = 64
 Raster dimensions of a region-bounded layout round up to this many pixels, so a region that moves by a fraction of a pixel, or regions of nearby sizes, keep one texture size.

Class Documentation

◆ donner::svg::FilterInputMargin

struct donner::svg::FilterInputMargin

Input a filter layer's capture must include beyond each output pixel, in device pixels.

Class Members
Vector2d captureReach Input read beyond userCapture by the primitives feeding it.
Vector2d pixels Farthest input read from an output pixel, per axis.
optional< Box2d > userCapture User-space rectangle the capture must cover in full.
bool wholeRegion = false Some primitive can read any position in its input.

◆ donner::svg::TransformedShadowGraphs

struct donner::svg::TransformedShadowGraphs

The shadow executed on the filter-aligned raster and its merge with the untouched capture.

Class Members
FilterGraph merge
bool preservePaddedBlur = false Internal stages of an explicit feDropShadow.
FilterGraph shadow

◆ donner::svg::FilterInputAxis

struct donner::svg::FilterInputAxis

One axis of a FilterInputBuffer.

Class Members
int before = 0 Pixels before the viewport.
int extent = 0 Total pixels.

◆ donner::svg::FilterRegionSample

struct donner::svg::FilterRegionSample

Resolved clipping bounds and optional un-clipped animated geometry, in user coordinates.

Class Members
optional< Box2d > animatedRegion Un-clipped region for image placement when sampled.
Box2d bounds Clip region, intersected with the filter region.