OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 glyphs.append(paint.textToGlyphs(text, len, nullptr)); | 37 glyphs.append(paint.textToGlyphs(text, len, nullptr)); |
38 paint.textToGlyphs(text, len, glyphs.begin()); | 38 paint.textToGlyphs(text, len, glyphs.begin()); |
39 | 39 |
40 SkTextBlobBuilder builder; | 40 SkTextBlobBuilder builder; |
41 | 41 |
42 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 42 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
43 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs
.count(), 10, 10, | 43 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs
.count(), 10, 10, |
44 nullptr); | 44 nullptr); |
45 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); | 45 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); |
46 | 46 |
47 fBlob.reset(builder.build()); | 47 fBlob = builder.make(); |
48 } | 48 } |
49 | 49 |
50 const char* onGetName() override { | 50 const char* onGetName() override { |
51 return "TextBlobBench"; | 51 return "TextBlobBench"; |
52 } | 52 } |
53 | 53 |
54 void onDraw(int loops, SkCanvas* canvas) override { | 54 void onDraw(int loops, SkCanvas* canvas) override { |
55 SkPaint paint; | 55 SkPaint paint; |
56 | 56 |
57 // To ensure maximum caching, we just redraw the blob at the same place
everytime | 57 // To ensure maximum caching, we just redraw the blob at the same place
everytime |
58 for (int i = 0; i < loops; i++) { | 58 for (int i = 0; i < loops; i++) { |
59 canvas->drawTextBlob(fBlob, 0, 0, paint); | 59 canvas->drawTextBlob(fBlob, 0, 0, paint); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 private: | 63 private: |
64 | 64 |
65 SkAutoTUnref<const SkTextBlob> fBlob; | 65 sk_sp<SkTextBlob> fBlob; |
66 SkTDArray<uint16_t> fGlyphs; | 66 SkTDArray<uint16_t> fGlyphs; |
67 sk_sp<SkTypeface> fTypeface; | 67 sk_sp<SkTypeface> fTypeface; |
68 | 68 |
69 typedef Benchmark INHERITED; | 69 typedef Benchmark INHERITED; |
70 }; | 70 }; |
71 | 71 |
72 DEF_BENCH( return new TextBlobBench(); ) | 72 DEF_BENCH( return new TextBlobBench(); ) |
OLD | NEW |