Bug 163423

Summary: CSS parsing should use Color not RGBA32
Product: WebKit Reporter: Dean Jackson <dino>
Component: New BugsAssignee: Dean Jackson <dino>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, ryanhaddad, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 163448    
Bug Blocks:    
Attachments:
Description Flags
Patch simon.fraser: review+

Description Dean Jackson 2016-10-13 17:30:18 PDT
CSS parsing should use Color not RGBA32
Comment 1 Radar WebKit Bug Importer 2016-10-13 17:30:59 PDT
<rdar://problem/28766903>
Comment 2 Dean Jackson 2016-10-13 17:41:46 PDT
Created attachment 291547 [details]
Patch
Comment 3 Simon Fraser (smfr) 2016-10-13 17:56:41 PDT
Comment on attachment 291547 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=291547&action=review

> Source/WebCore/html/canvas/CanvasStyle.cpp:-51
> -    if (equalLettersIgnoringASCIICase(colorString, "currentcolor"))
> -        return ParsedCurrentColor;

Does CSSParser::parseColor() do this part now?

> Source/WebCore/platform/graphics/Color.h:159
> +    explicit Color(WTF::HashTableDeletedValueType)
> +    {
> +        m_colorData.rgbaAndFlags = 0xfffffffffffffffd;
> +        ASSERT(!isExtended());
> +    }
> +
> +    bool isHashTableDeletedValue() const
> +    {
> +        return m_colorData.rgbaAndFlags == 0xfffffffffffffffd;
> +    }
> +
> +    explicit Color(WTF::HashTableEmptyValueType)
> +    {
> +        m_colorData.rgbaAndFlags = 0xffffffffffffffb;
> +        ASSERT(!isExtended());
> +    }

Can you use your bit enums to mask off bits, rather than hardcoding them here?
Comment 4 Dean Jackson 2016-10-13 18:03:23 PDT
Comment on attachment 291547 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=291547&action=review

>> Source/WebCore/html/canvas/CanvasStyle.cpp:-51
>> -        return ParsedCurrentColor;
> 
> Does CSSParser::parseColor() do this part now?

It's down in parseColorOrCurrentColor now.

>> Source/WebCore/platform/graphics/Color.h:159
>> +    }
> 
> Can you use your bit enums to mask off bits, rather than hardcoding them here?

I could, but I'd still need to do some explicit bit-fudging. These are colors that can never really exist. Supposedly valid RGBA32s, so they don't get deleted as ExtendedColor, but with junk in the spare space.
Comment 5 Dean Jackson 2016-10-13 18:13:34 PDT
Committed r207317: <http://trac.webkit.org/changeset/207317>
Comment 7 WebKit Commit Bot 2016-10-14 09:18:18 PDT
Re-opened since this is blocked by bug 163448
Comment 8 Dean Jackson 2016-10-14 16:41:39 PDT
Committed r207361: <http://trac.webkit.org/changeset/207361>
Comment 9 Darin Adler 2016-10-16 10:31:54 PDT
Comment on attachment 291547 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=291547&action=review

> Source/WebCore/html/canvas/CanvasGradient.cpp:60
> +    Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);

Should we use nullptr instead of 0 for canvas?

> Source/WebCore/platform/graphics/Color.h:146
> +        m_colorData.rgbaAndFlags = 0xfffffffffffffffd;

I normally use uppercase hex; not sure if it’s a WebKit coding style agree-to thing, but it’s seen just below in createUnchecked.

I suggest a private named constant rather than repeating this three times. Eliminates the possibility that one of the three has a different number of "f" letters.

>>> Source/WebCore/platform/graphics/Color.h:159
>>> +    }
>> 
>> Can you use your bit enums to mask off bits, rather than hardcoding them here?
> 
> I could, but I'd still need to do some explicit bit-fudging. These are colors that can never really exist. Supposedly valid RGBA32s, so they don't get deleted as ExtendedColor, but with junk in the spare space.

Could use some static_assert to document some of these properties of the magic value.

> Source/WebCore/platform/graphics/Color.h:204
> +    uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }

I would have preferred that you expose a hash function here rather than exposing this so the hash function can use it.

The capitalization of Uint64 seems peculiar.

> Source/WebCore/platform/graphics/ColorHash.h:34
> +    static unsigned hash(const WebCore::Color& key) { return intHash(key.asUint64()); }

When we add support for ExtendedColor, this hash function will no longer be correct. Also seems to me that if we are using asUint64 for the hash, we should also be using it directly in the equal function.

> Source/WebCore/platform/graphics/ColorHash.h:40
> +    typedef ColorHash Hash;

In new code we should use "using" instead of typedef.

    using Hash = ColorHash;
Comment 10 Dean Jackson 2016-10-18 15:38:14 PDT
Comment on attachment 291547 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=291547&action=review

>> Source/WebCore/html/canvas/CanvasGradient.cpp:60
>> +    Color color = parseColorOrCurrentColor(colorString, 0 /*canvas*/);
> 
> Should we use nullptr instead of 0 for canvas?

Done

>> Source/WebCore/platform/graphics/Color.h:146
>> +        m_colorData.rgbaAndFlags = 0xfffffffffffffffd;
> 
> I normally use uppercase hex; not sure if it’s a WebKit coding style agree-to thing, but it’s seen just below in createUnchecked.
> 
> I suggest a private named constant rather than repeating this three times. Eliminates the possibility that one of the three has a different number of "f" letters.

Fixed!

>>>> Source/WebCore/platform/graphics/Color.h:159
>>>> +    }
>>> 
>>> Can you use your bit enums to mask off bits, rather than hardcoding them here?
>> 
>> I could, but I'd still need to do some explicit bit-fudging. These are colors that can never really exist. Supposedly valid RGBA32s, so they don't get deleted as ExtendedColor, but with junk in the spare space.
> 
> Could use some static_assert to document some of these properties of the magic value.

Added some static_asserts. Disappointed I didn't think of this originally.

>> Source/WebCore/platform/graphics/Color.h:204
>> +    uint64_t asUint64() const { return m_colorData.rgbaAndFlags; }
> 
> I would have preferred that you expose a hash function here rather than exposing this so the hash function can use it.
> 
> The capitalization of Uint64 seems peculiar.

Done. Removed the incorrectly capitalized Uint64() and added the unsigned hash() const.

>> Source/WebCore/platform/graphics/ColorHash.h:34
>> +    static unsigned hash(const WebCore::Color& key) { return intHash(key.asUint64()); }
> 
> When we add support for ExtendedColor, this hash function will no longer be correct. Also seems to me that if we are using asUint64 for the hash, we should also be using it directly in the equal function.

Yep. I made a note of this in Color.h. (Same applies to operator==)

>> Source/WebCore/platform/graphics/ColorHash.h:40
>> +    typedef ColorHash Hash;
> 
> In new code we should use "using" instead of typedef.
> 
>     using Hash = ColorHash;

Fixed.