Skip to content
Permalink
Browse files
Add debug output support for WebCore::Gradient
https://bugs.webkit.org/show_bug.cgi?id=241767

Reviewed by Sam Weinig.

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/graphics/ColorInterpolationMethod.cpp: Added.
(WebCore::operator<<):
* Source/WebCore/platform/graphics/ColorInterpolationMethod.h:
* Source/WebCore/platform/graphics/Gradient.cpp:
(WebCore::operator<<):
* Source/WebCore/platform/graphics/Gradient.h:
* Source/WebCore/platform/graphics/GradientColorStop.cpp: Copied from Source/WebCore/platform/graphics/GradientColorStop.h.
(WebCore::operator<<):
* Source/WebCore/platform/graphics/GradientColorStop.h:
* Source/WebCore/platform/graphics/GradientColorStops.cpp: Copied from Source/WebCore/platform/graphics/GradientColorStop.h.
(WebCore::operator<<):
* Source/WebCore/platform/graphics/GradientColorStops.h:
* Source/WebCore/platform/graphics/GraphicsTypes.cpp:
(WebCore::operator<<):
* Source/WebCore/platform/graphics/GraphicsTypes.h:

Canonical link: https://commits.webkit.org/251672@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
heycam committed Jun 20, 2022
1 parent 16972b8 commit 53ec9e3e166a94a6c853461073b4a3a1ff1d3018
Showing 13 changed files with 267 additions and 3 deletions.
@@ -2023,6 +2023,7 @@ platform/graphics/Color.cpp
platform/graphics/ColorBlending.cpp
platform/graphics/ColorConversion.cpp
platform/graphics/ColorInterpolation.cpp
platform/graphics/ColorInterpolationMethod.cpp
platform/graphics/ColorLuminance.cpp
platform/graphics/ColorSerialization.cpp
platform/graphics/ColorSpace.cpp
@@ -2060,6 +2061,8 @@ platform/graphics/FourCC.cpp
platform/graphics/GeneratedImage.cpp
platform/graphics/GeometryUtilities.cpp
platform/graphics/Gradient.cpp
platform/graphics/GradientColorStop.cpp
platform/graphics/GradientColorStops.cpp
platform/graphics/GradientImage.cpp
platform/graphics/GraphicsContext.cpp
platform/graphics/GraphicsContextGL.cpp
@@ -8509,6 +8509,9 @@
32A70D552836138D0080060C /* PositionedGlyphs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PositionedGlyphs.cpp; sourceTree = "<group>"; };
32A70D562836138D0080060C /* PositionedGlyphs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PositionedGlyphs.h; sourceTree = "<group>"; };
32B0B0CF283C7483006217C6 /* GlyphDisplayListCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GlyphDisplayListCache.cpp; sourceTree = "<group>"; };
32B17614285FDDA100ED6DB8 /* GradientColorStop.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GradientColorStop.cpp; sourceTree = "<group>"; };
32B17615285FDDA100ED6DB8 /* GradientColorStops.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GradientColorStops.cpp; sourceTree = "<group>"; };
32E268FC285FC8F7004660BB /* ColorInterpolationMethod.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorInterpolationMethod.cpp; sourceTree = "<group>"; };
331FF67DE197B57393C46A7F /* RenderMathMLPadded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMathMLPadded.h; sourceTree = "<group>"; };
331FF67DE197B57393C46AA7 /* RenderMathMLSpace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMathMLSpace.h; sourceTree = "<group>"; };
333F704E0FB49CA2008E12A6 /* Notification.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Notification.idl; sourceTree = "<group>"; };
@@ -29199,6 +29202,7 @@
3103B7DE1DB01556008BB890 /* ColorHash.h */,
BCDC642427517B040038FB39 /* ColorInterpolation.cpp */,
BCDC642527517B040038FB39 /* ColorInterpolation.h */,
32E268FC285FC8F7004660BB /* ColorInterpolationMethod.cpp */,
BC2EE8E82765942A0077768B /* ColorInterpolationMethod.h */,
BC6EB84526266B61003225A7 /* ColorLuminance.cpp */,
BC4A23EB25EC160200AAC630 /* ColorLuminance.h */,
@@ -29301,7 +29305,9 @@
0873B86A136064EA00A522C2 /* GlyphPage.h */,
BC53C6070DA56C570021EB5D /* Gradient.cpp */,
BC53C5F40DA56B920021EB5D /* Gradient.h */,
32B17614285FDDA100ED6DB8 /* GradientColorStop.cpp */,
BC19CDF3277106390053F734 /* GradientColorStop.h */,
32B17615285FDDA100ED6DB8 /* GradientColorStops.cpp */,
BC19CE292772BF770053F734 /* GradientColorStops.h */,
2D2FC0561460CD6F00263633 /* GradientImage.cpp */,
2D2FC0571460CD6F00263633 /* GradientImage.h */,
@@ -0,0 +1,105 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "ColorInterpolationMethod.h"

