Changeset 207265 in webkit


Ignore:
Timestamp:
Oct 12, 2016 6:14:15 PM (8 years ago)
Author:
dino@apple.com
Message:

Add preliminary support for extended colors to WebCore::Color
https://bugs.webkit.org/show_bug.cgi?id=162878
<rdar://problem/28596413>

Reviewed by Darin Adler.

Source/WebCore:

Add an ExtendedColor class that will hold the data necessary
for wider-than-sRGB (and more precise) colors. In order to
avoid increasing the size of Color, implement a tagged
pointer that is either referencing an ExtendedColor, or
is a 64-bit number with the top 32-bits being the RGBA, and
the bottom 2 bits indicating an invalid RGBA or a valid RGBA,
plus the tag.

Add copy constructors and operator= so that the new Color objects
are correctly copied.

There isn't yet a way to create an ExtendedColor. That's coming
in a followup patch (and will require changes to the CSS parser).

Covered by existing tests, and new API tests in Color.

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj: Add new files.
  • platform/graphics/Color.cpp: Update everything to use m_rgbaAndFlags

instead of m_color + m_valid.
(WebCore::Color::Color):
(WebCore::Color::~Color):
(WebCore::Color::operator=):
(WebCore::Color::nameForRenderTreeAsText):
(WebCore::Color::setNamedColor):
(WebCore::Color::light):
(WebCore::Color::dark):
(WebCore::Color::setValid):
(WebCore::Color::setExtended):
(WebCore::Color::isExtended):
(WebCore::Color::asExtended):

  • platform/graphics/Color.h: Implement the tagged union.

(WebCore::Color::Color):
(WebCore::Color::isValid):
(WebCore::Color::red):
(WebCore::Color::green):
(WebCore::Color::blue):
(WebCore::Color::alpha):
(WebCore::Color::rgb):
(WebCore::Color::setRGB):
(WebCore::operator==):

  • platform/graphics/ExtendedColor.cpp: New file. Holds floating point

red, green, blue and alpha, plus a color space.
(WebCore::ExtendedColor::create):
(WebCore::ExtendedColor::~ExtendedColor):
(WebCore::ExtendedColor::ref):
(WebCore::ExtendedColor::deref):

  • platform/graphics/ExtendedColor.h:

(WebCore::ExtendedColor::red):
(WebCore::ExtendedColor::green):
(WebCore::ExtendedColor::blue):
(WebCore::ExtendedColor::alpha):
(WebCore::ExtendedColor::colorSpace):
(WebCore::ExtendedColor::ExtendedColor):

  • platform/graphics/cg/ColorCG.cpp: Update the constructors for

the platform specific color classes.
(WebCore::Color::Color):

  • platform/graphics/gtk/ColorGtk.cpp:

(WebCore::Color::Color):

  • platform/graphics/win/ColorDirect2D.cpp:

(WebCore::Color::Color):

  • rendering/RenderEmbeddedObject.cpp: Use NeverDestroyed.

(WebCore::replacementTextRoundedRectPressedColor):
(WebCore::replacementTextRoundedRectColor):
(WebCore::replacementTextColor):
(WebCore::unavailablePluginBorderColor):

  • rendering/RenderFrameSet.cpp: Ditto.

(WebCore::borderStartEdgeColor):
(WebCore::borderEndEdgeColor):
(WebCore::borderFillColor):

  • rendering/RenderTableCell.cpp: This grows in size slightly

because it can no longer pack bits.

Tools:

A new API test for Colors.

  • TestWebKitAPI/Tests/WebCore/Color.cpp:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
