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 "SkRadialGradient_Table.h" | 10 #include "SkRadialGradient_Table.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 : SkGradientShaderBase(desc), | 150 : SkGradientShaderBase(desc), |
151 fCenter(center), | 151 fCenter(center), |
152 fRadius(radius) | 152 fRadius(radius) |
153 { | 153 { |
154 // make sure our table is insync with our current #define for kSQRT_TABLE_SI
ZE | 154 // make sure our table is insync with our current #define for kSQRT_TABLE_SI
ZE |
155 SkASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE); | 155 SkASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE); |
156 | 156 |
157 rad_to_unit_matrix(center, radius, &fPtsToUnit); | 157 rad_to_unit_matrix(center, radius, &fPtsToUnit); |
158 } | 158 } |
159 | 159 |
160 void SkRadialGradient::shadeSpan16(int x, int y, uint16_t* dstCParam, | 160 size_t SkRadialGradient::contextSize() const { |
161 int count) { | 161 return sizeof(RadialGradientContext); |
| 162 } |
| 163 |
| 164 SkShader::Context* SkRadialGradient::createContext(const SkBitmap& device, const
SkPaint& paint, |
| 165 const SkMatrix& matrix, void*
storage) const { |
| 166 if (!this->validContext(device, paint, matrix)) { |
| 167 return NULL; |
| 168 } |
| 169 |
| 170 return SkNEW_PLACEMENT_ARGS(storage, RadialGradientContext, (*this, device,
paint, matrix)); |
| 171 } |
| 172 |
| 173 SkRadialGradient::RadialGradientContext::RadialGradientContext( |
| 174 const SkRadialGradient& shader, const SkBitmap& device, |
| 175 const SkPaint& paint, const SkMatrix& matrix) |
| 176 : INHERITED(shader, device, paint, matrix) {} |
| 177 |
| 178 void SkRadialGradient::RadialGradientContext::shadeSpan16(int x, int y, uint16_t
* dstCParam, |
| 179 int count) { |
162 SkASSERT(count > 0); | 180 SkASSERT(count > 0); |
163 | 181 |
| 182 const SkRadialGradient& radialGradient = static_cast<const SkRadialGradient&
>(fShader); |
| 183 |
164 uint16_t* SK_RESTRICT dstC = dstCParam; | 184 uint16_t* SK_RESTRICT dstC = dstCParam; |
165 | 185 |
166 SkPoint srcPt; | 186 SkPoint srcPt; |
167 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 187 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
168 TileProc proc = fTileProc; | 188 TileProc proc = radialGradient.fTileProc; |
169 const uint16_t* SK_RESTRICT cache = this->getCache16(); | 189 const uint16_t* SK_RESTRICT cache = fCache->getCache16(); |
170 int toggle = init_dither_toggle16(x, y); | 190 int toggle = init_dither_toggle16(x, y); |
171 | 191 |
172 if (fDstToIndexClass != kPerspective_MatrixClass) { | 192 if (fDstToIndexClass != kPerspective_MatrixClass) { |
173 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, | 193 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, |
174 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); | 194 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
175 | 195 |
176 SkScalar sdx = fDstToIndex.getScaleX(); | 196 SkScalar sdx = fDstToIndex.getScaleX(); |
177 SkScalar sdy = fDstToIndex.getSkewY(); | 197 SkScalar sdy = fDstToIndex.getSkewY(); |
178 | 198 |
179 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { | 199 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
180 SkFixed storage[2]; | 200 SkFixed storage[2]; |
181 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), | 201 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), |
182 &storage[0], &storage[1]); | 202 &storage[0], &storage[1]); |
183 sdx = SkFixedToScalar(storage[0]); | 203 sdx = SkFixedToScalar(storage[0]); |
184 sdy = SkFixedToScalar(storage[1]); | 204 sdy = SkFixedToScalar(storage[1]); |
185 } else { | 205 } else { |
186 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); | 206 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
187 } | 207 } |
188 | 208 |
189 RadialShade16Proc shadeProc = shadeSpan16_radial_repeat; | 209 RadialShade16Proc shadeProc = shadeSpan16_radial_repeat; |
190 if (SkShader::kClamp_TileMode == fTileMode) { | 210 if (SkShader::kClamp_TileMode == radialGradient.fTileMode) { |
191 shadeProc = shadeSpan16_radial_clamp; | 211 shadeProc = shadeSpan16_radial_clamp; |
192 } else if (SkShader::kMirror_TileMode == fTileMode) { | 212 } else if (SkShader::kMirror_TileMode == radialGradient.fTileMode) { |
193 shadeProc = shadeSpan16_radial_mirror; | 213 shadeProc = shadeSpan16_radial_mirror; |
194 } else { | 214 } else { |
195 SkASSERT(SkShader::kRepeat_TileMode == fTileMode); | 215 SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); |
196 } | 216 } |
197 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, | 217 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, |
198 cache, toggle, count); | 218 cache, toggle, count); |
199 } else { // perspective case | 219 } else { // perspective case |
200 SkScalar dstX = SkIntToScalar(x); | 220 SkScalar dstX = SkIntToScalar(x); |
201 SkScalar dstY = SkIntToScalar(y); | 221 SkScalar dstY = SkIntToScalar(y); |
202 do { | 222 do { |
203 dstProc(fDstToIndex, dstX, dstY, &srcPt); | 223 dstProc(fDstToIndex, dstX, dstY, &srcPt); |
204 unsigned fi = proc(SkScalarToFixed(srcPt.length())); | 224 unsigned fi = proc(SkScalarToFixed(srcPt.length())); |
205 SkASSERT(fi <= 0xFFFF); | 225 SkASSERT(fi <= 0xFFFF); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 402 } |
383 | 403 |
384 void shadeSpan_radial_repeat(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, | 404 void shadeSpan_radial_repeat(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar dy, |
385 SkPMColor* SK_RESTRICT dstC, const SkPMColor* SK_RE
STRICT cache, | 405 SkPMColor* SK_RESTRICT dstC, const SkPMColor* SK_RE
STRICT cache, |
386 int count, int toggle) { | 406 int count, int toggle) { |
387 shadeSpan_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, cou
nt, toggle); | 407 shadeSpan_radial<repeat_tileproc_nonstatic>(fx, dx, fy, dy, dstC, cache, cou
nt, toggle); |
388 } | 408 } |
389 | 409 |
390 } // namespace | 410 } // namespace |
391 | 411 |
392 void SkRadialGradient::shadeSpan(int x, int y, | 412 void SkRadialGradient::RadialGradientContext::shadeSpan(int x, int y, |
393 SkPMColor* SK_RESTRICT dstC, int count) { | 413 SkPMColor* SK_RESTRICT d
stC, int count) { |
394 SkASSERT(count > 0); | 414 SkASSERT(count > 0); |
395 | 415 |
| 416 const SkRadialGradient& radialGradient = static_cast<const SkRadialGradient&
>(fShader); |
| 417 |
396 SkPoint srcPt; | 418 SkPoint srcPt; |
397 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 419 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
398 TileProc proc = fTileProc; | 420 TileProc proc = radialGradient.fTileProc; |
399 const SkPMColor* SK_RESTRICT cache = this->getCache32(); | 421 const SkPMColor* SK_RESTRICT cache = fCache->getCache32(); |
400 int toggle = init_dither_toggle(x, y); | 422 int toggle = init_dither_toggle(x, y); |
401 | 423 |
402 if (fDstToIndexClass != kPerspective_MatrixClass) { | 424 if (fDstToIndexClass != kPerspective_MatrixClass) { |
403 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, | 425 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, |
404 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); | 426 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
405 SkScalar sdx = fDstToIndex.getScaleX(); | 427 SkScalar sdx = fDstToIndex.getScaleX(); |
406 SkScalar sdy = fDstToIndex.getSkewY(); | 428 SkScalar sdy = fDstToIndex.getSkewY(); |
407 | 429 |
408 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { | 430 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
409 SkFixed storage[2]; | 431 SkFixed storage[2]; |
410 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), | 432 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), |
411 &storage[0], &storage[1]); | 433 &storage[0], &storage[1]); |
412 sdx = SkFixedToScalar(storage[0]); | 434 sdx = SkFixedToScalar(storage[0]); |
413 sdy = SkFixedToScalar(storage[1]); | 435 sdy = SkFixedToScalar(storage[1]); |
414 } else { | 436 } else { |
415 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); | 437 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
416 } | 438 } |
417 | 439 |
418 RadialShadeProc shadeProc = shadeSpan_radial_repeat; | 440 RadialShadeProc shadeProc = shadeSpan_radial_repeat; |
419 if (SkShader::kClamp_TileMode == fTileMode) { | 441 if (SkShader::kClamp_TileMode == radialGradient.fTileMode) { |
420 shadeProc = shadeSpan_radial_clamp; | 442 shadeProc = shadeSpan_radial_clamp; |
421 } else if (SkShader::kMirror_TileMode == fTileMode) { | 443 } else if (SkShader::kMirror_TileMode == radialGradient.fTileMode) { |
422 shadeProc = shadeSpan_radial_mirror; | 444 shadeProc = shadeSpan_radial_mirror; |
423 } else { | 445 } else { |
424 SkASSERT(SkShader::kRepeat_TileMode == fTileMode); | 446 SkASSERT(SkShader::kRepeat_TileMode == radialGradient.fTileMode); |
425 } | 447 } |
426 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, cache, count, toggle); | 448 (*shadeProc)(srcPt.fX, sdx, srcPt.fY, sdy, dstC, cache, count, toggle); |
427 } else { // perspective case | 449 } else { // perspective case |
428 SkScalar dstX = SkIntToScalar(x); | 450 SkScalar dstX = SkIntToScalar(x); |
429 SkScalar dstY = SkIntToScalar(y); | 451 SkScalar dstY = SkIntToScalar(y); |
430 do { | 452 do { |
431 dstProc(fDstToIndex, dstX, dstY, &srcPt); | 453 dstProc(fDstToIndex, dstX, dstY, &srcPt); |
432 unsigned fi = proc(SkScalarToFixed(srcPt.length())); | 454 unsigned fi = proc(SkScalarToFixed(srcPt.length())); |
433 SkASSERT(fi <= 0xFFFF); | 455 SkASSERT(fi <= 0xFFFF); |
434 *dstC++ = cache[fi >> SkGradientShaderBase::kCache32Shift]; | 456 *dstC++ = cache[fi >> SkGradientShaderBase::kCache32Shift]; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 str->appendScalar(fCenter.fY); | 595 str->appendScalar(fCenter.fY); |
574 str->append(") radius: "); | 596 str->append(") radius: "); |
575 str->appendScalar(fRadius); | 597 str->appendScalar(fRadius); |
576 str->append(" "); | 598 str->append(" "); |
577 | 599 |
578 this->INHERITED::toString(str); | 600 this->INHERITED::toString(str); |
579 | 601 |
580 str->append(")"); | 602 str->append(")"); |
581 } | 603 } |
582 #endif | 604 #endif |
OLD | NEW |