| 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 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 } | 321 } |
| 321 #endif | 322 #endif |
| 322 | 323 |
| 323 hb_face_t* HarfBuzzFace::createFace() | 324 hb_face_t* HarfBuzzFace::createFace() |
| 324 { | 325 { |
| 325 #if OS(MACOSX) | 326 #if OS(MACOSX) |
| 326 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); | 327 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); |
| 327 #else | 328 #else |
| 328 hb_face_t* face = nullptr; | 329 hb_face_t* face = nullptr; |
| 329 | 330 |
| 331 DEFINE_STATIC_LOCAL(BooleanHistogram, |
| 332 zeroCopySuccessHistogram, |
| 333 ("Blink.Fonts.HarfBuzzFaceZeroCopyAccess")); |
| 330 SkTypeface* typeface = m_platformData->typeface(); | 334 SkTypeface* typeface = m_platformData->typeface(); |
| 331 int ttcIndex = 0; | 335 int ttcIndex = 0; |
| 332 SkStreamAsset* typefaceStream = typeface->openStream(&ttcIndex); | 336 SkStreamAsset* typefaceStream = typeface->openStream(&ttcIndex); |
| 333 if (typefaceStream->getMemoryBase()) { | 337 if (typefaceStream->getMemoryBase()) { |
| 334 std::unique_ptr<hb_blob_t, void(*)(hb_blob_t*)> faceBlob(hb_blob_create( | 338 std::unique_ptr<hb_blob_t, void(*)(hb_blob_t*)> faceBlob(hb_blob_create( |
| 335 reinterpret_cast<const char*>(typefaceStream->getMemoryBase()), | 339 reinterpret_cast<const char*>(typefaceStream->getMemoryBase()), |
| 336 typefaceStream->getLength(), | 340 typefaceStream->getLength(), |
| 337 HB_MEMORY_MODE_READONLY, | 341 HB_MEMORY_MODE_READONLY, |
| 338 typefaceStream, | 342 typefaceStream, |
| 339 deleteTypefaceStream), | 343 deleteTypefaceStream), |
| 340 hb_blob_destroy); | 344 hb_blob_destroy); |
| 341 face = hb_face_create(faceBlob.get(), ttcIndex); | 345 face = hb_face_create(faceBlob.get(), ttcIndex); |
| 342 } | 346 } |
| 343 | 347 |
| 344 // Fallback to table copies if there is no in-memory access. | 348 // Fallback to table copies if there is no in-memory access. |
| 345 if (!face) | 349 if (!face) { |
| 346 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platformData->t
ypeface(), 0); | 350 face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platformData->t
ypeface(), 0); |
| 351 zeroCopySuccessHistogram.count(false); |
| 352 } else { |
| 353 zeroCopySuccessHistogram.count(true); |
| 354 } |
| 347 #endif | 355 #endif |
| 348 ASSERT(face); | 356 ASSERT(face); |
| 349 return face; | 357 return face; |
| 350 } | 358 } |
| 351 | 359 |
| 352 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) | 360 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) |
| 353 { | 361 { |
| 354 HbFontUniquePtr otFont(hb_font_create(face)); | 362 HbFontUniquePtr otFont(hb_font_create(face)); |
| 355 hb_ot_font_set_funcs(otFont.get()); | 363 hb_ot_font_set_funcs(otFont.get()); |
| 356 // Creating a sub font means that non-available functions | 364 // Creating a sub font means that non-available functions |
| 357 // are found from the parent. | 365 // are found from the parent. |
| 358 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); | 366 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); |
| 359 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont)
; | 367 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont)
; |
| 360 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo
ntData(), nullptr); | 368 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo
ntData(), nullptr); |
| 361 return cacheEntry; | 369 return cacheEntry; |
| 362 } | 370 } |
| 363 | 371 |
| 364 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con
st | 372 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con
st |
| 365 { | 373 { |
| 366 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 374 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
| 367 m_harfBuzzFontData->m_rangeSet = rangeSet; | 375 m_harfBuzzFontData->m_rangeSet = rangeSet; |
| 368 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF
ontPlatformData(m_platformData).get(); | 376 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF
ontPlatformData(m_platformData).get(); |
| 369 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 377 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
| 370 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 378 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
| 371 hb_font_set_scale(m_unscaledFont, scale, scale); | 379 hb_font_set_scale(m_unscaledFont, scale, scale); |
| 372 return m_unscaledFont; | 380 return m_unscaledFont; |
| 373 } | 381 } |
| 374 | 382 |
| 375 } // namespace blink | 383 } // namespace blink |
| OLD | NEW |