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 */ |
| 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkRandom.h" | 11 #include "SkRandom.h" |
12 #include "SkView.h" | 12 #include "SkView.h" |
13 | 13 |
14 namespace { | |
15 | |
16 // Generates y values for the chart plots. | 14 // Generates y values for the chart plots. |
17 void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkTDArray<SkScalar>* d
ataPts) { | 15 static void gen_data(SkScalar yAvg, SkScalar ySpread, int count, SkTDArray<SkSca
lar>* dataPts) { |
18 dataPts->setCount(count); | 16 dataPts->setCount(count); |
19 static SkRandom gRandom; | 17 static SkRandom gRandom; |
20 for (int i = 0; i < count; ++i) { | 18 for (int i = 0; i < count; ++i) { |
21 (*dataPts)[i] = gRandom.nextRangeScalar(yAvg - SkScalarHalf(ySpread), | 19 (*dataPts)[i] = gRandom.nextRangeScalar(yAvg - SkScalarHalf(ySpread), |
22 yAvg + SkScalarHalf(ySpread)); | 20 yAvg + SkScalarHalf(ySpread)); |
23 } | 21 } |
24 } | 22 } |
25 | 23 |
26 // Generates a path to stroke along the top of each plot and a fill path for the
area below each | 24 // Generates a path to stroke along the top of each plot and a fill path for the
area below each |
27 // plot. The fill path is bounded below by the bottomData plot points or a horiz
ontal line at | 25 // plot. The fill path is bounded below by the bottomData plot points or a horiz
ontal line at |
28 // yBase if bottomData == NULL. | 26 // yBase if bottomData == NULL. |
29 // The plots are animated by rotating the data points by leftShift. | 27 // The plots are animated by rotating the data points by leftShift. |
30 void gen_paths(const SkTDArray<SkScalar>& topData, | 28 static void gen_paths(const SkTDArray<SkScalar>& topData, |
31 const SkTDArray<SkScalar>* bottomData, | 29 const SkTDArray<SkScalar>* bottomData, |
32 SkScalar yBase, | 30 SkScalar yBase, |
33 SkScalar xLeft, SkScalar xDelta, | 31 SkScalar xLeft, SkScalar xDelta, |
34 int leftShift, | 32 int leftShift, |
35 SkPath* plot, SkPath* fill) { | 33 SkPath* plot, SkPath* fill) { |
36 plot->rewind(); | 34 plot->rewind(); |
37 fill->rewind(); | 35 fill->rewind(); |
38 plot->incReserve(topData.count()); | 36 plot->incReserve(topData.count()); |
39 if (NULL == bottomData) { | 37 if (NULL == bottomData) { |
40 fill->incReserve(topData.count() + 2); | 38 fill->incReserve(topData.count() + 2); |
41 } else { | 39 } else { |
42 fill->incReserve(2 * topData.count()); | 40 fill->incReserve(2 * topData.count()); |
43 } | 41 } |
44 | 42 |
45 leftShift %= topData.count(); | 43 leftShift %= topData.count(); |
(...skipping 27 matching lines...) Expand all Loading... |
73 for (int i = 0; i < shiftToEndCount; ++i) { | 71 for (int i = 0; i < shiftToEndCount; ++i) { |
74 x -= xDelta; | 72 x -= xDelta; |
75 fill->lineTo(x, (*bottomData)[bottomData->count() - 1 - i]); | 73 fill->lineTo(x, (*bottomData)[bottomData->count() - 1 - i]); |
76 } | 74 } |
77 } else { | 75 } else { |
78 fill->lineTo(x - xDelta, yBase); | 76 fill->lineTo(x - xDelta, yBase); |
79 fill->lineTo(xLeft, yBase); | 77 fill->lineTo(xLeft, yBase); |
80 } | 78 } |
81 } | 79 } |
82 | 80 |
83 } | |
84 | |
85 // A set of scrolling line plots with the area between each plot filled. Stresse
s out GPU path | 81 // A set of scrolling line plots with the area between each plot filled. Stresse
s out GPU path |
86 // filling | 82 // filling |
87 class ChartView : public SampleView { | 83 class ChartView : public SampleView { |
88 public: | 84 public: |
89 ChartView() { | 85 ChartView() { |
90 fShift = 0; | 86 fShift = 0; |
91 fSize.set(-1, -1); | 87 fSize.set(-1, -1); |
92 } | 88 } |
93 | 89 |
94 protected: | 90 protected: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 int fShift; | 175 int fShift; |
180 SkISize fSize; | 176 SkISize fSize; |
181 SkTDArray<SkScalar> fData[kNumGraphs]; | 177 SkTDArray<SkScalar> fData[kNumGraphs]; |
182 typedef SampleView INHERITED; | 178 typedef SampleView INHERITED; |
183 }; | 179 }; |
184 | 180 |
185 ////////////////////////////////////////////////////////////////////////////// | 181 ////////////////////////////////////////////////////////////////////////////// |
186 | 182 |
187 static SkView* MyFactory() { return new ChartView; } | 183 static SkView* MyFactory() { return new ChartView; } |
188 static SkViewRegister reg(MyFactory); | 184 static SkViewRegister reg(MyFactory); |
OLD | NEW |