Skip to content
Permalink
Browse files
[GPU Process] [Filters] Remove SVGFilterBuilder
https://bugs.webkit.org/show_bug.cgi?id=241577
<rdar://problem/95074247>

Reviewed by Simon Fraser.

After r295498, all the methods of SVGFilterBuilder became static. So this patch
removes it and moves its methods to SVGFilter.

-- colorInterpolationForElement() will be moved to SVGElement::colorInterpolation().
-- effectGeometryFlagsForElement() will be moved to
   SVGFilterPrimitiveStandardAttributes::effectGeometryFlags().
-- FilterData::boundaries is removed. It is set in RenderSVGResourceFilter::
   applyResource() and used only in RenderSVGResourceFilter::postApplyResource()
   where we check '!isEmpty()'. This check can be replaced by checking if filter
   is not nullptr.
-- FilterData::scale is removed since it is not used.
-- FilterData::sourceGraphicBuffer and FilterData::drawingRegion are renamed
   sourceImage and sourceImageRect respectively to match the named of the inputs
   of GraphicsContext::drawFilteredImageBuffer().

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/rendering/CSSFilter.cpp:
(WebCore::calculateReferenceFilterOutsets):
* Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp:
(WebCore::RenderSVGResourceFilter::applyResource):
(WebCore::RenderSVGResourceFilter::postApplyResource):
(WebCore::RenderSVGResourceFilter::drawingRegion const):
* Source/WebCore/rendering/svg/RenderSVGResourceFilter.h:
* Source/WebCore/rendering/svg/SVGRenderTreeAsText.cpp:
(WebCore::writeSVGResourceContainer):
* Source/WebCore/svg/SVGElement.cpp:
(WebCore::SVGElement::colorInterpolation const):
* Source/WebCore/svg/SVGElement.h:
* Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.cpp:
(WebCore::SVGFilterPrimitiveStandardAttributes::effectGeometryFlags const):
* Source/WebCore/svg/SVGFilterPrimitiveStandardAttributes.h:
* Source/WebCore/svg/graphics/filters/SVGFilter.cpp:
(WebCore::SVGFilter::create):
(WebCore::buildFilterEffectsGraph):
(WebCore::SVGFilter::buildExpression):
(WebCore::buildFilterPrimitivesGraph):
(WebCore::SVGFilter::calculateOutsets):
* Source/WebCore/svg/graphics/filters/SVGFilter.h:
* Source/WebCore/svg/graphics/filters/SVGFilterBuilder.cpp: Removed.
* Source/WebCore/svg/graphics/filters/SVGFilterBuilder.h: Removed.