16 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r207041 r207265  
    22042204    platform/graphics/CrossfadeGeneratedImage.cpp
    22052205    platform/graphics/DisplayRefreshMonitorClient.cpp
     2206    platform/graphics/ExtendedColor.cpp
    22062207    platform/graphics/FloatPoint.cpp
    22072208    platform/graphics/FloatPoint3D.cpp
  • trunk/Source/WebCore/ChangeLog

    r207245 r207265  
     12016-10-11  Dean Jackson  <dino@apple.com>
     2
     3        Add preliminary support for extended colors to WebCore::Color
     4        https://bugs.webkit.org/show_bug.cgi?id=162878
     5        <rdar://problem/28596413>
     6
     7        Reviewed by Darin Adler.
     8
     9        Add an ExtendedColor class that will hold the data necessary
     10        for wider-than-sRGB (and more precise) colors. In order to
     11        avoid increasing the size of Color, implement a tagged
     12        pointer that is either referencing an ExtendedColor, or
     13        is a 64-bit number with the top 32-bits being the RGBA, and
     14        the bottom 2 bits indicating an invalid RGBA or a valid RGBA,
     15        plus the tag.
     16
     17        Add copy constructors and operator= so that the new Color objects
     18        are correctly copied.
     19
     20        There isn't yet a way to create an ExtendedColor. That's coming
     21        in a followup patch (and will require changes to the CSS parser).
     22
     23        Covered by existing tests, and new API tests in Color.
     24
     25        * CMakeLists.txt:
     26        * WebCore.xcodeproj/project.pbxproj: Add new files.
     27
     28        * platform/graphics/Color.cpp: Update everything to use m_rgbaAndFlags
     29        instead of m_color + m_valid.
     30        (WebCore::Color::Color):
     31        (WebCore::Color::~Color):
     32        (WebCore::Color::operator=):
     33        (WebCore::Color::nameForRenderTreeAsText):
     34        (WebCore::Color::setNamedColor):
     35        (WebCore::Color::light):
     36        (WebCore::Color::dark):
     37        (WebCore::Color::setValid):
     38        (WebCore::Color::setExtended):
     39        (WebCore::Color::isExtended):
     40        (WebCore::Color::asExtended):
     41        * platform/graphics/Color.h: Implement the tagged union.
     42        (WebCore::Color::Color):
     43        (WebCore::Color::isValid):
     44        (WebCore::Color::red):
     45        (WebCore::Color::green):
     46        (WebCore::Color::blue):
     47        (WebCore::Color::alpha):
     48        (WebCore::Color::rgb):
     49        (WebCore::Color::setRGB):
     50        (WebCore::operator==):
     51
     52        * platform/graphics/ExtendedColor.cpp: New file. Holds floating point
     53        red, green, blue and alpha, plus a color space.
     54        (WebCore::ExtendedColor::create):
     55        (WebCore::ExtendedColor::~ExtendedColor):
     56        (WebCore::ExtendedColor::ref):
     57        (WebCore::ExtendedColor::deref):
     58        * platform/graphics/ExtendedColor.h:
     59        (WebCore::ExtendedColor::red):
     60        (WebCore::ExtendedColor::green):
     61        (WebCore::ExtendedColor::blue):
     62        (WebCore::ExtendedColor::alpha):
     63        (WebCore::ExtendedColor::colorSpace):
     64        (WebCore::ExtendedColor::ExtendedColor):
     65
     66        * platform/graphics/cg/ColorCG.cpp: Update the constructors for
     67        the platform specific color classes.
     68        (WebCore::Color::Color):
     69        * platform/graphics/gtk/ColorGtk.cpp:
     70        (WebCore::Color::Color):
     71        * platform/graphics/win/ColorDirect2D.cpp:
     72        (WebCore::Color::Color):
     73
     74        * rendering/RenderEmbeddedObject.cpp: Use NeverDestroyed.
     75        (WebCore::replacementTextRoundedRectPressedColor):
     76        (WebCore::replacementTextRoundedRectColor):
     77        (WebCore::replacementTextColor):
     78        (WebCore::unavailablePluginBorderColor):
     79
     80        * rendering/RenderFrameSet.cpp: Ditto.
     81        (WebCore::borderStartEdgeColor):
     82        (WebCore::borderEndEdgeColor):
     83        (WebCore::borderFillColor):
     84
     85        * rendering/RenderTableCell.cpp: This grows in size slightly
     86        because it can no longer pack bits.
     87
    1882016-10-12  Antoine Quint  <graouts@apple.com>
    289
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r207239 r207265  
    13821382                31D591B316697A6C00E6BF02 /* PlugInClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 31D591B116697A6C00E6BF02 /* PlugInClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13831383                31DCD29D1AB4FBDE0072E817 /* AnimationTrigger.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DCD29C1AB4FBDE0072E817 /* AnimationTrigger.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1384                31DCDF431DA1C45400EA5B93 /* ExtendedColor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */; };
     1385                31DCDF441DA1C45400EA5B93 /* ExtendedColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */; settings = {ATTRIBUTES = (Private, ); }; };
    13841386                31DEA4551B39F4D900F77178 /* WebSystemBackdropLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 31DEA4531B39F4D900F77178 /* WebSystemBackdropLayer.mm */; };
    13851387                31DEA4561B39F4D900F77178 /* WebSystemBackdropLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 31DEA4541B39F4D900F77178 /* WebSystemBackdropLayer.h */; };
     
    83508352                31D591B116697A6C00E6BF02 /* PlugInClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlugInClient.h; sourceTree = "<group>"; };
    83518353                31DCD29C1AB4FBDE0072E817 /* AnimationTrigger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AnimationTrigger.h; sourceTree = "<group>"; };
     8354                31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ExtendedColor.cpp; sourceTree = "<group>"; };
     8355                31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ExtendedColor.h; sourceTree = "<group>"; };
    83528356                31DEA4531B39F4D900F77178 /* WebSystemBackdropLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebSystemBackdropLayer.mm; sourceTree = "<group>"; };
    83538357                31DEA4541B39F4D900F77178 /* WebSystemBackdropLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSystemBackdropLayer.h; sourceTree = "<group>"; };
     
    2073420738                                B27535380B053814002CE64F /* Color.cpp */,
    2073520739                                B27535390B053814002CE64F /* Color.h */,
     20740                                31DCDF411DA1C45400EA5B93 /* ExtendedColor.cpp */,
     20741                                31DCDF421DA1C45400EA5B93 /* ExtendedColor.h */,
    2073620742                                9382DF5710A8D5C900925652 /* ColorSpace.h */,
    2073720743                                2D2FC0541460CD6F00263633 /* CrossfadeGeneratedImage.cpp */,
     
    2492924935                                510192D218B6B9AB007FC7A1 /* ImageControlsRootElementMac.h in Headers */,
    2493024936                                A779791A0D6B9D0C003851B9 /* ImageData.h in Headers */,
     24937                                31DCDF441DA1C45400EA5B93 /* ExtendedColor.h in Headers */,
    2493124938                                555B87ED1CAAF0AB00349425 /* ImageDecoderCG.h in Headers */,
    2493224939                                97205AB61239291000B17380 /* ImageDocument.h in Headers */,
     
    3037730384                                B2227AF20D00BF220071B782 /* SVGViewSpec.cpp in Sources */,
    3037830385                                8485228A1190173C006EDC7F /* SVGVKernElement.cpp in Sources */,
     30386                                31DCDF431DA1C45400EA5B93 /* ExtendedColor.cpp in Sources */,
    3037930387                                B2227AF50D00BF220071B782 /* SVGZoomAndPan.cpp in Sources */,
    3038030388                                B2E4EC970D00C22B00432643 /* SVGZoomEvent.cpp in Sources */,
  • trunk/Source/WebCore/platform/graphics/Color.cpp

    r206043 r207265  
    226226{
    227227    if (name[0] == '#') {
     228        RGBA32 color;
     229        bool valid;
     230
    228231        if (name.is8Bit())
    229             m_valid = parseHexColor(name.characters8() + 1, name.length() - 1, m_color);
     232            valid = parseHexColor(name.characters8() + 1, name.length() - 1, color);
    230233        else
    231             m_valid = parseHexColor(name.characters16() + 1, name.length() - 1, m_color);
     234            valid = parseHexColor(name.characters16() + 1, name.length() - 1, color);
     235
     236        if (valid)
     237            setRGB(color);
    232238    } else
    233239        setNamedColor(name);
     
    236242Color::Color(const char* name)
    237243{
     244    RGBA32 color;
     245    bool valid;
    238246    if (name[0] == '#')
    239         m_valid = parseHexColor((String)&name[1], m_color);
     247        valid = parseHexColor((String)&name[1], color);
    240248    else {
    241249        const NamedColor* foundColor = findColor(name, strlen(name));
    242         m_color = foundColor ? foundColor->ARGBValue : 0;
    243         m_valid = foundColor;
    244     }
     250        color = foundColor ? foundColor->ARGBValue : 0;
     251        valid = foundColor;
     252    }
     253
     254    if (valid)
     255        setRGB(color);
     256}
     257
     258Color::Color(const Color& other)
     259    : m_colorData(other.m_colorData)
     260{
     261    if (isExtended())
     262        m_colorData.extendedColor->ref();
     263}
     264
     265Color::Color(Color&& other)
     266{
     267    *this = WTFMove(other);
     268}
     269
     270Color::~Color()
     271{
     272    if (isExtended())
     273        m_colorData.extendedColor->deref();
     274}
     275
     276Color& Color::operator=(const Color& other)
     277{
     278    if (*this == other)
     279        return *this;
     280
     281    if (isExtended())
     282        m_colorData.extendedColor->deref();
     283
     284    m_colorData = other.m_colorData;
     285
     286    if (isExtended())
     287        m_colorData.extendedColor->ref();
     288    return *this;
     289}
     290
     291Color& Color::operator=(Color&& other)
     292{
     293    if (*this == other)
     294        return *this;
     295
     296    m_colorData = other.m_colorData;
     297    other.m_colorData.rgbaAndFlags = invalidRGBAColor;
     298
     299    return *this;
    245300}
    246301
     
    292347String Color::nameForRenderTreeAsText() const
    293348{
     349    // FIXME: Handle ExtendedColors.
    294350    if (alpha() < 0xFF)
    295351        return String::format("#%02X%02X%02X%02X", red(), green(), blue(), alpha());
     
    316372{
    317373    const NamedColor* foundColor = findNamedColor(name);
    318     m_color = foundColor ? foundColor->ARGBValue : 0;
    319     m_valid = foundColor;
     374    if (foundColor)
     375        setRGB(foundColor->ARGBValue);
     376    else
     377        m_colorData.rgbaAndFlags = invalidRGBAColor;
    320378}
    321379
     
    323381{
    324382    // Hardcode this common case for speed.
    325     if (m_color == black)
     383    if (rgb() == black)
    326384        return lightenedBlack;
    327385   
     
    348406{
    349407    // Hardcode this common case for speed.
    350     if (m_color == white)
     408    if (rgb() == white)
    351409        return darkenedWhite;
    352410   
     
    562620}
    563621
     622void Color::tagAsValid()
     623{
     624    m_colorData.rgbaAndFlags |= validRGBAColor;
     625}
     626
     627void Color::tagAsExtended()
     628{
     629    // FIXME: Is this method necessary? Will colors ever change from RGBA32 to Extended?
     630    // Valid colors should not change type.
     631    ASSERT(!isValid());
     632    m_colorData.rgbaAndFlags &= ~(invalidRGBAColor);
     633}
     634
     635bool Color::isExtended() const
     636{
     637    return !(m_colorData.rgbaAndFlags & invalidRGBAColor);
     638}
     639
     640ExtendedColor* Color::asExtended() const
     641{
     642    ASSERT(isExtended());
     643    if (!isExtended())
     644        return nullptr;
     645    return m_colorData.extendedColor;
     646}
     647
    564648} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/Color.h

    r206773 r207265  
    2424 */
    2525
    26 #ifndef Color_h
    27 #define Color_h
     26#pragma once
    2827
    2928#include "ColorSpace.h"
     29#include "ExtendedColor.h"
    3030#include "PlatformExportMacros.h"
    3131#include <algorithm>
     
    108108    WTF_MAKE_FAST_ALLOCATED;
    109109public:
    110     Color() : m_color(0), m_valid(false) { }
    111     Color(RGBA, ColorSpace);
     110    Color() { }
    112111
    113112    // FIXME: Remove all these constructors and creation functions and replace the ones that are still needed with free functions.
    114     Color(RGBA32 color, bool valid = true) : m_color(color), m_valid(valid) { ASSERT(!m_color || m_valid); }
    115     Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
    116     Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
    117     // Color is currently limited to 32bit RGBA, perhaps some day we'll support better colors
    118     Color(float r, float g, float b, float a) : m_color(makeRGBA32FromFloats(r, g, b, a)), m_valid(true) { }
     113
     114    Color(RGBA32 color, bool valid = true)
     115    {
     116        if (valid)
     117            setRGB(color);
     118    }
     119
     120    Color(int r, int g, int b)
     121    {
     122        setRGB(r, g, b);
     123    }
     124
     125    Color(int r, int g, int b, int a)
     126    {
     127        setRGB(makeRGBA(r, g, b, a));
     128    }
     129
     130    Color(float r, float g, float b, float a)
     131    {
     132        setRGB(makeRGBA32FromFloats(r, g, b, a));
     133    }
     134
    119135    // Creates a new color from the specific CMYK and alpha values.
    120     Color(float c, float m, float y, float k, float a) : m_color(makeRGBAFromCMYKA(c, m, y, k, a)), m_valid(true) { }
     136    Color(float c, float m, float y, float k, float a)
     137    {
     138        setRGB(makeRGBAFromCMYKA(c, m, y, k, a));
     139    }
     140
    121141    WEBCORE_EXPORT explicit Color(const String&);
    122142    explicit Color(const char*);
     143
     144    // FIXME: Add constructor for ExtendedColor type.
     145
     146    Color(RGBA, ColorSpace);
     147    WEBCORE_EXPORT Color(const Color&);
     148    WEBCORE_EXPORT Color(Color&&);
     149
     150    WEBCORE_EXPORT ~Color();
     151
    123152    static Color createUnchecked(int r, int g, int b)
    124153    {
     
    144173    void setNamedColor(const String&);
    145174
    146     // FIXME: Remove this after moving clients to all use OptionalColor instead.
    147     bool isValid() const { return m_valid; }
     175    bool isValid() const { return m_colorData.rgbaAndFlags & validRGBAColorBit; }
    148176
    149177    bool hasAlpha() const { return alpha() < 255; }
    150178
    151     int red() const { return redChannel(m_color); }
    152     int green() const { return greenChannel(m_color); }
    153     int blue() const { return blueChannel(m_color); }
    154     int alpha() const { return alphaChannel(m_color); }
     179    int red() const { return redChannel(rgb()); }
     180    int green() const { return greenChannel(rgb()); }
     181    int blue() const { return blueChannel(rgb()); }
     182    int alpha() const { return alphaChannel(rgb()); }
    155183   
    156     RGBA32 rgb() const { return m_color; } // Preserve the alpha.
    157     void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
    158     void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
     184    RGBA32 rgb() const { ASSERT(!isExtended()); return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32); }
     185    void setRGB(int r, int g, int b) { setRGB(makeRGB(r, g, b)); }
     186    void setRGB(RGBA32);
     187
    159188    WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
    160189    WEBCORE_EXPORT void getRGBA(double& r, double& g, double& b, double& a) const;
     
    209238#endif
    210239
     240    WEBCORE_EXPORT bool isExtended() const;
     241    WEBCORE_EXPORT ExtendedColor* asExtended() const;
     242
     243    WEBCORE_EXPORT Color& operator=(const Color&);
     244    WEBCORE_EXPORT Color& operator=(Color&&);
     245
     246    friend bool operator==(const Color& a, const Color& b);
     247
    211248private:
    212     RGBA32 m_color;
    213     bool m_valid;
     249
     250    // 0x_______00 is an ExtendedColor pointer.
     251    // 0x_______01 is an invalid RGBA32.
     252    // 0x_______11 is a valid RGBA32.
     253    static const uint64_t extendedColor = 0x0;
     254    static const uint64_t invalidRGBAColor = 0x1;
     255    static const uint64_t validRGBAColorBit = 0x2;
     256    static const uint64_t validRGBAColor = 0x3;
     257
     258    WEBCORE_EXPORT void tagAsValid();
     259    void tagAsExtended();
     260
     261    union {
     262        uint64_t rgbaAndFlags { invalidRGBAColor };
     263        ExtendedColor* extendedColor;
     264    } m_colorData;
    214265};
    215266
     
    271322
    272323inline Color::Color(RGBA color, ColorSpace space)
    273     : m_color(color.m_integer)
    274     , m_valid(true)
    275 {
     324{
     325    setRGB(color.m_integer);
    276326    ASSERT_UNUSED(space, space == ColorSpaceSRGB);
    277327}
     
    279329inline bool operator==(const Color& a, const Color& b)
    280330{
    281     return a.rgb() == b.rgb() && a.isValid() == b.isValid();
     331    return a.m_colorData.rgbaAndFlags == b.m_colorData.rgbaAndFlags;
    282332}
    283333
     
    316366}
    317367
     368inline void Color::setRGB(RGBA32 rgb)
     369{
     370    m_colorData.rgbaAndFlags = static_cast<uint64_t>(rgb) << 32;
     371    tagAsValid();
     372}
     373
    318374WEBCORE_EXPORT TextStream& operator<<(TextStream&, const Color&);
    319375
    320376} // namespace WebCore
    321 
    322 #endif // Color_h
  • trunk/Source/WebCore/platform/graphics/ExtendedColor.cpp

    r207263 r207265  
    11/*
    2  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    2626#include "config.h"
    27 #include "Color.h"
     27#include "ExtendedColor.h"
    2828
    29 #if PLATFORM(WIN)
    30 
    31 #include <d2d1.h>
    32 #include <d2d1_1helper.h>
     29#include "ColorSpace.h"
    3330
    3431namespace WebCore {
    3532
    36 Color::Color(D2D1_COLOR_F color)
     33Ref<ExtendedColor> ExtendedColor::create(float r, float g, float b, float a, ColorSpace colorSpace)
    3734{
    38     m_color = makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255);
    39     m_valid = true;
    40 }
    41 
    42 Color::operator D2D1_COLOR_F() const
    43 {
    44     float colorAlpha = alpha() / 255.0f;
    45 
    46     return D2D1::ColorF(rgb(), colorAlpha);
    47 }
    48 
    49 Color::operator D2D1_VECTOR_4F() const
    50 {
    51     float r, g, b, a;
    52     getRGBA(r, g, b, a);
    53     return D2D1::Vector4F(r, g, b, a);
     35    return adoptRef(*new ExtendedColor(r, g, b, a, colorSpace));
    5436}
    5537
    5638}
    57 
    58 #endif // PLATFORM(WIN)
  • trunk/Source/WebCore/platform/graphics/ExtendedColor.h

    r207263 r207265  
    11/*
    2  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #include "config.h"
    27 #include "Color.h"
     26#pragma once
    2827
    29 #if PLATFORM(WIN)
     28#include "ColorSpace.h"
    3029
    31 #include <d2d1.h>
    32 #include <d2d1_1helper.h>
     30#include <wtf/Ref.h>
     31#include <wtf/RefCounted.h>
    3332
    3433namespace WebCore {
    3534
    36 Color::Color(D2D1_COLOR_F color)
    37 {
    38     m_color = makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255);
    39     m_valid = true;
    40 }
     35class ExtendedColor : public RefCounted<ExtendedColor> {
     36public:
     37    static Ref<ExtendedColor> create(float r, float g, float b, float a, ColorSpace = ColorSpace::ColorSpaceSRGB);
    4138
    42 Color::operator D2D1_COLOR_F() const
    43 {
    44     float colorAlpha = alpha() / 255.0f;
     39    float red() const { return m_red; }
     40    float green() const { return m_green; }
     41    float blue() const { return m_blue; }
     42    float alpha() const { return m_alpha; }
    4543
    46     return D2D1::ColorF(rgb(), colorAlpha);
    47 }
     44    ColorSpace colorSpace() const { return m_colorSpace; }
    4845
    49 Color::operator D2D1_VECTOR_4F() const
    50 {
    51     float r, g, b, a;
    52     getRGBA(r, g, b, a);
    53     return D2D1::Vector4F(r, g, b, a);
    54 }
     46private:
     47    ExtendedColor(float r, float g, float b, float a, ColorSpace colorSpace)
     48        : m_red(r)
     49        , m_green(g)
     50        , m_blue(b)
     51        , m_alpha(a)
     52        , m_colorSpace(colorSpace)
     53    { }
     54
     55    float m_red { 0 };
     56    float m_green { 0 };
     57    float m_blue { 0 };
     58    float m_alpha { 0 };
     59
     60    ColorSpace m_colorSpace { ColorSpace::ColorSpaceSRGB };
     61};
    5562
    5663}
    57 
    58 #endif // PLATFORM(WIN)
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

    r206830 r207265  
    13721372    // they start to obscure useful information.
    13731373    if ((!m_transform.isIdentity() || m_usingTiledBacking) && !m_visibleTileWashLayer) {
    1374         static Color washFillColor(255, 0, 0, 50);
    1375         static Color washBorderColor(255, 0, 0, 100);
     1374        static NeverDestroyed<Color> washFillColor(255, 0, 0, 50);
     1375        static NeverDestroyed<Color> washBorderColor(255, 0, 0, 100);
    13761376       
    13771377        m_visibleTileWashLayer = createPlatformCALayer(PlatformCALayer::LayerTypeLayer, this);
  • trunk/Source/WebCore/platform/graphics/cg/ColorCG.cpp

    r203038 r207265  
    7474{
    7575    if (!color) {
    76         m_color = 0;
    77         m_valid = false;
     76        m_colorData.rgbaAndFlags = invalidRGBAColor;
    7877        return;
    7978    }
     
    112111    }
    113112
    114     m_color = makeRGBA(r * 255, g * 255, b * 255, a * 255);
    115     m_valid = true;
     113    setRGB(makeRGBA(r * 255, g * 255, b * 255, a * 255));
    116114}
    117115
  • trunk/Source/WebCore/platform/graphics/gtk/ColorGtk.cpp

    r75056 r207265  
    2727
    2828Color::Color(const GdkColor& c)
    29     : m_color(makeRGB(c.red >> 8, c.green >> 8, c.blue >> 8))
    30     , m_valid(true)
    3129{
     30    setRGB(makeRGB(c.red >> 8, c.green >> 8, c.blue >> 8));
    3231}
    3332
    3433#ifndef GTK_API_VERSION_2
    3534Color::Color(const GdkRGBA& c)
    36     : m_color(makeRGBA(static_cast<int>(c.red * 255),
    37                        static_cast<int>(c.green * 255),
    38                        static_cast<int>(c.blue * 255),
    39                        static_cast<int>(c.alpha * 255)))
    40     , m_valid(true)
    4135{
     36    setRGB(makeRGBA(static_cast<int>(c.red * 255),
     37        static_cast<int>(c.green * 255),
     38        static_cast<int>(c.blue * 255),
     39        static_cast<int>(c.alpha * 255)));
    4240}
    4341
  • trunk/Source/WebCore/platform/graphics/win/ColorDirect2D.cpp

    r206773 r207265  
    3636Color::Color(D2D1_COLOR_F color)
    3737{
    38     m_color = makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255);
    39     m_valid = true;
     38    setRGB(makeRGBA(color.r * 255, color.g * 255, color.b * 255, color.a * 255));
    4039}
    4140
  • trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp

    r202105 r207265  
    7676static const Color& replacementTextRoundedRectPressedColor()
    7777{
    78     static const Color pressed(105, 105, 105, 242);
     78    static NeverDestroyed<Color> pressed(105, 105, 105, 242);
    7979    return pressed;
    8080}
     
    8282static const Color& replacementTextRoundedRectColor()
    8383{
    84     static const Color standard(125, 125, 125, 242);
     84    static NeverDestroyed<Color> standard(125, 125, 125, 242);
    8585    return standard;
    8686}
     
    8888static const Color& replacementTextColor()
    8989{
    90     static const Color standard(240, 240, 240, 255);
     90    static NeverDestroyed<Color> standard(240, 240, 240, 255);
    9191    return standard;
    9292}
     
    9494static const Color& unavailablePluginBorderColor()
    9595{
    96     static const Color standard(255, 255, 255, 216);
     96    static NeverDestroyed<Color> standard(255, 255, 255, 216);
    9797    return standard;
    9898}
  • trunk/Source/WebCore/rendering/RenderFrameSet.cpp

    r206538 r207265  
    7070static const Color& borderStartEdgeColor()
    7171{
    72     static const Color color(170, 170, 170);
     72    static NeverDestroyed<Color> color(170, 170, 170);
    7373    return color;
    7474}
     
    7676static const Color& borderEndEdgeColor()
    7777{
    78     static const Color color = Color::black;
     78    static NeverDestroyed<Color> color = Color::black;
    7979    return color;
    8080}
     
    8282static const Color& borderFillColor()
    8383{
    84     static const Color color(208, 208, 208);
     84    static NeverDestroyed<Color> color(208, 208, 208);
    8585    return color;
    8686}
  • trunk/Source/WebCore/rendering/RenderTableCell.cpp

    r205892 r207265  
    5353
    5454COMPILE_ASSERT(sizeof(RenderTableCell) == sizeof(SameSizeAsRenderTableCell), RenderTableCell_should_stay_small);
    55 COMPILE_ASSERT(sizeof(CollapsedBorderValue) == 16, CollapsedBorderValue_should_stay_small);
     55COMPILE_ASSERT(sizeof(CollapsedBorderValue) <= 24, CollapsedBorderValue_should_stay_small);
    5656
    5757RenderTableCell::RenderTableCell(Element& element, RenderStyle&& style)
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r206761 r207265  
    326326const Color& RenderThemeIOS::shadowColor() const
    327327{
    328     static Color color(0.0f, 0.0f, 0.0f, 0.7f);
     328    static NeverDestroyed<Color> color(0.0f, 0.0f, 0.0f, 0.7f);
    329329    return color;
    330330}
  • trunk/Source/WebKit/mac/WebView/WebIndicateLayer.mm

    r192140 r207265  
    3333#import <WebCore/QuartzCoreSPI.h>
    3434#import <WebCore/WAKWindow.h>
     35#import <wtf/NeverDestroyed.h>
    3536
    3637using namespace WebCore;
     
    5051
    5152    // Blue highlight color.
    52     static Color highlightColor(111.0f / 255.0f, 168.0f / 255.0f, 220.0f / 255.0f, 0.66f);
     53    static NeverDestroyed<Color> highlightColor(111.0f / 255.0f, 168.0f / 255.0f, 220.0f / 255.0f, 0.66f);
    5354    self.backgroundColor = cachedCGColor(highlightColor);
    5455
  • trunk/Tools/ChangeLog

    r207237 r207265  
     12016-10-11  Dean Jackson  <dino@apple.com>
     2
     3        Add preliminary support for extended colors to WebCore::Color
     4        https://bugs.webkit.org/show_bug.cgi?id=162878
     5        <rdar://problem/28596413>
     6
     7        Reviewed by Darin Adler.
     8
     9        A new API test for Colors.
     10
     11        * TestWebKitAPI/Tests/WebCore/Color.cpp:
     12        (TestWebKitAPI::TEST):
     13
    1142016-10-12  Ryan Haddad  <ryanhaddad@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/Color.cpp

    r200659 r207265  
    145145}
    146146
     147TEST(Color, Validity)
     148{
     149    Color invalidColor;
     150    EXPECT_FALSE(invalidColor.isValid());
     151    EXPECT_FALSE(invalidColor.isExtended());
     152
     153    Color otherInvalidColor = invalidColor;
     154    EXPECT_FALSE(otherInvalidColor.isValid());
     155    EXPECT_FALSE(otherInvalidColor.isExtended());
     156
     157    Color validColor(255, 0, 0);
     158    EXPECT_TRUE(validColor.isValid());
     159    EXPECT_FALSE(validColor.isExtended());
     160
     161    Color otherValidColor = validColor;
     162    EXPECT_TRUE(otherValidColor.isValid());
     163    EXPECT_FALSE(otherValidColor.isExtended());
     164
     165    validColor = Color(1, 2, 3, 4);
     166    EXPECT_TRUE(validColor.isValid());
     167    EXPECT_FALSE(validColor.isExtended());
     168    EXPECT_EQ(validColor.red(), 1);
     169    EXPECT_EQ(validColor.green(), 2);
     170    EXPECT_EQ(validColor.blue(), 3);
     171    EXPECT_EQ(validColor.alpha(), 4);
     172
     173    Color yetAnotherValidColor(WTFMove(validColor));
     174    EXPECT_TRUE(yetAnotherValidColor.isValid());
     175    EXPECT_FALSE(yetAnotherValidColor.isExtended());
     176    EXPECT_EQ(yetAnotherValidColor.red(), 1);
     177    EXPECT_EQ(yetAnotherValidColor.green(), 2);
     178    EXPECT_EQ(yetAnotherValidColor.blue(), 3);
     179    EXPECT_EQ(yetAnotherValidColor.alpha(), 4);
     180
     181    otherValidColor = WTFMove(yetAnotherValidColor);
     182    EXPECT_TRUE(otherValidColor.isValid());
     183    EXPECT_FALSE(otherValidColor.isExtended());
     184    EXPECT_EQ(otherValidColor.red(), 1);
     185    EXPECT_EQ(otherValidColor.green(), 2);
     186    EXPECT_EQ(otherValidColor.blue(), 3);
     187    EXPECT_EQ(otherValidColor.alpha(), 4);
     188}
     189
    147190} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.