Chromium Code Reviews| Index: bench/FontScalerBench.cpp |
| diff --git a/bench/FontScalerBench.cpp b/bench/FontScalerBench.cpp |
| index 6ef0703346ea9521d116569ffd992e649e0d8409..5d6f01aef15ff6063be0d95e419d66f525d372f0 100644 |
| --- a/bench/FontScalerBench.cpp |
| +++ b/bench/FontScalerBench.cpp |
| @@ -11,17 +11,44 @@ |
| #include "SkPaint.h" |
| #include "SkRandom.h" |
| #include "SkString.h" |
| +#include "SkTypeface.h" |
| extern bool gSkSuppressFontCachePurgeSpew; |
| +static const struct { |
| + const char* fStyleString; |
| + SkTypeface::Style fStyle; |
| +} gStyleNames [] = { |
| + { "normal", SkTypeface::kNormal }, |
| + { "bold", SkTypeface::kBold }, |
| + { "italic", SkTypeface::kItalic }, |
| + { "bolditalic", SkTypeface::kBoldItalic }, |
| +}; |
| + |
| class FontScalerBench : public SkBenchmark { |
| - SkString fName; |
| - SkString fText; |
| - bool fDoLCD; |
| + SkString fName; |
| + SkString fText; |
| + SkTypeface::Style fStyle; |
| + bool fDoLCD; |
| public: |
| - FontScalerBench(bool doLCD) { |
| - fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa"); |
| + FontScalerBench(SkTypeface::Style style, bool doLCD) { |
| + const char* styleString; |
| + |
| + styleString = gStyleNames[0].fStyleString; |
| + fStyle = gStyleNames[0].fStyle; |
| + |
| + for (unsigned int i = 0; |
| + i < sizeof(gStyleNames) / sizeof(gStyleNames[0]); i++) { |
| + if (gStyleNames[i].fStyle == style) { |
| + styleString = gStyleNames[i].fStyleString; |
| + fStyle = style; |
| + break; |
| + } |
| + } |
| + |
| + fName.printf("fontscaler_%s_%s", styleString, doLCD ? "lcd" : "aa"); |
| fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); |
| + |
| fDoLCD = doLCD; |
| } |
| @@ -30,6 +57,9 @@ protected: |
| virtual void onDraw(const int loops, SkCanvas* canvas) { |
| SkPaint paint; |
| this->setupPaint(&paint); |
| + |
| + SkTypeface* face = SkTypeface::CreateFromName(NULL, fStyle); |
|
bungeman-skia
2013/12/16 16:33:36
SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFr
zheng.xu
2013/12/17 10:02:51
Thanks for the hint. This is quite convenient.
|
| + paint.setTypeface(face); |
| paint.setLCDRenderText(fDoLCD); |
| bool prev = gSkSuppressFontCachePurgeSpew; |
| @@ -40,14 +70,16 @@ protected: |
| // explicitly flush our cache before each run |
| SkGraphics::PurgeFontCache(); |
| - for (int ps = 9; ps <= 24; ps += 2) { |
| + for (int y = 20, ps = 9; ps <= 24; y += ps, ps += 2) { |
| paint.setTextSize(SkIntToScalar(ps)); |
| canvas->drawText(fText.c_str(), fText.size(), |
| - 0, SkIntToScalar(20), paint); |
| + 0, SkIntToScalar(y), paint); |
| } |
| } |
| gSkSuppressFontCachePurgeSpew = prev; |
| + |
| + SkSafeUnref(face); |
| } |
| private: |
| typedef SkBenchmark INHERITED; |
| @@ -55,5 +87,11 @@ private: |
| /////////////////////////////////////////////////////////////////////////////// |
| -DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (false)); ) |
| -DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (true)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kNormal, false)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBold, false)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kItalic, false)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBoldItalic, false)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kNormal, true)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBold, true)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kItalic, true)); ) |
| +DEF_BENCH( return SkNEW_ARGS(FontScalerBench, (SkTypeface::kBoldItalic, true)); ) |