Index: src/effects/gradients/SkRadialGradient.cpp |
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp |
index d734aa056a4ad6e96455d2c7692c727cd447c706..7e7ac7a4069b0ed7b438b64f0ebfdac2df227807 100644 |
--- a/src/effects/gradients/SkRadialGradient.cpp |
+++ b/src/effects/gradients/SkRadialGradient.cpp |
@@ -7,46 +7,8 @@ |
*/ |
#include "SkRadialGradient.h" |
-#include "SkRadialGradient_Table.h" |
#include "SkNx.h" |
-#define kSQRT_TABLE_BITS 11 |
-#define kSQRT_TABLE_SIZE (1 << kSQRT_TABLE_BITS) |
- |
-static_assert(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE, "SqrtTableSizesMatch"); |
- |
-#if 0 |
- |
-#include <stdio.h> |
- |
-void SkRadialGradient_BuildTable() { |
- // build it 0..127 x 0..127, so we use 2^15 - 1 in the numerator for our "fixed" table |
- |
- FILE* file = ::fopen("SkRadialGradient_Table.h", "w"); |
- SkASSERT(file); |
- ::fprintf(file, "static const uint8_t gSqrt8Table[] = {\n"); |
- |
- for (int i = 0; i < kSQRT_TABLE_SIZE; i++) { |
- if ((i & 15) == 0) { |
- ::fprintf(file, "\t"); |
- } |
- |
- uint8_t value = SkToU8(SkFixedSqrt(i * SK_Fixed1 / kSQRT_TABLE_SIZE) >> 8); |
- |
- ::fprintf(file, "0x%02X", value); |
- if (i < kSQRT_TABLE_SIZE-1) { |
- ::fprintf(file, ", "); |
- } |
- if ((i & 15) == 15) { |
- ::fprintf(file, "\n"); |
- } |
- } |
- ::fprintf(file, "};\n"); |
- ::fclose(file); |
-} |
- |
-#endif |
- |
namespace { |
// GCC doesn't like using static functions as template arguments. So force these to be non-static. |
@@ -67,83 +29,6 @@ SkMatrix rad_to_unit_matrix(const SkPoint& center, SkScalar radius) { |
return matrix; |
} |
-typedef void (* RadialShade16Proc)(SkScalar sfx, SkScalar sdx, |
- SkScalar sfy, SkScalar sdy, |
- uint16_t* dstC, const uint16_t* cache, |
- int toggle, int count); |
- |
-void shadeSpan16_radial_clamp(SkScalar sfx, SkScalar sdx, |
- SkScalar sfy, SkScalar sdy, |
- uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RESTRICT cache, |
- int toggle, int count) { |
- const uint8_t* SK_RESTRICT sqrt_table = gSqrt8Table; |
- |
- /* knock these down so we can pin against +- 0x7FFF, which is an |
- immediate load, rather than 0xFFFF which is slower. This is a |
- compromise, since it reduces our precision, but that appears |
- to be visually OK. If we decide this is OK for all of our cases, |
- we could (it seems) put this scale-down into fDstToIndex, |
- to avoid having to do these extra shifts each time. |
- */ |
- SkFixed fx = SkScalarToFixed(sfx) >> 1; |
- SkFixed dx = SkScalarToFixed(sdx) >> 1; |
- SkFixed fy = SkScalarToFixed(sfy) >> 1; |
- SkFixed dy = SkScalarToFixed(sdy) >> 1; |
- // might perform this check for the other modes, |
- // but the win will be a smaller % of the total |
- if (dy == 0) { |
- fy = SkTPin(fy, -0xFFFF >> 1, 0xFFFF >> 1); |
- fy *= fy; |
- do { |
- unsigned xx = SkTPin(fx, -0xFFFF >> 1, 0xFFFF >> 1); |
- unsigned fi = (xx * xx + fy) >> (14 + 16 - kSQRT_TABLE_BITS); |
- fi = SkFastMin32(fi, 0xFFFF >> (16 - kSQRT_TABLE_BITS)); |
- fx += dx; |
- *dstC++ = cache[toggle + |
- (sqrt_table[fi] >> SkGradientShaderBase::kSqrt16Shift)]; |
- toggle = next_dither_toggle16(toggle); |
- } while (--count != 0); |
- } else { |
- do { |
- unsigned xx = SkTPin(fx, -0xFFFF >> 1, 0xFFFF >> 1); |
- unsigned fi = SkTPin(fy, -0xFFFF >> 1, 0xFFFF >> 1); |
- fi = (xx * xx + fi * fi) >> (14 + 16 - kSQRT_TABLE_BITS); |
- fi = SkFastMin32(fi, 0xFFFF >> (16 - kSQRT_TABLE_BITS)); |
- fx += dx; |
- fy += dy; |
- *dstC++ = cache[toggle + |
- (sqrt_table[fi] >> SkGradientShaderBase::kSqrt16Shift)]; |
- toggle = next_dither_toggle16(toggle); |
- } while (--count != 0); |
- } |
-} |
- |
-template <SkFixed (*TileProc)(SkFixed)> |
-void shadeSpan16_radial(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, |
- uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RESTRICT cache, |
- int toggle, int count) { |
- do { |
- const SkFixed dist = SkFloatToFixed(sk_float_sqrt(fx*fx + fy*fy)); |
- const unsigned fi = TileProc(dist); |
- SkASSERT(fi <= 0xFFFF); |
- *dstC++ = cache[toggle + (fi >> SkGradientShaderBase::kCache16Shift)]; |
- toggle = next_dither_toggle16(toggle); |
- fx += dx; |
- fy += dy; |
- } while (--count != 0); |
-} |
- |
-void shadeSpan16_radial_mirror(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, |
- uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RESTRICT cache, |
- int toggle, int count) { |
- shadeSpan16_radial<mirror_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, toggle, count); |
-} |
- |
-void shadeSpan16_radial_repeat(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, |
- uint16_t* SK_RESTRICT dstC, const uint16_t* SK_RESTRICT cache, |
- int toggle, int count) { |
- shadeSpan16_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, toggle, count); |
-} |
} // namespace |
@@ -167,64 +52,6 @@ SkRadialGradient::RadialGradientContext::RadialGradientContext( |
const SkRadialGradient& shader, const ContextRec& rec) |
: INHERITED(shader, rec) {} |
-void SkRadialGradient::RadialGradientContext::shadeSpan16(int x, int y, uint16_t* dstCParam, |
- int count) { |
- SkASSERT(count > 0); |
- |
- const SkRadialGradient& radialGradient = static_cast<const SkRadialGradient&>(fShader); |
- |
- uint16_t* SK_RESTRICT dstC = dstCParam; |
- |
- SkPoint srcPt; |
- SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
- TileProc proc = radialGradient.fTileProc; |
- const uint16_t* SK_RESTRICT cache = fCache->getCache16(); |
- int toggle = init_dither_toggle16(x, y); |
- |
- if (fDstToIndexClass != kPerspective_MatrixClass) { |
- dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, |
- SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
- |
- SkScalar sdx = fDstToIndex.getScaleX(); |
- SkScalar sdy = fDstToIndex.getSkewY(); |
- |
- if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
- SkFixed storage[2]; |
- (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), |
- &storage[0], &storage[1]); |
- sdx = SkFixedToScalar(storage[0]); |
- sdy = SkFixedToScalar(storage[1]); |
- } else { |
- SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
- } |
- |
- RadialShade16Proc shadeProc = shadeSpan16_radial_repeat; |
- if (SkShader::kClamp_TileMode == radialGradient.fTileMode) { |
- shadeProc = shadeSpan16_radial_clamp; |
- } else if (SkShader::kMirror_TileMode == radialGradient.fTileMode) { |
- shadeProc = shadeSpan16_radial_mirror; |
- } else { |
- SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); |
- } |
- (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, |
- cache, toggle, count); |
- } else { // perspective case |
- SkScalar dstX = SkIntToScalar(x); |
- SkScalar dstY = SkIntToScalar(y); |
- do { |
- dstProc(fDstToIndex, dstX, dstY, &srcPt); |
- unsigned fi = proc(SkScalarToFixed(srcPt.length())); |
- SkASSERT(fi <= 0xFFFF); |
- |
- int index = fi >> (16 - kCache16Bits); |
- *dstC++ = cache[toggle + index]; |
- toggle = next_dither_toggle16(toggle); |
- |
- dstX += SK_Scalar1; |
- } while (--count != 0); |
- } |
-} |
- |
SkShader::GradientType SkRadialGradient::asAGradient(GradientInfo* info) const { |
if (info) { |
commonAsAGradient(info); |