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 14 matching lines...) Expand all Loading... |
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 "FontFaceCreationParams.h" |
| 35 #include "platform/fonts/opentype/FontSettings.h" |
35 #include "wtf/Allocator.h" | 36 #include "wtf/Allocator.h" |
36 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
37 #include "wtf/HashTableDeletedValueType.h" | 38 #include "wtf/HashTableDeletedValueType.h" |
38 #include "wtf/text/AtomicStringHash.h" | 39 #include "wtf/text/AtomicStringHash.h" |
39 #include "wtf/text/StringHash.h" | 40 #include "wtf/text/StringHash.h" |
40 | 41 |
41 namespace blink { | 42 namespace blink { |
42 | 43 |
43 // Multiplying the floating point size by 100 gives two decimal point | 44 // Multiplying the floating point size by 100 gives two decimal point |
44 // precision which should be sufficient. | 45 // precision which should be sufficient. |
45 static const unsigned s_fontSizePrecisionMultiplier = 100; | 46 static const unsigned s_fontSizePrecisionMultiplier = 100; |
46 | 47 |
47 struct FontCacheKey { | 48 struct FontCacheKey { |
48 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 49 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
49 | 50 |
50 public: | 51 public: |
51 FontCacheKey() : m_creationParams(), m_fontSize(0), m_options(0) {} | 52 FontCacheKey() : m_creationParams(), m_fontSize(0), m_options(0) {} |
52 FontCacheKey(FontFaceCreationParams creationParams, | 53 FontCacheKey(FontFaceCreationParams creationParams, |
53 float fontSize, | 54 float fontSize, |
54 unsigned options) | 55 unsigned options, |
| 56 PassRefPtr<FontVariationSettings> variationSettings) |
55 : m_creationParams(creationParams), | 57 : m_creationParams(creationParams), |
56 m_fontSize(fontSize * s_fontSizePrecisionMultiplier), | 58 m_fontSize(fontSize * s_fontSizePrecisionMultiplier), |
57 m_options(options) {} | 59 m_options(options), |
| 60 m_variationSettings(variationSettings) {} |
| 61 |
58 FontCacheKey(WTF::HashTableDeletedValueType) | 62 FontCacheKey(WTF::HashTableDeletedValueType) |
59 : m_fontSize(hashTableDeletedSize()) {} | 63 : m_fontSize(hashTableDeletedSize()) {} |
60 | 64 |
61 unsigned hash() const { | 65 unsigned hash() const { |
62 unsigned hashCodes[3] = {m_creationParams.hash(), m_fontSize, m_options}; | 66 unsigned hashCodes[4] = { |
| 67 m_creationParams.hash(), m_fontSize, m_options, |
| 68 m_variationSettings ? m_variationSettings->hash() : 0}; |
63 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); | 69 return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes); |
64 } | 70 } |
65 | 71 |
66 bool operator==(const FontCacheKey& other) const { | 72 bool operator==(const FontCacheKey& other) const { |
67 return m_creationParams == other.m_creationParams && | 73 return m_creationParams == other.m_creationParams && |
68 m_fontSize == other.m_fontSize && m_options == other.m_options; | 74 m_fontSize == other.m_fontSize && m_options == other.m_options && |
| 75 m_variationSettings == other.m_variationSettings; |
69 } | 76 } |
70 | 77 |
71 bool isHashTableDeletedValue() const { | 78 bool isHashTableDeletedValue() const { |
72 return m_fontSize == hashTableDeletedSize(); | 79 return m_fontSize == hashTableDeletedSize(); |
73 } | 80 } |
74 | 81 |
75 static unsigned precisionMultiplier() { | 82 static unsigned precisionMultiplier() { |
76 return s_fontSizePrecisionMultiplier; | 83 return s_fontSizePrecisionMultiplier; |
77 } | 84 } |
78 | 85 |
79 void clearFontSize() { m_fontSize = 0; } | 86 void clearFontSize() { m_fontSize = 0; } |
80 | 87 |
81 private: | 88 private: |
82 static unsigned hashTableDeletedSize() { return 0xFFFFFFFFU; } | 89 static unsigned hashTableDeletedSize() { return 0xFFFFFFFFU; } |
83 | 90 |
84 FontFaceCreationParams m_creationParams; | 91 FontFaceCreationParams m_creationParams; |
85 unsigned m_fontSize; | 92 unsigned m_fontSize; |
86 unsigned m_options; | 93 unsigned m_options; |
| 94 RefPtr<FontVariationSettings> m_variationSettings; |
87 }; | 95 }; |
88 | 96 |
89 struct FontCacheKeyHash { | 97 struct FontCacheKeyHash { |
90 STATIC_ONLY(FontCacheKeyHash); | 98 STATIC_ONLY(FontCacheKeyHash); |
91 static unsigned hash(const FontCacheKey& key) { return key.hash(); } | 99 static unsigned hash(const FontCacheKey& key) { return key.hash(); } |
92 | 100 |
93 static bool equal(const FontCacheKey& a, const FontCacheKey& b) { | 101 static bool equal(const FontCacheKey& a, const FontCacheKey& b) { |
94 return a == b; | 102 return a == b; |
95 } | 103 } |
96 | 104 |
97 static const bool safeToCompareToEmptyOrDeleted = true; | 105 static const bool safeToCompareToEmptyOrDeleted = true; |
98 }; | 106 }; |
99 | 107 |
100 struct FontCacheKeyTraits : WTF::SimpleClassHashTraits<FontCacheKey> { | 108 struct FontCacheKeyTraits : WTF::SimpleClassHashTraits<FontCacheKey> { |
101 STATIC_ONLY(FontCacheKeyTraits); | 109 STATIC_ONLY(FontCacheKeyTraits); |
102 }; | 110 }; |
103 | 111 |
104 } // namespace blink | 112 } // namespace blink |
105 | 113 |
106 #endif // FontCacheKey_h | 114 #endif // FontCacheKey_h |
OLD | NEW |