#include <wtf/text/TextStream.h>

namespace WebCore {

TextStream& operator<<(TextStream& ts, ColorInterpolationColorSpace interpolationColorSpace)
{
switch (interpolationColorSpace) {
case ColorInterpolationColorSpace::HSL:
ts << "HSL";
break;
case ColorInterpolationColorSpace::HWB:
ts << "HWB";
break;
case ColorInterpolationColorSpace::LCH:
ts << "LCH";
break;
case ColorInterpolationColorSpace::Lab:
ts << "Lab";
break;
case ColorInterpolationColorSpace::OKLCH:
ts << "OKLCH";
break;
case ColorInterpolationColorSpace::OKLab:
ts << "OKLab";
break;
case ColorInterpolationColorSpace::SRGB:
ts << "sRGB";
break;
case ColorInterpolationColorSpace::SRGBLinear:
ts << "sRGB linear";
break;
case ColorInterpolationColorSpace::XYZD50:
ts << "XYZ D50";
break;
case ColorInterpolationColorSpace::XYZD65:
ts << "XYZ D65";
break;
}
return ts;
}

TextStream& operator<<(TextStream& ts, HueInterpolationMethod hueInterpolationMethod)
{
switch (hueInterpolationMethod) {
case HueInterpolationMethod::Shorter:
ts << "shorter";
break;
case HueInterpolationMethod::Longer:
ts << "longer";
break;
case HueInterpolationMethod::Increasing:
ts << "increasing";
break;
case HueInterpolationMethod::Decreasing:
ts << "decreasing";
break;
case HueInterpolationMethod::Specified:
ts << "specified";
break;
}
return ts;
}

TextStream& operator<<(TextStream& ts, const ColorInterpolationMethod& method)
{
WTF::switchOn(method.colorSpace,
[&] (auto& type) {
ts << type.interpolationColorSpace;
if constexpr (hasHueInterpolationMethod<decltype(type)>)
ts << ' ' << type.hueInterpolationMethod;
ts << ' ' << method.alphaPremultiplication;
}
);
return ts;
}

} // namespace WebCore
@@ -32,6 +32,10 @@
#include <wtf/EnumTraits.h>
#include <wtf/Hasher.h>

namespace WTF {
class TextStream;
}

