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