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