Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: src/effects/gradients/SkLinearGradient.cpp

Issue 1316513002: Change SkShader;asFragmentProcessor signature to no longer take skpaint\grcolor* (Closed) Base URL: https://skia.googlesource.com/skia.git@things
Patch Set: Address comments, fix roll(?) Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/gradients/SkLinearGradient.h ('k') | src/effects/gradients/SkRadialGradient.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(
545 const SkMatrix& viewm, const SkMatrix * localMatrix, 543 GrContext* context,
546 GrColor* paintColor, 544 const SkMatrix& viewm,
547 GrProcessorDataManager* procDataManag er, 545 const SkMatrix* localMatrix,
548 GrFragmentProcessor** fp) const { 546 SkFilterQuality,
547 GrProcessorDataManager* procDat aManager) const {
549 SkASSERT(context); 548 SkASSERT(context);
550 549
551 SkMatrix matrix; 550 SkMatrix matrix;
552 if (!this->getLocalMatrix().invert(&matrix)) { 551 if (!this->getLocalMatrix().invert(&matrix)) {
553 return false; 552 return nullptr;
554 } 553 }
555 if (localMatrix) { 554 if (localMatrix) {
556 SkMatrix inv; 555 SkMatrix inv;
557 if (!localMatrix->invert(&inv)) { 556 if (!localMatrix->invert(&inv)) {
558 return false; 557 return nullptr;
559 } 558 }
560 matrix.postConcat(inv); 559 matrix.postConcat(inv);
561 } 560 }
562 matrix.postConcat(fPtsToUnit); 561 matrix.postConcat(fPtsToUnit);
563 562
564 *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); 563 SkAutoTUnref<const GrFragmentProcessor> inner(
565 *fp = GrLinearGradient::Create(context, procDataManager, *this, matrix, fTil eMode); 564 GrLinearGradient::Create(context, procDataManager, *this, matrix, fTileM ode));
566 565 return GrExtractAlphaFragmentProcessor::Create(inner);
567 return true;
568 } 566 }
569 567
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 568
579 #endif 569 #endif
580 570
581 #ifndef SK_IGNORE_TO_STRING 571 #ifndef SK_IGNORE_TO_STRING
582 void SkLinearGradient::toString(SkString* str) const { 572 void SkLinearGradient::toString(SkString* str) const {
583 str->append("SkLinearGradient ("); 573 str->append("SkLinearGradient (");
584 574
585 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); 575 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY);
586 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); 576 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY);
587 577
588 this->INHERITED::toString(str); 578 this->INHERITED::toString(str);
589 579
590 str->append(")"); 580 str->append(")");
591 } 581 }
592 #endif 582 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkLinearGradient.h ('k') | src/effects/gradients/SkRadialGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698