Changeset 263688 in webkit


Ignore:
Timestamp:
Jun 29, 2020 1:31:18 PM (4 years ago)
Author:
weinig@apple.com
Message:

Remove remaining makeSimpleColorFrom* variants
https://bugs.webkit.org/show_bug.cgi?id=213706

Reviewed by Darin Adler.

Source/WebCore:

Removed makeSimpleColorFromFloats and makeSimpleColorFromCMYKA.

  • Updated callers that need to pass floats to use makeSimpleColor(SRGBA { ... });
  • Updated callers that don't need to pass floats, mostly compile time constant SimpleColors to use makeSimpleColor(...), passing in 0-255 based component values.
  • Updated callers of makeSimpleColorFromCMYKA to use makeSimpleColor(toSRGBA(CMYKA { ... })). This required adding CMYKA type to ColorTypes.h and moving conversion SRGBA to ColorUtilities with the other color conversion code.
  • Added deduction guides for color types to allow component type deduction. This allows us to write:

function(SRGBA { redFloat, greenFloat, blueFloat, alphaFloat })

reather than the more cumbersome:

function(SRGBA<float> { redFloat, greenFloat, blueFloat, alphaFloat })

  • Added operator==/operator!= for each color type. Only used by CMYKA at the moment, but generally useful, so added for all of them. For all types convertable to ColorComponents, the implementation uses the conversion to ColorComponents to avoid redundancy.
  • html/canvas/CanvasRenderingContext2DBase.cpp:

(WebCore::CanvasRenderingContext2DBase::setStrokeColor):
(WebCore::CanvasRenderingContext2DBase::setFillColor):
Update to call new typed color based CanvasStyle functions.
(WebCore::CanvasRenderingContext2DBase::setShadow):
Use makeSimpleColor rather than makeSimpleColorFromFloats/makeSimpleColorFromCMYKA.

  • html/canvas/CanvasStyle.cpp:

(WebCore::CanvasStyle::CanvasStyle):
Replace constructors taking raw floats with ones taking typed colors (SRGBA<float>/CMYKA<float>)
to make it more clear what the parameters mean.
(WebCore::CanvasStyle::isEquivalentColor const):
Compare the cmyka components using new operator== implementation for CMYKA<float>.
(WebCore::CanvasStyle::isEquivalent const):
(WebCore::CanvasStyle::isEquivalentRGBA const): Deleted.
(WebCore::CanvasStyle::isEquivalentCMYKA const): Deleted.
Replace isEquivalentRGBA/isEquivalentCMYKA with overloaded isEquivalent.
(WebCore::CanvasStyle::applyStrokeColor const):
(WebCore::CanvasStyle::applyFillColor const):
Update for new names of CMYKA members.

  • html/canvas/CanvasStyle.h:

Use SRGBA<float> and CMYKA<float> to simplify interfaces

  • page/DebugPageOverlays.cpp:
  • page/linux/ResourceUsageOverlayLinux.cpp:

(WebCore::ResourceUsageOverlay::platformInitialize):
Use makeSimpleColor rather than makeSimpleColorFromFloats, allowing for
constant expression creation of SimpleColors.

  • platform/graphics/Color.cpp:

(WebCore::Color::lightened const):
(WebCore::Color::darkened const):
Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats.

(WebCore::Color::luminance const):
Fix comment.

(WebCore::blendWithoutPremultiply):
Use makeSimpleColor(...) rather than makeSimpleColorFromFloats.

  • platform/graphics/ColorTypes.h:

(WebCore::operator==):
(WebCore::operator!=):

  • Add deduction guides and operator==/operator!= for each color type.
  • Add CMYKA type. No conversion to ColorComponents yet, as ColorComponents only works with 4 component colors, not ones with 5 like CMYKA.
  • platform/graphics/ColorUtilities.cpp:

(WebCore::toSRGBA):
Move conversion from CMYKA to SRGBA from makeSimpleColorFromCMYKA to here.

  • platform/graphics/ColorUtilities.h:

