Changeset 272311 in webkit
- Timestamp:
- Feb 3, 2021 6:38:52 AM (18 months ago)
- Location:
- trunk
- Files:
-
- 10 added
- 19 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/TestExpectations (modified) (1 diff)
-
LayoutTests/fast/css/parsing-color-function-expected.txt (modified) (1 diff)
-
LayoutTests/fast/css/parsing-color-function.html (modified) (1 diff)
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-001-expected.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-001.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-002-expected.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-002.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-003-expected.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-003.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-004-expected.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-004.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-005-expected.html (added)
-
LayoutTests/imported/w3c/web-platform-tests/css/css-color/xyz-005.html (added)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/CSSValueKeywords.in (modified) (1 diff)
-
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (modified) (2 diffs)
-
Source/WebCore/platform/graphics/ColorConversion.h (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorModels.h (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorSerialization.cpp (modified) (4 diffs)
-
Source/WebCore/platform/graphics/ColorSerialization.h (modified) (2 diffs)
-
Source/WebCore/platform/graphics/ColorSpace.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorSpace.h (modified) (2 diffs)
-
Source/WebCore/platform/graphics/ColorTypes.h (modified) (10 diffs)
-
Source/WebCore/platform/graphics/ColorUtilities.h (modified) (2 diffs)
-
Source/WebCore/platform/graphics/ExtendedColor.h (modified) (1 diff)
-
Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r272308 r272311 1 2021-02-03 Sam Weinig <weinig@apple.com> 2 3 Add support for color(xyz ...) as part of CSS Color 4 4 https://bugs.webkit.org/show_bug.cgi?id=221190 5 6 Reviewed by Simon Fraser. 7 8 * TestExpectations: 9 Remove now passing xyz test. Update comment for the other xyz test which is invalid. 10 Getting it removed in https://github.com/web-platform-tests/wpt/pull/27416. 11 12 * fast/css/parsing-color-function-expected.txt: 13 * fast/css/parsing-color-function.html: 14 Add xyz specific parsing tests, as the rgb ones can't be reusued due to xyz 15 not supporting percentages for any component. 16 1 17 2021-02-03 Ziran Sun <zsun@igalia.com> 2 18 -
trunk/LayoutTests/TestExpectations
r272308 r272311 4602 4602 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-014.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support 4603 4603 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-015.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support (unclear if this makes sense) 4604 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-016.html [ ImageOnlyFailure ] # Requires xyz support 4605 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-017.html [ ImageOnlyFailure ] # Requires xyz support 4604 webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-017.html [ ImageOnlyFailure ] # Invalid test, percentages are not allowed for color(xyz). 4606 4605 4607 4606 webkit.org/b/218496 http/tests/loading/redirect-with-no-location-crash.html [ Skip ] -
trunk/LayoutTests/fast/css/parsing-color-function-expected.txt
r272125 r272311 124 124 PASS computedStyle("background-color", "color(prophoto-rgb 0% 0% 0deg)") is "rgba(0, 0, 0, 0)" 125 125 PASS computedStyle("background-color", "color(prophoto-rgb 40% 0 0deg)") is "rgba(0, 0, 0, 0)" 126 127 Testing color(xyz ...) 128 PASS computedStyle("background-color", "color(xyz 0 0 0)") is "color(xyz 0 0 0)" 129 PASS computedStyle("background-color", "color(xyz 0 0 0 / 1)") is "color(xyz 0 0 0)" 130 PASS computedStyle("background-color", "color(xyz 1 1 1)") is "color(xyz 1 1 1)" 131 PASS computedStyle("background-color", "color(xyz 1 1 1 / 1)") is "color(xyz 1 1 1)" 132 PASS computedStyle("background-color", "color(xyz -1 -1 -1)") is "color(xyz -1 -1 -1)" 133 PASS computedStyle("background-color", "color(xyz 0.1 0.1 0.1)") is "color(xyz 0.1 0.1 0.1)" 134 PASS computedStyle("background-color", "color(xyz 10 10 10)") is "color(xyz 10 10 10)" 135 PASS computedStyle("background-color", "color(xyz .2 .2 .25)") is "color(xyz 0.2 0.2 0.25)" 136 PASS computedStyle("background-color", "color(xyz 0 0 0 / 0.5)") is "color(xyz 0 0 0 / 0.5)" 137 PASS computedStyle("background-color", "color(xyz .20 0 10/0.5)") is "color(xyz 0.2 0 10 / 0.5)" 138 PASS computedStyle("background-color", "color(xyz .20 0 10/50%)") is "color(xyz 0.2 0 10 / 0.5)" 139 PASS computedStyle("background-color", "color(xyz 0 0 0 / -10%)") is "color(xyz 0 0 0 / 0)" 140 PASS computedStyle("background-color", "color(xyz 0 0 0 / 110%)") is "color(xyz 0 0 0)" 141 PASS computedStyle("background-color", "color(xyz 0 0 0 / 300%)") is "color(xyz 0 0 0)" 142 PASS computedStyle("background-color", "color(xyz 1 1)") is "color(xyz 1 1 0)" 143 PASS computedStyle("background-color", "color(xyz 1)") is "color(xyz 1 0 0)" 144 PASS computedStyle("background-color", "color(xyz)") is "color(xyz 0 0 0)" 145 PASS computedStyle("background-color", "color(xyz 1 1 / .5)") is "color(xyz 1 1 0 / 0.5)" 146 PASS computedStyle("background-color", "color(xyz 1 / 0.5)") is "color(xyz 1 0 0 / 0.5)" 147 PASS computedStyle("background-color", "color(xyz / 50%)") is "color(xyz 0 0 0 / 0.5)" 148 149 Test invalid values 150 PASS computedStyle("background-color", "color(xyz 0 0 0 0)") is "rgba(0, 0, 0, 0)" 151 PASS computedStyle("background-color", "color(xyz 0deg 0% 0)") is "rgba(0, 0, 0, 0)" 152 PASS computedStyle("background-color", "color(xyz 0% 0 0)") is "rgba(0, 0, 0, 0)" 153 PASS computedStyle("background-color", "color(xyz 0% 0 0 1)") is "rgba(0, 0, 0, 0)" 154 PASS computedStyle("background-color", "color(xyz 0% 0 0 10%)") is "rgba(0, 0, 0, 0)" 155 PASS computedStyle("background-color", "color(xyz 0% 0 0deg)") is "rgba(0, 0, 0, 0)" 156 PASS computedStyle("background-color", "color(xyz 0% 0% 0deg)") is "rgba(0, 0, 0, 0)" 157 PASS computedStyle("background-color", "color(xyz 40% 0 0deg)") is "rgba(0, 0, 0, 0)" 126 158 PASS successfullyParsed is true 127 159 -
trunk/LayoutTests/fast/css/parsing-color-function.html
r272125 r272311 69 69 testComputed("background-color", `color(${color} 40% 0 0deg)`, `rgba(0, 0, 0, 0)`); 70 70 } 71 72 debug(''); 73 debug(`Testing color(xyz ...)`); 74 75 testComputed("background-color", `color(xyz 0 0 0)`, `color(xyz 0 0 0)`); 76 testComputed("background-color", `color(xyz 0 0 0 / 1)`, `color(xyz 0 0 0)`); 77 testComputed("background-color", `color(xyz 1 1 1)`, `color(xyz 1 1 1)`); 78 testComputed("background-color", `color(xyz 1 1 1 / 1)`, `color(xyz 1 1 1)`); 79 testComputed("background-color", `color(xyz -1 -1 -1)`, `color(xyz -1 -1 -1)`); 80 testComputed("background-color", `color(xyz 0.1 0.1 0.1)`, `color(xyz 0.1 0.1 0.1)`); 81 testComputed("background-color", `color(xyz 10 10 10)`, `color(xyz 10 10 10)`); 82 testComputed("background-color", `color(xyz .2 .2 .25)`, `color(xyz 0.2 0.2 0.25)`); 83 testComputed("background-color", `color(xyz 0 0 0 / 0.5)`, `color(xyz 0 0 0 / 0.5)`); 84 testComputed("background-color", `color(xyz .20 0 10/0.5)`, `color(xyz 0.2 0 10 / 0.5)`); 85 testComputed("background-color", `color(xyz .20 0 10/50%)`, `color(xyz 0.2 0 10 / 0.5)`); 86 testComputed("background-color", `color(xyz 0 0 0 / -10%)`, `color(xyz 0 0 0 / 0)`); 87 testComputed("background-color", `color(xyz 0 0 0 / 110%)`, `color(xyz 0 0 0)`); 88 testComputed("background-color", `color(xyz 0 0 0 / 300%)`, `color(xyz 0 0 0)`); 89 testComputed("background-color", `color(xyz 1 1)`, `color(xyz 1 1 0)`); 90 testComputed("background-color", `color(xyz 1)`, `color(xyz 1 0 0)`); 91 testComputed("background-color", `color(xyz)`, `color(xyz 0 0 0)`); 92 testComputed("background-color", `color(xyz 1 1 / .5)`, `color(xyz 1 1 0 / 0.5)`); 93 testComputed("background-color", `color(xyz 1 / 0.5)`, `color(xyz 1 0 0 / 0.5)`); 94 testComputed("background-color", `color(xyz / 50%)`, `color(xyz 0 0 0 / 0.5)`); 95 96 debug(''); 97 debug('Test invalid values'); 98 testComputed("background-color", `color(xyz 0 0 0 0)`, `rgba(0, 0, 0, 0)`); 99 testComputed("background-color", `color(xyz 0deg 0% 0)`, `rgba(0, 0, 0, 0)`); 100 testComputed("background-color", `color(xyz 0% 0 0)`, `rgba(0, 0, 0, 0)`); 101 testComputed("background-color", `color(xyz 0% 0 0 1)`, `rgba(0, 0, 0, 0)`); 102 testComputed("background-color", `color(xyz 0% 0 0 10%)`, `rgba(0, 0, 0, 0)`); 103 testComputed("background-color", `color(xyz 0% 0 0deg)`, `rgba(0, 0, 0, 0)`); 104 testComputed("background-color", `color(xyz 0% 0% 0deg)`, `rgba(0, 0, 0, 0)`); 105 testComputed("background-color", `color(xyz 40% 0 0deg)`, `rgba(0, 0, 0, 0)`); 106 71 107 </script> 72 108 -
trunk/LayoutTests/imported/w3c/ChangeLog
r272309 r272311 1 2021-02-03 Sam Weinig <weinig@apple.com> 2 3 Add support for color(xyz ...) as part of CSS Color 4 4 https://bugs.webkit.org/show_bug.cgi?id=221190 5 6 Reviewed by Simon Fraser. 7 8 Add some new WPT tests for color(xyz ) that will be upstreamed shortly. 9 10 * web-platform-tests/css/css-color/xyz-001-expected.html: Added. 11 * web-platform-tests/css/css-color/xyz-001.html: Added. 12 * web-platform-tests/css/css-color/xyz-002-expected.html: Added. 13 * web-platform-tests/css/css-color/xyz-002.html: Added. 14 * web-platform-tests/css/css-color/xyz-003-expected.html: Added. 15 * web-platform-tests/css/css-color/xyz-003.html: Added. 16 * web-platform-tests/css/css-color/xyz-004-expected.html: Added. 17 * web-platform-tests/css/css-color/xyz-004.html: Added. 18 * web-platform-tests/css/css-color/xyz-005-expected.html: Added. 19 * web-platform-tests/css/css-color/xyz-005.html: Added. 20 1 21 2021-02-03 Ziran Sun <zsun@igalia.com> 2 22 -
trunk/Source/WebCore/ChangeLog
r272310 r272311 1 2021-02-03 Sam Weinig <weinig@apple.com> 2 3 Add support for color(xyz ...) as part of CSS Color 4 4 https://bugs.webkit.org/show_bug.cgi?id=221190 5 6 Reviewed by Simon Fraser. 7 8 Add final (for now) predefined color space supported by color() in CSS Color 4, XYZ. 9 10 The specific XYZ use by CSS is the XYZ with D50 white point. To make the generic 11 XYZA<T, WhitePoint> type work in the infrastrucure, the colorSpace member was removed 12 from the color types, and the mapping from ColorSpace enum value to ColorType was 13 converted to use template specialization and can now be extracted using the syntax: 14 15 ColorSpaceFor<ColorType> 16 17 This change also removed the inclusion of all of the color type specific serialiazation 18 function declarations in ColorSerialization.h, and instead moved them to the cpp file. 19 They weren't being used, and to support the XYZA<float, WhitePoint::D50> would have required 20 incluing more headers, which seemed like the wrong tradeoff. If accessing serialization 21 without constructing a WebCore::Color is useful in the future, we can always add them back. 22 23 Tests: imported/w3c/web-platform-tests/css/css-color/xyz-001.html 24 imported/w3c/web-platform-tests/css/css-color/xyz-002.html 25 imported/w3c/web-platform-tests/css/css-color/xyz-003.html 26 imported/w3c/web-platform-tests/css/css-color/xyz-004.html 27 imported/w3c/web-platform-tests/css/css-color/xyz-005.html 28 29 * css/CSSValueKeywords.in: 30 Add xyz keyword. 31 32 * css/parser/CSSPropertyParserHelpers.cpp: 33 (WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZParameters): 34 (WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters): 35 Add parsing for color(xyz ) parameters. This can't reuse the RGB parameter 36 parsing because xyz does not allow percentages for any parameter. 37 38 * platform/graphics/ColorConversion.h: 39 (WebCore::callWithColorType): Deleted. 40 Moved callWithColorType to ColorSpace.h, where it makes a bit more sense 41 now that the color mapping is also defined there. This puts most of the 42 color mapping in one place. 43 44 * platform/graphics/ColorModels.h: 45 Add some needed includes that fiddling with headers exposed. 46 47 * platform/graphics/ColorSerialization.cpp: 48 (WebCore::serialization): 49 (WebCore::serializationForCSS): 50 (WebCore::serializationForHTML): 51 (WebCore::serializationForRenderTreeAsText): 52 * platform/graphics/ColorSerialization.h: 53 Add support for serializing XYZA<float, WhitePoint::D50>, taking the chance 54 to move all the unnecessarily exposed type specific serialization functions. 55 56 * platform/graphics/ColorSpace.cpp: 57 (WebCore::operator<<): 58 Add support for XYZ_D50. 59 60 * platform/graphics/ColorSpace.h: 61 Add color mapping replacing previous explicit static members for colorSpace 62 mapping which are no longer usable due to the generic nature of XYZA. 63 64 (WebCore::callWithColorType): 65 Moved from ColorConversion.h. 66 67 * platform/graphics/ColorTypes.h: 68 Remove colorSpace members. Replaced by color space mapping in ColorSpace.h 69 70 * platform/graphics/ColorUtilities.h: 71 (WebCore::isBlack): 72 (WebCore::isWhite): 73 Add overloads for XYZA needed by Color. 74 75 * platform/graphics/ExtendedColor.h: 76 (WebCore::ExtendedColor::create): 77 Replace color.colorSpace with ColorSpaceFor<ColorType>. 78 79 * platform/graphics/cg/ColorSpaceCG.cpp: 80 (WebCore::xyzD50ColorSpaceRef): 81 * platform/graphics/cg/ColorSpaceCG.h: 82 (WebCore::cachedCGColorSpace): 83 Add CoreGraphics support for the XYZ color space. (kCGColorSpaceGenericXYZ maps to XYZ with a D50 white point.) 84 1 85 2021-02-03 Zalan Bujtas <zalan@apple.com> 2 86 -
trunk/Source/WebCore/css/CSSValueKeywords.in
r272125 r272311 1410 1410 // rec2020 1411 1411 // sRGB 1412 xyz 1412 1413 1413 1414 // prefers-default-appearance -
trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
r272125 r272311 943 943 } 944 944 945 static Color parseColorFunctionForXYZParameters(CSSParserTokenRange& args) 946 { 947 ASSERT(args.peek().id() == CSSValueXyz); 948 consumeIdentRaw(args); 949 950 double channels[3] = { 0, 0, 0 }; 951 [&] { 952 auto x = consumeNumberRaw(args, ValueRangeAll); 953 if (!x) 954 return; 955 channels[0] = *x; 956 957 auto y = consumeNumberRaw(args, ValueRangeAll); 958 if (!y) 959 return; 960 channels[1] = *y; 961 962 auto z = consumeNumberRaw(args, ValueRangeAll); 963 if (!z) 964 return; 965 channels[2] = *z; 966 }(); 967 968 auto alpha = parseOptionalAlpha(args); 969 if (!alpha) 970 return { }; 971 972 return XYZA<float, WhitePoint::D50> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), *alpha }; 973 } 974 945 975 static Color parseColorFunctionParameters(CSSParserTokenRange& range) 946 976 { … … 967 997 case CSSValueSRGB: 968 998 color = parseColorFunctionForRGBTypes<SRGBA<float>>(args); 999 break; 1000 case CSSValueXyz: 1001 color = parseColorFunctionForXYZParameters(args); 969 1002 break; 970 1003 default: -
trunk/Source/WebCore/platform/graphics/ColorConversion.h
r272146 r272311 257 257 } 258 258 259 260 template<typename T, typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<T>& components, ColorSpace colorSpace, Functor&& functor)261 {262 switch (colorSpace) {263 case ColorSpace::A98RGB:264 return std::invoke(std::forward<Functor>(functor), makeFromComponents<A98RGB<T>>(components));265 case ColorSpace::DisplayP3:266 return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components));267 case ColorSpace::Lab:268 return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components));269 case ColorSpace::LinearRGB:270 return std::invoke(std::forward<Functor>(functor), makeFromComponents<LinearSRGBA<T>>(components));271 case ColorSpace::ProPhotoRGB:272 return std::invoke(std::forward<Functor>(functor), makeFromComponents<ProPhotoRGB<T>>(components));273 case ColorSpace::Rec2020:274 return std::invoke(std::forward<Functor>(functor), makeFromComponents<Rec2020<T>>(components));275 case ColorSpace::SRGB:276 return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components));277 }278 279 ASSERT_NOT_REACHED();280 return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components));281 }282 283 259 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/ColorModels.h
r272066 r272311 25 25 26 26 #pragma once 27 28 #include <array> 29 #include <limits> 27 30 28 31 namespace WebCore { -
trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp
r272125 r272311 37 37 namespace WebCore { 38 38 39 static String serializationForCSS(const A98RGB<float>&); 40 static String serializationForHTML(const A98RGB<float>&); 41 static String serializationForRenderTreeAsText(const A98RGB<float>&); 42 43 static String serializationForCSS(const DisplayP3<float>&); 44 static String serializationForHTML(const DisplayP3<float>&); 45 static String serializationForRenderTreeAsText(const DisplayP3<float>&); 46 47 static String serializationForCSS(const Lab<float>&); 48 static String serializationForHTML(const Lab<float>&); 49 static String serializationForRenderTreeAsText(const Lab<float>&); 50 51 static String serializationForCSS(const LinearSRGBA<float>&); 52 static String serializationForHTML(const LinearSRGBA<float>&); 53 static String serializationForRenderTreeAsText(const LinearSRGBA<float>&); 54 55 static String serializationForCSS(const ProPhotoRGB<float>&); 56 static String serializationForHTML(const ProPhotoRGB<float>&); 57 static String serializationForRenderTreeAsText(const ProPhotoRGB<float>&); 58 59 static String serializationForCSS(const Rec2020<float>&); 60 static String serializationForHTML(const Rec2020<float>&); 61 static String serializationForRenderTreeAsText(const Rec2020<float>&); 62 63 static String serializationForCSS(const SRGBA<float>&); 64 static String serializationForHTML(const SRGBA<float>&); 65 static String serializationForRenderTreeAsText(const SRGBA<float>&); 66 67 static String serializationForCSS(SRGBA<uint8_t>); 68 static String serializationForHTML(SRGBA<uint8_t>); 69 static String serializationForRenderTreeAsText(SRGBA<uint8_t>); 70 71 static String serializationForCSS(const XYZA<float, WhitePoint::D50>&); 72 static String serializationForHTML(const XYZA<float, WhitePoint::D50>&); 73 static String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>&); 74 75 39 76 String serializationForCSS(const Color& color) 40 77 { … … 75 112 case ColorSpace::SRGB: 76 113 return "srgb"_s; 114 case ColorSpace::XYZ_D50: 115 return "xyz"_s; 77 116 } 78 117 … … 85 124 auto [c1, c2, c3, alpha] = color; 86 125 if (WTF::areEssentiallyEqual(alpha, 1.0f)) 87 return makeString("color(", serialization( color.colorSpace), ' ', c1, ' ', c2, ' ', c3, ')');88 return makeString("color(", serialization( color.colorSpace), ' ', c1, ' ', c2, ' ', c3, " / ", alpha, ')');126 return makeString("color(", serialization(ColorSpaceFor<ColorType>), ' ', c1, ' ', c2, ' ', c3, ')'); 127 return makeString("color(", serialization(ColorSpaceFor<ColorType>), ' ', c1, ' ', c2, ' ', c3, " / ", alpha, ')'); 89 128 } 90 129 … … 261 300 } 262 301 263 } 302 // MARK: XYZA<float, WhitePoint::D50> overloads 303 304 String serializationForCSS(const XYZA<float, WhitePoint::D50>& color) 305 { 306 return serialization(color); 307 } 308 309 String serializationForHTML(const XYZA<float, WhitePoint::D50>& color) 310 { 311 return serialization(color); 312 } 313 314 String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>& color) 315 { 316 return serialization(color); 317 } 318 319 } -
trunk/Source/WebCore/platform/graphics/ColorSerialization.h
r272125 r272311 32 32 class Color; 33 33 34 template<typename> struct A98RGB; 35 template<typename> struct DisplayP3; 36 template<typename> struct Lab; 37 template<typename> struct LinearSRGBA; 38 template<typename> struct ProPhotoRGB; 39 template<typename> struct Rec2020; 40 template<typename> struct SRGBA; 41 42 // serializationForHTML returns the color serialized according to HTML5 <https://html.spec.whatwg.org/multipage/scripting.html#fill-and-stroke-styles> (10 September 2015) 43 // serializationForCSS returns the color serialized according to CSS 44 // serializationForRenderTreeAsText returns the color serialized for DumpRenderTree, #RRGGBB, #RRGGBBAA or the CSS serialization 34 // serializationForCSS returns the color serialized according to CSS <https://drafts.csswg.org/css-color-4/#serializing-color-values>. 35 // serializationForHTML returns the color serialized according to HTML5 <https://html.spec.whatwg.org/multipage/scripting.html#fill-and-stroke-styles> (10 September 2015). 36 // serializationForRenderTreeAsText returns the color serialized for DumpRenderTree, #RRGGBB, #RRGGBBAA or the CSS serialization. 45 37 46 38 WEBCORE_EXPORT String serializationForCSS(const Color&); … … 48 40 WEBCORE_EXPORT String serializationForRenderTreeAsText(const Color&); 49 41 50 // Per-ColorType specializations.51 52 WEBCORE_EXPORT String serializationForCSS(const A98RGB<float>&);53 WEBCORE_EXPORT String serializationForHTML(const A98RGB<float>&);54 WEBCORE_EXPORT String serializationForRenderTreeAsText(const A98RGB<float>&);55 56 WEBCORE_EXPORT String serializationForCSS(const DisplayP3<float>&);57 WEBCORE_EXPORT String serializationForHTML(const DisplayP3<float>&);58 WEBCORE_EXPORT String serializationForRenderTreeAsText(const DisplayP3<float>&);59 60 WEBCORE_EXPORT String serializationForCSS(const Lab<float>&);61 WEBCORE_EXPORT String serializationForHTML(const Lab<float>&);62 WEBCORE_EXPORT String serializationForRenderTreeAsText(const Lab<float>&);63 64 WEBCORE_EXPORT String serializationForCSS(const LinearSRGBA<float>&);65 WEBCORE_EXPORT String serializationForHTML(const LinearSRGBA<float>&);66 WEBCORE_EXPORT String serializationForRenderTreeAsText(const LinearSRGBA<float>&);67 68 WEBCORE_EXPORT String serializationForCSS(const ProPhotoRGB<float>&);69 WEBCORE_EXPORT String serializationForHTML(const ProPhotoRGB<float>&);70 WEBCORE_EXPORT String serializationForRenderTreeAsText(const ProPhotoRGB<float>&);71 72 WEBCORE_EXPORT String serializationForCSS(const Rec2020<float>&);73 WEBCORE_EXPORT String serializationForHTML(const Rec2020<float>&);74 WEBCORE_EXPORT String serializationForRenderTreeAsText(const Rec2020<float>&);75 76 WEBCORE_EXPORT String serializationForCSS(const SRGBA<float>&);77 WEBCORE_EXPORT String serializationForHTML(const SRGBA<float>&);78 WEBCORE_EXPORT String serializationForRenderTreeAsText(const SRGBA<float>&);79 80 WEBCORE_EXPORT String serializationForCSS(SRGBA<uint8_t>);81 WEBCORE_EXPORT String serializationForHTML(SRGBA<uint8_t>);82 WEBCORE_EXPORT String serializationForRenderTreeAsText(SRGBA<uint8_t>);83 84 42 } -
trunk/Source/WebCore/platform/graphics/ColorSpace.cpp
r272125 r272311 55 55 ts << "sRGB"; 56 56 break; 57 case ColorSpace::XYZ_D50: 58 ts << "XYZ"; 59 break; 57 60 } 58 61 return ts; -
trunk/Source/WebCore/platform/graphics/ColorSpace.h
r272125 r272311 26 26 #pragma once 27 27 28 #include "ColorTypes.h" 29 28 30 namespace WTF { 29 31 class TextStream; … … 40 42 Rec2020, 41 43 SRGB, 44 XYZ_D50, 42 45 }; 43 46 44 47 WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace); 45 48 49 50 template<typename> struct ColorSpaceMapping; 51 template<typename T> struct ColorSpaceMapping<A98RGB<T>> { static constexpr auto colorSpace { ColorSpace::A98RGB }; }; 52 template<typename T> struct ColorSpaceMapping<DisplayP3<T>> { static constexpr auto colorSpace { ColorSpace::DisplayP3 }; }; 53 template<typename T> struct ColorSpaceMapping<Lab<T>> { static constexpr auto colorSpace { ColorSpace::Lab }; }; 54 template<typename T> struct ColorSpaceMapping<LinearSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::LinearRGB }; }; 55 template<typename T> struct ColorSpaceMapping<ProPhotoRGB<T>> { static constexpr auto colorSpace { ColorSpace::ProPhotoRGB }; }; 56 template<typename T> struct ColorSpaceMapping<Rec2020<T>> { static constexpr auto colorSpace { ColorSpace::Rec2020 }; }; 57 template<typename T> struct ColorSpaceMapping<SRGBA<T>> { static constexpr auto colorSpace { ColorSpace::SRGB }; }; 58 template<typename T> struct ColorSpaceMapping<XYZA<T, WhitePoint::D50>> { static constexpr auto colorSpace { ColorSpace::XYZ_D50 }; }; 59 60 template<typename ColorType> constexpr ColorSpace ColorSpaceFor = ColorSpaceMapping<ColorType>::colorSpace; 61 62 63 template<typename T, typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<T>& components, ColorSpace colorSpace, Functor&& functor) 64 { 65 switch (colorSpace) { 66 case ColorSpace::A98RGB: 67 return std::invoke(std::forward<Functor>(functor), makeFromComponents<A98RGB<T>>(components)); 68 case ColorSpace::DisplayP3: 69 return std::invoke(std::forward<Functor>(functor), makeFromComponents<DisplayP3<T>>(components)); 70 case ColorSpace::Lab: 71 return std::invoke(std::forward<Functor>(functor), makeFromComponents<Lab<T>>(components)); 72 case ColorSpace::LinearRGB: 73 return std::invoke(std::forward<Functor>(functor), makeFromComponents<LinearSRGBA<T>>(components)); 74 case ColorSpace::ProPhotoRGB: 75 return std::invoke(std::forward<Functor>(functor), makeFromComponents<ProPhotoRGB<T>>(components)); 76 case ColorSpace::Rec2020: 77 return std::invoke(std::forward<Functor>(functor), makeFromComponents<Rec2020<T>>(components)); 78 case ColorSpace::SRGB: 79 return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components)); 80 case ColorSpace::XYZ_D50: 81 return std::invoke(std::forward<Functor>(functor), makeFromComponents<XYZA<T, WhitePoint::D50>>(components)); 82 } 83 84 ASSERT_NOT_REACHED(); 85 return std::invoke(std::forward<Functor>(functor), makeFromComponents<SRGBA<T>>(components)); 86 } 87 46 88 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/ColorTypes.h
r272146 r272311 28 28 #include "ColorComponents.h" 29 29 #include "ColorModels.h" 30 #include "ColorSpace.h"31 30 32 31 namespace WebCore { … … 150 149 #endif 151 150 152 template<typename, typename = void> inline constexpr bool HasColorSpaceMember = false;153 template<typename T> inline constexpr bool HasColorSpaceMember<T, std::void_t<decltype(std::declval<T>().colorSpace)>> = true;154 155 151 template<typename, typename = void> inline constexpr bool IsConvertibleToColorComponents = false; 156 152 template<typename T> inline constexpr bool IsConvertibleToColorComponents<T, std::void_t<decltype(asColorComponents(std::declval<T>()))>> = true; … … 163 159 template<typename T, typename U> inline constexpr bool HasComponentType = HasComponentTypeValue<T, U, HasComponentTypeMember<T>>; 164 160 165 template<typename T> inline constexpr bool IsColorType = HasColorSpaceMember<T> &&IsConvertibleToColorComponents<T> && HasComponentTypeMember<T>;166 template<typename T, typename U> inline constexpr bool IsColorTypeWithComponentType = HasColorSpaceMember<T> &&IsConvertibleToColorComponents<T> && HasComponentType<T, U>;161 template<typename T> inline constexpr bool IsColorType = IsConvertibleToColorComponents<T> && HasComponentTypeMember<T>; 162 template<typename T, typename U> inline constexpr bool IsColorTypeWithComponentType = IsConvertibleToColorComponents<T> && HasComponentType<T, U>; 167 163 168 164 template<typename Parent> struct ColorWithAlphaHelper { … … 229 225 using LinearCounterpart = LinearA98RGB<T>; 230 226 using ReferenceXYZ = XYZA<T, WhitePoint::D65>; 231 static constexpr auto colorSpace = ColorSpace::A98RGB;232 227 }; 233 228 template<typename T> A98RGB(T, T, T, T) -> A98RGB<T>; … … 237 232 using LinearCounterpart = LinearDisplayP3<T>; 238 233 using ReferenceXYZ = XYZA<T, WhitePoint::D65>; 239 static constexpr auto colorSpace = ColorSpace::DisplayP3;240 234 }; 241 235 template<typename T> DisplayP3(T, T, T, T) -> DisplayP3<T>; … … 287 281 using GammaEncodedCounterpart = SRGBA<T>; 288 282 using ReferenceXYZ = XYZA<T, WhitePoint::D65>; 289 static constexpr auto colorSpace = ColorSpace::LinearRGB;290 283 }; 291 284 template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>; … … 295 288 using LinearCounterpart = LinearProPhotoRGB<T>; 296 289 using ReferenceXYZ = XYZA<T, WhitePoint::D50>; 297 static constexpr auto colorSpace = ColorSpace::ProPhotoRGB;298 290 }; 299 291 template<typename T> ProPhotoRGB(T, T, T, T) -> ProPhotoRGB<T>; … … 303 295 using LinearCounterpart = LinearRec2020<T>; 304 296 using ReferenceXYZ = XYZA<T, WhitePoint::D65>; 305 static constexpr auto colorSpace { ColorSpace::Rec2020 };306 297 }; 307 298 template<typename T> Rec2020(T, T, T, T) -> Rec2020<T>; … … 311 302 using LinearCounterpart = LinearSRGBA<T>; 312 303 using ReferenceXYZ = XYZA<T, WhitePoint::D65>; 313 static constexpr auto colorSpace { ColorSpace::SRGB };314 304 }; 315 305 template<typename T> SRGBA(T, T, T, T) -> SRGBA<T>; … … 321 311 using Model = LabModel<T>; 322 312 using ReferenceXYZ = XYZA<T, WhitePoint::D50>; 323 static constexpr auto colorSpace = ColorSpace::Lab;324 313 325 314 constexpr Lab(T lightness, T a, T b, T alpha = AlphaTraits<T>::opaque) -
trunk/Source/WebCore/platform/graphics/ColorUtilities.h
r271695 r272311 172 172 } 173 173 174 template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>& color) 175 { 176 return color.y == 0 && color.alpha == AlphaTraits<float>::opaque; 177 } 178 174 179 constexpr bool isBlack(const Lab<float>& color) 175 180 { … … 183 188 constexpr auto ranges = ColorType::Model::ranges; 184 189 return c1 == ranges[0].min && c2 == ranges[1].min && c3 == ranges[2].min && alpha == AlphaTraits<typename ColorType::ComponentType>::opaque; 190 } 191 192 template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>& color) 193 { 194 return color.y == 1 && color.alpha == AlphaTraits<float>::opaque; 185 195 } 186 196 -
trunk/Source/WebCore/platform/graphics/ExtendedColor.h
r271089 r272311 67 67 template<typename ColorType> inline Ref<ExtendedColor> ExtendedColor::create(const ColorType& color) 68 68 { 69 return adoptRef(*new ExtendedColor(asColorComponents(color), color.colorSpace));69 return adoptRef(*new ExtendedColor(asColorComponents(color), ColorSpaceFor<ColorType>)); 70 70 } 71 71 -
trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp
r272125 r272311 149 149 } 150 150 151 CGColorSpaceRef xyzD50ColorSpaceRef() 152 { 153 static CGColorSpaceRef xyzD50ColorSpace; 154 static std::once_flag onceFlag; 155 std::call_once(onceFlag, [] { 156 #if PLATFORM(COCOA) 157 xyzD50ColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericXYZ); 158 #else 159 xyzD50ColorSpace = sRGBColorSpaceRef(); 160 #endif 161 }); 162 return xyzD50ColorSpace; 163 } 164 151 165 } 152 166 -
trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h
r272125 r272311 40 40 WEBCORE_EXPORT CGColorSpaceRef rec2020ColorSpaceRef(); 41 41 WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef(); 42 WEBCORE_EXPORT CGColorSpaceRef xyzD50ColorSpaceRef(); 42 43 43 44 static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace) … … 58 59 case ColorSpace::SRGB: 59 60 return sRGBColorSpaceRef(); 61 case ColorSpace::XYZ_D50: 62 return xyzD50ColorSpaceRef(); 60 63 } 61 64 ASSERT_NOT_REACHED();
Note: See TracChangeset
for help on using the changeset viewer.