| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 520 |
| 521 SkColor colors[kMaxRandomGradientColors]; | 521 SkColor colors[kMaxRandomGradientColors]; |
| 522 SkScalar stopsArray[kMaxRandomGradientColors]; | 522 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 523 SkScalar* stops = stopsArray; | 523 SkScalar* stops = stopsArray; |
| 524 SkShader::TileMode tm; | 524 SkShader::TileMode tm; |
| 525 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 525 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 526 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, | 526 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, |
| 527 colors, stops,
colorCount, | 527 colors, stops,
colorCount, |
| 528 tm)); | 528 tm)); |
| 529 SkPaint paint; | 529 SkPaint paint; |
| 530 return shader->asNewEffect(context, paint); | 530 return shader->asNewEffect(context, paint, NULL); |
| 531 } | 531 } |
| 532 | 532 |
| 533 ///////////////////////////////////////////////////////////////////// | 533 ///////////////////////////////////////////////////////////////////// |
| 534 | 534 |
| 535 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, | 535 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, |
| 536 const GrDrawEffect&, | 536 const GrDrawEffect&, |
| 537 EffectKey key, | 537 EffectKey key, |
| 538 const char* outputColor, | 538 const char* outputColor, |
| 539 const char* inputColor, | 539 const char* inputColor, |
| 540 const TransformedCoordsArray& coords, | 540 const TransformedCoordsArray& coords, |
| 541 const TextureSamplerArray& samplers) { | 541 const TextureSamplerArray& samplers) { |
| 542 this->emitUniforms(builder, key); | 542 this->emitUniforms(builder, key); |
| 543 SkString t = builder->ensureFSCoords2D(coords, 0); | 543 SkString t = builder->ensureFSCoords2D(coords, 0); |
| 544 t.append(".x"); | 544 t.append(".x"); |
| 545 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); | 545 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); |
| 546 } | 546 } |
| 547 | 547 |
| 548 ///////////////////////////////////////////////////////////////////// | 548 ///////////////////////////////////////////////////////////////////// |
| 549 | 549 |
| 550 GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) c
onst { | 550 GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&, |
| 551 const SkMatrix* localMatrix) const { |
| 551 SkASSERT(NULL != context); | 552 SkASSERT(NULL != context); |
| 552 SkMatrix matrix; | 553 SkMatrix matrix; |
| 553 if (!this->getLocalMatrix().invert(&matrix)) { | 554 if (!this->getLocalMatrix().invert(&matrix)) { |
| 554 return NULL; | 555 return NULL; |
| 555 } | 556 } |
| 557 if (localMatrix) { |
| 558 SkMatrix inv; |
| 559 if (!localMatrix->invert(&inv)) { |
| 560 return NULL; |
| 561 } |
| 562 matrix.postConcat(inv); |
| 563 } |
| 556 matrix.postConcat(fPtsToUnit); | 564 matrix.postConcat(fPtsToUnit); |
| 557 return GrLinearGradient::Create(context, *this, matrix, fTileMode); | 565 return GrLinearGradient::Create(context, *this, matrix, fTileMode); |
| 558 } | 566 } |
| 559 | 567 |
| 560 #else | 568 #else |
| 561 | 569 |
| 562 GrEffectRef* SkLinearGradient::asNewEffect(GrContext*, const SkPaint&) const { | 570 GrEffectRef* SkLinearGradient::asNewEffect(GrContext*, const SkPaint&) const { |
| 563 SkDEBUGFAIL("Should not call in GPU-less build"); | 571 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 564 return NULL; | 572 return NULL; |
| 565 } | 573 } |
| 566 | 574 |
| 567 #endif | 575 #endif |
| 568 | 576 |
| 569 #ifndef SK_IGNORE_TO_STRING | 577 #ifndef SK_IGNORE_TO_STRING |
| 570 void SkLinearGradient::toString(SkString* str) const { | 578 void SkLinearGradient::toString(SkString* str) const { |
| 571 str->append("SkLinearGradient ("); | 579 str->append("SkLinearGradient ("); |
| 572 | 580 |
| 573 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 581 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
| 574 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 582 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
| 575 | 583 |
| 576 this->INHERITED::toString(str); | 584 this->INHERITED::toString(str); |
| 577 | 585 |
| 578 str->append(")"); | 586 str->append(")"); |
| 579 } | 587 } |
| 580 #endif | 588 #endif |
| OLD | NEW |