OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "Benchmark.h" | |
9 | |
10 #include "SkCanvas.h" | |
11 #include "SkShader.h" | |
12 #include "SkGradientShader.h" | |
13 #include "SkString.h" | |
14 #include "SkColor.h" | |
15 #include "SkPaint.h" | |
16 | |
17 class HardStopGradientBench_ScaleNumHardStops : public Benchmark { | |
18 public: | |
19 HardStopGradientBench_ScaleNumHardStops(int colorCount, int hardStopCount) { | |
20 SkASSERT(hardStopCount <= colorCount); | |
21 | |
22 fName.printf("hardstop_scale_num_hard_stops_%03d_colors_%03d_hard_stops" , | |
23 colorCount, hardStopCount); | |
24 | |
25 fColorCount = colorCount; | |
26 fHardStopCount = hardStopCount; | |
27 } | |
28 | |
29 const char* onGetName() override { | |
30 return fName.c_str(); | |
31 } | |
32 | |
33 SkIPoint onGetSize() override { | |
34 return SkIPoint::Make(kSize, kSize); | |
35 } | |
36 | |
37 void onPreDraw(SkCanvas* canvas) override { | |
38 // Left to right | |
39 SkPoint points[2] = { | |
40 SkPoint::Make(0, kSize/2), | |
41 SkPoint::Make(kSize-1, kSize/2), | |
42 }; | |
43 | |
44 // "Evenly spaced" colors | |
45 SkAutoTArray<SkColor> colors(fColorCount); | |
46 for (int i = 0; i < fColorCount; i++) { | |
47 colors[i] = i * (0xffffffff / fColorCount); | |
48 } | |
49 | |
50 // Create requisite number of hard stops, and evenly | |
51 // space positions after that | |
52 SkAutoTArray<SkScalar> positions(fColorCount); | |
53 int k = 0; | |
54 for (int i = 0; i < fHardStopCount; i++) { | |
55 positions[k++] = 0.0f; | |
56 positions[k++] = 0.0f; | |
tomhudson
2016/07/26 13:42:28
Setting a 2*k-multiplicity hard stop at 0 isn't th
| |
57 } | |
58 for (int i = k; i < fColorCount; i++) { | |
59 positions[i] = i / (fColorCount - 1.0f); | |
60 } | |
61 | |
62 fPaint.setShader(SkGradientShader::MakeLinear(points, | |
63 colors.get(), | |
64 positions.get(), | |
65 fColorCount, | |
66 SkShader::kClamp_TileMode, | |
67 0, | |
68 nullptr)); | |
69 } | |
70 | |
71 /* | |
72 * Draw simple linear gradient from left to right | |
73 */ | |
74 void onDraw(int loops, SkCanvas* canvas) override { | |
75 for (int i = 0; i < loops; i++) { | |
76 canvas->drawPaint(fPaint); | |
77 } | |
78 } | |
79 | |
80 private: | |
81 static const int kSize = 500; | |
82 | |
83 SkString fName; | |
84 int fColorCount; | |
85 int fHardStopCount; | |
86 SkPaint fPaint; | |
87 | |
88 typedef Benchmark INHERITED; | |
89 }; | |
90 | |
91 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 1);) | |
92 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 2);) | |
93 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(10, 5);) | |
94 | |
95 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 1);) | |
96 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 5);) | |
97 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(20, 10);) | |
98 | |
99 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 1);) | |
100 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 10);) | |
101 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(50, 25);) | |
102 | |
103 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 1);) | |
104 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 25);) | |
105 DEF_BENCH(return new HardStopGradientBench_ScaleNumHardStops(100, 50);) | |
OLD | NEW |