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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 | 77 |
| 78 // struct to carry user-pointer data for hb_font_t callback functions. | 78 // struct to carry user-pointer data for hb_font_t callback functions. |
| 79 struct HarfBuzzFontData { | 79 struct HarfBuzzFontData { |
| 80 USING_FAST_MALLOC(HarfBuzzFontData); | 80 USING_FAST_MALLOC(HarfBuzzFontData); |
| 81 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData); | 81 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData); |
| 82 | 82 |
| 83 public: | 83 public: |
| 84 HarfBuzzFontData() | 84 HarfBuzzFontData() |
| 85 : m_paint(), m_simpleFontData(nullptr), m_rangeSet(nullptr) {} | 85 : m_paint(), m_simpleFontData(nullptr), m_rangeSet(nullptr) {} |
| 86 | 86 |
| 87 ~HarfBuzzFontData() { | |
| 88 if (m_simpleFontData) | |
| 89 FontCache::fontCache()->releaseFontData(m_simpleFontData); | |
| 90 } | |
| 91 | |
| 92 void updateSimpleFontData(FontPlatformData* platformData) { | |
| 93 SimpleFontData* simpleFontData = | |
| 94 FontCache::fontCache() | |
| 95 ->fontDataFromFontPlatformData(platformData) | |
| 96 .get(); | |
| 97 if (m_simpleFontData) | |
|
drott
2016/10/13 07:28:34
I think in the else case we need to release the ne
jb
2016/10/13 07:53:47
I think you misread the code. I always release the
drott
2016/10/13 08:06:29
True, sorry.
| |
| 98 FontCache::fontCache()->releaseFontData(m_simpleFontData); | |
| 99 m_simpleFontData = simpleFontData; | |
| 100 } | |
| 101 | |
| 87 SkPaint m_paint; | 102 SkPaint m_paint; |
| 88 SimpleFontData* m_simpleFontData; | 103 SimpleFontData* m_simpleFontData; |
| 89 RefPtr<UnicodeRangeSet> m_rangeSet; | 104 RefPtr<UnicodeRangeSet> m_rangeSet; |
| 90 }; | 105 }; |
| 91 | 106 |
| 92 // Though we have FontCache class, which provides the cache mechanism for | 107 // Though we have FontCache class, which provides the cache mechanism for |
| 93 // 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 |
| 94 // 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 |
| 95 // 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 |
| 96 // need one for each unique SkTypeface. | 111 // need one for each unique SkTypeface. |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), | 378 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), |
| 364 cacheEntry->hbFontData(), nullptr); | 379 cacheEntry->hbFontData(), nullptr); |
| 365 return cacheEntry; | 380 return cacheEntry; |
| 366 } | 381 } |
| 367 | 382 |
| 368 hb_font_t* HarfBuzzFace::getScaledFont( | 383 hb_font_t* HarfBuzzFace::getScaledFont( |
| 369 PassRefPtr<UnicodeRangeSet> rangeSet) const { | 384 PassRefPtr<UnicodeRangeSet> rangeSet) const { |
| 370 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); | 385 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); |
| 371 m_harfBuzzFontData->m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 386 m_harfBuzzFontData->m_paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 372 m_harfBuzzFontData->m_rangeSet = rangeSet; | 387 m_harfBuzzFontData->m_rangeSet = rangeSet; |
| 373 m_harfBuzzFontData->m_simpleFontData = | 388 m_harfBuzzFontData->updateSimpleFontData(m_platformData); |
| 374 FontCache::fontCache() | |
| 375 ->fontDataFromFontPlatformData(m_platformData) | |
| 376 .get(); | |
| 377 ASSERT(m_harfBuzzFontData->m_simpleFontData); | 389 ASSERT(m_harfBuzzFontData->m_simpleFontData); |
| 378 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); | 390 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); |
| 379 hb_font_set_scale(m_unscaledFont, scale, scale); | 391 hb_font_set_scale(m_unscaledFont, scale, scale); |
| 380 return m_unscaledFont; | 392 return m_unscaledFont; |
| 381 } | 393 } |
| 382 | 394 |
| 383 } // namespace blink | 395 } // namespace blink |
| OLD | NEW |