reed@google.com | 8af0371 | 2013-06-11 19:18:44 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2013 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 "SkFontHost.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkString.h" |
| 13 | #include "SkTemplates.h" |
| 14 | |
| 15 | #include "glyphs.h" |
| 16 | |
| 17 | class FontCacheBench : public SkBenchmark { |
| 18 | enum { N = SkBENCHLOOP(800) }; |
| 19 | public: |
| 20 | FontCacheBench(void* param) : INHERITED(param) { |
| 21 | } |
| 22 | |
| 23 | protected: |
| 24 | virtual const char* onGetName() SK_OVERRIDE { |
| 25 | return "fontcache"; |
| 26 | } |
| 27 | |
| 28 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 29 | SkPaint paint; |
| 30 | this->setupPaint(&paint); |
| 31 | paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 32 | |
| 33 | for (int i = 0; i < N; ++i) { |
| 34 | const int16_t* array = gUniqueGlyphIDs; |
| 35 | while (*array >= 0) { |
| 36 | const int16_t* end = array + 1; |
| 37 | while (*end >= 0) { |
| 38 | end += 1; |
| 39 | } |
| 40 | paint.measureText(array, end - array); |
| 41 | array = end + 1; // skip the sentinel |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | private: |
| 47 | typedef SkBenchmark INHERITED; |
| 48 | }; |
| 49 | |
| 50 | /////////////////////////////////////////////////////////////////////////////// |
| 51 | |
| 52 | DEF_BENCH( return new FontCacheBench(p); ) |