(WebCore::convertPrescaledToComponentByte):
(WebCore::convertToComponentByte):
Use std::round rather than std::lroundf, since it will have the same result
and it reads nicer.

  • platform/graphics/SimpleColor.cpp:

(WebCore::makeSimpleColorFromCMYKA): Deleted.

  • platform/graphics/SimpleColor.h:

(WebCore::makeSimpleColor):
(WebCore::makeSimpleColorFromFloats): Deleted.

  • Removed makeSimpleColorFromFloats and makeSimpleColorFromCMYKA.
  • Added constexpr overload of makeSimpleColor taking a const SRGBA<uint8_t>&.
  • Fixed forward declaration of makeSimpleColor that was taking ColorComponents to actually take an SRGBA<float>, which is what the inline implementation actually takes.
  • platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp:

(WebCore::makeSimpleColorFromARGBCFArray):

  • platform/graphics/cairo/GradientCairo.cpp:

(WebCore::interpolateColorStop):

  • platform/graphics/cg/ColorCG.cpp:

(WebCore::makeSimpleColorFromCGColor):

  • platform/graphics/win/PlatformContextDirect2D.cpp:

(WebCore::PlatformContextDirect2D::brushWithColor):
Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats.

  • platform/graphics/mac/ColorMac.mm:

(WebCore::makeSimpleColorFromNSColor):

  • platform/ios/ColorIOS.mm:

(WebCore::colorFromUIColor):
Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats. Casting to
float is needed, as the input types are CGFloat which is double in 64-bit environments
and won't automatically narrow with the new types.

  • platform/ios/LegacyTileCache.mm:

(WebCore::LegacyTileCache::colorForGridTileBorder const):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::beginTransparencyLayers):
Use makeSimpleColor rather than makeSimpleColorFromFloats, allowing for
constant expression creation of SimpleColors.

  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::paintCheckboxDecorations):
(WebCore::RenderThemeIOS::paintRadioDecorations):
(WebCore::RenderThemeIOS::paintMenuListButtonDecorations):
(WebCore::RenderThemeIOS::paintSystemPreviewBadge):
Use Color::black/Color::white.colorWithAlpha(...) rather than makeSimpleColorFromFloats,
allowing for constant expression creation of SimpleColors.

Source/WebKit:

  • UIProcess/API/wpe/WebKitColor.cpp:

(webkitColorToWebCoreColor):
Use makeSimpleColor(SRGBA { ... }) rather than makeSimpleColorFromFloats.

  • WebProcess/Inspector/WebInspectorClient.cpp:

(WebKit::WebInspectorClient::showPaintRect):

  • WebProcess/WebPage/FindController.cpp:

(WebKit::FindController::drawRect):
Use makeSimpleColor rather than makeSimpleColorFromFloats, allowing for
constant expression creation of SimpleColors.

