OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
9 | 9 |
10 #include "GrXferProcessor.h" | 10 #include "GrXferProcessor.h" |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 *ctOut = ct; | 635 *ctOut = ct; |
636 } | 636 } |
637 if (ptOut) { | 637 if (ptOut) { |
638 *ptOut = pt; | 638 *ptOut = pt; |
639 } | 639 } |
640 return true; | 640 return true; |
641 } | 641 } |
642 | 642 |
643 /////////////////////////////////////////////////////////////////////////////// | 643 /////////////////////////////////////////////////////////////////////////////// |
644 | 644 |
645 void SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPai
nt& skPaint, | 645 bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPai
nt& skPaint, |
646 GrColor paintColor, bool constantColor, GrPaint* gr
Paint) { | 646 GrColor paintColor, bool constantColor, GrPaint* gr
Paint) { |
647 | 647 |
648 grPaint->setDither(skPaint.isDither()); | 648 grPaint->setDither(skPaint.isDither()); |
649 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 649 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
650 | 650 |
651 SkXfermode* mode = skPaint.getXfermode(); | 651 SkXfermode* mode = skPaint.getXfermode(); |
652 GrXPFactory* xpFactory = NULL; | 652 GrXPFactory* xpFactory = NULL; |
653 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { | 653 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { |
654 // Fall back to src-over | 654 // Fall back to src-over |
| 655 // return false here? |
655 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); | 656 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); |
656 } | 657 } |
657 SkASSERT(xpFactory); | 658 SkASSERT(xpFactory); |
658 grPaint->setXPFactory(xpFactory)->unref(); | 659 grPaint->setXPFactory(xpFactory)->unref(); |
659 | 660 |
660 //set the color of the paint to the one of the parameter | 661 //set the color of the paint to the one of the parameter |
661 grPaint->setColor(paintColor); | 662 grPaint->setColor(paintColor); |
662 | 663 |
663 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 664 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
664 if (colorFilter) { | 665 if (colorFilter) { |
665 // if the source color is a constant then apply the filter here once rat
her than per pixel | 666 // if the source color is a constant then apply the filter here once rat
her than per pixel |
666 // in a shader. | 667 // in a shader. |
667 if (constantColor) { | 668 if (constantColor) { |
668 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 669 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
669 grPaint->setColor(SkColor2GrColor(filtered)); | 670 grPaint->setColor(SkColor2GrColor(filtered)); |
670 } else { | 671 } else { |
671 SkTDArray<GrFragmentProcessor*> array; | 672 SkTDArray<GrFragmentProcessor*> array; |
| 673 // return false if failed? |
672 if (colorFilter->asFragmentProcessors(context, &array)) { | 674 if (colorFilter->asFragmentProcessors(context, &array)) { |
673 for (int i = 0; i < array.count(); ++i) { | 675 for (int i = 0; i < array.count(); ++i) { |
674 grPaint->addColorProcessor(array[i]); | 676 grPaint->addColorProcessor(array[i]); |
675 array[i]->unref(); | 677 array[i]->unref(); |
676 } | 678 } |
677 } | 679 } |
678 } | 680 } |
679 } | 681 } |
680 | 682 |
681 #ifndef SK_IGNORE_GPU_DITHER | 683 #ifndef SK_IGNORE_GPU_DITHER |
(...skipping 10 matching lines...) Expand all Loading... |
692 // The dither flag is set and the target is likely | 694 // The dither flag is set and the target is likely |
693 // not going to be dithered by the GPU. | 695 // not going to be dithered by the GPU. |
694 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); | 696 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); |
695 if (fp.get()) { | 697 if (fp.get()) { |
696 grPaint->addColorProcessor(fp); | 698 grPaint->addColorProcessor(fp); |
697 grPaint->setDither(false); | 699 grPaint->setDither(false); |
698 } | 700 } |
699 } | 701 } |
700 } | 702 } |
701 #endif | 703 #endif |
| 704 return true; |
702 } | 705 } |
703 | 706 |
704 void SkPaint2GrPaintShader(GrContext* context, GrRenderTarget* rt, const SkPaint
& skPaint, | 707 bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPa
int, |
705 const SkMatrix& viewM, bool constantColor, GrPaint* g
rPaint) { | 708 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint
) { |
706 SkShader* shader = skPaint.getShader(); | 709 SkShader* shader = skPaint.getShader(); |
707 if (NULL == shader) { | 710 if (NULL == shader) { |
708 SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.ge
tColor()), | 711 return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skP
aint.getColor()), |
709 constantColor, grPaint); | 712 constantColor, grPaint); |
710 return; | |
711 } | 713 } |
712 | 714 |
713 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); | 715 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
714 | 716 |
715 // Start a new block here in order to preserve our context state after calli
ng | 717 // Start a new block here in order to preserve our context state after calli
ng |
716 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really | 718 // asFragmentProcessor(). Since these calls get passed back to the client, w
e don't really |
717 // want them messing around with the context. | 719 // want them messing around with the context. |
718 { | 720 { |
719 // Allow the shader to modify paintColor and also create an effect to be
installed as | 721 // Allow the shader to modify paintColor and also create an effect to be
installed as |
720 // the first color effect on the GrPaint. | 722 // the first color effect on the GrPaint. |
721 GrFragmentProcessor* fp = NULL; | 723 GrFragmentProcessor* fp = NULL; |
722 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { | 724 if (!shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCo
lor, &fp)) { |
| 725 return false; |
| 726 } |
| 727 if (fp) { |
723 grPaint->addColorProcessor(fp)->unref(); | 728 grPaint->addColorProcessor(fp)->unref(); |
724 constantColor = false; | 729 constantColor = false; |
725 } | 730 } |
726 } | 731 } |
727 | 732 |
728 // The grcolor is automatically set when calling asFragmentProcessor. | 733 // The grcolor is automatically set when calling asFragmentProcessor. |
729 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 734 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
730 SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grP
aint); | 735 return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantCol
or, grPaint); |
731 } | 736 } |
OLD | NEW |