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 "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 SkRandom* random, SkTDArray<SkScalar>* dataPts) { | 22 SkRandom* random, SkTDArray<SkScalar>* dataPts) { |
23 dataPts->setCount(count); | 23 dataPts->setCount(count); |
24 for (int i = 0; i < count; ++i) { | 24 for (int i = 0; i < count; ++i) { |
25 (*dataPts)[i] = random->nextRangeScalar(yAvg - SkScalarHalf(ySpread), | 25 (*dataPts)[i] = random->nextRangeScalar(yAvg - SkScalarHalf(ySpread), |
26 yAvg + SkScalarHalf(ySpread)); | 26 yAvg + SkScalarHalf(ySpread)); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 // Generates a path to stroke along the top of each plot and a fill path for the
area below each | 30 // Generates a path to stroke along the top of each plot and a fill path for the
area below each |
31 // plot. The fill path is bounded below by the bottomData plot points or a horiz
ontal line at | 31 // plot. The fill path is bounded below by the bottomData plot points or a horiz
ontal line at |
32 // yBase if bottomData == NULL. | 32 // yBase if bottomData == nullptr. |
33 // The plots are animated by rotating the data points by leftShift. | 33 // The plots are animated by rotating the data points by leftShift. |
34 static void gen_paths(const SkTDArray<SkScalar>& topData, | 34 static void gen_paths(const SkTDArray<SkScalar>& topData, |
35 const SkTDArray<SkScalar>* bottomData, | 35 const SkTDArray<SkScalar>* bottomData, |
36 SkScalar yBase, | 36 SkScalar yBase, |
37 SkScalar xLeft, SkScalar xDelta, | 37 SkScalar xLeft, SkScalar xDelta, |
38 int leftShift, | 38 int leftShift, |
39 SkPath* plot, SkPath* fill) { | 39 SkPath* plot, SkPath* fill) { |
40 plot->rewind(); | 40 plot->rewind(); |
41 fill->rewind(); | 41 fill->rewind(); |
42 plot->incReserve(topData.count()); | 42 plot->incReserve(topData.count()); |
43 if (NULL == bottomData) { | 43 if (nullptr == bottomData) { |
44 fill->incReserve(topData.count() + 2); | 44 fill->incReserve(topData.count() + 2); |
45 } else { | 45 } else { |
46 fill->incReserve(2 * topData.count()); | 46 fill->incReserve(2 * topData.count()); |
47 } | 47 } |
48 | 48 |
49 leftShift %= topData.count(); | 49 leftShift %= topData.count(); |
50 SkScalar x = xLeft; | 50 SkScalar x = xLeft; |
51 | 51 |
52 // Account for the leftShift using two loops | 52 // Account for the leftShift using two loops |
53 int shiftToEndCount = topData.count() - leftShift; | 53 int shiftToEndCount = topData.count() - leftShift; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 SkPaint plotPaint; | 142 SkPaint plotPaint; |
143 SkPaint fillPaint; | 143 SkPaint fillPaint; |
144 plotPaint.setAntiAlias(fAA); | 144 plotPaint.setAntiAlias(fAA); |
145 plotPaint.setStyle(SkPaint::kStroke_Style); | 145 plotPaint.setStyle(SkPaint::kStroke_Style); |
146 plotPaint.setStrokeWidth(kStrokeWidth); | 146 plotPaint.setStrokeWidth(kStrokeWidth); |
147 plotPaint.setStrokeCap(SkPaint::kRound_Cap); | 147 plotPaint.setStrokeCap(SkPaint::kRound_Cap); |
148 plotPaint.setStrokeJoin(SkPaint::kRound_Join); | 148 plotPaint.setStrokeJoin(SkPaint::kRound_Join); |
149 fillPaint.setAntiAlias(fAA); | 149 fillPaint.setAntiAlias(fAA); |
150 fillPaint.setStyle(SkPaint::kFill_Style); | 150 fillPaint.setStyle(SkPaint::kFill_Style); |
151 | 151 |
152 SkTDArray<SkScalar>* prevData = NULL; | 152 SkTDArray<SkScalar>* prevData = nullptr; |
153 for (int i = 0; i < kNumGraphs; ++i) { | 153 for (int i = 0; i < kNumGraphs; ++i) { |
154 gen_paths(fData[i], | 154 gen_paths(fData[i], |
155 prevData, | 155 prevData, |
156 height, | 156 height, |
157 0, | 157 0, |
158 SkIntToScalar(kPixelsPerTick), | 158 SkIntToScalar(kPixelsPerTick), |
159 fShift, | 159 fShift, |
160 &plotPath, | 160 &plotPath, |
161 &fillPath); | 161 &fillPath); |
162 | 162 |
(...skipping 22 matching lines...) Expand all Loading... |
185 SkTDArray<SkScalar> fData[kNumGraphs]; | 185 SkTDArray<SkScalar> fData[kNumGraphs]; |
186 bool fAA; | 186 bool fAA; |
187 | 187 |
188 typedef Benchmark INHERITED; | 188 typedef Benchmark INHERITED; |
189 }; | 189 }; |
190 | 190 |
191 ////////////////////////////////////////////////////////////////////////////// | 191 ////////////////////////////////////////////////////////////////////////////// |
192 | 192 |
193 DEF_BENCH( return new ChartBench(true); ) | 193 DEF_BENCH( return new ChartBench(true); ) |
194 DEF_BENCH( return new ChartBench(false); ) | 194 DEF_BENCH( return new ChartBench(false); ) |
OLD | NEW |