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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 }; | 463 }; |
464 | 464 |
465 ///////////////////////////////////////////////////////////////////// | 465 ///////////////////////////////////////////////////////////////////// |
466 | 466 |
467 class GrLinearGradient : public GrGradientEffect { | 467 class GrLinearGradient : public GrGradientEffect { |
468 public: | 468 public: |
469 | 469 |
470 static GrFragmentProcessor* Create(GrContext* ctx, | 470 static GrFragmentProcessor* Create(GrContext* ctx, |
471 const SkLinearGradient& shader, | 471 const SkLinearGradient& shader, |
472 const SkMatrix& matrix, | 472 const SkMatrix& matrix, |
473 SkShader::TileMode tm) { | 473 SkShader::TileMode tm, GrRenderTarget* ds
t) { |
474 return new GrLinearGradient(ctx, shader, matrix, tm); | 474 return new GrLinearGradient(ctx, shader, matrix, tm, dst); |
475 } | 475 } |
476 | 476 |
477 virtual ~GrLinearGradient() { } | 477 virtual ~GrLinearGradient() { } |
478 | 478 |
479 const char* name() const override { return "Linear Gradient"; } | 479 const char* name() const override { return "Linear Gradient"; } |
480 | 480 |
481 private: | 481 private: |
482 GrLinearGradient(GrContext* ctx, | 482 GrLinearGradient(GrContext* ctx, |
483 const SkLinearGradient& shader, | 483 const SkLinearGradient& shader, |
484 const SkMatrix& matrix, | 484 const SkMatrix& matrix, |
485 SkShader::TileMode tm) | 485 SkShader::TileMode tm, GrRenderTarget* dst) |
486 : INHERITED(ctx, shader, matrix, tm) { | 486 : INHERITED(ctx, shader, matrix, tm, dst) { |
487 this->initClassID<GrLinearGradient>(); | 487 this->initClassID<GrLinearGradient>(); |
488 } | 488 } |
489 | 489 |
490 GrGLFragmentProcessor* onCreateGLInstance() const override { | 490 GrGLFragmentProcessor* onCreateGLInstance() const override { |
491 return new GrGLLinearGradient(*this); | 491 return new GrGLLinearGradient(*this); |
492 } | 492 } |
493 | 493 |
494 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 494 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
495 GrProcessorKeyBuilder* b) const override { | 495 GrProcessorKeyBuilder* b) const override { |
496 GrGLLinearGradient::GenKey(*this, caps, b); | 496 GrGLLinearGradient::GenKey(*this, caps, b); |
(...skipping 14 matching lines...) Expand all Loading... |
511 | 511 |
512 SkColor colors[kMaxRandomGradientColors]; | 512 SkColor colors[kMaxRandomGradientColors]; |
513 SkScalar stopsArray[kMaxRandomGradientColors]; | 513 SkScalar stopsArray[kMaxRandomGradientColors]; |
514 SkScalar* stops = stopsArray; | 514 SkScalar* stops = stopsArray; |
515 SkShader::TileMode tm; | 515 SkShader::TileMode tm; |
516 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 516 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
517 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, | 517 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, |
518 colors, stops,
colorCount, | 518 colors, stops,
colorCount, |
519 tm)); | 519 tm)); |
520 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 520 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, |
521 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality); | 521 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, NULL); |
522 GrAlwaysAssert(fp); | 522 GrAlwaysAssert(fp); |
523 return fp; | 523 return fp; |
524 } | 524 } |
525 | 525 |
526 ///////////////////////////////////////////////////////////////////// | 526 ///////////////////////////////////////////////////////////////////// |
527 | 527 |
528 void GrGLLinearGradient::emitCode(EmitArgs& args) { | 528 void GrGLLinearGradient::emitCode(EmitArgs& args) { |
529 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>(); | 529 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>(); |
530 this->emitUniforms(args.fBuilder, ge); | 530 this->emitUniforms(args.fBuilder, ge); |
531 SkString t = args.fBuilder->getFragmentShaderBuilder()->ensureFSCoords2D(arg
s.fCoords, 0); | 531 SkString t = args.fBuilder->getFragmentShaderBuilder()->ensureFSCoords2D(arg
s.fCoords, 0); |
532 t.append(".x"); | 532 t.append(".x"); |
533 this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInput
Color, | 533 this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInput
Color, |
534 args.fSamplers); | 534 args.fSamplers); |
535 } | 535 } |
536 | 536 |
537 ///////////////////////////////////////////////////////////////////// | 537 ///////////////////////////////////////////////////////////////////// |
538 | 538 |
539 const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor( | 539 const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor( |
540 GrContext* context, | 540 GrContext* context, |
541 const SkMatrix& viewm, | 541 const SkMatrix& viewm, |
542 const SkMatrix* localMatrix, | 542 const SkMatrix* localMatrix, |
543 SkFilterQuality) const { | 543 SkFilterQuality, |
| 544 GrRenderTarget* dst) const { |
544 SkASSERT(context); | 545 SkASSERT(context); |
545 | 546 |
546 SkMatrix matrix; | 547 SkMatrix matrix; |
547 if (!this->getLocalMatrix().invert(&matrix)) { | 548 if (!this->getLocalMatrix().invert(&matrix)) { |
548 return nullptr; | 549 return nullptr; |
549 } | 550 } |
550 if (localMatrix) { | 551 if (localMatrix) { |
551 SkMatrix inv; | 552 SkMatrix inv; |
552 if (!localMatrix->invert(&inv)) { | 553 if (!localMatrix->invert(&inv)) { |
553 return nullptr; | 554 return nullptr; |
554 } | 555 } |
555 matrix.postConcat(inv); | 556 matrix.postConcat(inv); |
556 } | 557 } |
557 matrix.postConcat(fPtsToUnit); | 558 matrix.postConcat(fPtsToUnit); |
558 | 559 |
559 SkAutoTUnref<const GrFragmentProcessor> inner( | 560 SkAutoTUnref<const GrFragmentProcessor> inner( |
560 GrLinearGradient::Create(context, *this, matrix, fTileMode)); | 561 GrLinearGradient::Create(context, *this, matrix, fTileMode, dst)); |
561 return GrFragmentProcessor::MulOutputByInputAlpha(inner); | 562 return GrFragmentProcessor::MulOutputByInputAlpha(inner); |
562 } | 563 } |
563 | 564 |
564 | |
565 #endif | 565 #endif |
566 | 566 |
567 #ifndef SK_IGNORE_TO_STRING | 567 #ifndef SK_IGNORE_TO_STRING |
568 void SkLinearGradient::toString(SkString* str) const { | 568 void SkLinearGradient::toString(SkString* str) const { |
569 str->append("SkLinearGradient ("); | 569 str->append("SkLinearGradient ("); |
570 | 570 |
571 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 571 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
572 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 572 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
573 | 573 |
574 this->INHERITED::toString(str); | 574 this->INHERITED::toString(str); |
575 | 575 |
576 str->append(")"); | 576 str->append(")"); |
577 } | 577 } |
578 #endif | 578 #endif |
OLD | NEW |