Skip to content

Commit

Permalink
Part 1 of SimpleColor and SRGBA<uint8_t> are essentially the same - l…
Browse files Browse the repository at this point in the history
…et's converge them

https://bugs.webkit.org/show_bug.cgi?id=213948

Reviewed by Darin Adler.

Source/WebCore:

Begin converging SimpleColor and SRGBA<uint8_t>, starting with removing usages that
were getting SimpleColors to access or operate on the color's components.

- Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>
- Replace toSRGBALossy() with toSRGBALossy<float>().
- Remove direct color component accessors from SimpleColor.
- Add new ARGB type to support explicit conversion from packed ARGB bits to a color type.
- Update premulitplication functions to operate on SRGBA<uint8_t> and rename them to
  match existing function operating on SRGBA<float>.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
Removes SimpleColor.cpp

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::colorValue const):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* accessibility/atk/WebKitAccessibleInterfaceText.cpp:
(getAttributeSetForAccessibilityObject):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::colorValue const):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* css/DeprecatedCSSOMRGBColor.h:
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::detectContentInRange):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/Color.cpp:
(WebCore::Color::lightened const):
(WebCore::Color::darkened const):
(WebCore::Color::lightness const):
(WebCore::Color::luminance const):
(WebCore::Color::semanticColor const):
(WebCore::Color::toSRGBASimpleColorLossy const): Deleted.
(WebCore::Color::toSRGBALossy const): Deleted.
* platform/graphics/Color.h:
Remove toSRGBASimpleColorLossy() and templatize toSRGBALossy() to support both
lossy conversion to byte based components as well.

* platform/graphics/ColorBlending.cpp:
(WebCore::blendSourceOver):
(WebCore::blendWithWhite):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

(WebCore::blend):
(WebCore::blendWithoutPremultiply):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>. Adopt new premultipliedCeiling
and unpremultiplied functions that operate on SRGBA<uint8_t> (rather than SimpleColor) and
clamping conversion to SRGBA<uint8_t> via convertToComponentBytes<SRGBA>. premultipliedCeiling
now works correctly for 0 alpha, so no workaround is needed anymore.

* platform/graphics/ColorTypes.h:
(WebCore::asARGB):
(WebCore::asSRGBA):
Add new type of color struct representing a format packing. The initial one is ARGB to support
the few places using SimpleColor to manipulate ARGB pixel data.

* platform/graphics/ColorUtilities.cpp:
(WebCore::unpremultiplied):
(WebCore::premultipliedFlooring):
(WebCore::premultipliedCeiling):
(WebCore::unpremultipliedComponentByte):
* platform/graphics/ColorUtilities.h:
(WebCore::convertToComponentBytes):
(WebCore::convertToComponentFloats):
Move remaining premultiplication functions here (from SimpleColor.h/cpp) and reimplement
to operate on SRGBA<uint8_t>. Also slightly rename, premultiply -> premultiplied, to
match existing premultiplied functions. While moving them, also fix the premultiplied
functions to better support 0 alpha to avoid workarounds in callers.

Additional, this adds convertToComponentBytes/convertToComponentFloats helper functions
which convert to/from uint8_t/float based color types, and support creating color types
from values potentially outside of their supported value range. Right now, that value
range is always considerer to be 0-255 for uint8_t and 0-1 for float, but that can be
chnaged in the future by allowing color type structs to indicate their supported ranges.

* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::toSRGBAFloatComponentsLossy const):
(WebCore::ExtendedColor::toSRGBALossy const): Deleted.
* platform/graphics/ExtendedColor.h:
(WebCore::ExtendedColor::toSRGBALossy const):
Rename existing toSRGBALossy() to toSRGBAFloatComponentsLossy() and replace templatize
toSRGBALossy(), with the uint8_t case just down converting via new convertToComponentBytes.

* platform/graphics/ImageBackingStore.h:
(WebCore::ImageBackingStore::fillRect):
(WebCore::ImageBackingStore::setPixel):
(WebCore::ImageBackingStore::blendPixel):
(WebCore::ImageBackingStore::pixelValue const):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions. Also, update the interface to take pixel
components as uint8_t, rather than unsigned, as that is what the callers are passing anyway,
and it avoids us having to clamp/cast manually all over the case.

