⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287821 in webkit


Ignore:
Timestamp:
Jan 9, 2022, 10:06:02 AM (5 years ago)
Author:
weinig@apple.com
Message:

Add helpers to access CoreGraphics color spaces more easily in generic contexts
https://bugs.webkit.org/show_bug.cgi?id=235004

Reviewed by Darin Adler.

Source/WebCore:

Add some structs and type trait helpers to allow accessing the CoreGraphics
CGColorSpaceRef associated with a ColorSpace enum value at compile time. This
will be useful for generalizing some of the gradient rendering code optimizations
I have planned.

  • platform/graphics/cg/ColorCG.cpp:

(WebCore::Color::createAndLosslesslyConvertToSupportedColorSpace):

  • platform/graphics/cg/ColorSpaceCG.cpp:

(WebCore::colorSpaceForCGColorSpace):

  • platform/graphics/cg/ColorSpaceCG.h:

(WebCore::CGColorSpaceMapping<ColorSpace::SRGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::A98RGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::DisplayP3>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ExtendedA98RGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ExtendedDisplayP3>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ExtendedRec2020>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ExtendedLinearSRGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ExtendedProPhotoRGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ExtendedSRGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::Rec2020>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::LinearSRGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::ProPhotoRGB>::colorSpace):
(WebCore::CGColorSpaceMapping<ColorSpace::XYZ_D50>::colorSpace):
(WebCore::CGColorSpaceMappingGetter::colorSpace):
(WebCore::cachedNullableCGColorSpace):

Source/WTF:

  • wtf/PlatformHave.h:

