Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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 #include "platform/fonts/shaping/HarfBuzzFace.h" | 31 #include "platform/fonts/shaping/HarfBuzzFace.h" |
| 32 | 32 |
| 33 #include "platform/Histogram.h" | |
| 33 #include "platform/fonts/FontCache.h" | 34 #include "platform/fonts/FontCache.h" |
| 34 #include "platform/fonts/FontPlatformData.h" | 35 #include "platform/fonts/FontPlatformData.h" |
| 35 #include "platform/fonts/SimpleFontData.h" | 36 #include "platform/fonts/SimpleFontData.h" |
| 36 #include "platform/fonts/UnicodeRangeSet.h" | 37 #include "platform/fonts/UnicodeRangeSet.h" |
| 37 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 38 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
| 38 #include "wtf/HashMap.h" | 39 #include "wtf/HashMap.h" |
| 39 #include "wtf/MathExtras.h" | 40 #include "wtf/MathExtras.h" |
| 40 #include "wtf/PtrUtil.h" | 41 #include "wtf/PtrUtil.h" |
| 41 #include <memory> | 42 #include <memory> |
| 42 | 43 |
| 43 #include <hb-ot.h> | 44 #include <hb-ot.h> |
| 44 #include <hb.h> | 45 #include <hb.h> |
| 45 #if OS(MACOSX) | 46 #if OS(MACOSX) |
| 46 #include <hb-coretext.h> | 47 #include <hb-coretext.h> |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 #include <SkPaint.h> | 50 #include <SkPaint.h> |
| 50 #include <SkPath.h> | 51 #include <SkPath.h> |
| 51 #include <SkPoint.h> | 52 #include <SkPoint.h> |
| 52 #include <SkRect.h> | 53 #include <SkRect.h> |
| 53 #include <SkStream.h> | 54 #include <SkStream.h> |
| 54 #include <SkTypeface.h> | 55 #include <SkTypeface.h> |
| 55 | 56 |
| 56 | 57 |
| 57 namespace blink { | 58 namespace blink { |
| 58 | 59 |
| 60 enum HarfBuzzFaceInstantiationTypeUMA { | |
|
Mark P
2016/06/27 21:28:41
Please put the standard warning here that these va
drott
2016/06/28 07:38:47
I was initially considering reporting the differen
| |
| 61 HarfBuzzFaceInstantiationTypeInplace = 0, | |
| 62 HarfBuzzFaceInstantiationTypeTableCopy, | |
| 63 MaxHarfBuzzFaceInstantiationType | |
| 64 }; | |
| 65 | |
| 59 struct HbFontDeleter { | 66 struct HbFontDeleter { |
| 60 void operator()(hb_font_t* font) | 67 void operator()(hb_font_t* font) |
| 61 { | 68 { |
| 62 if (font) | 69 if (font) |
| 63 hb_font_destroy(font); | 70 hb_font_destroy(font); |
| 64 } | 71 } |
| 65 }; | 72 }; |
| 66 | 73 |
| 67 using HbFontUniquePtr = std::unique_ptr<hb_font_t, HbFontDeleter>; | 74 using HbFontUniquePtr = std::unique_ptr<hb_font_t, HbFontDeleter>; |
| 68 | 75 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 } | 327 } |
| 321 #endif | 328 #endif |
| 322 | 329 |
| 323 hb_face_t* HarfBuzzFace::createFace() | 330 hb_face_t* HarfBuzzFace::createFace() |
| 324 { | 331 { |
| 325 #if OS(MACOSX) | 332 #if OS(MACOSX) |
| 326 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); | 333 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); |
| 327 #else | 334 #else |
| 328 hb_face_t* face = nullptr; | 335 hb_face_t* face = nullptr; |
| 329 | 336 |
| 337 DEFINE_STATIC_LOCAL(EnumerationHistogram, | |
| 338 faceInstantiationHistogram, | |
| 339 ("Blink.Fonts.HarfBuzzFaceInstantiationType", MaxHarfBuzzFaceInstantiati onType)); | |
| 330 SkTypeface* typeface = m_platformData->typeface(); | 340 SkTypeface* typeface = m_platformData->typeface(); |
| 331 int ttcIndex = 0; | 341 int ttcIndex = 0; |
| 332 SkStreamAsset* typefaceStream = typeface->openStream(&ttcIndex); | 342 SkStreamAsset* typefaceStream = typeface->openStream(&ttcIndex); |
| 333 if (typefaceStream->getMemoryBase()) { | 343 if (typefaceStream->getMemoryBase()) { |
| 334 std::unique_ptr<hb_blob_t, void(*)(hb_blob_t*)> faceBlob(hb_blob_create( | 344 std::unique_ptr<hb_blob_t, void(*)(hb_blob_t*)> faceBlob(hb_blob_create( |
| 335 reinterpret_cast<const char*>(typefaceStream->getMemoryBase()), | 345 reinterpret_cast<const char*>(typefaceStream->getMemoryBase()), |
| 336 typefaceStream->getLength(), | 346 typefaceStream->getLength(), |
| 337 HB_MEMORY_MODE_READONLY, | 347 HB_MEMORY_MODE_READONLY, |
| 338 typefaceStream, | 348 typefaceStream, |
| 339 deleteTypefaceStream), | 349 deleteTypefaceStream), |
| 340 hb_blob_destroy); | 350 hb_blob_destroy); |
| 341 face = hb_face_create(faceBlob.get(), ttcIndex); | 351 face = hb_face_create(faceBlob.get(), ttcIndex); |
| 342 } | 352 } |
| 343 | 353 |
| 344 // Fallback to table copies if there is no in-memory access. | 354 // Fallback to table copies if there is no in-memory access. |
| 345 if (!face) | 355 if (!face) { |
| 346 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platformData->t ypeface(), 0); | 356 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platformData->t ypeface(), 0); |
| 357 faceInstantiationHistogram.count(HarfBuzzFaceInstantiationTypeTableCopy) ; | |
| 358 } else { | |
| 359 faceInstantiationHistogram.count(HarfBuzzFaceInstantiationTypeInplace); | |
| 360 } | |
| 347 #endif | 361 #endif |
| 348 ASSERT(face); | 362 ASSERT(face); |
| 349 return face; | 363 return face; |
| 350 } | 364 } |
| 351 | 365 |
| 352 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) | 366 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) |
| 353 { | 367 { |
| 354 HbFontUniquePtr otFont(hb_font_create(face)); | 368 HbFontUniquePtr otFont(hb_font_create(face)); |
| 355 hb_ot_font_set_funcs(otFont.get()); | 369 hb_ot_font_set_funcs(otFont.get()); |
| 356 // Creating a sub font means that non-available functions | 370 // Creating a sub font means that non-available functions |
| 357 // are found from the parent. | 371 // are found from the parent. |
| 358 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); | 372 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); |
| 359 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ; | 373 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ; |
| 360 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr); | 374 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr); |
| 361 return cacheEntry; | 375 return cacheEntry; |
| 362 } | 376 } |
| 363 | 377 |
| 364 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st | 378 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st |
| 365 { | 379 { |
| 366 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 380 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
| 367 m_harfBuzzFontData->m_rangeSet = rangeSet; | 381 m_harfBuzzFontData->m_rangeSet = rangeSet; |
| 368 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData).get(); | 382 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData).get(); |
| 369 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 383 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
| 370 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 384 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
| 371 hb_font_set_scale(m_unscaledFont, scale, scale); | 385 hb_font_set_scale(m_unscaledFont, scale, scale); |
| 372 return m_unscaledFont; | 386 return m_unscaledFont; |
| 373 } | 387 } |
| 374 | 388 |
| 375 } // namespace blink | 389 } // namespace blink |
| OLD | NEW |