Diff
Modified: trunk/LayoutTests/ChangeLog (271991 => 271992)
--- trunk/LayoutTests/ChangeLog 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/LayoutTests/ChangeLog 2021-01-28 01:22:09 UTC (rev 271992)
@@ -1,3 +1,17 @@
+2021-01-27 Sam Weinig <wei...@apple.com>
+
+ Add support for color(a98-rgb ...) as part of CSS Color 4
+ https://bugs.webkit.org/show_bug.cgi?id=221018
+
+ Reviewed by Darin Adler.
+
+ * TestExpectations:
+ Un-fail some now passing tests.
+
+ * fast/css/parsing-a98rgb-colors-expected.txt: Added.
+ * fast/css/parsing-a98rgb-colors.html: Added.
+ Add new tests for parsing color(a98-rgb ) colors.
+
2021-01-27 Ada Chan <ada.c...@apple.com>
Send the end XRSessionEvent after the platform-specific steps for session shutdown have completed
Modified: trunk/LayoutTests/TestExpectations (271991 => 271992)
--- trunk/LayoutTests/TestExpectations 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/LayoutTests/TestExpectations 2021-01-28 01:22:09 UTC (rev 271992)
@@ -4598,8 +4598,6 @@
# Unsupported css color() variants
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-003.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-004.html [ ImageOnlyFailure ] # Invalid test, no colorspace specified
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-007.html [ ImageOnlyFailure ] # Requires a98-rgb support
-webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-008.html [ ImageOnlyFailure ] # Requires a98-rgb support
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-009.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-010.html [ ImageOnlyFailure ] # Requires prophoto-rgb support
webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-011.html [ ImageOnlyFailure ] # Requires rec2020 support
Added: trunk/LayoutTests/fast/css/parsing-a98rgb-colors-expected.txt (0 => 271992)
--- trunk/LayoutTests/fast/css/parsing-a98rgb-colors-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/css/parsing-a98rgb-colors-expected.txt 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,37 @@
+Test the parsing of lab, lch and gray colors.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS computedStyle("background-color", "color(a98-rgb 0% 0% 0%)") is "color(a98-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb 10% 10% 10%)") is "color(a98-rgb 0.1 0.1 0.1)"
+PASS computedStyle("background-color", "color(a98-rgb .2 .2 25%)") is "color(a98-rgb 0.2 0.2 0.25)"
+PASS computedStyle("background-color", "color(a98-rgb 0 0 0 / 1)") is "color(a98-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0% 0 0 / 0.5)") is "color(a98-rgb 0 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(a98-rgb 20% 0 10/0.5)") is "color(a98-rgb 0.2 0 1 / 0.5)"
+PASS computedStyle("background-color", "color(a98-rgb 20% 0 10/50%)") is "color(a98-rgb 0.2 0 1 / 0.5)"
+PASS computedStyle("background-color", "color(a98-rgb 400% 0 10/50%)") is "color(a98-rgb 1 0 1 / 0.5)"
+PASS computedStyle("background-color", "color(a98-rgb 50% -160 160)") is "color(a98-rgb 0.5 0 1)"
+PASS computedStyle("background-color", "color(a98-rgb 50% -200 200)") is "color(a98-rgb 0.5 0 1)"
+PASS computedStyle("background-color", "color(a98-rgb 0 0 0 / -10%)") is "color(a98-rgb 0 0 0 / 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0 0 0 / 110%)") is "color(a98-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0 0 0 / 300%)") is "color(a98-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb 50% -200)") is "color(a98-rgb 0.5 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb 50%)") is "color(a98-rgb 0.5 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb)") is "color(a98-rgb 0 0 0)"
+PASS computedStyle("background-color", "color(a98-rgb 50% -200 / 0.5)") is "color(a98-rgb 0.5 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(a98-rgb 50% / 0.5)") is "color(a98-rgb 0.5 0 0 / 0.5)"
+PASS computedStyle("background-color", "color(a98-rgb / 0.5)") is "color(a98-rgb 0 0 0 / 0.5)"
+
+Test invalid values
+PASS computedStyle("background-color", "color(a98-rgb 0 0 0 0)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0deg 0% 0)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0% 0 0 1)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0% 0 0 10%)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0% 0 0deg)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(a98-rgb 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
+PASS computedStyle("background-color", "color(a98-rgb 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/css/parsing-a98rgb-colors.html (0 => 271992)
--- trunk/LayoutTests/fast/css/parsing-a98rgb-colors.html (rev 0)
+++ trunk/LayoutTests/fast/css/parsing-a98rgb-colors.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,71 @@
+<html>
+ <script src=""
+</head>
+<body>
+<script>
+ description("Test the parsing of lab, lch and gray colors.");
+
+ function computedStyle(property, value)
+ {
+ var div = document.createElement("div");
+ document.body.appendChild(div);
+ div.style.setProperty(property, value);
+ var computedValue = getComputedStyle(div).getPropertyValue(property);
+ document.body.removeChild(div);
+ return computedValue;
+ }
+
+ function innerStyle(property, value)
+ {
+ var div = document.createElement("div");
+ div.style.setProperty(property, value);
+ return div.style.getPropertyValue(property);
+ }
+
+ function testComputed(property, value, expected)
+ {
+ shouldBeEqualToString('computedStyle("' + property + '", "' + value + '")', expected);
+ }
+
+ function testInner(property, value, expected)
+ {
+ if (expected === null)
+ expected = "";
+ shouldBeEqualToString('innerStyle("' + property + '", "' + value + '")', expected);
+ }
+
+ testComputed("background-color", "color(a98-rgb 0% 0% 0%)", "color(a98-rgb 0 0 0)");
+ testComputed("background-color", "color(a98-rgb 10% 10% 10%)", "color(a98-rgb 0.1 0.1 0.1)");
+ testComputed("background-color", "color(a98-rgb .2 .2 25%)", "color(a98-rgb 0.2 0.2 0.25)");
+ testComputed("background-color", "color(a98-rgb 0 0 0 / 1)", "color(a98-rgb 0 0 0)");
+ testComputed("background-color", "color(a98-rgb 0% 0 0 / 0.5)", "color(a98-rgb 0 0 0 / 0.5)");
+ testComputed("background-color", "color(a98-rgb 20% 0 10/0.5)", "color(a98-rgb 0.2 0 1 / 0.5)");
+ testComputed("background-color", "color(a98-rgb 20% 0 10/50%)", "color(a98-rgb 0.2 0 1 / 0.5)");
+ testComputed("background-color", "color(a98-rgb 400% 0 10/50%)", "color(a98-rgb 1 0 1 / 0.5)");
+ testComputed("background-color", "color(a98-rgb 50% -160 160)", "color(a98-rgb 0.5 0 1)");
+ testComputed("background-color", "color(a98-rgb 50% -200 200)", "color(a98-rgb 0.5 0 1)");
+ testComputed("background-color", "color(a98-rgb 0 0 0 / -10%)", "color(a98-rgb 0 0 0 / 0)");
+ testComputed("background-color", "color(a98-rgb 0 0 0 / 110%)", "color(a98-rgb 0 0 0)");
+ testComputed("background-color", "color(a98-rgb 0 0 0 / 300%)", "color(a98-rgb 0 0 0)");
+ testComputed("background-color", "color(a98-rgb 50% -200)", "color(a98-rgb 0.5 0 0)");
+ testComputed("background-color", "color(a98-rgb 50%)", "color(a98-rgb 0.5 0 0)");
+ testComputed("background-color", "color(a98-rgb)", "color(a98-rgb 0 0 0)");
+ testComputed("background-color", "color(a98-rgb 50% -200 / 0.5)", "color(a98-rgb 0.5 0 0 / 0.5)");
+ testComputed("background-color", "color(a98-rgb 50% / 0.5)", "color(a98-rgb 0.5 0 0 / 0.5)");
+ testComputed("background-color", "color(a98-rgb / 0.5)", "color(a98-rgb 0 0 0 / 0.5)");
+
+ debug('');
+ debug('Test invalid values');
+ testComputed("background-color", "color(a98-rgb 0 0 0 0)", "rgba(0, 0, 0, 0)");
+ testComputed("background-color", "color(a98-rgb 0deg 0% 0)", "rgba(0, 0, 0, 0)");
+ testComputed("background-color", "color(a98-rgb 0% 0 0 1)", "rgba(0, 0, 0, 0)");
+ testComputed("background-color", "color(a98-rgb 0% 0 0 10%)", "rgba(0, 0, 0, 0)");
+ testComputed("background-color", "color(a98-rgb 0% 0 0deg)", "rgba(0, 0, 0, 0)");
+ testComputed("background-color", "color(a98-rgb 0% 0% 0deg)", "rgba(0, 0, 0, 0)");
+ testComputed("background-color", "color(a98-rgb 40% 0 0deg)", "rgba(0, 0, 0, 0)");
+
+</script>
+
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (271991 => 271992)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2021-01-28 01:22:09 UTC (rev 271992)
@@ -1,3 +1,21 @@
+2021-01-27 Sam Weinig <wei...@apple.com>
+
+ Add support for color(a98-rgb ...) as part of CSS Color 4
+ https://bugs.webkit.org/show_bug.cgi?id=221018
+
+ Reviewed by Darin Adler.
+
+ Add some new WPT tests for color(a98-rgb ) that will be upstreamed shortly.
+
+ * web-platform-tests/css/css-color/a98rgb-001-expected.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-001.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-002-expected.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-002.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-003-expected.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-003.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-004-expected.html: Added.
+ * web-platform-tests/css/css-color/a98rgb-004.html: Added.
+
2021-01-27 Manuel Rego Casasnovas <r...@igalia.com>
Upstream to WPT Shadow DOM tests related to :focus pseudo-class
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-001-expected.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-001-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-001-expected.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Green square reference</title>
+<style>
+ .test { background-color: #008000; width: 12em; height: 12em;}
+</style>
+<body>
+ <p>Test passes if you see a green square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-001.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-001.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-001.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: a98-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="a98-rgb with no alpha">
+<style>
+ .test { background-color: red; width: 12em; height: 12em; }
+ .test { background-color: color(a98-rgb 0.281363 0.498012 0.116746); } /* green (sRGB #008000) converted to a98-rgb */
+</style>
+<body>
+ <p>Test passes if you see a green square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-002-expected.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-002-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-002-expected.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Black square reference</title>
+<style>
+ .test { background-color: #000000; width: 12em; height: 12em; }
+</style>
+<body>
+ <p>Test passes if you see a black square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-002.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-002.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-002.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: a98-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="a98-rgb with no alpha">
+<style>
+ .test { background-color: red; width: 12em; height: 12em; }
+ .test { background-color: color(a98-rgb 0 0 0); } /* black (sRGB #000000) converted to a98-rgb */
+</style>
+<body>
+ <p>Test passes if you see a black square, and no red.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-003-expected.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-003-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-003-expected.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: CSS Color 4: a98-rgb</title>
+<style>
+ body { background-color: grey; }
+ .test { background-color: rgb(99.993% 100% 100%); width: 12em; height: 12em; } /* color(a98-rgb 1 1 1) converted to sRGB */
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-003.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-003.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-003.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: a98-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="a98-rgb with no alpha">
+<style>
+ body { background-color: grey; }
+ .test { background-color: red; width: 12em; height: 6em; margin-top: 0; }
+ .ref { background-color: rgb(99.993% 100% 100%); width: 12em; height: 6em; margin-bottom: 0; } /* color(a98-rgb 1 1 1) converted to sRGB */
+ .test { background-color: color(a98-rgb 1 1 1); }
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="ref"></div>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-004-expected.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-004-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-004-expected.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: CSS Color 4: a98-rgb</title>
+<style>
+ .test { background-color: lab(83.2141% -129.1072 87.1718); width: 12em; height: 12em; } /* color(a98-rgb 0 1 0) converted to Lab */
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="test"></div>
+</body>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-004.html (0 => 271992)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-004.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-color/a98rgb-004.html 2021-01-28 01:22:09 UTC (rev 271992)
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Color 4: a98-rgb</title>
+<link rel="author" title="Sam Weinig" href=""
+<link rel="help" href=""
+<link rel="match" href=""
+<meta name="assert" content="a98-rgb with no alpha">
+<style>
+ .test { background-color: red; width: 12em; height: 6em; margin-top: 0; }
+ .ref { background-color: lab(83.2141% -129.1072 87.1718); width: 12em; height: 6em; margin-bottom: 0; } /* color(a98-rgb 0 1 0) converted to Lab */
+ .test { background-color: color(a98-rgb 0 1 0); }
+</style>
+<body>
+ <p>Test passes if you see a single square, and not two rectangles of different colors.</p>
+ <div class="ref"></div>
+ <div class="test"></div>
+</body>
Modified: trunk/Source/WebCore/ChangeLog (271991 => 271992)
--- trunk/Source/WebCore/ChangeLog 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/ChangeLog 2021-01-28 01:22:09 UTC (rev 271992)
@@ -1,3 +1,115 @@
+2021-01-27 Sam Weinig <wei...@apple.com>
+
+ Add support for color(a98-rgb ...) as part of CSS Color 4
+ https://bugs.webkit.org/show_bug.cgi?id=221018
+
+ Reviewed by Darin Adler.
+
+ * css/CSSValueKeywords.in:
+ Add keyword for a98-rgb and a comment indicating that lab, which already exists as a value,
+ is also a valid identifier for the color function.
+
+ * css/parser/CSSPropertyParserHelpers.cpp:
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
+ (WebCore::CSSPropertyParserHelpers::parseColorFunctionForSRGBOrDisplayP3Parameters): Deleted.
+ Generalize parseColorFunctionForSRGBOrDisplayP3Parameters to work for all RGB types, which now include
+ A98RGB.
+
+ * platform/graphics/ColorConversion.cpp:
+ (WebCore::SRGBTransferFunction::fromLinearClamping):
+ (WebCore::SRGBTransferFunction::toLinearClamping):
+ (WebCore::SRGBTransferFunction::fromLinearNonClamping):
+ (WebCore::SRGBTransferFunction::toLinearNonClamping):
+ (WebCore::A98RGBTransferFunction::fromLinearClamping):
+ (WebCore::A98RGBTransferFunction::toLinearClamping):
+ (WebCore::A98RGBTransferFunction::fromLinearNonClamping):
+ (WebCore::A98RGBTransferFunction::toLinearNonClamping):
+ (WebCore::toLinearClamping):
+ (WebCore::fromLinearClamping):
+ (WebCore::toLinearNonClamping):
+ (WebCore::fromLinearNonClamping):
+ (WebCore::toLinearSRGBA):
+ (WebCore::toLinearExtendedSRGBA):
+ (WebCore::toSRGBA):
+ (WebCore::toExtendedSRGBA):
+ (WebCore::toLinearDisplayP3):
+ (WebCore::toDisplayP3):
+ (WebCore::toLinearA98RGB):
+ (WebCore::toA98RGB):
+ (WebCore::toXYZA):
+ (WebCore::linearToRGBColorComponentClamping): Deleted.
+ (WebCore::rgbToLinearColorComponentClamping): Deleted.
+ (WebCore::linearToRGBColorComponentNonClamping): Deleted.
+ (WebCore::rgbToLinearColorComponentNonClamping): Deleted.
+ * platform/graphics/ColorConversion.h:
+ (WebCore::toA98RGB):
+ (WebCore::toLinearA98RGB):
+ (WebCore::callWithColorType):
+ Add conversion support for A98RGB and LinearA98RGB. Move gamma conversion functions
+ into structs named for the type of transfer function. While not used currently, this
+ will allow future templatizing of conversion to avoid so much boiler plate in the
+ future.
+
+ * platform/graphics/ColorSerialization.cpp:
+ (WebCore::serialization):
+ (WebCore::serializationForCSS):
+ (WebCore::serializationForHTML):
+ (WebCore::serializationForRenderTreeAsText):
+ * platform/graphics/ColorSerialization.h:
+ Add serialization support for color(a98-rgb ...).
+
+ * platform/graphics/ColorSpace.cpp:
+ * platform/graphics/ColorSpace.h:
+ Add A98RGB as a ColorSpace, which really just means it is something
+ ExtendedColor can hold.
+
+ * platform/graphics/cg/ColorSpaceCG.cpp:
+ * platform/graphics/cg/ColorSpaceCG.h:
+ Add support for creating a CGColorSpace for A98RGB.
+
+ * platform/graphics/ColorTypes.h:
+ (WebCore::operator==):
+ (WebCore::operator!=):
+ (WebCore::RGBAType::RGBAType):
+ (WebCore::asColorComponents):
+ (WebCore::SRGBA::SRGBA): Deleted.
+ (WebCore::ExtendedSRGBA::ExtendedSRGBA): Deleted.
+ (WebCore::LinearSRGBA::LinearSRGBA): Deleted.
+ (WebCore::LinearExtendedSRGBA::LinearExtendedSRGBA): Deleted.
+ (WebCore::DisplayP3::DisplayP3): Deleted.
+ (WebCore::LinearDisplayP3::LinearDisplayP3): Deleted.
+ (WebCore::callWithColorType): Deleted.
+ Simplify adding new RGB color types by adding a shared base class, RGBAType
+ and and a shared asColorComponents funciton. Also simplify all color types
+ by removing the need to define your own operator==/!= for each type by having
+ a single one that operates on any type that can have asColorComponents() called
+ on it.
+
+ To create a new RGB color (one with red, green and blue named components) one
+ now only needs to do:
+
+ template<typename T> struct Foo : RGBAType<Foo, T, RGBModel<T>> {
+ using RGBAType<Foo, T, RGBModel<T>>::RGBAType;
+ };
+ template<typename T> Foo(T, T, T, T) -> Foo<T>;
+
+ Additionally, if the type has gamma encoded and linear versions, it should have
+ either a `using GammaEncoded = ...` or `using Linear = ...` decalaring its
+ counterpart and should add a colorSpace member if the type is used by ExtendedColor.
+
+ Note, the deduction guide is necessary to keep things like the following working:
+
+ auto color = SRGB { float1, float2, ... };
+
+ Unfortunately, deduction does not come along when you explitily inherit constructors
+ like is being done for these. See the "Deducing from inherited constructors" section
+ in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1021r4.html.
+
+ * platform/graphics/cairo/ImageBufferCairoBackend.cpp:
+ (WebCore::ImageBufferCairoBackend::transformColorSpace):
+ Update to use new name for gamma conversion functions.
+
2021-01-27 Ada Chan <ada.c...@apple.com>
Send the end XRSessionEvent after the platform-specific steps for session shutdown have completed
Modified: trunk/Source/WebCore/css/CSSValueKeywords.in (271991 => 271992)
--- trunk/Source/WebCore/css/CSSValueKeywords.in 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/css/CSSValueKeywords.in 2021-01-28 01:22:09 UTC (rev 271992)
@@ -1407,6 +1407,8 @@
// color() function
sRGB
display-p3
+a98-rgb
+// lab
// prefers-default-appearance
prefers
Modified: trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (271991 => 271992)
--- trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp 2021-01-28 01:22:09 UTC (rev 271992)
@@ -875,9 +875,9 @@
}
template<typename ColorType>
-static Color parseColorFunctionForSRGBOrDisplayP3Parameters(CSSParserTokenRange& args)
+static Color parseColorFunctionForRGBTypes(CSSParserTokenRange& args)
{
- ASSERT(args.peek().id() == CSSValueSRGB || args.peek().id() == CSSValueDisplayP3);
+ ASSERT(args.peek().id() == CSSValueSRGB || args.peek().id() == CSSValueDisplayP3 || args.peek().id() == CSSValueA98Rgb);
consumeIdentRaw(args);
double channels[3] = { 0, 0, 0 };
@@ -936,11 +936,14 @@
Color color;
switch (args.peek().id()) {
case CSSValueSRGB:
- color = parseColorFunctionForSRGBOrDisplayP3Parameters<SRGBA<float>>(args);
+ color = parseColorFunctionForRGBTypes<SRGBA<float>>(args);
break;
case CSSValueDisplayP3:
- color = parseColorFunctionForSRGBOrDisplayP3Parameters<DisplayP3<float>>(args);
+ color = parseColorFunctionForRGBTypes<DisplayP3<float>>(args);
break;
+ case CSSValueA98Rgb:
+ color = parseColorFunctionForRGBTypes<A98RGB<float>>(args);
+ break;
case CSSValueLab:
color = parseColorFunctionForLabParameters(args);
break;
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.cpp (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2021-01-28 01:22:09 UTC (rev 271992)
@@ -62,6 +62,20 @@
0.0f, 0.0451133818589026f, 1.043944368900976f
};
+// https://drafts.csswg.org/css-color/#color-conversion-code
+static constexpr ColorMatrix<3, 3> xyzToLinearA98RGBMatrix {
+ 2.493496911941425f, -0.9313836179191239f, -0.4027107844507168f,
+ -0.8294889695615747f, 1.7626640603183463f, 0.0236246858419436f,
+ 0.0358458302437845f, -0.0761723892680418f, 0.9568845240076872f
+};
+
+// https://drafts.csswg.org/css-color/#color-conversion-code
+static constexpr ColorMatrix<3, 3> linearA98RGBToXYZMatrix {
+ 0.5766690429101305f, 0.1855582379065463f, 0.1882286462349947f,
+ 0.29734497525053605f, 0.6273635662554661f, 0.07529145849399788f,
+ 0.02703136138641234f, 0.07068885253582723f, 0.9913375368376388f
+};
+
// http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
static constexpr ColorMatrix<3, 3> D50ToD65Matrix {
0.9555766f, -0.0230393f, 0.0631636f,
@@ -78,7 +92,7 @@
// Gamma conversions.
-float linearToRGBColorComponentClamping(float c)
+float SRGBTransferFunction::fromLinearClamping(float c)
{
if (c < 0.0031308f)
return std::max<float>(12.92f * c, 0);
@@ -86,7 +100,7 @@
return clampTo<float>(1.055f * std::pow(c, 1.0f / 2.4f) - 0.055f, 0, 1);
}
-float rgbToLinearColorComponentClamping(float c)
+float SRGBTransferFunction::toLinearClamping(float c)
{
if (c <= 0.04045f)
return std::max<float>(c / 12.92f, 0);
@@ -94,9 +108,9 @@
return clampTo<float>(std::pow((c + 0.055f) / 1.055f, 2.4f), 0, 1);
}
-float linearToRGBColorComponentNonClamping(float c)
+float SRGBTransferFunction::fromLinearNonClamping(float c)
{
- float sign = c > 0 ? 1.0f : -1.0f;
+ float sign = std::signbit(c) ? -1.0f : 1.0f;
c = std::abs(c);
if (c < 0.0031308f)
@@ -105,9 +119,9 @@
return (1.055f * std::pow(c, 1.0f / 2.4f) - 0.055f) * sign;
}
-float rgbToLinearColorComponentNonClamping(float c)
+float SRGBTransferFunction::toLinearNonClamping(float c)
{
- float sign = c > 0 ? 1.0f : -1.0f;
+ float sign = std::signbit(c) ? -1.0f : 1.0f;
c = std::abs(c);
if (c <= 0.04045f)
@@ -116,68 +130,96 @@
return std::pow((c + 0.055f) / 1.055f, 2.4f) * sign;
}
+float A98RGBTransferFunction::fromLinearClamping(float c)
+{
+ return clampTo<float>(fromLinearNonClamping(c), 0, 1);
+}
+
+float A98RGBTransferFunction::toLinearClamping(float c)
+{
+ return clampTo<float>(toLinearNonClamping(c), 0, 1);
+}
+
+float A98RGBTransferFunction::fromLinearNonClamping(float c)
+{
+ float sign = std::signbit(c) ? -1.0f : 1.0f;
+ return std::pow(std::abs(c), 256.0f / 563.0f) * sign;
+}
+
+float A98RGBTransferFunction::toLinearNonClamping(float c)
+{
+ float sign = std::signbit(c) ? -1.0f : 1.0f;
+ return std::pow(std::abs(c), 563.0f / 256.0f) * sign;
+}
+
+template<typename TransferFunction, typename T> static auto toLinearClamping(const T& color) -> typename T::LinearCounterpart
+{
+ auto [c1, c2, c3, alpha] = color;
+ return { TransferFunction::toLinearClamping(c1), TransferFunction::toLinearClamping(c2), TransferFunction::toLinearClamping(c3), alpha };
+}
+
+template<typename TransferFunction, typename T> static auto fromLinearClamping(const T& color) -> typename T::GammaEncodedCounterpart
+{
+ auto [c1, c2, c3, alpha] = color;
+ return { TransferFunction::fromLinearClamping(c1), TransferFunction::fromLinearClamping(c2), TransferFunction::fromLinearClamping(c3), alpha };
+}
+
+template<typename TransferFunction, typename T> static auto toLinearNonClamping(const T& color) -> typename T::LinearCounterpart
+{
+ auto [c1, c2, c3, alpha] = color;
+ return { TransferFunction::toLinearNonClamping(c1), TransferFunction::toLinearNonClamping(c2), TransferFunction::toLinearNonClamping(c3), alpha };
+}
+
+template<typename TransferFunction, typename T> static auto fromLinearNonClamping(const T& color) -> typename T::GammaEncodedCounterpart
+{
+ auto [c1, c2, c3, alpha] = color;
+ return { TransferFunction::fromLinearNonClamping(c1), TransferFunction::fromLinearNonClamping(c2), TransferFunction::fromLinearNonClamping(c3), alpha };
+}
+
LinearSRGBA<float> toLinearSRGBA(const SRGBA<float>& color)
{
- return {
- rgbToLinearColorComponentClamping(color.red),
- rgbToLinearColorComponentClamping(color.green),
- rgbToLinearColorComponentClamping(color.blue),
- color.alpha
- };
+ return toLinearClamping<SRGBTransferFunction>(color);
}
LinearExtendedSRGBA<float> toLinearExtendedSRGBA(const ExtendedSRGBA<float>& color)
{
- return {
- rgbToLinearColorComponentNonClamping(color.red),
- rgbToLinearColorComponentNonClamping(color.green),
- rgbToLinearColorComponentNonClamping(color.blue),
- color.alpha
- };
+ return toLinearNonClamping<SRGBTransferFunction>(color);
}
SRGBA<float> toSRGBA(const LinearSRGBA<float>& color)
{
- return {
- linearToRGBColorComponentClamping(color.red),
- linearToRGBColorComponentClamping(color.green),
- linearToRGBColorComponentClamping(color.blue),
- color.alpha
- };
+ return fromLinearClamping<SRGBTransferFunction>(color);
}
ExtendedSRGBA<float> toExtendedSRGBA(const LinearExtendedSRGBA<float>& color)
{
- return {
- linearToRGBColorComponentNonClamping(color.red),
- linearToRGBColorComponentNonClamping(color.green),
- linearToRGBColorComponentNonClamping(color.blue),
- color.alpha
- };
+ return fromLinearNonClamping<SRGBTransferFunction>(color);
}
LinearDisplayP3<float> toLinearDisplayP3(const DisplayP3<float>& color)
{
- return {
- rgbToLinearColorComponentClamping(color.red),
- rgbToLinearColorComponentClamping(color.green),
- rgbToLinearColorComponentClamping(color.blue),
- color.alpha
- };
+ return toLinearClamping<SRGBTransferFunction>(color);
}
DisplayP3<float> toDisplayP3(const LinearDisplayP3<float>& color)
{
- return {
- linearToRGBColorComponentClamping(color.red),
- linearToRGBColorComponentClamping(color.green),
- linearToRGBColorComponentClamping(color.blue),
- color.alpha
- };
+ return fromLinearClamping<SRGBTransferFunction>(color);
}
-// Matrix conversions.
+LinearA98RGB<float> toLinearA98RGB(const A98RGB<float>& color)
+{
+ return toLinearClamping<A98RGBTransferFunction>(color);
+}
+A98RGB<float> toA98RGB(const LinearA98RGB<float>& color)
+{
+ return fromLinearClamping<A98RGBTransferFunction>(color);
+}
+
+// Matrix conversions (to and from XYZ for all linear color types).
+
+// - LinearSRGBA matrix conversions.
+
LinearSRGBA<float> toLinearSRGBA(const XYZA<float>& color)
{
return makeFromComponentsClampingExceptAlpha<LinearSRGBA<float>>(xyzToLinearSRGBMatrix.transformedColorComponents(asColorComponents(color)));
@@ -188,6 +230,8 @@
return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearSRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
+// - LinearExtendedSRGBA matrix conversions.
+
LinearExtendedSRGBA<float> toLinearExtendedSRGBA(const XYZA<float>& color)
{
return makeFromComponentsClampingExceptAlpha<LinearExtendedSRGBA<float>>(xyzToLinearSRGBMatrix.transformedColorComponents(asColorComponents(color)));
@@ -198,6 +242,8 @@
return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearSRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
+// - LinearDisplayP3 matrix conversions.
+
LinearDisplayP3<float> toLinearDisplayP3(const XYZA<float>& color)
{
return makeFromComponentsClampingExceptAlpha<LinearDisplayP3<float>>(xyzToLinearDisplayP3Matrix.transformedColorComponents(asColorComponents(color)));
@@ -208,6 +254,18 @@
return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearDisplayP3ToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
+// - LinearA98RGB matrix conversions.
+
+LinearA98RGB<float> toLinearA98RGB(const XYZA<float>& color)
+{
+ return makeFromComponentsClampingExceptAlpha<LinearA98RGB<float>>(xyzToLinearA98RGBMatrix.transformedColorComponents(asColorComponents(color)));
+}
+
+XYZA<float> toXYZA(const LinearA98RGB<float>& color)
+{
+ return makeFromComponentsClampingExceptAlpha<XYZA<float>>(linearA98RGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
+}
+
// Chromatic Adaptation conversions.
static XYZA<float> convertFromD50WhitePointToD65WhitePoint(const XYZA<float>& color)
@@ -406,6 +464,8 @@
// Combination conversions (constructed from more basic conversions above).
+// - SRGB combination functions.
+
XYZA<float> toXYZA(const SRGBA<float>& color)
{
return toXYZA(toLinearSRGBA(color));
@@ -416,6 +476,8 @@
return toSRGBA(toLinearSRGBA(color));
}
+// - ExtendedSRGB combination functions.
+
XYZA<float> toXYZA(const ExtendedSRGBA<float>& color)
{
return toXYZA(toLinearExtendedSRGBA(color));
@@ -426,6 +488,8 @@
return toExtendedSRGBA(toLinearExtendedSRGBA(color));
}
+// - DisplayP3 combination functions.
+
XYZA<float> toXYZA(const DisplayP3<float>& color)
{
return toXYZA(toLinearDisplayP3(color));
@@ -436,6 +500,20 @@
return toDisplayP3(toLinearDisplayP3(color));
}
+// - A98RGB combination functions.
+
+XYZA<float> toXYZA(const A98RGB<float>& color)
+{
+ return toXYZA(toLinearA98RGB(color));
+}
+
+A98RGB<float> toA98RGB(const XYZA<float>& color)
+{
+ return toA98RGB(toLinearA98RGB(color));
+}
+
+// - LCHA combination functions.
+
XYZA<float> toXYZA(const LCHA<float>& color)
{
return toXYZA(toLab(color));
@@ -446,6 +524,8 @@
return toLCHA(toLab(color));
}
+// - HSLA combination functions.
+
XYZA<float> toXYZA(const HSLA<float>& color)
{
return toXYZA(toSRGBA(color));
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.h (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.h 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.h 2021-01-28 01:22:09 UTC (rev 271992)
@@ -29,12 +29,22 @@
namespace WebCore {
-// These are the standard sRGB <-> LinearRGB / DisplayP3 <-> LinearDisplayP3 conversion functions (https://en.wikipedia.org/wiki/SRGB).
-float linearToRGBColorComponentClamping(float);
-float rgbToLinearColorComponentClamping(float);
-float linearToRGBColorComponentNonClamping(float);
-float rgbToLinearColorComponentNonClamping(float);
+// Transfer functions for colors that can be gamma encoded.
+struct SRGBTransferFunction {
+ static float fromLinearClamping(float);
+ static float toLinearClamping(float);
+ static float fromLinearNonClamping(float);
+ static float toLinearNonClamping(float);
+};
+
+struct A98RGBTransferFunction {
+ static float fromLinearClamping(float);
+ static float toLinearClamping(float);
+ static float fromLinearNonClamping(float);
+ static float toLinearNonClamping(float);
+};
+
// All color types must at least implement the following conversions to and from the XYZA color space:
// XYZA<float> toXYZA(const ColorType<float>&);
// ColorType<float> toColorType(const XYZA<float>&);
@@ -98,7 +108,19 @@
// Additions
WEBCORE_EXPORT SRGBA<float> toSRGBA(const HSLA<float>&);
+// A98RGB
+WEBCORE_EXPORT XYZA<float> toXYZA(const A98RGB<float>&);
+WEBCORE_EXPORT A98RGB<float> toA98RGB(const XYZA<float>&);
+// Additions
+WEBCORE_EXPORT LinearA98RGB<float> toLinearA98RGB(const A98RGB<float>&);
+// LinearA98RGB
+WEBCORE_EXPORT XYZA<float> toXYZA(const LinearA98RGB<float>&);
+WEBCORE_EXPORT LinearA98RGB<float> toLinearA98RGB(const XYZA<float>&);
+// Additions
+WEBCORE_EXPORT A98RGB<float> toA98RGB(const LinearA98RGB<float>& color);
+
+
// Identity conversions (useful for generic contexts).
constexpr SRGBA<float> toSRGBA(const SRGBA<float>& color) { return color; }
@@ -111,6 +133,7 @@
constexpr LCHA<float> toLCHA(const LCHA<float>& color) { return color; }
constexpr HSLA<float> toHSLA(const HSLA<float>& color) { return color; }
constexpr XYZA<float> toXYZA(const XYZA<float>& color) { return color; }
+constexpr A98RGB<float> toA98RGB(const A98RGB<float>& color) { return color; }
// Fallback conversions.
@@ -163,4 +186,34 @@
return toHSLA(toXYZA(color));
}
+template<typename T> A98RGB<float> toA98RGB(const T& color)
+{
+ return toA98RGB(toXYZA(color));
+}
+
+template<typename T> LinearA98RGB<float> toLinearA98RGB(const T& color)
+{
+ return toLinearA98RGB(toXYZA(color));
+}
+
+
+template<typename T, typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<T>& components, ColorSpace colorSpace, Functor&& functor)
+{
+ switch (colorSpace) {
+ case ColorSpace::SRGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components));
+ case ColorSpace::LinearRGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<LinearSRGBA<T>>(components));
+ case ColorSpace::DisplayP3:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components));
+ case ColorSpace::A98RGB:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<A98RGB<T>>(components));
+ case ColorSpace::Lab:
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components));
+ }
+
+ ASSERT_NOT_REACHED();
+ return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components));
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp 2021-01-28 01:22:09 UTC (rev 271992)
@@ -96,6 +96,8 @@
return "linear-srgb"_s;
case ColorSpace::DisplayP3:
return "display-p3"_s;
+ case ColorSpace::A98RGB:
+ return "a98-rgb"_s;
case ColorSpace::Lab:
return "lab"_s;
}
@@ -163,6 +165,23 @@
return serialization(color);
}
+// A98RGB<float> overloads
+
+String serializationForCSS(const A98RGB<float>& color)
+{
+ return serialization(color);
+}
+
+String serializationForHTML(const A98RGB<float>& color)
+{
+ return serialization(color);
+}
+
+String serializationForRenderTreeAsText(const A98RGB<float>& color)
+{
+ return serialization(color);
+}
+
// Lab<float> overloads
String serializationForCSS(const Lab<float>& color)
Modified: trunk/Source/WebCore/platform/graphics/ColorSerialization.h (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorSerialization.h 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorSerialization.h 2021-01-28 01:22:09 UTC (rev 271992)
@@ -31,6 +31,7 @@
class Color;
+template<typename> struct A98RGB;
template<typename> struct DisplayP3;
template<typename> struct Lab;
template<typename> struct LinearSRGBA;
@@ -56,6 +57,10 @@
WEBCORE_EXPORT String serializationForHTML(const DisplayP3<float>&);
WEBCORE_EXPORT String serializationForRenderTreeAsText(const DisplayP3<float>&);
+WEBCORE_EXPORT String serializationForCSS(const A98RGB<float>&);
+WEBCORE_EXPORT String serializationForHTML(const A98RGB<float>&);
+WEBCORE_EXPORT String serializationForRenderTreeAsText(const A98RGB<float>&);
+
WEBCORE_EXPORT String serializationForCSS(const Lab<float>&);
WEBCORE_EXPORT String serializationForHTML(const Lab<float>&);
WEBCORE_EXPORT String serializationForRenderTreeAsText(const Lab<float>&);
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.cpp (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2021-01-28 01:22:09 UTC (rev 271992)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2020 Apple Inc. All rights reserved.
+ * Copyright (C) 2020-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -42,6 +42,9 @@
case ColorSpace::DisplayP3:
ts << "DisplayP3";
break;
+ case ColorSpace::A98RGB:
+ ts << "a98-rgb";
+ break;
case ColorSpace::Lab:
ts << "L*a*b";
break;
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.h (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.h 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.h 2021-01-28 01:22:09 UTC (rev 271992)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,6 +35,7 @@
SRGB,
LinearRGB,
DisplayP3,
+ A98RGB,
Lab
};
Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/ColorTypes.h 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h 2021-01-28 01:22:09 UTC (rev 271992)
@@ -31,6 +31,19 @@
namespace WebCore {
+template<typename> struct SRGBA;
+template<typename> struct ExtendedSRGBA;
+template<typename> struct LinearSRGBA;
+template<typename> struct LinearExtendedSRGBA;
+template<typename> struct DisplayP3;
+template<typename> struct LinearDisplayP3;
+template<typename> struct A98RGB;
+template<typename> struct LinearA98RGB;
+template<typename> struct Lab;
+template<typename> struct LCHA;
+template<typename> struct HSLA;
+template<typename> struct XYZ;
+
template<typename> struct AlphaTraits;
template<> struct AlphaTraits<uint8_t> {
@@ -118,6 +131,7 @@
static constexpr bool isInvertible = false;
};
+
template<typename ColorType, typename T> constexpr ColorType makeFromComponents(const ColorComponents<T>& c)
{
return ColorType { c[0], c[1], c[2], c[3] };
@@ -269,61 +283,37 @@
}
};
-template<typename T> struct SRGBA : ColorWithAlphaHelper<SRGBA<T>> {
- using ComponentType = T;
- using Model = RGBModel<T>;
- static constexpr auto colorSpace { ColorSpace::SRGB };
-
- constexpr SRGBA(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
- : red { red }
- , green { green }
- , blue { blue }
- , alpha { alpha }
- {
- assertInRange(*this);
- }
- constexpr SRGBA()
- : SRGBA { 0, 0, 0, 0 }
- {
- }
-
- T red;
- T green;
- T blue;
- T alpha;
-};
-
-template<typename T> constexpr ColorComponents<T> asColorComponents(const SRGBA<T>& c)
+template<typename ColorType, typename std::enable_if_t<IsConvertibleToColorComponents<ColorType>>* = nullptr>
+constexpr bool operator==(const ColorType& a, const ColorType& b)
{
- return { c.red, c.green, c.blue, c.alpha };
-}
-
-template<typename T> constexpr bool operator==(const SRGBA<T>& a, const SRGBA<T>& b)
-{
return asColorComponents(a) == asColorComponents(b);
}
-template<typename T> constexpr bool operator!=(const SRGBA<T>& a, const SRGBA<T>& b)
+template<typename ColorType, typename std::enable_if_t<IsConvertibleToColorComponents<ColorType>>* = nullptr>
+constexpr bool operator!=(const ColorType& a, const ColorType& b)
{
return !(a == b);
}
-template<typename T> struct ExtendedSRGBA : ColorWithAlphaHelper<ExtendedSRGBA<T>> {
+// MARK: - RGB Color Types.
+
+template<template<typename> class C, typename T, typename M> struct RGBAType : ColorWithAlphaHelper<C<T>> {
using ComponentType = T;
- using Model = ExtendedRGBModel<T>;
-
- constexpr ExtendedSRGBA(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
+ using Model = M;
+
+ constexpr RGBAType(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
: red { red }
, green { green }
, blue { blue }
, alpha { alpha }
{
+ assertInRange(*this);
}
- constexpr ExtendedSRGBA()
- : ExtendedSRGBA { 0, 0, 0, 0 }
+ constexpr RGBAType()
+ : RGBAType { 0, 0, 0, 0 }
{
}
@@ -333,183 +323,69 @@
T alpha;
};
-template<typename T> constexpr ColorComponents<T> asColorComponents(const ExtendedSRGBA<T>& c)
+template<template<typename> class ColorType, typename T, typename M> constexpr ColorComponents<T> asColorComponents(const RGBAType<ColorType, T, M>& c)
{
return { c.red, c.green, c.blue, c.alpha };
}
-template<typename T> constexpr bool operator==(const ExtendedSRGBA<T>& a, const ExtendedSRGBA<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
+template<typename T> struct SRGBA : RGBAType<SRGBA, T, RGBModel<T>> {
+ using RGBAType<SRGBA, T, RGBModel<T>>::RGBAType;
+ using LinearCounterpart = LinearSRGBA<T>;
+ static constexpr auto colorSpace { ColorSpace::SRGB };
+};
+template<typename T> SRGBA(T, T, T, T) -> SRGBA<T>;
-template<typename T> constexpr bool operator!=(const ExtendedSRGBA<T>& a, const ExtendedSRGBA<T>& b)
-{
- return !(a == b);
-}
-
-
-template<typename T> struct LinearSRGBA : ColorWithAlphaHelper<LinearSRGBA<T>> {
- using ComponentType = T;
- using Model = RGBModel<T>;
+template<typename T> struct LinearSRGBA : RGBAType<LinearSRGBA, T, RGBModel<T>> {
+ using RGBAType<LinearSRGBA, T, RGBModel<T>>::RGBAType;
+ using GammaEncodedCounterpart = SRGBA<T>;
static constexpr auto colorSpace = ColorSpace::LinearRGB;
+};
+template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>;
- constexpr LinearSRGBA(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
- : red { red }
- , green { green }
- , blue { blue }
- , alpha { alpha }
- {
- assertInRange(*this);
- }
- constexpr LinearSRGBA()
- : LinearSRGBA { 0, 0, 0, 0 }
- {
- }
-
- T red;
- T green;
- T blue;
- T alpha;
+template<typename T> struct ExtendedSRGBA : RGBAType<ExtendedSRGBA, T, ExtendedRGBModel<T>> {
+ using RGBAType<ExtendedSRGBA, T, ExtendedRGBModel<T>>::RGBAType;
+ using LinearCounterpart = LinearExtendedSRGBA<T>;
};
+template<typename T> ExtendedSRGBA(T, T, T, T) -> ExtendedSRGBA<T>;
-template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearSRGBA<T>& c)
-{
- return { c.red, c.green, c.blue, c.alpha };
-}
-
-template<typename T> constexpr bool operator==(const LinearSRGBA<T>& a, const LinearSRGBA<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
-
-template<typename T> constexpr bool operator!=(const LinearSRGBA<T>& a, const LinearSRGBA<T>& b)
-{
- return !(a == b);
-}
-
-
-template<typename T> struct LinearExtendedSRGBA : ColorWithAlphaHelper<LinearExtendedSRGBA<T>> {
- using ComponentType = T;
- using Model = ExtendedRGBModel<T>;
-
- constexpr LinearExtendedSRGBA(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
- : red { red }
- , green { green }
- , blue { blue }
- , alpha { alpha }
- {
- }
-
- constexpr LinearExtendedSRGBA()
- : LinearExtendedSRGBA { 0, 0, 0, 0 }
- {
- }
-
- T red;
- T green;
- T blue;
- T alpha;
+template<typename T> struct LinearExtendedSRGBA : RGBAType<LinearExtendedSRGBA, T, ExtendedRGBModel<T>> {
+ using RGBAType<LinearExtendedSRGBA, T, ExtendedRGBModel<T>>::RGBAType;
+ using GammaEncodedCounterpart = ExtendedSRGBA<T>;
};
+template<typename T> LinearExtendedSRGBA(T, T, T, T) -> LinearExtendedSRGBA<T>;
-template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearExtendedSRGBA<T>& c)
-{
- return { c.red, c.green, c.blue, c.alpha };
-}
-template<typename T> constexpr bool operator==(const LinearExtendedSRGBA<T>& a, const LinearExtendedSRGBA<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
-
-template<typename T> constexpr bool operator!=(const LinearExtendedSRGBA<T>& a, const LinearExtendedSRGBA<T>& b)
-{
- return !(a == b);
-}
-
-
-template<typename T> struct DisplayP3 : ColorWithAlphaHelper<DisplayP3<T>> {
- using ComponentType = T;
- using Model = RGBModel<T>;
+template<typename T> struct DisplayP3 : RGBAType<DisplayP3, T, RGBModel<T>> {
+ using RGBAType<DisplayP3, T, RGBModel<T>>::RGBAType;
+ using LinearCounterpart = LinearDisplayP3<T>;
static constexpr auto colorSpace = ColorSpace::DisplayP3;
+};
+template<typename T> DisplayP3(T, T, T, T) -> DisplayP3<T>;
- constexpr DisplayP3(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
- : red { red }
- , green { green }
- , blue { blue }
- , alpha { alpha }
- {
- assertInRange(*this);
- }
+template<typename T> struct LinearDisplayP3 : RGBAType<LinearDisplayP3, T, RGBModel<T>> {
+ using RGBAType<LinearDisplayP3, T, RGBModel<T>>::RGBAType;
+ using GammaEncodedCounterpart = DisplayP3<T>;
+};
+template<typename T> LinearDisplayP3(T, T, T, T) -> LinearDisplayP3<T>;
- constexpr DisplayP3()
- : DisplayP3 { 0, 0, 0, 0 }
- {
- }
- T red;
- T green;
- T blue;
- T alpha;
+template<typename T> struct A98RGB : RGBAType<A98RGB, T, RGBModel<T>> {
+ using RGBAType<A98RGB, T, RGBModel<T>>::RGBAType;
+ using LinearCounterpart = LinearA98RGB<T>;
+ static constexpr auto colorSpace = ColorSpace::A98RGB;
};
+template<typename T> A98RGB(T, T, T, T) -> A98RGB<T>;
-template<typename T> constexpr ColorComponents<T> asColorComponents(const DisplayP3<T>& c)
-{
- return { c.red, c.green, c.blue, c.alpha };
-}
-
-template<typename T> constexpr bool operator==(const DisplayP3<T>& a, const DisplayP3<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
-
-template<typename T> constexpr bool operator!=(const DisplayP3<T>& a, const DisplayP3<T>& b)
-{
- return !(a == b);
-}
-
-
-template<typename T> struct LinearDisplayP3 : ColorWithAlphaHelper<LinearDisplayP3<T>> {
- using ComponentType = T;
- using Model = RGBModel<T>;
-
- constexpr LinearDisplayP3(T red, T green, T blue, T alpha = AlphaTraits<T>::opaque)
- : red { red }
- , green { green }
- , blue { blue }
- , alpha { alpha }
- {
- assertInRange(*this);
- }
-
- constexpr LinearDisplayP3()
- : LinearDisplayP3 { 0, 0, 0, 0 }
- {
- }
-
- T red;
- T green;
- T blue;
- T alpha;
+template<typename T> struct LinearA98RGB : RGBAType<LinearA98RGB, T, RGBModel<T>> {
+ using RGBAType<LinearA98RGB, T, RGBModel<T>>::RGBAType;
+ using GammaEncodedCounterpart = A98RGB<T>;
};
+template<typename T> LinearA98RGB(T, T, T, T) -> LinearA98RGB<T>;
-template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearDisplayP3<T>& c)
-{
- return { c.red, c.green, c.blue, c.alpha };
-}
-template<typename T> constexpr bool operator==(const LinearDisplayP3<T>& a, const LinearDisplayP3<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
+// MARK: - Lab Color Type.
-template<typename T> constexpr bool operator!=(const LinearDisplayP3<T>& a, const LinearDisplayP3<T>& b)
-{
- return !(a == b);
-}
-
-
template<typename T> struct Lab : ColorWithAlphaHelper<Lab<T>> {
using ComponentType = T;
using Model = LabModel<T>;
@@ -540,17 +416,8 @@
return { c.lightness, c.a, c.b, c.alpha };
}
-template<typename T> constexpr bool operator==(const Lab<T>& a, const Lab<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
+// MARK: - LCHA Color Type.
-template<typename T> constexpr bool operator!=(const Lab<T>& a, const Lab<T>& b)
-{
- return !(a == b);
-}
-
-
template<typename T> struct LCHA : ColorWithAlphaHelper<LCHA<T>> {
using ComponentType = T;
using Model = LCHModel<T>;
@@ -580,17 +447,9 @@
return { c.lightness, c.chroma, c.hue, c.alpha };
}
-template<typename T> constexpr bool operator==(const LCHA<T>& a, const LCHA<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
-template<typename T> constexpr bool operator!=(const LCHA<T>& a, const LCHA<T>& b)
-{
- return !(a == b);
-}
+// MARK: - HSLA Color Type.
-
template<typename T> struct HSLA : ColorWithAlphaHelper<HSLA<T>> {
using ComponentType = T;
using Model = HSLModel<T>;
@@ -615,24 +474,13 @@
T alpha;
};
-template<typename T> HSLA(T, T, T, T) -> HSLA<T>;
-
template<typename T> constexpr ColorComponents<T> asColorComponents(const HSLA<T>& c)
{
return { c.hue, c.saturation, c.lightness, c.alpha };
}
-template<typename T> constexpr bool operator==(const HSLA<T>& a, const HSLA<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
+// MARK: - XYZ Color Type.
-template<typename T> constexpr bool operator!=(const HSLA<T>& a, const HSLA<T>& b)
-{
- return !(a == b);
-}
-
-
template<typename T> struct XYZA : ColorWithAlphaHelper<XYZA<T>> {
using ComponentType = T;
using Model = XYZModel<T>;
@@ -662,34 +510,7 @@
return { c.x, c.y, c.z, c.alpha };
}
-template<typename T> constexpr bool operator==(const XYZA<T>& a, const XYZA<T>& b)
-{
- return asColorComponents(a) == asColorComponents(b);
-}
-template<typename T> constexpr bool operator!=(const XYZA<T>& a, const XYZA<T>& b)
-{
- return !(a == b);
-}
-
-
-template<typename T, typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<T>& components, ColorSpace colorSpace, Functor&& functor)
-{
- switch (colorSpace) {
- case ColorSpace::SRGB:
- return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components));
- case ColorSpace::LinearRGB:
- return std::invoke(std::forward<Functor>(functor), makeFromComponents<LinearSRGBA<T>>(components));
- case ColorSpace::DisplayP3:
- return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components));
- case ColorSpace::Lab:
- return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components));
- }
-
- ASSERT_NOT_REACHED();
- return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components));
-}
-
// Packed Color Formats
namespace PackedColor {
Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoBackend.cpp (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoBackend.cpp 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairoBackend.cpp 2021-01-28 01:22:09 UTC (rev 271992)
@@ -104,7 +104,7 @@
std::array<uint8_t, 256> array;
for (unsigned i = 0; i < 256; i++) {
float color = i / 255.0f;
- color = rgbToLinearColorComponentClamping(color);
+ color = SRGBTransferFunction::toLinearClamping(color);
array[i] = static_cast<uint8_t>(round(color * 255));
}
return array;
@@ -115,7 +115,7 @@
std::array<uint8_t, 256> array;
for (unsigned i = 0; i < 256; i++) {
float color = i / 255.0f;
- color = linearToRGBColorComponentClamping(color);
+ color = SRGBTransferFunction::fromLinearClamping(color);
array[i] = static_cast<uint8_t>(round(color * 255));
}
return array;
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2021-01-28 01:22:09 UTC (rev 271992)
@@ -82,6 +82,20 @@
return displayP3ColorSpace;
}
+CGColorSpaceRef a98RGBColorSpaceRef()
+{
+ static CGColorSpaceRef a98RGBColorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+#if PLATFORM(COCOA)
+ a98RGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceAdobeRGB1998);
+#else
+ a98RGBColorSpace = sRGBColorSpaceRef();
+#endif
+ });
+ return a98RGBColorSpace;
+}
+
CGColorSpaceRef labColorSpaceRef()
{
// FIXME: Add support for conversion to Lab on supported platforms.
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (271991 => 271992)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2021-01-28 01:11:45 UTC (rev 271991)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2021-01-28 01:22:09 UTC (rev 271992)
@@ -35,6 +35,7 @@
WEBCORE_EXPORT CGColorSpaceRef linearRGBColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef labColorSpaceRef();
+WEBCORE_EXPORT CGColorSpaceRef a98RGBColorSpaceRef();
WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
@@ -46,6 +47,8 @@
return linearRGBColorSpaceRef();
case ColorSpace::DisplayP3:
return displayP3ColorSpaceRef();
+ case ColorSpace::A98RGB:
+ return a98RGBColorSpaceRef();
case ColorSpace::Lab:
return labColorSpaceRef();
}