Chromium Code Reviews| Index: bench/SkGlyphCacheBench.cpp |
| diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8172b05ac82f5de39f27c68b286fbc5dbf69aa1f |
| --- /dev/null |
| +++ b/bench/SkGlyphCacheBench.cpp |
| @@ -0,0 +1,82 @@ |
| +/* |
| + * Copyright 2015 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| + |
| +#include "SkGlyphCache.h" |
| + |
| +#include "Benchmark.h" |
| +#include "SkCanvas.h" |
| +#include "SkGlyphCache_Globals.h" |
| +#include "SkGraphics.h" |
| +#include "SkTaskGroup.h" |
| +#include "SkTypeface.h" |
| +#include "sk_tool_utils.h" |
| + |
| + |
| +class SkGlyphCacheBasic : public Benchmark { |
| + const char* onGetName() override { |
| + return "SkGlyphCacheBasic"; |
| + } |
| + void onDraw(const int loops, SkCanvas* canvas) override { |
| + SkGraphics::SetFontCacheLimit(256 * 1024); |
| + SkTypeface* typeface = sk_tool_utils::create_portable_typeface("serif", |
| + SkTypeface::kItalic); |
| + SkPaint paint; |
| + paint.setAntiAlias(true); |
| + paint.setSubpixelText(true); |
| + paint.setTypeface(typeface); |
| + |
| + for (int work = 0; work < loops; work++) { |
| + for (int i = 8; i < 128; i++) { |
| + paint.setTextSize(i); |
| + SkAutoGlyphCacheNoGamma autoCache(paint, nullptr, nullptr); |
| + SkGlyphCache* cache = autoCache.getCache(); |
| + uint16_t glyphId = cache->unicharToGlyph('e'); |
| + const SkGlyph& g = cache->getGlyphIDMetrics(glyphId); |
| + cache->findImage(g); |
| + } |
| + } |
| + } |
| +private: |
| + typedef Benchmark INHERITED; |
| +}; |
| + |
| +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.
|
| + const char* onGetName() override { |
| + return "SkGlyphCacheStressTest"; |
| + } |
| + void onDraw(const int loops, SkCanvas* canvas) override { |
| + 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.
|
| + SkTypeface* typefaces[] = |
| + {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic), |
| + sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic)}; |
| + |
| + for (int work = 0; work < loops; work++) { |
| + sk_parallel_for(16, [&](int threadIndex) { |
| + SkPaint paint; |
| + paint.setAntiAlias(true); |
| + paint.setSubpixelText(true); |
| + paint.setTypeface(typefaces[threadIndex % 2]); |
| + for (int size = 8; size < 128; size++) { |
| + paint.setTextSize(size); |
| + SkAutoGlyphCacheNoGamma autoCache(paint, nullptr, nullptr); |
| + SkGlyphCache* cache = autoCache.getCache(); |
| + for (int c = ' '; c < 'z'; c++) { |
| + uint16_t glyphId = cache->unicharToGlyph(c); |
| + const SkGlyph& g = cache->getGlyphIDMetrics(glyphId); |
| + cache->findImage(g); |
| + } |
| + } |
| + }); |
| + } |
| + } |
| +private: |
| + typedef Benchmark INHERITED; |
| +}; |
| + |
| +DEF_BENCH(return new SkGlyphCacheBasic; ) |
| +DEF_BENCH(return new SkGlyphCacheStressTest; ) |