Canonical link: https://commits.webkit.org/251522@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295517 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
shallawa committed Jun 14, 2022
1 parent 98129b5 commit 0e76c1008504c5e95db98bc672a9db4625dfd0ce
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 238 deletions.
@@ -2760,7 +2760,6 @@ svg/graphics/SVGImage.cpp
svg/graphics/SVGImageCache.cpp
svg/graphics/SVGImageForContainer.cpp
svg/graphics/filters/SVGFilter.cpp
svg/graphics/filters/SVGFilterBuilder.cpp
svg/properties/SVGAnimatedProperty.cpp
svg/properties/SVGAnimationAdditiveValueFunctionImpl.cpp
svg/properties/SVGAttributeAnimator.cpp
@@ -239,7 +239,6 @@
081668D4125603BF006F25DE /* SVGTextChunkBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 081668D2125603BF006F25DE /* SVGTextChunkBuilder.h */; };
081668DA125603D5006F25DE /* SVGTextLayoutEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 081668D8125603D5006F25DE /* SVGTextLayoutEngine.h */; };
081AA8DA1111237E002AB06E /* SVGElementRareData.h in Headers */ = {isa = PBXBuildFile; fileRef = 081AA8D91111237E002AB06E /* SVGElementRareData.h */; };
081EBF3B0FD34F4100DA7559 /* SVGFilterBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 081EBF390FD34F4100DA7559 /* SVGFilterBuilder.h */; };
083DAEA70F01A7FB00342754 /* RenderTextControlMultiLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 083DAEA30F01A7FB00342754 /* RenderTextControlMultiLine.h */; };
083DAEA90F01A7FB00342754 /* RenderTextControlSingleLine.h in Headers */ = {isa = PBXBuildFile; fileRef = 083DAEA50F01A7FB00342754 /* RenderTextControlSingleLine.h */; };
0844B01D1255B4E600B9CDD0 /* SVGBoundingBoxComputation.h in Headers */ = {isa = PBXBuildFile; fileRef = 0844B01D1255E4E600B9CDD0 /* SVGBoundingBoxComputation.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -6252,8 +6251,6 @@
081668D7125603D5006F25DE /* SVGTextLayoutEngine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGTextLayoutEngine.cpp; sourceTree = "<group>"; };
081668D8125603D5006F25DE /* SVGTextLayoutEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGTextLayoutEngine.h; sourceTree = "<group>"; };
081AA8D91111237E002AB06E /* SVGElementRareData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGElementRareData.h; sourceTree = "<group>"; };
081EBF380FD34F4100DA7559 /* SVGFilterBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGFilterBuilder.cpp; sourceTree = "<group>"; };
081EBF390FD34F4100DA7559 /* SVGFilterBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGFilterBuilder.h; sourceTree = "<group>"; };
0834B00C1244E4E600B9CDD0 /* SVGBoundingBoxComputation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGBoundingBoxComputation.cpp; sourceTree = "<group>"; };
0834B00C1244E5A610B8AFD1 /* SVGContainerLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGContainerLayout.cpp; sourceTree = "<group>"; };
083DAEA20F01A7FB00342754 /* RenderTextControlMultiLine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderTextControlMultiLine.cpp; sourceTree = "<group>"; };
@@ -29069,8 +29066,6 @@
children = (
845E72F90FD2623900A87D79 /* SVGFilter.cpp */,
845E72FA0FD2623900A87D79 /* SVGFilter.h */,
081EBF380FD34F4100DA7559 /* SVGFilterBuilder.cpp */,
081EBF390FD34F4100DA7559 /* SVGFilterBuilder.h */,
726CDE25275B489700A445B2 /* SVGFilterExpression.h */,
72F7A08027F171BF0008EEE8 /* SVGFilterGraph.h */,
);
@@ -37940,7 +37935,6 @@
B2227A060D00BF220071B782 /* SVGFETileElement.h in Headers */,
B2227A090D00BF220071B782 /* SVGFETurbulenceElement.h in Headers */,
845E72FC0FD2623900A87D79 /* SVGFilter.h in Headers */,
081EBF3B0FD34F4100DA7559 /* SVGFilterBuilder.h in Headers */,
B2227A0C0D00BF220071B782 /* SVGFilterElement.h in Headers */,
72A5D192275E8FFE0065833E /* SVGFilterExpression.h in Headers */,
B2227A0F0D00BF220071B782 /* SVGFilterPrimitiveStandardAttributes.h in Headers */,
@@ -36,7 +36,6 @@
#include "ReferencedSVGResources.h"
#include "RenderElement.h"
#include "SVGFilter.h"
#include "SVGFilterBuilder.h"
#include "SVGFilterElement.h"
#include "SourceGraphic.h"

@@ -253,7 +252,7 @@ static IntOutsets calculateReferenceFilterOutsets(const ReferenceFilterOperation
if (!filterElement)
return { };

return SVGFilterBuilder::calculateFilterOutsets(*filterElement, targetBoundingBox);
return SVGFilter::calculateOutsets(*filterElement, targetBoundingBox);
}

static RefPtr<SVGFilter> createReferenceFilter(CSSFilter& filter, const ReferenceFilterOperation& filterOperation, RenderElement& renderer, const FloatRect& targetBoundingBox, const GraphicsContext& destinationContext)
@@ -90,10 +90,9 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
auto addResult = m_rendererFilterDataMap.set(&renderer, makeUnique<FilterData>());
auto filterData = addResult.iterator->value.get();

FloatRect targetBoundingBox = renderer.objectBoundingBox();

