Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontDataCache.h

Issue 1931393002: Introduce typeface cache in blink::FontCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wip: others Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 static const bool safeToCompareToEmptyOrDeleted = true; 55 static const bool safeToCompareToEmptyOrDeleted = true;
56 }; 56 };
57 57
58 struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> { 58 struct FontDataCacheKeyTraits : WTF::GenericHashTraits<FontPlatformData> {
59 STATIC_ONLY(FontDataCacheKeyTraits); 59 STATIC_ONLY(FontDataCacheKeyTraits);
60 static const bool emptyValueIsZero = true; 60 static const bool emptyValueIsZero = true;
61 static const FontPlatformData& emptyValue() 61 static const FontPlatformData& emptyValue()
62 { 62 {
63 DEFINE_STATIC_LOCAL(FontPlatformData, key, (0.f, false, false)); 63 DEFINE_STATIC_LOCAL(FontPlatformData, key, (false, false));
64 return key; 64 return key;
65 } 65 }
66 static void constructDeletedValue(FontPlatformData& slot, bool) 66 static void constructDeletedValue(FontPlatformData& slot, bool)
67 { 67 {
68 new (NotNull, &slot) FontPlatformData(WTF::HashTableDeletedValue); 68 new (NotNull, &slot) FontPlatformData(WTF::HashTableDeletedValue);
69 } 69 }
70 static bool isDeletedValue(const FontPlatformData& value) 70 static bool isDeletedValue(const FontPlatformData& value)
71 { 71 {
72 return value.isHashTableDeletedValue(); 72 return value.isHashTableDeletedValue();
73 } 73 }
74 }; 74 };
75 75
76 class FontDataCache { 76 class FontDataCache {
77 USING_FAST_MALLOC(FontDataCache); 77 USING_FAST_MALLOC(FontDataCache);
78 WTF_MAKE_NONCOPYABLE(FontDataCache); 78 WTF_MAKE_NONCOPYABLE(FontDataCache);
79 public: 79 public:
80 FontDataCache() { } 80 FontDataCache() { }
81 81
82 PassRefPtr<SimpleFontData> get(const FontPlatformData*, ShouldRetain = Retai n); 82 PassRefPtr<SimpleFontData> get(const FontPlatformData*, float fontSize, Shou ldRetain = Retain);
83 bool contains(const FontPlatformData*) const; 83 bool contains(const FontPlatformData*) const;
84 void release(const SimpleFontData*); 84 void release(const SimpleFontData*);
85 85
86 // This is used by FontVerticalDataCache to mark all items with vertical dat a 86 // This is used by FontVerticalDataCache to mark all items with vertical dat a
87 // that are currently in cache as "in cache", which is later used to sweep t he FontVerticalDataCache. 87 // that are currently in cache as "in cache", which is later used to sweep t he FontVerticalDataCache.
88 void markAllVerticalData(); 88 void markAllVerticalData();
89 89
90 // Purges items in FontDataCache according to provided severity. 90 // Purges items in FontDataCache according to provided severity.
91 // Returns true if any removal of cache items actually occurred. 91 // Returns true if any removal of cache items actually occurred.
92 bool purge(PurgeSeverity); 92 bool purge(PurgeSeverity);
93 93
94 private: 94 private:
95 bool purgeLeastRecentlyUsed(int count); 95 bool purgeLeastRecentlyUsed(int count);
96 96
97 typedef HashMap<FontPlatformData, std::pair<RefPtr<SimpleFontData>, unsigned >, FontDataCacheKeyHash, FontDataCacheKeyTraits> Cache; 97 typedef HashMap<float, std::pair<RefPtr<SimpleFontData>, unsigned>> InnerCac he;
98 typedef HashMap<FontPlatformData, InnerCache, FontDataCacheKeyHash, FontData CacheKeyTraits> Cache;
98 Cache m_cache; 99 Cache m_cache;
99 ListHashSet<RefPtr<SimpleFontData>> m_inactiveFontData; 100 ListHashSet<RefPtr<SimpleFontData>> m_inactiveFontData;
100 }; 101 };
101 102
102 } // namespace blink 103 } // namespace blink
103 104
104 #endif 105 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698