OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SkBenchmark.h" | 7 #include "SkBenchmark.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 | 15 |
16 // This is designed to emulate about 4 screens of textual content | 16 // This is designed to emulate about 4 screens of textual content |
17 | 17 |
18 | 18 |
19 class PicturePlaybackBench : public SkBenchmark { | 19 class PicturePlaybackBench : public SkBenchmark { |
20 public: | 20 public: |
21 PicturePlaybackBench(void* param, const char name[]) : INHERITED(param) { | 21 PicturePlaybackBench(const char name[]) { |
22 fName.printf("picture_playback_%s", name); | 22 fName.printf("picture_playback_%s", name); |
23 fPictureWidth = SkIntToScalar(PICTURE_WIDTH); | 23 fPictureWidth = SkIntToScalar(PICTURE_WIDTH); |
24 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); | 24 fPictureHeight = SkIntToScalar(PICTURE_HEIGHT); |
25 fTextSize = SkIntToScalar(TEXT_SIZE); | 25 fTextSize = SkIntToScalar(TEXT_SIZE); |
26 } | 26 } |
27 | 27 |
28 enum { | 28 enum { |
29 PICTURE_WIDTH = 1000, | 29 PICTURE_WIDTH = 1000, |
30 PICTURE_HEIGHT = 4000, | 30 PICTURE_HEIGHT = 4000, |
31 TEXT_SIZE = 10 | 31 TEXT_SIZE = 10 |
(...skipping 30 matching lines...) Expand all Loading... |
62 SkScalar fPictureWidth; | 62 SkScalar fPictureWidth; |
63 SkScalar fPictureHeight; | 63 SkScalar fPictureHeight; |
64 SkScalar fTextSize; | 64 SkScalar fTextSize; |
65 private: | 65 private: |
66 typedef SkBenchmark INHERITED; | 66 typedef SkBenchmark INHERITED; |
67 }; | 67 }; |
68 | 68 |
69 | 69 |
70 class TextPlaybackBench : public PicturePlaybackBench { | 70 class TextPlaybackBench : public PicturePlaybackBench { |
71 public: | 71 public: |
72 TextPlaybackBench(void* param) : INHERITED(param, "drawText") { } | 72 TextPlaybackBench() : INHERITED("drawText") { } |
73 protected: | 73 protected: |
74 virtual void recordCanvas(SkCanvas* canvas) { | 74 virtual void recordCanvas(SkCanvas* canvas) { |
75 SkPaint paint; | 75 SkPaint paint; |
76 paint.setTextSize(fTextSize); | 76 paint.setTextSize(fTextSize); |
77 paint.setColor(SK_ColorBLACK); | 77 paint.setColor(SK_ColorBLACK); |
78 | 78 |
79 const char* text = "Hamburgefons"; | 79 const char* text = "Hamburgefons"; |
80 size_t len = strlen(text); | 80 size_t len = strlen(text); |
81 const SkScalar textWidth = paint.measureText(text, len); | 81 const SkScalar textWidth = paint.measureText(text, len); |
82 | 82 |
83 for (SkScalar x = 0; x < fPictureWidth; x += textWidth) { | 83 for (SkScalar x = 0; x < fPictureWidth; x += textWidth) { |
84 for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) { | 84 for (SkScalar y = 0; y < fPictureHeight; y += fTextSize) { |
85 canvas->drawText(text, len, x, y, paint); | 85 canvas->drawText(text, len, x, y, paint); |
86 } | 86 } |
87 } | 87 } |
88 } | 88 } |
89 private: | 89 private: |
90 typedef PicturePlaybackBench INHERITED; | 90 typedef PicturePlaybackBench INHERITED; |
91 }; | 91 }; |
92 | 92 |
93 class PosTextPlaybackBench : public PicturePlaybackBench { | 93 class PosTextPlaybackBench : public PicturePlaybackBench { |
94 public: | 94 public: |
95 PosTextPlaybackBench(void* param, bool drawPosH) | 95 PosTextPlaybackBench(bool drawPosH) |
96 : INHERITED(param, drawPosH ? "drawPosTextH" : "drawPosText") | 96 : INHERITED(drawPosH ? "drawPosTextH" : "drawPosText") |
97 , fDrawPosH(drawPosH) { } | 97 , fDrawPosH(drawPosH) { } |
98 protected: | 98 protected: |
99 virtual void recordCanvas(SkCanvas* canvas) { | 99 virtual void recordCanvas(SkCanvas* canvas) { |
100 SkPaint paint; | 100 SkPaint paint; |
101 paint.setTextSize(fTextSize); | 101 paint.setTextSize(fTextSize); |
102 paint.setColor(SK_ColorBLACK); | 102 paint.setColor(SK_ColorBLACK); |
103 | 103 |
104 const char* text = "Hamburgefons"; | 104 const char* text = "Hamburgefons"; |
105 size_t len = strlen(text); | 105 size_t len = strlen(text); |
106 const SkScalar textWidth = paint.measureText(text, len); | 106 const SkScalar textWidth = paint.measureText(text, len); |
(...skipping 22 matching lines...) Expand all Loading... |
129 delete[] adv; | 129 delete[] adv; |
130 } | 130 } |
131 private: | 131 private: |
132 bool fDrawPosH; | 132 bool fDrawPosH; |
133 typedef PicturePlaybackBench INHERITED; | 133 typedef PicturePlaybackBench INHERITED; |
134 }; | 134 }; |
135 | 135 |
136 | 136 |
137 /////////////////////////////////////////////////////////////////////////////// | 137 /////////////////////////////////////////////////////////////////////////////// |
138 | 138 |
139 static SkBenchmark* Fact0(void* p) { return new TextPlaybackBench(p); } | 139 DEF_BENCH( return new TextPlaybackBench(); ) |
140 static SkBenchmark* Fact1(void* p) { return new PosTextPlaybackBench(p, true); } | 140 DEF_BENCH( return new PosTextPlaybackBench(true); ) |
141 static SkBenchmark* Fact2(void* p) { return new PosTextPlaybackBench(p, false);
} | 141 DEF_BENCH( return new PosTextPlaybackBench(false); ) |
142 | |
143 static BenchRegistry gReg0(Fact0); | |
144 static BenchRegistry gReg1(Fact1); | |
145 static BenchRegistry gReg2(Fact2); | |
OLD | NEW |