Changeset 263688 in webkit
- Timestamp:
- Jun 29, 2020 1:31:18 PM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r263673 r263688 1 2020-06-29 Sam Weinig <weinig@apple.com> 2 3 Remove remaining makeSimpleColorFrom* variants 4 https://bugs.webkit.org/show_bug.cgi?id=213706 5 6 Reviewed by Darin Adler. 7 8 Removed makeSimpleColorFromFloats and makeSimpleColorFromCMYKA. 9 - Updated callers that need to pass floats to use makeSimpleColor(SRGBA { ... }); 10 - Updated callers that don't need to pass floats, mostly compile time constant 11 SimpleColors to use makeSimpleColor(...), passing in 0-255 based component 12 values. 13 - Updated callers of makeSimpleColorFromCMYKA to use makeSimpleColor(toSRGBA(CMYKA { ... })). 14 This required adding CMYKA type to ColorTypes.h and moving conversion SRGBA to 15 ColorUtilities with the other color conversion code. 16 - Added deduction guides for color types to allow component type deduction. This allows 17 us to write: 18 19 function(SRGBA { redFloat, greenFloat, blueFloat, alphaFloat }) 20 21 reather than the more cumbersome: 22 23 function(SRGBA<float> { redFloat, greenFloat, blueFloat, alphaFloat }) 24 25 - Added operator==/operator!= for each color type. Only used by CMYKA at the moment, 26 but generally useful, so added for all of them. For all types convertable to ColorComponents, 27 the implementation uses the conversion to ColorComponents to avoid redundancy. 28 29 * html/canvas/CanvasRenderingContext2DBase.cpp: 30 (WebCore::CanvasRenderingContext2DBase::setStrokeColor): 31 (WebCore::CanvasRenderingContext2DBase::setFillColor): 32 Update to call new typed color based CanvasStyle functions. 33 (WebCore::CanvasRenderingContext2DBase::setShadow): 34 Use makeSimpleColor rather than makeSimpleColorFromFloats/makeSimpleColorFromCMYKA. 35 36 * html/canvas/CanvasStyle.cpp: 37 (WebCore::CanvasStyle::CanvasStyle): 38 Replace constructors taking raw floats with ones taking typed colors (SRGBA<float>/CMYKA<float>) 39 to make it more clear what the parameters mean. 40 (WebCore::CanvasStyle::isEquivalentColor const): 41 Compare the cmyka components using new operator== implementation for CMYKA<float>. 42 (WebCore::CanvasStyle::isEquivalent const): 43 (WebCore::CanvasStyle::isEquivalentRGBA const): Deleted. 44 (WebCore::CanvasStyle::isEquivalentCMYKA const): Deleted. 45 Replace isEquivalentRGBA/isEquivalentCMYKA with overloaded isEquivalent. 46 (WebCore::CanvasStyle::applyStrokeColor const): 47 (WebCore::CanvasStyle::applyFillColor const): 48 Update for new names of CMYKA members. 49 * html/canvas/CanvasStyle.h: 50 Use SRGBA<float> and CMYKA<float> to simplify interfaces 51 52 * page/DebugPageOverlays.cpp: 53 * page/linux/ResourceUsageOverlayLinux.cpp: 54 (WebCore::ResourceUsageOverlay::platformInitialize): 55 Use makeSimpleColor rather than makeSimpleColorFromFloats, allowing for 56 constant expression creation of SimpleColors. 57 58 * platform/graphics/Color.cpp: 59 (WebCore::Color::lightened const): 60 (WebCore::Color::darkened const): 61 Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats. 62 63 (WebCore::Color::luminance const): 64 Fix comment. 65 66 (WebCore::blendWithoutPremultiply): 67 Use makeSimpleColor(...) rather than makeSimpleColorFromFloats. 68 69 * platform/graphics/ColorTypes.h: 70 (WebCore::operator==): 71 (WebCore::operator!=): 72 - Add deduction guides and operator==/operator!= for each color type. 73 - Add CMYKA type. No conversion to ColorComponents yet, as ColorComponents 74 only works with 4 component colors, not ones with 5 like CMYKA. 75 76 * platform/graphics/ColorUtilities.cpp: 77 (WebCore::toSRGBA): 78 Move conversion from CMYKA to SRGBA from makeSimpleColorFromCMYKA to here. 79 80 * platform/graphics/ColorUtilities.h: 81 (WebCore::convertPrescaledToComponentByte): 82 (WebCore::convertToComponentByte): 83 Use std::round rather than std::lroundf, since it will have the same result 84 and it reads nicer. 85 86 * platform/graphics/SimpleColor.cpp: 87 (WebCore::makeSimpleColorFromCMYKA): Deleted. 88 * platform/graphics/SimpleColor.h: 89 (WebCore::makeSimpleColor): 90 (WebCore::makeSimpleColorFromFloats): Deleted. 91 - Removed makeSimpleColorFromFloats and makeSimpleColorFromCMYKA. 92 - Added constexpr overload of makeSimpleColor taking a const SRGBA<uint8_t>&. 93 - Fixed forward declaration of makeSimpleColor that was taking ColorComponents 94 to actually take an SRGBA<float>, which is what the inline implementation actually 95 takes. 96 97 * platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp: 98 (WebCore::makeSimpleColorFromARGBCFArray): 99 * platform/graphics/cairo/GradientCairo.cpp: 100 (WebCore::interpolateColorStop): 101 * platform/graphics/cg/ColorCG.cpp: 102 (WebCore::makeSimpleColorFromCGColor): 103 * platform/graphics/win/PlatformContextDirect2D.cpp: 104 (WebCore::PlatformContextDirect2D::brushWithColor): 105 Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats. 106 107 * platform/graphics/mac/ColorMac.mm: 108 (WebCore::makeSimpleColorFromNSColor): 109 * platform/ios/ColorIOS.mm: 110 (WebCore::colorFromUIColor): 111 Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats. Casting to 112 float is needed, as the input types are CGFloat which is double in 64-bit environments 113 and won't automatically narrow with the new types. 114 115 * platform/ios/LegacyTileCache.mm: 116 (WebCore::LegacyTileCache::colorForGridTileBorder const): 117 * rendering/RenderLayer.cpp: 118 (WebCore::RenderLayer::beginTransparencyLayers): 119 Use makeSimpleColor rather than makeSimpleColorFromFloats, allowing for 120 constant expression creation of SimpleColors. 121 122 * rendering/RenderThemeIOS.mm: 123 (WebCore::RenderThemeIOS::paintCheckboxDecorations): 124 (WebCore::RenderThemeIOS::paintRadioDecorations): 125 (WebCore::RenderThemeIOS::paintMenuListButtonDecorations): 126 (WebCore::RenderThemeIOS::paintSystemPreviewBadge): 127 Use Color::black/Color::white.colorWithAlpha(...) rather than makeSimpleColorFromFloats, 128 allowing for constant expression creation of SimpleColors. 129 1 130 2020-06-29 Chris Fleizach <cfleizach@apple.com> 2 131 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
r262733 r263688 372 372 return; 373 373 374 if (state().strokeStyle.is Valid() && state().strokeStyle.isEquivalentColor(style))374 if (state().strokeStyle.isEquivalentColor(style)) 375 375 return; 376 376 … … 395 395 return; 396 396 397 if (state().fillStyle.is Valid() && state().fillStyle.isEquivalentColor(style))397 if (state().fillStyle.isEquivalentColor(style)) 398 398 return; 399 399 … … 915 915 void CanvasRenderingContext2DBase::setStrokeColor(float grayLevel, float alpha) 916 916 { 917 if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha)) 918 return; 919 setStrokeStyle(CanvasStyle(grayLevel, alpha)); 917 auto color = SRGBA { grayLevel, grayLevel, grayLevel, alpha }; 918 if (state().strokeStyle.isEquivalent(color)) 919 return; 920 setStrokeStyle(CanvasStyle(color)); 920 921 } 921 922 922 923 void CanvasRenderingContext2DBase::setStrokeColor(float r, float g, float b, float a) 923 924 { 924 if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(r, g, b, a)) 925 return; 926 setStrokeStyle(CanvasStyle(r, g, b, a)); 925 auto color = SRGBA { r, g, b, a }; 926 if (state().strokeStyle.isEquivalent(color)) 927 return; 928 setStrokeStyle(CanvasStyle(color)); 927 929 } 928 930 929 931 void CanvasRenderingContext2DBase::setStrokeColor(float c, float m, float y, float k, float a) 930 932 { 931 if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentCMYKA(c, m, y, k, a)) 932 return; 933 setStrokeStyle(CanvasStyle(c, m, y, k, a)); 933 auto color = CMYKA { c, m, y, k, a }; 934 if (state().strokeStyle.isEquivalent(color)) 935 return; 936 setStrokeStyle(CanvasStyle(color)); 934 937 } 935 938 … … 951 954 void CanvasRenderingContext2DBase::setFillColor(float grayLevel, float alpha) 952 955 { 953 if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha)) 954 return; 955 setFillStyle(CanvasStyle(grayLevel, alpha)); 956 auto color = SRGBA { grayLevel, grayLevel, grayLevel, alpha }; 957 if (state().fillStyle.isEquivalent(color)) 958 return; 959 setFillStyle(CanvasStyle(color)); 956 960 } 957 961 958 962 void CanvasRenderingContext2DBase::setFillColor(float r, float g, float b, float a) 959 963 { 960 if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(r, g, b, a)) 961 return; 962 setFillStyle(CanvasStyle(r, g, b, a)); 964 auto color = SRGBA { r, g, b, a }; 965 if (state().fillStyle.isEquivalent(color)) 966 return; 967 setFillStyle(CanvasStyle(color)); 963 968 } 964 969 965 970 void CanvasRenderingContext2DBase::setFillColor(float c, float m, float y, float k, float a) 966 971 { 967 if (state().fillStyle.isValid() && state().fillStyle.isEquivalentCMYKA(c, m, y, k, a)) 968 return; 969 setFillStyle(CanvasStyle(c, m, y, k, a)); 972 auto color = CMYKA { c, m, y, k, a }; 973 if (state().fillStyle.isEquivalent(color)) 974 return; 975 setFillStyle(CanvasStyle(color)); 970 976 } 971 977 … … 1308 1314 void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float grayLevel, float alpha) 1309 1315 { 1310 setShadow(FloatSize(width, height), blur, makeSimpleColor FromFloats(grayLevel, grayLevel, grayLevel, alpha));1316 setShadow(FloatSize(width, height), blur, makeSimpleColor(SRGBA { grayLevel, grayLevel, grayLevel, alpha })); 1311 1317 } 1312 1318 1313 1319 void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float r, float g, float b, float a) 1314 1320 { 1315 setShadow(FloatSize(width, height), blur, makeSimpleColor FromFloats(r, g, b, a));1321 setShadow(FloatSize(width, height), blur, makeSimpleColor(SRGBA { r, g, b, a })); 1316 1322 } 1317 1323 1318 1324 void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a) 1319 1325 { 1320 setShadow(FloatSize(width, height), blur, makeSimpleColor FromCMYKA(c, m, y, k, a));1326 setShadow(FloatSize(width, height), blur, makeSimpleColor(toSRGBA(CMYKA { c, m, y, k, a }))); 1321 1327 } 1322 1328 -
trunk/Source/WebCore/html/canvas/CanvasStyle.cpp
r262733 r263688 93 93 } 94 94 95 CanvasStyle::CanvasStyle(float grayLevel, float alpha) 96 : m_style(makeSimpleColorFromFloats(grayLevel, grayLevel, grayLevel, alpha)) 97 { 98 } 99 100 CanvasStyle::CanvasStyle(float r, float g, float b, float a) 101 : m_style(makeSimpleColorFromFloats(r, g, b, a)) 102 { 103 } 104 105 CanvasStyle::CanvasStyle(float c, float m, float y, float k, float a) 106 : m_style(CMYKAColor { makeSimpleColorFromCMYKA(c, m, y, k, a), c, m, y, k, a }) 95 CanvasStyle::CanvasStyle(const SRGBA<float>& colorComponents) 96 : m_style(makeSimpleColor(colorComponents)) 97 { 98 } 99 100 CanvasStyle::CanvasStyle(const CMYKA<float>& colorComponents) 101 : m_style(CMYKAColor { makeSimpleColor(toSRGBA(colorComponents)), colorComponents }) 107 102 { 108 103 } … … 152 147 return WTF::get<Color>(m_style) == WTF::get<Color>(other.m_style); 153 148 154 if (WTF::holds_alternative<CMYKAColor>(m_style) && WTF::holds_alternative<CMYKAColor>(other.m_style)) { 155 auto& a = WTF::get<CMYKAColor>(m_style); 156 auto& b = WTF::get<CMYKAColor>(other.m_style); 157 return a.c == b.c && a.m == b.m && a.y == b.y && a.k == b.k && a.a == b.a; 158 } 149 if (WTF::holds_alternative<CMYKAColor>(m_style) && WTF::holds_alternative<CMYKAColor>(other.m_style)) 150 return WTF::get<CMYKAColor>(m_style).components == WTF::get<CMYKAColor>(other.m_style).components; 159 151 160 152 return false; 161 153 } 162 154 163 bool CanvasStyle::isEquivalentRGBA(float r, float g, float b, float a) const 164 { 165 return WTF::holds_alternative<Color>(m_style) && WTF::get<Color>(m_style) == makeSimpleColorFromFloats(r, g, b, a); 166 } 167 168 bool CanvasStyle::isEquivalentCMYKA(float c, float m, float y, float k, float a) const 169 { 170 if (!WTF::holds_alternative<CMYKAColor>(m_style)) 171 return false; 172 173 auto& channels = WTF::get<CMYKAColor>(m_style); 174 return c == channels.c && m == channels.m && y == channels.y && k == channels.k && a == channels.a; 155 bool CanvasStyle::isEquivalent(const SRGBA<float>& components) const 156 { 157 return WTF::holds_alternative<Color>(m_style) && WTF::get<Color>(m_style) == makeSimpleColor(components); 158 } 159 160 bool CanvasStyle::isEquivalent(const CMYKA<float>& components) const 161 { 162 return WTF::holds_alternative<CMYKAColor>(m_style) && WTF::get<CMYKAColor>(m_style).components == components; 175 163 } 176 164 … … 185 173 // We'll need a fancier Color abstraction to support CMYKA correctly 186 174 #if USE(CG) 187 CGContextSetCMYKStrokeColor(context.platformContext(), color.c , color.m, color.y, color.k, color.a);175 CGContextSetCMYKStrokeColor(context.platformContext(), color.components.cyan, color.components.magenta, color.components.yellow, color.components.black, color.components.alpha); 188 176 #else 189 context.setStrokeColor(color.color );177 context.setStrokeColor(color.colorConvertedToSRGBA); 190 178 #endif 191 179 }, … … 215 203 // We'll need a fancier Color abstraction to support CMYKA correctly 216 204 #if USE(CG) 217 CGContextSetCMYKFillColor(context.platformContext(), color.c , color.m, color.y, color.k, color.a);205 CGContextSetCMYKFillColor(context.platformContext(), color.components.cyan, color.components.magenta, color.components.yellow, color.components.black, color.components.alpha); 218 206 #else 219 context.setFillColor(color.color );207 context.setFillColor(color.colorConvertedToSRGBA); 220 208 #endif 221 209 }, -
trunk/Source/WebCore/html/canvas/CanvasStyle.h
r262035 r263688 42 42 CanvasStyle(); 43 43 CanvasStyle(Color); 44 CanvasStyle(float grayLevel, float alpha); 45 CanvasStyle(float r, float g, float b, float alpha); 46 CanvasStyle(float c, float m, float y, float k, float alpha); 44 CanvasStyle(const SRGBA<float>&); 45 CanvasStyle(const CMYKA<float>&); 47 46 CanvasStyle(CanvasGradient&); 48 47 CanvasStyle(CanvasPattern&); … … 54 53 bool isCurrentColor() const { return WTF::holds_alternative<CurrentColor>(m_style); } 55 54 Optional<float> overrideAlpha() const { return WTF::get<CurrentColor>(m_style).overrideAlpha; } 56 57 55 58 56 String color() const; … … 64 62 65 63 bool isEquivalentColor(const CanvasStyle&) const; 66 bool isEquivalent RGBA(float red, float green, float blue, float alpha) const;67 bool isEquivalent CMYKA(float cyan, float magenta, float yellow, float black, float alpha) const;64 bool isEquivalent(const SRGBA<float>&) const; 65 bool isEquivalent(const CMYKA<float>&) const; 68 66 69 67 private: … … 71 69 72 70 struct CMYKAColor { 73 Color color; 74 float c { 0 }; 75 float m { 0 }; 76 float y { 0 }; 77 float k { 0 }; 78 float a { 0 }; 79 80 CMYKAColor(const CMYKAColor&) = default; 71 Color colorConvertedToSRGBA; 72 CMYKA<float> components; 81 73 }; 82 74 … … 117 109 inline String CanvasStyle::color() const 118 110 { 119 auto& color = WTF::holds_alternative<Color>(m_style) ? WTF::get<Color>(m_style) : WTF::get<CMYKAColor>(m_style).color ;111 auto& color = WTF::holds_alternative<Color>(m_style) ? WTF::get<Color>(m_style) : WTF::get<CMYKAColor>(m_style).colorConvertedToSRGBA; 120 112 return color.serialized(); 121 113 } -
trunk/Source/WebCore/page/DebugPageOverlays.cpp
r262377 r263688 83 83 private: 84 84 explicit MouseWheelRegionOverlay(Page& page) 85 : RegionOverlay(page, makeSimpleColor FromFloats(0.5f, 0.0f, 0.0f, 0.4f))85 : RegionOverlay(page, makeSimpleColor(128, 0, 0, 102)) 86 86 { 87 87 } … … 119 119 private: 120 120 explicit NonFastScrollableRegionOverlay(Page& page) 121 : RegionOverlay(page, makeSimpleColor FromFloats(1.0f, 0.5f, 0.0f, 0.4f))121 : RegionOverlay(page, makeSimpleColor(255, 128, 0, 102)) 122 122 { 123 123 } -
trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp
r262377 r263688 89 89 { 90 90 GraphicsContextStateSaver stateSaver(context); 91 context.fillRect(clip, makeSimpleColor FromFloats(0.0f, 0.0f, 0.0f, 0.8f));92 context.setFillColor(makeSimpleColor FromFloats(0.9f, 0.9f, 0.9f, 1.f));91 context.fillRect(clip, makeSimpleColor(0, 0, 0, 204)); 92 context.setFillColor(makeSimpleColor(230, 230, 230, 255)); 93 93 94 94 FloatPoint position = { 10, 20 }; … … 138 138 m_paintLayer->setAnchorPoint(FloatPoint3D()); 139 139 m_paintLayer->setSize({ normalWidth, normalHeight }); 140 m_paintLayer->setBackgroundColor(makeSimpleColor FromFloats(0.0f, 0.0f, 0.0f, 0.8f));140 m_paintLayer->setBackgroundColor(makeSimpleColor(0, 0, 0, 204)); 141 141 m_paintLayer->setDrawsContent(true); 142 142 overlay().layer().addChild(*m_paintLayer); -
trunk/Source/WebCore/platform/graphics/Color.cpp
r263000 r263688 115 115 float multiplier = std::min(1.0f, v + 0.33f) / v; 116 116 117 return makeSimpleColor FromFloats(multiplier * r, multiplier * g, multiplier * b, a);117 return makeSimpleColor(SRGBA { multiplier * r, multiplier * g, multiplier * b, a }); 118 118 } 119 119 … … 129 129 float multiplier = std::max(0.0f, (v - 0.33f) / v); 130 130 131 return makeSimpleColor FromFloats(multiplier * r, multiplier * g, multiplier * b, a);131 return makeSimpleColor(SRGBA { multiplier * r, multiplier * g, multiplier * b, a }); 132 132 } 133 133 … … 148 148 float Color::luminance() const 149 149 { 150 // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms for luminance (e.g. convertToXYZ(c).yComponent()). 150 // FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms 151 // for luminance (e.g. convertToXYZ(c).yComponent()). 151 152 return WebCore::luminance(toSRGBALossy()); 152 153 } … … 291 292 auto toSRGB = from.toSRGBASimpleColorLossy(); 292 293 293 return makeSimpleColor FromFloats(294 return makeSimpleColor( 294 295 WebCore::blend(fromSRGB.redComponent(), toSRGB.redComponent(), progress), 295 296 WebCore::blend(fromSRGB.greenComponent(), toSRGB.greenComponent(), progress), -
trunk/Source/WebCore/platform/graphics/ColorTypes.h
r263000 r263688 37 37 }; 38 38 39 template<typename T> SRGBA(T, T, T, T) -> SRGBA<T>; 40 39 41 template<typename T> constexpr ColorComponents<T> asColorComponents(const SRGBA<T>& c) 40 42 { … … 45 47 { 46 48 return { c[0], c[1], c[2], c[3] }; 49 } 50 51 template<typename T> constexpr bool operator==(const SRGBA<T>& a, const SRGBA<T>& b) 52 { 53 return asColorComponents(a) == asColorComponents(b); 54 } 55 56 template<typename T> constexpr bool operator!=(const SRGBA<T>& a, const SRGBA<T>& b) 57 { 58 return !(a == b); 47 59 } 48 60 … … 54 66 } 55 67 68 56 69 template<typename T> struct LinearSRGBA { 57 70 T red; … … 61 74 }; 62 75 76 template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>; 77 63 78 template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearSRGBA<T>& c) 64 79 { … … 71 86 } 72 87 88 template<typename T> constexpr bool operator==(const LinearSRGBA<T>& a, const LinearSRGBA<T>& b) 89 { 90 return asColorComponents(a) == asColorComponents(b); 91 } 92 93 template<typename T> constexpr bool operator!=(const LinearSRGBA<T>& a, const LinearSRGBA<T>& b) 94 { 95 return !(a == b); 96 } 97 98 73 99 template<typename T> struct DisplayP3 { 74 100 T red; … … 78 104 }; 79 105 106 template<typename T> DisplayP3(T, T, T, T) -> DisplayP3<T>; 107 80 108 template<typename T> constexpr ColorComponents<T> asColorComponents(const DisplayP3<T>& c) 81 109 { … … 88 116 } 89 117 118 template<typename T> constexpr bool operator==(const DisplayP3<T>& a, const DisplayP3<T>& b) 119 { 120 return asColorComponents(a) == asColorComponents(b); 121 } 122 123 template<typename T> constexpr bool operator!=(const DisplayP3<T>& a, const DisplayP3<T>& b) 124 { 125 return !(a == b); 126 } 127 128 90 129 template<typename T> struct LinearDisplayP3 { 91 130 T red; … … 95 134 }; 96 135 136 template<typename T> LinearDisplayP3(T, T, T, T) -> LinearDisplayP3<T>; 137 97 138 template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearDisplayP3<T>& c) 98 139 { … … 104 145 return { c[0], c[1], c[2], c[3] }; 105 146 } 147 148 template<typename T> constexpr bool operator==(const LinearDisplayP3<T>& a, const LinearDisplayP3<T>& b) 149 { 150 return asColorComponents(a) == asColorComponents(b); 151 } 152 153 template<typename T> constexpr bool operator!=(const LinearDisplayP3<T>& a, const LinearDisplayP3<T>& b) 154 { 155 return !(a == b); 156 } 157 106 158 107 159 template<typename T> struct HSLA { … … 112 164 }; 113 165 166 template<typename T> HSLA(T, T, T, T) -> HSLA<T>; 167 114 168 template<typename T> constexpr ColorComponents<T> asColorComponents(const HSLA<T>& c) 115 169 { … … 121 175 return { c[0], c[1], c[2], c[3] }; 122 176 } 177 178 template<typename T> constexpr bool operator==(const HSLA<T>& a, const HSLA<T>& b) 179 { 180 return asColorComponents(a) == asColorComponents(b); 181 } 182 183 template<typename T> constexpr bool operator!=(const HSLA<T>& a, const HSLA<T>& b) 184 { 185 return !(a == b); 186 } 187 188 189 // FIXME: When ColorComponents supports more than length == 4, add conversion to/from ColorComponents<T> for CMYKA 190 template<typename T> struct CMYKA { 191 T cyan; 192 T magenta; 193 T yellow; 194 T black; 195 T alpha; 196 }; 197 198 template<typename T> CMYKA(T, T, T, T, T) -> CMYKA<T>; 199 200 template<typename T> constexpr bool operator==(const CMYKA<T>& a, const CMYKA<T>& b) 201 { 202 return a.cyan == b.cyan && a.magenta == b.magenta && a.yellow == b.yellow && a.black == b.black && a.alpha == b.alpha; 203 } 204 205 template<typename T> constexpr bool operator!=(const CMYKA<T>& a, const CMYKA<T>& b) 206 { 207 return !(a == b); 208 } 209 123 210 124 211 template<typename T> struct XYZA { … … 129 216 }; 130 217 218 template<typename T> XYZA(T, T, T, T) -> XYZA<T>; 219 131 220 template<typename T> constexpr ColorComponents<T> asColorComponents(const XYZA<T>& c) 132 221 { … … 139 228 } 140 229 230 template<typename T> constexpr bool operator==(const XYZA<T>& a, const XYZA<T>& b) 231 { 232 return asColorComponents(a) == asColorComponents(b); 233 } 234 235 template<typename T> constexpr bool operator!=(const XYZA<T>& a, const XYZA<T>& b) 236 { 237 return !(a == b); 238 } 239 141 240 } // namespace WebCore -
trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp
r263000 r263688 260 260 } 261 261 262 SRGBA<float> toSRGBA(const CMYKA<float>& color) 263 { 264 auto [c, m, y, k, a] = color; 265 float colors = 1 - k; 266 float r = colors * (1.0f - c); 267 float g = colors * (1.0f - m); 268 float b = colors * (1.0f - y); 269 return { r, g, b, a }; 270 } 271 262 272 SRGBA<float> premultiplied(const SRGBA<float>& color) 263 273 { -
trunk/Source/WebCore/platform/graphics/ColorUtilities.h
r263000 r263688 31 31 namespace WebCore { 32 32 33 template<typename> struct CMYKA; 33 34 template<typename> struct DisplayP3; 34 35 template<typename> struct HSLA; … … 53 54 WEBCORE_EXPORT SRGBA<float> toSRGBA(const HSLA<float>&); 54 55 56 SRGBA<float> toSRGBA(const CMYKA<float>&); 57 58 55 59 float lightness(const SRGBA<float>&); 56 60 float luminance(const SRGBA<float>&); 57 58 61 float contrastRatio(const SRGBA<float>&, const SRGBA<float>&); 59 62 … … 62 65 inline uint8_t convertPrescaledToComponentByte(float f) 63 66 { 64 return std::clamp(st atic_cast<int>(std::lroundf(f)), 0, 255);67 return std::clamp(std::lround(f), 0l, 255l); 65 68 } 66 69 67 70 inline uint8_t convertToComponentByte(float f) 68 71 { 69 return std::clamp(st atic_cast<int>(std::lroundf(f * 255.0f)), 0, 255);72 return std::clamp(std::lround(f * 255.0f), 0l, 255l); 70 73 } 71 74 -
trunk/Source/WebCore/platform/graphics/SimpleColor.cpp
r262810 r263688 63 63 } 64 64 65 SimpleColor makeSimpleColorFromCMYKA(float c, float m, float y, float k, float a)66 {67 float colors = 1 - k;68 float r = colors * (1.0f - c);69 float g = colors * (1.0f - m);70 float b = colors * (1.0f - y);71 return makeSimpleColorFromFloats(r, g, b, a);72 }73 74 65 String SimpleColor::serializationForHTML() const 75 66 { -
trunk/Source/WebCore/platform/graphics/SimpleColor.h
r263000 r263688 92 92 constexpr SimpleColor makeSimpleColor(int r, int g, int b); 93 93 constexpr SimpleColor makeSimpleColor(int r, int g, int b, int a); 94 95 SimpleColor makeSimpleColor(const ColorComponents<float>& sRGBComponents); 96 SimpleColor makeSimpleColorFromFloats(float r, float g, float b, float a); 97 SimpleColor makeSimpleColorFromCMYKA(float c, float m, float y, float k, float a); 94 constexpr SimpleColor makeSimpleColor(const SRGBA<uint8_t>&); 95 SimpleColor makeSimpleColor(const SRGBA<float>&); 98 96 99 97 SimpleColor premultiplyFlooring(SimpleColor); … … 121 119 } 122 120 121 constexpr SimpleColor makeSimpleColor(const SRGBA<uint8_t>& sRGBA) 122 { 123 auto [r, g, b, a] = sRGBA; 124 return { r, g, b, a }; 125 } 126 123 127 inline SimpleColor makeSimpleColor(const SRGBA<float>& sRGBA) 124 128 { 125 129 auto [r, g, b, a] = sRGBA; 126 return makeSimpleColorFromFloats(r, g, b, a);127 }128 129 inline SimpleColor makeSimpleColorFromFloats(float r, float g, float b, float a)130 {131 130 return { convertToComponentByte(r), convertToComponentByte(g), convertToComponentByte(b), convertToComponentByte(a) }; 132 131 } -
trunk/Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp
r262128 r263688 81 81 } 82 82 83 return makeSimpleColor FromFloats(componentArray[1], componentArray[2], componentArray[3], componentArray[0]);83 return makeSimpleColor(SRGBA { componentArray[1], componentArray[2], componentArray[3], componentArray[0] }); 84 84 } 85 85 -
trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp
r263000 r263688 145 145 float a = a1 + (a2 - a1) * 0.5f; 146 146 147 return Gradient::ColorStop(offset, makeSimpleColor FromFloats(r, g, b, a));147 return Gradient::ColorStop(offset, makeSimpleColor(SRGBA { r, g, b, a })); 148 148 } 149 149 -
trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp
r262790 r263688 79 79 } 80 80 81 return makeSimpleColor FromFloats(r, g, b, a);81 return makeSimpleColor(SRGBA { r, g, b, a }); 82 82 } 83 83 -
trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm
r262790 r263688 98 98 END_BLOCK_OBJC_EXCEPTIONS; 99 99 100 return makeSimpleColor FromFloats(redComponent, greenComponent, blueComponent, alpha);100 return makeSimpleColor(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) }); 101 101 } 102 102 -
trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp
r262128 r263688 133 133 COMPtr<ID2D1SolidColorBrush> PlatformContextDirect2D::brushWithColor(const D2D1_COLOR_F& color) 134 134 { 135 SimpleColor colorKey = makeSimpleColorFromFloats(color.r, color.g, color.b, color.a);135 auto colorKey = makeSimpleColor(SRGBA { color.r, color.g, color.b, color.a }); 136 136 137 137 if (!colorKey) { -
trunk/Source/WebCore/platform/ios/ColorIOS.mm
r262733 r263688 48 48 [color getRed:&redComponent green:&greenComponent blue:&blueComponent alpha:&alpha]; 49 49 50 return makeSimpleColor FromFloats(redComponent, greenComponent, blueComponent, alpha);50 return makeSimpleColor(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) }); 51 51 } 52 52 -
trunk/Source/WebCore/platform/ios/LegacyTileCache.mm
r262377 r263688 463 463 { 464 464 if (grid == m_zoomedOutTileGrid.get()) 465 return makeSimpleColorFromFloats(0.2f, 1.0f, 0.f, 0.5f); 466 467 return makeSimpleColorFromFloats(0.2f, 0.9f, 0.f, 0.5f); 465 return makeSimpleColor(51, 255, 0, 128); 466 return makeSimpleColor(51, 230, 0, 128); 468 467 } 469 468 -
trunk/Source/WebCore/rendering/RenderLayer.cpp
r263578 r263688 2219 2219 2220 2220 #ifdef REVEAL_TRANSPARENCY_LAYERS 2221 context.setFillColor(makeSimpleColor FromFloats(0.0f, 0.0f, 0.5f, 0.2f));2221 context.setFillColor(makeSimpleColor(0, 0, 128, 51)); 2222 2222 context.fillRect(pixelSnappedClipRect); 2223 2223 #endif -
trunk/Source/WebCore/rendering/RenderThemeIOS.mm
r263293 r263688 381 381 if (checked || indeterminate) { 382 382 auto border = box.style().getRoundedBorderFor(rect); 383 paintInfo.context().fillRoundedRect(border.pixelSnappedRoundedRectForPainting(box.document().deviceScaleFactor()), makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.8f));383 paintInfo.context().fillRoundedRect(border.pixelSnappedRoundedRectForPainting(box.document().deviceScaleFactor()), Color::black.colorWithAlpha(204)); 384 384 385 385 auto clip = addRoundedBorderClip(box, paintInfo.context(), rect); … … 417 417 418 418 lineWidth = std::max<float>(lineWidth, 1); 419 drawJoinedLines(cgContext, Vector<CGPoint> { WTFMove(shadow) }, kCGLineCapSquare, lineWidth, makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.7f));419 drawJoinedLines(cgContext, Vector<CGPoint> { WTFMove(shadow) }, kCGLineCapSquare, lineWidth, Color::black.colorWithAlpha(179)); 420 420 421 421 lineWidth = std::max<float>(std::min(width, height) * thicknessRatio, 1); 422 drawJoinedLines(cgContext, Vector<CGPoint> { WTFMove(line) }, kCGLineCapButt, lineWidth, makeSimpleColorFromFloats(1.0f, 1.0f, 1.0f, 240 / 255.0f));422 drawJoinedLines(cgContext, Vector<CGPoint> { WTFMove(line) }, kCGLineCapButt, lineWidth, Color::white.colorWithAlpha(240)); 423 423 } else { 424 424 auto clip = addRoundedBorderClip(box, paintInfo.context(), rect); … … 478 478 if (isChecked(box)) { 479 479 auto border = box.style().getRoundedBorderFor(rect); 480 paintInfo.context().fillRoundedRect(border.pixelSnappedRoundedRectForPainting(box.document().deviceScaleFactor()), makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.8f));480 paintInfo.context().fillRoundedRect(border.pixelSnappedRoundedRectForPainting(box.document().deviceScaleFactor()), Color::black.colorWithAlpha(204)); 481 481 482 482 auto clip = addRoundedBorderClip(box, paintInfo.context(), rect); … … 491 491 clip.inflateY(-clip.height() * InnerInverseRatio); 492 492 493 constexpr auto shadowColor = makeSimpleColor(0, 0, 0, 0.7f * 255);493 constexpr auto shadowColor = Color::black.colorWithAlpha(179); 494 494 paintInfo.context().drawRaisedEllipse(clip, Color::white, shadowColor); 495 495 … … 739 739 740 740 for (int i = 0; i < count; ++i) { 741 paintInfo.context().drawRaisedEllipse(ellipse, Color::white, makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.5f));741 paintInfo.context().drawRaisedEllipse(ellipse, Color::white, Color::black.colorWithAlpha(128)); 742 742 ellipse.move(size + padding, 0); 743 743 } … … 758 758 }; 759 759 760 float opacity = isReadOnlyControl(box) ? 0.2 : 0.5;761 paintInfo.context().setStrokeColor( makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f,opacity));762 paintInfo.context().setFillColor( makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f,opacity));760 uint8_t opacity = isReadOnlyControl(box) ? 51 : 128; 761 paintInfo.context().setStrokeColor(Color::black.colorWithAlpha(opacity)); 762 paintInfo.context().setFillColor(Color::black.colorWithAlpha(opacity)); 763 763 paintInfo.context().drawPath(Path::polygonPathFromPoints(shadow)); 764 764 … … 1841 1841 // Use the GraphicsContext function, because it calculates the blur radius in context space, 1842 1842 // rather than screen space. 1843 auto shadowColor = makeSimpleColorFromFloats(0.f, 0.f, 0.f, 0.1f);1843 constexpr auto shadowColor = Color::black.colorWithAlpha(26); 1844 1844 graphicsContext.setShadow(FloatSize { }, 16, shadowColor); 1845 1845 -
trunk/Source/WebKit/ChangeLog
r263670 r263688 1 2020-06-29 Sam Weinig <weinig@apple.com> 2 3 Remove remaining makeSimpleColorFrom* variants 4 https://bugs.webkit.org/show_bug.cgi?id=213706 5 6 Reviewed by Darin Adler. 7 8 * UIProcess/API/wpe/WebKitColor.cpp: 9 (webkitColorToWebCoreColor): 10 Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats. 11 12 * WebProcess/Inspector/WebInspectorClient.cpp: 13 (WebKit::WebInspectorClient::showPaintRect): 14 * WebProcess/WebPage/FindController.cpp: 15 (WebKit::FindController::drawRect): 16 Use makeSimpleColor rather than makeSimpleColorFromFloats, allowing for 17 constant expression creation of SimpleColors. 18 1 19 2020-06-29 Youenn Fablet <youenn@apple.com> 2 20 -
trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp
r263000 r263688 76 76 const WebCore::Color webkitColorToWebCoreColor(WebKitColor* color) 77 77 { 78 return WebCore::makeSimpleColorFromFloats(static_cast<float>(color->red), static_cast<float>(color->green), 79 static_cast<float>(color->blue), static_cast<float>(color->alpha)); 78 return WebCore::makeSimpleColor(WebCore::SRGBA { static_cast<float>(color->red), static_cast<float>(color->green), static_cast<float>(color->blue), static_cast<float>(color->alpha) }); 80 79 } 81 80 -
trunk/Source/WebKit/WebProcess/Inspector/WebInspectorClient.cpp
r262377 r263688 178 178 paintLayer->setPosition(rect.location()); 179 179 paintLayer->setSize(rect.size()); 180 paintLayer->setBackgroundColor(makeSimpleColor FromFloats(1.0f, 0.0f, 0.0f, 0.2f));180 paintLayer->setBackgroundColor(makeSimpleColor(255, 0, 0, 51)); 181 181 182 182 KeyframeValueList fadeKeyframes(AnimatedPropertyOpacity); -
trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp
r262377 r263688 510 510 const int borderWidth = 1; 511 511 512 auto overlayBackgroundColor = makeSimpleColorFromFloats(0.1f, 0.1f, 0.1f, 0.25f);513 auto shadowColor = makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.5f);512 constexpr auto overlayBackgroundColor = makeSimpleColor(26, 26, 26, 64); 513 constexpr auto shadowColor = makeSimpleColor(0, 0, 0, 128); 514 514 515 515 IntRect borderInflatedDirtyRect = dirtyRect;
Note: See TracChangeset
for help on using the changeset viewer.