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

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

Issue 2026683003: Table blob leakage tracking Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Leak tracking per table tag 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 | « no previous file | 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalAdvance, 0, 0); 260 hb_font_funcs_set_glyph_h_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalAdvance, 0, 0);
261 hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalKerning, 0, 0); 261 hb_font_funcs_set_glyph_h_kerning_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphHorizontalKerning, 0, 0);
262 hb_font_funcs_set_glyph_v_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphVerticalAdvance, 0, 0); 262 hb_font_funcs_set_glyph_v_advance_func(harfBuzzSkiaFontFuncs, harfBuzzGe tGlyphVerticalAdvance, 0, 0);
263 hb_font_funcs_set_glyph_v_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet GlyphVerticalOrigin, 0, 0); 263 hb_font_funcs_set_glyph_v_origin_func(harfBuzzSkiaFontFuncs, harfBuzzGet GlyphVerticalOrigin, 0, 0);
264 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG lyphExtents, 0, 0); 264 hb_font_funcs_set_glyph_extents_func(harfBuzzSkiaFontFuncs, harfBuzzGetG lyphExtents, 0, 0);
265 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs); 265 hb_font_funcs_make_immutable(harfBuzzSkiaFontFuncs);
266 } 266 }
267 return harfBuzzSkiaFontFuncs; 267 return harfBuzzSkiaFontFuncs;
268 } 268 }
269 269
270
271 struct HbAllocMeta {
272 unsigned int tableSize;
273 hb_tag_t tableTag;
274 };
275
276 typedef HashMap<hb_tag_t, unsigned int, WTF::IntHash<hb_tag_t>, WTF::UnsignedWit hZeroKeyHashTraits<hb_tag_t>> TagTracking;
277
278 TagTracking* tagTracker() {
279 DEFINE_STATIC_LOCAL(TagTracking, s_TagTracking, ());
280 return &s_TagTracking;
281 }
282
283 void reportTagTracking() {
284 LOG(INFO) << "\n";
285 char tagBuf[4] = { 0 };
286 unsigned int totalLeftover = 0;
287 for (auto tagTrackIterator = tagTracker()->begin(); tagTrackIterator != tagT racker()->end(); ++tagTrackIterator) {
288 hb_tag_to_string(tagTrackIterator->key, tagBuf);
289 LOG(INFO) << "Tag: " << tagBuf << " leftover kb " << tagTrackIterator->v alue / 1024.0;
290 totalLeftover += tagTrackIterator->value;
291 }
292 LOG(INFO) << "---------------------";
293 LOG(INFO) << "Total: kb " << totalLeftover / 1024.0 << "\n";
294 }
295
296 void subtractFromTagTracking(hb_tag_t tag, unsigned size) {
297 auto findResult = tagTracker()->find(tag);
298 ASSERT(findResult != tagTracker()->end());
299 findResult->value -= size;
300 }
301
302 void tableBlobfastFree(void* p) {
303 if (p) {
304 HbAllocMeta* allocMeta = reinterpret_cast<HbAllocMeta*>(p);
305 subtractFromTagTracking(allocMeta->tableTag, allocMeta->tableSize);
306 }
307 WTF::Partitions::fastFree(p);
308 reportTagTracking();
309 }
310
311 void addToTagTracking(hb_tag_t tag, unsigned size) {
312 unsigned newSize = size;
313 auto tagTrackerFindResult = tagTracker()->find(tag);
314 if (tagTrackerFindResult != tagTracker()->end()) {
315 newSize += tagTrackerFindResult->value;
316 }
317 auto tagEntry = tagTracker()->set(tag, newSize);
318 }
319
270 #if !OS(MACOSX) 320 #if !OS(MACOSX)
271 static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user Data) 321 static hb_blob_t* harfBuzzSkiaGetTable(hb_face_t* face, hb_tag_t tag, void* user Data)
272 { 322 {
273 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(userData); 323 SkTypeface* typeface = reinterpret_cast<SkTypeface*>(userData);
274 324
275 const size_t tableSize = typeface->getTableSize(tag); 325 const size_t tableSize = typeface->getTableSize(tag);
276 if (!tableSize) { 326 if (!tableSize) {
277 return nullptr; 327 return nullptr;
278 } 328 }
279 329
280 char* buffer = reinterpret_cast<char*>(WTF::Partitions::fastMalloc(tableSize , WTF_HEAP_PROFILER_TYPE_NAME(HarfBuzzFontData))); 330 char* buffer = reinterpret_cast<char*>(WTF::Partitions::fastMalloc(tableSize + sizeof(HbAllocMeta), WTF_HEAP_PROFILER_TYPE_NAME(HarfBuzzFontData)));
281 if (!buffer) 331 if (!buffer)
282 return nullptr; 332 return nullptr;
283 size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer); 333 size_t actualSize = typeface->getTableData(tag, 0, tableSize, buffer + sizeo f(HbAllocMeta));
284 if (tableSize != actualSize) { 334 if (tableSize != actualSize) {
285 WTF::Partitions::fastFree(buffer); 335 WTF::Partitions::fastFree(buffer);
286 return nullptr; 336 return nullptr;
287 } 337 }
288 return hb_blob_create(const_cast<char*>(buffer), tableSize, HB_MEMORY_MODE_W RITABLE, buffer, WTF::Partitions::fastFree); 338
339 HbAllocMeta* allocMeta = reinterpret_cast<HbAllocMeta*>(buffer);
340 allocMeta->tableSize = tableSize;
341 allocMeta->tableTag = tag;
342 addToTagTracking(tag, tableSize);
343
344 hb_blob_t* returnBlob = hb_blob_create(const_cast<char*>(buffer + sizeof(Hb AllocMeta)), tableSize, HB_MEMORY_MODE_WRITABLE, buffer, tableBlobfastFree);
345 LOG(INFO) << "Blob memory allocated: " << tableSize << " bytes.";
346 ASSERT(hb_blob_get_length(returnBlob) == tableSize);
347 return returnBlob;
289 } 348 }
290 #endif 349 #endif
291 350
292 hb_face_t* HarfBuzzFace::createFace() 351 hb_face_t* HarfBuzzFace::createFace()
293 { 352 {
294 #if OS(MACOSX) 353 #if OS(MACOSX)
295 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont()); 354 hb_face_t* face = hb_coretext_face_create(m_platformData->cgFont());
296 #else 355 #else
297 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0); 356 hb_face_t* face = hb_face_create_for_tables(harfBuzzSkiaGetTable, m_platform Data->typeface(), 0);
298 #endif 357 #endif
(...skipping 18 matching lines...) Expand all
317 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint); 376 m_platformData->setupPaint(&m_harfBuzzFontData->m_paint);
318 m_harfBuzzFontData->m_rangeSet = rangeSet; 377 m_harfBuzzFontData->m_rangeSet = rangeSet;
319 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData); 378 m_harfBuzzFontData->m_simpleFontData = FontCache::fontCache()->fontDataFromF ontPlatformData(m_platformData);
320 ASSERT(m_harfBuzzFontData->m_simpleFontData); 379 ASSERT(m_harfBuzzFontData->m_simpleFontData);
321 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size()); 380 int scale = SkiaScalarToHarfBuzzPosition(m_platformData->size());
322 hb_font_set_scale(m_unscaledFont, scale, scale); 381 hb_font_set_scale(m_unscaledFont, scale, scale);
323 return m_unscaledFont; 382 return m_unscaledFont;
324 } 383 }
325 384
326 } // namespace blink 385 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698