Changeset 272311 in webkit


Ignore:
Timestamp:
Feb 3, 2021 6:38:52 AM (18 months ago)
Author:
weinig@apple.com
Message:

Add support for color(xyz ...) as part of CSS Color 4
https://bugs.webkit.org/show_bug.cgi?id=221190

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Add some new WPT tests for color(xyz ) that will be upstreamed shortly.

  • web-platform-tests/css/css-color/xyz-001-expected.html: Added.
  • web-platform-tests/css/css-color/xyz-001.html: Added.
  • web-platform-tests/css/css-color/xyz-002-expected.html: Added.
  • web-platform-tests/css/css-color/xyz-002.html: Added.
  • web-platform-tests/css/css-color/xyz-003-expected.html: Added.
  • web-platform-tests/css/css-color/xyz-003.html: Added.
  • web-platform-tests/css/css-color/xyz-004-expected.html: Added.
  • web-platform-tests/css/css-color/xyz-004.html: Added.
  • web-platform-tests/css/css-color/xyz-005-expected.html: Added.
  • web-platform-tests/css/css-color/xyz-005.html: Added.

Source/WebCore:

Add final (for now) predefined color space supported by color() in CSS Color 4, XYZ.

The specific XYZ use by CSS is the XYZ with D50 white point. To make the generic
XYZA<T, WhitePoint> type work in the infrastrucure, the colorSpace member was removed
from the color types, and the mapping from ColorSpace enum value to ColorType was
converted to use template specialization and can now be extracted using the syntax:

ColorSpaceFor<ColorType>

This change also removed the inclusion of all of the color type specific serialiazation
function declarations in ColorSerialization.h, and instead moved them to the cpp file.
They weren't being used, and to support the XYZA<float, WhitePoint::D50> would have required
incluing more headers, which seemed like the wrong tradeoff. If accessing serialization
without constructing a WebCore::Color is useful in the future, we can always add them back.

Tests: imported/w3c/web-platform-tests/css/css-color/xyz-001.html

imported/w3c/web-platform-tests/css/css-color/xyz-002.html
imported/w3c/web-platform-tests/css/css-color/xyz-003.html
imported/w3c/web-platform-tests/css/css-color/xyz-004.html
imported/w3c/web-platform-tests/css/css-color/xyz-005.html

  • css/CSSValueKeywords.in:

Add xyz keyword.

  • css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::parseColorFunctionForXYZParameters):
(WebCore::CSSPropertyParserHelpers::parseColorFunctionParameters):
Add parsing for color(xyz ) parameters. This can't reuse the RGB parameter
parsing because xyz does not allow percentages for any parameter.

  • platform/graphics/ColorConversion.h:

(WebCore::callWithColorType): Deleted.
Moved callWithColorType to ColorSpace.h, where it makes a bit more sense
now that the color mapping is also defined there. This puts most of the
color mapping in one place.

  • platform/graphics/ColorModels.h:

Add some needed includes that fiddling with headers exposed.

  • platform/graphics/ColorSerialization.cpp:

(WebCore::serialization):
(WebCore::serializationForCSS):
(WebCore::serializationForHTML):
(WebCore::serializationForRenderTreeAsText):

  • platform/graphics/ColorSerialization.h:

Add support for serializing XYZA<float, WhitePoint::D50>, taking the chance
to move all the unnecessarily exposed type specific serialization functions.

  • platform/graphics/ColorSpace.cpp:

(WebCore::operator<<):
Add support for XYZ_D50.

  • platform/graphics/ColorSpace.h:

Add color mapping replacing previous explicit static members for colorSpace
mapping which are no longer usable due to the generic nature of XYZA.

(WebCore::callWithColorType):
Moved from ColorConversion.h.

  • platform/graphics/ColorTypes.h:

Remove colorSpace members. Replaced by color space mapping in ColorSpace.h

  • platform/graphics/ColorUtilities.h:

(WebCore::isBlack):
(WebCore::isWhite):
Add overloads for XYZA needed by Color.

  • platform/graphics/ExtendedColor.h:

(WebCore::ExtendedColor::create):
Replace color.colorSpace with ColorSpaceFor<ColorType>.

  • platform/graphics/cg/ColorSpaceCG.cpp:

(WebCore::xyzD50ColorSpaceRef):

  • platform/graphics/cg/ColorSpaceCG.h:

