Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: bench/TextBlobBench.cpp

Issue 1144023002: Move font loading in gm tests and benches out of constructors (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "Benchmark.h" 9 #include "Benchmark.h"
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkRandom.h" 13 #include "SkRandom.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 #include "SkTemplates.h" 16 #include "SkTemplates.h"
17 #include "SkTextBlob.h" 17 #include "SkTextBlob.h"
18 #include "SkTypeface.h" 18 #include "SkTypeface.h"
19 19
20 #include "sk_tool_utils.h" 20 #include "sk_tool_utils.h"
21 21
22 /* 22 /*
23 * A trivial test which benchmarks the performance of a textblob with a single r un. 23 * A trivial test which benchmarks the performance of a textblob with a single r un.
24 */ 24 */
25 class TextBlobBench : public Benchmark { 25 class TextBlobBench : public Benchmark {
26 public: 26 public:
27 TextBlobBench() 27 TextBlobBench()
28 : fTypeface(sk_tool_utils::create_portable_typeface("Times", SkTypeface: :kNormal)) { 28 : fTypeface(NULL) {
29 }
30
31 protected:
32 void onPreDraw() override {
33 fTypeface.reset(sk_tool_utils::create_portable_typeface("Times", SkTypef ace::kNormal));
29 // make textblob 34 // make textblob
30 SkPaint paint; 35 SkPaint paint;
31 paint.setTypeface(fTypeface); 36 paint.setTypeface(fTypeface);
32 const char* text = "Hello blob!"; 37 const char* text = "Hello blob!";
33 SkTDArray<uint16_t> glyphs; 38 SkTDArray<uint16_t> glyphs;
34 size_t len = strlen(text); 39 size_t len = strlen(text);
35 glyphs.append(paint.textToGlyphs(text, len, NULL)); 40 glyphs.append(paint.textToGlyphs(text, len, NULL));
36 paint.textToGlyphs(text, len, glyphs.begin()); 41 paint.textToGlyphs(text, len, glyphs.begin());
37 42
38 SkTextBlobBuilder builder; 43 SkTextBlobBuilder builder;
39 44
40 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 45 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
41 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs .count(), 10, 10, 46 const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(paint, glyphs .count(), 10, 10,
42 NULL); 47 NULL);
43 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t)); 48 memcpy(run.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
44 49
45 fBlob.reset(builder.build()); 50 fBlob.reset(builder.build());
46 } 51 }
47 52
48 protected:
49 const char* onGetName() { 53 const char* onGetName() {
50 return "TextBlobBench"; 54 return "TextBlobBench";
51 } 55 }
52 56
53 void onDraw(const int loops, SkCanvas* canvas) { 57 void onDraw(const int loops, SkCanvas* canvas) {
54 SkPaint paint; 58 SkPaint paint;
55 59
56 // To ensure maximum caching, we just redraw the blob at the same place everytime 60 // To ensure maximum caching, we just redraw the blob at the same place everytime
57 for (int i = 0; i < loops; i++) { 61 for (int i = 0; i < loops; i++) {
58 canvas->drawTextBlob(fBlob, 0, 0, paint); 62 canvas->drawTextBlob(fBlob, 0, 0, paint);
59 } 63 }
60 } 64 }
61 65
62 private: 66 private:
63 67
64 SkAutoTUnref<const SkTextBlob> fBlob; 68 SkAutoTUnref<const SkTextBlob> fBlob;
65 SkTDArray<uint16_t> fGlyphs; 69 SkTDArray<uint16_t> fGlyphs;
66 SkAutoTUnref<SkTypeface> fTypeface; 70 SkAutoTUnref<SkTypeface> fTypeface;
67 71
68 typedef Benchmark INHERITED; 72 typedef Benchmark INHERITED;
69 }; 73 };
70 74
71 DEF_BENCH( return new TextBlobBench(); ) 75 DEF_BENCH( return new TextBlobBench(); )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698