* platform/graphics/SimpleColor.cpp: Removed.
* platform/graphics/SimpleColor.h:
(WebCore::SimpleColor::alphaComponent const):
(WebCore::SimpleColor::asSRGBA const):
(WebCore::SimpleColor::redComponent const):
(WebCore::SimpleColor::greenComponent const):
(WebCore::SimpleColor::blueComponent const):
(WebCore::operator==):
(WebCore::makeSimpleColor):
Simplify interface, making red, green and blue component accessors private and having
callers all use SRGBA directly. Remove premultiplication functions in favor of new ones
in ColorUtilities.

* platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
(WebCore::PlatformCAAnimationCocoa::setFromValue):
(WebCore::PlatformCAAnimationCocoa::setToValue):
(WebCore::PlatformCAAnimationCocoa::setValues):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/ca/win/PlatformCAAnimationWin.cpp:
(PlatformCAAnimationWin::setFromValue):
(PlatformCAAnimationWin::setToValue):
(PlatformCAAnimationWin::setValues):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::setSourceRGBAFromColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::addColorStopRGBA):
(WebCore::setCornerColorRGBA):
(WebCore::interpolateColorStop):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:
(WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions.

* platform/graphics/cairo/NativeImageCairo.cpp:
(WebCore::nativeImageSinglePixelSolidColor):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions.

* platform/graphics/cpu/arm/filters/FELightingNEON.h:
(WebCore::FELighting::platformApplyNeon):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::drawLighting):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/filters/FilterOperations.cpp:
(WebCore::FilterOperations::transformColor const):
(WebCore::FilterOperations::inverseTransformColor const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/gtk/ColorGtk.cpp:
(WebCore::Color::operator GdkRGBA const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawBorder):
(WebCore::TextureMapperGL::drawNumber):
(WebCore::prepareFilterProgram):
(WebCore::TextureMapperGL::drawSolidColor):
(WebCore::TextureMapperGL::clearColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/ColorDirect2D.cpp:
(WebCore::Color::operator D2D1_COLOR_F const):
(WebCore::Color::operator D2D1_VECTOR_4F const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/GradientDirect2D.cpp:
(WebCore::Gradient::generateGradient):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/GraphicsContextCGWin.cpp:
(WebCore::GraphicsContext::drawDotsForDocumentMarker):
Replace direct usage component access from SimpleColor with usage of accessed SRGBA<uint8_t>.

* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::colorWithGlobalAlpha const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::disabledTextColor const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/RenderThemeIOS.mm:
(WebCore::shouldUseConvexGradient):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/TextPaintStyle.cpp:
(WebCore::textColorIsLegibleAgainstBackgroundColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* svg/properties/SVGAnimationAdditiveValueFunctionImpl.h:
(WebCore::SVGAnimationColorFunction::animate):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

Source/WebKit:

* UIProcess/API/wpe/WebKitColor.cpp:
(webkitColorFillFromWebCoreColor):
* UIProcess/gtk/ViewGestureControllerGtk.cpp:
(WebKit::ViewGestureController::beginSwipeGesture):
* WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.mm:
(WebKit::animationValueFromKeyframeValue):
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::getDocumentBackgroundColor):
Adapt to use templatized toSRGBALossy<float/uint8_t>.

Tools:

* TestWebKitAPI/Tests/WebCore/ColorTests.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/ExtendedColorTests.cpp:
(TestWebKitAPI::TEST):
Adapt tests to use templatized toSRGBALossy<float/uint8_t>.


Canonical link: https://commits.webkit.org/226765@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263941 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
weinig committed Jul 4, 2020
1 parent 5ba7ba1 commit 1a972b5
Show file tree
Hide file tree
Showing 46 changed files with 521 additions and 269 deletions.
210 changes: 210 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,213 @@
2020-07-04 Sam Weinig <weinig@apple.com>

Part 1 of SimpleColor and SRGBA<uint8_t> are essentially the same - let's converge them
https://bugs.webkit.org/show_bug.cgi?id=213948

Reviewed by Darin Adler.

Begin converging SimpleColor and SRGBA<uint8_t>, starting with removing usages that
were getting SimpleColors to access or operate on the color's components.

- Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>
- Replace toSRGBALossy() with toSRGBALossy<float>().
- Remove direct color component accessors from SimpleColor.
- Add new ARGB type to support explicit conversion from packed ARGB bits to a color type.
- Update premulitplication functions to operate on SRGBA<uint8_t> and rename them to
match existing function operating on SRGBA<float>.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
Removes SimpleColor.cpp

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::AccessibilityNodeObject::colorValue const):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* accessibility/atk/WebKitAccessibleInterfaceText.cpp:
(getAttributeSetForAccessibilityObject):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::colorValue const):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* css/DeprecatedCSSOMRGBColor.h:
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* editing/cocoa/DataDetection.mm:
(WebCore::DataDetection::detectContentInRange):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/Color.cpp:
(WebCore::Color::lightened const):
(WebCore::Color::darkened const):
(WebCore::Color::lightness const):
(WebCore::Color::luminance const):
(WebCore::Color::semanticColor const):
(WebCore::Color::toSRGBASimpleColorLossy const): Deleted.
(WebCore::Color::toSRGBALossy const): Deleted.
* platform/graphics/Color.h:
Remove toSRGBASimpleColorLossy() and templatize toSRGBALossy() to support both
lossy conversion to byte based components as well.

* platform/graphics/ColorBlending.cpp:
(WebCore::blendSourceOver):
(WebCore::blendWithWhite):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

(WebCore::blend):
(WebCore::blendWithoutPremultiply):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>. Adopt new premultipliedCeiling
and unpremultiplied functions that operate on SRGBA<uint8_t> (rather than SimpleColor) and
clamping conversion to SRGBA<uint8_t> via convertToComponentBytes<SRGBA>. premultipliedCeiling
now works correctly for 0 alpha, so no workaround is needed anymore.

* platform/graphics/ColorTypes.h:
(WebCore::asARGB):
(WebCore::asSRGBA):
Add new type of color struct representing a format packing. The initial one is ARGB to support
the few places using SimpleColor to manipulate ARGB pixel data.

* platform/graphics/ColorUtilities.cpp:
(WebCore::unpremultiplied):
(WebCore::premultipliedFlooring):
(WebCore::premultipliedCeiling):
(WebCore::unpremultipliedComponentByte):
* platform/graphics/ColorUtilities.h:
(WebCore::convertToComponentBytes):
(WebCore::convertToComponentFloats):
Move remaining premultiplication functions here (from SimpleColor.h/cpp) and reimplement
to operate on SRGBA<uint8_t>. Also slightly rename, premultiply -> premultiplied, to
match existing premultiplied functions. While moving them, also fix the premultiplied
functions to better support 0 alpha to avoid workarounds in callers.

Additional, this adds convertToComponentBytes/convertToComponentFloats helper functions
which convert to/from uint8_t/float based color types, and support creating color types
from values potentially outside of their supported value range. Right now, that value
range is always considerer to be 0-255 for uint8_t and 0-1 for float, but that can be
chnaged in the future by allowing color type structs to indicate their supported ranges.

* platform/graphics/ExtendedColor.cpp:
(WebCore::ExtendedColor::toSRGBAFloatComponentsLossy const):
(WebCore::ExtendedColor::toSRGBALossy const): Deleted.
* platform/graphics/ExtendedColor.h:
(WebCore::ExtendedColor::toSRGBALossy const):
Rename existing toSRGBALossy() to toSRGBAFloatComponentsLossy() and replace templatize
toSRGBALossy(), with the uint8_t case just down converting via new convertToComponentBytes.

* platform/graphics/ImageBackingStore.h:
(WebCore::ImageBackingStore::fillRect):
(WebCore::ImageBackingStore::setPixel):
(WebCore::ImageBackingStore::blendPixel):
(WebCore::ImageBackingStore::pixelValue const):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions. Also, update the interface to take pixel
components as uint8_t, rather than unsigned, as that is what the callers are passing anyway,
and it avoids us having to clamp/cast manually all over the case.

* platform/graphics/SimpleColor.cpp: Removed.
* platform/graphics/SimpleColor.h:
(WebCore::SimpleColor::alphaComponent const):
(WebCore::SimpleColor::asSRGBA const):
(WebCore::SimpleColor::redComponent const):
(WebCore::SimpleColor::greenComponent const):
(WebCore::SimpleColor::blueComponent const):
(WebCore::operator==):
(WebCore::makeSimpleColor):
Simplify interface, making red, green and blue component accessors private and having
callers all use SRGBA directly. Remove premultiplication functions in favor of new ones
in ColorUtilities.

* platform/graphics/ca/cocoa/PlatformCAAnimationCocoa.mm:
(WebCore::PlatformCAAnimationCocoa::setFromValue):
(WebCore::PlatformCAAnimationCocoa::setToValue):
(WebCore::PlatformCAAnimationCocoa::setValues):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/ca/win/PlatformCAAnimationWin.cpp:
(PlatformCAAnimationWin::setFromValue):
(PlatformCAAnimationWin::setToValue):
(PlatformCAAnimationWin::setValues):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/cairo/CairoUtilities.cpp:
(WebCore::setSourceRGBAFromColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/cairo/GradientCairo.cpp:
(WebCore::addColorStopRGBA):
(WebCore::setCornerColorRGBA):
(WebCore::interpolateColorStop):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/cairo/ImageBufferCairoImageSurfaceBackend.cpp:
(WebCore::ImageBufferCairoImageSurfaceBackend::platformTransformColorSpace):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions.

* platform/graphics/cairo/NativeImageCairo.cpp:
(WebCore::nativeImageSinglePixelSolidColor):
Replace usage of SimpleColor with new ARGB type for conversion from ARGB to SRGBA<uint8_t>.
Update to use new premulitplication functions.

* platform/graphics/cpu/arm/filters/FELightingNEON.h:
(WebCore::FELighting::platformApplyNeon):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

* platform/graphics/filters/FELighting.cpp:
(WebCore::FELighting::drawLighting):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/filters/FilterOperations.cpp:
(WebCore::FilterOperations::transformColor const):
(WebCore::FilterOperations::inverseTransformColor const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/gtk/ColorGtk.cpp:
(WebCore::Color::operator GdkRGBA const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/texmap/TextureMapperGL.cpp:
(WebCore::TextureMapperGL::drawBorder):
(WebCore::TextureMapperGL::drawNumber):
(WebCore::prepareFilterProgram):
(WebCore::TextureMapperGL::drawSolidColor):
(WebCore::TextureMapperGL::clearColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/ColorDirect2D.cpp:
(WebCore::Color::operator D2D1_COLOR_F const):
(WebCore::Color::operator D2D1_VECTOR_4F const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/GradientDirect2D.cpp:
(WebCore::Gradient::generateGradient):
Replace toSRGBALossy() with toSRGBALossy<float>().

* platform/graphics/win/GraphicsContextCGWin.cpp:
(WebCore::GraphicsContext::drawDotsForDocumentMarker):
Replace direct usage component access from SimpleColor with usage of accessed SRGBA<uint8_t>.

* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::colorWithGlobalAlpha const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/RenderTheme.cpp:
(WebCore::RenderTheme::disabledTextColor const):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/RenderThemeIOS.mm:
(WebCore::shouldUseConvexGradient):
Replace toSRGBALossy() with toSRGBALossy<float>().

* rendering/TextPaintStyle.cpp:
(WebCore::textColorIsLegibleAgainstBackgroundColor):
Replace toSRGBALossy() with toSRGBALossy<float>().

* svg/properties/SVGAnimationAdditiveValueFunctionImpl.h:
(WebCore::SVGAnimationColorFunction::animate):
Replace toSRGBASimpleColorLossy() with toSRGBALossy<uint8_t>.

2020-07-04 Zalan Bujtas <zalan@apple.com>

[LFC] Remove redundant Display::Box::HorizontalMargin c'tors
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/Sources.txt
Expand Up @@ -1886,7 +1886,6 @@ platform/graphics/Region.cpp
platform/graphics/RemoteVideoSample.cpp
platform/graphics/RoundedRect.cpp
platform/graphics/ShadowBlur.cpp
platform/graphics/SimpleColor.cpp
platform/graphics/StringTruncator.cpp
platform/graphics/SurrogatePairAwareTextIterator.cpp
platform/graphics/TextRun.cpp
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Expand Up @@ -9984,7 +9984,6 @@
7C30D9801F815AC100268356 /* JSAbortController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbortController.h; sourceTree = "<group>"; };
7C30D9811F815AC100268356 /* JSAbortSignal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbortSignal.h; sourceTree = "<group>"; };
7C30D9821F815AC200268356 /* JSAbortSignal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAbortSignal.cpp; sourceTree = "<group>"; };
7C31C88A247AD594005BF319 /* SimpleColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SimpleColor.cpp; sourceTree = "<group>"; };
7C31C88C247AD595005BF319 /* SimpleColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleColor.h; sourceTree = "<group>"; };
7C330A011DF8FAC600D3395C /* GraphicsContextGLAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLAttributes.h; sourceTree = "<group>"; };
7C330A031DF9E95B00D3395C /* PositionOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = PositionOptions.idl; sourceTree = "<group>"; };
Expand Down Expand Up @@ -25697,7 +25696,6 @@
A73F95FD12C97BFE0031AAF9 /* RoundedRect.h */,
0F3DD44D12F5EA1B000D9190 /* ShadowBlur.cpp */,
0F3DD44E12F5EA1B000D9190 /* ShadowBlur.h */,
7C31C88A247AD594005BF319 /* SimpleColor.cpp */,
7C31C88C247AD595005BF319 /* SimpleColor.h */,
CD641EB21818F5ED00EE4C41 /* SourceBufferPrivate.h */,
CDC8B5AC1804AE5D0016E685 /* SourceBufferPrivateClient.h */,
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Expand Up @@ -1983,10 +1983,10 @@ void AccessibilityNodeObject::colorValue(int& r, int& g, int& b) const
if (!is<HTMLInputElement>(node()))
return;

auto color = downcast<HTMLInputElement>(*node()).valueAsColor().toSRGBASimpleColorLossy();
r = color.redComponent();
g = color.greenComponent();
b = color.blueComponent();
auto color = downcast<HTMLInputElement>(*node()).valueAsColor().toSRGBALossy<uint8_t>();
r = color.red;
g = color.green;
b = color.blue;
#endif
}

Expand Down
Expand Up @@ -92,14 +92,14 @@ static AtkAttributeSet* getAttributeSetForAccessibilityObject(const Accessibilit

Color bgColor = style->visitedDependentColor(CSSPropertyBackgroundColor);
if (bgColor.isValid()) {
auto [r, g, b, a] = bgColor.toSRGBASimpleColorLossy();
auto [r, g, b, a] = bgColor.toSRGBALossy<uint8_t>();
buffer.reset(g_strdup_printf("%i,%i,%i", r, g, b));
result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_BG_COLOR), buffer.get());
}

Color fgColor = style->visitedDependentColor(CSSPropertyColor);
if (fgColor.isValid()) {
auto [r, g, b, a] = fgColor.toSRGBASimpleColorLossy();
auto [r, g, b, a] = fgColor.toSRGBALossy<uint8_t>();
buffer.reset(g_strdup_printf("%i,%i,%i", r, g, b));
result = addToAtkAttributeSet(result, atk_text_attribute_get_name(ATK_TEXT_ATTR_FG_COLOR), buffer.get());
}
Expand Down
Expand Up @@ -701,10 +701,10 @@ void AXIsolatedObject::setPreventKeyboardDOMEventDispatch(bool value)

void AXIsolatedObject::colorValue(int& r, int& g, int& b) const
{
auto color = colorAttributeValue(AXPropertyName::ColorValue).toSRGBASimpleColorLossy();
r = color.redComponent();
g = color.greenComponent();
b = color.blueComponent();
auto color = colorAttributeValue(AXPropertyName::ColorValue).toSRGBALossy<uint8_t>();
r = color.red;
g = color.green;
b = color.blue;
}

AXCoreObject* AXIsolatedObject::accessibilityHitTest(const IntPoint& point) const
Expand Down
14 changes: 7 additions & 7 deletions Source/WebCore/css/DeprecatedCSSOMRGBColor.h
Expand Up @@ -37,7 +37,7 @@ class DeprecatedCSSOMRGBColor final : public RefCounted<DeprecatedCSSOMRGBColor>
DeprecatedCSSOMPrimitiveValue& blue() { return m_blue; }
DeprecatedCSSOMPrimitiveValue& alpha() { return m_alpha; }

SimpleColor color() const { return m_color; }
SimpleColor color() const { return makeSimpleColor(m_color); }

private:
template<typename NumberType> static Ref<DeprecatedCSSOMPrimitiveValue> createWrapper(CSSStyleDeclaration& owner, NumberType number)
Expand All @@ -46,15 +46,15 @@ class DeprecatedCSSOMRGBColor final : public RefCounted<DeprecatedCSSOMRGBColor>
}

DeprecatedCSSOMRGBColor(CSSStyleDeclaration& owner, const Color& color)
: m_color(color.toSRGBASimpleColorLossy())
, m_red(createWrapper(owner, m_color.redComponent()))
, m_green(createWrapper(owner, m_color.greenComponent()))
, m_blue(createWrapper(owner, m_color.blueComponent()))
, m_alpha(createWrapper(owner, m_color.alphaComponentAsFloat()))
: m_color(color.toSRGBALossy<uint8_t>())
, m_red(createWrapper(owner, m_color.red))
, m_green(createWrapper(owner, m_color.green))
, m_blue(createWrapper(owner, m_color.blue))
, m_alpha(createWrapper(owner, convertToComponentFloat(m_color.alpha)))
{
}

SimpleColor m_color;
SRGBA<uint8_t> m_color;
Ref<DeprecatedCSSOMPrimitiveValue> m_red;
Ref<DeprecatedCSSOMPrimitiveValue> m_green;
Ref<DeprecatedCSSOMPrimitiveValue> m_blue;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/editing/cocoa/DataDetection.mm
Expand Up @@ -621,7 +621,7 @@ static inline CFComparisonResult queryOffsetCompare(DDQueryOffset o1, DDQueryOff
if (renderStyle) {
auto textColor = renderStyle->visitedDependentColor(CSSPropertyColor);
if (textColor.isValid()) {
auto hsla = toHSLA(textColor.toSRGBALossy());
auto hsla = toHSLA(textColor.toSRGBALossy<float>());

// Force the lightness of the underline color to the middle, and multiply the alpha by 38%,
// so the color will appear on light and dark backgrounds, since only one color can be specified.
Expand Down
24 changes: 5 additions & 19 deletions Source/WebCore/platform/graphics/Color.cpp
Expand Up @@ -86,7 +86,7 @@ Color Color::lightened() const
if (isSimple() && asSimple() == black)
return lightenedBlack;

auto [r, g, b, a] = toSRGBALossy();
auto [r, g, b, a] = toSRGBALossy<float>();
float v = std::max({ r, g, b });

if (v == 0.0f)
Expand All @@ -103,7 +103,7 @@ Color Color::darkened() const
if (isSimple() && asSimple() == white)
return darkenedWhite;

auto [r, g, b, a] = toSRGBALossy();
auto [r, g, b, a] = toSRGBALossy<float>();

float v = std::max({ r, g, b });
float multiplier = std::max(0.0f, (v - 0.33f) / v);
Expand All @@ -114,14 +114,14 @@ Color Color::darkened() const
float Color::lightness() const
{
// FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms for HSL.
return WebCore::lightness(toSRGBALossy());
return WebCore::lightness(toSRGBALossy<float>());
}

float Color::luminance() const
{
// FIXME: This can probably avoid conversion to sRGB by having per-colorspace algorithms
// for luminance (e.g. convertToXYZ(c).yComponent()).
return WebCore::luminance(toSRGBALossy());
return WebCore::luminance(toSRGBALossy<float>());
}

Color Color::colorWithAlpha(float alpha) const
Expand Down Expand Up @@ -149,7 +149,7 @@ Color Color::semanticColor() const
if (isSemantic())
return *this;

return { toSRGBASimpleColorLossy(), Semantic };
return { makeSimpleColor(toSRGBALossy<uint8_t>()), Semantic };
}

std::pair<ColorSpace, ColorComponents<float>> Color::colorSpaceAndComponents() const
Expand All @@ -159,20 +159,6 @@ std::pair<ColorSpace, ColorComponents<float>> Color::colorSpaceAndComponents() c
return { ColorSpace::SRGB, asColorComponents(asSimple().asSRGBA<float>()) };
}

SimpleColor Color::toSRGBASimpleColorLossy() const
{
if (isExtended())
return makeSimpleColor(asExtended().toSRGBALossy());
return asSimple();
}

SRGBA<float> Color::toSRGBALossy() const
{
if (isExtended())
return asExtended().toSRGBALossy();
return asSimple().asSRGBA<float>();
}

TextStream& operator<<(TextStream& ts, const Color& color)
{
return ts << serializationForRenderTreeAsText(color);
Expand Down

0 comments on commit 1a972b5

Please sign in to comment.