| 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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 dstX += SK_Scalar1; | 451 dstX += SK_Scalar1; |
| 452 } while (--count != 0); | 452 } while (--count != 0); |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 | 455 |
| 456 ///////////////////////////////////////////////////////////////////// | 456 ///////////////////////////////////////////////////////////////////// |
| 457 | 457 |
| 458 #if SK_SUPPORT_GPU | 458 #if SK_SUPPORT_GPU |
| 459 | 459 |
| 460 #include "GrTBackendEffectFactory.h" | 460 #include "GrTBackendEffectFactory.h" |
| 461 #include "SkGr.h" |
| 461 | 462 |
| 462 class GrGLRadialGradient : public GrGLGradientEffect { | 463 class GrGLRadialGradient : public GrGLGradientEffect { |
| 463 public: | 464 public: |
| 464 | 465 |
| 465 GrGLRadialGradient(const GrBackendEffectFactory& factory, | 466 GrGLRadialGradient(const GrBackendEffectFactory& factory, |
| 466 const GrDrawEffect&) : INHERITED (factory) { } | 467 const GrDrawEffect&) : INHERITED (factory) { } |
| 467 virtual ~GrGLRadialGradient() { } | 468 virtual ~GrGLRadialGradient() { } |
| 468 | 469 |
| 469 virtual void emitCode(GrGLShaderBuilder*, | 470 virtual void emitCode(GrGLShaderBuilder*, |
| 470 const GrDrawEffect&, | 471 const GrDrawEffect&, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 | 532 |
| 532 SkColor colors[kMaxRandomGradientColors]; | 533 SkColor colors[kMaxRandomGradientColors]; |
| 533 SkScalar stopsArray[kMaxRandomGradientColors]; | 534 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 534 SkScalar* stops = stopsArray; | 535 SkScalar* stops = stopsArray; |
| 535 SkShader::TileMode tm; | 536 SkShader::TileMode tm; |
| 536 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 537 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
| 537 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, | 538 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, |
| 538 colors, stops,
colorCount, | 539 colors, stops,
colorCount, |
| 539 tm)); | 540 tm)); |
| 540 SkPaint paint; | 541 SkPaint paint; |
| 541 return shader->asNewEffect(context, paint, NULL); | 542 GrColor grColor; |
| 543 GrEffectRef* effect; |
| 544 shader->asNewEffect(context, paint, NULL, &grColor, &effect); |
| 545 return effect; |
| 542 } | 546 } |
| 543 | 547 |
| 544 ///////////////////////////////////////////////////////////////////// | 548 ///////////////////////////////////////////////////////////////////// |
| 545 | 549 |
| 546 void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder, | 550 void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder, |
| 547 const GrDrawEffect&, | 551 const GrDrawEffect&, |
| 548 EffectKey key, | 552 EffectKey key, |
| 549 const char* outputColor, | 553 const char* outputColor, |
| 550 const char* inputColor, | 554 const char* inputColor, |
| 551 const TransformedCoordsArray& coords, | 555 const TransformedCoordsArray& coords, |
| 552 const TextureSamplerArray& samplers) { | 556 const TextureSamplerArray& samplers) { |
| 553 this->emitUniforms(builder, key); | 557 this->emitUniforms(builder, key); |
| 554 SkString t("length("); | 558 SkString t("length("); |
| 555 t.append(builder->ensureFSCoords2D(coords, 0)); | 559 t.append(builder->ensureFSCoords2D(coords, 0)); |
| 556 t.append(")"); | 560 t.append(")"); |
| 557 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); | 561 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); |
| 558 } | 562 } |
| 559 | 563 |
| 560 ///////////////////////////////////////////////////////////////////// | 564 ///////////////////////////////////////////////////////////////////// |
| 561 | 565 |
| 562 GrEffectRef* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&, | 566 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 563 const SkMatrix* localMatrix) const { | 567 const SkMatrix* localMatrix, GrColor* grColor
, |
| 568 GrEffectRef** grEffect) const { |
| 564 SkASSERT(NULL != context); | 569 SkASSERT(NULL != context); |
| 565 | 570 |
| 566 SkMatrix matrix; | 571 SkMatrix matrix; |
| 567 if (!this->getLocalMatrix().invert(&matrix)) { | 572 if (!this->getLocalMatrix().invert(&matrix)) { |
| 568 return NULL; | 573 return false; |
| 569 } | 574 } |
| 570 if (localMatrix) { | 575 if (localMatrix) { |
| 571 SkMatrix inv; | 576 SkMatrix inv; |
| 572 if (!localMatrix->invert(&inv)) { | 577 if (!localMatrix->invert(&inv)) { |
| 573 return NULL; | 578 return false; |
| 574 } | 579 } |
| 575 matrix.postConcat(inv); | 580 matrix.postConcat(inv); |
| 576 } | 581 } |
| 577 matrix.postConcat(fPtsToUnit); | 582 matrix.postConcat(fPtsToUnit); |
| 578 return GrRadialGradient::Create(context, *this, matrix, fTileMode); | 583 |
| 584 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 585 *grEffect = GrRadialGradient::Create(context, *this, matrix, fTileMode); |
| 586 |
| 587 return true; |
| 579 } | 588 } |
| 580 | 589 |
| 581 #else | 590 #else |
| 582 | 591 |
| 583 GrEffectRef* SkRadialGradient::asNewEffect(GrContext*, const SkPaint&, const SkM
atrix*) const { | 592 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 593 const SkMatrix* localMatrix, GrColor* grColor
, |
| 594 GrEffectRef** grEffect) const { |
| 584 SkDEBUGFAIL("Should not call in GPU-less build"); | 595 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 585 return NULL; | 596 return false; |
| 586 } | 597 } |
| 587 | 598 |
| 588 #endif | 599 #endif |
| 589 | 600 |
| 590 #ifndef SK_IGNORE_TO_STRING | 601 #ifndef SK_IGNORE_TO_STRING |
| 591 void SkRadialGradient::toString(SkString* str) const { | 602 void SkRadialGradient::toString(SkString* str) const { |
| 592 str->append("SkRadialGradient: ("); | 603 str->append("SkRadialGradient: ("); |
| 593 | 604 |
| 594 str->append("center: ("); | 605 str->append("center: ("); |
| 595 str->appendScalar(fCenter.fX); | 606 str->appendScalar(fCenter.fX); |
| 596 str->append(", "); | 607 str->append(", "); |
| 597 str->appendScalar(fCenter.fY); | 608 str->appendScalar(fCenter.fY); |
| 598 str->append(") radius: "); | 609 str->append(") radius: "); |
| 599 str->appendScalar(fRadius); | 610 str->appendScalar(fRadius); |
| 600 str->append(" "); | 611 str->append(" "); |
| 601 | 612 |
| 602 this->INHERITED::toString(str); | 613 this->INHERITED::toString(str); |
| 603 | 614 |
| 604 str->append(")"); | 615 str->append(")"); |
| 605 } | 616 } |
| 606 #endif | 617 #endif |
| OLD | NEW |