| 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 "GrTextureMaker.h" | 8 #include "GrTextureMaker.h" |
| 9 | 9 |
| 10 #include "SkGr.h" | 10 #include "SkGr.h" |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 } | 670 } |
| 671 if (ptOut) { | 671 if (ptOut) { |
| 672 *ptOut = pt; | 672 *ptOut = pt; |
| 673 } | 673 } |
| 674 return true; | 674 return true; |
| 675 } | 675 } |
| 676 | 676 |
| 677 | 677 |
| 678 ////////////////////////////////////////////////////////////////////////////////
//////////////// | 678 ////////////////////////////////////////////////////////////////////////////////
//////////////// |
| 679 | 679 |
| 680 static inline bool blend_requires_shader(const SkXfermode::Mode mode, bool primi
tiveIsSrc) { |
| 681 if (primitiveIsSrc) { |
| 682 return SkXfermode::kSrc_Mode != mode; |
| 683 } else { |
| 684 return SkXfermode::kDst_Mode != mode; |
| 685 } |
| 686 } |
| 687 |
| 680 static inline bool skpaint_to_grpaint_impl(GrContext* context, | 688 static inline bool skpaint_to_grpaint_impl(GrContext* context, |
| 681 const SkPaint& skPaint, | 689 const SkPaint& skPaint, |
| 682 const SkMatrix& viewM, | 690 const SkMatrix& viewM, |
| 683 const GrFragmentProcessor** shaderPro
cessor, | 691 const GrFragmentProcessor** shaderPro
cessor, |
| 684 SkXfermode::Mode* primColorMode, | 692 SkXfermode::Mode* primColorMode, |
| 685 bool primitiveIsSrc, | 693 bool primitiveIsSrc, |
| 686 GrPaint* grPaint) { | 694 GrPaint* grPaint) { |
| 687 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 695 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 688 | 696 |
| 689 // Setup the initial color considering the shader, the SkPaint color, and th
e presence or not | 697 // Setup the initial color considering the shader, the SkPaint color, and th
e presence or not |
| 690 // of per-vertex colors. | 698 // of per-vertex colors. |
| 691 SkAutoTUnref<const GrFragmentProcessor> aufp; | 699 SkAutoTUnref<const GrFragmentProcessor> aufp; |
| 692 const GrFragmentProcessor* shaderFP = NULL; | 700 const GrFragmentProcessor* shaderFP = nullptr; |
| 693 if (shaderProcessor) { | 701 if (!primColorMode || blend_requires_shader(*primColorMode, primitiveIsSrc))
{ |
| 694 shaderFP = *shaderProcessor; | 702 if (shaderProcessor) { |
| 695 } else if (const SkShader* shader = skPaint.getShader()) { | 703 shaderFP = *shaderProcessor; |
| 696 aufp.reset(shader->asFragmentProcessor(context, viewM, NULL, skPaint.get
FilterQuality(), | 704 } else if (const SkShader* shader = skPaint.getShader()) { |
| 697 grPaint->getProcessorDataManager(
))); | 705 aufp.reset(shader->asFragmentProcessor(context, viewM, nullptr, |
| 698 shaderFP = aufp; | 706 skPaint.getFilterQuality(), |
| 699 if (!shaderFP) { | 707 grPaint->getProcessorDataMana
ger())); |
| 700 return false; | 708 shaderFP = aufp; |
| 709 if (!shaderFP) { |
| 710 return false; |
| 711 } |
| 701 } | 712 } |
| 702 } | 713 } |
| 703 | 714 |
| 704 // Set this in below cases if the output of the shader/paint-color/paint-alp
ha/primXfermode is | 715 // Set this in below cases if the output of the shader/paint-color/paint-alp
ha/primXfermode is |
| 705 // a known constant value. In that case we can simply apply a color filter d
uring this | 716 // a known constant value. In that case we can simply apply a color filter d
uring this |
| 706 // conversion without converting the color filter to a GrFragmentProcessor. | 717 // conversion without converting the color filter to a GrFragmentProcessor. |
| 707 bool applyColorFilterToPaintColor = false; | 718 bool applyColorFilterToPaintColor = false; |
| 708 if (shaderFP) { | 719 if (shaderFP) { |
| 709 if (primColorMode) { | 720 if (primColorMode) { |
| 710 // There is a blend between the primitive color and the shader color
. The shader sees | 721 // There is a blend between the primitive color and the shader color
. The shader sees |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754
*primColorMode)); | 765
*primColorMode)); |
| 755 } else { | 766 } else { |
| 756 processor.reset(GrXfermodeFragmentProcessor::CreateFromSrcProces
sor(processor, | 767 processor.reset(GrXfermodeFragmentProcessor::CreateFromSrcProces
sor(processor, |
| 757
*primColorMode)); | 768
*primColorMode)); |
| 758 | 769 |
| 759 } | 770 } |
| 760 if (processor) { | 771 if (processor) { |
| 761 grPaint->addColorFragmentProcessor(processor); | 772 grPaint->addColorFragmentProcessor(processor); |
| 762 } | 773 } |
| 763 | 774 |
| 764 grPaint->setColor(SkColorToUnpremulGrColor(skPaint.getColor()) | 0xF
F000000); | 775 grPaint->setColor(SkColorToOpaqueGrColor(skPaint.getColor())); |
| 765 | 776 |
| 766 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); | 777 GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor()); |
| 767 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Create( | 778 if (GrColor_WHITE != paintAlpha) { |
| 768 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode))->un
ref(); | 779 grPaint->addColorFragmentProcessor(GrConstColorProcessor::Create
( |
| 780 paintAlpha, GrConstColorProcessor::kModulateRGBA_InputMode))
->unref(); |
| 781 } |
| 769 } else { | 782 } else { |
| 770 // No shader, no primitive color. | 783 // No shader, no primitive color. |
| 771 grPaint->setColor(SkColorToPremulGrColor(skPaint.getColor())); | 784 grPaint->setColor(SkColorToPremulGrColor(skPaint.getColor())); |
| 772 applyColorFilterToPaintColor = true; | 785 applyColorFilterToPaintColor = true; |
| 773 } | 786 } |
| 774 } | 787 } |
| 775 | 788 |
| 776 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 789 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
| 777 if (colorFilter) { | 790 if (colorFilter) { |
| 778 if (applyColorFilterToPaintColor) { | 791 if (applyColorFilterToPaintColor) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 SkBitmap stretchedBmp = stretch_on_cpu(bitmap, stretch); | 974 SkBitmap stretchedBmp = stretch_on_cpu(bitmap, stretch); |
| 962 return create_unstretched_bitmap_texture(ctx, stretchedBmp, GrUniqueKey(
)); | 975 return create_unstretched_bitmap_texture(ctx, stretchedBmp, GrUniqueKey(
)); |
| 963 } else { | 976 } else { |
| 964 SkAutoTUnref<GrTexture> unstretched(this->onRefUnstretchedTexture(ctx)); | 977 SkAutoTUnref<GrTexture> unstretched(this->onRefUnstretchedTexture(ctx)); |
| 965 if (!unstretched) { | 978 if (!unstretched) { |
| 966 return nullptr; | 979 return nullptr; |
| 967 } | 980 } |
| 968 return stretch_texture(unstretched, stretch, nullptr, GrUniqueKey()); | 981 return stretch_texture(unstretched, stretch, nullptr, GrUniqueKey()); |
| 969 } | 982 } |
| 970 } | 983 } |
| OLD | NEW |