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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 // Though we have FontCache class, which provides the cache mechanism for | 107 // Though we have FontCache class, which provides the cache mechanism for |
108 // WebKit's font objects, we also need additional caching layer for HarfBuzz to | 108 // WebKit's font objects, we also need additional caching layer for HarfBuzz to |
109 // reduce the number of hb_font_t objects created. Without it, we would create | 109 // reduce the number of hb_font_t objects created. Without it, we would create |
110 // an hb_font_t object for every FontPlatformData object. But insted, we only | 110 // an hb_font_t object for every FontPlatformData object. But insted, we only |
111 // need one for each unique SkTypeface. | 111 // need one for each unique SkTypeface. |
112 // FIXME, crbug.com/609099: We should fix the FontCache to only keep one | 112 // FIXME, crbug.com/609099: We should fix the FontCache to only keep one |
113 // FontPlatformData object independent of size, then consider using this here. | 113 // FontPlatformData object independent of size, then consider using this here. |
114 class HbFontCacheEntry : public RefCounted<HbFontCacheEntry> { | 114 class HbFontCacheEntry : public RefCounted<HbFontCacheEntry> { |
115 public: | 115 public: |
116 static PassRefPtr<HbFontCacheEntry> create(hb_font_t* hbFont) { | 116 static PassRefPtr<HbFontCacheEntry> create(hb_font_t* hbFont) { |
117 ASSERT(hbFont); | 117 DCHECK(hbFont); |
118 return adoptRef(new HbFontCacheEntry(hbFont)); | 118 return adoptRef(new HbFontCacheEntry(hbFont)); |
119 } | 119 } |
120 | 120 |
121 hb_font_t* hbFont() { return m_hbFont.get(); } | 121 hb_font_t* hbFont() { return m_hbFont.get(); } |
122 HarfBuzzFontData* hbFontData() { return m_hbFontData.get(); } | 122 HarfBuzzFontData* hbFontData() { return m_hbFontData.get(); } |
123 | 123 |
124 private: | 124 private: |
125 explicit HbFontCacheEntry(hb_font_t* font) | 125 explicit HbFontCacheEntry(hb_font_t* font) |
126 : m_hbFont(HbFontUniquePtr(font)), | 126 : m_hbFont(HbFontUniquePtr(font)), |
127 m_hbFontData(WTF::makeUnique<HarfBuzzFontData>()){}; | 127 m_hbFontData(WTF::makeUnique<HarfBuzzFontData>()){}; |
(...skipping 24 matching lines...) Expand all Loading... |
152 result.storedValue->value = createHbFontCacheEntry(face.get()); | 152 result.storedValue->value = createHbFontCacheEntry(face.get()); |
153 } | 153 } |
154 result.storedValue->value->ref(); | 154 result.storedValue->value->ref(); |
155 m_unscaledFont = result.storedValue->value->hbFont(); | 155 m_unscaledFont = result.storedValue->value->hbFont(); |
156 m_harfBuzzFontData = result.storedValue->value->hbFontData(); | 156 m_harfBuzzFontData = result.storedValue->value->hbFontData(); |
157 } | 157 } |
158 | 158 |
159 HarfBuzzFace::~HarfBuzzFace() { | 159 HarfBuzzFace::~HarfBuzzFace() { |
160 HarfBuzzFontCache::iterator result = harfBuzzFontCache()->find(m_uniqueID); | 160 HarfBuzzFontCache::iterator result = harfBuzzFontCache()->find(m_uniqueID); |
161 SECURITY_DCHECK(result != harfBuzzFontCache()->end()); | 161 SECURITY_DCHECK(result != harfBuzzFontCache()->end()); |
162 ASSERT(result.get()->value->refCount() > 1); | 162 DCHECK_GT(result.get()->value->refCount(), 1); |
163 result.get()->value->deref(); | 163 result.get()->value->deref(); |
164 if (result.get()->value->refCount() == 1) | 164 if (result.get()->value->refCount() == 1) |
165 harfBuzzFontCache()->erase(m_uniqueID); | 165 harfBuzzFontCache()->erase(m_uniqueID); |
166 } | 166 } |
167 | 167 |
168 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) { | 168 static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value) { |
169 // We treat HarfBuzz hb_position_t as 16.16 fixed-point. | 169 // We treat HarfBuzz hb_position_t as 16.16 fixed-point. |
170 static const int kHbPosition1 = 1 << 16; | 170 static const int kHbPosition1 = 1 << 16; |
171 return clampTo<int>(value * kHbPosition1); | 171 return clampTo<int>(value * kHbPosition1); |
172 } | 172 } |
173 | 173 |
174 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, | 174 static hb_bool_t harfBuzzGetGlyph(hb_font_t* hbFont, |
175 void* fontData, | 175 void* fontData, |
176 hb_codepoint_t unicode, | 176 hb_codepoint_t unicode, |
177 hb_codepoint_t variationSelector, | 177 hb_codepoint_t variationSelector, |
178 hb_codepoint_t* glyph, | 178 hb_codepoint_t* glyph, |
179 void* userData) { | 179 void* userData) { |
180 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData); | 180 HarfBuzzFontData* hbFontData = reinterpret_cast<HarfBuzzFontData*>(fontData); |
181 | 181 |
182 RELEASE_ASSERT(hbFontData); | 182 CHECK(hbFontData); |
183 if (hbFontData->m_rangeSet && !hbFontData->m_rangeSet->contains(unicode)) | 183 if (hbFontData->m_rangeSet && !hbFontData->m_rangeSet->contains(unicode)) |
184 return false; | 184 return false; |
185 | 185 |
186 return hb_font_get_glyph(hb_font_get_parent(hbFont), unicode, | 186 return hb_font_get_glyph(hb_font_get_parent(hbFont), unicode, |
187 variationSelector, glyph); | 187 variationSelector, glyph); |
188 } | 188 } |
189 | 189 |
190 static hb_position_t harfBuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, | 190 static hb_position_t harfBuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, |
191 void* fontData, | 191 void* fontData, |
192 hb_codepoint_t glyph, | 192 hb_codepoint_t glyph, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 357 |
358 // Fallback to table copies if there is no in-memory access. | 358 // Fallback to table copies if there is no in-memory access. |
359 if (!face) { | 359 if (!face) { |
360 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, | 360 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, |
361 m_platformData->typeface(), 0); | 361 m_platformData->typeface(), 0); |
362 zeroCopySuccessHistogram.count(false); | 362 zeroCopySuccessHistogram.count(false); |
363 } else { | 363 } else { |
364 zeroCopySuccessHistogram.count(true); | 364 zeroCopySuccessHistogram.count(true); |
365 } | 365 } |
366 #endif | 366 #endif |
367 ASSERT(face); | 367 DCHECK(face); |
368 return face; | 368 return face; |
369 } | 369 } |
370 | 370 |
371 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) { | 371 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) { |
372 HbFontUniquePtr otFont(hb_font_create(face)); | 372 HbFontUniquePtr otFont(hb_font_create(face)); |
373 hb_ot_font_set_funcs(otFont.get()); | 373 hb_ot_font_set_funcs(otFont.get()); |
374 // Creating a sub font means that non-available functions | 374 // Creating a sub font means that non-available functions |
375 // are found from the parent. | 375 // are found from the parent. |
376 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); | 376 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); |
377 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont); | 377 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont); |
(...skipping 13 matching lines...) Expand all Loading... |
391 "Skia and HarfBuzz Variation parameter types must match in structure and " | 391 "Skia and HarfBuzz Variation parameter types must match in structure and " |
392 "size."); | 392 "size."); |
393 | 393 |
394 hb_font_t* HarfBuzzFace::getScaledFont( | 394 hb_font_t* HarfBuzzFace::getScaledFont( |
395 PassRefPtr<UnicodeRangeSet> rangeSet) const { | 395 PassRefPtr<UnicodeRangeSet> rangeSet) const { |
396 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 396 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
397 m_harfBuzzFontData->m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 397 m_harfBuzzFontData->m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
398 m_harfBuzzFontData->m_rangeSet = std::move(rangeSet); | 398 m_harfBuzzFontData->m_rangeSet = std::move(rangeSet); |
399 m_harfBuzzFontData->updateSimpleFontData(m_platformData); | 399 m_harfBuzzFontData->updateSimpleFontData(m_platformData); |
400 | 400 |
401 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 401 DCHECK(m_harfBuzzFontData->m_simpleFontData); |
402 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 402 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
403 hb_font_set_scale(m_unscaledFont, scale, scale); | 403 hb_font_set_scale(m_unscaledFont, scale, scale); |
404 | 404 |
405 SkTypeface* typeface = m_harfBuzzFontData->m_paint.getTypeface(); | 405 SkTypeface* typeface = m_harfBuzzFontData->m_paint.getTypeface(); |
406 int axisCount = typeface->getVariationDesignPosition(nullptr, 0); | 406 int axisCount = typeface->getVariationDesignPosition(nullptr, 0); |
407 if (axisCount > 0) { | 407 if (axisCount > 0) { |
408 Vector<SkFontArguments::VariationPosition::Coordinate> axisValues; | 408 Vector<SkFontArguments::VariationPosition::Coordinate> axisValues; |
409 axisValues.resize(axisCount); | 409 axisValues.resize(axisCount); |
410 if (typeface->getVariationDesignPosition(axisValues.data(), | 410 if (typeface->getVariationDesignPosition(axisValues.data(), |
411 axisValues.size()) > 0) { | 411 axisValues.size()) > 0) { |
412 hb_font_set_variations( | 412 hb_font_set_variations( |
413 m_unscaledFont, reinterpret_cast<hb_variation_t*>(axisValues.data()), | 413 m_unscaledFont, reinterpret_cast<hb_variation_t*>(axisValues.data()), |
414 axisValues.size()); | 414 axisValues.size()); |
415 } | 415 } |
416 } | 416 } |
417 | 417 |
418 return m_unscaledFont; | 418 return m_unscaledFont; |
419 } | 419 } |
420 | 420 |
421 } // namespace blink | 421 } // namespace blink |
OLD | NEW |