| 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 } |
| 502 |
| 503 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { |
| 504 return SkNEW_ARGS(GrGLLinearGradient, (*this)); |
| 505 } |
| 506 |
| 507 |
| 508 virtual uint32_t classID() const { |
| 509 static uint32_t id = GenClassID(); |
| 510 return id; |
| 501 } | 511 } |
| 502 | 512 |
| 503 typedef GrGLLinearGradient GLProcessor; | 513 typedef GrGLLinearGradient GLProcessor; |
| 504 | 514 |
| 505 private: | 515 private: |
| 506 GrLinearGradient(GrContext* ctx, | 516 GrLinearGradient(GrContext* ctx, |
| 507 const SkLinearGradient& shader, | 517 const SkLinearGradient& shader, |
| 508 const SkMatrix& matrix, | 518 const SkMatrix& matrix, |
| 509 SkShader::TileMode tm) | 519 SkShader::TileMode tm) |
| 510 : INHERITED(ctx, shader, matrix, tm) { } | 520 : INHERITED(ctx, shader, matrix, tm) { } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 540 } | 550 } |
| 541 | 551 |
| 542 ///////////////////////////////////////////////////////////////////// | 552 ///////////////////////////////////////////////////////////////////// |
| 543 | 553 |
| 544 void GrGLLinearGradient::emitCode(GrGLFPBuilder* builder, | 554 void GrGLLinearGradient::emitCode(GrGLFPBuilder* builder, |
| 545 const GrFragmentProcessor& fp, | 555 const GrFragmentProcessor& fp, |
| 546 const char* outputColor, | 556 const char* outputColor, |
| 547 const char* inputColor, | 557 const char* inputColor, |
| 548 const TransformedCoordsArray& coords, | 558 const TransformedCoordsArray& coords, |
| 549 const TextureSamplerArray& samplers) { | 559 const TextureSamplerArray& samplers) { |
| 550 const GrGradientEffect& ge = fp.cast<GrGradientEffect>(); | 560 const GrLinearGradient& ge = fp.cast<GrLinearGradient>(); |
| 551 this->emitUniforms(builder, ge); | 561 this->emitUniforms(builder, ge); |
| 552 SkString t = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0
); | 562 SkString t = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0
); |
| 553 t.append(".x"); | 563 t.append(".x"); |
| 554 this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers); | 564 this->emitColor(builder, ge, t.c_str(), outputColor, inputColor, samplers); |
| 555 } | 565 } |
| 556 | 566 |
| 557 ///////////////////////////////////////////////////////////////////// | 567 ///////////////////////////////////////////////////////////////////// |
| 558 | 568 |
| 559 bool SkLinearGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, | 569 bool SkLinearGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, |
| 560 const SkMatrix* localMatrix, GrColor*
paintColor, | 570 const SkMatrix* localMatrix, GrColor*
paintColor, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 str->append("SkLinearGradient ("); | 605 str->append("SkLinearGradient ("); |
| 596 | 606 |
| 597 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 607 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
| 598 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 608 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
| 599 | 609 |
| 600 this->INHERITED::toString(str); | 610 this->INHERITED::toString(str); |
| 601 | 611 |
| 602 str->append(")"); | 612 str->append(")"); |
| 603 } | 613 } |
| 604 #endif | 614 #endif |
| OLD | NEW |