From c21b09eec91c9e263cb0b88467ea44e348ed4962 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Fri, 28 Aug 2015 18:46:56 -0700 Subject: Change SkShader;asFragmentProcessor signature to no longer take skpaint\grcolor* Committed: https://skia.googlesource.com/skia/+/ecfdc251be71f3d634e76afdd6375bf55fc061aa Review URL: https://codereview.chromium.org/1316513002 --- src/core/SkBitmapProcShader.cpp | 41 ++++++++++++----------------- src/core/SkBitmapProcShader.h | 9 ++++--- src/core/SkColorShader.h | 8 +++--- src/core/SkLightingShader.cpp | 57 +++++++++++++++++++---------------------- src/core/SkLocalMatrixShader.h | 21 +++------------ src/core/SkPictureShader.cpp | 23 ++++++----------- src/core/SkPictureShader.h | 11 +++++--- src/core/SkShader.cpp | 32 ++++++++--------------- 8 files changed, 82 insertions(+), 120 deletions(-) (limited to 'src/core') diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index e382d09c99..c3b10184f4 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -15,6 +15,7 @@ #if SK_SUPPORT_GPU #include "effects/GrBicubicEffect.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "effects/GrSimpleTextureEffect.h" #endif @@ -353,22 +354,21 @@ void SkBitmapProcShader::toString(SkString* str) const { #include "SkGr.h" #include "effects/GrSimpleTextureEffect.h" -bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* context, + const SkMatrix& viewM, const SkMatrix* localMatrix, + SkFilterQuality filterQuality, + GrProcessorDataManager* procDataManager) const { SkMatrix matrix; matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); SkMatrix lmInverse; if (!this->getLocalMatrix().invert(&lmInverse)) { - return false; + return nullptr; } if (localMatrix) { SkMatrix inv; if (!localMatrix->invert(&inv)) { - return false; + return nullptr; } lmInverse.postConcat(inv); } @@ -385,7 +385,7 @@ bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& // are provided by the caller. bool doBicubic; GrTextureParams::FilterMode textureFilterMode = - GrSkFilterQualityToGrFilterMode(paint.getFilterQuality(), viewM, this->getLocalMatrix(), + GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic); GrTextureParams params(tm, textureFilterMode); SkAutoTUnref texture(GrRefCachedBitmapTexture(context, fRawBitmap, ¶ms)); @@ -393,29 +393,20 @@ bool SkBitmapProcShader::asFragmentProcessor(GrContext* context, const SkPaint& if (!texture) { SkErrorInternals::SetError( kInternalError_SkError, "Couldn't convert bitmap to texture."); - return false; + return nullptr; } - *paintColor = (kAlpha_8_SkColorType == fRawBitmap.colorType()) ? - SkColor2GrColor(paint.getColor()) : - SkColor2GrColorJustAlpha(paint.getColor()); - + SkAutoTUnref inner; if (doBicubic) { - *fp = GrBicubicEffect::Create(procDataManager, texture, matrix, tm); + inner.reset(GrBicubicEffect::Create(procDataManager, texture, matrix, tm)); } else { - *fp = GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params); + inner.reset(GrSimpleTextureEffect::Create(procDataManager, texture, matrix, params)); } - return true; -} - -#else - -bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { + return SkRef(inner.get()); + } + return GrExtractAlphaFragmentProcessor::Create(inner); } #endif diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h index 30f860a9bf..4215b90efb 100644 --- a/src/core/SkBitmapProcShader.h +++ b/src/core/SkBitmapProcShader.h @@ -29,10 +29,11 @@ public: SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader) - - bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM, const SkMatrix*, - GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const override; +#if SK_SUPPORT_GPU + const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, + const SkMatrix*, SkFilterQuality, + GrProcessorDataManager*) const override; +#endif class BitmapProcShaderContext : public SkShader::Context { public: diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h index 6702ef6085..b5902b41e1 100644 --- a/src/core/SkColorShader.h +++ b/src/core/SkColorShader.h @@ -49,9 +49,11 @@ public: GradientType asAGradient(GradientInfo* info) const override; - bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const override; +#if SK_SUPPORT_GPU + const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, + const SkMatrix*, SkFilterQuality, + GrProcessorDataManager*) const override; +#endif SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp index a8d346ab1e..4ab233a828 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -72,9 +72,13 @@ public: bool isOpaque() const override; - bool asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor* color, - GrProcessorDataManager*, GrFragmentProcessor** fp) const override; +#if SK_SUPPORT_GPU + const GrFragmentProcessor* asFragmentProcessor(GrContext*, + const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality, + GrProcessorDataManager*) const override; +#endif size_t contextSize() const override; @@ -127,6 +131,7 @@ private: #include "GrCoordTransform.h" #include "GrFragmentProcessor.h" #include "GrTextureAccess.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "SkGr.h" @@ -341,10 +346,12 @@ static bool make_mat(const SkBitmap& bm, return true; } -bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, const SkMatrix* localMatrix, - GrColor* color, GrProcessorDataManager* pdm, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( + GrContext* context, + const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality filterQuality, + GrProcessorDataManager* pdm) const { // we assume diffuse and normal maps have same width and height // TODO: support different sizes SkASSERT(fDiffuseMap.width() == fNormalMap.width() && @@ -352,23 +359,23 @@ bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint SkMatrix diffM, normM; if (!make_mat(fDiffuseMap, this->getLocalMatrix(), localMatrix, &diffM)) { - return false; + return nullptr; } if (!make_mat(fNormalMap, fNormLocalMatrix, localMatrix, &normM)) { - return false; + return nullptr; } bool doBicubic; GrTextureParams::FilterMode diffFilterMode = GrSkFilterQualityToGrFilterMode( - SkTMin(paint.getFilterQuality(), kMedium_SkFilterQuality), + SkTMin(filterQuality, kMedium_SkFilterQuality), viewM, this->getLocalMatrix(), &doBicubic); SkASSERT(!doBicubic); GrTextureParams::FilterMode normFilterMode = GrSkFilterQualityToGrFilterMode( - SkTMin(paint.getFilterQuality(), kMedium_SkFilterQuality), + SkTMin(filterQuality, kMedium_SkFilterQuality), viewM, fNormLocalMatrix, &doBicubic); @@ -379,34 +386,22 @@ bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint SkAutoTUnref diffuseTexture(GrRefCachedBitmapTexture(context, fDiffuseMap, &diffParams)); if (!diffuseTexture) { - SkErrorInternals::SetError(kInternalError_SkError, - "Couldn't convert bitmap to texture."); - return false; + SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bitmap to texture."); + return nullptr; } GrTextureParams normParams(kClamp_TileMode, normFilterMode); SkAutoTUnref normalTexture(GrRefCachedBitmapTexture(context, fNormalMap, &normParams)); if (!normalTexture) { - SkErrorInternals::SetError(kInternalError_SkError, - "Couldn't convert bitmap to texture."); - return false; + SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bitmap to texture."); + return nullptr; } - *fp = new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffParams, normParams, - fLights, fInvNormRotation); - - *color = GrColorPackA4(paint.getAlpha()); - return true; -} -#else - -bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, const SkMatrix* localMatrix, - GrColor* color, GrProcessorDataManager*, - GrFragmentProcessor** fp) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + SkAutoTUnref inner ( + new LightingFP(pdm, diffuseTexture, normalTexture, diffM, normM, diffParams, normParams, + fLights, fInvNormRotation)); + return GrExtractAlphaFragmentProcessor::Create(inner); } #endif diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h index a145432a16..9c6a526f7b 100644 --- a/src/core/SkLocalMatrixShader.h +++ b/src/core/SkLocalMatrixShader.h @@ -33,28 +33,15 @@ public: } #if SK_SUPPORT_GPU - - virtual bool asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, const SkMatrix* localMatrix, - GrColor* grColor, GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const override { + const GrFragmentProcessor* asFragmentProcessor(GrContext* context, const SkMatrix& viewM, + const SkMatrix* localMatrix, SkFilterQuality fq, + GrProcessorDataManager* procDataManager) const override { SkMatrix tmp = this->getLocalMatrix(); if (localMatrix) { tmp.preConcat(*localMatrix); } - return fProxyShader->asFragmentProcessor(context, paint, viewM, &tmp, grColor, - procDataManager, fp); + return fProxyShader->asFragmentProcessor(context, viewM, &tmp, fq, procDataManager); } - -#else - - virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const override { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; - } - #endif SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const override { diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp index 0b3c9e864b..1f4d3cd948 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -336,27 +336,20 @@ void SkPictureShader::toString(SkString* str) const { #endif #if SK_SUPPORT_GPU -bool SkPictureShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, const SkMatrix* localMatrix, - GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkPictureShader::asFragmentProcessor( + GrContext* context, + const SkMatrix& viewM, + const SkMatrix* localMatrix, + SkFilterQuality fq, + GrProcessorDataManager* procDataManager) const { int maxTextureSize = 0; if (context) { maxTextureSize = context->caps()->maxTextureSize(); } SkAutoTUnref bitmapShader(this->refBitmapShader(viewM, localMatrix, maxTextureSize)); if (!bitmapShader) { - return false; + return nullptr; } - return bitmapShader->asFragmentProcessor(context, paint, viewM, nullptr, paintColor, - procDataManager, fp); -} -#else -bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + return bitmapShader->asFragmentProcessor(context, viewM, nullptr, fq, procDataManager); } #endif diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h index 31a60fd9e2..9b270e3899 100644 --- a/src/core/SkPictureShader.h +++ b/src/core/SkPictureShader.h @@ -1,3 +1,4 @@ + /* * Copyright 2014 Google Inc. * @@ -30,9 +31,13 @@ public: SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader) - bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM, const SkMatrix*, - GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const override; +#if SK_SUPPORT_GPU + const GrFragmentProcessor* asFragmentProcessor(GrContext*, + const SkMatrix& viewM, + const SkMatrix*, + SkFilterQuality, + GrProcessorDataManager*) const override; +#endif protected: SkPictureShader(SkReadBuffer&); diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp index 51a8017b5e..b3edf47dfd 100644 --- a/src/core/SkShader.cpp +++ b/src/core/SkShader.cpp @@ -214,10 +214,10 @@ SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const { return kNone_GradientType; } -bool SkShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, const SkMatrix*, - GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - return false; +const GrFragmentProcessor* SkShader::asFragmentProcessor(GrContext*, const SkMatrix&, + const SkMatrix*, SkFilterQuality, + GrProcessorDataManager*) const { + return nullptr; } SkShader* SkShader::refAsALocalMatrixShader(SkMatrix*) const { @@ -335,24 +335,12 @@ SkShader::GradientType SkColorShader::asAGradient(GradientInfo* info) const { #if SK_SUPPORT_GPU #include "SkGr.h" - -bool SkColorShader::asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix&, - const SkMatrix*, GrColor* paintColor, - GrProcessorDataManager*, GrFragmentProcessor** fp) const { - *fp = nullptr; - SkColor skColor = fColor; - U8CPU newA = SkMulDiv255Round(SkColorGetA(fColor), paint.getAlpha()); - *paintColor = SkColor2GrColor(SkColorSetA(skColor, newA)); - return true; -} - -#else - -bool SkColorShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; +#include "effects/GrConstColorProcessor.h" +const GrFragmentProcessor* SkColorShader::asFragmentProcessor(GrContext*, const SkMatrix&, + const SkMatrix*, SkFilterQuality, + GrProcessorDataManager*) const { + GrColor color = SkColor2GrColor(fColor); + return GrConstColorProcessor::Create(color, GrConstColorProcessor::kModulateA_InputMode); } #endif -- cgit v1.2.3