Changeset 287821 in webkit
- Timestamp:
- Jan 9, 2022, 10:06:02 AM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 5 edited
-
WTF/ChangeLog (modified) (1 diff)
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/platform/graphics/cg/ColorCG.cpp (modified) (1 diff)
-
WebCore/platform/graphics/cg/ColorSpaceCG.cpp (modified) (2 diffs)
-
WebCore/platform/graphics/cg/ColorSpaceCG.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r287784 r287821 1 2022-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 1 12 2022-01-07 Tim Horton <timothy_horton@apple.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r287820 r287821 1 2022-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 1 34 2022-01-08 Antoine Quint <graouts@webkit.org> 2 35 -
trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp
r287552 r287821 92 92 { 93 93 auto sourceCGColorSpace = CGColorGetColorSpace(color); 94 #if HAVE(CORE_GRAPHICS_XYZ_ COLOR_SPACE)94 #if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE) 95 95 auto destinationCGColorSpace = xyzD50ColorSpaceRef(); 96 96 auto destinationColorSpace = ColorSpace::XYZ_D50; -
trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp
r287481 r287821 142 142 #endif 143 143 144 #if HAVE(CORE_GRAPHICS_XYZ_ COLOR_SPACE)144 #if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE) 145 145 CGColorSpaceRef xyzD50ColorSpaceRef() 146 146 { … … 217 217 #endif 218 218 219 #if HAVE(CORE_GRAPHICS_XYZ_ COLOR_SPACE)219 #if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE) 220 220 if (CGColorSpaceEqualToColorSpace(colorSpace, xyzD50ColorSpaceRef())) 221 221 return ColorSpace::XYZ_D50; -
trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h
r287481 r287821 35 35 namespace WebCore { 36 36 37 template<ColorSpace> struct CGColorSpaceMapping; 38 37 39 WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef(); 40 template<> struct CGColorSpaceMapping<ColorSpace::SRGB> { static CGColorSpaceRef colorSpace() { return sRGBColorSpaceRef(); } }; 38 41 39 42 #if HAVE(CORE_GRAPHICS_ADOBE_RGB_1998_COLOR_SPACE) 40 43 WEBCORE_EXPORT CGColorSpaceRef adobeRGB1998ColorSpaceRef(); 44 template<> struct CGColorSpaceMapping<ColorSpace::A98RGB> { static CGColorSpaceRef colorSpace() { return adobeRGB1998ColorSpaceRef(); } }; 45 #else 46 template<> struct CGColorSpaceMapping<ColorSpace::A98RGB> { }; 41 47 #endif 42 48 43 49 #if HAVE(CORE_GRAPHICS_DISPLAY_P3_COLOR_SPACE) 44 50 WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef(); 51 template<> struct CGColorSpaceMapping<ColorSpace::DisplayP3> { static CGColorSpaceRef colorSpace() { return displayP3ColorSpaceRef(); } }; 52 #else 53 template<> struct CGColorSpaceMapping<ColorSpace::DisplayP3> { }; 45 54 #endif 46 55 47 56 #if HAVE(CORE_GRAPHICS_EXTENDED_ADOBE_RGB_1998_COLOR_SPACE) 48 57 WEBCORE_EXPORT CGColorSpaceRef extendedAdobeRGB1998ColorSpaceRef(); 58 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedA98RGB> { static CGColorSpaceRef colorSpace() { return extendedAdobeRGB1998ColorSpaceRef(); } }; 59 #else 60 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedA98RGB> { }; 49 61 #endif 50 62 51 63 #if HAVE(CORE_GRAPHICS_EXTENDED_DISPLAY_P3_COLOR_SPACE) 52 64 WEBCORE_EXPORT CGColorSpaceRef extendedDisplayP3ColorSpaceRef(); 65 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedDisplayP3> { static CGColorSpaceRef colorSpace() { return extendedDisplayP3ColorSpaceRef(); } }; 66 #else 67 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedDisplayP3> { }; 53 68 #endif 54 69 55 70 #if HAVE(CORE_GRAPHICS_EXTENDED_ITUR_2020_COLOR_SPACE) 56 71 WEBCORE_EXPORT CGColorSpaceRef extendedITUR_2020ColorSpaceRef(); 72 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedRec2020> { static CGColorSpaceRef colorSpace() { return extendedITUR_2020ColorSpaceRef(); } }; 73 #else 74 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedRec2020> { }; 57 75 #endif 58 76 59 77 #if HAVE(CORE_GRAPHICS_EXTENDED_LINEAR_SRGB_COLOR_SPACE) 60 78 WEBCORE_EXPORT CGColorSpaceRef extendedLinearSRGBColorSpaceRef(); 79 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedLinearSRGB> { static CGColorSpaceRef colorSpace() { return extendedLinearSRGBColorSpaceRef(); } }; 80 #else 81 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedLinearSRGB> { }; 61 82 #endif 62 83 63 84 #if HAVE(CORE_GRAPHICS_EXTENDED_ROMMRGB_COLOR_SPACE) 64 85 WEBCORE_EXPORT CGColorSpaceRef extendedROMMRGBColorSpaceRef(); 86 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedProPhotoRGB> { static CGColorSpaceRef colorSpace() { return extendedROMMRGBColorSpaceRef(); } }; 87 #else 88 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedProPhotoRGB> { }; 65 89 #endif 66 90 67 91 #if HAVE(CORE_GRAPHICS_EXTENDED_SRGB_COLOR_SPACE) 68 92 WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef(); 93 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedSRGB> { static CGColorSpaceRef colorSpace() { return extendedSRGBColorSpaceRef(); } }; 94 #else 95 template<> struct CGColorSpaceMapping<ColorSpace::ExtendedSRGB> { }; 69 96 #endif 70 97 71 98 #if HAVE(CORE_GRAPHICS_ITUR_2020_COLOR_SPACE) 72 99 WEBCORE_EXPORT CGColorSpaceRef ITUR_2020ColorSpaceRef(); 100 template<> struct CGColorSpaceMapping<ColorSpace::Rec2020> { static CGColorSpaceRef colorSpace() { return ITUR_2020ColorSpaceRef(); } }; 101 #else 102 template<> struct CGColorSpaceMapping<ColorSpace::Rec2020> { }; 73 103 #endif 74 104 75 105 #if HAVE(CORE_GRAPHICS_LINEAR_SRGB_COLOR_SPACE) 76 106 WEBCORE_EXPORT CGColorSpaceRef linearSRGBColorSpaceRef(); 107 template<> struct CGColorSpaceMapping<ColorSpace::LinearSRGB> { static CGColorSpaceRef colorSpace() { return linearSRGBColorSpaceRef(); } }; 108 #else 109 template<> struct CGColorSpaceMapping<ColorSpace::LinearSRGB> { }; 77 110 #endif 78 111 79 112 #if HAVE(CORE_GRAPHICS_ROMMRGB_COLOR_SPACE) 80 113 WEBCORE_EXPORT CGColorSpaceRef ROMMRGBColorSpaceRef(); 81 #endif 82 83 #if HAVE(CORE_GRAPHICS_XYZ_COLOR_SPACE) 114 template<> struct CGColorSpaceMapping<ColorSpace::ProPhotoRGB> { static CGColorSpaceRef colorSpace() { return ROMMRGBColorSpaceRef(); } }; 115 #else 116 template<> struct CGColorSpaceMapping<ColorSpace::ProPhotoRGB> { }; 117 #endif 118 119 #if HAVE(CORE_GRAPHICS_XYZ_D50_COLOR_SPACE) 84 120 WEBCORE_EXPORT CGColorSpaceRef xyzD50ColorSpaceRef(); 85 #endif 121 template<> struct CGColorSpaceMapping<ColorSpace::XYZ_D50> { static CGColorSpaceRef colorSpace() { return xyzD50ColorSpaceRef(); } }; 122 #else 123 template<> struct CGColorSpaceMapping<ColorSpace::XYZ_D50> { }; 124 #endif 125 126 // FIXME: Add support for these once/if CoreGraphics adds support for them. 127 template<> struct CGColorSpaceMapping<ColorSpace::HSL> { }; 128 template<> struct CGColorSpaceMapping<ColorSpace::HWB> { }; 129 template<> struct CGColorSpaceMapping<ColorSpace::LCH> { }; 130 template<> struct CGColorSpaceMapping<ColorSpace::Lab> { }; 131 template<> struct CGColorSpaceMapping<ColorSpace::OKLab> { }; 132 template<> struct CGColorSpaceMapping<ColorSpace::OKLCH> { }; 133 template<> struct CGColorSpaceMapping<ColorSpace::XYZ_D65> { }; 134 86 135 87 136 std::optional<ColorSpace> colorSpaceForCGColorSpace(CGColorSpaceRef); 137 138 139 template<ColorSpace, typename = void> inline constexpr bool HasCGColorSpaceMapping = false; 140 template<ColorSpace space> inline constexpr bool HasCGColorSpaceMapping<space, std::void_t<decltype(CGColorSpaceMapping<space>::colorSpace())>> = true; 141 static_assert(HasCGColorSpaceMapping<ColorSpace::SRGB>, "An SRGB color space mapping must be supported on all platforms."); 142 143 template<ColorSpace space, bool = HasCGColorSpaceMapping<space>> struct CGColorSpaceMappingOrNullGetter { static CGColorSpaceRef colorSpace() { return nullptr; } }; 144 template<ColorSpace space> struct CGColorSpaceMappingOrNullGetter<space, true> { static CGColorSpaceRef colorSpace() { return CGColorSpaceMapping<space>::colorSpace(); } }; 145 146 template<ColorSpace space> CGColorSpaceRef cachedCGColorSpace() 147 { 148 return CGColorSpaceMapping<space>::colorSpace(); 149 } 150 151 template<ColorSpace space> CGColorSpaceRef cachedNullableCGColorSpace() 152 { 153 return CGColorSpaceMappingOrNullGetter<space>::colorSpace(); 154 } 88 155 89 156 static inline CGColorSpaceRef cachedNullableCGColorSpace(ColorSpace colorSpace) 90 157 { 91 158 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>(); 92 193 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>(); 172 195 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>(); 186 197 case ColorSpace::XYZ_D65: 187 return nullptr; 188 189 198 return cachedNullableCGColorSpace<ColorSpace::XYZ_D65>(); 190 199 } 200 191 201 ASSERT_NOT_REACHED(); 192 202 return nullptr;
Note:
See TracChangeset
for help on using the changeset viewer.