Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.cpp

Issue 2043613002: Remove the use of OwnedPtrDeleter in HarfBuzzFace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 #include <SkPaint.h> 47 #include <SkPaint.h>
48 #include <SkPath.h> 48 #include <SkPath.h>
49 #include <SkPoint.h> 49 #include <SkPoint.h>
50 #include <SkRect.h> 50 #include <SkRect.h>
51 #include <SkTypeface.h> 51 #include <SkTypeface.h>
52 52
53 53
54 namespace blink { 54 namespace blink {
55 55
56 struct HbFontDeleter {
57 void operator()(hb_font_t* font)
58 {
59 if (font)
60 hb_font_destroy(font);
61 }
62 };
63
64 using HbFontUniquePtr = std::unique_ptr<hb_font_t, HbFontDeleter>;
65
66 struct HbFaceDeleter {
67 void operator()(hb_face_t* face)
68 {
69 if (face)
70 hb_face_destroy(face);
71 }
72 };
73
74 using HbFaceUniquePtr = std::unique_ptr<hb_face_t, HbFaceDeleter>;
75
56 // struct to carry user-pointer data for hb_font_t callback functions. 76 // struct to carry user-pointer data for hb_font_t callback functions.
57 struct HarfBuzzFontData { 77 struct HarfBuzzFontData {
58 USING_FAST_MALLOC(HarfBuzzFontData); 78 USING_FAST_MALLOC(HarfBuzzFontData);
59 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData); 79 WTF_MAKE_NONCOPYABLE(HarfBuzzFontData);
60 public: 80 public:
61 81
62 HarfBuzzFontData() 82 HarfBuzzFontData()
63 : m_paint() 83 : m_paint()
64 , m_simpleFontData(nullptr) 84 , m_simpleFontData(nullptr)
65 , m_rangeSet(nullptr) 85 , m_rangeSet(nullptr)
(...skipping 18 matching lines...) Expand all
84 { 104 {
85 ASSERT(hbFont); 105 ASSERT(hbFont);
86 return adoptRef(new HbFontCacheEntry(hbFont)); 106 return adoptRef(new HbFontCacheEntry(hbFont));
87 } 107 }
88 108
89 hb_font_t* hbFont() { return m_hbFont.get(); } 109 hb_font_t* hbFont() { return m_hbFont.get(); }
90 HarfBuzzFontData* hbFontData() { return m_hbFontData.get(); } 110 HarfBuzzFontData* hbFontData() { return m_hbFontData.get(); }
91 111
92 private: 112 private:
93 explicit HbFontCacheEntry(hb_font_t* font) 113 explicit HbFontCacheEntry(hb_font_t* font)
94 : m_hbFont(adoptPtr(font)) 114 : m_hbFont(HbFontUniquePtr(font))
95 , m_hbFontData(adoptPtr(new HarfBuzzFontData())) 115 , m_hbFontData(adoptPtr(new HarfBuzzFontData()))
96 { }; 116 { };
97 117
98 OwnPtr<hb_font_t> m_hbFont; 118 HbFontUniquePtr m_hbFont;
99 OwnPtr<HarfBuzzFontData> m_hbFontData; 119 OwnPtr<HarfBuzzFontData> m_hbFontData;
100 }; 120 };
101 121
102 typedef HashMap<uint64_t, RefPtr<HbFontCacheEntry>, WTF::IntHash<uint64_t>, WTF: :UnsignedWithZeroKeyHashTraits<uint64_t>> HarfBuzzFontCache; 122 typedef HashMap<uint64_t, RefPtr<HbFontCacheEntry>, WTF::IntHash<uint64_t>, WTF: :UnsignedWithZeroKeyHashTraits<uint64_t>> HarfBuzzFontCache;
103 123
104 static HarfBuzzFontCache* harfBuzzFontCache() 124 static HarfBuzzFontCache* harfBuzzFontCache()
105 { 125 {
106 DEFINE_STATIC_LOCAL(HarfBuzzFontCache, s_harfBuzzFontCache, ()); 126 DEFINE_STATIC_LOCAL(HarfBuzzFontCache, s_harfBuzzFontCache, ());
107 return &s_harfBuzzFontCache; 127 return &s_harfBuzzFontCache;
108 } 128 }
109 129
110 static PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t*); 130 static PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t*);
111 131
112 HarfBuzzFace::HarfBuzzFace(FontPlatformData* platformData, uint64_t uniqueID) 132 HarfBuzzFace::HarfBuzzFace(FontPlatformData* platformData, uint64_t uniqueID)
113 : m_platformData(platformData) 133 : m_platformData(platformData)
114 , m_uniqueID(uniqueID) 134 , m_uniqueID(uniqueID)
115 { 135 {
116 HarfBuzzFontCache::AddResult result = harfBuzzFontCache()->add(m_uniqueID, n ullptr); 136 HarfBuzzFontCache::AddResult result = harfBuzzFontCache()->add(m_uniqueID, n ullptr);
117 if (result.isNewEntry) { 137 if (result.isNewEntry) {
118 OwnPtr<hb_face_t> face = adoptPtr(createFace()); 138 HbFaceUniquePtr face(createFace());
119 result.storedValue->value = createHbFontCacheEntry(face.get()); 139 result.storedValue->value = createHbFontCacheEntry(face.get());
120 } 140 }
121 result.storedValue->value->ref(); 141 result.storedValue->value->ref();
122 m_unscaledFont = result.storedValue->value->hbFont(); 142 m_unscaledFont = result.storedValue->value->hbFont();
123 m_harfBuzzFontData = result.storedValue->value->hbFontData(); 143 m_harfBuzzFontData = result.storedValue->value->hbFontData();
124 } 144 }
125 145
126 HarfBuzzFace::~HarfBuzzFace() 146 HarfBuzzFace::~HarfBuzzFace()
127 { 147 {
128 HarfBuzzFontCache::iterator result = harfBuzzFontCache()->find(m_uniqueID); 148 HarfBuzzFontCache::iterator result = harfBuzzFontCache()->find(m_uniqueID);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); 315 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
296 #else 316 #else
297 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0); 317 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0);
298 #endif 318 #endif
299 ASSERT(face); 319 ASSERT(face);
300 return face; 320 return face;
301 } 321 }
302 322
303 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face) 323 PassRefPtr<HbFontCacheEntry> createHbFontCacheEntry(hb_face_t* face)
304 { 324 {
305 OwnPtr<hb_font_t> otFont = adoptPtr(hb_font_create(face)); 325 HbFontUniquePtr otFont(hb_font_create(face));
306 hb_ot_font_set_funcs(otFont.get()); 326 hb_ot_font_set_funcs(otFont.get());
307 // Creating a sub font means that non-available functions 327 // Creating a sub font means that non-available functions
308 // are found from the parent. 328 // are found from the parent.
309 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get()); 329 hb_font_t* unscaledFont = hb_font_create_sub_font(otFont.get());
310 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ; 330 RefPtr<HbFontCacheEntry> cacheEntry = HbFontCacheEntry::create(unscaledFont) ;
311 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr); 331 hb_font_set_funcs(unscaledFont, harfBuzzSkiaGetFontFuncs(), cacheEntry->hbFo ntData(), nullptr);
312 return cacheEntry; 332 return cacheEntry;
313 } 333 }
314 334
315 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st 335 hb_font_t* HarfBuzzFace::getScaledFont(PassRefPtr<UnicodeRangeSet> rangeSet) con st
316 { 336 {
317 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); 337 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint);
318 m_harfBuzzFontData->m_rangeSet = rangeSet; 338 m_harfBuzzFontData->m_rangeSet = rangeSet;
319 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData); 339 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData);
320 ASSERT(m_harfBuzzFontData->m_simpleFontData); 340 ASSERT(m_harfBuzzFontData->m_simpleFontData);
321 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); 341 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size());
322 hb_font_set_scale(m_unscaledFont, scale, scale); 342 hb_font_set_scale(m_unscaledFont, scale, scale);
323 return m_unscaledFont; 343 return m_unscaledFont;
324 } 344 }
325 345
326 } // namespace blink 346 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzFace.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698