| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 *dstC++ = cache[toggle + index]; | 432 *dstC++ = cache[toggle + index]; |
| 433 toggle = next_dither_toggle16(toggle); | 433 toggle = next_dither_toggle16(toggle); |
| 434 | 434 |
| 435 dstX += SK_Scalar1; | 435 dstX += SK_Scalar1; |
| 436 } while (--count != 0); | 436 } while (--count != 0); |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 | 439 |
| 440 #if SK_SUPPORT_GPU | 440 #if SK_SUPPORT_GPU |
| 441 | 441 |
| 442 #include "effects/GrExtractAlphaFragmentProcessor.h" | |
| 443 #include "gl/builders/GrGLProgramBuilder.h" | 442 #include "gl/builders/GrGLProgramBuilder.h" |
| 444 #include "SkGr.h" | 443 #include "SkGr.h" |
| 445 | 444 |
| 446 ///////////////////////////////////////////////////////////////////// | 445 ///////////////////////////////////////////////////////////////////// |
| 447 | 446 |
| 448 class GrGLLinearGradient : public GrGLGradientEffect { | 447 class GrGLLinearGradient : public GrGLGradientEffect { |
| 449 public: | 448 public: |
| 450 | 449 |
| 451 GrGLLinearGradient(const GrProcessor&) {} | 450 GrGLLinearGradient(const GrProcessor&) {} |
| 452 | 451 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 500 |
| 502 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 501 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 503 | 502 |
| 504 typedef GrGradientEffect INHERITED; | 503 typedef GrGradientEffect INHERITED; |
| 505 }; | 504 }; |
| 506 | 505 |
| 507 ///////////////////////////////////////////////////////////////////// | 506 ///////////////////////////////////////////////////////////////////// |
| 508 | 507 |
| 509 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); | 508 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); |
| 510 | 509 |
| 511 const GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d)
{ | 510 GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d) { |
| 512 SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}
, | 511 SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}
, |
| 513 {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}
}; | 512 {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}
}; |
| 514 | 513 |
| 515 SkColor colors[kMaxRandomGradientColors]; | 514 SkColor colors[kMaxRandomGradientColors]; |
| 516 SkScalar stopsArray[kMaxRandomGradientColors]; | 515 SkScalar stopsArray[kMaxRandomGradientColors]; |
| 517 SkScalar* stops = stopsArray; | 516 SkScalar* stops = stopsArray; |
| 518 SkShader::TileMode tm; | 517 SkShader::TileMode tm; |
| 519 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); | 518 int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tm); |
| 520 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, | 519 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, |
| 521 colors, stops,
colorCount, | 520 colors, stops,
colorCount, |
| 522 tm)); | 521 tm)); |
| 523 const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, | 522 SkPaint paint; |
| 524 GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDat
aManager); | 523 GrColor paintColor; |
| 525 GrAlwaysAssert(fp); | 524 GrFragmentProcessor* fp; |
| 525 SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, |
| 526 GrTest::TestMatrix(d->fRandom), n
ullptr, |
| 527 &paintColor, d->fProcDataManager,
&fp)); |
| 526 return fp; | 528 return fp; |
| 527 } | 529 } |
| 528 | 530 |
| 529 ///////////////////////////////////////////////////////////////////// | 531 ///////////////////////////////////////////////////////////////////// |
| 530 | 532 |
| 531 void GrGLLinearGradient::emitCode(EmitArgs& args) { | 533 void GrGLLinearGradient::emitCode(EmitArgs& args) { |
| 532 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>(); | 534 const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>(); |
| 533 this->emitUniforms(args.fBuilder, ge); | 535 this->emitUniforms(args.fBuilder, ge); |
| 534 SkString t = args.fBuilder->getFragmentShaderBuilder()->ensureFSCoords2D(arg
s.fCoords, 0); | 536 SkString t = args.fBuilder->getFragmentShaderBuilder()->ensureFSCoords2D(arg
s.fCoords, 0); |
| 535 t.append(".x"); | 537 t.append(".x"); |
| 536 this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInput
Color, | 538 this->emitColor(args.fBuilder, ge, t.c_str(), args.fOutputColor, args.fInput
Color, |
| 537 args.fSamplers); | 539 args.fSamplers); |
| 538 } | 540 } |
| 539 | 541 |
| 540 ///////////////////////////////////////////////////////////////////// | 542 ///////////////////////////////////////////////////////////////////// |
| 541 | 543 |
| 542 const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor( | 544 bool SkLinearGradient::asFragmentProcessor(GrContext* context, const SkPaint& pa
int, |
| 543 GrContext* context, const SkMatrix& viewm, const SkMatrix* localMatrix, SkFi
lterQuality, | 545 const SkMatrix& viewm, const SkMatrix
* localMatrix, |
| 544 GrProcessorDataManager* procDataManager) const { | 546 GrColor* paintColor, |
| 547 GrProcessorDataManager* procDataManag
er, |
| 548 GrFragmentProcessor** fp) const { |
| 545 SkASSERT(context); | 549 SkASSERT(context); |
| 546 | 550 |
| 547 SkMatrix matrix; | 551 SkMatrix matrix; |
| 548 if (!this->getLocalMatrix().invert(&matrix)) { | 552 if (!this->getLocalMatrix().invert(&matrix)) { |
| 549 return nullptr; | 553 return false; |
| 550 } | 554 } |
| 551 if (localMatrix) { | 555 if (localMatrix) { |
| 552 SkMatrix inv; | 556 SkMatrix inv; |
| 553 if (!localMatrix->invert(&inv)) { | 557 if (!localMatrix->invert(&inv)) { |
| 554 return nullptr; | 558 return false; |
| 555 } | 559 } |
| 556 matrix.postConcat(inv); | 560 matrix.postConcat(inv); |
| 557 } | 561 } |
| 558 matrix.postConcat(fPtsToUnit); | 562 matrix.postConcat(fPtsToUnit); |
| 559 | 563 |
| 560 SkAutoTUnref<const GrFragmentProcessor> inner( | 564 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 561 GrLinearGradient::Create(context, procDataManager, *this, matrix, fTileM
ode)); | 565 *fp = GrLinearGradient::Create(context, procDataManager, *this, matrix, fTil
eMode); |
| 562 return GrExtractAlphaFragmentProcessor::Create(inner); | 566 |
| 567 return true; |
| 563 } | 568 } |
| 564 | 569 |
| 570 #else |
| 571 |
| 572 bool SkLinearGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkM
atrix&, |
| 573 const SkMatrix*, GrColor*, GrProcesso
rDataManager*, |
| 574 GrFragmentProcessor**) const { |
| 575 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 576 return false; |
| 577 } |
| 565 | 578 |
| 566 #endif | 579 #endif |
| 567 | 580 |
| 568 #ifndef SK_IGNORE_TO_STRING | 581 #ifndef SK_IGNORE_TO_STRING |
| 569 void SkLinearGradient::toString(SkString* str) const { | 582 void SkLinearGradient::toString(SkString* str) const { |
| 570 str->append("SkLinearGradient ("); | 583 str->append("SkLinearGradient ("); |
| 571 | 584 |
| 572 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); | 585 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); |
| 573 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); | 586 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); |
| 574 | 587 |
| 575 this->INHERITED::toString(str); | 588 this->INHERITED::toString(str); |
| 576 | 589 |
| 577 str->append(")"); | 590 str->append(")"); |
| 578 } | 591 } |
| 579 #endif | 592 #endif |
| OLD | NEW |