Changeset 207487 in webkit
- Timestamp:
- Oct 18, 2016 1:55:49 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207486 r207487 1 2016-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 1 22 2016-10-18 Ryosuke Niwa <rniwa@webkit.org> 2 23 -
trunk/Source/WebCore/html/canvas/CanvasGradient.cpp
r207361 r207487 58 58 } 59 59 60 Color color = parseColorOrCurrentColor(colorString, 0/*canvas*/);60 Color color = parseColorOrCurrentColor(colorString, nullptr /*canvas*/); 61 61 if (!color.isValid()) { 62 62 #if ENABLE(DASHBOARD_SUPPORT) -
trunk/Source/WebCore/platform/graphics/Color.cpp
r207442 r207487 290 290 Color::Color(float r, float g, float b, float a, ColorSpace colorSpace) 291 291 { 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; 292 295 auto extendedColorRef = ExtendedColor::create(r, g, b, a, colorSpace); 293 296 m_colorData.extendedColor = &extendedColorRef.leakRef(); -
trunk/Source/WebCore/platform/graphics/Color.h
r207442 r207487 33 33 #include <unicode/uchar.h> 34 34 #include <wtf/Forward.h> 35 #include <wtf/HashFunctions.h> 35 36 #include <wtf/Optional.h> 36 37 #include <wtf/text/LChar.h> … … 144 145 explicit Color(WTF::HashTableDeletedValueType) 145 146 { 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; 147 151 ASSERT(!isExtended()); 148 152 } … … 150 154 bool isHashTableDeletedValue() const 151 155 { 152 return m_colorData.rgbaAndFlags == 0xfffffffffffffffd;156 return m_colorData.rgbaAndFlags == deletedHashValue; 153 157 } 154 158 155 159 explicit Color(WTF::HashTableEmptyValueType) 156 160 { 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; 158 164 ASSERT(!isExtended()); 159 165 } … … 201 207 202 208 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); } 204 213 205 214 WEBCORE_EXPORT void getRGBA(float& r, float& g, float& b, float& a) const; … … 275 284 static const uint64_t validRGBAColor = 0x3; 276 285 286 static const uint64_t deletedHashValue = 0xFFFFFFFFFFFFFFFD; 287 static const uint64_t emptyHashValue = 0xFFFFFFFFFFFFFFFB; 288 277 289 WEBCORE_EXPORT void tagAsValid(); 278 290 … … 283 295 }; 284 296 297 // FIXME: These do not work for ExtendedColor because 298 // they become just pointer comparison. 285 299 bool operator==(const Color&, const Color&); 286 300 bool operator!=(const Color&, const Color&); -
trunk/Source/WebCore/platform/graphics/ColorHash.h
r207361 r207487 32 32 33 33 struct ColorHash { 34 static unsigned hash(const WebCore::Color& key) { return intHash(key.asUint64()); }34 static unsigned hash(const WebCore::Color& key) { return key.hash(); } 35 35 static bool equal(const WebCore::Color& a, const WebCore::Color& b) { return a == b; } 36 36 static const bool safeToCompareToEmptyOrDeleted = true; … … 38 38 39 39 template<> struct DefaultHash<WebCore::Color> { 40 typedef ColorHashHash;40 using Hash = ColorHash; 41 41 }; 42 42
Note: See TracChangeset
for help on using the changeset viewer.