filterData->boundaries = SVGLengthContext::resolveRectangle<SVGFilterElement>(&filterElement(), filterElement().filterUnits(), targetBoundingBox);
if (filterData->boundaries.isEmpty()) {
auto targetBoundingBox = renderer.objectBoundingBox();
auto filterRegion = SVGLengthContext::resolveRectangle<SVGFilterElement>(&filterElement(), filterElement().filterUnits(), targetBoundingBox);
if (filterRegion.isEmpty()) {
m_rendererFilterDataMap.remove(&renderer);
return false;
}
@@ -109,17 +108,17 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
FloatSize filterScale(absoluteTransform.xScale(), absoluteTransform.yScale());

// Determine absolute boundaries of the filter and the drawing region.
filterData->drawingRegion = renderer.strokeBoundingBox();
filterData->drawingRegion.intersect(filterData->boundaries);
filterData->sourceImageRect = renderer.strokeBoundingBox();
filterData->sourceImageRect.intersect(filterRegion);

// Determine scale factor for filter. The size of intermediate ImageBuffers shouldn't be bigger than kMaxFilterSize.
ImageBuffer::sizeNeedsClamping(filterData->drawingRegion.size(), filterScale);
ImageBuffer::sizeNeedsClamping(filterData->sourceImageRect.size(), filterScale);

// Set the rendering mode from the page's settings.
auto renderingMode = renderer.page().acceleratedFiltersEnabled() ? RenderingMode::Accelerated : RenderingMode::Unaccelerated;

// Create the SVGFilter object.
filterData->filter = SVGFilter::create(filterElement(), renderingMode, filterScale, Filter::ClipOperation::Intersect, filterData->boundaries, targetBoundingBox, *context);
filterData->filter = SVGFilter::create(filterElement(), renderingMode, filterScale, Filter::ClipOperation::Intersect, filterRegion, targetBoundingBox, *context);
if (!filterData->filter) {
m_rendererFilterDataMap.remove(&renderer);
return false;
@@ -128,9 +127,9 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
if (filterData->filter->clampFilterRegionIfNeeded())
filterScale = filterData->filter->filterScale();

// If the drawingRegion is empty, we have something like <g filter=".."/>.
// If the sourceImageRect is empty, we have something like <g filter=".."/>.
// Even if the target objectBoundingBox() is empty, we still have to draw the last effect result image in postApplyResource.
if (filterData->drawingRegion.isEmpty()) {
if (filterData->sourceImageRect.isEmpty()) {
ASSERT(m_rendererFilterDataMap.contains(&renderer));
filterData->savedContext = context;
return false;
@@ -142,19 +141,15 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
auto colorSpace = DestinationColorSpace::SRGB();
#endif

auto sourceGraphic = context->createScaledImageBuffer(filterData->drawingRegion, filterScale, colorSpace, filterData->filter->renderingMode());
if (!sourceGraphic) {
filterData->sourceImage = context->createScaledImageBuffer(filterData->sourceImageRect, filterScale, colorSpace, filterData->filter->renderingMode());
if (!filterData->sourceImage) {
ASSERT(m_rendererFilterDataMap.contains(&renderer));
filterData->savedContext = context;
return false;
}

auto& sourceGraphicContext = sourceGraphic->context();

filterData->sourceGraphicBuffer = WTFMove(sourceGraphic);
filterData->savedContext = context;

context = &sourceGraphicContext;
context = &filterData->sourceImage->context();

ASSERT(m_rendererFilterDataMap.contains(&renderer));
return true;
@@ -201,9 +196,9 @@ void RenderSVGResourceFilter::postApplyResource(RenderElement& renderer, Graphic
break;
}

if (!filterData.boundaries.isEmpty()) {
if (filterData.filter) {
filterData.state = FilterData::Built;
context->drawFilteredImageBuffer(filterData.sourceGraphicBuffer.get(), filterData.drawingRegion, *filterData.filter, filterData.results);
context->drawFilteredImageBuffer(filterData.sourceImage.get(), filterData.sourceImageRect, *filterData.filter, filterData.results);
}

LOG_WITH_STREAM(Filters, stream << "RenderSVGResourceFilter " << this << " postApplyResource done\n");
@@ -240,7 +235,7 @@ void RenderSVGResourceFilter::markFilterForRebuild()
FloatRect RenderSVGResourceFilter::drawingRegion(RenderObject* object) const
{
FilterData* filterData = m_rendererFilterDataMap.get(object);
return filterData ? filterData->drawingRegion : FloatRect();
return filterData ? filterData->sourceImageRect : FloatRect();
}

TextStream& operator<<(TextStream& ts, FilterData::FilterDataState state)
@@ -27,13 +27,13 @@
#include "ImageBuffer.h"
#include "RenderSVGResourceContainer.h"
#include "SVGFilter.h"
#include "SVGFilterBuilder.h"
#include "SVGUnitTypes.h"
#include <wtf/IsoMalloc.h>
#include <wtf/RefPtr.h>

namespace WebCore {

class GraphicsContext;
class SVGFilterElement;

struct FilterData {
@@ -45,17 +45,15 @@ struct FilterData {
FilterData() = default;

RefPtr<SVGFilter> filter;
RefPtr<ImageBuffer> sourceGraphicBuffer;
FilterResults results;

RefPtr<ImageBuffer> sourceImage;
FloatRect sourceImageRect;

GraphicsContext* savedContext { nullptr };
FloatRect boundaries;
FloatRect drawingRegion;
FloatSize scale;
FilterDataState state { PaintingSource };
FilterResults results;
};

class GraphicsContext;

class RenderSVGResourceFilter final : public RenderSVGResourceContainer {
WTF_MAKE_ISO_ALLOCATED(RenderSVGResourceFilter);
public:
@@ -26,6 +26,8 @@
#include "config.h"
#include "SVGElement.h"

#include "CSSComputedStyleDeclaration.h"
#include "CSSPrimitiveValueMappings.h"
#include "CSSPropertyParser.h"
#include "Document.h"
#include "ElementChildIterator.h"
@@ -712,6 +714,20 @@ const RenderStyle* SVGElement::computedStyle(PseudoId pseudoElementSpecifier)
return m_svgRareData->overrideComputedStyle(*this, parentStyle);
}

ColorInterpolation SVGElement::colorInterpolation() const
{
if (auto renderer = this->renderer())
return renderer->style().svgStyle().colorInterpolationFilters();

// Try to determine the property value from the computed style.
if (auto value = ComputedStyleExtractor(const_cast<SVGElement*>(this)).propertyValue(CSSPropertyColorInterpolationFilters, DoNotUpdateLayout)) {
if (is<CSSPrimitiveValue>(value))
return downcast<CSSPrimitiveValue>(*value);
}

return ColorInterpolation::Auto;
}

QualifiedName SVGElement::animatableAttributeForName(const AtomString& localName)
{
static NeverDestroyed animatableAttributes = [] {
@@ -27,6 +27,7 @@
#include "SVGNames.h"
#include "SVGParsingError.h"
#include "SVGPropertyOwnerRegistry.h"
#include "SVGRenderStyleDefs.h"
#include "StyledElement.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
@@ -149,6 +150,8 @@ class SVGElement : public StyledElement, public SVGPropertyOwner {
void animatorWillBeDeleted(const QualifiedName&);

const RenderStyle* computedStyle(PseudoId = PseudoId::None) final;

ColorInterpolation colorInterpolation() const;

// These are needed for the RenderTree, animation and DOM.
AtomString className() const { return AtomString { m_className->currentValue() }; }
@@ -66,6 +66,22 @@ void SVGFilterPrimitiveStandardAttributes::parseAttribute(const QualifiedName& n
SVGElement::parseAttribute(name, value);
}

OptionSet<FilterEffectGeometry::Flags> SVGFilterPrimitiveStandardAttributes::effectGeometryFlags() const
{
OptionSet<FilterEffectGeometry::Flags> flags;

if (hasAttribute(SVGNames::xAttr))
flags.add(FilterEffectGeometry::Flags::HasX);
if (hasAttribute(SVGNames::yAttr))
flags.add(FilterEffectGeometry::Flags::HasY);
if (hasAttribute(SVGNames::widthAttr))
flags.add(FilterEffectGeometry::Flags::HasWidth);
if (hasAttribute(SVGNames::heightAttr))
flags.add(FilterEffectGeometry::Flags::HasHeight);

return flags;
}

RefPtr<FilterEffect> SVGFilterPrimitiveStandardAttributes::filterEffect(const FilterEffectVector& inputs, const GraphicsContext& destinationContext)
{
if (!m_effect)
@@ -21,6 +21,7 @@

#pragma once

#include "FilterEffectGeometry.h"
#include "RenderSVGResourceFilter.h"
#include "RenderSVGResourceFilterPrimitive.h"
#include "SVGElement.h"
@@ -50,13 +51,15 @@ class SVGFilterPrimitiveStandardAttributes : public SVGElement {
SVGAnimatedLength& heightAnimated() { return m_height; }
SVGAnimatedString& resultAnimated() { return m_result; }

void primitiveAttributeChanged(const QualifiedName&);
void markFilterEffectForRebuild();
OptionSet<FilterEffectGeometry::Flags> effectGeometryFlags() const;

virtual Vector<AtomString> filterEffectInputsNames() const { return { }; }
virtual IntOutsets outsets(const FloatRect&, SVGUnitTypes::SVGUnitType) const { return { }; }
RefPtr<FilterEffect> filterEffect(const FilterEffectVector&, const GraphicsContext& destinationContext);

void primitiveAttributeChanged(const QualifiedName&);
void markFilterEffectForRebuild();

static void invalidateFilterPrimitiveParent(SVGElement*);

protected:

0 comments on commit 0e76c10

Please sign in to comment.