OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
11 #include "SkPaint.h" | 10 #include "SkPaint.h" |
12 #include "SkRandom.h" | 11 #include "SkRandom.h" |
13 | 12 |
14 /** | 13 /** |
15 * This is a conversion of samplecode/SampleChart.cpp into a bench. It sure woul
d be nice to be able | 14 * This is a conversion of samplecode/SampleChart.cpp into a bench. It sure woul
d be nice to be able |
16 * to write one subclass that can be a GM, bench, and/or Sample. | 15 * to write one subclass that can be a GM, bench, and/or Sample. |
17 */ | 16 */ |
18 | 17 |
19 namespace { | |
20 | |
21 // Generates y values for the chart plots. | 18 // Generates y values for the chart plots. |
22 void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkTDArray<SkScalar>* d
ataPts) { | 19 static void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkTDArray<SkSca
lar>* dataPts) { |
23 dataPts->setCount(count); | 20 dataPts->setCount(count); |
24 static SkRandom gRandom; | 21 static SkRandom gRandom; |
25 for (int i = 0; i < count; ++i) { | 22 for (int i = 0; i < count; ++i) { |
26 (*dataPts)[i] = gRandom.nextRangeScalar(yAvg - SkScalarHalf(ySpread), | 23 (*dataPts)[i] = gRandom.nextRangeScalar(yAvg - SkScalarHalf(ySpread), |
27 yAvg + SkScalarHalf(ySpread)); | 24 yAvg + SkScalarHalf(ySpread)); |
28 } | 25 } |
29 } | 26 } |
30 | 27 |
31 // Generates a path to stroke along the top of each plot and a fill path for the
area below each | 28 // Generates a path to stroke along the top of each plot and a fill path for the
area below each |
32 // plot. The fill path is bounded below by the bottomData plot points or a horiz
ontal line at | 29 // plot. The fill path is bounded below by the bottomData plot points or a horiz
ontal line at |
33 // yBase if bottomData == NULL. | 30 // yBase if bottomData == NULL. |
34 // The plots are animated by rotating the data points by leftShift. | 31 // The plots are animated by rotating the data points by leftShift. |
35 void gen_paths(const SkTDArray<SkScalar>& topData, | 32 static void gen_paths(const SkTDArray<SkScalar>& topData, |
36 const SkTDArray<SkScalar>* bottomData, | 33 const SkTDArray<SkScalar>* bottomData, |
37 SkScalar yBase, | 34 SkScalar yBase, |
38 SkScalar xLeft, SkScalar xDelta, | 35 SkScalar xLeft, SkScalar xDelta, |
39 int leftShift, | 36 int leftShift, |
40 SkPath* plot, SkPath* fill) { | 37 SkPath* plot, SkPath* fill) { |
41 plot->rewind(); | 38 plot->rewind(); |
42 fill->rewind(); | 39 fill->rewind(); |
43 plot->incReserve(topData.count()); | 40 plot->incReserve(topData.count()); |
44 if (NULL == bottomData) { | 41 if (NULL == bottomData) { |
45 fill->incReserve(topData.count() + 2); | 42 fill->incReserve(topData.count() + 2); |
46 } else { | 43 } else { |
47 fill->incReserve(2 * topData.count()); | 44 fill->incReserve(2 * topData.count()); |
48 } | 45 } |
49 | 46 |
50 leftShift %= topData.count(); | 47 leftShift %= topData.count(); |
(...skipping 27 matching lines...) Expand all Loading... |
78 for (int i = 0; i < shiftToEndCount; ++i) { | 75 for (int i = 0; i < shiftToEndCount; ++i) { |
79 x -= xDelta; | 76 x -= xDelta; |
80 fill->lineTo(x, (*bottomData)[bottomData->count() - 1 - i]); | 77 fill->lineTo(x, (*bottomData)[bottomData->count() - 1 - i]); |
81 } | 78 } |
82 } else { | 79 } else { |
83 fill->lineTo(x - xDelta, yBase); | 80 fill->lineTo(x - xDelta, yBase); |
84 fill->lineTo(xLeft, yBase); | 81 fill->lineTo(xLeft, yBase); |
85 } | 82 } |
86 } | 83 } |
87 | 84 |
88 } | |
89 | |
90 // A set of scrolling line plots with the area between each plot filled. Stresse
s out GPU path | 85 // A set of scrolling line plots with the area between each plot filled. Stresse
s out GPU path |
91 // filling | 86 // filling |
92 class ChartBench : public SkBenchmark { | 87 class ChartBench : public SkBenchmark { |
93 public: | 88 public: |
94 ChartBench(bool aa) { | 89 ChartBench(bool aa) { |
95 fShift = 0; | 90 fShift = 0; |
96 fAA = aa; | 91 fAA = aa; |
97 fSize.fWidth = -1; | 92 fSize.fWidth = -1; |
98 fSize.fHeight = -1; | 93 fSize.fHeight = -1; |
99 } | 94 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 SkTDArray<SkScalar> fData[kNumGraphs]; | 184 SkTDArray<SkScalar> fData[kNumGraphs]; |
190 bool fAA; | 185 bool fAA; |
191 | 186 |
192 typedef SkBenchmark INHERITED; | 187 typedef SkBenchmark INHERITED; |
193 }; | 188 }; |
194 | 189 |
195 ////////////////////////////////////////////////////////////////////////////// | 190 ////////////////////////////////////////////////////////////////////////////// |
196 | 191 |
197 DEF_BENCH( return new ChartBench(true); ) | 192 DEF_BENCH( return new ChartBench(true); ) |
198 DEF_BENCH( return new ChartBench(false); ) | 193 DEF_BENCH( return new ChartBench(false); ) |
OLD | NEW |