Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 | |
| 9 #include "SkGlyphCache.h" | |
| 10 | |
| 11 #include "Benchmark.h" | |
| 12 #include "SkCanvas.h" | |
| 13 #include "SkGlyphCache_Globals.h" | |
| 14 #include "SkGraphics.h" | |
| 15 #include "SkTaskGroup.h" | |
| 16 #include "SkTypeface.h" | |
| 17 #include "sk_tool_utils.h" | |
| 18 | |
| 19 | |
| 20 class SkGlyphCacheBasic : public Benchmark { | |
| 21 const char* onGetName() override { | |
| 22 return "SkGlyphCacheBasic"; | |
| 23 } | |
| 24 void onDraw(const int loops, SkCanvas* canvas) override { | |
| 25 SkGraphics::SetFontCacheLimit(256 * 1024); | |
| 26 SkTypeface* typeface = sk_tool_utils::create_portable_typeface("serif", | |
| 27 SkTypefac e::kItalic); | |
| 28 SkPaint paint; | |
| 29 paint.setAntiAlias(true); | |
| 30 paint.setSubpixelText(true); | |
| 31 paint.setTypeface(typeface); | |
| 32 | |
| 33 for (int work = 0; work < loops; work++) { | |
| 34 for (int i = 8; i < 128; i++) { | |
| 35 paint.setTextSize(i); | |
| 36 SkAutoGlyphCacheNoGamma autoCache(paint, nullptr, nullptr); | |
| 37 SkGlyphCache* cache = autoCache.getCache(); | |
| 38 uint16_t glyphId = cache->unicharToGlyph('e'); | |
| 39 const SkGlyph& g = cache->getGlyphIDMetrics(glyphId); | |
| 40 cache->findImage(g); | |
| 41 } | |
| 42 } | |
| 43 } | |
| 44 private: | |
| 45 typedef Benchmark INHERITED; | |
| 46 }; | |
| 47 | |
| 48 class SkGlyphCacheStressTest : public Benchmark { | |
|
mtklein
2015/09/16 22:33:51
For non-rendering benchmarks like these, typically
herb_g
2015/09/17 15:33:19
Done.
| |
| 49 const char* onGetName() override { | |
| 50 return "SkGlyphCacheStressTest"; | |
| 51 } | |
| 52 void onDraw(const int loops, SkCanvas* canvas) override { | |
| 53 SkGraphics::SetFontCacheLimit(256 * 1024); | |
|
mtklein
2015/09/16 22:33:51
Might be nice to set this back to whatever it star
herb_g
2015/09/17 15:33:19
Done.
| |
| 54 SkTypeface* typefaces[] = | |
| 55 {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItali c), | |
| 56 sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::k Italic)}; | |
| 57 | |
| 58 for (int work = 0; work < loops; work++) { | |
| 59 sk_parallel_for(16, [&](int threadIndex) { | |
| 60 SkPaint paint; | |
| 61 paint.setAntiAlias(true); | |
| 62 paint.setSubpixelText(true); | |
| 63 paint.setTypeface(typefaces[threadIndex % 2]); | |
| 64 for (int size = 8; size < 128; size++) { | |
| 65 paint.setTextSize(size); | |
| 66 SkAutoGlyphCacheNoGamma autoCache(paint, nullptr, nullptr); | |
| 67 SkGlyphCache* cache = autoCache.getCache(); | |
| 68 for (int c = ' '; c < 'z'; c++) { | |
| 69 uint16_t glyphId = cache->unicharToGlyph(c); | |
| 70 const SkGlyph& g = cache->getGlyphIDMetrics(glyphId); | |
| 71 cache->findImage(g); | |
| 72 } | |
| 73 } | |
| 74 }); | |
| 75 } | |
| 76 } | |
| 77 private: | |
| 78 typedef Benchmark INHERITED; | |
| 79 }; | |
| 80 | |
| 81 DEF_BENCH(return new SkGlyphCacheBasic; ) | |
| 82 DEF_BENCH(return new SkGlyphCacheStressTest; ) | |
| OLD | NEW |