Changeset 228525 in webkit
- Timestamp:
- Feb 15, 2018, 11:06:05 AM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r228524 r228525 1 2018-02-15 Zan Dobersek <zdobersek@igalia.com> 2 3 HarfBuzzFace: rework cache entry reference holding 4 https://bugs.webkit.org/show_bug.cgi?id=182828 5 6 Reviewed by Michael Catanzaro. 7 8 Move the FaceCacheEntry and HarfBuzzFaceCache types into the 9 HarfBuzzFace class as CacheEntry and Cache, respectively. The Cache 10 singleton is also moved there. 11 12 In the HarfBuzzFace constructor, we now don't increase the CacheEntry 13 reference, but instead just keep a reference to that object through 14 a RefPtr<CacheEntry> object. We don't need to retrieve the hb_face_t 15 object and the glyph cache HashMap in the constructor anymore, we just 16 retrieve them when necessary through that CacheEntry reference. 17 18 In the destructor, that RefPtr<CacheEntry> object is nulled out before 19 the object in Cache is removed if that's where the final reference is 20 kept. 21 22 * platform/graphics/harfbuzz/HarfBuzzFace.cpp: 23 (WebCore::HarfBuzzFace::CacheEntry::CacheEntry): 24 (WebCore::HarfBuzzFace::CacheEntry::~CacheEntry): 25 (WebCore::HarfBuzzFace::cache): 26 (WebCore::HarfBuzzFace::HarfBuzzFace): 27 (WebCore::HarfBuzzFace::~HarfBuzzFace): 28 (WebCore::HarfBuzzFace::setScriptForVerticalGlyphSubstitution): 29 (WebCore::FaceCacheEntry::create): Deleted. 30 (WebCore::FaceCacheEntry::~FaceCacheEntry): Deleted. 31 (WebCore::FaceCacheEntry::face): Deleted. 32 (WebCore::FaceCacheEntry::glyphCache): Deleted. 33 (WebCore::FaceCacheEntry::FaceCacheEntry): Deleted. 34 (WebCore::harfBuzzFaceCache): Deleted. 35 * platform/graphics/harfbuzz/HarfBuzzFace.h: 36 (WebCore::HarfBuzzFace::CacheEntry::create): 37 (WebCore::HarfBuzzFace::CacheEntry::face): 38 (WebCore::HarfBuzzFace::CacheEntry::glyphCache): 39 * platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp: 40 (WebCore::harfBuzzGetGlyph): 41 (WebCore::HarfBuzzFace::createFont): 42 1 43 2018-02-15 Zan Dobersek <zdobersek@igalia.com> 2 44 -
trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.cpp
r219858 r228525 48 48 // underling font data (e.g. CTFontRef, FTFace). 49 49 50 class FaceCacheEntry : public RefCounted<FaceCacheEntry> { 51 public: 52 static Ref<FaceCacheEntry> create(hb_face_t* face) 53 { 54 ASSERT(face); 55 return adoptRef(*new FaceCacheEntry(face)); 56 } 57 ~FaceCacheEntry() 58 { 59 hb_face_destroy(m_face); 60 } 50 HarfBuzzFace::CacheEntry::CacheEntry(hb_face_t* face) 51 : m_face(face) 52 { 53 ASSERT(m_face); 54 } 61 55 62 hb_face_t* face() { return m_face; } 63 HashMap<uint32_t, uint16_t>* glyphCache() { return &m_glyphCache; } 56 HarfBuzzFace::CacheEntry::~CacheEntry() 57 { 58 hb_face_destroy(m_face); 59 } 64 60 65 private: 66 explicit FaceCacheEntry(hb_face_t* face) 67 : m_face(face) 68 { } 69 70 hb_face_t* m_face; 71 HashMap<uint32_t, uint16_t> m_glyphCache; 72 }; 73 74 typedef HashMap<uint64_t, RefPtr<FaceCacheEntry>, WTF::IntHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t> > HarfBuzzFaceCache; 75 76 static HarfBuzzFaceCache* harfBuzzFaceCache() 61 HarfBuzzFace::Cache& HarfBuzzFace::cache() 77 62 { 78 static NeverDestroyed< HarfBuzzFaceCache> s_harfBuzzFaceCache;79 return &s_harfBuzzFaceCache.get();63 static NeverDestroyed<Cache> s_cache; 64 return s_cache; 80 65 } 81 66 … … 85 70 , m_scriptForVerticalText(HB_SCRIPT_INVALID) 86 71 { 87 HarfBuzzFaceCache::AddResult result = harfBuzzFaceCache()->add(m_uniqueID, nullptr);72 auto result = cache().add(m_uniqueID, nullptr); 88 73 if (result.isNewEntry) 89 result.iterator->value = FaceCacheEntry::create(createFace()); 90 result.iterator->value->ref(); 91 m_face = result.iterator->value->face(); 92 m_glyphCacheForFaceCacheEntry = result.iterator->value->glyphCache(); 74 result.iterator->value = CacheEntry::create(createFace()); 75 m_cacheEntry = result.iterator->value; 93 76 } 94 77 95 78 HarfBuzzFace::~HarfBuzzFace() 96 79 { 97 HarfBuzzFaceCache::iterator result = harfBuzzFaceCache()->find(m_uniqueID); 98 ASSERT(result != harfBuzzFaceCache()->end()); 99 ASSERT(result.get()->value->refCount() > 1); 100 result.get()->value->deref(); 101 if (result.get()->value->refCount() == 1) 102 harfBuzzFaceCache()->remove(m_uniqueID); 80 auto it = cache().find(m_uniqueID); 81 ASSERT(it != cache().end()); 82 ASSERT(it->value == m_cacheEntry); 83 ASSERT(it->value->refCount() > 1); 84 85 m_cacheEntry = nullptr; 86 if (it->value->refCount() == 1) 87 cache().remove(it); 103 88 } 104 89 … … 127 112 { 128 113 if (m_scriptForVerticalText == HB_SCRIPT_INVALID) 129 m_scriptForVerticalText = findScriptForVerticalGlyphSubstitution(m_ face);114 m_scriptForVerticalText = findScriptForVerticalGlyphSubstitution(m_cacheEntry->face()); 130 115 hb_buffer_set_script(buffer, m_scriptForVerticalText); 131 116 } -
trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFace.h
r228507 r228525 37 37 #include <wtf/FastMalloc.h> 38 38 #include <wtf/HashMap.h> 39 #include <wtf/Ref.h> 40 #include <wtf/RefCounted.h> 39 41 40 42 namespace WebCore { … … 57 59 58 60 private: 61 class CacheEntry : public RefCounted<CacheEntry> { 62 public: 63 using GlyphCache = HashMap<uint32_t, uint16_t>; 64 65 static Ref<CacheEntry> create(hb_face_t* face) 66 { 67 return adoptRef(*new CacheEntry(face)); 68 } 69 ~CacheEntry(); 70 71 hb_face_t* face() { return m_face; } 72 GlyphCache& glyphCache() { return m_glyphCache; } 73 74 private: 75 CacheEntry(hb_face_t*); 76 77 hb_face_t* m_face; 78 GlyphCache m_glyphCache; 79 }; 80 81 using Cache = HashMap<uint64_t, RefPtr<CacheEntry>, WTF::IntHash<uint64_t>, WTF::UnsignedWithZeroKeyHashTraits<uint64_t>>; 82 static Cache& cache(); 83 59 84 hb_face_t* createFace(); 60 85 61 86 FontPlatformData* m_platformData; 62 87 uint64_t m_uniqueID; 63 hb_face_t* m_face; 64 WTF::HashMap<uint32_t, uint16_t>* m_glyphCacheForFaceCacheEntry; 88 RefPtr<CacheEntry> m_cacheEntry; 65 89 66 90 hb_script_t m_scriptForVerticalText; -
trunk/Source/WebCore/platform/graphics/harfbuzz/HarfBuzzFaceCairo.cpp
r228509 r228525 51 51 52 52 struct HarfBuzzFontData { 53 WTF::HashMap<uint32_t, uint16_t> *glyphCacheForFaceCacheEntry;53 WTF::HashMap<uint32_t, uint16_t>& glyphCacheForFaceCacheEntry; 54 54 RefPtr<cairo_scaled_font_t> cairoScaledFont; 55 55 }; … … 92 92 ASSERT(scaledFont); 93 93 94 WTF::HashMap<uint32_t, uint16_t>::AddResult result = hbFontData.glyphCacheForFaceCacheEntry->add(unicode, 0);94 auto result = hbFontData.glyphCacheForFaceCacheEntry.add(unicode, 0); 95 95 if (result.isNewEntry) { 96 96 cairo_glyph_t* glyphs = 0; … … 202 202 hb_font_t* HarfBuzzFace::createFont() 203 203 { 204 hb_font_t* font = hb_font_create(m_ face);205 hb_font_set_funcs(font, harfBuzzCairoTextGetFontFuncs(), new HarfBuzzFontData { m_ glyphCacheForFaceCacheEntry, m_platformData->scaledFont() },204 hb_font_t* font = hb_font_create(m_cacheEntry->face()); 205 hb_font_set_funcs(font, harfBuzzCairoTextGetFontFuncs(), new HarfBuzzFontData { m_cacheEntry->glyphCache(), m_platformData->scaledFont() }, 206 206 [](void* data) 207 207 {
Note:
See TracChangeset
for help on using the changeset viewer.