reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2011 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 | #include "SkBenchmark.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkGraphics.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
| 13 | #include "SkString.h" |
| 14 | |
| 15 | extern bool gSkSuppressFontCachePurgeSpew; |
| 16 | |
| 17 | class FontScalerBench : public SkBenchmark { |
| 18 | SkString fName; |
| 19 | SkString fText; |
| 20 | public: |
| 21 | FontScalerBench(void* param) : INHERITED(param) { |
| 22 | fName.set("fontscaler"); |
| 23 | fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); |
| 24 | } |
| 25 | |
| 26 | protected: |
| 27 | virtual const char* onGetName() { return fName.c_str(); } |
| 28 | virtual void onDraw(SkCanvas* canvas) { |
| 29 | SkPaint paint; |
| 30 | this->setupPaint(&paint); |
| 31 | |
| 32 | bool prev = gSkSuppressFontCachePurgeSpew; |
| 33 | gSkSuppressFontCachePurgeSpew = true; |
| 34 | |
| 35 | // this is critical - we want to time the creation process, so we |
| 36 | // explicitly flush our cache before each run |
| 37 | SkGraphics::SetFontCacheUsed(0); |
| 38 | for (int ps = 9; ps <= 24; ps += 2) { |
| 39 | paint.setTextSize(SkIntToScalar(ps)); |
| 40 | canvas->drawText(fText.c_str(), fText.size(), |
| 41 | 0, SkIntToScalar(20), paint); |
| 42 | } |
| 43 | |
| 44 | gSkSuppressFontCachePurgeSpew = prev; |
| 45 | } |
| 46 | private: |
| 47 | typedef SkBenchmark INHERITED; |
| 48 | }; |
| 49 | |
| 50 | /////////////////////////////////////////////////////////////////////////////// |
| 51 | |
| 52 | static SkBenchmark* Fact(void* p) { return SkNEW_ARGS(FontScalerBench, (p)); } |
| 53 | |
| 54 | static BenchRegistry gReg(Fact); |