| 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 "GrCaps.h" | 10 #include "GrCaps.h" |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 *ctOut = ct; | 701 *ctOut = ct; |
| 702 } | 702 } |
| 703 if (ptOut) { | 703 if (ptOut) { |
| 704 *ptOut = pt; | 704 *ptOut = pt; |
| 705 } | 705 } |
| 706 return true; | 706 return true; |
| 707 } | 707 } |
| 708 | 708 |
| 709 /////////////////////////////////////////////////////////////////////////////// | 709 /////////////////////////////////////////////////////////////////////////////// |
| 710 | 710 |
| 711 bool SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPai
nt& skPaint, | 711 bool SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor
paintColor, |
| 712 GrColor paintColor, bool constantColor, GrPaint* gr
Paint) { | 712 bool constantColor, GrPaint* grPaint) { |
| 713 | 713 |
| 714 grPaint->setDither(skPaint.isDither()); | |
| 715 grPaint->setAntiAlias(skPaint.isAntiAlias()); | 714 grPaint->setAntiAlias(skPaint.isAntiAlias()); |
| 716 | 715 |
| 717 SkXfermode* mode = skPaint.getXfermode(); | 716 SkXfermode* mode = skPaint.getXfermode(); |
| 718 GrXPFactory* xpFactory = nullptr; | 717 GrXPFactory* xpFactory = nullptr; |
| 719 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { | 718 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { |
| 720 // Fall back to src-over | 719 // Fall back to src-over |
| 721 // return false here? | 720 // return false here? |
| 722 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); | 721 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); |
| 723 } | 722 } |
| 724 SkASSERT(xpFactory); | 723 SkASSERT(xpFactory); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 741 &array)) { | 740 &array)) { |
| 742 for (int i = 0; i < array.count(); ++i) { | 741 for (int i = 0; i < array.count(); ++i) { |
| 743 grPaint->addColorFragmentProcessor(array[i]); | 742 grPaint->addColorFragmentProcessor(array[i]); |
| 744 array[i]->unref(); | 743 array[i]->unref(); |
| 745 } | 744 } |
| 746 } | 745 } |
| 747 } | 746 } |
| 748 } | 747 } |
| 749 | 748 |
| 750 #ifndef SK_IGNORE_GPU_DITHER | 749 #ifndef SK_IGNORE_GPU_DITHER |
| 751 // If the dither flag is set, then we need to see if the underlying context | |
| 752 // supports it. If not, then install a dither effect. | |
| 753 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) { | 750 if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0) { |
| 754 // What are we rendering into? | 751 grPaint->addColorFragmentProcessor(GrDitherEffect::Create())->unref(); |
| 755 SkASSERT(rt); | |
| 756 | |
| 757 // Suspect the dithering flag has no effect on these configs, otherwise | |
| 758 // fall back on setting the appropriate state. | |
| 759 if (GrPixelConfigIs8888(rt->config()) || | |
| 760 GrPixelConfigIs8888(rt->config())) { | |
| 761 // The dither flag is set and the target is likely | |
| 762 // not going to be dithered by the GPU. | |
| 763 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); | |
| 764 if (fp.get()) { | |
| 765 grPaint->addColorFragmentProcessor(fp); | |
| 766 grPaint->setDither(false); | |
| 767 } | |
| 768 } | |
| 769 } | 752 } |
| 770 #endif | 753 #endif |
| 771 return true; | 754 return true; |
| 772 } | 755 } |
| 773 | 756 |
| 774 bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPa
int, | 757 bool SkPaint2GrPaint(GrContext* context,const SkPaint& skPaint, const SkMatrix&
viewM, |
| 775 const SkMatrix& viewM, bool constantColor, GrPaint* grPaint
) { | 758 bool constantColor, GrPaint* grPaint) { |
| 776 SkShader* shader = skPaint.getShader(); | 759 SkShader* shader = skPaint.getShader(); |
| 777 if (nullptr == shader) { | 760 if (nullptr == shader) { |
| 778 return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skP
aint.getColor()), | 761 return SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint
.getColor()), |
| 779 constantColor, grPaint); | 762 constantColor, grPaint); |
| 780 } | 763 } |
| 781 | 764 |
| 782 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); | 765 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); |
| 783 | 766 |
| 784 const GrFragmentProcessor* fp = shader->asFragmentProcessor(context, viewM,
NULL, | 767 const GrFragmentProcessor* fp = shader->asFragmentProcessor(context, viewM,
NULL, |
| 785 skPaint.getFilterQuality(), grPaint->getProcessorDataManager()); | 768 skPaint.getFilterQuality(), grPaint->getProcessorDataManager()); |
| 786 if (!fp) { | 769 if (!fp) { |
| 787 return false; | 770 return false; |
| 788 } | 771 } |
| 789 grPaint->addColorFragmentProcessor(fp)->unref(); | 772 grPaint->addColorFragmentProcessor(fp)->unref(); |
| 790 constantColor = false; | 773 constantColor = false; |
| 791 | 774 |
| 792 // The grcolor is automatically set when calling asFragmentProcessor. | 775 // The grcolor is automatically set when calling asFragmentProcessor. |
| 793 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 776 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 794 return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantCol
or, grPaint); | 777 return SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor,
grPaint); |
| 795 } | 778 } |
| 796 | 779 |
| 797 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { | 780 SkImageInfo GrMakeInfoFromTexture(GrTexture* tex, int w, int h, bool isOpaque) { |
| 798 #ifdef SK_DEBUG | 781 #ifdef SK_DEBUG |
| 799 const GrSurfaceDesc& desc = tex->desc(); | 782 const GrSurfaceDesc& desc = tex->desc(); |
| 800 SkASSERT(w <= desc.fWidth); | 783 SkASSERT(w <= desc.fWidth); |
| 801 SkASSERT(h <= desc.fHeight); | 784 SkASSERT(h <= desc.fHeight); |
| 802 #endif | 785 #endif |
| 803 const GrPixelConfig config = tex->config(); | 786 const GrPixelConfig config = tex->config(); |
| 804 SkColorType ct; | 787 SkColorType ct; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 SkErrorInternals::SetError( kInvalidPaint_SkError, | 833 SkErrorInternals::SetError( kInvalidPaint_SkError, |
| 851 "Sorry, I don't understand the filtering
" | 834 "Sorry, I don't understand the filtering
" |
| 852 "mode you asked for. Falling back to " | 835 "mode you asked for. Falling back to " |
| 853 "MIPMaps."); | 836 "MIPMaps."); |
| 854 textureFilterMode = GrTextureParams::kMipMap_FilterMode; | 837 textureFilterMode = GrTextureParams::kMipMap_FilterMode; |
| 855 break; | 838 break; |
| 856 | 839 |
| 857 } | 840 } |
| 858 return textureFilterMode; | 841 return textureFilterMode; |
| 859 } | 842 } |
| OLD | NEW |