OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 HarfBuzzFontCache; | 122 HarfBuzzFontCache; |
123 | 123 |
124 static HarfBuzzFontCache* harfBuzzFontCache() { | 124 static HarfBuzzFontCache* harfBuzzFontCache() { |
125 DEFINE_STATIC_LOCAL(HarfBuzzFontCache, s_harfBuzzFontCache, ()); | 125 DEFINE_STATIC_LOCAL(HarfBuzzFontCache, s_harfBuzzFontCache, ()); |
126 return &s_harfBuzzFontCache; | 126 return &s_harfBuzzFontCache; |
127 } | 127 } |
128 | 128 |
129 static PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t*); | 129 static PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t*); |
130 | 130 |
131 HarfBuzzFace::HarfBuzzFace(FontPlatformData* platformData, uint64_t uniqueID) | 131 HarfBuzzFace::HarfBuzzFace(FontPlatformData* platformData, uint64_t uniqueID) |
132 : m_platformData(platformData), m_uniqueID(uniqueID) { | 132 : m_platformData(platformData), |
133 m_uniqueID(uniqueID), | |
134 m_simpleFontData(nullptr) { | |
133 HarfBuzzFontCache::AddResult result = | 135 HarfBuzzFontCache::AddResult result = |
134 harfBuzzFontCache()->add(m_uniqueID, nullptr); | 136 harfBuzzFontCache()->add(m_uniqueID, nullptr); |
135 if (result.isNewEntry) { | 137 if (result.isNewEntry) { |
136 HbFaceUniquePtr face(createFace()); | 138 HbFaceUniquePtr face(createFace()); |
137 result.storedValue->value = createHbFontCacheEntry(face.get()); | 139 result.storedValue->value = createHbFontCacheEntry(face.get()); |
138 } | 140 } |
139 result.storedValue->value->ref(); | 141 result.storedValue->value->ref(); |
140 m_unscaledFont = result.storedValue->value->hbFont(); | 142 m_unscaledFont = result.storedValue->value->hbFont(); |
141 m_harfBuzzFontData = result.storedValue->value->hbFontData(); | 143 m_harfBuzzFontData = result.storedValue->value->hbFontData(); |
142 } | 144 } |
143 | 145 |
144 HarfBuzzFace::~HarfBuzzFace() { | 146 HarfBuzzFace::~HarfBuzzFace() { |
145 HarfBuzzFontCache::iterator result = harfBuzzFontCache()->find(m_uniqueID); | 147 HarfBuzzFontCache::iterator result = harfBuzzFontCache()->find(m_uniqueID); |
146 ASSERT_WITH_SECURITY_IMPLICATION(result != harfBuzzFontCache()->end()); | 148 ASSERT_WITH_SECURITY_IMPLICATION(result != harfBuzzFontCache()->end()); |
147 ASSERT(result.get()->value->refCount() > 1); | 149 ASSERT(result.get()->value->refCount() > 1); |
148 result.get()->value->deref(); | 150 result.get()->value->deref(); |
149 if (result.get()->value->refCount() == 1) | 151 if (result.get()->value->refCount() == 1) |
150 harfBuzzFontCache()->remove(m_uniqueID); | 152 harfBuzzFontCache()->remove(m_uniqueID); |
153 if (m_simpleFontData) | |
154 FontCache::fontCache()->releaseFontData(m_simpleFontData); | |
drott
2016/10/11 11:40:44
Yes, this definitely seems needed.
| |
151 } | 155 } |
152 | 156 |
153 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) { | 157 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) { |
154 // We treat HarfBuzz hb_position_t as 16.16 fixed-point. | 158 // We treat HarfBuzz hb_position_t as 16.16 fixed-point. |
155 static const int kHbPosition1 = 1 << 16; | 159 static const int kHbPosition1 = 1 << 16; |
156 return clampTo<int>(value * kHbPosition1); | 160 return clampTo<int>(value * kHbPosition1); |
157 } | 161 } |
158 | 162 |
159 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, | 163 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, |
160 void* fontData, | 164 void* fontData, |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), | 367 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), |
364 cacheEntry->hbFontData(), nullptr); | 368 cacheEntry->hbFontData(), nullptr); |
365 return cacheEntry; | 369 return cacheEntry; |
366 } | 370 } |
367 | 371 |
368 hb_font_t* HarfBuzzFace::getScaledFont( | 372 hb_font_t* HarfBuzzFace::getScaledFont( |
369 PassRefPtr<UnicodeRangeSet> rangeSet) const { | 373 PassRefPtr<UnicodeRangeSet> rangeSet) const { |
370 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 374 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
371 m_harfBuzzFontData->m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 375 m_harfBuzzFontData->m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
372 m_harfBuzzFontData->m_rangeSet = rangeSet; | 376 m_harfBuzzFontData->m_rangeSet = rangeSet; |
373 m_harfBuzzFontData->m_simpleFontData = | 377 if (!m_simpleFontData) { |
374 FontCache::fontCache() | 378 m_simpleFontData = FontCache::fontCache() |
375 ->fontDataFromFontPlatformData(m_platformData) | 379 ->fontDataFromFontPlatformData(m_platformData) |
376 .get(); | 380 .get(); |
381 } | |
382 DCHECK_EQ(m_simpleFontData, | |
383 FontCache::fontCache() | |
384 ->fontDataFromFontPlatformData(m_platformData, DoNotRetain) | |
385 .get()); | |
386 m_harfBuzzFontData->m_simpleFontData = m_simpleFontData; | |
377 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 387 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
378 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 388 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
379 hb_font_set_scale(m_unscaledFont, scale, scale); | 389 hb_font_set_scale(m_unscaledFont, scale, scale); |
380 return m_unscaledFont; | 390 return m_unscaledFont; |
381 } | 391 } |
382 | 392 |
383 } // namespace blink | 393 } // namespace blink |
OLD | NEW |