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 #include "SkGr.h" |
9 | 10 |
10 static inline int repeat_bits(int x, const int bits) { | 11 static inline int repeat_bits(int x, const int bits) { |
11 return x & ((1 << bits) - 1); | 12 return x & ((1 << bits) - 1); |
12 } | 13 } |
13 | 14 |
14 static inline int repeat_8bits(int x) { | 15 static inline int repeat_8bits(int x) { |
15 return x & 0xFF; | 16 return x & 0xFF; |
16 } | 17 } |
17 | 18 |
18 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. | 19 // Visual Studio 2010 (MSC_VER=1600) optimizes bit-shift code incorrectly. |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 | 521 |
521 SkColor colors[kMaxRandomGradientColors]; | 522 SkColor colors[kMaxRandomGradientColors]; |
522 SkScalar stopsArray[kMaxRandomGradientColors]; | 523 SkScalar stopsArray[kMaxRandomGradientColors]; |
523 SkScalar* stops = stopsArray; | 524 SkScalar* stops = stopsArray; |
524 SkShader::TileMode tm; | 525 SkShader::TileMode tm; |
525 int colorCount = RandomGradientParams(random, colors, &stops, &tm); | 526 int colorCount = RandomGradientParams(random, colors, &stops, &tm); |
526 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, | 527 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, |
527 colors, stops,
colorCount, | 528 colors, stops,
colorCount, |
528 tm)); | 529 tm)); |
529 SkPaint paint; | 530 SkPaint paint; |
530 return shader->asNewEffect(context, paint, NULL); | 531 GrColor grColor; |
| 532 GrEffectRef* effect; |
| 533 shader->asNewEffect(context, paint, NULL, &grColor, &effect); |
| 534 return effect; |
531 } | 535 } |
532 | 536 |
533 ///////////////////////////////////////////////////////////////////// | 537 ///////////////////////////////////////////////////////////////////// |
534 | 538 |
535 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, | 539 void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder, |
536 const GrDrawEffect&, | 540 const GrDrawEffect&, |
537 EffectKey key, | 541 EffectKey key, |
538 const char* outputColor, | 542 const char* outputColor, |
539 const char* inputColor, | 543 const char* inputColor, |
540 const TransformedCoordsArray& coords, | 544 const TransformedCoordsArray& coords, |
541 const TextureSamplerArray& samplers) { | 545 const TextureSamplerArray& samplers) { |
542 this->emitUniforms(builder, key); | 546 this->emitUniforms(builder, key); |
543 SkString t = builder->ensureFSCoords2D(coords, 0); | 547 SkString t = builder->ensureFSCoords2D(coords, 0); |
544 t.append(".x"); | 548 t.append(".x"); |
545 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); | 549 this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers); |
546 } | 550 } |
547 | 551 |
548 ///////////////////////////////////////////////////////////////////// | 552 ///////////////////////////////////////////////////////////////////// |
549 | 553 |
550 GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&, | 554 bool SkLinearGradient::asNewEffect(GrContext* context, const SkPaint& paint, |
551 const SkMatrix* localMatrix) const { | 555 const SkMatrix* localMatrix, GrColor* grColor
, |
| 556 GrEffectRef** grEffect) const { |
552 SkASSERT(NULL != context); | 557 SkASSERT(NULL != context); |
| 558 |
553 SkMatrix matrix; | 559 SkMatrix matrix; |
554 if (!this->getLocalMatrix().invert(&matrix)) { | 560 if (!this->getLocalMatrix().invert(&matrix)) { |
555 return NULL; | 561 return false; |
556 } | 562 } |
557 if (localMatrix) { | 563 if (localMatrix) { |
558 SkMatrix inv; | 564 SkMatrix inv; |
559 if (!localMatrix->invert(&inv)) { | 565 if (!localMatrix->invert(&inv)) { |
560 return NULL; | 566 return false; |
561 } | 567 } |
562 matrix.postConcat(inv); | 568 matrix.postConcat(inv); |
563 } | 569 } |
564 matrix.postConcat(fPtsToUnit); | 570 matrix.postConcat(fPtsToUnit); |
565 return GrLinearGradient::Create(context, *this, matrix, fTileMode); | 571 |
| 572 *grColor = SkColor2GrColorJustAlpha(paint.getColor()); |
| 573 *grEffect = GrLinearGradient::Create(context, *this, matrix, fTileMode); |
| 574 |
| 575 return true; |
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 |
OLD | NEW |