Diff
Modified: trunk/Source/WebCore/ChangeLog (271088 => 271089)
--- trunk/Source/WebCore/ChangeLog 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/ChangeLog 2020-12-26 17:42:33 UTC (rev 271089)
@@ -1,3 +1,107 @@
+2020-12-26 Sam Weinig <wei...@apple.com>
+
+ Simplify adding new color spaces to WebCore
+ https://bugs.webkit.org/show_bug.cgi?id=220146
+
+ Reviewed by Dean Jackson.
+
+ Reduce the number of places one needs to touch when adding new color types to:
+
+ - ColorTypes.h
+ - ColorConversion.h/cpp
+ - ColorSpace.h/cpp (only needed if support in Color is required).
+ - ColorSerialization.h (only needed if support in Color is required).
+ - ColorSpaceCG.h/cpp (only needed if support in Color is required).
+
+ * Sources.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ Add ColorSpace.cpp, ColorSpaceCG.h and ColorSpaceCG.cpp.
+
+ * platform/graphics/Color.cpp:
+ * platform/graphics/Color.h:
+ (WebCore::Color::Color):
+ (WebCore::Color::setColor):
+ Replace specific overloads of the contructor and setColor with template functions
+ that do the same things. These are safe to make as if a non-supported color type
+ (one that doesn't have a colorSpace member) is passed it will fail to compile due
+ to use beneath ExtendedColor::create().
+
+ Also moves WTF::TextStream operator<< overload for ColorSpace out and into
+ ColorSpace.cpp where it makes more sense.
+
+ * platform/graphics/ColorConversion.cpp:
+ * platform/graphics/ColorConversion.h:
+ Re-order and explicitly comment conversion functions to be more clear.
+
+ As the comment indicates, all color types must implement at least the following
+ conversions:
+ XYZA<float> toXYZA(const ColorType<float>&);
+ ColorType<float> toColorType(const XYZA<float>&);
+
+ This allows generic fallback code, inline at the bottom of the header, to
+ support conversion to and from any set of colors. Additional conversion functions
+ are useful for the cases where the optimal or base conversion is not through XYZ
+ such as from SRGBA to LinearSRGBA.
+
+ To allow this to work a few additional conversion functions were added which just
+ combine existing conversions together and one was added for SRGBA to CMYKA which
+ was missing, though currently unused.
+
+ * platform/graphics/ColorSpace.cpp: Added.
+ (WebCore::operator<<):
+ * platform/graphics/ColorSpace.h:
+ Moved from Color.h
+
+ * platform/graphics/ColorTypes.h:
+ (WebCore::callWithColorType):
+ This is a generalization of ExtendedColor::callOnUnderlyingType() that also
+ has the benefit of now being in the same file as the color type definitions,
+ reducing the number of files people need to touch.
+
+ * platform/graphics/ColorUtilities.h:
+ (WebCore::colorByModifingEachNonAlphaComponent):
+ Update to not assume that colors use the names red/green/blue for non-alpha
+ components. This makes it work generically for all four component color types.
+
+ * platform/graphics/ExtendedColor.h:
+ (WebCore::ExtendedColor::callOnUnderlyingType const):
+ Use generalized form, callWithColorType to avoid requiring modiftying this
+ when new color types are added.
+
+ * platform/graphics/cg/ColorCG.cpp:
+ (WebCore::leakCGColor):
+ When going to generalize this (we could have simply called
+ `return CGColorCreate(cachedCGColorSpace(colorSpace), cgFloatComponents))`
+ I noticed this was not doing the right thing for CG ports that don't support
+ all the color spaces WebCore requires (such as Windows). For instance,
+ displayP3ColorSpaceRef() just returns sRGBColorSpaceRef() on windows, meaning
+ we would be taking some DisplayP3 components and having CG interpret them as
+ sRGB. To avoid this, we now check if the color space returned is the fallback
+ color space, sRGB, and do our own conversion to sRGB using ColorConversion
+ before creating the color.
+
+ This also resolves a long standing bug / FIXME around LinearRGB where we were
+ using sRGBColorSpaceRef() for them. In practice, we don't actually ever create
+ LinearRGB CGColorRefs right now, but if we ever do in the future, makes sense
+ to use the right color space.
+
+ * platform/graphics/cg/ColorSpaceCG.cpp: Added.
+ (WebCore::sRGBColorSpaceRef):
+ (WebCore::linearRGBColorSpaceRef):
+ (WebCore::displayP3ColorSpaceRef):
+ (WebCore::extendedSRGBColorSpaceRef):
+ * platform/graphics/cg/ColorSpaceCG.h: Added.
+ (WebCore::cachedCGColorSpace):
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::sRGBColorSpaceRef): Deleted.
+ (WebCore::linearRGBColorSpaceRef): Deleted.
+ (WebCore::extendedSRGBColorSpaceRef): Deleted.
+ (WebCore::displayP3ColorSpaceRef): Deleted.
+ * platform/graphics/cg/GraphicsContextCG.h:
+ (WebCore::cachedCGColorSpace): Deleted.
+ Moved color space specific CG code to its own files to make it more clear
+ where to find them.
+
2020-12-26 Zalan Bujtas <za...@apple.com>
[LFC][Integration] Set pre-computed inline box geometries (margin, border and padding)
Modified: trunk/Source/WebCore/PlatformAppleWin.cmake (271088 => 271089)
--- trunk/Source/WebCore/PlatformAppleWin.cmake 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/PlatformAppleWin.cmake 2020-12-26 17:42:33 UTC (rev 271089)
@@ -128,6 +128,7 @@
platform/graphics/ca/win/WebTiledBackingLayerWin.cpp
platform/graphics/cg/ColorCG.cpp
+ platform/graphics/cg/ColorSpaceCG.cpp
platform/graphics/cg/FloatPointCG.cpp
platform/graphics/cg/FloatRectCG.cpp
platform/graphics/cg/FloatSizeCG.cpp
@@ -182,6 +183,7 @@
platform/graphics/ca/win/CACFLayerTreeHostClient.h
platform/graphics/ca/win/PlatformCALayerWin.h
+ platform/graphics/cg/ColorSpaceCG.h
platform/graphics/cg/GraphicsContextCG.h
platform/graphics/cg/IOSurfacePool.h
platform/graphics/cg/ImageBufferCGBackend.h
Modified: trunk/Source/WebCore/PlatformMac.cmake (271088 => 271089)
--- trunk/Source/WebCore/PlatformMac.cmake 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/PlatformMac.cmake 2020-12-26 17:42:33 UTC (rev 271089)
@@ -279,6 +279,7 @@
platform/graphics/ca/cocoa/WebTiledBackingLayer.mm
platform/graphics/cg/ColorCG.cpp
+ platform/graphics/cg/ColorSpaceCG.cpp
platform/graphics/cg/FloatPointCG.cpp
platform/graphics/cg/FloatRectCG.cpp
platform/graphics/cg/FloatSizeCG.cpp
@@ -544,6 +545,7 @@
platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.h
platform/graphics/ca/cocoa/PlatformCALayerCocoa.h
+ platform/graphics/cg/ColorSpaceCG.h
platform/graphics/cg/GraphicsContextCG.h
platform/graphics/cg/IOSurfacePool.h
platform/graphics/cg/ImageBufferCGBackend.h
Modified: trunk/Source/WebCore/Sources.txt (271088 => 271089)
--- trunk/Source/WebCore/Sources.txt 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/Sources.txt 2020-12-26 17:42:33 UTC (rev 271089)
@@ -1911,6 +1911,7 @@
platform/graphics/ColorBlending.cpp
platform/graphics/ColorConversion.cpp
platform/graphics/ColorSerialization.cpp
+platform/graphics/ColorSpace.cpp
platform/graphics/ColorUtilities.cpp
platform/graphics/ComplexTextController.cpp
platform/graphics/CrossfadeGeneratedImage.cpp
Modified: trunk/Source/WebCore/SourcesCocoa.txt (271088 => 271089)
--- trunk/Source/WebCore/SourcesCocoa.txt 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/SourcesCocoa.txt 2020-12-26 17:42:33 UTC (rev 271089)
@@ -327,6 +327,7 @@
platform/graphics/ca/cocoa/WebTiledBackingLayer.mm
platform/graphics/ca/cocoa/WebVideoContainerLayer.mm
platform/graphics/cg/ColorCG.cpp
+platform/graphics/cg/ColorSpaceCG.cpp
platform/graphics/cg/FloatPointCG.cpp
platform/graphics/cg/FloatRectCG.cpp
platform/graphics/cg/FloatSizeCG.cpp
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (271088 => 271089)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2020-12-26 17:42:33 UTC (rev 271089)
@@ -4034,6 +4034,7 @@
BCAB418213E356E800D8AAF3 /* Region.h in Headers */ = {isa = PBXBuildFile; fileRef = BCAB418013E356E800D8AAF3 /* Region.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCACF3BD1072921A00C0C8A3 /* UserContentURLPattern.h in Headers */ = {isa = PBXBuildFile; fileRef = BCACF3BB1072921A00C0C8A3 /* UserContentURLPattern.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCAE1FA712939DB7004CB026 /* ScrollAnimatorMac.h in Headers */ = {isa = PBXBuildFile; fileRef = BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */; };
+ BCAFEDB425968D0B0030E6AA /* ColorSpaceCG.h in Headers */ = {isa = PBXBuildFile; fileRef = BCAFEDB225968D0B0030E6AA /* ColorSpaceCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCB16C180979C3BD00467741 /* MemoryCache.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB16BFF0979C3BD00467741 /* MemoryCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCB16C1A0979C3BD00467741 /* CachedCSSStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB16C010979C3BD00467741 /* CachedCSSStyleSheet.h */; };
BCB16C1C0979C3BD00467741 /* CachedImage.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB16C030979C3BD00467741 /* CachedImage.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -14113,6 +14114,9 @@
BCACF3BB1072921A00C0C8A3 /* UserContentURLPattern.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UserContentURLPattern.h; sourceTree = "<group>"; };
BCAD1809131C7A0D00990406 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = SOURCE_ROOT; };
BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollAnimatorMac.h; sourceTree = "<group>"; };
+ BCAFEDAF25966D050030E6AA /* ColorSpace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorSpace.cpp; sourceTree = "<group>"; };
+ BCAFEDB225968D0B0030E6AA /* ColorSpaceCG.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ColorSpaceCG.h; sourceTree = "<group>"; };
+ BCAFEDB325968D0B0030E6AA /* ColorSpaceCG.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ColorSpaceCG.cpp; sourceTree = "<group>"; };
BCB16BFE0979C3BD00467741 /* MemoryCache.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryCache.cpp; sourceTree = "<group>"; };
BCB16BFF0979C3BD00467741 /* MemoryCache.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MemoryCache.h; sourceTree = "<group>"; };
BCB16C000979C3BD00467741 /* CachedCSSStyleSheet.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = CachedCSSStyleSheet.cpp; sourceTree = "<group>"; };
@@ -26417,6 +26421,8 @@
isa = PBXGroup;
children = (
0FCF33230F2B9715004B6795 /* ColorCG.cpp */,
+ BCAFEDB325968D0B0030E6AA /* ColorSpaceCG.cpp */,
+ BCAFEDB225968D0B0030E6AA /* ColorSpaceCG.h */,
B275352B0B053814002CE64F /* FloatPointCG.cpp */,
B275352C0B053814002CE64F /* FloatRectCG.cpp */,
B275352D0B053814002CE64F /* FloatSizeCG.cpp */,
@@ -26522,6 +26528,7 @@
7CAC6AE8247F082000E61D59 /* ColorMatrix.h */,
7CD1E69224ABF6240089C419 /* ColorSerialization.cpp */,
7CD1E69124ABF6240089C419 /* ColorSerialization.h */,
+ BCAFEDAF25966D050030E6AA /* ColorSpace.cpp */,
9382DF5710A8D5C900925652 /* ColorSpace.h */,
7C029C6D2493C8F800268204 /* ColorTypes.h */,
0FE6C76B1FBFB7A60025C053 /* ColorUtilities.cpp */,
@@ -34808,6 +34815,7 @@
B22279F20D00BF220071B782 /* SVGFELightElement.h in Headers */,
B22279F40D00BF220071B782 /* SVGFEMergeElement.h in Headers */,
B22279F70D00BF220071B782 /* SVGFEMergeNodeElement.h in Headers */,
+ BCAFEDB425968D0B0030E6AA /* ColorSpaceCG.h in Headers */,
84224194107E78A700766A87 /* SVGFEMorphologyElement.h in Headers */,
B22279FA0D00BF220071B782 /* SVGFEOffsetElement.h in Headers */,
B22279FD0D00BF220071B782 /* SVGFEPointLightElement.h in Headers */,
Modified: trunk/Source/WebCore/platform/graphics/Color.cpp (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/Color.cpp 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/Color.cpp 2020-12-26 17:42:33 UTC (rev 271089)
@@ -165,20 +165,4 @@
return ts << serializationForRenderTreeAsText(color);
}
-TextStream& operator<<(TextStream& ts, ColorSpace colorSpace)
-{
- switch (colorSpace) {
- case ColorSpace::SRGB:
- ts << "sRGB";
- break;
- case ColorSpace::LinearRGB:
- ts << "LinearRGB";
- break;
- case ColorSpace::DisplayP3:
- ts << "DisplayP3";
- break;
- }
- return ts;
-}
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/Color.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/Color.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/Color.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -181,9 +181,6 @@
Color(Ref<ExtendedColor>&&);
void setColor(SRGBA<uint8_t>);
- void setColor(const SRGBA<float>&);
- void setColor(const LinearSRGBA<float>&);
- void setColor(const DisplayP3<float>&);
void setExtendedColor(Ref<ExtendedColor>&&);
void tagAsSemantic() { m_colorData.inlineColorAndFlags |= isSemanticInlineColorBit; }
@@ -218,7 +215,6 @@
#endif
WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, const Color&);
-WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace);
inline bool operator==(const Color& a, const Color& b)
{
@@ -276,32 +272,22 @@
inline Color::Color(ColorComponents<float> components, ColorSpace colorSpace)
{
- switch (colorSpace) {
- case ColorSpace::SRGB:
- setColor(asSRGBA(components));
- return;
- case ColorSpace::LinearRGB:
- setColor(asLinearSRGBA(components));
- return;
- case ColorSpace::DisplayP3:
- setColor(asDisplayP3(components));
- return;
- }
+ setExtendedColor(ExtendedColor::create(components, colorSpace));
}
inline Color::Color(const SRGBA<float>& color)
{
- setColor(color);
+ setExtendedColor(ExtendedColor::create(color));
}
inline Color::Color(const LinearSRGBA<float>& color)
{
- setColor(color);
+ setExtendedColor(ExtendedColor::create(color));
}
inline Color::Color(const DisplayP3<float>& color)
{
- setColor(color);
+ setExtendedColor(ExtendedColor::create(color));
}
inline Color::Color(Ref<ExtendedColor>&& extendedColor)
@@ -402,21 +388,6 @@
tagAsValid();
}
-inline void Color::setColor(const SRGBA<float>& color)
-{
- setExtendedColor(ExtendedColor::create(color));
-}
-
-inline void Color::setColor(const LinearSRGBA<float>& color)
-{
- setExtendedColor(ExtendedColor::create(color));
-}
-
-inline void Color::setColor(const DisplayP3<float>& color)
-{
- setExtendedColor(ExtendedColor::create(color));
-}
-
inline void Color::setExtendedColor(Ref<ExtendedColor>&& extendedColor)
{
// Zero the union, just in case a 32-bit system only assigns the
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.cpp (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.cpp 2020-12-26 17:42:33 UTC (rev 271089)
@@ -88,7 +88,7 @@
};
}
-static LinearSRGBA<float> toLinearSRGBA(const XYZA<float>& color)
+LinearSRGBA<float> toLinearSRGBA(const XYZA<float>& color)
{
// https://en.wikipedia.org/wiki/SRGB
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
@@ -100,7 +100,7 @@
return asLinearSRGBA(xyzToLinearSRGBMatrix.transformedColorComponents(asColorComponents(color)));
}
-static XYZA<float> toXYZ(const LinearSRGBA<float>& color)
+XYZA<float> toXYZA(const LinearSRGBA<float>& color)
{
// https://en.wikipedia.org/wiki/SRGB
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
@@ -112,7 +112,7 @@
return asXYZA(linearSRGBToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
-static LinearDisplayP3<float> toLinearDisplayP3(const XYZA<float>& color)
+LinearDisplayP3<float> toLinearDisplayP3(const XYZA<float>& color)
{
// https://drafts.csswg.org/css-color/#color-conversion-code
constexpr ColorMatrix<3, 3> xyzToLinearDisplayP3Matrix {
@@ -123,7 +123,7 @@
return asLinearDisplayP3(xyzToLinearDisplayP3Matrix.transformedColorComponents(asColorComponents(color)));
}
-static XYZA<float> toXYZ(const LinearDisplayP3<float>& color)
+XYZA<float> toXYZA(const LinearDisplayP3<float>& color)
{
// https://drafts.csswg.org/css-color/#color-conversion-code
constexpr ColorMatrix<3, 3> linearDisplayP3ToXYZMatrix {
@@ -134,16 +134,6 @@
return asXYZA(linearDisplayP3ToXYZMatrix.transformedColorComponents(asColorComponents(color)));
}
-SRGBA<float> toSRGBA(const DisplayP3<float>& color)
-{
- return toSRGBA(toLinearSRGBA(toXYZ(toLinearDisplayP3(color))));
-}
-
-DisplayP3<float> toDisplayP3(const SRGBA<float>& color)
-{
- return toDisplayP3(toLinearDisplayP3(toXYZ(toLinearSRGBA(color))));
-}
-
HSLA<float> toHSLA(const SRGBA<float>& color)
{
// http://en.wikipedia.org/wiki/HSL_color_space.
@@ -239,4 +229,58 @@
return { r, g, b, a };
}
+CMYKA<float> toCMYKA(const SRGBA<float>& color)
+{
+ auto [r, g, b, a] = color;
+
+ auto k = 1.0f - std::max({ r, g, b });
+ if (k == 1.0f)
+ return { 0, 0, 0, 1.0f, a };
+
+ auto c = (1.0f - r - k) / (1.0f - k);
+ auto m = (1.0f - g - k) / (1.0f - k);
+ auto y = (1.0f - b - k) / (1.0f - k);
+ return { c, m, y, k, a };
+}
+
+XYZA<float> toXYZA(const SRGBA<float>& color)
+{
+ return toXYZA(toLinearSRGBA(color));
+}
+
+SRGBA<float> toSRGBA(const XYZA<float>& color)
+{
+ return toSRGBA(toLinearSRGBA(color));
+}
+
+XYZA<float> toXYZA(const DisplayP3<float>& color)
+{
+ return toXYZA(toLinearDisplayP3(color));
+}
+
+DisplayP3<float> toDisplayP3(const XYZA<float>& color)
+{
+ return toDisplayP3(toLinearDisplayP3(color));
+}
+
+XYZA<float> toXYZA(const HSLA<float>& color)
+{
+ return toXYZA(toSRGBA(color));
+}
+
+HSLA<float> toHSLA(const XYZA<float>& color)
+{
+ return toHSLA(toSRGBA(color));
+}
+
+XYZA<float> toXYZA(const CMYKA<float>& color)
+{
+ return toXYZA(toSRGBA(color));
+}
+
+CMYKA<float> toCMYKA(const XYZA<float>& color)
+{
+ return toCMYKA(toSRGBA(color));
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ColorConversion.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/ColorConversion.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/ColorConversion.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -33,27 +33,102 @@
float linearToRGBColorComponent(float);
float rgbToLinearColorComponent(float);
+
+// All color types must at least implement the following conversions to and from the XYZA color space:
+// XYZA<float> toXYZA(const ColorType<float>&);
+// ColorType<float> toColorType(const XYZA<float>&);
+//
+// Any additional conversions can be thought of as optimizations, shortcutting unnecessary steps, though
+// some may be integral to the base conversion.
+
+
+// SRGBA
+WEBCORE_EXPORT XYZA<float> toXYZA(const SRGBA<float>&);
+WEBCORE_EXPORT SRGBA<float> toSRGBA(const XYZA<float>&);
+// Additions
WEBCORE_EXPORT LinearSRGBA<float> toLinearSRGBA(const SRGBA<float>&);
+WEBCORE_EXPORT HSLA<float> toHSLA(const SRGBA<float>&);
+WEBCORE_EXPORT CMYKA<float> toCMYKA(const SRGBA<float>&);
+
+// LinearSRGBA
+WEBCORE_EXPORT XYZA<float> toXYZA(const LinearSRGBA<float>&);
+WEBCORE_EXPORT LinearSRGBA<float> toLinearSRGBA(const XYZA<float>&);
+// Additions
WEBCORE_EXPORT SRGBA<float> toSRGBA(const LinearSRGBA<float>&);
+
+// DisplayP3
+WEBCORE_EXPORT XYZA<float> toXYZA(const DisplayP3<float>&);
+WEBCORE_EXPORT DisplayP3<float> toDisplayP3(const XYZA<float>&);
+// Additions
WEBCORE_EXPORT LinearDisplayP3<float> toLinearDisplayP3(const DisplayP3<float>&);
+
+
+// LinearDisplayP3
+WEBCORE_EXPORT XYZA<float> toXYZA(const LinearDisplayP3<float>&);
+WEBCORE_EXPORT LinearDisplayP3<float> toLinearDisplayP3(const XYZA<float>&);
+// Additions
WEBCORE_EXPORT DisplayP3<float> toDisplayP3(const LinearDisplayP3<float>&);
-WEBCORE_EXPORT SRGBA<float> toSRGBA(const DisplayP3<float>&);
-WEBCORE_EXPORT DisplayP3<float> toDisplayP3(const SRGBA<float>&);
-WEBCORE_EXPORT HSLA<float> toHSLA(const SRGBA<float>&);
+// HSLA
+WEBCORE_EXPORT XYZA<float> toXYZA(const HSLA<float>&);
+WEBCORE_EXPORT HSLA<float> toHSLA(const XYZA<float>&);
+// Additions
WEBCORE_EXPORT SRGBA<float> toSRGBA(const HSLA<float>&);
-SRGBA<float> toSRGBA(const CMYKA<float>&);
+// CMYKA
+WEBCORE_EXPORT XYZA<float> toXYZA(const CMYKA<float>&);
+WEBCORE_EXPORT CMYKA<float> toCMYKA(const XYZA<float>&);
+// Additions
+WEBCORE_EXPORT SRGBA<float> toSRGBA(const CMYKA<float>&);
-// Identity conversions (useful for generic contexts)
+// Identity conversions (useful for generic contexts).
+
constexpr SRGBA<float> toSRGBA(const SRGBA<float>& color) { return color; }
constexpr LinearSRGBA<float> toLinearSRGBA(const LinearSRGBA<float>& color) { return color; }
constexpr DisplayP3<float> toDisplayP3(const DisplayP3<float>& color) { return color; }
constexpr LinearDisplayP3<float> toLinearDisplayP3(const LinearDisplayP3<float>& color) { return color; }
constexpr HSLA<float> toHSLA(const HSLA<float>& color) { return color; }
+constexpr CMYKA<float> toCMYKA(const CMYKA<float>& color) { return color; }
+constexpr XYZA<float> toXYZA(const XYZA<float>& color) { return color; }
+
+// Fallback conversions.
+
+// All types are required to have a conversion to XYZA, so these are guaranteed to work if
+// another overload is not already provided.
+
+template<typename T> SRGBA<float> toSRGBA(const T& color)
+{
+ return toSRGBA(toXYZA(color));
+}
+
+template<typename T> SRGBA<float> toLinearSRGBA(const T& color)
+{
+ return toLinearSRGBA(toXYZA(color));
+}
+
+template<typename T> SRGBA<float> toDisplayP3(const T& color)
+{
+ return toDisplayP3(toXYZA(color));
+}
+
+template<typename T> SRGBA<float> toLinearDisplayP3(const T& color)
+{
+ return toLinearDisplayP3(toXYZA(color));
+}
+
+template<typename T> SRGBA<float> toHSLA(const T& color)
+{
+ return toHSLA(toXYZA(color));
+}
+
+template<typename T> SRGBA<float> toCMYKA(const T& color)
+{
+ return toCMYKA(toXYZA(color));
+}
+
} // namespace WebCore
Added: trunk/Source/WebCore/platform/graphics/ColorSpace.cpp (0 => 271089)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.cpp 2020-12-26 17:42:33 UTC (rev 271089)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ColorSpace.h"
+
+#include <wtf/text/TextStream.h>
+
+namespace WebCore {
+
+TextStream& operator<<(TextStream& ts, ColorSpace colorSpace)
+{
+ switch (colorSpace) {
+ case ColorSpace::SRGB:
+ ts << "sRGB";
+ break;
+ case ColorSpace::LinearRGB:
+ ts << "LinearRGB";
+ break;
+ case ColorSpace::DisplayP3:
+ ts << "DisplayP3";
+ break;
+ }
+ return ts;
+}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/ColorSpace.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/ColorSpace.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/ColorSpace.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -25,6 +25,10 @@
#pragma once
+namespace WTF {
+class TextStream;
+}
+
namespace WebCore {
enum class ColorSpace : uint8_t {
@@ -33,4 +37,6 @@
DisplayP3
};
+WEBCORE_EXPORT WTF::TextStream& operator<<(WTF::TextStream&, ColorSpace);
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/graphics/ColorTypes.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/ColorTypes.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/ColorTypes.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -25,11 +25,12 @@
#pragma once
+#include "ColorComponents.h"
#include "ColorSpace.h"
+#include <functional>
namespace WebCore {
-template<typename> struct ColorComponents;
template<typename> struct ComponentTraits;
template<> struct ComponentTraits<uint8_t> {
@@ -353,7 +354,21 @@
return !(a == b);
}
+template<typename Functor> constexpr decltype(auto) callWithColorType(const ColorComponents<float>& components, ColorSpace colorSpace, Functor&& functor)
+{
+ switch (colorSpace) {
+ case ColorSpace::SRGB:
+ return std::invoke(std::forward<Functor>(functor), asSRGBA(components));
+ case ColorSpace::LinearRGB:
+ return std::invoke(std::forward<Functor>(functor), asLinearSRGBA(components));
+ case ColorSpace::DisplayP3:
+ return std::invoke(std::forward<Functor>(functor), asDisplayP3(components));
+ }
+ ASSERT_NOT_REACHED();
+ return std::invoke(std::forward<Functor>(functor), asSRGBA(components));
+}
+
// Packed Color Formats
namespace PackedColor {
Modified: trunk/Source/WebCore/platform/graphics/ColorUtilities.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/ColorUtilities.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -25,6 +25,7 @@
#pragma once
+#include "ColorComponents.h"
#include "ColorTypes.h"
#include <algorithm>
#include <cmath>
@@ -33,8 +34,6 @@
namespace WebCore {
-template<typename> struct SRGBA;
-
float lightness(const SRGBA<float>&);
float luminance(const SRGBA<float>&);
float contrastRatio(const SRGBA<float>&, const SRGBA<float>&);
@@ -147,12 +146,12 @@
template<typename ColorType, typename Functor> ColorType colorByModifingEachNonAlphaComponent(const ColorType& color, Functor&& functor)
{
- // FIXME: This should be made to work with colors that don't use the names red, green, and blue for their channels.
- auto copy = color;
- copy.red = std::invoke(functor, color.red);
- copy.green = std::invoke(functor, color.green);
- copy.blue = std::invoke(std::forward<Functor>(functor), color.blue);
- return copy;
+ auto components = asColorComponents(color);
+ auto copy = components;
+ copy[0] = std::invoke(functor, components[0]);
+ copy[1] = std::invoke(functor, components[1]);
+ copy[2] = std::invoke(std::forward<Functor>(functor), components[2]);
+ return { copy[0], copy[1], copy[2], copy[3] };
}
template<typename ColorType> constexpr ColorType colorWithOverridenAlpha(const ColorType& color, uint8_t overrideAlpha)
Modified: trunk/Source/WebCore/platform/graphics/ExtendedColor.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/ExtendedColor.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/ExtendedColor.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -82,17 +82,7 @@
template<typename Functor> decltype(auto) ExtendedColor::callOnUnderlyingType(Functor&& functor) const
{
- switch (m_colorSpace) {
- case ColorSpace::SRGB:
- return std::invoke(std::forward<Functor>(functor), asSRGBA(m_components));
- case ColorSpace::LinearRGB:
- return std::invoke(std::forward<Functor>(functor), asLinearSRGBA(m_components));
- case ColorSpace::DisplayP3:
- return std::invoke(std::forward<Functor>(functor), asDisplayP3(m_components));
- }
-
- ASSERT_NOT_REACHED();
- return std::invoke(std::forward<Functor>(functor), asSRGBA(m_components));
+ return callWithColorType(m_components, m_colorSpace, std::forward<Functor>(functor));
}
}
Modified: trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp 2020-12-26 17:42:33 UTC (rev 271089)
@@ -28,7 +28,7 @@
#if USE(CG)
-#include "GraphicsContextCG.h"
+#include "ColorSpaceCG.h"
#include <wtf/Assertions.h>
#include <wtf/RetainPtr.h>
#include <wtf/TinyLRUCache.h>
@@ -97,21 +97,24 @@
static CGColorRef leakCGColor(const Color& color)
{
auto [colorSpace, components] = color.colorSpaceAndComponents();
+
+ auto cgColorSpace = cachedCGColorSpace(colorSpace);
+
+ // Some CG ports don't support all the color spaces required and return
+ // sRGBColorSpaceRef() for unsupported color spaces. In those cases, we
+ // need to eagerly and potentially lossily convert the color into sRGB
+ // ourselves before creating the CGColorRef.
+ if (colorSpace != ColorSpace::SRGB && cgColorSpace == sRGBColorSpaceRef()) {
+ auto colorConvertedToSRGBA = callWithColorType(components, colorSpace, [] (const auto& color) {
+ return toSRGBA(color);
+ });
+ components = asColorComponents(colorConvertedToSRGBA);
+ }
+
auto [r, g, b, a] = components;
CGFloat cgFloatComponents[4] { r, g, b, a };
- switch (colorSpace) {
- case ColorSpace::SRGB:
- return CGColorCreate(sRGBColorSpaceRef(), cgFloatComponents);
- case ColorSpace::DisplayP3:
- return CGColorCreate(displayP3ColorSpaceRef(), cgFloatComponents);
- case ColorSpace::LinearRGB:
- // FIXME: Do we ever create CGColorRefs in these spaces? It may only be ImageBuffers.
- return CGColorCreate(sRGBColorSpaceRef(), cgFloatComponents);
- }
-
- ASSERT_NOT_REACHED();
- return nullptr;
+ return CGColorCreate(cgColorSpace, cgFloatComponents);
}
CGColorRef cachedCGColor(const Color& color)
Added: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp (0 => 271089)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.cpp 2020-12-26 17:42:33 UTC (rev 271089)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ColorSpaceCG.h"
+
+#if USE(CG)
+
+#include <mutex>
+#include <pal/spi/cg/CoreGraphicsSPI.h>
+
+namespace WebCore {
+
+CGColorSpaceRef sRGBColorSpaceRef()
+{
+ static CGColorSpaceRef sRGBColorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+#if PLATFORM(WIN)
+ // Out-of-date CG installations will not honor kCGColorSpaceSRGB. This logic avoids
+ // causing a crash under those conditions. Since the default color space in Windows
+ // is sRGB, this all works out nicely.
+ // FIXME: Is this still needed? rdar://problem/15213515 was fixed.
+ sRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+ if (!sRGBColorSpace)
+ sRGBColorSpace = CGColorSpaceCreateDeviceRGB();
+#else
+ sRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+#endif // PLATFORM(WIN)
+ });
+ return sRGBColorSpace;
+}
+
+CGColorSpaceRef linearRGBColorSpaceRef()
+{
+ static CGColorSpaceRef linearRGBColorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+#if PLATFORM(WIN)
+ // FIXME: Windows should be able to use linear sRGB, this is tracked by http://webkit.org/b/80000.
+ linearRGBColorSpace = sRGBColorSpaceRef();
+#else
+ linearRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB);
+#endif
+ });
+ return linearRGBColorSpace;
+}
+
+CGColorSpaceRef displayP3ColorSpaceRef()
+{
+ static CGColorSpaceRef displayP3ColorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+#if PLATFORM(COCOA)
+ displayP3ColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3);
+#else
+ displayP3ColorSpace = sRGBColorSpaceRef();
+#endif
+ });
+ return displayP3ColorSpace;
+}
+
+CGColorSpaceRef extendedSRGBColorSpaceRef()
+{
+ static CGColorSpaceRef extendedSRGBColorSpace;
+ static std::once_flag onceFlag;
+ std::call_once(onceFlag, [] {
+ CGColorSpaceRef colorSpace = nullptr;
+#if PLATFORM(COCOA)
+ colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
+#endif
+ // If there is no support for extended sRGB, fall back to sRGB.
+ if (!colorSpace)
+ colorSpace = sRGBColorSpaceRef();
+
+ extendedSRGBColorSpace = colorSpace;
+ });
+ return extendedSRGBColorSpace;
+}
+
+}
+
+#endif // USE(CG)
Added: trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (0 => 271089)
--- trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/cg/ColorSpaceCG.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ColorSpace.h"
+
+typedef struct CGColorSpace *CGColorSpaceRef;
+
+namespace WebCore {
+
+WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
+WEBCORE_EXPORT CGColorSpaceRef linearRGBColorSpaceRef();
+WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
+WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
+
+static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
+{
+ switch (colorSpace) {
+ case ColorSpace::SRGB:
+ return sRGBColorSpaceRef();
+ case ColorSpace::LinearRGB:
+ return linearRGBColorSpaceRef();
+ case ColorSpace::DisplayP3:
+ return displayP3ColorSpaceRef();
+ }
+ ASSERT_NOT_REACHED();
+ return sRGBColorSpaceRef();
+}
+
+}
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2020-12-26 17:42:33 UTC (rev 271089)
@@ -71,73 +71,6 @@
return CGAffineTransformConcat(CGContextGetCTM(context), CGAffineTransformInvert(CGContextGetBaseCTM(context)));
}
-CGColorSpaceRef sRGBColorSpaceRef()
-{
- static CGColorSpaceRef sRGBColorSpace;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [] {
-#if PLATFORM(WIN)
- // Out-of-date CG installations will not honor kCGColorSpaceSRGB. This logic avoids
- // causing a crash under those conditions. Since the default color space in Windows
- // is sRGB, this all works out nicely.
- // FIXME: Is this still needed? rdar://problem/15213515 was fixed.
- sRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
- if (!sRGBColorSpace)
- sRGBColorSpace = CGColorSpaceCreateDeviceRGB();
-#else
- sRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
-#endif // PLATFORM(WIN)
- });
- return sRGBColorSpace;
-}
-
-CGColorSpaceRef linearRGBColorSpaceRef()
-{
- static CGColorSpaceRef linearRGBColorSpace;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [] {
-#if PLATFORM(WIN)
- // FIXME: Windows should be able to use linear sRGB, this is tracked by http://webkit.org/b/80000.
- linearRGBColorSpace = sRGBColorSpaceRef();
-#else
- linearRGBColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceLinearSRGB);
-#endif
- });
- return linearRGBColorSpace;
-}
-
-CGColorSpaceRef extendedSRGBColorSpaceRef()
-{
- static CGColorSpaceRef extendedSRGBColorSpace;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [] {
- CGColorSpaceRef colorSpace = NULL;
-#if PLATFORM(COCOA)
- colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceExtendedSRGB);
-#endif
- // If there is no support for extended sRGB, fall back to sRGB.
- if (!colorSpace)
- colorSpace = sRGBColorSpaceRef();
-
- extendedSRGBColorSpace = colorSpace;
- });
- return extendedSRGBColorSpace;
-}
-
-CGColorSpaceRef displayP3ColorSpaceRef()
-{
- static CGColorSpaceRef displayP3ColorSpace;
- static std::once_flag onceFlag;
- std::call_once(onceFlag, [] {
-#if PLATFORM(COCOA)
- displayP3ColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceDisplayP3);
-#else
- displayP3ColorSpace = sRGBColorSpaceRef();
-#endif
- });
- return displayP3ColorSpace;
-}
-
static InterpolationQuality convertInterpolationQuality(CGInterpolationQuality quality)
{
switch (quality) {
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h (271088 => 271089)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h 2020-12-26 15:22:08 UTC (rev 271088)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h 2020-12-26 17:42:33 UTC (rev 271089)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2006, 2007, 2010, 2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -25,33 +25,13 @@
#pragma once
+#include "ColorSpaceCG.h"
#include "GraphicsContext.h"
-typedef struct CGColorSpace *CGColorSpaceRef;
-
namespace WebCore {
-WEBCORE_EXPORT CGColorSpaceRef sRGBColorSpaceRef();
-WEBCORE_EXPORT CGColorSpaceRef extendedSRGBColorSpaceRef();
-WEBCORE_EXPORT CGColorSpaceRef displayP3ColorSpaceRef();
-WEBCORE_EXPORT CGColorSpaceRef linearRGBColorSpaceRef();
-
CGAffineTransform getUserToBaseCTM(CGContextRef);
-static inline CGColorSpaceRef cachedCGColorSpace(ColorSpace colorSpace)
-{
- switch (colorSpace) {
- case ColorSpace::SRGB:
- return sRGBColorSpaceRef();
- case ColorSpace::LinearRGB:
- return linearRGBColorSpaceRef();
- case ColorSpace::DisplayP3:
- return displayP3ColorSpaceRef();
- }
- ASSERT_NOT_REACHED();
- return sRGBColorSpaceRef();
-}
-
class CGContextStateSaver {
public:
CGContextStateSaver(CGContextRef context, bool saveAndRestore = true)