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

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

Issue 318923005: SkShader::asNewEffect Refactoring (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SkColorShader refactor and fix Created 6 years, 6 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
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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 520
521 SkColor colors[kMaxRandomGradientColors]; 521 SkColor colors[kMaxRandomGradientColors];
522 SkScalar stopsArray[kMaxRandomGradientColors]; 522 SkScalar stopsArray[kMaxRandomGradientColors];
523 SkScalar* stops = stopsArray; 523 SkScalar* stops = stopsArray;
524 SkShader::TileMode tm; 524 SkShader::TileMode tm;
525 int colorCount = RandomGradientParams(random, colors, &stops, &tm); 525 int colorCount = RandomGradientParams(random, colors, &stops, &tm);
526 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, 526 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points,
527 colors, stops, colorCount, 527 colors, stops, colorCount,
528 tm)); 528 tm));
529 SkPaint paint; 529 SkPaint paint;
530 return shader->asNewEffect(context, paint, NULL); 530 GrColor grColor;
531 GrEffectRef* effect;
532 shader->asNewEffect(context, paint, NULL, &grColor, &effect);
533 return effect;
531 } 534 }
532 535
533 ///////////////////////////////////////////////////////////////////// 536 /////////////////////////////////////////////////////////////////////
534 537
535 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, 538 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
536 const GrDrawEffect&, 539 const GrDrawEffect&,
537 EffectKey key, 540 EffectKey key,
538 const char* outputColor, 541 const char* outputColor,
539 const char* inputColor, 542 const char* inputColor,
540 const TransformedCoordsArray& coords, 543 const TransformedCoordsArray& coords,
541 const TextureSamplerArray& samplers) { 544 const TextureSamplerArray& samplers) {
542 this->emitUniforms(builder, key); 545 this->emitUniforms(builder, key);
543 SkString t = builder->ensureFSCoords2D(coords, 0); 546 SkString t = builder->ensureFSCoords2D(coords, 0);
544 t.append(".x"); 547 t.append(".x");
545 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); 548 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers);
546 } 549 }
547 550
548 ///////////////////////////////////////////////////////////////////// 551 /////////////////////////////////////////////////////////////////////
549 552
550 GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&, 553 bool SkLinearGradient::asNewEffect(GrContext* context, const SkPaint& paint,
551 const SkMatrix* localMatrix) const { 554 const SkMatrix* localMatrix, GrColor* grColor ,
555 GrEffectRef** grEffect) const {
552 SkASSERT(NULL != context); 556 SkASSERT(NULL != context);
557
558 *grColor = this->getColorAsAlpha(paint);
559
553 SkMatrix matrix; 560 SkMatrix matrix;
554 if (!this->getLocalMatrix().invert(&matrix)) { 561 if (!this->getLocalMatrix().invert(&matrix)) {
555 return NULL; 562 return false;
556 } 563 }
557 if (localMatrix) { 564 if (localMatrix) {
558 SkMatrix inv; 565 SkMatrix inv;
559 if (!localMatrix->invert(&inv)) { 566 if (!localMatrix->invert(&inv)) {
560 return NULL; 567 return false;
561 } 568 }
562 matrix.postConcat(inv); 569 matrix.postConcat(inv);
563 } 570 }
564 matrix.postConcat(fPtsToUnit); 571 matrix.postConcat(fPtsToUnit);
565 return GrLinearGradient::Create(context, *this, matrix, fTileMode); 572
573 *grEffect = GrLinearGradient::Create(context, *this, matrix, fTileMode);
574
575 return NULL != *grEffect;
566 } 576 }
567 577
568 #else 578 #else
569 579
570 GrEffectRef* SkLinearGradient::asNewEffect(GrContext*, const SkPaint&, const SkM atrix*) const { 580 bool SkLinearGradient::asNewEffect(GrContext* context, const SkPaint& paint,
581 const SkMatrix* localMatrix, GrColor* grColor ,
582 GrEffectRef** grEffect) const {
571 SkDEBUGFAIL("Should not call in GPU-less build"); 583 SkDEBUGFAIL("Should not call in GPU-less build");
572 return NULL; 584 return false;
573 } 585 }
574 586
575 #endif 587 #endif
576 588
577 #ifndef SK_IGNORE_TO_STRING 589 #ifndef SK_IGNORE_TO_STRING
578 void SkLinearGradient::toString(SkString* str) const { 590 void SkLinearGradient::toString(SkString* str) const {
579 str->append("SkLinearGradient ("); 591 str->append("SkLinearGradient (");
580 592
581 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY); 593 str->appendf("start: (%f, %f)", fStart.fX, fStart.fY);
582 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY); 594 str->appendf(" end: (%f, %f) ", fEnd.fX, fEnd.fY);
583 595
584 this->INHERITED::toString(str); 596 this->INHERITED::toString(str);
585 597
586 str->append(")"); 598 str->append(")");
587 } 599 }
588 #endif 600 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698