| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBenchmark.h" | 8 #include "Benchmark.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkFontHost.h" | 10 #include "SkFontHost.h" |
| 11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
| 12 #include "SkString.h" | 12 #include "SkString.h" |
| 13 #include "SkTemplates.h" | 13 #include "SkTemplates.h" |
| 14 | 14 |
| 15 #include "gUniqueGlyphIDs.h" | 15 #include "gUniqueGlyphIDs.h" |
| 16 #define gUniqueGlyphIDs_Sentinel 0xFFFF | 16 #define gUniqueGlyphIDs_Sentinel 0xFFFF |
| 17 | 17 |
| 18 static int count_glyphs(const uint16_t start[]) { | 18 static int count_glyphs(const uint16_t start[]) { |
| 19 const uint16_t* curr = start; | 19 const uint16_t* curr = start; |
| 20 while (*curr != gUniqueGlyphIDs_Sentinel) { | 20 while (*curr != gUniqueGlyphIDs_Sentinel) { |
| 21 curr += 1; | 21 curr += 1; |
| 22 } | 22 } |
| 23 return static_cast<int>(curr - start); | 23 return static_cast<int>(curr - start); |
| 24 } | 24 } |
| 25 | 25 |
| 26 class FontCacheBench : public SkBenchmark { | 26 class FontCacheBench : public Benchmark { |
| 27 public: | 27 public: |
| 28 FontCacheBench() {} | 28 FontCacheBench() {} |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 virtual const char* onGetName() SK_OVERRIDE { | 31 virtual const char* onGetName() SK_OVERRIDE { |
| 32 return "fontcache"; | 32 return "fontcache"; |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { | 35 virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 36 SkPaint paint; | 36 SkPaint paint; |
| 37 this->setupPaint(&paint); | 37 this->setupPaint(&paint); |
| 38 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 38 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 39 | 39 |
| 40 const uint16_t* array = gUniqueGlyphIDs; | 40 const uint16_t* array = gUniqueGlyphIDs; |
| 41 while (*array != gUniqueGlyphIDs_Sentinel) { | 41 while (*array != gUniqueGlyphIDs_Sentinel) { |
| 42 int count = count_glyphs(array); | 42 int count = count_glyphs(array); |
| 43 for (int i = 0; i < loops; ++i) { | 43 for (int i = 0; i < loops; ++i) { |
| 44 paint.measureText(array, count * sizeof(uint16_t)); | 44 paint.measureText(array, count * sizeof(uint16_t)); |
| 45 } | 45 } |
| 46 array += count + 1; // skip the sentinel | 46 array += count + 1; // skip the sentinel |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 typedef SkBenchmark INHERITED; | 51 typedef Benchmark INHERITED; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
| 55 | 55 |
| 56 static uint32_t rotr(uint32_t value, unsigned bits) { | 56 static uint32_t rotr(uint32_t value, unsigned bits) { |
| 57 return (value >> bits) | (value << (32 - bits)); | 57 return (value >> bits) | (value << (32 - bits)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 typedef uint32_t (*HasherProc)(uint32_t); | 60 typedef uint32_t (*HasherProc)(uint32_t); |
| 61 | 61 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return collisions; | 100 return collisions; |
| 101 } | 101 } |
| 102 | 102 |
| 103 static void dump_array(const uint16_t array[], int count) { | 103 static void dump_array(const uint16_t array[], int count) { |
| 104 for (int i = 0; i < count; ++i) { | 104 for (int i = 0; i < count; ++i) { |
| 105 SkDebugf(" %d,", array[i]); | 105 SkDebugf(" %d,", array[i]); |
| 106 } | 106 } |
| 107 SkDebugf("\n"); | 107 SkDebugf("\n"); |
| 108 } | 108 } |
| 109 | 109 |
| 110 class FontCacheEfficiency : public SkBenchmark { | 110 class FontCacheEfficiency : public Benchmark { |
| 111 public: | 111 public: |
| 112 FontCacheEfficiency() { | 112 FontCacheEfficiency() { |
| 113 if (false) dump_array(NULL, 0); | 113 if (false) dump_array(NULL, 0); |
| 114 if (false) rotr(0, 0); | 114 if (false) rotr(0, 0); |
| 115 } | 115 } |
| 116 | 116 |
| 117 protected: | 117 protected: |
| 118 virtual const char* onGetName() SK_OVERRIDE { | 118 virtual const char* onGetName() SK_OVERRIDE { |
| 119 return "fontefficiency"; | 119 return "fontefficiency"; |
| 120 } | 120 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 140 array += count + 1; // skip the sentinel | 140 array += count + 1; // skip the sentinel |
| 141 } | 141 } |
| 142 SkDebugf("hashBits [%d] limit [%d] collisions [%d / %d = %1.
2g%%] using %s\n", hashBits, limit, collisions, glyphs, | 142 SkDebugf("hashBits [%d] limit [%d] collisions [%d / %d = %1.
2g%%] using %s\n", hashBits, limit, collisions, glyphs, |
| 143 collisions * 100.0 / glyphs, gRec[i].fName); | 143 collisions * 100.0 / glyphs, gRec[i].fName); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 typedef SkBenchmark INHERITED; | 150 typedef Benchmark INHERITED; |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 /////////////////////////////////////////////////////////////////////////////// | 153 /////////////////////////////////////////////////////////////////////////////// |
| 154 | 154 |
| 155 DEF_BENCH( return new FontCacheBench(); ) | 155 DEF_BENCH( return new FontCacheBench(); ) |
| 156 | 156 |
| 157 // undefine this to run the efficiency test | 157 // undefine this to run the efficiency test |
| 158 //DEF_BENCH( return new FontCacheEfficiency(); ) | 158 //DEF_BENCH( return new FontCacheEfficiency(); ) |
| OLD | NEW |