| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef FontCacheKey_h | 31 #ifndef FontCacheKey_h |
| 32 #define FontCacheKey_h | 32 #define FontCacheKey_h |
| 33 | 33 |
| 34 #include "FontFaceCreationParams.h" |
| 34 #include "wtf/HashMap.h" | 35 #include "wtf/HashMap.h" |
| 35 #include "wtf/HashTableDeletedValueType.h" | 36 #include "wtf/HashTableDeletedValueType.h" |
| 36 #include "wtf/text/AtomicStringHash.h" | 37 #include "wtf/text/AtomicStringHash.h" |
| 37 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
| 38 | 39 |
| 39 namespace WebCore { | 40 namespace WebCore { |
| 40 | 41 |
| 41 // Multiplying the floating point size by 100 gives two decimal point | 42 // Multiplying the floating point size by 100 gives two decimal point |
| 42 // precision which should be sufficient. | 43 // precision which should be sufficient. |
| 43 static const unsigned s_fontSizePrecisionMultiplier = 100; | 44 static const unsigned s_fontSizePrecisionMultiplier = 100; |
| 44 | 45 |
| 45 struct FontCacheKey { | 46 struct FontCacheKey { |
| 46 WTF_MAKE_FAST_ALLOCATED; | 47 WTF_MAKE_FAST_ALLOCATED; |
| 47 public: | 48 public: |
| 48 FontCacheKey() | 49 FontCacheKey() |
| 49 : m_familyName() | 50 : m_creationParams() |
| 50 , m_fontSize(0) | 51 , m_fontSize(0) |
| 51 , m_options(0) { } | 52 , m_options(0) { } |
| 52 FontCacheKey(AtomicString familyName, float fontSize, unsigned options) | 53 FontCacheKey(FontFaceCreationParams creationParams, float fontSize, unsigned
options) |
| 53 : m_familyName(familyName) | 54 : m_creationParams(creationParams) |
| 54 , m_fontSize(fontSize * s_fontSizePrecisionMultiplier) | 55 , m_fontSize(fontSize * s_fontSizePrecisionMultiplier) |
| 55 , m_options(options) { } | 56 , m_options(options) { } |
| 56 FontCacheKey(WTF::HashTableDeletedValueType) | 57 FontCacheKey(WTF::HashTableDeletedValueType) |
| 57 : m_fontSize(hashTableDeletedSize()) { } | 58 : m_fontSize(hashTableDeletedSize()) { } |
| 58 | 59 |
| 59 unsigned hash() const | 60 unsigned hash() const |
| 60 { | 61 { |
| 61 unsigned hashCodes[3] = { | 62 unsigned hashCodes[3] = { |
| 62 CaseFoldingHash::hash(m_familyName), | 63 m_creationParams.hash(), |
| 63 m_fontSize, | 64 m_fontSize, |
| 64 m_options | 65 m_options |
| 65 }; | 66 }; |
| 66 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 67 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
| 67 } | 68 } |
| 68 | 69 |
| 69 bool operator==(const FontCacheKey& other) const | 70 bool operator==(const FontCacheKey& other) const |
| 70 { | 71 { |
| 71 return equalIgnoringCase(m_familyName, other.m_familyName) | 72 return m_creationParams == other.m_creationParams |
| 72 && m_fontSize == other.m_fontSize | 73 && m_fontSize == other.m_fontSize |
| 73 && m_options == other.m_options; | 74 && m_options == other.m_options; |
| 74 } | 75 } |
| 75 | 76 |
| 76 bool isHashTableDeletedValue() const | 77 bool isHashTableDeletedValue() const |
| 77 { | 78 { |
| 78 return m_fontSize == hashTableDeletedSize(); | 79 return m_fontSize == hashTableDeletedSize(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 static unsigned precisionMultiplier() | 82 static unsigned precisionMultiplier() |
| 82 { | 83 { |
| 83 return s_fontSizePrecisionMultiplier; | 84 return s_fontSizePrecisionMultiplier; |
| 84 } | 85 } |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 static unsigned hashTableDeletedSize() | 88 static unsigned hashTableDeletedSize() |
| 88 { | 89 { |
| 89 return 0xFFFFFFFFU; | 90 return 0xFFFFFFFFU; |
| 90 } | 91 } |
| 91 | 92 |
| 92 AtomicString m_familyName; | 93 FontFaceCreationParams m_creationParams; |
| 93 unsigned m_fontSize; | 94 unsigned m_fontSize; |
| 94 unsigned m_options; | 95 unsigned m_options; |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 struct FontCacheKeyHash { | 98 struct FontCacheKeyHash { |
| 98 static unsigned hash(const FontCacheKey& key) | 99 static unsigned hash(const FontCacheKey& key) |
| 99 { | 100 { |
| 100 return key.hash(); | 101 return key.hash(); |
| 101 } | 102 } |
| 102 | 103 |
| 103 static bool equal(const FontCacheKey& a, const FontCacheKey& b) | 104 static bool equal(const FontCacheKey& a, const FontCacheKey& b) |
| 104 { | 105 { |
| 105 return a == b; | 106 return a == b; |
| 106 } | 107 } |
| 107 | 108 |
| 108 static const bool safeToCompareToEmptyOrDeleted = true; | 109 static const bool safeToCompareToEmptyOrDeleted = true; |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 struct FontCacheKeyTraits : WTF::SimpleClassHashTraits<FontCacheKey> { }; | 112 struct FontCacheKeyTraits : WTF::SimpleClassHashTraits<FontCacheKey> { }; |
| 112 | 113 |
| 113 } | 114 } |
| 114 | 115 |
| 115 #endif // FontCacheKey_h | 116 #endif // FontCacheKey_h |
| OLD | NEW |