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 "SkTwoPointRadialGradient.h" | 9 #include "SkTwoPointRadialGradient.h" |
10 | 10 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (info) { | 213 if (info) { |
214 commonAsAGradient(info); | 214 commonAsAGradient(info); |
215 info->fPoint[0] = fCenter1; | 215 info->fPoint[0] = fCenter1; |
216 info->fPoint[1] = fCenter2; | 216 info->fPoint[1] = fCenter2; |
217 info->fRadius[0] = fRadius1; | 217 info->fRadius[0] = fRadius1; |
218 info->fRadius[1] = fRadius2; | 218 info->fRadius[1] = fRadius2; |
219 } | 219 } |
220 return kRadial2_GradientType; | 220 return kRadial2_GradientType; |
221 } | 221 } |
222 | 222 |
223 size_t SkTwoPointRadialGradient::contextSize() const { | 223 void SkTwoPointRadialGradient::shadeSpan(int x, int y, SkPMColor* dstCParam, |
224 return sizeof(TwoPointRadialGradientContext); | 224 int count) { |
225 } | |
226 | |
227 bool SkTwoPointRadialGradient::validContext(const SkBitmap& device, const SkPain
t& paint, | |
228 const SkMatrix& matrix, SkMatrix* to
talInverse) const { | |
229 // For now, we might have divided by zero, so detect that. | |
230 if (0 == fDiffRadius) { | |
231 return false; | |
232 } | |
233 | |
234 return this->INHERITED::validContext(device, paint, matrix, totalInverse); | |
235 } | |
236 | |
237 SkShader::Context* SkTwoPointRadialGradient::createContext( | |
238 const SkBitmap& device, const SkPaint& paint, | |
239 const SkMatrix& matrix, void* storage) const { | |
240 if (!this->validContext(device, paint, matrix)) { | |
241 return NULL; | |
242 } | |
243 | |
244 return SkNEW_PLACEMENT_ARGS(storage, TwoPointRadialGradientContext, | |
245 (*this, device, paint, matrix)); | |
246 } | |
247 | |
248 SkTwoPointRadialGradient::TwoPointRadialGradientContext::TwoPointRadialGradientC
ontext( | |
249 const SkTwoPointRadialGradient& shader, const SkBitmap& device, | |
250 const SkPaint& paint, const SkMatrix& matrix) | |
251 : INHERITED(shader, device, paint, matrix) | |
252 { | |
253 // we don't have a span16 proc | |
254 fFlags &= ~kHasSpan16_Flag; | |
255 } | |
256 | |
257 void SkTwoPointRadialGradient::TwoPointRadialGradientContext::shadeSpan( | |
258 int x, int y, SkPMColor* dstCParam, int count) { | |
259 SkASSERT(count > 0); | 225 SkASSERT(count > 0); |
260 | 226 |
261 const SkTwoPointRadialGradient& twoPointRadialGradient = | |
262 static_cast<const SkTwoPointRadialGradient&>(fShader); | |
263 | |
264 SkPMColor* SK_RESTRICT dstC = dstCParam; | 227 SkPMColor* SK_RESTRICT dstC = dstCParam; |
265 | 228 |
266 // Zero difference between radii: fill with transparent black. | 229 // Zero difference between radii: fill with transparent black. |
267 if (twoPointRadialGradient.fDiffRadius == 0) { | 230 if (fDiffRadius == 0) { |
268 sk_bzero(dstC, count * sizeof(*dstC)); | 231 sk_bzero(dstC, count * sizeof(*dstC)); |
269 return; | 232 return; |
270 } | 233 } |
271 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 234 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
272 TileProc proc = twoPointRadialGradient.fTileProc; | 235 TileProc proc = fTileProc; |
273 const SkPMColor* SK_RESTRICT cache = fCache->getCache32(); | 236 const SkPMColor* SK_RESTRICT cache = this->getCache32(); |
274 | 237 |
275 SkScalar foura = twoPointRadialGradient.fA * 4; | 238 SkScalar foura = fA * 4; |
276 bool posRoot = twoPointRadialGradient.fDiffRadius < 0; | 239 bool posRoot = fDiffRadius < 0; |
277 if (fDstToIndexClass != kPerspective_MatrixClass) { | 240 if (fDstToIndexClass != kPerspective_MatrixClass) { |
278 SkPoint srcPt; | 241 SkPoint srcPt; |
279 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, | 242 dstProc(fDstToIndex, SkIntToScalar(x) + SK_ScalarHalf, |
280 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); | 243 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); |
281 SkScalar dx, fx = srcPt.fX; | 244 SkScalar dx, fx = srcPt.fX; |
282 SkScalar dy, fy = srcPt.fY; | 245 SkScalar dy, fy = srcPt.fY; |
283 | 246 |
284 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { | 247 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { |
285 SkFixed fixedX, fixedY; | 248 SkFixed fixedX, fixedY; |
286 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY); | 249 (void)fDstToIndex.fixedStepInX(SkIntToScalar(y), &fixedX, &fixedY); |
287 dx = SkFixedToScalar(fixedX); | 250 dx = SkFixedToScalar(fixedX); |
288 dy = SkFixedToScalar(fixedY); | 251 dy = SkFixedToScalar(fixedY); |
289 } else { | 252 } else { |
290 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); | 253 SkASSERT(fDstToIndexClass == kLinear_MatrixClass); |
291 dx = fDstToIndex.getScaleX(); | 254 dx = fDstToIndex.getScaleX(); |
292 dy = fDstToIndex.getSkewY(); | 255 dy = fDstToIndex.getSkewY(); |
293 } | 256 } |
294 SkScalar b = (SkScalarMul(twoPointRadialGradient.fDiff.fX, fx) + | 257 SkScalar b = (SkScalarMul(fDiff.fX, fx) + |
295 SkScalarMul(twoPointRadialGradient.fDiff.fY, fy) - | 258 SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2; |
296 twoPointRadialGradient.fStartRadius) * 2; | 259 SkScalar db = (SkScalarMul(fDiff.fX, dx) + |
297 SkScalar db = (SkScalarMul(twoPointRadialGradient.fDiff.fX, dx) + | 260 SkScalarMul(fDiff.fY, dy)) * 2; |
298 SkScalarMul(twoPointRadialGradient.fDiff.fY, dy)) * 2; | |
299 | 261 |
300 TwoPointRadialShadeProc shadeProc = shadeSpan_twopoint_repeat; | 262 TwoPointRadialShadeProc shadeProc = shadeSpan_twopoint_repeat; |
301 if (SkShader::kClamp_TileMode == twoPointRadialGradient.fTileMode) { | 263 if (SkShader::kClamp_TileMode == fTileMode) { |
302 shadeProc = shadeSpan_twopoint_clamp; | 264 shadeProc = shadeSpan_twopoint_clamp; |
303 } else if (SkShader::kMirror_TileMode == twoPointRadialGradient.fTileMod
e) { | 265 } else if (SkShader::kMirror_TileMode == fTileMode) { |
304 shadeProc = shadeSpan_twopoint_mirror; | 266 shadeProc = shadeSpan_twopoint_mirror; |
305 } else { | 267 } else { |
306 SkASSERT(SkShader::kRepeat_TileMode == twoPointRadialGradient.fTileM
ode); | 268 SkASSERT(SkShader::kRepeat_TileMode == fTileMode); |
307 } | 269 } |
308 (*shadeProc)(fx, dx, fy, dy, b, db, | 270 (*shadeProc)(fx, dx, fy, dy, b, db, |
309 twoPointRadialGradient.fSr2D2, foura, | 271 fSr2D2, foura, fOneOverTwoA, posRoot, |
310 twoPointRadialGradient.fOneOverTwoA, posRoot, | |
311 dstC, cache, count); | 272 dstC, cache, count); |
312 } else { // perspective case | 273 } else { // perspective case |
313 SkScalar dstX = SkIntToScalar(x); | 274 SkScalar dstX = SkIntToScalar(x); |
314 SkScalar dstY = SkIntToScalar(y); | 275 SkScalar dstY = SkIntToScalar(y); |
315 for (; count > 0; --count) { | 276 for (; count > 0; --count) { |
316 SkPoint srcPt; | 277 SkPoint srcPt; |
317 dstProc(fDstToIndex, dstX, dstY, &srcPt); | 278 dstProc(fDstToIndex, dstX, dstY, &srcPt); |
318 SkScalar fx = srcPt.fX; | 279 SkScalar fx = srcPt.fX; |
319 SkScalar fy = srcPt.fY; | 280 SkScalar fy = srcPt.fY; |
320 SkScalar b = (SkScalarMul(twoPointRadialGradient.fDiff.fX, fx) + | 281 SkScalar b = (SkScalarMul(fDiff.fX, fx) + |
321 SkScalarMul(twoPointRadialGradient.fDiff.fY, fy) - | 282 SkScalarMul(fDiff.fY, fy) - fStartRadius) * 2; |
322 twoPointRadialGradient.fStartRadius) * 2; | 283 SkFixed t = two_point_radial(b, fx, fy, fSr2D2, foura, |
323 SkFixed t = two_point_radial(b, fx, fy, twoPointRadialGradient.fSr2D
2, foura, | 284 fOneOverTwoA, posRoot); |
324 twoPointRadialGradient.fOneOverTwoA, po
sRoot); | |
325 SkFixed index = proc(t); | 285 SkFixed index = proc(t); |
326 SkASSERT(index <= 0xFFFF); | 286 SkASSERT(index <= 0xFFFF); |
327 *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift]; | 287 *dstC++ = cache[index >> SkGradientShaderBase::kCache32Shift]; |
328 dstX += SK_Scalar1; | 288 dstX += SK_Scalar1; |
329 } | 289 } |
330 } | 290 } |
331 } | 291 } |
332 | 292 |
| 293 bool SkTwoPointRadialGradient::setContext( const SkBitmap& device, |
| 294 const SkPaint& paint, |
| 295 const SkMatrix& matrix){ |
| 296 // For now, we might have divided by zero, so detect that |
| 297 if (0 == fDiffRadius) { |
| 298 return false; |
| 299 } |
| 300 |
| 301 if (!this->INHERITED::setContext(device, paint, matrix)) { |
| 302 return false; |
| 303 } |
| 304 |
| 305 // we don't have a span16 proc |
| 306 fFlags &= ~kHasSpan16_Flag; |
| 307 return true; |
| 308 } |
| 309 |
333 #ifndef SK_IGNORE_TO_STRING | 310 #ifndef SK_IGNORE_TO_STRING |
334 void SkTwoPointRadialGradient::toString(SkString* str) const { | 311 void SkTwoPointRadialGradient::toString(SkString* str) const { |
335 str->append("SkTwoPointRadialGradient: ("); | 312 str->append("SkTwoPointRadialGradient: ("); |
336 | 313 |
337 str->append("center1: ("); | 314 str->append("center1: ("); |
338 str->appendScalar(fCenter1.fX); | 315 str->appendScalar(fCenter1.fX); |
339 str->append(", "); | 316 str->append(", "); |
340 str->appendScalar(fCenter1.fY); | 317 str->appendScalar(fCenter1.fY); |
341 str->append(") radius1: "); | 318 str->append(") radius1: "); |
342 str->appendScalar(fRadius1); | 319 str->appendScalar(fRadius1); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 } | 682 } |
706 | 683 |
707 #else | 684 #else |
708 | 685 |
709 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c
onst { | 686 GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext*, const SkPaint&) c
onst { |
710 SkDEBUGFAIL("Should not call in GPU-less build"); | 687 SkDEBUGFAIL("Should not call in GPU-less build"); |
711 return NULL; | 688 return NULL; |
712 } | 689 } |
713 | 690 |
714 #endif | 691 #endif |
OLD | NEW |