Changeset 273211 in webkit
- Timestamp:
- Feb 20, 2021 4:47:59 PM (17 months ago)
- Location:
- trunk
- Files:
-
- 14 edited
-
LayoutTests/ChangeLog (modified) (1 diff)
-
LayoutTests/fast/css/parsing-lab-colors-expected.txt (modified) (2 diffs)
-
LayoutTests/fast/css/parsing-lab-colors.html (modified) (2 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp (modified) (4 diffs)
-
Source/WebCore/platform/graphics/Color.cpp (modified) (7 diffs)
-
Source/WebCore/platform/graphics/Color.h (modified) (20 diffs)
-
Source/WebCore/platform/graphics/ColorBlending.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/ColorSerialization.cpp (modified) (11 diffs)
-
Source/WebCore/platform/graphics/ColorUtilities.h (modified) (5 diffs)
-
Source/WebCore/platform/graphics/cg/ColorCG.cpp (modified) (1 diff)
-
Source/WebCore/platform/graphics/mac/ColorMac.mm (modified) (1 diff)
-
Source/WebCore/rendering/RenderThemeIOS.mm (modified) (2 diffs)
-
Source/WebCore/rendering/RenderThemeMac.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r273209 r273211 1 2021-02-20 Sam Weinig <weinig@apple.com> 2 3 color(lab ...) should serialize as color(lab ...) not lab() according to latest CSS Color 4 spec 4 https://bugs.webkit.org/show_bug.cgi?id=222110 5 6 Reviewed by Dean Jackson. 7 8 * fast/css/parsing-lab-colors-expected.txt: 9 * fast/css/parsing-lab-colors.html: 10 Update test and results for new serialization of color(lab ...). 11 1 12 2021-02-20 Jiewen Tan <jiewen_tan@apple.com> 2 13 -
trunk/LayoutTests/fast/css/parsing-lab-colors-expected.txt
r273078 r273211 1 Test the parsing of lab , lch and graycolors.1 Test the parsing of lab(...), lch(...) and color(lab ...) colors. 2 2 3 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". … … 41 41 42 42 color(lab ) 43 PASS computedStyle("background-color", "color(lab 0% 0 0)") is " lab(0% 0 0)"44 PASS computedStyle("background-color", "color(lab 0% 0 0 / 1)") is " lab(0% 0 0)"45 PASS computedStyle("background-color", "color(lab 0% 0 0 / 0.5)") is " lab(0% 0 0 / 0.5)"46 PASS computedStyle("background-color", "color(lab 20% 0 10/0.5)") is " lab(20% 0 10 / 0.5)"47 PASS computedStyle("background-color", "color(lab 20% 0 10/50%)") is " lab(20% 0 10 / 0.5)"48 PASS computedStyle("background-color", "color(lab 400% 0 10/50%)") is " lab(400% 0 10 / 0.5)"49 PASS computedStyle("background-color", "color(lab 50% -160 160)") is " lab(50% -160 160)"50 PASS computedStyle("background-color", "color(lab 50% -200 200)") is " lab(50% -200 200)"51 PASS computedStyle("background-color", "color(lab 0% 0 0 / -10%)") is " lab(0% 0 0 / 0)"52 PASS computedStyle("background-color", "color(lab 0% 0 0 / 110%)") is " lab(0% 0 0)"53 PASS computedStyle("background-color", "color(lab 0% 0 0 / 300%)") is " lab(0% 0 0)"54 PASS computedStyle("background-color", "color(lab 50% -200)") is " lab(50% -200 0)"55 PASS computedStyle("background-color", "color(lab 50%)") is " lab(50% 0 0)"56 PASS computedStyle("background-color", "color(lab)") is " lab(0% 0 0)"57 PASS computedStyle("background-color", "color(lab 50% -200 / 0.5)") is " lab(50% -200 0 / 0.5)"58 PASS computedStyle("background-color", "color(lab 50% / 0.5)") is " lab(50% 0 0 / 0.5)"59 PASS computedStyle("background-color", "color(lab / 0.5)") is " lab(0% 0 0 / 0.5)"60 PASS computedStyle("background-color", "color(lab -40% 0 0)") is " lab(0% 0 0)"61 PASS computedStyle("background-color", "color(lab 50% -20 0)") is " lab(50% -20 0)"62 PASS computedStyle("background-color", "color(lab 50% 0 -20)") is " lab(50% 0 -20)"43 PASS computedStyle("background-color", "color(lab 0% 0 0)") is "color(lab 0% 0 0)" 44 PASS computedStyle("background-color", "color(lab 0% 0 0 / 1)") is "color(lab 0% 0 0)" 45 PASS computedStyle("background-color", "color(lab 0% 0 0 / 0.5)") is "color(lab 0% 0 0 / 0.5)" 46 PASS computedStyle("background-color", "color(lab 20% 0 10/0.5)") is "color(lab 20% 0 10 / 0.5)" 47 PASS computedStyle("background-color", "color(lab 20% 0 10/50%)") is "color(lab 20% 0 10 / 0.5)" 48 PASS computedStyle("background-color", "color(lab 400% 0 10/50%)") is "color(lab 400% 0 10 / 0.5)" 49 PASS computedStyle("background-color", "color(lab 50% -160 160)") is "color(lab 50% -160 160)" 50 PASS computedStyle("background-color", "color(lab 50% -200 200)") is "color(lab 50% -200 200)" 51 PASS computedStyle("background-color", "color(lab 0% 0 0 / -10%)") is "color(lab 0% 0 0 / 0)" 52 PASS computedStyle("background-color", "color(lab 0% 0 0 / 110%)") is "color(lab 0% 0 0)" 53 PASS computedStyle("background-color", "color(lab 0% 0 0 / 300%)") is "color(lab 0% 0 0)" 54 PASS computedStyle("background-color", "color(lab 50% -200)") is "color(lab 50% -200 0)" 55 PASS computedStyle("background-color", "color(lab 50%)") is "color(lab 50% 0 0)" 56 PASS computedStyle("background-color", "color(lab)") is "color(lab 0% 0 0)" 57 PASS computedStyle("background-color", "color(lab 50% -200 / 0.5)") is "color(lab 50% -200 0 / 0.5)" 58 PASS computedStyle("background-color", "color(lab 50% / 0.5)") is "color(lab 50% 0 0 / 0.5)" 59 PASS computedStyle("background-color", "color(lab / 0.5)") is "color(lab 0% 0 0 / 0.5)" 60 PASS computedStyle("background-color", "color(lab -40% 0 0)") is "color(lab 0% 0 0)" 61 PASS computedStyle("background-color", "color(lab 50% -20 0)") is "color(lab 50% -20 0)" 62 PASS computedStyle("background-color", "color(lab 50% 0 -20)") is "color(lab 50% 0 -20)" 63 63 64 64 Test invalid values -
trunk/LayoutTests/fast/css/parsing-lab-colors.html
r273078 r273211 4 4 <body> 5 5 <script> 6 description("Test the parsing of lab , lch and graycolors.");6 description("Test the parsing of lab(...), lch(...) and color(lab ...) colors."); 7 7 8 8 function computedStyle(property, value) … … 75 75 debug(''); 76 76 debug('color(lab )'); 77 testComputed("background-color", "color(lab 0% 0 0)", " lab(0% 0 0)");78 testComputed("background-color", "color(lab 0% 0 0 / 1)", " lab(0% 0 0)");79 testComputed("background-color", "color(lab 0% 0 0 / 0.5)", " lab(0% 0 0 / 0.5)");80 testComputed("background-color", "color(lab 20% 0 10/0.5)", " lab(20% 0 10 / 0.5)");81 testComputed("background-color", "color(lab 20% 0 10/50%)", " lab(20% 0 10 / 0.5)");82 testComputed("background-color", "color(lab 400% 0 10/50%)", " lab(400% 0 10 / 0.5)");83 testComputed("background-color", "color(lab 50% -160 160)", " lab(50% -160 160)");84 testComputed("background-color", "color(lab 50% -200 200)", " lab(50% -200 200)");85 testComputed("background-color", "color(lab 0% 0 0 / -10%)", " lab(0% 0 0 / 0)");86 testComputed("background-color", "color(lab 0% 0 0 / 110%)", " lab(0% 0 0)");87 testComputed("background-color", "color(lab 0% 0 0 / 300%)", " lab(0% 0 0)");88 testComputed("background-color", "color(lab 50% -200)", " lab(50% -200 0)");89 testComputed("background-color", "color(lab 50%)", " lab(50% 0 0)");90 testComputed("background-color", "color(lab)", " lab(0% 0 0)");91 testComputed("background-color", "color(lab 50% -200 / 0.5)", " lab(50% -200 0 / 0.5)");92 testComputed("background-color", "color(lab 50% / 0.5)", " lab(50% 0 0 / 0.5)");93 testComputed("background-color", "color(lab / 0.5)", " lab(0% 0 0 / 0.5)");94 testComputed("background-color", "color(lab -40% 0 0)", " lab(0% 0 0)");95 testComputed("background-color", "color(lab 50% -20 0)", " lab(50% -20 0)");96 testComputed("background-color", "color(lab 50% 0 -20)", " lab(50% 0 -20)");77 testComputed("background-color", "color(lab 0% 0 0)", "color(lab 0% 0 0)"); 78 testComputed("background-color", "color(lab 0% 0 0 / 1)", "color(lab 0% 0 0)"); 79 testComputed("background-color", "color(lab 0% 0 0 / 0.5)", "color(lab 0% 0 0 / 0.5)"); 80 testComputed("background-color", "color(lab 20% 0 10/0.5)", "color(lab 20% 0 10 / 0.5)"); 81 testComputed("background-color", "color(lab 20% 0 10/50%)", "color(lab 20% 0 10 / 0.5)"); 82 testComputed("background-color", "color(lab 400% 0 10/50%)", "color(lab 400% 0 10 / 0.5)"); 83 testComputed("background-color", "color(lab 50% -160 160)", "color(lab 50% -160 160)"); 84 testComputed("background-color", "color(lab 50% -200 200)", "color(lab 50% -200 200)"); 85 testComputed("background-color", "color(lab 0% 0 0 / -10%)", "color(lab 0% 0 0 / 0)"); 86 testComputed("background-color", "color(lab 0% 0 0 / 110%)", "color(lab 0% 0 0)"); 87 testComputed("background-color", "color(lab 0% 0 0 / 300%)", "color(lab 0% 0 0)"); 88 testComputed("background-color", "color(lab 50% -200)", "color(lab 50% -200 0)"); 89 testComputed("background-color", "color(lab 50%)", "color(lab 50% 0 0)"); 90 testComputed("background-color", "color(lab)", "color(lab 0% 0 0)"); 91 testComputed("background-color", "color(lab 50% -200 / 0.5)", "color(lab 50% -200 0 / 0.5)"); 92 testComputed("background-color", "color(lab 50% / 0.5)", "color(lab 50% 0 0 / 0.5)"); 93 testComputed("background-color", "color(lab / 0.5)", "color(lab 0% 0 0 / 0.5)"); 94 testComputed("background-color", "color(lab -40% 0 0)", "color(lab 0% 0 0)"); 95 testComputed("background-color", "color(lab 50% -20 0)", "color(lab 50% -20 0)"); 96 testComputed("background-color", "color(lab 50% 0 -20)", "color(lab 50% 0 -20)"); 97 97 98 98 debug(''); -
trunk/Source/WebCore/ChangeLog
r273210 r273211 1 2021-02-20 Sam Weinig <weinig@apple.com> 2 3 color(lab ...) should serialize as color(lab ...) not lab() according to latest CSS Color 4 spec 4 https://bugs.webkit.org/show_bug.cgi?id=222110 5 6 Reviewed by Dean Jackson. 7 8 To make this work it was necessary to make it so that extended colors, like Lab, 9 could store an extra bit of data on Color to indicate that it should use the 10 color() function for serialization when parsed using the color() form. 11 12 To do that, Color was reworked to allow extra metadata flags for both inline and 13 extended colors. Previously, only inline colors could make use of the extra bits. 14 Now, we take advantage of the fact that we have the high 16 bits available to us 15 for pointers to also store that metadata for extended colors. Rather than using a 16 union, we encode the pointer / inline color into a uint64_t, and use the extra bits 17 for the flags we need. Currently we only use 6, so there is quite a bit more that 18 could be used here. 19 20 Finally, the color serialization code has been updated to check for the new bit, 21 called UseColorFunctionSerialization, and to serialize using color() notation 22 if it is set. 23 24 We are currently only taking advantage of this for differentiating between lab(...) 25 and color(lab ...), but in the future we should be able to also optimize color(srgb ...) 26 values that can be represented fully by SRGBA<uint8_t>. 27 28 Since we can now add flags for extended colors, the semantic bit is also now usable 29 for extended colors, though none currently exist. 30 31 * css/parser/CSSPropertyParserHelpers.cpp: 32 (WebCore::CSSPropertyParserHelpers::parseColorFunctionForRGBTypes): 33 (WebCore::CSSPropertyParserHelpers::parseColorFunctionForLabParameters): 34 (WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZParameters): 35 (WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters): 36 * platform/graphics/Color.cpp: 37 (WebCore::Color::Color): 38 (WebCore::Color::operator=): 39 (WebCore::Color::colorWithAlpha const): 40 (WebCore::Color::semanticColor const): 41 * platform/graphics/Color.h: 42 (WebCore::Color::isHashTableDeletedValue const): 43 (WebCore::Color::Color): 44 (WebCore::Color::toAllFlags): 45 (WebCore::Color::setColor): 46 (WebCore::Color::setExtendedColor): 47 (WebCore::operator==): 48 (WebCore::extendedColorsEqual): 49 (WebCore::extendedColorsEqualIgnoringSemanticColor): 50 (WebCore::equalIgnoringSemanticColor): 51 (WebCore::Color::~Color): 52 (WebCore::Color::hash const): 53 (WebCore::Color::isValid const): 54 (WebCore::Color::isSemantic const): 55 (WebCore::Color::usesColorFunctionSerialization const): 56 (WebCore::Color::flags const): 57 (WebCore::Color::isExtended const): 58 (WebCore::Color::isInline const): 59 (WebCore::Color::asExtended const): 60 (WebCore::Color::asExtendedRef const): 61 (WebCore::Color::asInline const): 62 (WebCore::Color::asPackedInline const): 63 (WebCore::Color::encodedFlags): 64 (WebCore::Color::encodedInlineColor): 65 (WebCore::Color::encodedPackedInlineColor): 66 (WebCore::Color::encodedExtendedColor): 67 (WebCore::Color::decodedFlags): 68 (WebCore::Color::decodedInlineColor): 69 (WebCore::Color::decodedPackedInlineColor): 70 (WebCore::Color::decodedExtendedColor): 71 (WebCore::Color::setInvalid): 72 (WebCore::Color::encode const): 73 (WebCore::Color::decode): 74 (WebCore::Color::tagAsSemantic): Deleted. 75 (WebCore::Color::tagAsValid): Deleted. 76 * platform/graphics/ColorBlending.cpp: 77 (WebCore::blendWithWhite): 78 * platform/graphics/ColorSerialization.cpp: 79 (WebCore::serializationForCSS): 80 (WebCore::serializationForHTML): 81 (WebCore::serializationForRenderTreeAsText): 82 (WebCore::serializationUsingColorFunction): 83 * platform/graphics/cg/ColorCG.cpp: 84 (WebCore::Color::Color): 85 * platform/graphics/mac/ColorMac.mm: 86 (WebCore::semanticColorFromNSColor): 87 * rendering/RenderThemeIOS.mm: 88 (WebCore::systemColorFromCSSValueIDSelector): 89 (WebCore::systemColorFromCSSValueID): 90 * rendering/RenderThemeMac.mm: 91 (WebCore::RenderThemeMac::systemColor const): 92 1 93 2021-02-20 Simon Fraser <simon.fraser@apple.com> 2 94 -
trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
r273127 r273211 1372 1372 return { }; 1373 1373 1374 return ColorType { clampTo<float>(channels[0], 0.0, 1.0), clampTo<float>(channels[1], 0.0, 1.0), clampTo<float>(channels[2], 0.0, 1.0), static_cast<float>(*alpha)};1374 return { ColorType { clampTo<float>(channels[0], 0.0, 1.0), clampTo<float>(channels[1], 0.0, 1.0), clampTo<float>(channels[2], 0.0, 1.0), static_cast<float>(*alpha) }, Color::Flags::UseColorFunctionSerialization }; 1375 1375 } 1376 1376 … … 1404 1404 auto normalizedLightness = std::max(0.0, channels[0]); 1405 1405 1406 return Lab<float> { static_cast<float>(normalizedLightness), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha)};1406 return { Lab<float> { static_cast<float>(normalizedLightness), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) }, Color::Flags::UseColorFunctionSerialization }; 1407 1407 } 1408 1408 … … 1434 1434 return { }; 1435 1435 1436 return XYZA<float, WhitePoint::D50> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha)};1436 return { XYZA<float, WhitePoint::D50> { static_cast<float>(channels[0]), static_cast<float>(channels[1]), static_cast<float>(channels[2]), static_cast<float>(*alpha) }, Color::Flags::UseColorFunctionSerialization }; 1437 1437 } 1438 1438 … … 1477 1477 return { }; 1478 1478 1479 ASSERT(color.usesColorFunctionSerialization()); 1479 1480 return color; 1480 1481 } -
trunk/Source/WebCore/platform/graphics/Color.cpp
r272731 r273211 1 1 /* 2 * Copyright (C) 2003-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2003-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 38 38 39 39 Color::Color(const Color& other) 40 : m_color Data(other.m_colorData)40 : m_colorAndFlags(other.m_colorAndFlags) 41 41 { 42 42 if (isExtended()) 43 m_colorData.extendedColor->ref();43 asExtended().ref(); 44 44 } 45 45 … … 55 55 56 56 if (isExtended()) 57 m_colorData.extendedColor->deref();57 asExtended().deref(); 58 58 59 m_color Data = other.m_colorData;59 m_colorAndFlags = other.m_colorAndFlags; 60 60 61 61 if (isExtended()) 62 m_colorData.extendedColor->ref(); 62 asExtended().ref(); 63 63 64 return *this; 64 65 } … … 70 71 71 72 if (isExtended()) 72 m_colorData.extendedColor->deref();73 asExtended().deref(); 73 74 74 m_color Data = other.m_colorData;75 other.m_color Data.inlineColorAndFlags = invalidInlineColor;75 m_colorAndFlags = other.m_colorAndFlags; 76 other.m_colorAndFlags = invalidColorAndFlags; 76 77 77 78 return *this; … … 124 125 Color Color::colorWithAlpha(float alpha) const 125 126 { 126 return callOnUnderlyingType(WTF::makeVisitor( 127 [&] (const SRGBA<uint8_t>& underlyingColor) -> Color { 128 Color result = colorWithOverridenAlpha(underlyingColor, alpha); 127 return callOnUnderlyingType([&] (const auto& underlyingColor) -> Color { 128 auto result = colorWithOverriddenAlpha(underlyingColor, alpha); 129 129 130 // FIXME: Why is preserving the semantic bit desired and/or correct here? 131 if (isSemantic()) 132 result.tagAsSemantic(); 133 return result; 134 }, 135 [&] (const auto& underlyingColor) -> Color { 136 return colorWithOverridenAlpha(underlyingColor, alpha); 137 } 138 )); 130 // FIXME: Why is preserving the semantic bit desired and/or correct here? 131 if (isSemantic()) 132 return { result, Flags::Semantic }; 133 134 return { result }; 135 }); 139 136 } 140 137 … … 148 145 // of alternatives. 149 146 if constexpr (ColorType::Model::isInvertible) 150 return inverted ColorWithOverridenAlpha(underlyingColor, alpha);147 return invertedcolorWithOverriddenAlpha(underlyingColor, alpha); 151 148 else 152 return inverted ColorWithOverridenAlpha(convertColor<SRGBA<float>>(underlyingColor), alpha);149 return invertedcolorWithOverriddenAlpha(convertColor<SRGBA<float>>(underlyingColor), alpha); 153 150 }); 154 151 } … … 158 155 if (isSemantic()) 159 156 return *this; 160 161 return { toSRGBALossy<uint8_t>(), Semantic }; 157 158 if (isExtended()) 159 return { asExtendedRef(), Flags::Semantic }; 160 return { asInline(), Flags::Semantic }; 162 161 } 163 162 -
trunk/Source/WebCore/platform/graphics/Color.h
r272436 r273211 1 1 /* 2 * Copyright (C) 2003-202 0Apple Inc. All rights reserved.2 * Copyright (C) 2003-2021 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 32 32 #include <wtf/HashFunctions.h> 33 33 #include <wtf/Hasher.h> 34 #include <wtf/OptionSet.h> 34 35 #include <wtf/Optional.h> 36 #include <wtf/StdLibExtras.h> 35 37 36 38 #if USE(CG) … … 57 59 // - 4x 8-bit (0-255) sRGBA, stored inline, no allocation 58 60 // - 4x float color components + color space, stored in a reference counted sub-object 59 //60 // Additionally, the inline 8-bit sRGBA can have an optional "semantic" bit set on it,61 // which indicates the color originated from a CSS semantic color name.62 // FIXME: If we keep the "semantic" bit on Color, we should extend support to all colors,63 // not just inline ones, by using the unused pointer bits.64 61 65 62 class Color { 66 63 WTF_MAKE_FAST_ALLOCATED; 67 64 public: 65 enum class Flags { 66 Semantic = 1 << 0, 67 UseColorFunctionSerialization = 1 << 1, 68 }; 69 68 70 Color() = default; 69 71 70 Color(SRGBA<uint8_t>); 71 Color(Optional<SRGBA<uint8_t>>); 72 73 enum SemanticTag { Semantic }; 74 Color(SRGBA<uint8_t>, SemanticTag); 75 Color(Optional<SRGBA<uint8_t>>, SemanticTag); 76 77 Color(ColorComponents<float>, ColorSpace); 78 72 Color(SRGBA<uint8_t>, OptionSet<Flags> = { }); 73 Color(Optional<SRGBA<uint8_t>>, OptionSet<Flags> = { }); 74 75 Color(ColorComponents<float>, ColorSpace, OptionSet<Flags> = { }); 79 76 template<typename ColorType, typename std::enable_if_t<IsColorTypeWithComponentType<ColorType, float>>* = nullptr> 80 Color(const ColorType& );77 Color(const ColorType&, OptionSet<Flags> = { }); 81 78 82 79 explicit Color(WTF::HashTableEmptyValueType); 83 80 explicit Color(WTF::HashTableDeletedValueType); 84 bool isHashTableDeletedValue() const { return m_colorData.inlineColorAndFlags == deletedHashValue; }81 bool isHashTableDeletedValue() const; 85 82 86 83 WEBCORE_EXPORT Color(const Color&); … … 94 91 unsigned hash() const; 95 92 96 bool isValid() const { return isExtended() || (m_colorData.inlineColorAndFlags & validInlineColorBit); } 97 bool isSemantic() const { return isInline() && (m_colorData.inlineColorAndFlags & isSemanticInlineColorBit); } 93 bool isValid() const; 94 bool isSemantic() const; 95 bool usesColorFunctionSerialization() const; 98 96 99 97 bool isOpaque() const { return isExtended() ? asExtended().alpha() == 1.0 : asInline().alpha == 255; } … … 141 139 #if USE(CG) 142 140 WEBCORE_EXPORT Color(CGColorRef); 143 WEBCORE_EXPORT Color(CGColorRef, SemanticTag);141 WEBCORE_EXPORT Color(CGColorRef, OptionSet<Flags>); 144 142 #endif 145 143 … … 165 163 static constexpr auto orange = SRGBA<uint8_t> { 255, 128, 0 }; 166 164 167 bool isExtended() const { return !(m_colorData.inlineColorAndFlags & invalidInlineColor); }168 bool isInline() const { return !isExtended(); }165 bool isExtended() const; 166 bool isInline() const; 169 167 170 168 const ExtendedColor& asExtended() const; … … 175 173 friend bool equalIgnoringSemanticColor(const Color& a, const Color& b); 176 174 friend bool extendedColorsEqual(const Color&, const Color&); 175 friend bool extendedColorsEqualIgnoringSemanticColor(const Color&, const Color&); 177 176 178 177 static bool isBlackColor(const Color&); … … 183 182 184 183 private: 185 Color(Ref<ExtendedColor>&&); 186 187 void setColor(SRGBA<uint8_t>); 188 void setExtendedColor(Ref<ExtendedColor>&&); 189 190 void tagAsSemantic() { m_colorData.inlineColorAndFlags |= isSemanticInlineColorBit; } 191 void tagAsValid() { m_colorData.inlineColorAndFlags |= validInlineColor; } 192 193 // 0x_______00 is an ExtendedColor pointer. 194 // 0x_______01 is an invalid inline color. 195 // 0x_______11 is a valid inline color. 196 static const uint64_t extendedColor = 0x0; 197 static const uint64_t invalidInlineColor = 0x1; 198 static const uint64_t validInlineColorBit = 0x2; 199 static const uint64_t validInlineColor = 0x3; 200 static const uint64_t isSemanticInlineColorBit = 0x4; 201 202 static const uint64_t deletedHashValue = 0xFFFFFFFFFFFFFFFD; 203 static const uint64_t emptyHashValue = 0xFFFFFFFFFFFFFFFB; 204 205 union { 206 uint64_t inlineColorAndFlags { invalidInlineColor }; 207 ExtendedColor* extendedColor; 208 } m_colorData; 184 Color(Ref<ExtendedColor>&&, OptionSet<Flags> = { }); 185 186 enum class FlagsIncludingPrivate : uint16_t { 187 Semantic = static_cast<uint16_t>(Flags::Semantic), 188 UseColorFunctionSerialization = static_cast<uint16_t>(Flags::UseColorFunctionSerialization), 189 Valid = 1 << 2, 190 Extended = 1 << 3, 191 HashTableEmptyValue = 1 << 4, 192 HashTableDeletedValue = 1 << 5, 193 }; 194 static OptionSet<FlagsIncludingPrivate> toFlagsIncludingPrivate(OptionSet<Flags> flags) { return OptionSet<FlagsIncludingPrivate>::fromRaw(flags.toRaw()); } 195 196 OptionSet<FlagsIncludingPrivate> flags() const; 197 198 void setColor(SRGBA<uint8_t>, OptionSet<FlagsIncludingPrivate> = { }); 199 void setExtendedColor(Ref<ExtendedColor>&&, OptionSet<FlagsIncludingPrivate> = { }); 200 201 PackedColor::RGBA asPackedInline() const; 202 Ref<ExtendedColor> asExtendedRef() const; 203 204 #if CPU(ADDRESS64) 205 static constexpr unsigned maxNumberOfBitsInPointer = 48; 206 #else 207 static constexpr unsigned maxNumberOfBitsInPointer = 32; 208 #endif 209 static constexpr uint64_t colorValueMask = (1ULL << maxNumberOfBitsInPointer) - 1; 210 211 static uint64_t encodedFlags(OptionSet<FlagsIncludingPrivate>); 212 static uint64_t encodedInlineColor(SRGBA<uint8_t>); 213 static uint64_t encodedPackedInlineColor(PackedColor::RGBA); 214 static uint64_t encodedExtendedColor(Ref<ExtendedColor>&&); 215 216 static OptionSet<FlagsIncludingPrivate> decodedFlags(uint64_t); 217 static SRGBA<uint8_t> decodedInlineColor(uint64_t); 218 static PackedColor::RGBA decodedPackedInlineColor(uint64_t); 219 static ExtendedColor& decodedExtendedColor(uint64_t); 220 221 static constexpr uint64_t invalidColorAndFlags = 0; 222 uint64_t m_colorAndFlags { invalidColorAndFlags }; 209 223 }; 210 224 … … 214 228 // One or both must be extended colors. 215 229 bool extendedColorsEqual(const Color&, const Color&); 230 bool extendedColorsEqualIgnoringSemanticColor(const Color&, const Color&); 216 231 217 232 #if USE(CG) … … 225 240 if (a.isExtended() || b.isExtended()) 226 241 return extendedColorsEqual(a, b); 227 228 return a.m_colorData.inlineColorAndFlags == b.m_colorData.inlineColorAndFlags; 242 return a.m_colorAndFlags == b.m_colorAndFlags; 229 243 } 230 244 … … 237 251 { 238 252 if (a.isExtended() && b.isExtended()) 239 return a.asExtended() == b.asExtended() ;253 return a.asExtended() == b.asExtended() && a.flags() == b.flags(); 240 254 241 255 ASSERT(a.isExtended() || b.isExtended()); … … 243 257 } 244 258 259 inline bool extendedColorsEqualIgnoringSemanticColor(const Color& a, const Color& b) 260 { 261 if (a.isExtended() && b.isExtended()) { 262 auto aFlags = a.flags() - Color::FlagsIncludingPrivate::Semantic; 263 auto bFlags = b.flags() - Color::FlagsIncludingPrivate::Semantic; 264 return a.asExtended() == b.asExtended() && aFlags == bFlags; 265 } 266 267 ASSERT(a.isExtended() || b.isExtended()); 268 return false; 269 } 270 245 271 inline bool equalIgnoringSemanticColor(const Color& a, const Color& b) 246 272 { 247 273 if (a.isExtended() || b.isExtended()) 248 return extendedColorsEqual(a, b); 249 return (a.m_colorData.inlineColorAndFlags & ~Color::isSemanticInlineColorBit) == (b.m_colorData.inlineColorAndFlags & ~Color::isSemanticInlineColorBit); 250 } 251 252 inline Color::Color(SRGBA<uint8_t> color) 253 { 254 setColor(color); 255 } 256 257 inline Color::Color(Optional<SRGBA<uint8_t>> color) 274 return extendedColorsEqualIgnoringSemanticColor(a, b); 275 276 auto aFlags = a.flags() - Color::FlagsIncludingPrivate::Semantic; 277 auto bFlags = b.flags() - Color::FlagsIncludingPrivate::Semantic; 278 return a.asPackedInline().value == b.asPackedInline().value && aFlags == bFlags; 279 } 280 281 inline Color::Color(SRGBA<uint8_t> color, OptionSet<Flags> flags) 282 { 283 setColor(color, toFlagsIncludingPrivate(flags)); 284 } 285 286 inline Color::Color(Optional<SRGBA<uint8_t>> color, OptionSet<Flags> flags) 258 287 { 259 288 if (color) 260 setColor(*color); 261 } 262 263 inline Color::Color(SRGBA<uint8_t> color, SemanticTag) 264 { 265 setColor(color); 266 tagAsSemantic(); 267 } 268 269 inline Color::Color(Optional<SRGBA<uint8_t>> color, SemanticTag) 270 { 271 if (color) { 272 setColor(*color); 273 tagAsSemantic(); 274 } 275 } 276 277 inline Color::Color(ColorComponents<float> components, ColorSpace colorSpace) 278 { 279 setExtendedColor(ExtendedColor::create(components, colorSpace)); 289 setColor(*color, toFlagsIncludingPrivate(flags)); 290 } 291 292 inline Color::Color(ColorComponents<float> components, ColorSpace colorSpace, OptionSet<Flags> flags) 293 { 294 setExtendedColor(ExtendedColor::create(components, colorSpace), toFlagsIncludingPrivate(flags)); 280 295 } 281 296 282 297 template<typename ColorType, typename std::enable_if_t<IsColorTypeWithComponentType<ColorType, float>>*> 283 inline Color::Color(const ColorType& color) 284 { 285 setExtendedColor(ExtendedColor::create(color)); 286 } 287 288 inline Color::Color(Ref<ExtendedColor>&& extendedColor) 289 { 290 setExtendedColor(WTFMove(extendedColor)); 298 inline Color::Color(const ColorType& color, OptionSet<Flags> flags) 299 { 300 setExtendedColor(ExtendedColor::create(color), toFlagsIncludingPrivate(flags)); 301 } 302 303 inline Color::Color(Ref<ExtendedColor>&& extendedColor, OptionSet<Flags> flags) 304 { 305 setExtendedColor(WTFMove(extendedColor), toFlagsIncludingPrivate(flags)); 306 } 307 308 inline Color::Color(WTF::HashTableEmptyValueType) 309 { 310 m_colorAndFlags = encodedFlags({ FlagsIncludingPrivate::HashTableEmptyValue }); 291 311 } 292 312 293 313 inline Color::Color(WTF::HashTableDeletedValueType) 294 314 { 295 static_assert(deletedHashValue & invalidInlineColor, "Color's deleted hash value must not look like an ExtendedColor"); 296 static_assert(!(deletedHashValue & validInlineColorBit), "Color's deleted hash value must not look like a valid InlineColor"); 297 static_assert(deletedHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an InlineColor wouldn't have"); 298 m_colorData.inlineColorAndFlags = deletedHashValue; 299 ASSERT(!isExtended()); 300 } 301 302 inline Color::Color(WTF::HashTableEmptyValueType) 303 { 304 static_assert(emptyHashValue & invalidInlineColor, "Color's empty hash value must not look like an ExtendedColor"); 305 static_assert(emptyHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an InlineColor wouldn't have"); 306 m_colorData.inlineColorAndFlags = emptyHashValue; 307 ASSERT(!isExtended()); 315 m_colorAndFlags = encodedFlags({ FlagsIncludingPrivate::HashTableDeletedValue }); 316 } 317 318 inline bool Color::isHashTableDeletedValue() const 319 { 320 return flags().contains(FlagsIncludingPrivate::HashTableDeletedValue); 308 321 } 309 322 … … 311 324 { 312 325 if (isExtended()) 313 m_colorData.extendedColor->deref();326 asExtended().deref(); 314 327 } 315 328 … … 317 330 { 318 331 if (isExtended()) 319 return computeHash(asExtended().components(), asExtended().colorSpace()); 320 return WTF::intHash(m_colorData.inlineColorAndFlags); 332 return computeHash(asExtended().components(), asExtended().colorSpace(), flags().toRaw()); 333 return computeHash(asPackedInline().value, flags().toRaw()); 334 } 335 336 inline bool Color::isValid() const 337 { 338 return flags().contains(FlagsIncludingPrivate::Valid); 339 } 340 341 inline bool Color::isSemantic() const 342 { 343 return flags().contains(FlagsIncludingPrivate::Semantic); 344 } 345 346 inline bool Color::usesColorFunctionSerialization() const 347 { 348 return flags().contains(FlagsIncludingPrivate::UseColorFunctionSerialization); 321 349 } 322 350 … … 355 383 } 356 384 385 inline OptionSet<Color::FlagsIncludingPrivate> Color::flags() const 386 { 387 return decodedFlags(m_colorAndFlags); 388 } 389 390 inline bool Color::isExtended() const 391 { 392 return flags().contains(FlagsIncludingPrivate::Extended); 393 } 394 395 inline bool Color::isInline() const 396 { 397 return !flags().contains(FlagsIncludingPrivate::Extended); 398 } 399 357 400 inline const ExtendedColor& Color::asExtended() const 358 401 { 359 402 ASSERT(isExtended()); 360 return *m_colorData.extendedColor; 403 return decodedExtendedColor(m_colorAndFlags); 404 } 405 406 inline Ref<ExtendedColor> Color::asExtendedRef() const 407 { 408 ASSERT(isExtended()); 409 return decodedExtendedColor(m_colorAndFlags); 361 410 } 362 411 … … 364 413 { 365 414 ASSERT(isInline()); 366 return asSRGBA(PackedColor::RGBA { static_cast<uint32_t>(m_colorData.inlineColorAndFlags >> 32) }); 367 } 368 369 inline void Color::setColor(SRGBA<uint8_t> color) 370 { 371 m_colorData.inlineColorAndFlags = static_cast<uint64_t>(PackedColor::RGBA { color }.value) << 32; 372 tagAsValid(); 373 } 374 375 inline void Color::setExtendedColor(Ref<ExtendedColor>&& extendedColor) 376 { 377 // Zero the union, just in case a 32-bit system only assigns the 378 // top 32 bits when copying the ExtendedColor pointer below. 379 m_colorData.inlineColorAndFlags = 0; 380 m_colorData.extendedColor = &extendedColor.leakRef(); 415 return asSRGBA(asPackedInline()); 416 } 417 418 inline PackedColor::RGBA Color::asPackedInline() const 419 { 420 ASSERT(isInline()); 421 return decodedPackedInlineColor(m_colorAndFlags); 422 } 423 424 inline uint64_t Color::encodedFlags(OptionSet<FlagsIncludingPrivate> flags) 425 { 426 return static_cast<uint64_t>(flags.toRaw()) << maxNumberOfBitsInPointer; 427 } 428 429 inline uint64_t Color::encodedInlineColor(SRGBA<uint8_t> color) 430 { 431 return encodedPackedInlineColor(PackedColor::RGBA { color }); 432 } 433 434 inline uint64_t Color::encodedPackedInlineColor(PackedColor::RGBA color) 435 { 436 return color.value; 437 } 438 439 inline uint64_t Color::encodedExtendedColor(Ref<ExtendedColor>&& extendedColor) 440 { 441 #if CPU(ADDRESS64) 442 return bitwise_cast<uint64_t>(&extendedColor.leakRef()); 443 #else 444 return bitwise_cast<uint32_t>(&extendedColor.leakRef()); 445 #endif 446 } 447 448 inline OptionSet<Color::FlagsIncludingPrivate> Color::decodedFlags(uint64_t value) 449 { 450 return OptionSet<Color::FlagsIncludingPrivate>::fromRaw(static_cast<unsigned>(value >> maxNumberOfBitsInPointer)); 451 } 452 453 inline SRGBA<uint8_t> Color::decodedInlineColor(uint64_t value) 454 { 455 return asSRGBA(decodedPackedInlineColor(value)); 456 } 457 458 inline PackedColor::RGBA Color::decodedPackedInlineColor(uint64_t value) 459 { 460 return PackedColor::RGBA { static_cast<uint32_t>(value & colorValueMask) }; 461 } 462 463 inline ExtendedColor& Color::decodedExtendedColor(uint64_t value) 464 { 465 #if CPU(ADDRESS64) 466 return *bitwise_cast<ExtendedColor*>(value & colorValueMask); 467 #else 468 return *bitwise_cast<ExtendedColor*>(static_cast<uint32_t>(value & colorValueMask)); 469 #endif 470 } 471 472 inline void Color::setColor(SRGBA<uint8_t> color, OptionSet<FlagsIncludingPrivate> flags) 473 { 474 flags.add({ FlagsIncludingPrivate::Valid }); 475 m_colorAndFlags = encodedInlineColor(color) | encodedFlags(flags); 476 ASSERT(isInline()); 477 } 478 479 inline void Color::setExtendedColor(Ref<ExtendedColor>&& color, OptionSet<FlagsIncludingPrivate> flags) 480 { 481 flags.add({ FlagsIncludingPrivate::Valid, FlagsIncludingPrivate::Extended }); 482 m_colorAndFlags = encodedExtendedColor(WTFMove(color)) | encodedFlags(flags); 381 483 ASSERT(isExtended()); 382 484 } … … 398 500 template<class Encoder> void Color::encode(Encoder& encoder) const 399 501 { 502 if (!isValid()) { 503 encoder << false; 504 return; 505 } 506 encoder << true; 507 508 encoder << flags().contains(FlagsIncludingPrivate::Semantic); 509 encoder << flags().contains(FlagsIncludingPrivate::UseColorFunctionSerialization); 510 400 511 if (isExtended()) { 401 512 encoder << true; … … 410 521 return; 411 522 } 412 413 523 encoder << false; 414 524 415 if (!isValid()) { 416 encoder << false; 417 return; 418 } 419 420 // FIXME: This should encode whether the color is semantic. 421 422 encoder << true; 423 encoder << PackedColor::RGBA { asInline() }.value; 525 encoder << asPackedInline().value; 424 526 } 425 527 426 528 template<class Decoder> Optional<Color> Color::decode(Decoder& decoder) 427 529 { 530 bool isValid; 531 if (!decoder.decode(isValid)) 532 return WTF::nullopt; 533 534 if (!isValid) 535 return Color { }; 536 537 OptionSet<Flags> flags; 538 539 bool isSemantic; 540 if (!decoder.decode(isSemantic)) 541 return WTF::nullopt; 542 543 if (isSemantic) 544 flags.add(Flags::Semantic); 545 546 bool usesColorFunctionSerialization; 547 if (!decoder.decode(usesColorFunctionSerialization)) 548 return WTF::nullopt; 549 550 if (usesColorFunctionSerialization) 551 flags.add(Flags::UseColorFunctionSerialization); 552 428 553 bool isExtended; 429 554 if (!decoder.decode(isExtended)) … … 446 571 if (!decoder.decode(colorSpace)) 447 572 return WTF::nullopt; 448 return Color { ExtendedColor::create({ c1, c2, c3, alpha }, colorSpace) };573 return Color { ExtendedColor::create({ c1, c2, c3, alpha }, colorSpace), flags }; 449 574 } 450 451 bool isValid;452 if (!decoder.decode(isValid))453 return WTF::nullopt;454 455 if (!isValid)456 return Color { };457 575 458 576 uint32_t value; … … 460 578 return WTF::nullopt; 461 579 462 return Color { asSRGBA(PackedColor::RGBA { value }) };580 return Color { asSRGBA(PackedColor::RGBA { value }), flags }; 463 581 } 464 582 -
trunk/Source/WebCore/platform/graphics/ColorBlending.cpp
r271695 r273211 87 87 // FIXME: Why is preserving the semantic bit desired and/or correct here? 88 88 if (color.isSemantic()) 89 return Color(result, Color::Semantic);89 return { result, Color::Flags::Semantic }; 90 90 return result; 91 91 } -
trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp
r273078 r273211 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 LCHA<float>& );48 static String serializationForHTML(const LCHA<float>& );49 static String serializationForRenderTreeAsText(const LCHA<float>& );50 51 static String serializationForCSS(const Lab<float>& );52 static String serializationForHTML(const Lab<float>& );53 static String serializationForRenderTreeAsText(const Lab<float>& );54 55 static String serializationForCSS(const LinearSRGBA<float>& );56 static String serializationForHTML(const LinearSRGBA<float>& );57 static String serializationForRenderTreeAsText(const LinearSRGBA<float>& );58 59 static String serializationForCSS(const ProPhotoRGB<float>& );60 static String serializationForHTML(const ProPhotoRGB<float>& );61 static String serializationForRenderTreeAsText(const ProPhotoRGB<float>& );62 63 static String serializationForCSS(const Rec2020<float>& );64 static String serializationForHTML(const Rec2020<float>& );65 static String serializationForRenderTreeAsText(const Rec2020<float>& );66 67 static String serializationForCSS(const SRGBA<float>& );68 static String serializationForHTML(const SRGBA<float>& );69 static String serializationForRenderTreeAsText(const SRGBA<float>& );70 71 static String serializationForCSS(SRGBA<uint8_t> );72 static String serializationForHTML(SRGBA<uint8_t> );73 static String serializationForRenderTreeAsText(SRGBA<uint8_t> );74 75 static String serializationForCSS(const XYZA<float, WhitePoint::D50>& );76 static String serializationForHTML(const XYZA<float, WhitePoint::D50>& );77 static String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>& );39 static String serializationForCSS(const A98RGB<float>&, bool useColorFunctionSerialization); 40 static String serializationForHTML(const A98RGB<float>&, bool useColorFunctionSerialization); 41 static String serializationForRenderTreeAsText(const A98RGB<float>&, bool useColorFunctionSerialization); 42 43 static String serializationForCSS(const DisplayP3<float>&, bool useColorFunctionSerialization); 44 static String serializationForHTML(const DisplayP3<float>&, bool useColorFunctionSerialization); 45 static String serializationForRenderTreeAsText(const DisplayP3<float>&, bool useColorFunctionSerialization); 46 47 static String serializationForCSS(const LCHA<float>&, bool useColorFunctionSerialization); 48 static String serializationForHTML(const LCHA<float>&, bool useColorFunctionSerialization); 49 static String serializationForRenderTreeAsText(const LCHA<float>&, bool useColorFunctionSerialization); 50 51 static String serializationForCSS(const Lab<float>&, bool useColorFunctionSerialization); 52 static String serializationForHTML(const Lab<float>&, bool useColorFunctionSerialization); 53 static String serializationForRenderTreeAsText(const Lab<float>&, bool useColorFunctionSerialization); 54 55 static String serializationForCSS(const LinearSRGBA<float>&, bool useColorFunctionSerialization); 56 static String serializationForHTML(const LinearSRGBA<float>&, bool useColorFunctionSerialization); 57 static String serializationForRenderTreeAsText(const LinearSRGBA<float>&, bool useColorFunctionSerialization); 58 59 static String serializationForCSS(const ProPhotoRGB<float>&, bool useColorFunctionSerialization); 60 static String serializationForHTML(const ProPhotoRGB<float>&, bool useColorFunctionSerialization); 61 static String serializationForRenderTreeAsText(const ProPhotoRGB<float>&, bool useColorFunctionSerialization); 62 63 static String serializationForCSS(const Rec2020<float>&, bool useColorFunctionSerialization); 64 static String serializationForHTML(const Rec2020<float>&, bool useColorFunctionSerialization); 65 static String serializationForRenderTreeAsText(const Rec2020<float>&, bool useColorFunctionSerialization); 66 67 static String serializationForCSS(const SRGBA<float>&, bool useColorFunctionSerialization); 68 static String serializationForHTML(const SRGBA<float>&, bool useColorFunctionSerialization); 69 static String serializationForRenderTreeAsText(const SRGBA<float>&, bool useColorFunctionSerialization); 70 71 static String serializationForCSS(SRGBA<uint8_t>, bool useColorFunctionSerialization); 72 static String serializationForHTML(SRGBA<uint8_t>, bool useColorFunctionSerialization); 73 static String serializationForRenderTreeAsText(SRGBA<uint8_t>, bool useColorFunctionSerialization); 74 75 static String serializationForCSS(const XYZA<float, WhitePoint::D50>&, bool useColorFunctionSerialization); 76 static String serializationForHTML(const XYZA<float, WhitePoint::D50>&, bool useColorFunctionSerialization); 77 static String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>&, bool useColorFunctionSerialization); 78 78 79 79 80 80 String serializationForCSS(const Color& color) 81 81 { 82 return color.callOnUnderlyingType([ ] (auto underlyingColor) {83 return serializationForCSS(underlyingColor );82 return color.callOnUnderlyingType([&] (auto underlyingColor) { 83 return serializationForCSS(underlyingColor, color.usesColorFunctionSerialization()); 84 84 }); 85 85 } … … 87 87 String serializationForHTML(const Color& color) 88 88 { 89 return color.callOnUnderlyingType([ ] (auto underlyingColor) {90 return serializationForHTML(underlyingColor );89 return color.callOnUnderlyingType([&] (auto underlyingColor) { 90 return serializationForHTML(underlyingColor, color.usesColorFunctionSerialization()); 91 91 }); 92 92 } … … 94 94 String serializationForRenderTreeAsText(const Color& color) 95 95 { 96 return color.callOnUnderlyingType([ ] (auto underlyingColor) {97 return serializationForRenderTreeAsText(underlyingColor );96 return color.callOnUnderlyingType([&] (auto underlyingColor) { 97 return serializationForRenderTreeAsText(underlyingColor, color.usesColorFunctionSerialization()); 98 98 }); 99 99 } … … 126 126 } 127 127 128 template<typename ColorType> static String serialization(const ColorType& color) 129 { 128 template<typename ColorType> static String serializationUsingColorFunction(const ColorType& color) 129 { 130 static_assert(std::is_same_v<typename ColorType::ComponentType, float>); 131 130 132 auto [c1, c2, c3, alpha] = color; 131 133 if (WTF::areEssentiallyEqual(alpha, 1.0f)) … … 134 136 } 135 137 138 static String serializationUsingColorFunction(const Lab<float>& color) 139 { 140 auto [c1, c2, c3, alpha] = color; 141 if (WTF::areEssentiallyEqual(alpha, 1.0f)) 142 return makeString("color(", serialization(ColorSpaceFor<Lab<float>>), ' ', c1, "% ", c2, ' ', c3, ')'); 143 return makeString("color(", serialization(ColorSpaceFor<Lab<float>>), ' ', c1, "% ", c2, ' ', c3, " / ", alpha, ')'); 144 } 145 146 static String serializationUsingColorFunction(const SRGBA<uint8_t>& color) 147 { 148 return serializationUsingColorFunction(convertColor<SRGBA<float>>(color)); 149 } 150 136 151 // MARK: A98RGB<float> overloads 137 152 138 String serializationForCSS(const A98RGB<float>& color )139 { 140 return serialization (color);141 } 142 143 String serializationForHTML(const A98RGB<float>& color )144 { 145 return serialization (color);146 } 147 148 String serializationForRenderTreeAsText(const A98RGB<float>& color )149 { 150 return serialization (color);153 String serializationForCSS(const A98RGB<float>& color, bool) 154 { 155 return serializationUsingColorFunction(color); 156 } 157 158 String serializationForHTML(const A98RGB<float>& color, bool) 159 { 160 return serializationUsingColorFunction(color); 161 } 162 163 String serializationForRenderTreeAsText(const A98RGB<float>& color, bool) 164 { 165 return serializationUsingColorFunction(color); 151 166 } 152 167 153 168 // MARK: DisplayP3<float> overloads 154 169 155 String serializationForCSS(const DisplayP3<float>& color )156 { 157 return serialization (color);158 } 159 160 String serializationForHTML(const DisplayP3<float>& color )161 { 162 return serialization (color);163 } 164 165 String serializationForRenderTreeAsText(const DisplayP3<float>& color )166 { 167 return serialization (color);170 String serializationForCSS(const DisplayP3<float>& color, bool) 171 { 172 return serializationUsingColorFunction(color); 173 } 174 175 String serializationForHTML(const DisplayP3<float>& color, bool) 176 { 177 return serializationUsingColorFunction(color); 178 } 179 180 String serializationForRenderTreeAsText(const DisplayP3<float>& color, bool) 181 { 182 return serializationUsingColorFunction(color); 168 183 } 169 184 170 185 // MARK: LCHA<float> overloads 171 186 172 String serializationForCSS(const LCHA<float>& color )187 String serializationForCSS(const LCHA<float>& color, bool useColorFunctionSerialization) 173 188 { 174 189 // https://www.w3.org/TR/css-color-4/#serializing-lab-lch 190 if (useColorFunctionSerialization) 191 return serializationUsingColorFunction(color); 175 192 176 193 auto [c1, c2, c3, alpha] = color; … … 180 197 } 181 198 182 String serializationForHTML(const LCHA<float>& color )183 { 184 return serializationForCSS(color );185 } 186 187 String serializationForRenderTreeAsText(const LCHA<float>& color )188 { 189 return serializationForCSS(color );199 String serializationForHTML(const LCHA<float>& color, bool useColorFunctionSerialization) 200 { 201 return serializationForCSS(color, useColorFunctionSerialization); 202 } 203 204 String serializationForRenderTreeAsText(const LCHA<float>& color, bool useColorFunctionSerialization) 205 { 206 return serializationForCSS(color, useColorFunctionSerialization); 190 207 } 191 208 192 209 // MARK: Lab<float> overloads 193 210 194 String serializationForCSS(const Lab<float>& color )211 String serializationForCSS(const Lab<float>& color, bool useColorFunctionSerialization) 195 212 { 196 213 // https://www.w3.org/TR/css-color-4/#serializing-lab-lch 214 if (useColorFunctionSerialization) 215 return serializationUsingColorFunction(color); 197 216 198 217 auto [c1, c2, c3, alpha] = color; … … 202 221 } 203 222 204 String serializationForHTML(const Lab<float>& color )205 { 206 return serializationForCSS(color );207 } 208 209 String serializationForRenderTreeAsText(const Lab<float>& color )210 { 211 return serializationForCSS(color );223 String serializationForHTML(const Lab<float>& color, bool useColorFunctionSerialization) 224 { 225 return serializationForCSS(color, useColorFunctionSerialization); 226 } 227 228 String serializationForRenderTreeAsText(const Lab<float>& color, bool useColorFunctionSerialization) 229 { 230 return serializationForCSS(color, useColorFunctionSerialization); 212 231 } 213 232 214 233 // MARK: LinearSRGBA<float> overloads 215 234 216 String serializationForCSS(const LinearSRGBA<float>& color )217 { 218 return serialization (color);219 } 220 221 String serializationForHTML(const LinearSRGBA<float>& color )222 { 223 return serialization (color);224 } 225 226 String serializationForRenderTreeAsText(const LinearSRGBA<float>& color )227 { 228 return serialization (color);235 String serializationForCSS(const LinearSRGBA<float>& color, bool) 236 { 237 return serializationUsingColorFunction(color); 238 } 239 240 String serializationForHTML(const LinearSRGBA<float>& color, bool) 241 { 242 return serializationUsingColorFunction(color); 243 } 244 245 String serializationForRenderTreeAsText(const LinearSRGBA<float>& color, bool) 246 { 247 return serializationUsingColorFunction(color); 229 248 } 230 249 231 250 // MARK: ProPhotoRGB<float> overloads 232 251 233 String serializationForCSS(const ProPhotoRGB<float>& color )234 { 235 return serialization (color);236 } 237 238 String serializationForHTML(const ProPhotoRGB<float>& color )239 { 240 return serialization (color);241 } 242 243 String serializationForRenderTreeAsText(const ProPhotoRGB<float>& color )244 { 245 return serialization (color);252 String serializationForCSS(const ProPhotoRGB<float>& color, bool) 253 { 254 return serializationUsingColorFunction(color); 255 } 256 257 String serializationForHTML(const ProPhotoRGB<float>& color, bool) 258 { 259 return serializationUsingColorFunction(color); 260 } 261 262 String serializationForRenderTreeAsText(const ProPhotoRGB<float>& color, bool) 263 { 264 return serializationUsingColorFunction(color); 246 265 } 247 266 248 267 // MARK: Rec2020<float> overloads 249 268 250 String serializationForCSS(const Rec2020<float>& color )251 { 252 return serialization (color);253 } 254 255 String serializationForHTML(const Rec2020<float>& color )256 { 257 return serialization (color);258 } 259 260 String serializationForRenderTreeAsText(const Rec2020<float>& color )261 { 262 return serialization (color);269 String serializationForCSS(const Rec2020<float>& color, bool) 270 { 271 return serializationUsingColorFunction(color); 272 } 273 274 String serializationForHTML(const Rec2020<float>& color, bool) 275 { 276 return serializationUsingColorFunction(color); 277 } 278 279 String serializationForRenderTreeAsText(const Rec2020<float>& color, bool) 280 { 281 return serializationUsingColorFunction(color); 263 282 } 264 283 265 284 // MARK: SRGBA<float> overloads 266 285 267 String serializationForCSS(const SRGBA<float>& color )268 { 269 return serialization (color);270 } 271 272 String serializationForHTML(const SRGBA<float>& color )273 { 274 return serialization (color);275 } 276 277 String serializationForRenderTreeAsText(const SRGBA<float>& color )278 { 279 return serialization (color);286 String serializationForCSS(const SRGBA<float>& color, bool) 287 { 288 return serializationUsingColorFunction(color); 289 } 290 291 String serializationForHTML(const SRGBA<float>& color, bool) 292 { 293 return serializationUsingColorFunction(color); 294 } 295 296 String serializationForRenderTreeAsText(const SRGBA<float>& color, bool) 297 { 298 return serializationUsingColorFunction(color); 280 299 } 281 300 … … 299 318 } 300 319 301 String serializationForCSS(SRGBA<uint8_t> color) 302 { 320 String serializationForCSS(SRGBA<uint8_t> color, bool useColorFunctionSerialization) 321 { 322 if (useColorFunctionSerialization) 323 return serializationUsingColorFunction(color); 324 303 325 auto [red, green, blue, alpha] = color; 304 326 switch (alpha) { … … 312 334 } 313 335 314 String serializationForHTML(SRGBA<uint8_t> color) 315 { 336 String serializationForHTML(SRGBA<uint8_t> color, bool useColorFunctionSerialization) 337 { 338 if (useColorFunctionSerialization) 339 return serializationUsingColorFunction(color); 340 316 341 auto [red, green, blue, alpha] = color; 317 342 if (alpha == 0xFF) … … 320 345 } 321 346 322 String serializationForRenderTreeAsText(SRGBA<uint8_t> color) 323 { 347 String serializationForRenderTreeAsText(SRGBA<uint8_t> color, bool useColorFunctionSerialization) 348 { 349 if (useColorFunctionSerialization) 350 return serializationUsingColorFunction(color); 351 324 352 auto [red, green, blue, alpha] = color; 325 353 if (alpha < 0xFF) … … 330 358 // MARK: XYZA<float, WhitePoint::D50> overloads 331 359 332 String serializationForCSS(const XYZA<float, WhitePoint::D50>& color )333 { 334 return serialization (color);335 } 336 337 String serializationForHTML(const XYZA<float, WhitePoint::D50>& color )338 { 339 return serialization (color);340 } 341 342 String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>& color )343 { 344 return serialization (color);345 } 346 347 } 360 String serializationForCSS(const XYZA<float, WhitePoint::D50>& color, bool) 361 { 362 return serializationUsingColorFunction(color); 363 } 364 365 String serializationForHTML(const XYZA<float, WhitePoint::D50>& color, bool) 366 { 367 return serializationUsingColorFunction(color); 368 } 369 370 String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>& color, bool) 371 { 372 return serializationUsingColorFunction(color); 373 } 374 375 } -
trunk/Source/WebCore/platform/graphics/ColorUtilities.h
r273078 r273211 53 53 template<typename ColorType, typename Functor> ColorType colorByModifingEachNonAlphaComponent(const ColorType&, Functor&&); 54 54 55 template<typename ColorType> constexpr ColorType colorWithOverrid enAlpha(const ColorType&, uint8_t overrideAlpha);56 template<typename ColorType> ColorType colorWithOverrid enAlpha(const ColorType&, float overrideAlpha);57 58 template<typename ColorType> constexpr ColorType inverted ColorWithOverridenAlpha(const ColorType&, uint8_t overrideAlpha);59 template<typename ColorType> ColorType inverted ColorWithOverridenAlpha(const ColorType&, float overrideAlpha);55 template<typename ColorType> constexpr ColorType colorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha); 56 template<typename ColorType> ColorType colorWithOverriddenAlpha(const ColorType&, float overrideAlpha); 57 58 template<typename ColorType> constexpr ColorType invertedcolorWithOverriddenAlpha(const ColorType&, uint8_t overrideAlpha); 59 template<typename ColorType> ColorType invertedcolorWithOverriddenAlpha(const ColorType&, float overrideAlpha); 60 60 61 61 template<typename ColorType, typename std::enable_if_t<std::is_same_v<typename ColorType::Model, RGBModel<typename ColorType::ComponentType>>>* = nullptr> constexpr bool isBlack(const ColorType&); … … 108 108 } 109 109 110 template<typename ColorType> constexpr ColorType colorWithOverrid enAlpha(const ColorType& color, uint8_t overrideAlpha)110 template<typename ColorType> constexpr ColorType colorWithOverriddenAlpha(const ColorType& color, uint8_t overrideAlpha) 111 111 { 112 112 auto copy = color; … … 115 115 } 116 116 117 template<typename ColorType> ColorType colorWithOverrid enAlpha(const ColorType& color, float overrideAlpha)117 template<typename ColorType> ColorType colorWithOverriddenAlpha(const ColorType& color, float overrideAlpha) 118 118 { 119 119 auto copy = color; … … 122 122 } 123 123 124 template<typename ColorType> constexpr ColorType inverted ColorWithOverridenAlpha(const ColorType& color, uint8_t overrideAlpha)124 template<typename ColorType> constexpr ColorType invertedcolorWithOverriddenAlpha(const ColorType& color, uint8_t overrideAlpha) 125 125 { 126 126 static_assert(ColorType::Model::isInvertible); … … 136 136 } 137 137 138 template<typename ColorType> ColorType inverted ColorWithOverridenAlpha(const ColorType& color, float overrideAlpha)138 template<typename ColorType> ColorType invertedcolorWithOverriddenAlpha(const ColorType& color, float overrideAlpha) 139 139 { 140 140 static_assert(ColorType::Model::isInvertible); -
trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp
r272736 r273211 90 90 } 91 91 92 Color::Color(CGColorRef color, SemanticTag tag)93 : Color(roundAndClampToSRGBALossy(color), tag)92 Color::Color(CGColorRef color, OptionSet<Flags> flags) 93 : Color(roundAndClampToSRGBALossy(color), flags) 94 94 { 95 95 } -
trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm
r272731 r273211 109 109 Color semanticColorFromNSColor(NSColor *color) 110 110 { 111 return Color(makeSimpleColorFromNSColor(color), Color:: Semantic);111 return Color(makeSimpleColorFromNSColor(color), Color::Flags::Semantic); 112 112 } 113 113 -
trunk/Source/WebCore/rendering/RenderThemeIOS.mm
r273014 r273211 1392 1392 { 1393 1393 if (auto color = wtfObjCMsgSend<UIColor *>(PAL::getUIColorClass(), idAndSelector.selector)) 1394 return Color { color.CGColor, Color:: Semantic };1394 return Color { color.CGColor, Color::Flags::Semantic }; 1395 1395 return WTF::nullopt; 1396 1396 } … … 1410 1410 if (auto selector = cssColorToSelector()) { 1411 1411 if (auto color = wtfObjCMsgSend<UIColor *>(PAL::getUIColorClass(), selector)) 1412 return Color (color.CGColor, Color::Semantic);1412 return Color { color.CGColor, Color::Flags::Semantic }; 1413 1413 } 1414 1414 return WTF::nullopt; -
trunk/Source/WebCore/rendering/RenderThemeMac.mm
r272805 r273211 730 730 // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting. 731 731 if (localAppearance.usingDarkAppearance()) 732 return { SRGBA<uint8_t> { 26, 169, 255 }, Color:: Semantic };733 return { SRGBA<uint8_t> { 0, 103, 244 }, Color:: Semantic };732 return { SRGBA<uint8_t> { 26, 169, 255 }, Color::Flags::Semantic }; 733 return { SRGBA<uint8_t> { 0, 103, 244 }, Color::Flags::Semantic }; 734 734 735 735 case CSSValueAppleSystemControlAccent: 736 736 // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting. 737 737 // Same color in light and dark appearances. 738 return { SRGBA<uint8_t> { 0, 122, 255 }, Color:: Semantic };738 return { SRGBA<uint8_t> { 0, 122, 255 }, Color::Flags::Semantic }; 739 739 740 740 case CSSValueAppleSystemSelectedContentBackground: 741 741 // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting. 742 742 if (localAppearance.usingDarkAppearance()) 743 return { SRGBA<uint8_t> { 0, 88, 208 }, Color:: Semantic };744 return { SRGBA<uint8_t> { 0, 99, 225 }, Color:: Semantic };743 return { SRGBA<uint8_t> { 0, 88, 208 }, Color::Flags::Semantic }; 744 return { SRGBA<uint8_t> { 0, 99, 225 }, Color::Flags::Semantic }; 745 745 746 746 case CSSValueHighlight: … … 748 748 // Hardcoded to avoid exposing a user appearance preference to the web for fingerprinting. 749 749 if (localAppearance.usingDarkAppearance()) 750 return { SRGBA<uint8_t> { 63, 99, 139, 204 }, Color:: Semantic };751 return { SRGBA<uint8_t> { 128, 188, 254, 153 }, Color:: Semantic };750 return { SRGBA<uint8_t> { 63, 99, 139, 204 }, Color::Flags::Semantic }; 751 return { SRGBA<uint8_t> { 128, 188, 254, 153 }, Color::Flags::Semantic }; 752 752 753 753 #if !HAVE(OS_DARK_MODE_SUPPORT)
Note: See TracChangeset
for help on using the changeset viewer.