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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "Benchmark.h" |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
| 10 | #include "SkGraphics.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRandom.h" |
| 13 | #include "SkString.h" |
| 14 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 15 | class FontScalerBench : public Benchmark { |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 16 | SkString fName; |
| 17 | SkString fText; |
reed@google.com | 8e372c9 | 2011-11-03 13:45:38 +0000 | [diff] [blame] | 18 | bool fDoLCD; |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 19 | public: |
mtklein@google.com | 410e6e8 | 2013-09-13 19:52:27 +0000 | [diff] [blame] | 20 | FontScalerBench(bool doLCD) { |
reed@google.com | 8e372c9 | 2011-11-03 13:45:38 +0000 | [diff] [blame] | 21 | fName.printf("fontscaler_%s", doLCD ? "lcd" : "aa"); |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 22 | fText.set("abcdefghijklmnopqrstuvwxyz01234567890"); |
reed@google.com | 8e372c9 | 2011-11-03 13:45:38 +0000 | [diff] [blame] | 23 | fDoLCD = doLCD; |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | protected: |
| 27 | virtual const char* onGetName() { return fName.c_str(); } |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 28 | virtual void onDraw(int loops, SkCanvas* canvas) { |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 29 | SkPaint paint; |
| 30 | this->setupPaint(&paint); |
reed@google.com | 8e372c9 | 2011-11-03 13:45:38 +0000 | [diff] [blame] | 31 | paint.setLCDRenderText(fDoLCD); |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 32 | |
commit-bot@chromium.org | 3361471 | 2013-12-03 18:17:16 +0000 | [diff] [blame] | 33 | for (int i = 0; i < loops; i++) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 34 | // this is critical - we want to time the creation process, so we |
| 35 | // explicitly flush our cache before each run |
| 36 | SkGraphics::PurgeFontCache(); |
reed@google.com | 073c907 | 2011-11-08 20:03:48 +0000 | [diff] [blame] | 37 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 38 | for (int ps = 9; ps <= 24; ps += 2) { |
| 39 | paint.setTextSize(SkIntToScalar(ps)); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 40 | canvas->drawString(fText, |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 41 | 0, SkIntToScalar(20), paint); |
| 42 | } |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 43 | } |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 44 | } |
| 45 | private: |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 46 | typedef Benchmark INHERITED; |
reed@google.com | 6e5a45c | 2011-11-02 21:02:57 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /////////////////////////////////////////////////////////////////////////////// |
| 50 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 51 | DEF_BENCH(return new FontScalerBench(false);) |
| 52 | DEF_BENCH(return new FontScalerBench(true);) |