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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 SkScalar stopsArray[kMaxRandomGradientColors]; | 538 SkScalar stopsArray[kMaxRandomGradientColors]; |
539 SkScalar* stops = stopsArray; | 539 SkScalar* stops = stopsArray; |
540 SkShader::TileMode tm; | 540 SkShader::TileMode tm; |
541 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 541 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
542 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, | 542 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, |
543 colors, stops,
colorCount, | 543 colors, stops,
colorCount, |
544 tm)); | 544 tm)); |
545 SkPaint paint; | 545 SkPaint paint; |
546 GrColor paintColor; | 546 GrColor paintColor; |
547 GrFragmentProcessor* fp; | 547 GrFragmentProcessor* fp; |
548 SkAssertResult(shader->asFragmentProcessor(context, paint, NULL, &paintColor
, &fp)); | 548 SkAssertResult(shader->asFragmentProcessor(context, paint, |
| 549 GrProcessorUnitTest::TestMatrix(r
andom), NULL, |
| 550 &paintColor, &fp)); |
549 return fp; | 551 return fp; |
550 } | 552 } |
551 | 553 |
552 ///////////////////////////////////////////////////////////////////// | 554 ///////////////////////////////////////////////////////////////////// |
553 | 555 |
554 void GrGLRadialGradient::emitCode(GrGLFPBuilder* builder, | 556 void GrGLRadialGradient::emitCode(GrGLFPBuilder* builder, |
555 const GrFragmentProcessor& fp, | 557 const GrFragmentProcessor& fp, |
556 const char* outputColor, | 558 const char* outputColor, |
557 const char* inputColor, | 559 const char* inputColor, |
558 const TransformedCoordsArray& coords, | 560 const TransformedCoordsArray& coords, |
559 const TextureSamplerArray& samplers) { | 561 const TextureSamplerArray& samplers) { |
560 const GrRadialGradient& ge = fp.cast<GrRadialGradient>(); | 562 const GrRadialGradient& ge = fp.cast<GrRadialGradient>(); |
561 this->emitUniforms(builder, ge); | 563 this->emitUniforms(builder, ge); |
562 SkString t("length("); | 564 SkString t("length("); |
563 t.append(builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0)); | 565 t.append(builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0)); |
564 t.append(")"); | 566 t.append(")"); |
565 this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers); | 567 this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers); |
566 } | 568 } |
567 | 569 |
568 ///////////////////////////////////////////////////////////////////// | 570 ///////////////////////////////////////////////////////////////////// |
569 | 571 |
570 bool SkRadialGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, | 572 bool SkRadialGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, |
| 573 const SkMatrix& viewM, |
571 const SkMatrix* localMatrix, GrColor*
paintColor, | 574 const SkMatrix* localMatrix, GrColor*
paintColor, |
572 GrFragmentProcessor** fp) const { | 575 GrFragmentProcessor** fp) const { |
573 SkASSERT(context); | 576 SkASSERT(context); |
574 | 577 |
575 SkMatrix matrix; | 578 SkMatrix matrix; |
576 if (!this->getLocalMatrix().invert(&matrix)) { | 579 if (!this->getLocalMatrix().invert(&matrix)) { |
577 return false; | 580 return false; |
578 } | 581 } |
579 if (localMatrix) { | 582 if (localMatrix) { |
580 SkMatrix inv; | 583 SkMatrix inv; |
581 if (!localMatrix->invert(&inv)) { | 584 if (!localMatrix->invert(&inv)) { |
582 return false; | 585 return false; |
583 } | 586 } |
584 matrix.postConcat(inv); | 587 matrix.postConcat(inv); |
585 } | 588 } |
586 matrix.postConcat(fPtsToUnit); | 589 matrix.postConcat(fPtsToUnit); |
587 | 590 |
588 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); | 591 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
589 *fp = GrRadialGradient::Create(context, *this, matrix, fTileMode); | 592 *fp = GrRadialGradient::Create(context, *this, matrix, fTileMode); |
590 | 593 |
591 return true; | 594 return true; |
592 } | 595 } |
593 | 596 |
594 #else | 597 #else |
595 | 598 |
596 bool SkRadialGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkM
atrix*, GrColor*, | 599 bool SkRadialGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkM
atrix&, |
| 600 const SkMatrix*, GrColor*, |
597 GrFragmentProcessor**) const { | 601 GrFragmentProcessor**) const { |
598 SkDEBUGFAIL("Should not call in GPU-less build"); | 602 SkDEBUGFAIL("Should not call in GPU-less build"); |
599 return false; | 603 return false; |
600 } | 604 } |
601 | 605 |
602 #endif | 606 #endif |
603 | 607 |
604 #ifndef SK_IGNORE_TO_STRING | 608 #ifndef SK_IGNORE_TO_STRING |
605 void SkRadialGradient::toString(SkString* str) const { | 609 void SkRadialGradient::toString(SkString* str) const { |
606 str->append("SkRadialGradient: ("); | 610 str->append("SkRadialGradient: ("); |
607 | 611 |
608 str->append("center: ("); | 612 str->append("center: ("); |
609 str->appendScalar(fCenter.fX); | 613 str->appendScalar(fCenter.fX); |
610 str->append(", "); | 614 str->append(", "); |
611 str->appendScalar(fCenter.fY); | 615 str->appendScalar(fCenter.fY); |
612 str->append(") radius: "); | 616 str->append(") radius: "); |
613 str->appendScalar(fRadius); | 617 str->appendScalar(fRadius); |
614 str->append(" "); | 618 str->append(" "); |
615 | 619 |
616 this->INHERITED::toString(str); | 620 this->INHERITED::toString(str); |
617 | 621 |
618 str->append(")"); | 622 str->append(")"); |
619 } | 623 } |
620 #endif | 624 #endif |
OLD | NEW |