OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkPMFloat.h" | 9 #include "SkPMFloat.h" |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 void onDraw(const int loops, SkCanvas*) override { | 105 void onDraw(const int loops, SkCanvas*) override { |
106 Sk4f c0 = SkPMFloat::FromARGB(255, 255, 0, 0), | 106 Sk4f c0 = SkPMFloat::FromARGB(255, 255, 0, 0), |
107 c1 = SkPMFloat::FromARGB(255, 0, 0, 255), | 107 c1 = SkPMFloat::FromARGB(255, 0, 0, 255), |
108 dc = c1 - c0, | 108 dc = c1 - c0, |
109 fx(0.1f), | 109 fx(0.1f), |
110 dx(0.002f), | 110 dx(0.002f), |
111 dcdx(dc*dx), | 111 dcdx(dc*dx), |
112 dcdx4(dcdx+dcdx+dcdx+dcdx); | 112 dcdx4(dcdx+dcdx+dcdx+dcdx); |
113 | 113 |
114 for (int n = 0; n < loops; n++) { | 114 for (int n = 0; n < loops; n++) { |
115 Sk4f a = c0 + dc*fx, // TODO: add 0.5f, here call trunc() instead o
f get(). | 115 Sk4f a = c0 + dc*fx + Sk4f(0.5f), // The +0.5f lets us call trunc()
instead of get(). |
116 b = a + dcdx, | 116 b = a + dcdx, |
117 c = b + dcdx, | 117 c = b + dcdx, |
118 d = c + dcdx; | 118 d = c + dcdx; |
119 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) { | 119 for (size_t i = 0; i < SK_ARRAY_COUNT(fDevice); i += 4) { |
120 fDevice[i+0] = SkPMFloat(a).get(); | 120 fDevice[i+0] = SkPMFloat(a).trunc(); |
121 fDevice[i+1] = SkPMFloat(b).get(); | 121 fDevice[i+1] = SkPMFloat(b).trunc(); |
122 fDevice[i+2] = SkPMFloat(c).get(); | 122 fDevice[i+2] = SkPMFloat(c).trunc(); |
123 fDevice[i+3] = SkPMFloat(d).get(); | 123 fDevice[i+3] = SkPMFloat(d).trunc(); |
124 a += dcdx4; | 124 a += dcdx4; |
125 b += dcdx4; | 125 b += dcdx4; |
126 c += dcdx4; | 126 c += dcdx4; |
127 d += dcdx4; | 127 d += dcdx4; |
128 } | 128 } |
129 } | 129 } |
130 } | 130 } |
131 }; | 131 }; |
132 | 132 |
133 DEF_BENCH(return new PMFloatGradientBench;) | 133 DEF_BENCH(return new PMFloatGradientBench;) |
OLD | NEW |