(WebCore::cachedCGColorSpace):
Add CoreGraphics support for the XYZ color space. (kCGColorSpaceGenericXYZ maps to XYZ with a D50 white point.)

LayoutTests:

Remove now passing xyz test. Update comment for the other xyz test which is invalid.
Getting it removed in https://github.com/web-platform-tests/wpt/pull/27416.

  • fast/css/parsing-color-function-expected.txt:
  • fast/css/parsing-color-function.html:

Add xyz specific parsing tests, as the rgb ones can't be reusued due to xyz
not supporting percentages for any component.

Location:
trunk
Files:
10 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r272308 r272311  
     12021-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
    1172021-02-03  Ziran Sun  <zsun@igalia.com>
    218
  • trunk/LayoutTests/TestExpectations

    r272308 r272311  
    46024602webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-014.html [ ImageOnlyFailure ] # Requires fallback (at parse time) support
    46034603webkit.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
     4604webkit.org/b/220928 imported/w3c/web-platform-tests/css/css-color/predefined-017.html [ ImageOnlyFailure ] # Invalid test, percentages are not allowed for color(xyz).
    46064605
    46074606webkit.org/b/218496 http/tests/loading/redirect-with-no-location-crash.html [ Skip ]
  • trunk/LayoutTests/fast/css/parsing-color-function-expected.txt

    r272125 r272311  
    124124PASS computedStyle("background-color", "color(prophoto-rgb 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
    125125PASS computedStyle("background-color", "color(prophoto-rgb 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
     126
     127Testing color(xyz ...)
     128PASS computedStyle("background-color", "color(xyz 0 0 0)") is "color(xyz 0 0 0)"
     129PASS computedStyle("background-color", "color(xyz 0 0 0 / 1)") is "color(xyz 0 0 0)"
     130PASS computedStyle("background-color", "color(xyz 1 1 1)") is "color(xyz 1 1 1)"
     131PASS computedStyle("background-color", "color(xyz 1 1 1 / 1)") is "color(xyz 1 1 1)"
     132PASS computedStyle("background-color", "color(xyz -1 -1 -1)") is "color(xyz -1 -1 -1)"
     133PASS computedStyle("background-color", "color(xyz 0.1 0.1 0.1)") is "color(xyz 0.1 0.1 0.1)"
     134PASS computedStyle("background-color", "color(xyz 10 10 10)") is "color(xyz 10 10 10)"
     135PASS computedStyle("background-color", "color(xyz .2 .2 .25)") is "color(xyz 0.2 0.2 0.25)"
     136PASS computedStyle("background-color", "color(xyz 0 0 0 / 0.5)") is "color(xyz 0 0 0 / 0.5)"
     137PASS computedStyle("background-color", "color(xyz .20 0 10/0.5)") is "color(xyz 0.2 0 10 / 0.5)"
     138PASS computedStyle("background-color", "color(xyz .20 0 10/50%)") is "color(xyz 0.2 0 10 / 0.5)"
     139PASS computedStyle("background-color", "color(xyz 0 0 0 / -10%)") is "color(xyz 0 0 0 / 0)"
     140PASS computedStyle("background-color", "color(xyz 0 0 0 / 110%)") is "color(xyz 0 0 0)"
     141PASS computedStyle("background-color", "color(xyz 0 0 0 / 300%)") is "color(xyz 0 0 0)"
     142PASS computedStyle("background-color", "color(xyz 1 1)") is "color(xyz 1 1 0)"
     143PASS computedStyle("background-color", "color(xyz 1)") is "color(xyz 1 0 0)"
     144PASS computedStyle("background-color", "color(xyz)") is "color(xyz 0 0 0)"
     145PASS computedStyle("background-color", "color(xyz 1 1 / .5)") is "color(xyz 1 1 0 / 0.5)"
     146PASS computedStyle("background-color", "color(xyz 1 / 0.5)") is "color(xyz 1 0 0 / 0.5)"
     147PASS computedStyle("background-color", "color(xyz / 50%)") is "color(xyz 0 0 0 / 0.5)"
     148
     149Test invalid values
     150PASS computedStyle("background-color", "color(xyz 0 0 0 0)") is "rgba(0, 0, 0, 0)"
     151PASS computedStyle("background-color", "color(xyz 0deg 0% 0)") is "rgba(0, 0, 0, 0)"
     152PASS computedStyle("background-color", "color(xyz 0% 0 0)") is "rgba(0, 0, 0, 0)"
     153PASS computedStyle("background-color", "color(xyz 0% 0 0 1)") is "rgba(0, 0, 0, 0)"
     154PASS computedStyle("background-color", "color(xyz 0% 0 0 10%)") is "rgba(0, 0, 0, 0)"
     155PASS computedStyle("background-color", "color(xyz 0% 0 0deg)") is "rgba(0, 0, 0, 0)"
     156PASS computedStyle("background-color", "color(xyz 0% 0% 0deg)") is "rgba(0, 0, 0, 0)"
     157PASS computedStyle("background-color", "color(xyz 40% 0 0deg)") is "rgba(0, 0, 0, 0)"
    126158PASS successfullyParsed is true
    127159
  • trunk/LayoutTests/fast/css/parsing-color-function.html

    r272125 r272311  
    6969        testComputed("background-color", `color(${color} 40% 0 0deg)`, `rgba(0, 0, 0, 0)`);
    7070    }
     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
    71107</script>
    72108   
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r272309 r272311  
     12021-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
    1212021-02-03  Ziran Sun  <zsun@igalia.com>
    222
  • trunk/Source/WebCore/ChangeLog

    r272310 r272311  
     12021-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
    1852021-02-03  Zalan Bujtas  <zalan@apple.com>
    286
  • trunk/Source/WebCore/css/CSSValueKeywords.in

    r272125 r272311  
    14101410// rec2020
    14111411// sRGB
     1412xyz
    14121413
    14131414// prefers-default-appearance
  • trunk/Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp

    r272125 r272311  
    943943}
    944944
     945static 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
    945975static Color parseColorFunctionParameters(CSSParserTokenRange& range)
    946976{
     
    967997    case CSSValueSRGB:
    968998        color = parseColorFunctionForRGBTypes<SRGBA<float>>(args);
     999        break;
     1000    case CSSValueXyz:
     1001        color = parseColorFunctionForXYZParameters(args);
    9691002        break;
    9701003    default:
  • trunk/Source/WebCore/platform/graphics/ColorConversion.h

    r272146 r272311  
    257257}
    258258
    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 
    283259} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/ColorModels.h

    r272066 r272311  
    2525
    2626#pragma once
     27
     28#include <array>
     29#include <limits>
    2730
    2831namespace WebCore {
  • trunk/Source/WebCore/platform/graphics/ColorSerialization.cpp

    r272125 r272311  
    3737namespace WebCore {
    3838
     39static String serializationForCSS(const A98RGB<float>&);
     40static String serializationForHTML(const A98RGB<float>&);
     41static String serializationForRenderTreeAsText(const A98RGB<float>&);
     42
     43static String serializationForCSS(const DisplayP3<float>&);
     44static String serializationForHTML(const DisplayP3<float>&);
     45static String serializationForRenderTreeAsText(const DisplayP3<float>&);
     46
     47static String serializationForCSS(const Lab<float>&);
     48static String serializationForHTML(const Lab<float>&);
     49static String serializationForRenderTreeAsText(const Lab<float>&);
     50
     51static String serializationForCSS(const LinearSRGBA<float>&);
     52static String serializationForHTML(const LinearSRGBA<float>&);
     53static String serializationForRenderTreeAsText(const LinearSRGBA<float>&);
     54
     55static String serializationForCSS(const ProPhotoRGB<float>&);
     56static String serializationForHTML(const ProPhotoRGB<float>&);
     57static String serializationForRenderTreeAsText(const ProPhotoRGB<float>&);
     58
     59static String serializationForCSS(const Rec2020<float>&);
     60static String serializationForHTML(const Rec2020<float>&);
     61static String serializationForRenderTreeAsText(const Rec2020<float>&);
     62
     63static String serializationForCSS(const SRGBA<float>&);
     64static String serializationForHTML(const SRGBA<float>&);
     65static String serializationForRenderTreeAsText(const SRGBA<float>&);
     66
     67static String serializationForCSS(SRGBA<uint8_t>);
     68static String serializationForHTML(SRGBA<uint8_t>);
     69static String serializationForRenderTreeAsText(SRGBA<uint8_t>);
     70
     71static String serializationForCSS(const XYZA<float, WhitePoint::D50>&);
     72static String serializationForHTML(const XYZA<float, WhitePoint::D50>&);
     73static String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>&);
     74
     75
    3976String serializationForCSS(const Color& color)
    4077{
     
    75112    case ColorSpace::SRGB:
    76113        return "srgb"_s;
     114    case ColorSpace::XYZ_D50:
     115        return "xyz"_s;
    77116    }
    78117
     
    85124    auto [c1, c2, c3, alpha] = color;
    86125    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, ')');
    89128}
    90129
     
    261300}
    262301
    263 }
     302// MARK: XYZA<float, WhitePoint::D50> overloads
     303
     304String serializationForCSS(const XYZA<float, WhitePoint::D50>& color)
     305{
     306    return serialization(color);
     307}
     308
     309String serializationForHTML(const XYZA<float, WhitePoint::D50>& color)
     310{
     311    return serialization(color);
     312}
     313
     314String serializationForRenderTreeAsText(const XYZA<float, WhitePoint::D50>& color)
     315{
     316    return serialization(color);
     317}
     318
     319}
  • trunk/Source/WebCore/platform/graphics/ColorSerialization.h

    r272125 r272311  
    3232class Color;
    3333
    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.
    4537
    4638WEBCORE_EXPORT String serializationForCSS(const Color&);
     
    4840WEBCORE_EXPORT String serializationForRenderTreeAsText(const Color&);
    4941
    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 
    8442}
  • trunk/Source/WebCore/platform/graphics/ColorSpace.cpp

    r272125 r272311  
    5555        ts << "sRGB";
    5656        break;
     57    case ColorSpace::XYZ_D50:
     58        ts << "XYZ";
     59        break;
    5760    }
    5861    return ts;
  • trunk/Source/WebCore/platform/graphics/ColorSpace.h

    r272125 r272311  
    2626#pragma once
    2727
     28#include "ColorTypes.h"
     29
    2830namespace WTF {
    2931class TextStream;
     
    4042    Rec2020,
    4143    SRGB,
     44    XYZ_D50,
    4245};
    4346
    4447WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace);
    4548
     49
     50template<typename> struct ColorSpaceMapping;
     51template<typename T> struct ColorSpaceMapping<A98RGB<T>> { static constexpr auto colorSpace { ColorSpace::A98RGB }; };
     52template<typename T> struct ColorSpaceMapping<DisplayP3<T>> { static constexpr auto colorSpace { ColorSpace::DisplayP3 }; };
     53template<typename T> struct ColorSpaceMapping<Lab<T>> { static constexpr auto colorSpace { ColorSpace::Lab }; };
     54template<typename T> struct ColorSpaceMapping<LinearSRGBA<T>> { static constexpr auto colorSpace { ColorSpace::LinearRGB }; };
     55template<typename T> struct ColorSpaceMapping<ProPhotoRGB<T>> { static constexpr auto colorSpace { ColorSpace::ProPhotoRGB }; };
     56template<typename T> struct ColorSpaceMapping<Rec2020<T>> { static constexpr auto colorSpace { ColorSpace::Rec2020 }; };
     57template<typename T> struct ColorSpaceMapping<SRGBA<T>> { static constexpr auto colorSpace { ColorSpace::SRGB }; };
     58template<typename T> struct ColorSpaceMapping<XYZA<T, WhitePoint::D50>> { static constexpr auto colorSpace { ColorSpace::XYZ_D50 }; };
     59
     60template<typename ColorType> constexpr ColorSpace ColorSpaceFor = ColorSpaceMapping<ColorType>::colorSpace;
     61
     62
     63template<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
    4688} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/ColorTypes.h

    r272146 r272311  
    2828#include "ColorComponents.h"
    2929#include "ColorModels.h"
    30 #include "ColorSpace.h"
    3130
    3231namespace WebCore {
     
    150149#endif
    151150
    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 
    155151template<typename, typename = void> inline constexpr bool IsConvertibleToColorComponents = false;
    156152template<typename T> inline constexpr bool IsConvertibleToColorComponents<T, std::void_t<decltype(asColorComponents(std::declval<T>()))>> = true;
     
    163159template<typename T, typename U> inline constexpr bool HasComponentType = HasComponentTypeValue<T, U, HasComponentTypeMember<T>>;
    164160
    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>;
     161template<typename T> inline constexpr bool IsColorType = IsConvertibleToColorComponents<T> && HasComponentTypeMember<T>;
     162template<typename T, typename U> inline constexpr bool IsColorTypeWithComponentType = IsConvertibleToColorComponents<T> && HasComponentType<T, U>;
    167163
    168164template<typename Parent> struct ColorWithAlphaHelper {
     
    229225    using LinearCounterpart = LinearA98RGB<T>;
    230226    using ReferenceXYZ = XYZA<T, WhitePoint::D65>;
    231     static constexpr auto colorSpace = ColorSpace::A98RGB;
    232227};
    233228template<typename T> A98RGB(T, T, T, T) -> A98RGB<T>;
     
    237232    using LinearCounterpart = LinearDisplayP3<T>;
    238233    using ReferenceXYZ = XYZA<T, WhitePoint::D65>;
    239     static constexpr auto colorSpace = ColorSpace::DisplayP3;
    240234};
    241235template<typename T> DisplayP3(T, T, T, T) -> DisplayP3<T>;
     
    287281    using GammaEncodedCounterpart = SRGBA<T>;
    288282    using ReferenceXYZ = XYZA<T, WhitePoint::D65>;
    289     static constexpr auto colorSpace = ColorSpace::LinearRGB;
    290283};
    291284template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>;
     
    295288    using LinearCounterpart = LinearProPhotoRGB<T>;
    296289    using ReferenceXYZ = XYZA<T, WhitePoint::D50>;
    297     static constexpr auto colorSpace = ColorSpace::ProPhotoRGB;
    298290};
    299291template<typename T> ProPhotoRGB(T, T, T, T) -> ProPhotoRGB<T>;
     
    303295    using LinearCounterpart = LinearRec2020<T>;
    304296    using ReferenceXYZ = XYZA<T, WhitePoint::D65>;
    305     static constexpr auto colorSpace { ColorSpace::Rec2020 };
    306297};
    307298template<typename T> Rec2020(T, T, T, T) -> Rec2020<T>;
     
    311302    using LinearCounterpart = LinearSRGBA<T>;
    312303    using ReferenceXYZ = XYZA<T, WhitePoint::D65>;
    313     static constexpr auto colorSpace { ColorSpace::SRGB };
    314304};
    315305template<typename T> SRGBA(T, T, T, T) -> SRGBA<T>;
     
    321311    using Model = LabModel<T>;
    322312    using ReferenceXYZ = XYZA<T, WhitePoint::D50>;
    323     static constexpr auto colorSpace = ColorSpace::Lab;
    324313
    325314    constexpr Lab(T lightness, T a, T b, T alpha = AlphaTraits<T>::opaque)
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.h

    r271695 r272311  
    172172}
    173173
     174template<WhitePoint W> constexpr bool isBlack(const XYZA<float, W>& color)
     175{
     176    return color.y == 0 && color.alpha == AlphaTraits<float>::opaque;
     177}
     178
    174179constexpr bool isBlack(const Lab<float>& color)
    175180{
     
    183188    constexpr auto ranges = ColorType::Model::ranges;
    184189    return c1 == ranges[0].min && c2 == ranges[1].min && c3 == ranges[2].min && alpha == AlphaTraits<typename ColorType::ComponentType>::opaque;
     190}
     191
     192template<WhitePoint W> constexpr bool isWhite(const XYZA<float, W>& color)
     193{
     194    return color.y == 1 && color.alpha == AlphaTraits<float>::opaque;
    185195}
    186196
  • trunk/Source/WebCore/platform/graphics/ExtendedColor.h

    r271089 r272311  
    6767template<typename ColorType> inline Ref<ExtendedColor> ExtendedColor::create(const ColorType& color)
    6868{
    69     return adoptRef(*new ExtendedColor(asColorComponents(color), color.colorSpace));
     69    return adoptRef(*new ExtendedColor(asColorComponents(color), ColorSpaceFor<ColorType>));
    7070}
    7171
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp

    r272125 r272311  
    149149}
    150150
     151CGColorSpaceRef 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
    151165}
    152166
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h

    r272125 r272311  
    4040WEBCORE_EXPORT CGColorSpaceRef rec2020ColorSpaceRef();
    4141WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
     42WEBCORE_EXPORT CGColorSpaceRef xyzD50ColorSpaceRef();
    4243
    4344static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
     
    5859    case ColorSpace::SRGB:
    5960        return sRGBColorSpaceRef();
     61    case ColorSpace::XYZ_D50:
     62        return xyzD50ColorSpaceRef();
    6063    }
    6164    ASSERT_NOT_REACHED();
Note: See TracChangeset for help on using the changeset viewer.