| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "SkRadialGradient.h" | 9 #include "SkRadialGradient.h" |
| 10 #include "SkNx.h" | 10 #include "SkNx.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // GCC doesn't like using static functions as template arguments. So force thes
e to be non-static. | 14 // GCC doesn't like using static functions as template arguments. So force thes
e to be non-static. |
| 15 inline SkFixed mirror_tileproc_nonstatic(SkFixed x) { | 15 inline unsigned mirror_tileproc_nonstatic(float x) { |
| 16 return mirror_tileproc(x); | 16 return mirror_tileproc(x); |
| 17 } | 17 } |
| 18 | 18 |
| 19 inline SkFixed repeat_tileproc_nonstatic(SkFixed x) { | 19 inline unsigned repeat_tileproc_nonstatic(float x) { |
| 20 return repeat_tileproc(x); | 20 return repeat_tileproc(x); |
| 21 } | 21 } |
| 22 | 22 |
| 23 SkMatrix rad_to_unit_matrix(const SkPoint& center, SkScalar radius) { | 23 SkMatrix rad_to_unit_matrix(const SkPoint& center, SkScalar radius) { |
| 24 SkScalar inv = SkScalarInvert(radius); | 24 SkScalar inv = SkScalarInvert(radius); |
| 25 | 25 |
| 26 SkMatrix matrix; | 26 SkMatrix matrix; |
| 27 matrix.setTranslate(-center.fX, -center.fY); | 27 matrix.setTranslate(-center.fX, -center.fY); |
| 28 matrix.postScale(inv, inv); | 28 matrix.postScale(inv, inv); |
| 29 return matrix; | 29 return matrix; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 *dstC++ = cache[toggle + fi[i]]; | 152 *dstC++ = cache[toggle + fi[i]]; |
| 153 toggle = next_dither_toggle(toggle); | 153 toggle = next_dither_toggle(toggle); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Unrolling this loop doesn't seem to help (when float); we're stalling to | 159 // Unrolling this loop doesn't seem to help (when float); we're stalling to |
| 160 // get the results of the sqrt (?), and don't have enough extra registers to | 160 // get the results of the sqrt (?), and don't have enough extra registers to |
| 161 // have many in flight. | 161 // have many in flight. |
| 162 template <SkFixed (*TileProc)(SkFixed)> | 162 template <unsigned (*TileProc)(float)> |
| 163 void shadeSpan_radial(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, | 163 void shadeSpan_radial(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, |
| 164 SkPMColor* SK_RESTRICT dstC, const SkPMColor* SK_RESTRICT
cache, | 164 SkPMColor* SK_RESTRICT dstC, const SkPMColor* SK_RESTRICT
cache, |
| 165 int count, int toggle) { | 165 int count, int toggle) { |
| 166 do { | 166 do { |
| 167 const SkFixed dist = SkFloatToFixed(sk_float_sqrt(fx*fx + fy*fy)); | 167 const float dist = sk_float_sqrt(fx*fx + fy*fy); |
| 168 const unsigned fi = TileProc(dist); | 168 const unsigned fi = TileProc(dist); |
| 169 SkASSERT(fi <= 0xFFFF); | 169 SkASSERT(fi <= 0xFFFF); |
| 170 *dstC++ = cache[toggle + (fi >> SkGradientShaderBase::kCache32Shift)]; | 170 *dstC++ = cache[toggle + (fi >> SkGradientShaderBase::kCache32Shift)]; |
| 171 toggle = next_dither_toggle(toggle); | 171 toggle = next_dither_toggle(toggle); |
| 172 fx += dx; | 172 fx += dx; |
| 173 fy += dy; | 173 fy += dy; |
| 174 } while (--count != 0); | 174 } while (--count != 0); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void shadeSpan_radial_mirror(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, | 177 void shadeSpan_radial_mirror(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 shadeProc = shadeSpan_radial_mirror; | 221 shadeProc = shadeSpan_radial_mirror; |
| 222 } else { | 222 } else { |
| 223 SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); | 223 SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); |
| 224 } | 224 } |
| 225 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, cache, count, toggle); | 225 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, cache, count, toggle); |
| 226 } else { // perspective case | 226 } else { // perspective case |
| 227 SkScalar dstX = SkIntToScalar(x); | 227 SkScalar dstX = SkIntToScalar(x); |
| 228 SkScalar dstY = SkIntToScalar(y); | 228 SkScalar dstY = SkIntToScalar(y); |
| 229 do { | 229 do { |
| 230 dstProc(fDstToIndex, dstX, dstY, &srcPt); | 230 dstProc(fDstToIndex, dstX, dstY, &srcPt); |
| 231 unsigned fi = proc(SkScalarToFixed(srcPt.length())); | 231 unsigned fi = proc(SkScalarToFloat(srcPt.length())); |
| 232 SkASSERT(fi <= 0xFFFF); | 232 SkASSERT(fi <= 0xFFFF); |
| 233 *dstC++ = cache[fi >> SkGradientShaderBase::kCache32Shift]; | 233 *dstC++ = cache[fi >> SkGradientShaderBase::kCache32Shift]; |
| 234 dstX += SK_Scalar1; | 234 dstX += SK_Scalar1; |
| 235 } while (--count != 0); | 235 } while (--count != 0); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 ///////////////////////////////////////////////////////////////////// | 239 ///////////////////////////////////////////////////////////////////// |
| 240 | 240 |
| 241 #if SK_SUPPORT_GPU | 241 #if SK_SUPPORT_GPU |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 str->appendScalar(fCenter.fY); | 377 str->appendScalar(fCenter.fY); |
| 378 str->append(") radius: "); | 378 str->append(") radius: "); |
| 379 str->appendScalar(fRadius); | 379 str->appendScalar(fRadius); |
| 380 str->append(" "); | 380 str->append(" "); |
| 381 | 381 |
| 382 this->INHERITED::toString(str); | 382 this->INHERITED::toString(str); |
| 383 | 383 |
| 384 str->append(")"); | 384 str->append(")"); |
| 385 } | 385 } |
| 386 #endif | 386 #endif |
| OLD | NEW |