Location:
trunk/Source
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r263673 r263688  
     12020-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
    11302020-06-29  Chris Fleizach  <cfleizach@apple.com>
    2131
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp

    r262733 r263688  
    372372        return;
    373373
    374     if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentColor(style))
     374    if (state().strokeStyle.isEquivalentColor(style))
    375375        return;
    376376
     
    395395        return;
    396396
    397     if (state().fillStyle.isValid() && state().fillStyle.isEquivalentColor(style))
     397    if (state().fillStyle.isEquivalentColor(style))
    398398        return;
    399399
     
    915915void CanvasRenderingContext2DBase::setStrokeColor(float grayLevel, float alpha)
    916916{
    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));
    920921}
    921922
    922923void CanvasRenderingContext2DBase::setStrokeColor(float r, float g, float b, float a)
    923924{
    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));
    927929}
    928930
    929931void CanvasRenderingContext2DBase::setStrokeColor(float c, float m, float y, float k, float a)
    930932{
    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));
    934937}
    935938
     
    951954void CanvasRenderingContext2DBase::setFillColor(float grayLevel, float alpha)
    952955{
    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));
    956960}
    957961
    958962void CanvasRenderingContext2DBase::setFillColor(float r, float g, float b, float a)
    959963{
    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));
    963968}
    964969
    965970void CanvasRenderingContext2DBase::setFillColor(float c, float m, float y, float k, float a)
    966971{
    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));
    970976}
    971977
     
    13081314void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float grayLevel, float alpha)
    13091315{
    1310     setShadow(FloatSize(width, height), blur, makeSimpleColorFromFloats(grayLevel, grayLevel, grayLevel, alpha));
     1316    setShadow(FloatSize(width, height), blur, makeSimpleColor(SRGBA { grayLevel, grayLevel, grayLevel, alpha }));
    13111317}
    13121318
    13131319void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float r, float g, float b, float a)
    13141320{
    1315     setShadow(FloatSize(width, height), blur, makeSimpleColorFromFloats(r, g, b, a));
     1321    setShadow(FloatSize(width, height), blur, makeSimpleColor(SRGBA { r, g, b, a }));
    13161322}
    13171323
    13181324void CanvasRenderingContext2DBase::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a)
    13191325{
    1320     setShadow(FloatSize(width, height), blur, makeSimpleColorFromCMYKA(c, m, y, k, a));
     1326    setShadow(FloatSize(width, height), blur, makeSimpleColor(toSRGBA(CMYKA { c, m, y, k, a })));
    13211327}
    13221328
  • trunk/Source/WebCore/html/canvas/CanvasStyle.cpp

    r262733 r263688  
    9393}
    9494
    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 })
     95CanvasStyle::CanvasStyle(const SRGBA<float>& colorComponents)
     96    : m_style(makeSimpleColor(colorComponents))
     97{
     98}
     99
     100CanvasStyle::CanvasStyle(const CMYKA<float>& colorComponents)
     101    : m_style(CMYKAColor { makeSimpleColor(toSRGBA(colorComponents)), colorComponents })
    107102{
    108103}
     
    152147        return WTF::get<Color>(m_style) == WTF::get<Color>(other.m_style);
    153148
    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;
    159151
    160152    return false;
    161153}
    162154
    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;
     155bool 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
     160bool CanvasStyle::isEquivalent(const CMYKA<float>& components) const
     161{
     162    return WTF::holds_alternative<CMYKAColor>(m_style) && WTF::get<CMYKAColor>(m_style).components == components;
    175163}
    176164
     
    185173            // We'll need a fancier Color abstraction to support CMYKA correctly
    186174#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);
    188176#else
    189             context.setStrokeColor(color.color);
     177            context.setStrokeColor(color.colorConvertedToSRGBA);
    190178#endif
    191179        },
     
    215203            // We'll need a fancier Color abstraction to support CMYKA correctly
    216204#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);
    218206#else
    219             context.setFillColor(color.color);
     207            context.setFillColor(color.colorConvertedToSRGBA);
    220208#endif
    221209        },
  • trunk/Source/WebCore/html/canvas/CanvasStyle.h

    r262035 r263688  
    4242    CanvasStyle();
    4343    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>&);
    4746    CanvasStyle(CanvasGradient&);
    4847    CanvasStyle(CanvasPattern&);
     
    5453    bool isCurrentColor() const { return WTF::holds_alternative<CurrentColor>(m_style); }
    5554    Optional<float> overrideAlpha() const { return WTF::get<CurrentColor>(m_style).overrideAlpha; }
    56    
    5755
    5856    String color() const;
     
    6462
    6563    bool isEquivalentColor(const CanvasStyle&) const;
    66     bool isEquivalentRGBA(float red, float green, float blue, float alpha) const;
    67     bool isEquivalentCMYKA(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;
    6866
    6967private:
     
    7169
    7270    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;
    8173    };
    8274
     
    117109inline String CanvasStyle::color() const
    118110{
    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;
    120112    return color.serialized();
    121113}
  • trunk/Source/WebCore/page/DebugPageOverlays.cpp

    r262377 r263688  
    8383private:
    8484    explicit MouseWheelRegionOverlay(Page& page)
    85         : RegionOverlay(page, makeSimpleColorFromFloats(0.5f, 0.0f, 0.0f, 0.4f))
     85        : RegionOverlay(page, makeSimpleColor(128, 0, 0, 102))
    8686    {
    8787    }
     
    119119private:
    120120    explicit NonFastScrollableRegionOverlay(Page& page)
    121         : RegionOverlay(page, makeSimpleColorFromFloats(1.0f, 0.5f, 0.0f, 0.4f))
     121        : RegionOverlay(page, makeSimpleColor(255, 128, 0, 102))
    122122    {
    123123    }
  • trunk/Source/WebCore/page/linux/ResourceUsageOverlayLinux.cpp

    r262377 r263688  
    8989    {
    9090        GraphicsContextStateSaver stateSaver(context);
    91         context.fillRect(clip, makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.8f));
    92         context.setFillColor(makeSimpleColorFromFloats(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));
    9393
    9494        FloatPoint position = { 10, 20 };
     
    138138    m_paintLayer->setAnchorPoint(FloatPoint3D());
    139139    m_paintLayer->setSize({ normalWidth, normalHeight });
    140     m_paintLayer->setBackgroundColor(makeSimpleColorFromFloats(0.0f, 0.0f, 0.0f, 0.8f));
     140    m_paintLayer->setBackgroundColor(makeSimpleColor(0, 0, 0, 204));
    141141    m_paintLayer->setDrawsContent(true);
    142142    overlay().layer().addChild(*m_paintLayer);
  • trunk/Source/WebCore/platform/graphics/Color.cpp

    r263000 r263688  
    115115    float multiplier = std::min(1.0f, v + 0.33f) / v;
    116116
    117     return makeSimpleColorFromFloats(multiplier * r, multiplier * g, multiplier * b, a);
     117    return makeSimpleColor(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
    118118}
    119119
     
    129129    float multiplier = std::max(0.0f, (v - 0.33f) / v);
    130130
    131     return makeSimpleColorFromFloats(multiplier * r, multiplier * g, multiplier * b, a);
     131    return makeSimpleColor(SRGBA { multiplier * r, multiplier * g, multiplier * b, a });
    132132}
    133133
     
    148148float Color::luminance() const
    149149{
    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()).
    151152    return WebCore::luminance(toSRGBALossy());
    152153}
     
    291292    auto toSRGB = from.toSRGBASimpleColorLossy();
    292293
    293     return makeSimpleColorFromFloats(
     294    return makeSimpleColor(
    294295        WebCore::blend(fromSRGB.redComponent(), toSRGB.redComponent(), progress),
    295296        WebCore::blend(fromSRGB.greenComponent(), toSRGB.greenComponent(), progress),
  • trunk/Source/WebCore/platform/graphics/ColorTypes.h

    r263000 r263688  
    3737};
    3838
     39template<typename T> SRGBA(T, T, T, T) -> SRGBA<T>;
     40
    3941template<typename T> constexpr ColorComponents<T> asColorComponents(const SRGBA<T>& c)
    4042{
     
    4547{
    4648    return { c[0], c[1], c[2], c[3] };
     49}
     50
     51template<typename T> constexpr bool operator==(const SRGBA<T>& a, const SRGBA<T>& b)
     52{
     53    return asColorComponents(a) == asColorComponents(b);
     54}
     55
     56template<typename T> constexpr bool operator!=(const SRGBA<T>& a, const SRGBA<T>& b)
     57{
     58    return !(a == b);
    4759}
    4860
     
    5466}
    5567
     68
    5669template<typename T> struct LinearSRGBA {
    5770    T red;
     
    6174};
    6275
     76template<typename T> LinearSRGBA(T, T, T, T) -> LinearSRGBA<T>;
     77
    6378template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearSRGBA<T>& c)
    6479{
     
    7186}
    7287
     88template<typename T> constexpr bool operator==(const LinearSRGBA<T>& a, const LinearSRGBA<T>& b)
     89{
     90    return asColorComponents(a) == asColorComponents(b);
     91}
     92
     93template<typename T> constexpr bool operator!=(const LinearSRGBA<T>& a, const LinearSRGBA<T>& b)
     94{
     95    return !(a == b);
     96}
     97
     98
    7399template<typename T> struct DisplayP3 {
    74100    T red;
     
    78104};
    79105
     106template<typename T> DisplayP3(T, T, T, T) -> DisplayP3<T>;
     107
    80108template<typename T> constexpr ColorComponents<T> asColorComponents(const DisplayP3<T>& c)
    81109{
     
    88116}
    89117
     118template<typename T> constexpr bool operator==(const DisplayP3<T>& a, const DisplayP3<T>& b)
     119{
     120    return asColorComponents(a) == asColorComponents(b);
     121}
     122
     123template<typename T> constexpr bool operator!=(const DisplayP3<T>& a, const DisplayP3<T>& b)
     124{
     125    return !(a == b);
     126}
     127
     128
    90129template<typename T> struct LinearDisplayP3 {
    91130    T red;
     
    95134};
    96135
     136template<typename T> LinearDisplayP3(T, T, T, T) -> LinearDisplayP3<T>;
     137
    97138template<typename T> constexpr ColorComponents<T> asColorComponents(const LinearDisplayP3<T>& c)
    98139{
     
    104145    return { c[0], c[1], c[2], c[3] };
    105146}
     147
     148template<typename T> constexpr bool operator==(const LinearDisplayP3<T>& a, const LinearDisplayP3<T>& b)
     149{
     150    return asColorComponents(a) == asColorComponents(b);
     151}
     152
     153template<typename T> constexpr bool operator!=(const LinearDisplayP3<T>& a, const LinearDisplayP3<T>& b)
     154{
     155    return !(a == b);
     156}
     157
    106158
    107159template<typename T> struct HSLA {
     
    112164};
    113165
     166template<typename T> HSLA(T, T, T, T) -> HSLA<T>;
     167
    114168template<typename T> constexpr ColorComponents<T> asColorComponents(const HSLA<T>& c)
    115169{
     
    121175    return { c[0], c[1], c[2], c[3] };
    122176}
     177
     178template<typename T> constexpr bool operator==(const HSLA<T>& a, const HSLA<T>& b)
     179{
     180    return asColorComponents(a) == asColorComponents(b);
     181}
     182
     183template<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
     190template<typename T> struct CMYKA {
     191    T cyan;
     192    T magenta;
     193    T yellow;
     194    T black;
     195    T alpha;
     196};
     197
     198template<typename T> CMYKA(T, T, T, T, T) -> CMYKA<T>;
     199
     200template<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
     205template<typename T> constexpr bool operator!=(const CMYKA<T>& a, const CMYKA<T>& b)
     206{
     207    return !(a == b);
     208}
     209
    123210
    124211template<typename T> struct XYZA {
     
    129216};
    130217
     218template<typename T> XYZA(T, T, T, T) -> XYZA<T>;
     219
    131220template<typename T> constexpr ColorComponents<T> asColorComponents(const XYZA<T>& c)
    132221{
     
    139228}
    140229
     230template<typename T> constexpr bool operator==(const XYZA<T>& a, const XYZA<T>& b)
     231{
     232    return asColorComponents(a) == asColorComponents(b);
     233}
     234
     235template<typename T> constexpr bool operator!=(const XYZA<T>& a, const XYZA<T>& b)
     236{
     237    return !(a == b);
     238}
     239
    141240} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.cpp

    r263000 r263688  
    260260}
    261261
     262SRGBA<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
    262272SRGBA<float> premultiplied(const SRGBA<float>& color)
    263273{
  • trunk/Source/WebCore/platform/graphics/ColorUtilities.h

    r263000 r263688  
    3131namespace WebCore {
    3232
     33template<typename> struct CMYKA;
    3334template<typename> struct DisplayP3;
    3435template<typename> struct HSLA;
     
    5354WEBCORE_EXPORT SRGBA<float> toSRGBA(const HSLA<float>&);
    5455
     56SRGBA<float> toSRGBA(const CMYKA<float>&);
     57
     58
    5559float lightness(const SRGBA<float>&);
    5660float luminance(const SRGBA<float>&);
    57 
    5861float contrastRatio(const SRGBA<float>&, const SRGBA<float>&);
    5962
     
    6265inline uint8_t convertPrescaledToComponentByte(float f)
    6366{
    64     return std::clamp(static_cast<int>(std::lroundf(f)), 0, 255);
     67    return std::clamp(std::lround(f), 0l, 255l);
    6568}
    6669
    6770inline uint8_t convertToComponentByte(float f)
    6871{
    69     return std::clamp(static_cast<int>(std::lroundf(f * 255.0f)), 0, 255);
     72    return std::clamp(std::lround(f * 255.0f), 0l, 255l);
    7073}
    7174
  • trunk/Source/WebCore/platform/graphics/SimpleColor.cpp

    r262810 r263688  
    6363}
    6464
    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 
    7465String SimpleColor::serializationForHTML() const
    7566{
  • trunk/Source/WebCore/platform/graphics/SimpleColor.h

    r263000 r263688  
    9292constexpr SimpleColor makeSimpleColor(int r, int g, int b);
    9393constexpr 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);
     94constexpr SimpleColor makeSimpleColor(const SRGBA<uint8_t>&);
     95SimpleColor makeSimpleColor(const SRGBA<float>&);
    9896
    9997SimpleColor premultiplyFlooring(SimpleColor);
     
    121119}
    122120
     121constexpr SimpleColor makeSimpleColor(const SRGBA<uint8_t>& sRGBA)
     122{
     123    auto [r, g, b, a] = sRGBA;
     124    return { r, g, b, a };
     125}
     126
    123127inline SimpleColor makeSimpleColor(const SRGBA<float>& sRGBA)
    124128{
    125129    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 {
    131130    return { convertToComponentByte(r), convertToComponentByte(g), convertToComponentByte(b), convertToComponentByte(a) };
    132131}
  • trunk/Source/WebCore/platform/graphics/avfoundation/InbandTextTrackPrivateAVF.cpp

    r262128 r263688  
    8181    }
    8282
    83     return makeSimpleColorFromFloats(componentArray[1], componentArray[2], componentArray[3], componentArray[0]);
     83    return makeSimpleColor(SRGBA { componentArray[1], componentArray[2], componentArray[3], componentArray[0] });
    8484}
    8585
  • trunk/Source/WebCore/platform/graphics/cairo/GradientCairo.cpp

    r263000 r263688  
    145145    float a = a1 + (a2 - a1) * 0.5f;
    146146
    147     return Gradient::ColorStop(offset, makeSimpleColorFromFloats(r, g, b, a));
     147    return Gradient::ColorStop(offset, makeSimpleColor(SRGBA { r, g, b, a }));
    148148}
    149149
  • trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp

    r262790 r263688  
    7979    }
    8080
    81     return makeSimpleColorFromFloats(r, g, b, a);
     81    return makeSimpleColor(SRGBA { r, g, b, a });
    8282}
    8383
  • trunk/Source/WebCore/platform/graphics/mac/ColorMac.mm

    r262790 r263688  
    9898    END_BLOCK_OBJC_EXCEPTIONS;
    9999
    100     return makeSimpleColorFromFloats(redComponent, greenComponent, blueComponent, alpha);
     100    return makeSimpleColor(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) });
    101101}
    102102
  • trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.cpp

    r262128 r263688  
    133133COMPtr<ID2D1SolidColorBrush> PlatformContextDirect2D::brushWithColor(const D2D1_COLOR_F& color)
    134134{
    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 });
    136136
    137137    if (!colorKey) {
  • trunk/Source/WebCore/platform/ios/ColorIOS.mm

    r262733 r263688  
    4848    [color getRed:&redComponent green:&greenComponent blue:&blueComponent alpha:&alpha];
    4949
    50     return makeSimpleColorFromFloats(redComponent, greenComponent, blueComponent, alpha);
     50    return makeSimpleColor(SRGBA { static_cast<float>(redComponent), static_cast<float>(greenComponent), static_cast<float>(blueComponent), static_cast<float>(alpha) });
    5151}
    5252
  • trunk/Source/WebCore/platform/ios/LegacyTileCache.mm

    r262377 r263688  
    463463{
    464464    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);
    468467}
    469468
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r263578 r263688  
    22192219
    22202220#ifdef REVEAL_TRANSPARENCY_LAYERS
    2221         context.setFillColor(makeSimpleColorFromFloats(0.0f, 0.0f, 0.5f, 0.2f));
     2221        context.setFillColor(makeSimpleColor(0, 0, 128, 51));
    22222222        context.fillRect(pixelSnappedClipRect);
    22232223#endif
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r263293 r263688  
    381381    if (checked || indeterminate) {
    382382        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));
    384384
    385385        auto clip = addRoundedBorderClip(box, paintInfo.context(), rect);
     
    417417
    418418        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));
    420420
    421421        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));
    423423    } else {
    424424        auto clip = addRoundedBorderClip(box, paintInfo.context(), rect);
     
    478478    if (isChecked(box)) {
    479479        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));
    481481
    482482        auto clip = addRoundedBorderClip(box, paintInfo.context(), rect);
     
    491491        clip.inflateY(-clip.height() * InnerInverseRatio);
    492492       
    493         constexpr auto shadowColor = makeSimpleColor(0, 0, 0, 0.7f * 255);
     493        constexpr auto shadowColor = Color::black.colorWithAlpha(179);
    494494        paintInfo.context().drawRaisedEllipse(clip, Color::white, shadowColor);
    495495
     
    739739
    740740        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));
    742742            ellipse.move(size + padding, 0);
    743743        }
     
    758758        };
    759759
    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));
    763763        paintInfo.context().drawPath(Path::polygonPathFromPoints(shadow));
    764764
     
    18411841    // Use the GraphicsContext function, because it calculates the blur radius in context space,
    18421842    // rather than screen space.
    1843     auto shadowColor = makeSimpleColorFromFloats(0.f, 0.f, 0.f, 0.1f);
     1843    constexpr auto shadowColor = Color::black.colorWithAlpha(26);
    18441844    graphicsContext.setShadow(FloatSize { }, 16, shadowColor);
    18451845
  • trunk/Source/WebKit/ChangeLog

    r263670 r263688  
     12020-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
    1192020-06-29  Youenn Fablet  <youenn@apple.com>
    220
  • trunk/Source/WebKit/UIProcess/API/wpe/WebKitColor.cpp

    r263000 r263688  
    7676const WebCore::Color webkitColorToWebCoreColor(WebKitColor* color)
    7777{
    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) });
    8079}
    8180
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorClient.cpp

    r262377 r263688  
    178178    paintLayer->setPosition(rect.location());
    179179    paintLayer->setSize(rect.size());
    180     paintLayer->setBackgroundColor(makeSimpleColorFromFloats(1.0f, 0.0f, 0.0f, 0.2f));
     180    paintLayer->setBackgroundColor(makeSimpleColor(255, 0, 0, 51));
    181181
    182182    KeyframeValueList fadeKeyframes(AnimatedPropertyOpacity);
  • trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp

    r262377 r263688  
    510510    const int borderWidth = 1;
    511511
    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);
    514514
    515515    IntRect borderInflatedDirtyRect = dirtyRect;
Note: See TracChangeset for help on using the changeset viewer.