code style

git-svn-id: http://skia.googlecode.com/svn/trunk@1133 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2011-04-15 12:11:12 +00:00
parent 676d69b82f
commit 61eb040e2f

View File

@ -27,7 +27,7 @@
#define USE_DITHER_32BIT_GRADIENT #define USE_DITHER_32BIT_GRADIENT
#endif #endif
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
typedef SkFixed (*TileProc)(SkFixed); typedef SkFixed (*TileProc)(SkFixed);
@ -50,7 +50,7 @@ static const TileProc gTileProcs[] = {
mirror_tileproc mirror_tileproc
}; };
////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static inline int repeat_bits(int x, const int bits) { static inline int repeat_bits(int x, const int bits) {
return x & ((1 << bits) - 1); return x & ((1 << bits) - 1);
@ -83,7 +83,7 @@ static inline int mirror_8bits(int x) {
#endif #endif
} }
////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class Gradient_Shader : public SkShader { class Gradient_Shader : public SkShader {
public: public:
@ -709,7 +709,7 @@ void Gradient_Shader::commonAsAGradient(GradientInfo* info) const {
} }
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
static void pts_to_unit_matrix(const SkPoint pts[2], SkMatrix* matrix) { static void pts_to_unit_matrix(const SkPoint pts[2], SkMatrix* matrix) {
SkVector vec = pts[1] - pts[0]; SkVector vec = pts[1] - pts[0];
@ -789,14 +789,12 @@ bool Linear_Gradient::setContext(const SkBitmap& device, const SkPaint& paint,
} }
// Return true if fx, fx+dx, fx+2*dx, ... is always in range // Return true if fx, fx+dx, fx+2*dx, ... is always in range
static inline bool no_need_for_clamp(int fx, int dx, int count) static inline bool no_need_for_clamp(int fx, int dx, int count) {
{
SkASSERT(count > 0); SkASSERT(count > 0);
return (unsigned)((fx | (fx + (count - 1) * dx)) >> 8) <= 0xFF; return (unsigned)((fx | (fx + (count - 1) * dx)) >> 8) <= 0xFF;
} }
void Linear_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count) void Linear_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
{
SkASSERT(count > 0); SkASSERT(count > 0);
SkPoint srcPt; SkPoint srcPt;
@ -913,8 +911,7 @@ static void dither_memset16(uint16_t dst[], uint16_t value, uint16_t other,
} }
} }
void Linear_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count) void Linear_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count) {
{
SkASSERT(count > 0); SkASSERT(count > 0);
SkPoint srcPt; SkPoint srcPt;
@ -996,27 +993,28 @@ void Linear_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count)
#include <stdio.h> #include <stdio.h>
void SkRadialGradient_BuildTable() void SkRadialGradient_BuildTable() {
{
// build it 0..127 x 0..127, so we use 2^15 - 1 in the numerator for our "fixed" table // 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"); FILE* file = ::fopen("SkRadialGradient_Table.h", "w");
SkASSERT(file); SkASSERT(file);
::fprintf(file, "static const uint8_t gSqrt8Table[] = {\n"); ::fprintf(file, "static const uint8_t gSqrt8Table[] = {\n");
for (int i = 0; i < kSQRT_TABLE_SIZE; i++) for (int i = 0; i < kSQRT_TABLE_SIZE; i++) {
{ if ((i & 15) == 0) {
if ((i & 15) == 0)
::fprintf(file, "\t"); ::fprintf(file, "\t");
}
uint8_t value = SkToU8(SkFixedSqrt(i * SK_Fixed1 / kSQRT_TABLE_SIZE) >> 8); uint8_t value = SkToU8(SkFixedSqrt(i * SK_Fixed1 / kSQRT_TABLE_SIZE) >> 8);
::fprintf(file, "0x%02X", value); ::fprintf(file, "0x%02X", value);
if (i < kSQRT_TABLE_SIZE-1) if (i < kSQRT_TABLE_SIZE-1) {
::fprintf(file, ", "); ::fprintf(file, ", ");
if ((i & 15) == 15) }
if ((i & 15) == 15) {
::fprintf(file, "\n"); ::fprintf(file, "\n");
} }
}
::fprintf(file, "};\n"); ::fprintf(file, "};\n");
::fclose(file); ::fclose(file);
} }
@ -1024,8 +1022,8 @@ void SkRadialGradient_BuildTable()
#endif #endif
static void rad_to_unit_matrix(const SkPoint& center, SkScalar radius, SkMatrix* matrix) static void rad_to_unit_matrix(const SkPoint& center, SkScalar radius,
{ SkMatrix* matrix) {
SkScalar inv = SkScalarInvert(radius); SkScalar inv = SkScalarInvert(radius);
matrix->setTranslate(-center.fX, -center.fY); matrix->setTranslate(-center.fX, -center.fY);
@ -1046,8 +1044,8 @@ public:
rad_to_unit_matrix(center, radius, &fPtsToUnit); rad_to_unit_matrix(center, radius, &fPtsToUnit);
} }
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count)
{ virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) {
SkASSERT(count > 0); SkASSERT(count > 0);
SkPoint srcPt; SkPoint srcPt;
@ -1055,29 +1053,24 @@ public:
TileProc proc = fTileProc; TileProc proc = fTileProc;
const SkPMColor* cache = this->getCache32(); const SkPMColor* cache = this->getCache32();
if (fDstToIndexClass != kPerspective_MatrixClass) if (fDstToIndexClass != kPerspective_MatrixClass) {
{
dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf,
SkIntToScalar(y) + SK_ScalarHalf, &srcPt); SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
SkFixed dx, fx = SkScalarToFixed(srcPt.fX); SkFixed dx, fx = SkScalarToFixed(srcPt.fX);
SkFixed dy, fy = SkScalarToFixed(srcPt.fY); SkFixed dy, fy = SkScalarToFixed(srcPt.fY);
if (fDstToIndexClass == kFixedStepInX_MatrixClass) if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
{
SkFixed storage[2]; SkFixed storage[2];
(void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &storage[0], &storage[1]); (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &storage[0], &storage[1]);
dx = storage[0]; dx = storage[0];
dy = storage[1]; dy = storage[1];
} } else {
else
{
SkASSERT(fDstToIndexClass == kLinear_MatrixClass); SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = SkScalarToFixed(fDstToIndex.getScaleX()); dx = SkScalarToFixed(fDstToIndex.getScaleX());
dy = SkScalarToFixed(fDstToIndex.getSkewY()); dy = SkScalarToFixed(fDstToIndex.getSkewY());
} }
if (proc == clamp_tileproc) if (proc == clamp_tileproc) {
{
const uint8_t* sqrt_table = gSqrt8Table; const uint8_t* sqrt_table = gSqrt8Table;
fx >>= 1; fx >>= 1;
dx >>= 1; dx >>= 1;
@ -1092,9 +1085,7 @@ public:
fx += dx; fx += dx;
fy += dy; fy += dy;
} while (--count != 0); } while (--count != 0);
} } else if (proc == mirror_tileproc) {
else if (proc == mirror_tileproc)
{
do { do {
SkFixed magnitudeSquared = SkFixedSquare(fx) + SkFixedSquare(fy); SkFixed magnitudeSquared = SkFixedSquare(fx) + SkFixedSquare(fy);
if (magnitudeSquared < 0) // Overflow. if (magnitudeSquared < 0) // Overflow.
@ -1106,9 +1097,7 @@ public:
fx += dx; fx += dx;
fy += dy; fy += dy;
} while (--count != 0); } while (--count != 0);
} } else {
else
{
SkASSERT(proc == repeat_tileproc); SkASSERT(proc == repeat_tileproc);
do { do {
SkFixed magnitudeSquared = SkFixedSquare(fx) + SkFixedSquare(fy); SkFixed magnitudeSquared = SkFixedSquare(fx) + SkFixedSquare(fy);
@ -1122,9 +1111,7 @@ public:
fy += dy; fy += dy;
} while (--count != 0); } while (--count != 0);
} }
} } else { // perspective case
else // perspective case
{
SkScalar dstX = SkIntToScalar(x); SkScalar dstX = SkIntToScalar(x);
SkScalar dstY = SkIntToScalar(y); SkScalar dstY = SkIntToScalar(y);
do { do {
@ -1439,8 +1426,7 @@ public:
return kRadial2_GradientType; return kRadial2_GradientType;
} }
virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) virtual void shadeSpan(int x, int y, SkPMColor dstC[], int count) {
{
SkASSERT(count > 0); SkASSERT(count > 0);
// Zero difference between radii: fill with transparent black. // Zero difference between radii: fill with transparent black.
@ -1454,23 +1440,19 @@ public:
SkScalar foura = fA * 4; SkScalar foura = fA * 4;
bool posRoot = fDiffRadius < 0; bool posRoot = fDiffRadius < 0;
if (fDstToIndexClass != kPerspective_MatrixClass) if (fDstToIndexClass != kPerspective_MatrixClass) {
{
SkPoint srcPt; SkPoint srcPt;
dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf,
SkIntToScalar(y) + SK_ScalarHalf, &srcPt); SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
SkScalar dx, fx = srcPt.fX; SkScalar dx, fx = srcPt.fX;
SkScalar dy, fy = srcPt.fY; SkScalar dy, fy = srcPt.fY;
if (fDstToIndexClass == kFixedStepInX_MatrixClass) if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
{
SkFixed fixedX, fixedY; SkFixed fixedX, fixedY;
(void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY); (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY);
dx = SkFixedToScalar(fixedX); dx = SkFixedToScalar(fixedX);
dy = SkFixedToScalar(fixedY); dy = SkFixedToScalar(fixedY);
} } else {
else
{
SkASSERT(fDstToIndexClass == kLinear_MatrixClass); SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = fDstToIndex.getScaleX(); dx = fDstToIndex.getScaleX();
dy = fDstToIndex.getSkewY(); dy = fDstToIndex.getSkewY();
@ -1479,8 +1461,7 @@ public:
SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2; SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2;
SkScalar db = (SkScalarMul(fDiff.fX, dx) + SkScalar db = (SkScalarMul(fDiff.fX, dx) +
SkScalarMul(fDiff.fY, dy)) * 2; SkScalarMul(fDiff.fY, dy)) * 2;
if (proc == clamp_tileproc) if (proc == clamp_tileproc) {
{
for (; count > 0; --count) { for (; count > 0; --count) {
SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot); SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot);
SkFixed index = SkClampMax(t, 0xFFFF); SkFixed index = SkClampMax(t, 0xFFFF);
@ -1490,9 +1471,7 @@ public:
fy += dy; fy += dy;
b += db; b += db;
} }
} } else if (proc == mirror_tileproc) {
else if (proc == mirror_tileproc)
{
for (; count > 0; --count) { for (; count > 0; --count) {
SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot); SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot);
SkFixed index = mirror_tileproc(t); SkFixed index = mirror_tileproc(t);
@ -1502,9 +1481,7 @@ public:
fy += dy; fy += dy;
b += db; b += db;
} }
} } else {
else
{
SkASSERT(proc == repeat_tileproc); SkASSERT(proc == repeat_tileproc);
for (; count > 0; --count) { for (; count > 0; --count) {
SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot); SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, fOneOverTwoA, posRoot);
@ -1516,9 +1493,7 @@ public:
b += db; b += db;
} }
} }
} } else { // perspective case
else // perspective case
{
SkScalar dstX = SkIntToScalar(x); SkScalar dstX = SkIntToScalar(x);
SkScalar dstY = SkIntToScalar(y); SkScalar dstY = SkIntToScalar(y);
for (; count > 0; --count) { for (; count > 0; --count) {
@ -1669,10 +1644,8 @@ static uint8_t gSweepTable[65];
/* Our table stores precomputed values for atan: [0...1] -> [0..PI/4] /* Our table stores precomputed values for atan: [0...1] -> [0..PI/4]
We scale the results to [0..32] We scale the results to [0..32]
*/ */
static const uint8_t* build_sweep_table() static const uint8_t* build_sweep_table() {
{ if (!gSweepTableReady) {
if (!gSweepTableReady)
{
const int N = 65; const int N = 65;
const double DENOM = N - 1; const double DENOM = N - 1;
@ -1705,8 +1678,7 @@ static const uint8_t* build_sweep_table() { return gSweepTable; }
// Same as (but faster than) SkFixedDiv(numer, denom) >> 10 // Same as (but faster than) SkFixedDiv(numer, denom) >> 10
//unsigned div_64(int numer, int denom); //unsigned div_64(int numer, int denom);
static unsigned div_64(int numer, int denom) static unsigned div_64(int numer, int denom) {
{
SkASSERT(numer <= denom); SkASSERT(numer <= denom);
SkASSERT(numer > 0); SkASSERT(numer > 0);
SkASSERT(denom > 0); SkASSERT(denom > 0);
@ -1716,8 +1688,9 @@ static unsigned div_64(int numer, int denom)
int bits = 6 - nbits + dbits; int bits = 6 - nbits + dbits;
SkASSERT(bits <= 6); SkASSERT(bits <= 6);
if (bits < 0) // detect underflow if (bits < 0) { // detect underflow
return 0; return 0;
}
denom <<= dbits - 1; denom <<= dbits - 1;
numer <<= nbits - 1; numer <<= nbits - 1;
@ -1725,14 +1698,14 @@ static unsigned div_64(int numer, int denom)
unsigned result = 0; unsigned result = 0;
// do the first one // do the first one
if ((numer -= denom) >= 0) if ((numer -= denom) >= 0) {
result = 1; result = 1;
else } else {
numer += denom; numer += denom;
}
// Now fall into our switch statement if there are more bits to compute // Now fall into our switch statement if there are more bits to compute
if (bits > 0) if (bits > 0) {
{
// make room for the rest of the answer bits // make room for the rest of the answer bits
result <<= bits; result <<= bits;
switch (bits) { switch (bits) {
@ -1773,13 +1746,11 @@ static unsigned div_64(int numer, int denom)
} }
// Given x,y in the first quadrant, return 0..63 for the angle [0..90] // Given x,y in the first quadrant, return 0..63 for the angle [0..90]
static unsigned atan_0_90(SkFixed y, SkFixed x) static unsigned atan_0_90(SkFixed y, SkFixed x) {
{
#ifdef SK_DEBUG #ifdef SK_DEBUG
{ {
static bool gOnce; static bool gOnce;
if (!gOnce) if (!gOnce) {
{
gOnce = true; gOnce = true;
SkASSERT(div_64(55, 55) == 64); SkASSERT(div_64(55, 55) == 64);
SkASSERT(div_64(128, 256) == 32); SkASSERT(div_64(128, 256) == 32);
@ -1799,8 +1770,7 @@ static unsigned atan_0_90(SkFixed y, SkFixed x)
unsigned result; unsigned result;
bool swap = (x < y); bool swap = (x < y);
if (swap) if (swap) {
{
// first part of the atan(v) = PI/2 - atan(1/v) identity // first part of the atan(v) = PI/2 - atan(1/v) identity
// since our div_64 and table want v <= 1, where v = y/x // since our div_64 and table want v <= 1, where v = y/x
SkTSwap<SkFixed>(x, y); SkTSwap<SkFixed>(x, y);
@ -1819,8 +1789,7 @@ static unsigned atan_0_90(SkFixed y, SkFixed x)
SkASSERT(result < SK_ARRAY_COUNT(gSweepTable)); SkASSERT(result < SK_ARRAY_COUNT(gSweepTable));
result = table[result]; result = table[result];
if (swap) if (swap) {
{
// complete the atan(v) = PI/2 - atan(1/v) identity // complete the atan(v) = PI/2 - atan(1/v) identity
result = 64 - result; result = 64 - result;
// pin to 63 // pin to 63
@ -1832,16 +1801,16 @@ static unsigned atan_0_90(SkFixed y, SkFixed x)
} }
// returns angle in a circle [0..2PI) -> [0..255] // returns angle in a circle [0..2PI) -> [0..255]
static unsigned SkATan2_255(SkFixed y, SkFixed x) static unsigned SkATan2_255(SkFixed y, SkFixed x) {
{ if (x == 0) {
if (x == 0) if (y == 0) {
{
if (y == 0)
return 0; return 0;
}
return y < 0 ? 192 : 64; return y < 0 ? 192 : 64;
} }
if (y == 0) if (y == 0) {
return x < 0 ? 128 : 0; return x < 0 ? 128 : 0;
}
/* Find the right quadrant for x,y /* Find the right quadrant for x,y
Since atan_0_90 only handles the first quadrant, we rotate x,y Since atan_0_90 only handles the first quadrant, we rotate x,y
@ -1878,54 +1847,46 @@ static unsigned SkATan2_255(SkFixed y, SkFixed x)
*/ */
x = (x ^ xsign) - xsign; x = (x ^ xsign) - xsign;
y = (y ^ ysign) - ysign; y = (y ^ ysign) - ysign;
if (add & 64) // quads 1 or 3 need to swap x,y if (add & 64) { // quads 1 or 3 need to swap x,y
SkTSwap<SkFixed>(x, y); SkTSwap<SkFixed>(x, y);
}
unsigned result = add + atan_0_90(y, x); unsigned result = add + atan_0_90(y, x);
SkASSERT(result < 256); SkASSERT(result < 256);
return result; return result;
} }
void Sweep_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count) void Sweep_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
{
SkMatrix::MapXYProc proc = fDstToIndexProc; SkMatrix::MapXYProc proc = fDstToIndexProc;
const SkMatrix& matrix = fDstToIndex; const SkMatrix& matrix = fDstToIndex;
const SkPMColor* cache = this->getCache32(); const SkPMColor* cache = this->getCache32();
SkPoint srcPt; SkPoint srcPt;
if (fDstToIndexClass != kPerspective_MatrixClass) if (fDstToIndexClass != kPerspective_MatrixClass) {
{
proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
SkIntToScalar(y) + SK_ScalarHalf, &srcPt); SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
SkFixed dx, fx = SkScalarToFixed(srcPt.fX); SkFixed dx, fx = SkScalarToFixed(srcPt.fX);
SkFixed dy, fy = SkScalarToFixed(srcPt.fY); SkFixed dy, fy = SkScalarToFixed(srcPt.fY);
if (fDstToIndexClass == kFixedStepInX_MatrixClass) if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
{
SkFixed storage[2]; SkFixed storage[2];
(void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf, (void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf,
&storage[0], &storage[1]); &storage[0], &storage[1]);
dx = storage[0]; dx = storage[0];
dy = storage[1]; dy = storage[1];
} } else {
else
{
SkASSERT(fDstToIndexClass == kLinear_MatrixClass); SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = SkScalarToFixed(matrix.getScaleX()); dx = SkScalarToFixed(matrix.getScaleX());
dy = SkScalarToFixed(matrix.getSkewY()); dy = SkScalarToFixed(matrix.getSkewY());
} }
for (; count > 0; --count) for (; count > 0; --count) {
{
*dstC++ = cache[SkATan2_255(fy, fx)]; *dstC++ = cache[SkATan2_255(fy, fx)];
fx += dx; fx += dx;
fy += dy; fy += dy;
} }
} } else { // perspective case
else // perspective case for (int stop = x + count; x < stop; x++) {
{
for (int stop = x + count; x < stop; x++)
{
proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
SkIntToScalar(y) + SK_ScalarHalf, &srcPt); SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
@ -1936,49 +1897,40 @@ void Sweep_Gradient::shadeSpan(int x, int y, SkPMColor dstC[], int count)
} }
} }
void Sweep_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count) void Sweep_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count) {
{
SkMatrix::MapXYProc proc = fDstToIndexProc; SkMatrix::MapXYProc proc = fDstToIndexProc;
const SkMatrix& matrix = fDstToIndex; const SkMatrix& matrix = fDstToIndex;
const uint16_t* cache = this->getCache16(); const uint16_t* cache = this->getCache16();
int toggle = ((x ^ y) & 1) << kCache16Bits; int toggle = ((x ^ y) & 1) << kCache16Bits;
SkPoint srcPt; SkPoint srcPt;
if (fDstToIndexClass != kPerspective_MatrixClass) if (fDstToIndexClass != kPerspective_MatrixClass) {
{
proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
SkIntToScalar(y) + SK_ScalarHalf, &srcPt); SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
SkFixed dx, fx = SkScalarToFixed(srcPt.fX); SkFixed dx, fx = SkScalarToFixed(srcPt.fX);
SkFixed dy, fy = SkScalarToFixed(srcPt.fY); SkFixed dy, fy = SkScalarToFixed(srcPt.fY);
if (fDstToIndexClass == kFixedStepInX_MatrixClass) if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
{
SkFixed storage[2]; SkFixed storage[2];
(void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf, (void)matrix.fixedStepInX(SkIntToScalar(y) + SK_ScalarHalf,
&storage[0], &storage[1]); &storage[0], &storage[1]);
dx = storage[0]; dx = storage[0];
dy = storage[1]; dy = storage[1];
} } else {
else
{
SkASSERT(fDstToIndexClass == kLinear_MatrixClass); SkASSERT(fDstToIndexClass == kLinear_MatrixClass);
dx = SkScalarToFixed(matrix.getScaleX()); dx = SkScalarToFixed(matrix.getScaleX());
dy = SkScalarToFixed(matrix.getSkewY()); dy = SkScalarToFixed(matrix.getSkewY());
} }
for (; count > 0; --count) for (; count > 0; --count) {
{
int index = SkATan2_255(fy, fx) >> (8 - kCache16Bits); int index = SkATan2_255(fy, fx) >> (8 - kCache16Bits);
*dstC++ = cache[toggle + index]; *dstC++ = cache[toggle + index];
toggle ^= (1 << kCache16Bits); toggle ^= (1 << kCache16Bits);
fx += dx; fx += dx;
fy += dy; fy += dy;
} }
} } else { // perspective case
else // perspective case for (int stop = x + count; x < stop; x++) {
{
for (int stop = x + count; x < stop; x++)
{
proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
SkIntToScalar(y) + SK_ScalarHalf, &srcPt); SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
@ -1991,8 +1943,8 @@ void Sweep_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count)
} }
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// assumes colors is SkColor* and pos is SkScalar* // assumes colors is SkColor* and pos is SkScalar*
#define EXPAND_1_COLOR(count) \ #define EXPAND_1_COLOR(count) \
@ -2006,10 +1958,11 @@ void Sweep_Gradient::shadeSpan16(int x, int y, uint16_t dstC[], int count)
} \ } \
} while (0) } while (0)
SkShader* SkGradientShader::CreateLinear( const SkPoint pts[2], SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
const SkColor colors[], const SkScalar pos[], int colorCount, const SkColor colors[],
SkShader::TileMode mode, SkUnitMapper* mapper) const SkScalar pos[], int colorCount,
{ SkShader::TileMode mode,
SkUnitMapper* mapper) {
if (NULL == pts || NULL == colors || colorCount < 1) { if (NULL == pts || NULL == colors || colorCount < 1) {
return NULL; return NULL;
} }
@ -2019,10 +1972,11 @@ SkShader* SkGradientShader::CreateLinear( const SkPoint pts[2],
(pts, colors, pos, colorCount, mode, mapper)); (pts, colors, pos, colorCount, mode, mapper));
} }
SkShader* SkGradientShader::CreateRadial( const SkPoint& center, SkScalar radius, SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
const SkColor colors[], const SkScalar pos[], int colorCount, const SkColor colors[],
SkShader::TileMode mode, SkUnitMapper* mapper) const SkScalar pos[], int colorCount,
{ SkShader::TileMode mode,
SkUnitMapper* mapper) {
if (radius <= 0 || NULL == colors || colorCount < 1) { if (radius <= 0 || NULL == colors || colorCount < 1) {
return NULL; return NULL;
} }
@ -2040,22 +1994,21 @@ SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
const SkScalar pos[], const SkScalar pos[],
int colorCount, int colorCount,
SkShader::TileMode mode, SkShader::TileMode mode,
SkUnitMapper* mapper) SkUnitMapper* mapper) {
{
if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) { if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
return NULL; return NULL;
} }
EXPAND_1_COLOR(colorCount); EXPAND_1_COLOR(colorCount);
return SkNEW_ARGS(Two_Point_Radial_Gradient, return SkNEW_ARGS(Two_Point_Radial_Gradient,
(start, startRadius, end, endRadius, colors, pos, colorCount, mode, mapper)); (start, startRadius, end, endRadius, colors, pos,
colorCount, mode, mapper));
} }
SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy, SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
const SkColor colors[], const SkColor colors[],
const SkScalar pos[], const SkScalar pos[],
int count, SkUnitMapper* mapper) int count, SkUnitMapper* mapper) {
{
if (NULL == colors || count < 1) { if (NULL == colors || count < 1) {
return NULL; return NULL;
} }