| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 *dstC++ = cache[toggle + index]; | 444 *dstC++ = cache[toggle + index]; |
| 445 toggle = next_dither_toggle16(toggle); | 445 toggle = next_dither_toggle16(toggle); |
| 446 | 446 |
| 447 dstX += SK_Scalar1; | 447 dstX += SK_Scalar1; |
| 448 } while (--count != 0); | 448 } while (--count != 0); |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 | 451 |
| 452 #if SK_SUPPORT_GPU | 452 #if SK_SUPPORT_GPU |
| 453 | 453 |
| 454 #include "GrTBackendProcessorFactory.h" | |
| 455 #include "gl/builders/GrGLProgramBuilder.h" | 454 #include "gl/builders/GrGLProgramBuilder.h" |
| 456 #include "SkGr.h" | 455 #include "SkGr.h" |
| 457 | 456 |
| 458 ///////////////////////////////////////////////////////////////////// | 457 ///////////////////////////////////////////////////////////////////// |
| 459 | 458 |
| 460 class GrGLLinearGradient : public GrGLGradientEffect { | 459 class GrGLLinearGradient : public GrGLGradientEffect { |
| 461 public: | 460 public: |
| 462 | 461 |
| 463 GrGLLinearGradient(const GrBackendProcessorFactory& factory, const GrProcess
or&) | 462 GrGLLinearGradient(const GrProcessor&) {} |
| 464 : INHERITED (factory) { } | |
| 465 | 463 |
| 466 virtual ~GrGLLinearGradient() { } | 464 virtual ~GrGLLinearGradient() { } |
| 467 | 465 |
| 468 virtual void emitCode(GrGLFPBuilder*, | 466 virtual void emitCode(GrGLFPBuilder*, |
| 469 const GrFragmentProcessor&, | 467 const GrFragmentProcessor&, |
| 470 const char* outputColor, | 468 const char* outputColor, |
| 471 const char* inputColor, | 469 const char* inputColor, |
| 472 const TransformedCoordsArray&, | 470 const TransformedCoordsArray&, |
| 473 const TextureSamplerArray&) SK_OVERRIDE; | 471 const TextureSamplerArray&) SK_OVERRIDE; |
| 474 | 472 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 488 | 486 |
| 489 static GrFragmentProcessor* Create(GrContext* ctx, | 487 static GrFragmentProcessor* Create(GrContext* ctx, |
| 490 const SkLinearGradient& shader, | 488 const SkLinearGradient& shader, |
| 491 const SkMatrix& matrix, | 489 const SkMatrix& matrix, |
| 492 SkShader::TileMode tm) { | 490 SkShader::TileMode tm) { |
| 493 return SkNEW_ARGS(GrLinearGradient, (ctx, shader, matrix, tm)); | 491 return SkNEW_ARGS(GrLinearGradient, (ctx, shader, matrix, tm)); |
| 494 } | 492 } |
| 495 | 493 |
| 496 virtual ~GrLinearGradient() { } | 494 virtual ~GrLinearGradient() { } |
| 497 | 495 |
| 498 static const char* Name() { return "Linear Gradient"; } | 496 virtual const char* name() const { return "Linear Gradient"; } |
| 499 const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERRIDE { | 497 |
| 500 return GrTBackendFragmentProcessorFactory<GrLinearGradient>::getInstance
(); | 498 virtual void getGLProcessorKey(const GrGLCaps& caps, |
| 499 GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
| 500 GrGLLinearGradient::GenKey(*this, caps, b); |
| 501 } | 501 } |
| 502 | 502 |
| 503 typedef GrGLLinearGradient GLProcessor; | 503 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { |
| 504 return SkNEW_ARGS(GrGLLinearGradient, (*this)); |
| 505 } |
| 504 | 506 |
| 505 private: | 507 private: |
| 506 GrLinearGradient(GrContext* ctx, | 508 GrLinearGradient(GrContext* ctx, |
| 507 const SkLinearGradient& shader, | 509 const SkLinearGradient& shader, |
| 508 const SkMatrix& matrix, | 510 const SkMatrix& matrix, |
| 509 SkShader::TileMode tm) | 511 SkShader::TileMode tm) |
| 510 : INHERITED(ctx, shader, matrix, tm) { } | 512 : INHERITED(ctx, shader, matrix, tm) { |
| 513 this->initClassID<GrLinearGradient>(); |
| 514 } |
| 511 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 515 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 512 | 516 |
| 513 typedef GrGradientEffect INHERITED; | 517 typedef GrGradientEffect INHERITED; |
| 514 }; | 518 }; |
| 515 | 519 |
| 516 ///////////////////////////////////////////////////////////////////// | 520 ///////////////////////////////////////////////////////////////////// |
| 517 | 521 |
| 518 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); | 522 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); |
| 519 | 523 |
| 520 GrFragmentProcessor* GrLinearGradient::TestCreate(SkRandom* random, | 524 GrFragmentProcessor* GrLinearGradient::TestCreate(SkRandom* random, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 540 } | 544 } |
| 541 | 545 |
| 542 ///////////////////////////////////////////////////////////////////// | 546 ///////////////////////////////////////////////////////////////////// |
| 543 | 547 |
| 544 void GrGLLinearGradient::emitCode(GrGLFPBuilder* builder, | 548 void GrGLLinearGradient::emitCode(GrGLFPBuilder* builder, |
| 545 const GrFragmentProcessor& fp, | 549 const GrFragmentProcessor& fp, |
| 546 const char* outputColor, | 550 const char* outputColor, |
| 547 const char* inputColor, | 551 const char* inputColor, |
| 548 const TransformedCoordsArray& coords, | 552 const TransformedCoordsArray& coords, |
| 549 const TextureSamplerArray& samplers) { | 553 const TextureSamplerArray& samplers) { |
| 550 const GrGradientEffect& ge = fp.cast<GrGradientEffect>(); | 554 const GrLinearGradient& ge = fp.cast<GrLinearGradient>(); |
| 551 this->emitUniforms(builder, ge); | 555 this->emitUniforms(builder, ge); |
| 552 SkString t = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0
); | 556 SkString t = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0
); |
| 553 t.append(".x"); | 557 t.append(".x"); |
| 554 this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers); | 558 this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers); |
| 555 } | 559 } |
| 556 | 560 |
| 557 ///////////////////////////////////////////////////////////////////// | 561 ///////////////////////////////////////////////////////////////////// |
| 558 | 562 |
| 559 bool SkLinearGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, | 563 bool SkLinearGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, |
| 560 const SkMatrix* localMatrix, GrColor*
paintColor, | 564 const SkMatrix* localMatrix, GrColor*
paintColor, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 str->append("SkLinearGradient ("); | 599 str->append("SkLinearGradient ("); |
| 596 | 600 |
| 597 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 601 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
| 598 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 602 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
| 599 | 603 |
| 600 this->INHERITED::toString(str); | 604 this->INHERITED::toString(str); |
| 601 | 605 |
| 602 str->append(")"); | 606 str->append(")"); |
| 603 } | 607 } |
| 604 #endif | 608 #endif |
| OLD | NEW |