Skip to content

Commit 6dc3ccc

Browse files
authored
Merge pull request #1287 from WebPlatformForEmbedded/pgorszkowski/2.38/enable_support_for_linearRGB_color_space
Regression(251234@main): [Cairo][GTK][WPE] Darker output of SVG with …
2 parents 7c28049 + 528e002 commit 6dc3ccc

10 files changed

Lines changed: 26 additions & 14 deletions

File tree

LayoutTests/fast/gradients/conic-gradient-extended-stops.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
<body>
3838
<svg viewBox="0 0 700 100">
39+
<meta name="fuzzy" content="maxDifference=0-16; totalPixels=0-30000" />
3940
<defs>
4041
<filter id="posterize" filterUnits="objectBoundingBox" primitiveUnits="objectBoundingBox">
4142
<feComponentTransfer color-interpolation-filters="sRGB">

LayoutTests/platform/glib/TestExpectations

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,15 +2651,11 @@ fast/text/line-break-with-locale.html [ ImageOnlyFailure ]
26512651
webkit.org/b/225423 fast/canvas/canvas-composite-text-alpha.html [ Failure ]
26522652

26532653
# Non-sRGB color spaces are not currently supported by the glib ports.
2654-
css3/color-filters/svg/color-filter-inline-svg.html [ ImageOnlyFailure ]
2655-
css3/filters/reference-filter-color-space.html [ ImageOnlyFailure ]
26562654
fast/canvas/canvas-color-space-display-p3.html [ Skip ]
26572655
fast/canvas/canvas-color-space-display-p3-ImageData.html [ Skip ]
26582656
imported/w3c/web-platform-tests/html/canvas/element/wide-gamut-canvas/ [ Skip ]
26592657
imported/w3c/web-platform-tests/html/canvas/element/manual/wide-gamut-canvas/ [ Skip ]
26602658
imported/w3c/web-platform-tests/html/canvas/offscreen/wide-gamut-canvas/ [ Skip ]
2661-
svg/filters/feCompositeOpaque.html [ ImageOnlyFailure ]
2662-
svg/filters/feDiffuseLighting-bottomRightPixel.html [ ImageOnlyFailure ]
26632659

26642660
storage/indexeddb/structured-clone-image-data-display-p3.html [ Skip ]
26652661

LayoutTests/svg/filters/feConvolveMatrix-clipped.svg

Lines changed: 1 addition & 0 deletions
Loading

LayoutTests/svg/filters/feGaussianBlur-clipped.svg

Lines changed: 1 addition & 0 deletions
Loading

Source/WTF/wtf/PlatformEnable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@
245245
#endif
246246

247247
#if !defined(ENABLE_DESTINATION_COLOR_SPACE_LINEAR_SRGB)
248-
#define ENABLE_DESTINATION_COLOR_SPACE_LINEAR_SRGB 0
248+
#define ENABLE_DESTINATION_COLOR_SPACE_LINEAR_SRGB 1
249249
#endif
250250

251251
#if !defined(ENABLE_DOWNLOAD_ATTRIBUTE)

Source/WebCore/platform/graphics/filters/FEDropShadow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class FEDropShadow : public FilterEffect {
5151

5252
template<class Encoder> void encode(Encoder&) const;
5353
template<class Decoder> static std::optional<Ref<FEDropShadow>> decode(Decoder&);
54+
#if USE(CAIRO)
55+
void setOperatingColorSpace(const DestinationColorSpace&) override { }
56+
#endif
57+
5458

5559
private:
5660
FEDropShadow(float stdX, float stdY, float dx, float dy, const Color& shadowColor, float shadowOpacity);

Source/WebCore/platform/graphics/filters/SourceGraphic.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131

3232
namespace WebCore {
3333

34-
Ref<SourceGraphic> SourceGraphic::create()
34+
Ref<SourceGraphic> SourceGraphic::create(const DestinationColorSpace& colorSpace)
3535
{
36-
return adoptRef(*new SourceGraphic());
36+
return adoptRef(*new SourceGraphic(colorSpace));
3737
}
3838

39-
SourceGraphic::SourceGraphic()
39+
SourceGraphic::SourceGraphic(const DestinationColorSpace& colorSpace)
4040
: FilterEffect(FilterEffect::Type::SourceGraphic)
4141
{
42+
setOperatingColorSpace(colorSpace);
4243
}
4344

4445
bool SourceGraphic::supportsAcceleratedRendering() const

Source/WebCore/platform/graphics/filters/SourceGraphic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ namespace WebCore {
2727

2828
class SourceGraphic : public FilterEffect {
2929
public:
30-
WEBCORE_EXPORT static Ref<SourceGraphic> create();
30+
WEBCORE_EXPORT static Ref<SourceGraphic> create(const DestinationColorSpace& = DestinationColorSpace::SRGB());
3131

3232
static AtomString effectName() { return FilterEffect::sourceGraphicName(); }
3333

3434
private:
35-
SourceGraphic();
35+
SourceGraphic(const DestinationColorSpace&);
3636

3737
unsigned numberOfEffectInputs() const override { return 0; }
3838

Source/WebCore/rendering/svg/RenderSVGResourceFilter.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ bool RenderSVGResourceFilter::applyResource(RenderElement& renderer, const Rende
140140
return false;
141141
}
142142

143-
#if ENABLE(DESTINATION_COLOR_SPACE_LINEAR_SRGB)
144-
auto colorSpace = DestinationColorSpace::LinearSRGB();
145-
#else
143+
#if USE(CAIRO)
146144
auto colorSpace = DestinationColorSpace::SRGB();
145+
#else
146+
auto colorSpace = DestinationColorSpace::LinearSRGB();
147147
#endif
148148

149149
filterData->sourceImage = context->createScaledImageBuffer(filterData->sourceImageRect, filterScale, colorSpace, filterData->filter->renderingMode());
@@ -203,6 +203,13 @@ void RenderSVGResourceFilter::postApplyResource(RenderElement& renderer, Graphic
203203

204204
if (filterData.filter) {
205205
filterData.state = FilterData::Built;
206+
#if USE(CAIRO)
207+
// Cairo operates in SRGB which is why the SourceImage initially is in SRGB color space,
208+
// but before applying all filters it has to be transformed to LinearRGB to comply with
209+
// specification (https://www.w3.org/TR/filter-effects-1/#attr-valuedef-in-sourcegraphic).
210+
if (filterData.sourceImage.get())
211+
filterData.sourceImage.get()->transformToColorSpace(DestinationColorSpace::LinearSRGB());
212+
#endif
206213
context->drawFilteredImageBuffer(filterData.sourceImage.get(), filterData.sourceImageRect, *filterData.filter, filterData.results);
207214
}
208215

Source/WebCore/svg/graphics/filters/SVGFilter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ static std::optional<std::tuple<SVGFilterEffectsGraph, FilterEffectGeometryMap>>
7878
if (filterElement.countChildNodes() > maxCountChildNodes)
7979
return std::nullopt;
8080

81-
SVGFilterEffectsGraph graph(SourceGraphic::create(), SourceAlpha::create());
81+
const auto colorSpace = filterElement.colorInterpolation() == ColorInterpolation::LinearRGB ? DestinationColorSpace::LinearSRGB() : DestinationColorSpace::SRGB();
82+
SVGFilterEffectsGraph graph(SourceGraphic::create(colorSpace), SourceAlpha::create(colorSpace));
8283
FilterEffectGeometryMap effectGeometryMap;
8384

8485
for (auto& effectElement : childrenOfType<SVGFilterPrimitiveStandardAttributes>(filterElement)) {

0 commit comments

Comments
 (0)