Update have macro, HAVE_CORE_GRAPHICS_XYZ_COLOR_SPACE, to have a more specific name,
HAVE_CORE_GRAPHICS_XYZ_D50_COLOR_SPACE, which is really what it is.

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r287784 r287821  
     12022-01-09  Sam Weinig  <weinig@apple.com>
     2
     3        Add helpers to access CoreGraphics color spaces more easily in generic contexts
     4        https://bugs.webkit.org/show_bug.cgi?id=235004
     5
     6        Reviewed by Darin Adler.
     7
     8        * wtf/PlatformHave.h:
     9        Update have macro, HAVE_CORE_GRAPHICS_XYZ_COLOR_SPACE, to have a more specific name,
     10        HAVE_CORE_GRAPHICS_XYZ_D50_COLOR_SPACE, which is really what it is.
     11
    1122022-01-07  Tim Horton  <timothy_horton@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r287820 r287821  
     12022-01-09  Sam Weinig  <weinig@apple.com>
     2
     3        Add helpers to access CoreGraphics color spaces more easily in generic contexts
     4        https://bugs.webkit.org/show_bug.cgi?id=235004
     5
     6        Reviewed by Darin Adler.
     7
     8        Add some structs and type trait helpers to allow accessing the CoreGraphics
     9        CGColorSpaceRef associated with a ColorSpace enum value at compile time. This
     10        will be useful for generalizing some of the gradient rendering code optimizations
     11        I have planned.
     12
     13        * platform/graphics/cg/ColorCG.cpp:
     14        (WebCore::Color::createAndLosslesslyConvertToSupportedColorSpace):
     15        * platform/graphics/cg/ColorSpaceCG.cpp:
     16        (WebCore::colorSpaceForCGColorSpace):
     17        * platform/graphics/cg/ColorSpaceCG.h:
     18        (WebCore::CGColorSpaceMapping<ColorSpace::SRGB>::colorSpace):
     19        (WebCore::CGColorSpaceMapping<ColorSpace::A98RGB>::colorSpace):
     20        (WebCore::CGColorSpaceMapping<ColorSpace::DisplayP3>::colorSpace):
     21        (WebCore::CGColorSpaceMapping<ColorSpace::ExtendedA98RGB>::colorSpace):
     22        (WebCore::CGColorSpaceMapping<ColorSpace::ExtendedDisplayP3>::colorSpace):
     23        (WebCore::CGColorSpaceMapping<ColorSpace::ExtendedRec2020>::colorSpace):
     24        (WebCore::CGColorSpaceMapping<ColorSpace::ExtendedLinearSRGB>::colorSpace):
     25        (WebCore::CGColorSpaceMapping<ColorSpace::ExtendedProPhotoRGB>::colorSpace):
     26        (WebCore::CGColorSpaceMapping<ColorSpace::ExtendedSRGB>::colorSpace):
     27        (WebCore::CGColorSpaceMapping<ColorSpace::Rec2020>::colorSpace):
     28        (WebCore::CGColorSpaceMapping<ColorSpace::LinearSRGB>::colorSpace):
     29        (WebCore::CGColorSpaceMapping<ColorSpace::ProPhotoRGB>::colorSpace):
     30        (WebCore::CGColorSpaceMapping<ColorSpace::XYZ_D50>::colorSpace):
     31        (WebCore::CGColorSpaceMappingGetter::colorSpace):
     32        (WebCore::cachedNullableCGColorSpace):
     33
    1342022-01-08  Antoine Quint  <graouts@webkit.org>
    235
  • trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp

    r287552 r287821  
    9292{
    9393    auto sourceCGColorSpace = CGColorGetColorSpace(color);
    94 #if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
     94#if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE)
    9595    auto destinationCGColorSpace = xyzD50ColorSpaceRef();
    9696    auto destinationColorSpace = ColorSpace::XYZ_D50;
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp

    r287481 r287821  
    142142#endif
    143143
    144 #if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
     144#if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE)
    145145CGColorSpaceRef xyzD50ColorSpaceRef()
    146146{
     
    217217#endif
    218218
    219 #if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
     219#if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE)
    220220    if (CGColorSpaceEqualToColorSpace(colorSpace, xyzD50ColorSpaceRef()))
    221221        return ColorSpace::XYZ_D50;
  • trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h

    r287481 r287821  
    3535namespace WebCore {
    3636
     37template<ColorSpace> struct CGColorSpaceMapping;
     38
    3739WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
     40template<> struct CGColorSpaceMapping<ColorSpace::SRGB> { static CGColorSpaceRef colorSpace() { return sRGBColorSpaceRef(); } };
    3841
    3942#if HAVE(CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE)
    4043WEBCORE_EXPORT CGColorSpaceRef adobeRGB1998ColorSpaceRef();
     44template<> struct CGColorSpaceMapping<ColorSpace::A98RGB> { static CGColorSpaceRef colorSpace() { return adobeRGB1998ColorSpaceRef(); } };
     45#else
     46template<> struct CGColorSpaceMapping<ColorSpace::A98RGB> { };
    4147#endif
    4248
    4349#if HAVE(CORE_GRAPHICS_DISPLAY_P3_COLOR_SPACE)
    4450WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
     51template<> struct CGColorSpaceMapping<ColorSpace::DisplayP3> { static CGColorSpaceRef colorSpace() { return displayP3ColorSpaceRef(); } };
     52#else
     53template<> struct CGColorSpaceMapping<ColorSpace::DisplayP3> { };
    4554#endif
    4655
    4756#if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE)
    4857WEBCORE_EXPORT CGColorSpaceRef extendedAdobeRGB1998ColorSpaceRef();
     58template<> struct CGColorSpaceMapping<ColorSpace::ExtendedA98RGB> { static CGColorSpaceRef colorSpace() { return extendedAdobeRGB1998ColorSpaceRef(); } };
     59#else
     60template<> struct CGColorSpaceMapping<ColorSpace::ExtendedA98RGB> { };
    4961#endif
    5062
    5163#if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE)
    5264WEBCORE_EXPORT CGColorSpaceRef extendedDisplayP3ColorSpaceRef();
     65template<> struct CGColorSpaceMapping<ColorSpace::ExtendedDisplayP3> { static CGColorSpaceRef colorSpace() { return extendedDisplayP3ColorSpaceRef(); } };
     66#else
     67template<> struct CGColorSpaceMapping<ColorSpace::ExtendedDisplayP3> { };
    5368#endif
    5469
    5570#if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE)
    5671WEBCORE_EXPORT CGColorSpaceRef extendedITUR_2020ColorSpaceRef();
     72template<> struct CGColorSpaceMapping<ColorSpace::ExtendedRec2020> { static CGColorSpaceRef colorSpace() { return extendedITUR_2020ColorSpaceRef(); } };
     73#else
     74template<> struct CGColorSpaceMapping<ColorSpace::ExtendedRec2020> { };
    5775#endif
    5876
    5977#if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE)
    6078WEBCORE_EXPORT CGColorSpaceRef extendedLinearSRGBColorSpaceRef();
     79template<> struct CGColorSpaceMapping<ColorSpace::ExtendedLinearSRGB> { static CGColorSpaceRef colorSpace() { return extendedLinearSRGBColorSpaceRef(); } };
     80#else
     81template<> struct CGColorSpaceMapping<ColorSpace::ExtendedLinearSRGB> { };
    6182#endif
    6283
    6384#if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE)
    6485WEBCORE_EXPORT CGColorSpaceRef extendedROMMRGBColorSpaceRef();
     86template<> struct CGColorSpaceMapping<ColorSpace::ExtendedProPhotoRGB> { static CGColorSpaceRef colorSpace() { return extendedROMMRGBColorSpaceRef(); } };
     87#else
     88template<> struct CGColorSpaceMapping<ColorSpace::ExtendedProPhotoRGB> { };
    6589#endif
    6690
    6791#if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE)
    6892WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
     93template<> struct CGColorSpaceMapping<ColorSpace::ExtendedSRGB> { static CGColorSpaceRef colorSpace() { return extendedSRGBColorSpaceRef(); } };
     94#else
     95template<> struct CGColorSpaceMapping<ColorSpace::ExtendedSRGB> { };
    6996#endif
    7097
    7198#if HAVE(CORE_GRAPHICS_ITUR_2020_COLOR_SPACE)
    7299WEBCORE_EXPORT CGColorSpaceRef ITUR_2020ColorSpaceRef();
     100template<> struct CGColorSpaceMapping<ColorSpace::Rec2020> { static CGColorSpaceRef colorSpace() { return ITUR_2020ColorSpaceRef(); } };
     101#else
     102template<> struct CGColorSpaceMapping<ColorSpace::Rec2020> { };
    73103#endif
    74104
    75105#if HAVE(CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE)
    76106WEBCORE_EXPORT CGColorSpaceRef linearSRGBColorSpaceRef();
     107template<> struct CGColorSpaceMapping<ColorSpace::LinearSRGB> { static CGColorSpaceRef colorSpace() { return linearSRGBColorSpaceRef(); } };
     108#else
     109template<> struct CGColorSpaceMapping<ColorSpace::LinearSRGB> { };
    77110#endif
    78111
    79112#if HAVE(CORE_GRAPHICS_ROMMRGB_COLOR_SPACE)
    80113WEBCORE_EXPORT CGColorSpaceRef ROMMRGBColorSpaceRef();
    81 #endif
    82 
    83 #if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
     114template<> struct CGColorSpaceMapping<ColorSpace::ProPhotoRGB> { static CGColorSpaceRef colorSpace() { return ROMMRGBColorSpaceRef(); } };
     115#else
     116template<> struct CGColorSpaceMapping<ColorSpace::ProPhotoRGB> { };
     117#endif
     118
     119#if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE)
    84120WEBCORE_EXPORT CGColorSpaceRef xyzD50ColorSpaceRef();
    85 #endif
     121template<> struct CGColorSpaceMapping<ColorSpace::XYZ_D50> { static CGColorSpaceRef colorSpace() { return xyzD50ColorSpaceRef(); } };
     122#else
     123template<> struct CGColorSpaceMapping<ColorSpace::XYZ_D50> { };
     124#endif
     125
     126// FIXME: Add support for these once/if CoreGraphics adds support for them.
     127template<> struct CGColorSpaceMapping<ColorSpace::HSL> { };
     128template<> struct CGColorSpaceMapping<ColorSpace::HWB> { };
     129template<> struct CGColorSpaceMapping<ColorSpace::LCH> { };
     130template<> struct CGColorSpaceMapping<ColorSpace::Lab> { };
     131template<> struct CGColorSpaceMapping<ColorSpace::OKLab> { };
     132template<> struct CGColorSpaceMapping<ColorSpace::OKLCH> { };
     133template<> struct CGColorSpaceMapping<ColorSpace::XYZ_D65> { };
     134
    86135
    87136std::optional<ColorSpace> colorSpaceForCGColorSpace(CGColorSpaceRef);
     137
     138
     139template<ColorSpace, typename = void> inline constexpr bool HasCGColorSpaceMapping = false;
     140template<ColorSpace space> inline constexpr bool HasCGColorSpaceMapping<space, std::void_t<decltype(CGColorSpaceMapping<space>::colorSpace())>> = true;
     141static_assert(HasCGColorSpaceMapping<ColorSpace::SRGB>, "An SRGB color space mapping must be supported on all platforms.");
     142
     143template<ColorSpace space, bool = HasCGColorSpaceMapping<space>> struct CGColorSpaceMappingOrNullGetter { static CGColorSpaceRef colorSpace() { return nullptr; } };
     144template<ColorSpace space> struct CGColorSpaceMappingOrNullGetter<space, true> { static CGColorSpaceRef colorSpace() { return CGColorSpaceMapping<space>::colorSpace(); } };
     145
     146template<ColorSpace space> CGColorSpaceRef cachedCGColorSpace()
     147{
     148    return CGColorSpaceMapping<space>::colorSpace();
     149}
     150
     151template<ColorSpace space> CGColorSpaceRef cachedNullableCGColorSpace()
     152{
     153    return CGColorSpaceMappingOrNullGetter<space>::colorSpace();
     154}
    88155
    89156static inline CGColorSpaceRef cachedNullableCGColorSpace(ColorSpace colorSpace)
    90157{
    91158    switch (colorSpace) {
     159    case ColorSpace::A98RGB:
     160        return cachedNullableCGColorSpace<ColorSpace::A98RGB>();
     161    case ColorSpace::DisplayP3:
     162        return cachedNullableCGColorSpace<ColorSpace::DisplayP3>();
     163    case ColorSpace::ExtendedA98RGB:
     164        return cachedNullableCGColorSpace<ColorSpace::ExtendedA98RGB>();
     165    case ColorSpace::ExtendedDisplayP3:
     166        return cachedNullableCGColorSpace<ColorSpace::ExtendedDisplayP3>();
     167    case ColorSpace::ExtendedLinearSRGB:
     168        return cachedNullableCGColorSpace<ColorSpace::ExtendedLinearSRGB>();
     169    case ColorSpace::ExtendedProPhotoRGB:
     170        return cachedNullableCGColorSpace<ColorSpace::ExtendedProPhotoRGB>();
     171    case ColorSpace::ExtendedRec2020:
     172        return cachedNullableCGColorSpace<ColorSpace::ExtendedRec2020>();
     173    case ColorSpace::ExtendedSRGB:
     174        return cachedNullableCGColorSpace<ColorSpace::ExtendedSRGB>();
     175    case ColorSpace::HSL:
     176        return cachedNullableCGColorSpace<ColorSpace::HSL>();
     177    case ColorSpace::HWB:
     178        return cachedNullableCGColorSpace<ColorSpace::HWB>();
     179    case ColorSpace::LCH:
     180        return cachedNullableCGColorSpace<ColorSpace::LCH>();
     181    case ColorSpace::Lab:
     182        return cachedNullableCGColorSpace<ColorSpace::Lab>();
     183    case ColorSpace::LinearSRGB:
     184        return cachedNullableCGColorSpace<ColorSpace::LinearSRGB>();
     185    case ColorSpace::OKLCH:
     186        return cachedNullableCGColorSpace<ColorSpace::OKLCH>();
     187    case ColorSpace::OKLab:
     188        return cachedNullableCGColorSpace<ColorSpace::OKLab>();
     189    case ColorSpace::ProPhotoRGB:
     190        return cachedNullableCGColorSpace<ColorSpace::ProPhotoRGB>();
     191    case ColorSpace::Rec2020:
     192        return cachedNullableCGColorSpace<ColorSpace::Rec2020>();
    92193    case ColorSpace::SRGB:
    93         return sRGBColorSpaceRef();
    94 
    95     case ColorSpace::A98RGB:
    96 #if HAVE(CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE)
    97         return adobeRGB1998ColorSpaceRef();
    98 #else
    99         return nullptr;
    100 #endif
    101 
    102     case ColorSpace::DisplayP3:
    103 #if HAVE(CORE_GRAPHICS_DISPLAY_P3_COLOR_SPACE)
    104         return displayP3ColorSpaceRef();
    105 #else
    106         return nullptr;
    107 #endif
    108 
    109     case ColorSpace::ExtendedA98RGB:
    110 #if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE)
    111         return extendedAdobeRGB1998ColorSpaceRef();
    112 #else
    113         return nullptr;
    114 #endif
    115 
    116     case ColorSpace::ExtendedDisplayP3:
    117 #if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE)
    118         return extendedDisplayP3ColorSpaceRef();
    119 #else
    120         return nullptr;
    121 #endif
    122 
    123     case ColorSpace::ExtendedLinearSRGB:
    124 #if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE)
    125         return extendedLinearSRGBColorSpaceRef();
    126 #else
    127         return nullptr;
    128 #endif
    129 
    130     case ColorSpace::ExtendedProPhotoRGB:
    131 #if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE)
    132         return extendedROMMRGBColorSpaceRef();
    133 #else
    134         return nullptr;
    135 #endif
    136 
    137     case ColorSpace::ExtendedRec2020:
    138 #if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE)
    139         return extendedITUR_2020ColorSpaceRef();
    140 #else
    141         return nullptr;
    142 #endif
    143 
    144     case ColorSpace::ExtendedSRGB:
    145 #if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE)
    146         return extendedSRGBColorSpaceRef();
    147 #else
    148         return nullptr;
    149 #endif
    150 
    151     case ColorSpace::LinearSRGB:
    152 #if HAVE(CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE)
    153         return linearSRGBColorSpaceRef();
    154 #else
    155         return nullptr;
    156 #endif
    157 
    158     case ColorSpace::ProPhotoRGB:
    159 #if HAVE(CORE_GRAPHICS_ROMMRGB_COLOR_SPACE)
    160         return ROMMRGBColorSpaceRef();
    161 #else
    162         return nullptr;
    163 #endif
    164 
    165     case ColorSpace::Rec2020:
    166 #if HAVE(CORE_GRAPHICS_ITUR_2020_COLOR_SPACE)
    167         return ITUR_2020ColorSpaceRef();
    168 #else
    169         return nullptr;
    170 #endif
    171 
     194        return cachedNullableCGColorSpace<ColorSpace::SRGB>();
    172195    case ColorSpace::XYZ_D50:
    173 #if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE)
    174         return xyzD50ColorSpaceRef();
    175 #else
    176         return nullptr;
    177 #endif
    178 
    179     // FIXME: Add support for these once/if CoreGraphics adds support for it.
    180     case ColorSpace::HSL:
    181     case ColorSpace::HWB:
    182     case ColorSpace::LCH:
    183     case ColorSpace::Lab:
    184     case ColorSpace::OKLCH:
    185     case ColorSpace::OKLab:
     196        return cachedNullableCGColorSpace<ColorSpace::XYZ_D50>();
    186197    case ColorSpace::XYZ_D65:
    187         return nullptr;
    188 
    189 
     198        return cachedNullableCGColorSpace<ColorSpace::XYZ_D65>();
    190199    }
     200
    191201    ASSERT_NOT_REACHED();
    192202    return nullptr;
Note: See TracChangeset for help on using the changeset viewer.