Diff
Modified: trunk/Source/WebCore/ChangeLog (261790 => 261791)
--- trunk/Source/WebCore/ChangeLog 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/ChangeLog 2020-05-17 04:55:40 UTC (rev 261791)
@@ -1,3 +1,52 @@
+2020-05-16 Simon Fraser <[email protected]>
+
+ Some color-related cleanup
+ https://bugs.webkit.org/show_bug.cgi?id=211991
+
+ Reviewed by Sam Weinig.
+
+ Change FloatComponents and ColorComponents to use std::array<>.
+
+ Add Color::toSRGBAComponentsLossy() to make explicit potentially lossy conversions
+ between P3 and sRGB colors, and call it in places where we do that conversion.
+
+ Add const in a few places.
+
+ * Headers.cmake:
+ * WebCore.xcodeproj/project.pbxproj:
+ * platform/graphics/Color.cpp:
+ (WebCore::Color::Color):
+ (WebCore::Color::toSRGBAComponentsLossy const):
+ (WebCore::Color::asExtended const):
+ * platform/graphics/Color.h:
+ * platform/graphics/ColorUtilities.cpp:
+ (WebCore::ColorMatrix::ColorMatrix):
+ * platform/graphics/ColorUtilities.h:
+ (WebCore::FloatComponents::FloatComponents):
+ (): Deleted.
+ * platform/graphics/ExtendedColor.cpp:
+ (WebCore::ExtendedColor::create):
+ (WebCore::ExtendedColor::cssText const):
+ * platform/graphics/ExtendedColor.h:
+ (WebCore::ExtendedColor::red const):
+ (WebCore::ExtendedColor::green const):
+ (WebCore::ExtendedColor::blue const):
+ (WebCore::ExtendedColor::alpha const):
+ (WebCore::ExtendedColor::channels const):
+ (WebCore::ExtendedColor::ExtendedColor):
+ * platform/graphics/cg/ColorCG.cpp:
+ (WebCore::leakCGColor):
+ * platform/graphics/filters/FETurbulence.cpp:
+ (WebCore::FETurbulence::fillRegion const):
+ * platform/graphics/filters/FilterOperation.cpp:
+ (WebCore::InvertLightnessFilterOperation::transformColor const):
+ (WebCore::InvertLightnessFilterOperation::inverseTransformColor const):
+ * platform/graphics/gtk/ColorGtk.cpp:
+ (WebCore::Color::operator GdkRGBA const):
+ * platform/graphics/win/ColorDirect2D.cpp:
+ (WebCore::Color::operator D2D1_COLOR_F const):
+ (WebCore::Color::operator D2D1_VECTOR_4F const):
+
2020-05-16 Andy Estes <[email protected]>
Fix the build after r261785.
Modified: trunk/Source/WebCore/Headers.cmake (261790 => 261791)
--- trunk/Source/WebCore/Headers.cmake 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/Headers.cmake 2020-05-17 04:55:40 UTC (rev 261791)
@@ -1080,6 +1080,7 @@
platform/graphics/Color.h
platform/graphics/ColorHash.h
platform/graphics/ColorSpace.h
+ platform/graphics/ColorUtilities.h
platform/graphics/ComplexTextController.h
platform/graphics/ConcreteImageBuffer.h
platform/graphics/DashArray.h
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (261790 => 261791)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-05-17 04:55:40 UTC (rev 261791)
@@ -363,6 +363,7 @@
0FEA3E80191B3169000F1B55 /* ScrollingTreeOverflowScrollingNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEA3E7E191B3169000F1B55 /* ScrollingTreeOverflowScrollingNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
0FEA3E84191B31BF000F1B55 /* ScrollingStateOverflowScrollingNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEA3E82191B31BF000F1B55 /* ScrollingStateOverflowScrollingNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
0FEA3E88191B3BD7000F1B55 /* ScrollingTreeFrameScrollingNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEA3E86191B3BD7000F1B55 /* ScrollingTreeFrameScrollingNode.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 0FEAF66B23BFC39E004030DA /* ColorUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FE6C76C1FBFB7A60025C053 /* ColorUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
0FEC120C22BF2CD2004E9D35 /* LayerAncestorClippingStack.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC120922BF2CC7004E9D35 /* LayerAncestorClippingStack.h */; settings = {ATTRIBUTES = (Private, ); }; };
0FF3B9291EE3B6DE00B84144 /* JSDOMQuad.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FF3B9251EE3B6DE00B84144 /* JSDOMQuad.h */; };
0FF3B92B1EE3B6DE00B84144 /* JSDOMQuadInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FF3B9271EE3B6DE00B84144 /* JSDOMQuadInit.h */; };
@@ -29878,6 +29879,7 @@
CE5169E721F1B84700EA4F78 /* ColorIOS.h in Headers */,
EDE3A5000C7A430600956A37 /* ColorMac.h in Headers */,
9382DF5810A8D5C900925652 /* ColorSpace.h in Headers */,
+ 0FEAF66B23BFC39E004030DA /* ColorUtilities.h in Headers */,
BCDD454E1236C95C009A7985 /* ColumnInfo.h in Headers */,
43EDD67F1B485DBF00640E75 /* CombinedFiltersAlphabet.h in Headers */,
26E944D91AC4B2DD007B85B5 /* CombinedURLFilters.h in Headers */,
Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/Color.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -240,12 +240,12 @@
*this = WTFMove(other);
}
-Color::Color(float r, float g, float b, float a, ColorSpace colorSpace)
+Color::Color(float c1, float c2, float c3, float alpha, ColorSpace colorSpace)
{
// Zero the union, just in case a 32-bit system only assigns the
// top 32 bits when copying the extendedColor pointer below.
m_colorData.rgbaAndFlags = 0;
- auto extendedColorRef = ExtendedColor::create(r, g, b, a, colorSpace);
+ auto extendedColorRef = ExtendedColor::create(c1, c2, c3, alpha, colorSpace);
m_colorData.extendedColor = &extendedColorRef.leakRef();
ASSERT(isExtended());
}
@@ -555,6 +555,23 @@
value = max;
}
+FloatComponents Color::toSRGBAComponentsLossy() const
+{
+ if (isExtended()) {
+ auto& extendedColor = asExtended();
+ switch (extendedColor.colorSpace()) {
+ case ColorSpace::SRGB:
+ case ColorSpace::LinearRGB:
+ case ColorSpace::DisplayP3:
+ // FIXME: This doesn't convert into sRGB and should.
+ return extendedColor.channels();
+ }
+ }
+ float r, g, b, a;
+ getRGBA(r, g, b, a);
+ return { r, g, b, a };
+}
+
Color colorFromPremultipliedARGB(RGBA32 pixelColor)
{
if (pixelColor.isVisible() && !pixelColor.isOpaque())
@@ -607,7 +624,7 @@
m_colorData.rgbaAndFlags |= validRGBAColor;
}
-ExtendedColor& Color::asExtended() const
+const ExtendedColor& Color::asExtended() const
{
ASSERT(isExtended());
return *m_colorData.extendedColor;
Modified: trunk/Source/WebCore/platform/graphics/Color.h (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/Color.h 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/Color.h 2020-05-17 04:55:40 UTC (rev 261791)
@@ -54,6 +54,8 @@
namespace WebCore {
+struct FloatComponents;
+
// Color value with 8-bit components for red, green, blue, and alpha.
// For historical reasons, stored as a 32-bit integer, with alpha in the high bits: ARGB.
class SimpleColor {
@@ -169,7 +171,7 @@
// This creates an ExtendedColor.
// FIXME: If the colorSpace is sRGB and the values can all be
// converted exactly to integers, we should make a normal Color.
- WEBCORE_EXPORT Color(float r, float g, float b, float a, ColorSpace colorSpace);
+ WEBCORE_EXPORT Color(float, float, float, float, ColorSpace);
WEBCORE_EXPORT Color(const Color&);
WEBCORE_EXPORT Color(Color&&);
@@ -214,6 +216,9 @@
WEBCORE_EXPORT void getHSL(double& h, double& s, double& l) const;
WEBCORE_EXPORT void getHSV(double& h, double& s, double& v) const;
+ // This will convert non-sRGB colorspace colors into sRGB.
+ FloatComponents toSRGBAComponentsLossy() const;
+
Color light() const;
Color dark() const;
@@ -272,7 +277,7 @@
{
return !(m_colorData.rgbaAndFlags & invalidRGBAColor);
}
- WEBCORE_EXPORT ExtendedColor& asExtended() const;
+ WEBCORE_EXPORT const ExtendedColor& asExtended() const;
WEBCORE_EXPORT Color& operator=(const Color&);
WEBCORE_EXPORT Color& operator=(Color&&);
Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -220,7 +220,7 @@
makeIdentity();
}
-ColorMatrix::ColorMatrix(float values[20])
+ColorMatrix::ColorMatrix(const float values[20])
{
m_matrix[0][0] = values[0];
m_matrix[0][1] = values[1];
Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2020-05-17 04:55:40 UTC (rev 261791)
@@ -25,12 +25,14 @@
#pragma once
-#include "Color.h"
#include <algorithm>
+#include <array>
#include <math.h>
namespace WebCore {
+class Color;
+
struct FloatComponents {
FloatComponents(float a = 0, float b = 0, float c = 0, float d = 0)
{
@@ -40,6 +42,14 @@
components[3] = d;
}
+ FloatComponents(const std::array<float, 4>& values)
+ {
+ components[0] = values[0];
+ components[1] = values[1];
+ components[2] = values[2];
+ components[3] = values[3];
+ }
+
FloatComponents(const Color&);
FloatComponents& operator+=(const FloatComponents& rhs)
@@ -91,7 +101,7 @@
return result;
}
- float components[4];
+ std::array<float, 4> components;
};
struct ColorComponents {
@@ -115,7 +125,7 @@
return components[0] << 24 | components[1] << 16 | components[2] << 8 | components[3];
}
- uint8_t components[4] { };
+ std::array<uint8_t, 4> components;
};
inline ColorComponents perComponentMax(const ColorComponents& a, const ColorComponents& b)
@@ -172,7 +182,7 @@
static ColorMatrix sepiaMatrix(float);
ColorMatrix();
- ColorMatrix(float[20]);
+ ColorMatrix(const float[20]);
void transformColorComponents(FloatComponents&) const;
Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -31,9 +31,9 @@
namespace WebCore {
-Ref<ExtendedColor> ExtendedColor::create(float red, float green, float blue, float alpha, ColorSpace colorSpace)
+Ref<ExtendedColor> ExtendedColor::create(float c1, float c2, float c3, float alpha, ColorSpace colorSpace)
{
- return adoptRef(*new ExtendedColor(red, green, blue, alpha, colorSpace));
+ return adoptRef(*new ExtendedColor(c1, c2, c3, alpha, colorSpace));
}
String ExtendedColor::cssText() const
@@ -53,6 +53,7 @@
if (WTF::areEssentiallyEqual(alpha(), 1.0f))
return makeString("color(", colorSpace, ' ', red(), ' ', green(), ' ', blue(), ')');
+
return makeString("color(", colorSpace, ' ', red(), ' ', green(), ' ', blue(), " / ", alpha(), ')');
}
Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.h (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/ExtendedColor.h 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.h 2020-05-17 04:55:40 UTC (rev 261791)
@@ -27,6 +27,7 @@
#include "ColorSpace.h"
+#include "ColorUtilities.h"
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
@@ -35,31 +36,38 @@
class ExtendedColor : public RefCounted<ExtendedColor> {
public:
- static Ref<ExtendedColor> create(float red, float green, float blue, float alpha, ColorSpace = ColorSpace::SRGB);
+ static Ref<ExtendedColor> create(float, float, float, float alpha, ColorSpace = ColorSpace::SRGB);
- float red() const { return m_red; }
- float green() const { return m_green; }
- float blue() const { return m_blue; }
- float alpha() const { return m_alpha; }
+ float red() const
+ {
+ return m_channels.components[0];
+ }
+ float green() const
+ {
+ return m_channels.components[1];
+ }
+
+ float blue() const
+ {
+ return m_channels.components[2];
+ }
+
+ float alpha() const { return m_channels.components[3]; }
+
+ const FloatComponents& channels() const { return m_channels; }
+
ColorSpace colorSpace() const { return m_colorSpace; }
WEBCORE_EXPORT String cssText() const;
private:
- ExtendedColor(float r, float g, float b, float a, ColorSpace colorSpace)
- : m_red(r)
- , m_green(g)
- , m_blue(b)
- , m_alpha(a)
+ ExtendedColor(float c1, float c2, float c3, float alpha, ColorSpace colorSpace)
+ : m_channels(c1, c2, c3, alpha)
, m_colorSpace(colorSpace)
{ }
- float m_red { 0 };
- float m_green { 0 };
- float m_blue { 0 };
- float m_alpha { 0 };
-
+ FloatComponents m_channels;
ColorSpace m_colorSpace { ColorSpace::SRGB };
};
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -105,11 +105,12 @@
{
CGFloat components[4];
if (color.isExtended()) {
- ExtendedColor& extendedColor = color.asExtended();
- components[0] = extendedColor.red();
- components[1] = extendedColor.green();
- components[2] = extendedColor.blue();
- components[3] = extendedColor.alpha();
+ const auto& extendedColor = color.asExtended();
+ auto channels = extendedColor.channels();
+ components[0] = channels.components[0];
+ components[1] = channels.components[1];
+ components[2] = channels.components[2];
+ components[3] = channels.components[3];
switch (extendedColor.colorSpace()) {
case ColorSpace::SRGB:
return CGColorCreate(sRGBColorSpaceRef(), components);
Modified: trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/filters/FETurbulence.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -382,7 +382,7 @@
point.setX(point.x() + 1);
FloatPoint localPoint = inverseTransfrom.mapPoint(point);
ColorComponents values = calculateTurbulenceValueForPoint(paintingData, stitchData, localPoint);
- pixelArray.setRange(values.components, 4, indexOfPixelChannel);
+ pixelArray.setRange(values.components.data(), 4, indexOfPixelChannel);
indexOfPixelChannel += 4;
}
}
Modified: trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/filters/FilterOperation.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -236,7 +236,7 @@
sRGBColorComponents = HSLToSRGB(hslComponents);
// Apply the matrix. See rdar://problem/41146650 for how this matrix was derived.
- float matrixValues[20] = {
+ const float matrixValues[20] = {
-0.770, 0.059, -0.089, 0, 1,
0.030, -0.741, -0.089, 0, 1,
0.030, 0.059, -0.890, 0, 1,
@@ -252,7 +252,7 @@
{
FloatComponents rgbComponents = sRGBColorComponents;
// Apply the matrix.
- float matrixValues[20] = {
+ const float matrixValues[20] = {
-1.300, -0.097, 0.147, 0, 1.25,
-0.049, -1.347, 0.146, 0, 1.25,
-0.049, -0.097, -1.104, 0, 1.25,
Modified: trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -21,6 +21,7 @@
#include "config.h"
#include "Color.h"
+#include "ColorUtilities.h"
#include <gdk/gdk.h>
namespace WebCore {
@@ -35,8 +36,10 @@
Color::operator GdkRGBA() const
{
- if (isExtended())
- return { asExtended().red(), asExtended().green(), asExtended().blue(), asExtended().alpha() };
+ if (isExtended()) {
+ auto asRGBA = toSRGBAComponentsLossy();
+ return { asRGBA.components[0], asRGBA.components[1], asRGBA.components[2], asRGBA.components[3] };
+ }
#if USE(GTK4)
float red, green, blue, alpha;
Modified: trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp (261790 => 261791)
--- trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2020-05-17 02:57:00 UTC (rev 261790)
+++ trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp 2020-05-17 04:55:40 UTC (rev 261791)
@@ -28,6 +28,7 @@
#if PLATFORM(WIN)
+#include "ColorUtilities.h"
#include <d2d1.h>
#include <d2d1_1helper.h>
@@ -40,16 +41,19 @@
Color::operator D2D1_COLOR_F() const
{
+ if (isExtended()) {
+ auto asRGBA = toSRGBAComponentsLossy();
+ return D2D1::ColorF(asRGBA.components[0], asRGBA.components[1], asRGBA.components[2], asRGBA.components[3]);
+ }
+
float colorAlpha = alpha() / 255.0f;
-
return D2D1::ColorF(rgb().value(), colorAlpha);
}
Color::operator D2D1_VECTOR_4F() const
{
- float r, g, b, a;
- getRGBA(r, g, b, a);
- return D2D1::Vector4F(r, g, b, a);
+ auto asRGBA = toSRGBAComponentsLossy();
+ return D2D1::Vector4F(asRGBA.components[0], asRGBA.components[1], asRGBA.components[2], asRGBA.components[3]);
}
}