| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkLinearGradient.h" | 8 #include "SkLinearGradient.h" |
| 9 | 9 |
| 10 static inline int repeat_bits(int x, const int bits) { | 10 static inline int repeat_bits(int x, const int bits) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 , fStart(buffer.readPoint()) | 64 , fStart(buffer.readPoint()) |
| 65 , fEnd(buffer.readPoint()) { | 65 , fEnd(buffer.readPoint()) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { | 68 void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { |
| 69 this->INHERITED::flatten(buffer); | 69 this->INHERITED::flatten(buffer); |
| 70 buffer.writePoint(fStart); | 70 buffer.writePoint(fStart); |
| 71 buffer.writePoint(fEnd); | 71 buffer.writePoint(fEnd); |
| 72 } | 72 } |
| 73 | 73 |
| 74 #if 0 |
| 74 bool SkLinearGradient::setContext(const SkBitmap& device, const SkPaint& paint, | 75 bool SkLinearGradient::setContext(const SkBitmap& device, const SkPaint& paint, |
| 75 const SkMatrix& matrix) { | 76 const SkMatrix& matrix) { |
| 76 if (!this->INHERITED::setContext(device, paint, matrix)) { | 77 if (!this->INHERITED::setContext(device, paint, matrix)) { |
| 77 return false; | 78 return false; |
| 78 } | 79 } |
| 79 | 80 |
| 80 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; | 81 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; |
| 81 if ((fDstToIndex.getType() & ~mask) == 0) { | 82 if ((fDstToIndex.getType() & ~mask) == 0) { |
| 82 // when we dither, we are (usually) not const-in-Y | 83 // when we dither, we are (usually) not const-in-Y |
| 83 if ((fFlags & SkShader::kHasSpan16_Flag) && !paint.isDither()) { | 84 if ((fFlags & SkShader::kHasSpan16_Flag) && !paint.isDither()) { |
| 84 // only claim this if we do have a 16bit mode (i.e. none of our | 85 // only claim this if we do have a 16bit mode (i.e. none of our |
| 85 // colors have alpha), and if we are not dithering (which obviously | 86 // colors have alpha), and if we are not dithering (which obviously |
| 86 // is not const in Y). | 87 // is not const in Y). |
| 87 fFlags |= SkShader::kConstInY16_Flag; | 88 fFlags |= SkShader::kConstInY16_Flag; |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 return true; | 91 return true; |
| 91 } | 92 } |
| 93 #endif |
| 92 | 94 |
| 93 #define NO_CHECK_ITER \ | 95 #define NO_CHECK_ITER \ |
| 94 do { \ | 96 do { \ |
| 95 unsigned fi = fx >> SkGradientShaderBase::kCache32Shift; \ | 97 unsigned fi = fx >> SkGradientShaderBase::kCache32Shift; \ |
| 96 SkASSERT(fi <= 0xFF); \ | 98 SkASSERT(fi <= 0xFF); \ |
| 97 fx += dx; \ | 99 fx += dx; \ |
| 98 *dstC++ = cache[toggle + fi]; \ | 100 *dstC++ = cache[toggle + fi]; \ |
| 99 toggle = next_dither_toggle(toggle); \ | 101 toggle = next_dither_toggle(toggle); \ |
| 100 } while (0) | 102 } while (0) |
| 101 | 103 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 unsigned fi = repeat_8bits(fx >> 8); | 191 unsigned fi = repeat_8bits(fx >> 8); |
| 190 SkASSERT(fi <= 0xFF); | 192 SkASSERT(fi <= 0xFF); |
| 191 fx += dx; | 193 fx += dx; |
| 192 *dstC++ = cache[toggle + fi]; | 194 *dstC++ = cache[toggle + fi]; |
| 193 toggle = next_dither_toggle(toggle); | 195 toggle = next_dither_toggle(toggle); |
| 194 } while (--count != 0); | 196 } while (--count != 0); |
| 195 } | 197 } |
| 196 | 198 |
| 197 } | 199 } |
| 198 | 200 |
| 201 #if 0 |
| 199 void SkLinearGradient::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC, | 202 void SkLinearGradient::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC, |
| 200 int count) { | 203 int count) { |
| 201 SkASSERT(count > 0); | 204 SkASSERT(count > 0); |
| 202 | 205 |
| 203 SkPoint srcPt; | 206 SkPoint srcPt; |
| 204 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 207 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
| 205 TileProc proc = fTileProc; | 208 TileProc proc = fTileProc; |
| 206 const SkPMColor* SK_RESTRICT cache = this->getCache32(); | 209 const SkPMColor* SK_RESTRICT cache = this->getCache32(); |
| 207 int toggle = init_dither_toggle(x, y); | 210 int toggle = init_dither_toggle(x, y); |
| 208 | 211 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 237 do { | 240 do { |
| 238 dstProc(fDstToIndex, dstX, dstY, &srcPt); | 241 dstProc(fDstToIndex, dstX, dstY, &srcPt); |
| 239 unsigned fi = proc(SkScalarToFixed(srcPt.fX)); | 242 unsigned fi = proc(SkScalarToFixed(srcPt.fX)); |
| 240 SkASSERT(fi <= 0xFFFF); | 243 SkASSERT(fi <= 0xFFFF); |
| 241 *dstC++ = cache[toggle + (fi >> kCache32Shift)]; | 244 *dstC++ = cache[toggle + (fi >> kCache32Shift)]; |
| 242 toggle = next_dither_toggle(toggle); | 245 toggle = next_dither_toggle(toggle); |
| 243 dstX += SK_Scalar1; | 246 dstX += SK_Scalar1; |
| 244 } while (--count != 0); | 247 } while (--count != 0); |
| 245 } | 248 } |
| 246 } | 249 } |
| 250 #endif |
| 247 | 251 |
| 248 SkShader::BitmapType SkLinearGradient::asABitmap(SkBitmap* bitmap, | 252 SkShader::BitmapType SkLinearGradient::asABitmap(SkBitmap* bitmap, |
| 249 SkMatrix* matrix, | 253 SkMatrix* matrix, |
| 250 TileMode xy[]) const { | 254 TileMode xy[]) const { |
| 251 if (bitmap) { | 255 if (bitmap) { |
| 252 this->getGradientTableBitmap(bitmap); | 256 this->getGradientTableBitmap(bitmap); |
| 253 } | 257 } |
| 254 if (matrix) { | 258 if (matrix) { |
| 255 matrix->preConcat(fPtsToUnit); | 259 matrix->preConcat(fPtsToUnit); |
| 256 } | 260 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 unsigned fi = repeat_bits(fx >> SkGradientShaderBase::kCache16Shift, | 374 unsigned fi = repeat_bits(fx >> SkGradientShaderBase::kCache16Shift, |
| 371 SkGradientShaderBase::kCache16Bits); | 375 SkGradientShaderBase::kCache16Bits); |
| 372 SkASSERT(fi < SkGradientShaderBase::kCache16Count); | 376 SkASSERT(fi < SkGradientShaderBase::kCache16Count); |
| 373 fx += dx; | 377 fx += dx; |
| 374 *dstC++ = cache[toggle + fi]; | 378 *dstC++ = cache[toggle + fi]; |
| 375 toggle = next_dither_toggle16(toggle); | 379 toggle = next_dither_toggle16(toggle); |
| 376 } while (--count != 0); | 380 } while (--count != 0); |
| 377 } | 381 } |
| 378 } | 382 } |
| 379 | 383 |
| 384 #if 0 |
| 380 static bool fixed_nearly_zero(SkFixed x) { | 385 static bool fixed_nearly_zero(SkFixed x) { |
| 381 return SkAbs32(x) < (SK_Fixed1 >> 12); | 386 return SkAbs32(x) < (SK_Fixed1 >> 12); |
| 382 } | 387 } |
| 383 | 388 |
| 384 void SkLinearGradient::shadeSpan16(int x, int y, | 389 void SkLinearGradient::shadeSpan16(int x, int y, |
| 385 uint16_t* SK_RESTRICT dstC, int count) { | 390 uint16_t* SK_RESTRICT dstC, int count) { |
| 386 SkASSERT(count > 0); | 391 SkASSERT(count > 0); |
| 387 | 392 |
| 388 SkPoint srcPt; | 393 SkPoint srcPt; |
| 389 SkMatrix::MapXYProc dstProc = fDstToIndexProc; | 394 SkMatrix::MapXYProc dstProc = fDstToIndexProc; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 SkASSERT(fi <= 0xFFFF); | 430 SkASSERT(fi <= 0xFFFF); |
| 426 | 431 |
| 427 int index = fi >> kCache16Shift; | 432 int index = fi >> kCache16Shift; |
| 428 *dstC++ = cache[toggle + index]; | 433 *dstC++ = cache[toggle + index]; |
| 429 toggle = next_dither_toggle16(toggle); | 434 toggle = next_dither_toggle16(toggle); |
| 430 | 435 |
| 431 dstX += SK_Scalar1; | 436 dstX += SK_Scalar1; |
| 432 } while (--count != 0); | 437 } while (--count != 0); |
| 433 } | 438 } |
| 434 } | 439 } |
| 440 #endif |
| 435 | 441 |
| 436 #if SK_SUPPORT_GPU | 442 #if SK_SUPPORT_GPU |
| 437 | 443 |
| 438 #include "GrTBackendEffectFactory.h" | 444 #include "GrTBackendEffectFactory.h" |
| 439 | 445 |
| 440 ///////////////////////////////////////////////////////////////////// | 446 ///////////////////////////////////////////////////////////////////// |
| 441 | 447 |
| 442 class GrGLLinearGradient : public GrGLGradientEffect { | 448 class GrGLLinearGradient : public GrGLGradientEffect { |
| 443 public: | 449 public: |
| 444 | 450 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 str->append("SkLinearGradient ("); | 567 str->append("SkLinearGradient ("); |
| 562 | 568 |
| 563 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 569 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
| 564 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 570 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
| 565 | 571 |
| 566 this->INHERITED::toString(str); | 572 this->INHERITED::toString(str); |
| 567 | 573 |
| 568 str->append(")"); | 574 str->append(")"); |
| 569 } | 575 } |
| 570 #endif | 576 #endif |
| OLD | NEW |