Changeset 207487 in webkit


Ignore:
Timestamp:
Oct 18, 2016 1:55:49 PM (7 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>

Follow-up review comments from Darin Adler.

  • html/canvas/CanvasGradient.cpp:

(WebCore::CanvasGradient::addColorStop): Use nullptr.

  • platform/graphics/Color.cpp:

(WebCore::Color::Color): Explicitly zero before assigning the pointer.

  • platform/graphics/Color.h: Add some comments about the failings of operator== and hash.

(WebCore::Color::Color): Add some static_asserts to the constructors. Move the empty and deleted values
to static constants.
(WebCore::Color::isHashTableDeletedValue):
(WebCore::Color::hash): Replacement for asUint64, which was only being used for a hash.
(WebCore::Color::asUint64): Deleted.

  • platform/graphics/ColorHash.h: Use new hash functions. Use "using" instead of typedef.

(WTF::ColorHash::hash):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207486 r207487  
     12016-10-18  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        Follow-up review comments from Darin Adler.
     8
     9        * html/canvas/CanvasGradient.cpp:
     10        (WebCore::CanvasGradient::addColorStop): Use nullptr.
     11        * platform/graphics/Color.cpp:
     12        (WebCore::Color::Color): Explicitly zero before assigning the pointer.
     13        * platform/graphics/Color.h: Add some comments about the failings of operator== and hash.
     14        (WebCore::Color::Color): Add some static_asserts to the constructors. Move the empty and deleted values
     15        to static constants.
     16        (WebCore::Color::isHashTableDeletedValue):
     17        (WebCore::Color::hash): Replacement for asUint64, which was only being used for a hash.
     18        (WebCore::Color::asUint64): Deleted.
     19        * platform/graphics/ColorHash.h: Use new hash functions. Use "using" instead of typedef.
     20        (WTF::ColorHash::hash):
     21
    1222016-10-18  Ryosuke Niwa  <rniwa@webkit.org>
    223
  • trunk/Source/WebCore/html/canvas/CanvasGradient.cpp

    r207361 r207487  
    5858    }
    5959
    60     Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);
     60    Color color = parseColorOrCurrentColor(colorString, nullptr /*canvas*/);
    6161    if (!color.isValid()) {
    6262#if ENABLE(DASHBOARD_SUPPORT)
  • trunk/Source/WebCore/platform/graphics/Color.cpp

    r207442 r207487  
    290290Color::Color(float r, float g, float b, float a, ColorSpace colorSpace)
    291291{
     292    // Zero the union, just in case a 32-bit system only assigns the
     293    // top 32 bits when copying the extendedColor pointer below.
     294    m_colorData.rgbaAndFlags = 0;
    292295    auto extendedColorRef = ExtendedColor::create(r, g, b, a, colorSpace);
    293296    m_colorData.extendedColor = &extendedColorRef.leakRef();
  • trunk/Source/WebCore/platform/graphics/Color.h

    r207442 r207487  
    3333#include <unicode/uchar.h>
    3434#include <wtf/Forward.h>
     35#include <wtf/HashFunctions.h>
    3536#include <wtf/Optional.h>
    3637#include <wtf/text/LChar.h>
     
    144145    explicit Color(WTF::HashTableDeletedValueType)
    145146    {
    146         m_colorData.rgbaAndFlags = 0xfffffffffffffffd;
     147        static_assert(deletedHashValue & invalidRGBAColor, "Color's deleted hash value must not look like an ExtendedColor");
     148        static_assert(!(deletedHashValue & validRGBAColorBit), "Color's deleted hash value must not look like a valid RGBA32 Color");
     149        static_assert(deletedHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an RGBA32 Color wouldn't have");
     150        m_colorData.rgbaAndFlags = deletedHashValue;
    147151        ASSERT(!isExtended());
    148152    }
     
    150154    bool isHashTableDeletedValue() const
    151155    {
    152         return m_colorData.rgbaAndFlags == 0xfffffffffffffffd;
     156        return m_colorData.rgbaAndFlags == deletedHashValue;
    153157    }
    154158
    155159    explicit Color(WTF::HashTableEmptyValueType)
    156160    {
    157         m_colorData.rgbaAndFlags = 0xffffffffffffffb;
     161        static_assert(emptyHashValue & invalidRGBAColor, "Color's empty hash value must not look like an ExtendedColor");
     162        static_assert(emptyHashValue & (1 << 4), "Color's deleted hash value must have some bits set that an RGBA32 Color wouldn't have");
     163        m_colorData.rgbaAndFlags = emptyHashValue;
    158164        ASSERT(!isExtended());
    159165    }
     
    201207   
    202208    RGBA32 rgb() const { ASSERT(!isExtended()); return static_cast<RGBA32>(m_colorData.rgbaAndFlags >> 32); }
    203     uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }
     209
     210    // FIXME: Like operator==, this will give different values for ExtendedColors that
     211    // should be identical, since the respective pointer will be different.
     212    unsigned hash() const { return WTF::intHash(m_colorData.rgbaAndFlags); }
    204213
    205214    WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const;
     
    275284    static const uint64_t validRGBAColor = 0x3;
    276285
     286    static const uint64_t deletedHashValue = 0xFFFFFFFFFFFFFFFD;
     287    static const uint64_t emptyHashValue = 0xFFFFFFFFFFFFFFFB;
     288
    277289    WEBCORE_EXPORT void tagAsValid();
    278290
     
    283295};
    284296
     297// FIXME: These do not work for ExtendedColor because
     298// they become just pointer comparison.
    285299bool operator==(const Color&, const Color&);
    286300bool operator!=(const Color&, const Color&);
  • trunk/Source/WebCore/platform/graphics/ColorHash.h

    r207361 r207487  
    3232
    3333struct ColorHash {
    34     static unsigned hash(const WebCore::Color& key) { return intHash(key.asUint64()); }
     34    static unsigned hash(const WebCore::Color& key) { return key.hash(); }
    3535    static bool equal(const WebCore::Color& a, const WebCore::Color& b) { return a == b; }
    3636    static const bool safeToCompareToEmptyOrDeleted = true;
     
    3838
    3939template<> struct DefaultHash<WebCore::Color> {
    40     typedef ColorHash Hash;
     40    using Hash = ColorHash;
    4141};
    4242
Note: See TracChangeset for help on using the changeset viewer.