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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 531 |
532 SkColor colors[kMaxRandomGradientColors]; | 532 SkColor colors[kMaxRandomGradientColors]; |
533 SkScalar stopsArray[kMaxRandomGradientColors]; | 533 SkScalar stopsArray[kMaxRandomGradientColors]; |
534 SkScalar* stops = stopsArray; | 534 SkScalar* stops = stopsArray; |
535 SkShader::TileMode tm; | 535 SkShader::TileMode tm; |
536 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 536 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
537 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, | 537 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, |
538 colors, stops,
colorCount, | 538 colors, stops,
colorCount, |
539 tm)); | 539 tm)); |
540 SkPaint paint; | 540 SkPaint paint; |
541 return shader->asNewEffect(context, paint, NULL); | 541 GrColor grColor; |
| 542 GrEffectRef* effect; |
| 543 shader->asNewEffect(context, paint, NULL, &grColor, &effect); |
| 544 return effect; |
542 } | 545 } |
543 | 546 |
544 ///////////////////////////////////////////////////////////////////// | 547 ///////////////////////////////////////////////////////////////////// |
545 | 548 |
546 void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder, | 549 void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder, |
547 const GrDrawEffect&, | 550 const GrDrawEffect&, |
548 EffectKey key, | 551 EffectKey key, |
549 const char* outputColor, | 552 const char* outputColor, |
550 const char* inputColor, | 553 const char* inputColor, |
551 const TransformedCoordsArray& coords, | 554 const TransformedCoordsArray& coords, |
552 const TextureSamplerArray& samplers) { | 555 const TextureSamplerArray& samplers) { |
553 this->emitUniforms(builder, key); | 556 this->emitUniforms(builder, key); |
554 SkString t("length("); | 557 SkString t("length("); |
555 t.append(builder->ensureFSCoords2D(coords, 0)); | 558 t.append(builder->ensureFSCoords2D(coords, 0)); |
556 t.append(")"); | 559 t.append(")"); |
557 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); | 560 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); |
558 } | 561 } |
559 | 562 |
560 ///////////////////////////////////////////////////////////////////// | 563 ///////////////////////////////////////////////////////////////////// |
561 | 564 |
562 GrEffectRef* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&, | 565 bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
563 const SkMatrix* localMatrix) const { | 566 const SkMatrix* localMatrix, GrColor* grColor
, |
| 567 GrEffectRef** grEffect) const { |
564 SkASSERT(NULL != context); | 568 SkASSERT(NULL != context); |
565 | 569 |
| 570 *grColor = this->getColorAsAlpha(paint); |
| 571 |
566 SkMatrix matrix; | 572 SkMatrix matrix; |
567 if (!this->getLocalMatrix().invert(&matrix)) { | 573 if (!this->getLocalMatrix().invert(&matrix)) { |
568 return NULL; | 574 return false; |
569 } | 575 } |
570 if (localMatrix) { | 576 if (localMatrix) { |
571 SkMatrix inv; | 577 SkMatrix inv; |
572 if (!localMatrix->invert(&inv)) { | 578 if (!localMatrix->invert(&inv)) { |
573 return NULL; | 579 return false; |
574 } | 580 } |
575 matrix.postConcat(inv); | 581 matrix.postConcat(inv); |
576 } | 582 } |
577 matrix.postConcat(fPtsToUnit); | 583 matrix.postConcat(fPtsToUnit); |
578 return GrRadialGradient::Create(context, *this, matrix, fTileMode); | 584 |
| 585 *grEffect = GrRadialGradient::Create(context, *this, matrix, fTileMode); |
| 586 |
| 587 return NULL != *grEffect; |
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 |