namespace WebCore {

enum class HueInterpolationMethod : uint8_t {
@@ -55,6 +59,15 @@ enum class ColorInterpolationColorSpace : uint8_t {
XYZD65
};

template <typename T, typename = void>
struct HasHueInterpolationMethod : std::false_type { };

template <typename T>
struct HasHueInterpolationMethod<T, std::void_t<decltype(T::hueInterpolationMethod)>> : std::true_type { };

template <typename T>
inline constexpr bool hasHueInterpolationMethod = HasHueInterpolationMethod<T>::value;

struct ColorInterpolationMethod {
struct HSL {
static constexpr auto interpolationColorSpace = ColorInterpolationColorSpace::HSL;
@@ -253,6 +266,10 @@ inline constexpr bool operator==(const ColorInterpolationMethod& a, const ColorI
return a.alphaPremultiplication == b.alphaPremultiplication && a.colorSpace == b.colorSpace;
}

WTF::TextStream& operator<<(WTF::TextStream&, ColorInterpolationColorSpace);
WTF::TextStream& operator<<(WTF::TextStream&, HueInterpolationMethod);
WTF::TextStream& operator<<(WTF::TextStream&, const ColorInterpolationMethod&);

}

namespace WTF {
@@ -30,6 +30,8 @@
#include "FloatRect.h"
#include <wtf/HashFunctions.h>
#include <wtf/Hasher.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/TextStream.h>

namespace WebCore {

@@ -120,4 +122,29 @@ unsigned Gradient::hash() const
return m_cachedHash;
}

TextStream& operator<<(TextStream& ts, const Gradient& gradient)
{
WTF::switchOn(gradient.m_data,
[&] (const Gradient::LinearData& data) {
ts.dumpProperty("p0", data.point0);
ts.dumpProperty("p1", data.point1);
},
[&] (const Gradient::RadialData& data) {
ts.dumpProperty("p0", data.point0);
ts.dumpProperty("p1", data.point1);
ts.dumpProperty("start-radius", data.startRadius);
ts.dumpProperty("end-radius", data.endRadius);
ts.dumpProperty("aspect-ratio", data.aspectRatio);
},
[&] (const Gradient::ConicData& data) {
ts.dumpProperty("p0", data.point0);
ts.dumpProperty("angle-radians", data.angleRadians);
}
);
ts.dumpProperty("color-interpolation-method", gradient.m_colorInterpolationMethod);
ts.dumpProperty("spread-method", gradient.m_spreadMethod);
ts.dumpProperty("stops", gradient.m_stops);
return ts;
}

}
@@ -47,13 +47,18 @@ typedef struct CGContext* CGContextRef;
typedef struct _cairo_pattern cairo_pattern_t;
#endif

namespace WTF {
class TextStream;
}

namespace WebCore {

class AffineTransform;
class FloatRect;
class GraphicsContext;

class Gradient : public RefCounted<Gradient> {
friend WTF::TextStream& operator<<(WTF::TextStream&, const Gradient&);
public:
struct LinearData {
FloatPoint point0;
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "GradientColorStop.h"

#include <wtf/text/TextStream.h>

namespace WebCore {

TextStream& operator<<(TextStream& ts, const GradientColorStop& stop)
{
ts << stop.color << " at " << stop.offset;
return ts;
}

} // namespace WebCore
@@ -27,6 +27,7 @@

#include "Color.h"
#include <optional>
#include <wtf/Forward.h>
#include <wtf/Hasher.h>

namespace WebCore {
@@ -65,4 +66,6 @@ inline void add(Hasher& hasher, const GradientColorStop& stop)
add(hasher, stop.offset, stop.color);
}

}
TextStream& operator<<(TextStream&, const GradientColorStop&);

} // namespace WebCore
@@ -0,0 +1,39 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "GradientColorStops.h"

#include <wtf/text/TextStream.h>

namespace WebCore {

TextStream& operator<<(TextStream& ts, const GradientColorStops& stops)
{
ts << stops.stops();
return ts;
}

} // namespace WebCore
@@ -28,6 +28,7 @@
#include "GradientColorStop.h"
#include <algorithm>
#include <optional>
#include <wtf/Forward.h>
#include <wtf/Vector.h>

namespace WebCore {
@@ -138,4 +139,6 @@ template<typename Decoder> std::optional<GradientColorStops> GradientColorStops:
return {{ WTFMove(*stops) }};
}

}
TextStream& operator<<(TextStream&, const GradientColorStops&);

} // namespace WebCore
@@ -152,6 +152,22 @@ TextStream& operator<<(TextStream& ts, const DropShadow& dropShadow)
return ts;
}

TextStream& operator<<(TextStream& ts, GradientSpreadMethod spreadMethod)
{
switch (spreadMethod) {
case GradientSpreadMethod::Pad:
ts << "pad";
break;
case GradientSpreadMethod::Reflect:
ts << "reflect";
break;
case GradientSpreadMethod::Repeat:
ts << "repeat";
break;
}
return ts;
}

TextStream& operator<<(TextStream& ts, InterpolationQuality interpolationQuality)
{
switch (interpolationQuality) {
@@ -293,6 +293,7 @@ WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, WebCore::BlendMode)
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, WebCore::CompositeOperator);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, CompositeMode);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const DropShadow&);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, GradientSpreadMethod);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, InterpolationQuality);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, LineCap);
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, LineJoin);
@@ -79,7 +79,7 @@ WTF::TextStream& operator<<(TextStream& ts, const SourceBrush& brush)
ts.dumpProperty("color", brush.color());

if (auto gradient = brush.gradient())
ts.dumpProperty("gradient", gradient);
ts.dumpProperty("gradient", *gradient);

if (auto pattern = brush.pattern())
ts.dumpProperty("pattern", pattern);

0 comments on commit 53ec9e3

Please sign in to comment.