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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 toggle = next_dither_toggle16(toggle); | 439 toggle = next_dither_toggle16(toggle); |
440 | 440 |
441 dstX += SK_Scalar1; | 441 dstX += SK_Scalar1; |
442 } while (--count != 0); | 442 } while (--count != 0); |
443 } | 443 } |
444 } | 444 } |
445 | 445 |
446 #if SK_SUPPORT_GPU | 446 #if SK_SUPPORT_GPU |
447 | 447 |
448 #include "GrTBackendEffectFactory.h" | 448 #include "GrTBackendEffectFactory.h" |
| 449 #include "SkGr.h" |
449 | 450 |
450 ///////////////////////////////////////////////////////////////////// | 451 ///////////////////////////////////////////////////////////////////// |
451 | 452 |
452 class GrGLLinearGradient : public GrGLGradientEffect { | 453 class GrGLLinearGradient : public GrGLGradientEffect { |
453 public: | 454 public: |
454 | 455 |
455 GrGLLinearGradient(const GrBackendEffectFactory& factory, const GrDrawEffect
&) | 456 GrGLLinearGradient(const GrBackendEffectFactory& factory, const GrDrawEffect
&) |
456 : INHERITED (factory) { } | 457 : INHERITED (factory) { } |
457 | 458 |
458 virtual ~GrGLLinearGradient() { } | 459 virtual ~GrGLLinearGradient() { } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 521 |
521 SkColor colors[kMaxRandomGradientColors]; | 522 SkColor colors[kMaxRandomGradientColors]; |
522 SkScalar stopsArray[kMaxRandomGradientColors]; | 523 SkScalar stopsArray[kMaxRandomGradientColors]; |
523 SkScalar* stops = stopsArray; | 524 SkScalar* stops = stopsArray; |
524 SkShader::TileMode tm; | 525 SkShader::TileMode tm; |
525 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 526 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
526 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, | 527 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, |
527 colors, stops,
colorCount, | 528 colors, stops,
colorCount, |
528 tm)); | 529 tm)); |
529 SkPaint paint; | 530 SkPaint paint; |
530 return shader->asNewEffect(context, paint, NULL); | 531 GrColor grColor; |
| 532 GrEffectRef* effect; |
| 533 shader->asNewEffect(context, paint, NULL, &grColor, &effect); |
| 534 return effect; |
531 } | 535 } |
532 | 536 |
533 ///////////////////////////////////////////////////////////////////// | 537 ///////////////////////////////////////////////////////////////////// |
534 | 538 |
535 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, | 539 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, |
536 const GrDrawEffect&, | 540 const GrDrawEffect&, |
537 EffectKey key, | 541 EffectKey key, |
538 const char* outputColor, | 542 const char* outputColor, |
539 const char* inputColor, | 543 const char* inputColor, |
540 const TransformedCoordsArray& coords, | 544 const TransformedCoordsArray& coords, |
541 const TextureSamplerArray& samplers) { | 545 const TextureSamplerArray& samplers) { |
542 this->emitUniforms(builder, key); | 546 this->emitUniforms(builder, key); |
543 SkString t = builder->ensureFSCoords2D(coords, 0); | 547 SkString t = builder->ensureFSCoords2D(coords, 0); |
544 t.append(".x"); | 548 t.append(".x"); |
545 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); | 549 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); |
546 } | 550 } |
547 | 551 |
548 ///////////////////////////////////////////////////////////////////// | 552 ///////////////////////////////////////////////////////////////////// |
549 | 553 |
550 GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&, | 554 bool SkLinearGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
551 const SkMatrix* localMatrix) const { | 555 const SkMatrix* localMatrix, GrColor* grColor
, |
| 556 GrEffectRef** grEffect) const { |
552 SkASSERT(NULL != context); | 557 SkASSERT(NULL != context); |
| 558 |
553 SkMatrix matrix; | 559 SkMatrix matrix; |
554 if (!this->getLocalMatrix().invert(&matrix)) { | 560 if (!this->getLocalMatrix().invert(&matrix)) { |
555 return NULL; | 561 return false; |
556 } | 562 } |
557 if (localMatrix) { | 563 if (localMatrix) { |
558 SkMatrix inv; | 564 SkMatrix inv; |
559 if (!localMatrix->invert(&inv)) { | 565 if (!localMatrix->invert(&inv)) { |
560 return NULL; | 566 return false; |
561 } | 567 } |
562 matrix.postConcat(inv); | 568 matrix.postConcat(inv); |
563 } | 569 } |
564 matrix.postConcat(fPtsToUnit); | 570 matrix.postConcat(fPtsToUnit); |
565 return GrLinearGradient::Create(context, *this, matrix, fTileMode); | 571 |
| 572 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 573 *grEffect = GrLinearGradient::Create(context, *this, matrix, fTileMode); |
| 574 |
| 575 return true; |
566 } | 576 } |
567 | 577 |
568 #else | 578 #else |
569 | 579 |
570 GrEffectRef* SkLinearGradient::asNewEffect(GrContext*, const SkPaint&, const SkM
atrix*) const { | 580 bool SkLinearGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
| 581 const SkMatrix* localMatrix, GrColor* grColor
, |
| 582 GrEffectRef** grEffect) const { |
571 SkDEBUGFAIL("Should not call in GPU-less build"); | 583 SkDEBUGFAIL("Should not call in GPU-less build"); |
572 return NULL; | 584 return false; |
573 } | 585 } |
574 | 586 |
575 #endif | 587 #endif |
576 | 588 |
577 #ifndef SK_IGNORE_TO_STRING | 589 #ifndef SK_IGNORE_TO_STRING |
578 void SkLinearGradient::toString(SkString* str) const { | 590 void SkLinearGradient::toString(SkString* str) const { |
579 str->append("SkLinearGradient ("); | 591 str->append("SkLinearGradient ("); |
580 | 592 |
581 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 593 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
582 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 594 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
583 | 595 |
584 this->INHERITED::toString(str); | 596 this->INHERITED::toString(str); |
585 | 597 |
586 str->append(")"); | 598 str->append(")"); |
587 } | 599 } |
588 #endif | 600 #endif |
OLD | NEW |