diff options
62 files changed, 370 insertions, 442 deletions
diff --git a/gm/dcshader.cpp b/gm/dcshader.cpp index 3eee43d147..28c811de22 100644 --- a/gm/dcshader.cpp +++ b/gm/dcshader.cpp @@ -10,6 +10,7 @@ #if SK_SUPPORT_GPU #include "GrFragmentProcessor.h" #include "GrCoordTransform.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "Resources.h" @@ -33,9 +34,8 @@ public: buf.writeMatrix(fDeviceMatrix); } - bool asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor* color, GrProcessorDataManager*, - GrFragmentProcessor** fp) const override; + const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix& viewM, + const SkMatrix* localMatrix, SkFilterQuality, GrProcessorDataManager*) const override; #ifndef SK_IGNORE_TO_STRING void toString(SkString* str) const override { @@ -94,13 +94,10 @@ private: GrCoordTransform fDeviceTransform; }; -bool DCShader::asFragmentProcessor(GrContext*, const SkPaint& paint, const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor* color, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { - *fp = new DCFP(procDataManager, fDeviceMatrix); - *color = GrColorPackA4(paint.getAlpha()); - return true; +const GrFragmentProcessor* DCShader::asFragmentProcessor(GrContext*, const SkMatrix& viewM, + const SkMatrix* localMatrix, SkFilterQuality, GrProcessorDataManager* procDataManager) const { + SkAutoTUnref<const GrFragmentProcessor> inner(new DCFP(procDataManager, fDeviceMatrix)); + return GrExtractAlphaFragmentProcessor::Create(inner); } class DCShaderGM : public GM { diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index 60ac5eb30b..ce623560cd 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -46,6 +46,7 @@ '<(skia_include_path)/gpu/effects/GrConstColorProcessor.h', '<(skia_include_path)/gpu/effects/GrCoverageSetOpXP.h', '<(skia_include_path)/gpu/effects/GrCustomXfermode.h', + '<(skia_include_path)/gpu/effects/GrExtractAlphaFragmentProcessor.h', '<(skia_include_path)/gpu/effects/GrPorterDuffXferProcessor.h', '<(skia_include_path)/gpu/gl/GrGLConfig.h', @@ -249,6 +250,7 @@ '<(skia_src_path)/gpu/effects/GrConfigConversionEffect.cpp', '<(skia_src_path)/gpu/effects/GrConfigConversionEffect.h', '<(skia_src_path)/gpu/effects/GrConstColorProcessor.cpp', + '<(skia_src_path)/gpu/effects/GrExtractAlphaFragmentProcessor.cpp', '<(skia_src_path)/gpu/effects/GrCoverageSetOpXP.cpp', '<(skia_src_path)/gpu/effects/GrCustomXfermode.cpp', '<(skia_src_path)/gpu/effects/GrCustomXfermodePriv.h', diff --git a/include/core/SkShader.h b/include/core/SkShader.h index 47fdc9492f..8aaaf52047 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -334,27 +334,20 @@ public: /** - * Returns true if the shader subclass succeeds in creating an effect or if none is required. - * False is returned if it fails or if there is not an implementation of this method in the - * shader subclass. + * Returns a GrFragmentProcessor that implements the shader for the GPU backend. NULL is + * returned if there is no GPU implementation. * - * On success an implementation of this method must inspect the SkPaint and set paintColor to - * the color the effect expects as its input color. If the SkShader wishes to emit a solid - * color then it should set paintColor to that color and not create an effect. Note that - * GrColor is always premul. The common patterns are to convert paint's SkColor to GrColor or - * to extract paint's alpha and replicate it to all channels in paintColor. Upon failure - * paintColor should not be modified. It is not recommended to specialize the effect to - * the paint's color as then many GPU shaders may be generated. + * The GPU device does not call SkShader::createContext(), instead we pass the view matrix, + * local matrix, and filter quality directly. * - * The GrContext may be used by the effect to create textures. The GPU device does not - * call createContext. Instead we pass the SkPaint here in case the shader needs paint info. - * - * A view matrix is always required to create the correct GrFragmentProcessor. Some shaders - * may also use the optional localMatrix to define a matrix relevant only for sampling. + * The GrContext may be used by the to create textures that are required by the returned + * processor. */ - virtual bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor*, - GrProcessorDataManager*, GrFragmentProcessor**) const; + virtual const GrFragmentProcessor* asFragmentProcessor(GrContext*, + const SkMatrix& viewMatric, + const SkMatrix* localMatrix, + SkFilterQuality, + GrProcessorDataManager*) const; /** * If the shader can represent its "average" luminance in a single color, return true and diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h index f548c674e2..1caece6f20 100644 --- a/include/effects/SkPerlinNoiseShader.h +++ b/include/effects/SkPerlinNoiseShader.h @@ -96,9 +96,11 @@ public: typedef SkShader::Context INHERITED; }; - virtual bool asFragmentProcessor(GrContext* context, const SkPaint&, const SkMatrix& viewM, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const override; +#if SK_SUPPORT_GPU + const GrFragmentProcessor* asFragmentProcessor(GrContext* context, const SkMatrix& viewM, + const SkMatrix*, SkFilterQuality, + GrProcessorDataManager*) const override; +#endif SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h index 9c9f05acdb..3fc87c0de7 100644 --- a/include/gpu/GrFragmentProcessor.h +++ b/include/gpu/GrFragmentProcessor.h @@ -9,6 +9,7 @@ #define GrFragmentProcessor_DEFINED #include "GrProcessor.h" +#include "GrInvariantOutput.h" class GrCoordTransform; class GrGLSLCaps; @@ -82,7 +83,9 @@ public: * inout to indicate known values of its output. A component of the color member only has * meaning if the corresponding bit in validFlags is set. */ - void computeInvariantOutput(GrInvariantOutput* inout) const; + void computeInvariantOutput(GrInvariantOutput* inout) const { + this->onComputeInvariantOutput(inout); + } protected: void addTextureAccess(const GrTextureAccess* textureAccess) override; diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h index 3a2457e98c..66ba239602 100644 --- a/include/gpu/GrProcessorUnitTest.h +++ b/include/gpu/GrProcessorUnitTest.h @@ -61,14 +61,14 @@ template <class Processor> class GrProcessorTestFactory : SkNoncopyable { public: - typedef Processor* (*CreateProc)(GrProcessorTestData*); + typedef const Processor* (*CreateProc)(GrProcessorTestData*); GrProcessorTestFactory(CreateProc createProc) { fCreateProc = createProc; GetFactories()->push_back(this); } - static Processor* CreateStage(GrProcessorTestData* data) { + static const Processor* CreateStage(GrProcessorTestData* data) { VerifyFactoryCount(); SkASSERT(GetFactories()->count()); uint32_t idx = data->fRandom->nextRangeU(0, GetFactories()->count() - 1); @@ -92,15 +92,15 @@ private: */ #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ static GrProcessorTestFactory<GrGeometryProcessor> gTestFactory SK_UNUSED; \ - static GrGeometryProcessor* TestCreate(GrProcessorTestData*) + static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ static GrProcessorTestFactory<GrFragmentProcessor> gTestFactory SK_UNUSED; \ - static GrFragmentProcessor* TestCreate(GrProcessorTestData*) + static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) #define GR_DECLARE_XP_FACTORY_TEST \ static GrProcessorTestFactory<GrXPFactory> gTestFactory SK_UNUSED; \ - static GrXPFactory* TestCreate(GrProcessorTestData*) + static const GrXPFactory* TestCreate(GrProcessorTestData*) /** GrProcessor subclasses should insert this macro in their implementation file. They must then @@ -121,19 +121,19 @@ private: // The unit test relies on static initializers. Just declare the TestCreate function so that // its definitions will compile. #define GR_DECLARE_FRAGMENT_PROCESSOR_TEST \ - static GrFragmentProcessor* TestCreate(GrProcessorTestData*) + static const GrFragmentProcessor* TestCreate(GrProcessorTestData*) #define GR_DEFINE_FRAGMENT_PROCESSOR_TEST(X) // The unit test relies on static initializers. Just declare the TestCreate function so that // its definitions will compile. #define GR_DECLARE_XP_FACTORY_TEST \ - static GrXPFactory* TestCreate(GrProcessorTestData*) + static const GrXPFactory* TestCreate(GrProcessorTestData*) #define GR_DEFINE_XP_FACTORY_TEST(X) // The unit test relies on static initializers. Just declare the TestCreate function so that // its definitions will compile. #define GR_DECLARE_GEOMETRY_PROCESSOR_TEST \ - static GrGeometryProcessor* TestCreate(GrProcessorTestData*) + static const GrGeometryProcessor* TestCreate(GrProcessorTestData*) #define GR_DEFINE_GEOMETRY_PROCESSOR_TEST(X) #endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS diff --git a/include/gpu/effects/GrConstColorProcessor.h b/include/gpu/effects/GrConstColorProcessor.h index ccd28684a5..f5fdb7e35c 100644 --- a/include/gpu/effects/GrConstColorProcessor.h +++ b/include/gpu/effects/GrConstColorProcessor.h @@ -10,8 +10,6 @@ #include "GrFragmentProcessor.h" -class GrInvariantOutput; - /** * This is a simple GrFragmentProcessor that outputs a constant color. It may do one of the * following with its input color: ignore it, or multiply it by the constant color, multiply its @@ -32,8 +30,6 @@ public: return new GrConstColorProcessor(color, mode); } - ~GrConstColorProcessor() override {} - const char* name() const override { return "Color"; } GrColor color() const { return fColor; } diff --git a/include/gpu/effects/GrExtractAlphaFragmentProcessor.h b/include/gpu/effects/GrExtractAlphaFragmentProcessor.h new file mode 100644 index 0000000000..d26f00f9a9 --- /dev/null +++ b/include/gpu/effects/GrExtractAlphaFragmentProcessor.h @@ -0,0 +1,45 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrExtractAlphaFragmentProcessor_DEFINED +#define GrExtractAlphaFragmentProcessor_DEFINED + +#include "GrFragmentProcessor.h" + +/** This processor extracts the incoming color's alpha, ignores r, g, and b, and feeds + the replicated alpha to it's inner processor. */ +class GrExtractAlphaFragmentProcessor : public GrFragmentProcessor { +public: + static GrFragmentProcessor* Create(const GrFragmentProcessor* processor) { + if (!processor) { + return nullptr; + } + return SkNEW_ARGS(GrExtractAlphaFragmentProcessor, (processor)); + } + + ~GrExtractAlphaFragmentProcessor() override {} + + const char* name() const override { return "Extract Alpha"; } + +private: + GrExtractAlphaFragmentProcessor(const GrFragmentProcessor* processor) { + this->initClassID<GrExtractAlphaFragmentProcessor>(); + this->registerChildProcessor(processor); + } + + GrGLFragmentProcessor* onCreateGLInstance() const override; + + void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override; + + bool onIsEqual(const GrFragmentProcessor&) const override; + + void onComputeInvariantOutput(GrInvariantOutput* inout) const override; + + typedef GrFragmentProcessor INHERITED; +}; + +#endif 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<GrTexture> 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<GrFragmentProcessor> 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..212cdb65f9 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -72,9 +72,10 @@ 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 +128,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 +343,9 @@ 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 +353,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 +380,22 @@ bool SkLightingShaderImpl::asFragmentProcessor(GrContext* context, const SkPaint SkAutoTUnref<GrTexture> 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<GrTexture> 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<const GrFragmentProcessor> 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..f3ac638025 100644 --- a/src/core/SkPictureShader.cpp +++ b/src/core/SkPictureShader.cpp @@ -336,27 +336,17 @@ 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<SkShader> 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..6249e41e37 100644 --- a/src/core/SkPictureShader.h +++ b/src/core/SkPictureShader.h @@ -30,9 +30,10 @@ 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 diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index 0f96cdf59a..b28a62bcd7 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -195,7 +195,7 @@ void GrGLAlphaThresholdEffect::onSetData(const GrGLProgramDataManager& pdman, GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AlphaThresholdEffect); -GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* AlphaThresholdEffect::TestCreate(GrProcessorTestData* d) { GrTexture* bmpTex = d->fTextures[GrProcessorUnitTest::kSkiaPMTextureIdx]; GrTexture* maskTex = d->fTextures[GrProcessorUnitTest::kAlphaTextureIdx]; float innerThresh = d->fRandom->nextUScalar1(); diff --git a/src/effects/SkArithmeticMode_gpu.cpp b/src/effects/SkArithmeticMode_gpu.cpp index 7732917e42..fd20b73cdc 100644 --- a/src/effects/SkArithmeticMode_gpu.cpp +++ b/src/effects/SkArithmeticMode_gpu.cpp @@ -137,7 +137,7 @@ void GrArithmeticFP::onComputeInvariantOutput(GrInvariantOutput* inout) const { /////////////////////////////////////////////////////////////////////////////// -GrFragmentProcessor* GrArithmeticFP::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrArithmeticFP::TestCreate(GrProcessorTestData* d) { float k1 = d->fRandom->nextF(); float k2 = d->fRandom->nextF(); float k3 = d->fRandom->nextF(); @@ -295,7 +295,7 @@ void GrArithmeticXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorP GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory); -GrXPFactory* GrArithmeticXPFactory::TestCreate(GrProcessorTestData* d) { +const GrXPFactory* GrArithmeticXPFactory::TestCreate(GrProcessorTestData* d) { float k1 = d->fRandom->nextF(); float k2 = d->fRandom->nextF(); float k3 = d->fRandom->nextF(); diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index f2bcf3ed0d..1bd708b5e0 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -816,7 +816,7 @@ void GrRectBlurEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRectBlurEffect); -GrFragmentProcessor* GrRectBlurEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrRectBlurEffect::TestCreate(GrProcessorTestData* d) { float sigma = d->fRandom->nextRangeF(3,8); float width = d->fRandom->nextRangeF(200,300); float height = d->fRandom->nextRangeF(200,300); @@ -997,7 +997,7 @@ bool GrRRectBlurEffect::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRRectBlurEffect); -GrFragmentProcessor* GrRRectBlurEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrRRectBlurEffect::TestCreate(GrProcessorTestData* d) { SkScalar w = d->fRandom->nextRangeScalar(100.f, 1000.f); SkScalar h = d->fRandom->nextRangeScalar(100.f, 1000.f); SkScalar r = d->fRandom->nextRangeF(1.f, 9.f); diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp index c3fa730d00..c38328ccbb 100644 --- a/src/effects/SkColorFilters.cpp +++ b/src/effects/SkColorFilters.cpp @@ -339,7 +339,7 @@ void ModeColorFilterEffect::onComputeInvariantOutput(GrInvariantOutput* inout) c } GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ModeColorFilterEffect); -GrFragmentProcessor* ModeColorFilterEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* ModeColorFilterEffect::TestCreate(GrProcessorTestData* d) { SkXfermode::Mode mode = SkXfermode::kDst_Mode; while (SkXfermode::kDst_Mode == mode) { mode = static_cast<SkXfermode::Mode>(d->fRandom->nextRangeU(0, SkXfermode::kLastCoeffMode)); diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index 8dc603042c..92b26ebdf9 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -526,7 +526,7 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorMatrixEffect); -GrFragmentProcessor* ColorMatrixEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* ColorMatrixEffect::TestCreate(GrProcessorTestData* d) { SkColorMatrix colorMatrix; for (size_t i = 0; i < SK_ARRAY_COUNT(colorMatrix.fMat); ++i) { colorMatrix.fMat[i] = d->fRandom->nextSScalar1(); diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 9044284300..49290718e3 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -517,7 +517,7 @@ void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout) GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect); -GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(GrProcessorTestData* d) { int texIdxDispl = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; int texIdxColor = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index dd56751382..240a6939ae 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -1633,7 +1633,7 @@ GrGLFragmentProcessor* GrDiffuseLightingEffect::onCreateGLInstance() const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDiffuseLightingEffect); -GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrDiffuseLightingEffect::TestCreate(GrProcessorTestData* d) { SkScalar surfaceScale = d->fRandom->nextSScalar1(); SkScalar kd = d->fRandom->nextUScalar1(); SkAutoTUnref<SkImageFilterLight> light(create_random_light(d->fRandom)); @@ -1836,7 +1836,7 @@ GrGLFragmentProcessor* GrSpecularLightingEffect::onCreateGLInstance() const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSpecularLightingEffect); -GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrSpecularLightingEffect::TestCreate(GrProcessorTestData* d) { SkScalar surfaceScale = d->fRandom->nextSScalar1(); SkScalar ks = d->fRandom->nextUScalar1(); SkScalar shininess = d->fRandom->nextUScalar1(); diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index b9998f8122..622144bfad 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -195,7 +195,7 @@ GrGLFragmentProcessor* GrMagnifierEffect::onCreateGLInstance() const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMagnifierEffect); -GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrMagnifierEffect::TestCreate(GrProcessorTestData* d) { GrTexture* texture = d->fTextures[0]; const int kMaxWidth = 200; const int kMaxHeight = 200; diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index cde29c0f4c..2c99af92da 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -445,7 +445,7 @@ void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMorphologyEffect); -GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrMorphologyEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index af6622be4d..40da2db14a 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -19,6 +19,8 @@ #include "GrCoordTransform.h" #include "GrInvariantOutput.h" #include "SkGr.h" +#include "effects/GrConstColorProcessor.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #endif @@ -500,7 +502,6 @@ private: bool fStitchTiles; int fNumOctaves; GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; - GrGLProgramDataManager::UniformHandle fAlphaUni; private: typedef GrGLFragmentProcessor INHERITED; @@ -515,9 +516,9 @@ public: int numOctaves, bool stitchTiles, SkPerlinNoiseShader::PaintingData* paintingData, GrTexture* permutationsTexture, GrTexture* noiseTexture, - const SkMatrix& matrix, uint8_t alpha) { + const SkMatrix& matrix) { return new GrPerlinNoiseEffect(procDataManager, type, numOctaves, stitchTiles, paintingData, - permutationsTexture, noiseTexture, matrix, alpha); + permutationsTexture, noiseTexture, matrix); } virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } @@ -531,7 +532,6 @@ public: const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency; } int numOctaves() const { return fNumOctaves; } const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } - uint8_t alpha() const { return fAlpha; } private: GrGLFragmentProcessor* onCreateGLInstance() const override { @@ -549,7 +549,6 @@ private: fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency && fNumOctaves == s.fNumOctaves && fStitchTiles == s.fStitchTiles && - fAlpha == s.fAlpha && fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit; } @@ -561,11 +560,10 @@ private: int numOctaves, bool stitchTiles, SkPerlinNoiseShader::PaintingData* paintingData, GrTexture* permutationsTexture, GrTexture* noiseTexture, - const SkMatrix& matrix, uint8_t alpha) + const SkMatrix& matrix) : fType(type) , fNumOctaves(numOctaves) , fStitchTiles(stitchTiles) - , fAlpha(alpha) , fPermutationsAccess(permutationsTexture) , fNoiseAccess(noiseTexture) , fPaintingData(paintingData) { @@ -582,7 +580,6 @@ private: GrCoordTransform fCoordTransform; int fNumOctaves; bool fStitchTiles; - uint8_t fAlpha; GrTextureAccess fPermutationsAccess; GrTextureAccess fNoiseAccess; SkPerlinNoiseShader::PaintingData *fPaintingData; @@ -594,7 +591,7 @@ private: ///////////////////////////////////////////////////////////////////// GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoiseEffect); -GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { int numOctaves = d->fRandom->nextRangeU(2, 10); bool stitchTiles = d->fRandom->nextBool(); SkScalar seed = SkIntToScalar(d->fRandom->nextU()); @@ -611,14 +608,12 @@ GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, stitchTiles ? &tileSize : nullptr); - SkPaint paint; - GrColor paintColor; GrFragmentProcessor* effect; GrPaint grPaint; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, grPaint.getProcessorDataManager(), - &effect)); + return shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, + kNone_SkFilterQuality, + grPaint.getProcessorDataManager()); delete shader; @@ -639,10 +634,6 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) { kVec2f_GrSLType, kDefault_GrSLPrecision, "baseFrequency"); const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyUni); - fAlphaUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility, - kFloat_GrSLType, kDefault_GrSLPrecision, - "alpha"); - const char* alphaUni = args.fBuilder->getUniformCStr(fAlphaUni); const char* stitchDataUni = nullptr; if (fStitchTiles) { @@ -875,8 +866,6 @@ void GrGLPerlinNoise::emitCode(EmitArgs& args) { args.fOutputColor,args.fOutputColor); } - fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", args.fOutputColor, alphaUni); - // Clamp values fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args.fOutputColor); @@ -920,7 +909,6 @@ void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrPro const SkVector& baseFrequency = turbulence.baseFrequency(); pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); - pdman.set1f(fAlphaUni, SkIntToScalar(turbulence.alpha()) / 255); if (turbulence.stitchTiles()) { const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchData(); @@ -930,17 +918,11 @@ void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrPro } ///////////////////////////////////////////////////////////////////// - -bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, - const SkMatrix* externalLocalMatrix, - GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, + const SkMatrix& viewM, const SkMatrix* externalLocalMatrix, SkFilterQuality, + GrProcessorDataManager* procDataManager) const { SkASSERT(context); - *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); - SkMatrix localMatrix = this->getLocalMatrix(); if (externalLocalMatrix) { localMatrix.preConcat(*externalLocalMatrix); @@ -951,13 +933,14 @@ bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint& if (0 == fNumOctaves) { if (kFractalNoise_Type == fType) { - uint32_t alpha = paint.getAlpha() >> 1; - uint32_t rgb = alpha >> 1; - *paintColor = GrColorPackRGBA(rgb, rgb, rgb, alpha); - } else { - *paintColor = 0; + // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) + SkAutoTUnref<const GrFragmentProcessor> inner( + GrConstColorProcessor::Create(0x80404040, + GrConstColorProcessor::kModulateRGBA_InputMode)); + return GrExtractAlphaFragmentProcessor::Create(inner); } - return true; + // Emit zero. + return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore_InputMode); } // Either we don't stitch tiles, either we have a valid tile size @@ -974,27 +957,18 @@ bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint& m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); if ((permutationsTexture) && (noiseTexture)) { - *fp = GrPerlinNoiseEffect::Create(procDataManager, - fType, - fNumOctaves, - fStitchTiles, - paintingData, - permutationsTexture, noiseTexture, - m, paint.getAlpha()); - } else { - delete paintingData; - *fp = nullptr; - } - return true; -} - -#else - -bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + SkAutoTUnref<GrFragmentProcessor> inner( + GrPerlinNoiseEffect::Create(procDataManager, + fType, + fNumOctaves, + fStitchTiles, + paintingData, + permutationsTexture, noiseTexture, + m)); + return GrExtractAlphaFragmentProcessor::Create(inner); + } + delete paintingData; + return nullptr; } #endif diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index f0245b7cfa..1a2b1343b6 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -541,7 +541,7 @@ void ColorTableEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const GR_DEFINE_FRAGMENT_PROCESSOR_TEST(ColorTableEffect); -GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d) { int flags = 0; uint8_t luts[256][4]; do { diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp index 86142fda73..df27ebcb17 100644 --- a/src/effects/gradients/SkLinearGradient.cpp +++ b/src/effects/gradients/SkLinearGradient.cpp @@ -439,6 +439,7 @@ void SkLinearGradient::LinearGradientContext::shadeSpan16(int x, int y, #if SK_SUPPORT_GPU +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" #include "SkGr.h" @@ -507,7 +508,7 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrLinearGradient); -GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d) { SkPoint points[] = {{d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}, {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}}; @@ -519,12 +520,9 @@ GrFragmentProcessor* GrLinearGradient::TestCreate(GrProcessorTestData* d) { SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points, colors, stops, colorCount, tm)); - SkPaint paint; - GrColor paintColor; - GrFragmentProcessor* fp; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } @@ -541,40 +539,29 @@ void GrGLLinearGradient::emitCode(EmitArgs& args) { ///////////////////////////////////////////////////////////////////// -bool SkLinearGradient::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewm, const SkMatrix* localMatrix, - GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkLinearGradient::asFragmentProcessor( + GrContext* context, const SkMatrix& viewm, const SkMatrix* localMatrix, SkFilterQuality, + GrProcessorDataManager* procDataManager) const { SkASSERT(context); SkMatrix matrix; if (!this->getLocalMatrix().invert(&matrix)) { - return false; + return nullptr; } if (localMatrix) { SkMatrix inv; if (!localMatrix->invert(&inv)) { - return false; + return nullptr; } matrix.postConcat(inv); } matrix.postConcat(fPtsToUnit); - *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); - *fp = GrLinearGradient::Create(context, procDataManager, *this, matrix, fTileMode); - - return true; + SkAutoTUnref<const GrFragmentProcessor> inner( + GrLinearGradient::Create(context, procDataManager, *this, matrix, fTileMode)); + return GrExtractAlphaFragmentProcessor::Create(inner); } -#else - -bool SkLinearGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; -} #endif diff --git a/src/effects/gradients/SkLinearGradient.h b/src/effects/gradients/SkLinearGradient.h index eddb35512f..a1ae39fb44 100644 --- a/src/effects/gradients/SkLinearGradient.h +++ b/src/effects/gradients/SkLinearGradient.h @@ -29,9 +29,10 @@ 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(SkLinearGradient) diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp index c7e7308251..9cd198cf37 100644 --- a/src/effects/gradients/SkRadialGradient.cpp +++ b/src/effects/gradients/SkRadialGradient.cpp @@ -415,6 +415,7 @@ void SkRadialGradient::RadialGradientContext::shadeSpan(int x, int y, #if SK_SUPPORT_GPU #include "SkGr.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" class GrGLRadialGradient : public GrGLGradientEffect { @@ -479,7 +480,7 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrRadialGradient); -GrFragmentProcessor* GrRadialGradient::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrRadialGradient::TestCreate(GrProcessorTestData* d) { SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkScalar radius = d->fRandom->nextUScalar1(); @@ -491,12 +492,9 @@ GrFragmentProcessor* GrRadialGradient::TestCreate(GrProcessorTestData* d) { SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius, colors, stops, colorCount, tm)); - SkPaint paint; - GrColor paintColor; - GrFragmentProcessor* fp; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } @@ -514,39 +512,26 @@ void GrGLRadialGradient::emitCode(EmitArgs& args) { ///////////////////////////////////////////////////////////////////// -bool SkRadialGradient::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkRadialGradient::asFragmentProcessor(GrContext* context, + const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality, + GrProcessorDataManager* procDataManager) const { SkASSERT(context); SkMatrix matrix; if (!this->getLocalMatrix().invert(&matrix)) { - return false; + return nullptr; } if (localMatrix) { SkMatrix inv; if (!localMatrix->invert(&inv)) { - return false; + return nullptr; } matrix.postConcat(inv); } matrix.postConcat(fPtsToUnit); - - *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); - *fp = GrRadialGradient::Create(context, procDataManager, *this, matrix, fTileMode); - - return true; -} - -#else - -bool SkRadialGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + SkAutoTUnref<const GrFragmentProcessor> inner( + GrRadialGradient::Create(context, procDataManager, *this, matrix, fTileMode)); + return GrExtractAlphaFragmentProcessor::Create(inner); } #endif diff --git a/src/effects/gradients/SkRadialGradient.h b/src/effects/gradients/SkRadialGradient.h index d0f63ac54d..bc79d92660 100644 --- a/src/effects/gradients/SkRadialGradient.h +++ b/src/effects/gradients/SkRadialGradient.h @@ -29,9 +29,10 @@ 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(SkRadialGradient) diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index c6699e87e0..ae88c8a311 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -167,6 +167,7 @@ void SkSweepGradient::SweepGradientContext::shadeSpan16(int x, int y, uint16_t* #if SK_SUPPORT_GPU #include "SkGr.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" class GrGLSweepGradient : public GrGLGradientEffect { @@ -226,7 +227,7 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSweepGradient); -GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) { SkPoint center = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkColor colors[kMaxRandomGradientColors]; @@ -236,12 +237,11 @@ GrFragmentProcessor* GrSweepGradient::TestCreate(GrProcessorTestData* d) { int colorCount = RandomGradientParams(d->fRandom, colors, &stops, &tmIgnored); SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY, colors, stops, colorCount)); - SkPaint paint; - GrFragmentProcessor* fp; - GrColor paintColor; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), + NULL, kNone_SkFilterQuality, + d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } @@ -270,38 +270,26 @@ void GrGLSweepGradient::emitCode(EmitArgs& args) { ///////////////////////////////////////////////////////////////////// -bool SkSweepGradient::asFragmentProcessor(GrContext* context, const SkPaint& paint, - const SkMatrix& viewM, - const SkMatrix* localMatrix, GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** effect) const { +const GrFragmentProcessor* SkSweepGradient::asFragmentProcessor(GrContext* context, + const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality, + GrProcessorDataManager* procDataManager) const { SkMatrix matrix; if (!this->getLocalMatrix().invert(&matrix)) { - return false; + return nullptr; } if (localMatrix) { SkMatrix inv; if (!localMatrix->invert(&inv)) { - return false; + return nullptr; } matrix.postConcat(inv); } matrix.postConcat(fPtsToUnit); - *effect = GrSweepGradient::Create(context, procDataManager, *this, matrix); - *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); - - return true; -} - -#else - -bool SkSweepGradient::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, - const SkMatrix*, GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + SkAutoTUnref<const GrFragmentProcessor> inner( + GrSweepGradient::Create(context, procDataManager, *this, matrix)); + return GrExtractAlphaFragmentProcessor::Create(inner); } #endif diff --git a/src/effects/gradients/SkSweepGradient.h b/src/effects/gradients/SkSweepGradient.h index bc465bdc44..8094a48c79 100644 --- a/src/effects/gradients/SkSweepGradient.h +++ b/src/effects/gradients/SkSweepGradient.h @@ -30,9 +30,10 @@ 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(SkSweepGradient) diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp index 41b5c1bbae..d1fa7b005d 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp @@ -359,31 +359,17 @@ void SkTwoPointConicalGradient::flatten(SkWriteBuffer& buffer) const { #if SK_SUPPORT_GPU #include "SkGr.h" +#include "effects/GrExtractAlphaFragmentProcessor.h" -bool SkTwoPointConicalGradient::asFragmentProcessor(GrContext* context, - const SkPaint& paint, - const SkMatrix& viewM, - const SkMatrix* localMatrix, - GrColor* paintColor, - GrProcessorDataManager* procDataManager, - GrFragmentProcessor** fp) const { +const GrFragmentProcessor* SkTwoPointConicalGradient::asFragmentProcessor(GrContext* context, + const SkMatrix& viewM, const SkMatrix* localMatrix, SkFilterQuality, + GrProcessorDataManager* procDataManager) const { SkASSERT(context); SkASSERT(fPtsToUnit.isIdentity()); - - *fp = Gr2PtConicalGradientEffect::Create(context, procDataManager, *this, fTileMode, - localMatrix); - *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); - return true; -} - -#else - -bool SkTwoPointConicalGradient::asFragmentProcessor(GrContext*, const SkPaint&, - const SkMatrix&, const SkMatrix*, - GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const { - SkDEBUGFAIL("Should not call in GPU-less build"); - return false; + SkAutoTUnref<const GrFragmentProcessor> inner( + Gr2PtConicalGradientEffect::Create(context, procDataManager, *this, fTileMode, + localMatrix)); + return GrExtractAlphaFragmentProcessor::Create(inner); } #endif diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h index 8bba9e1b7f..17ed32b018 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.h +++ b/src/effects/gradients/SkTwoPointConicalGradient.h @@ -59,9 +59,10 @@ public: }; SkShader::GradientType asAGradient(GradientInfo* info) const override; - bool asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, const SkMatrix*, - GrColor*, GrProcessorDataManager*, - GrFragmentProcessor**) const override; +#if SK_SUPPORT_GPU + const GrFragmentProcessor* asFragmentProcessor(GrContext*, const SkMatrix&, const SkMatrix*, + SkFilterQuality, GrProcessorDataManager*) const override; +#endif bool isOpaque() const override; SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); } diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp index 30f0fdf6a1..c88e75692c 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp @@ -183,7 +183,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(Edge2PtConicalEffect); /* * All Two point conical gradient test create functions may occasionally create edge case shaders */ -GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData* d) { SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkScalar radius1 = d->fRandom->nextUScalar1(); SkPoint center2; @@ -209,12 +209,9 @@ GrFragmentProcessor* Edge2PtConicalEffect::TestCreate(GrProcessorTestData* d) { center2, radius2, colors, stops, colorCount, tm)); - SkPaint paint; - GrFragmentProcessor* fp; - GrColor paintColor; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } @@ -465,7 +462,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalOutside2PtConicalEffect); /* * All Two point conical gradient test create functions may occasionally create edge case shaders */ -GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkScalar radius1 = 0.f; SkPoint center2; @@ -488,15 +485,10 @@ GrFragmentProcessor* FocalOutside2PtConicalEffect::TestCreate(GrProcessorTestDat center2, radius2, colors, stops, colorCount, tm)); - SkPaint paint; - GrFragmentProcessor* effect; - GrColor paintColor; - GrPaint grPaint; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, - &effect)); - return effect; + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDataManager); + GrAlwaysAssert(fp); + return fp; } GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrProcessor& processor) @@ -676,7 +668,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(FocalInside2PtConicalEffect); /* * All Two point conical gradient test create functions may occasionally create edge case shaders */ -GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkScalar radius1 = 0.f; SkPoint center2; @@ -701,12 +693,9 @@ GrFragmentProcessor* FocalInside2PtConicalEffect::TestCreate(GrProcessorTestData center2, radius2, colors, stops, colorCount, tm)); - SkPaint paint; - GrColor paintColor; - GrFragmentProcessor* fp; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } @@ -923,8 +912,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleInside2PtConicalEffect); /* * All Two point conical gradient test create functions may occasionally create edge case shaders */ -GrFragmentProcessor* -CircleInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* CircleInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkScalar radius1 = d->fRandom->nextUScalar1() + 0.0001f; // make sure radius1 != 0 SkPoint center2; @@ -948,12 +936,9 @@ CircleInside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { center2, radius2, colors, stops, colorCount, tm)); - SkPaint paint; - GrColor paintColor; - GrFragmentProcessor* fp; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor(d->fContext, + GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } @@ -1154,7 +1139,7 @@ GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleOutside2PtConicalEffect); /* * All Two point conical gradient test create functions may occasionally create edge case shaders */ -GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessorTestData* d) { SkPoint center1 = {d->fRandom->nextUScalar1(), d->fRandom->nextUScalar1()}; SkScalar radius1 = d->fRandom->nextUScalar1() + 0.0001f; // make sure radius1 != 0 SkPoint center2; @@ -1179,12 +1164,10 @@ GrFragmentProcessor* CircleOutside2PtConicalEffect::TestCreate(GrProcessorTestDa center2, radius2, colors, stops, colorCount, tm)); - SkPaint paint; - GrColor paintColor; - GrFragmentProcessor* fp; - SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, - GrTest::TestMatrix(d->fRandom), nullptr, - &paintColor, d->fProcDataManager, &fp)); + const GrFragmentProcessor* fp = shader->asFragmentProcessor( + d->fContext,GrTest::TestMatrix(d->fRandom), NULL, kNone_SkFilterQuality, + d->fProcDataManager); + GrAlwaysAssert(fp); return fp; } diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp index 296f6daf84..6023f188df 100644 --- a/src/gpu/GrAAConvexPathRenderer.cpp +++ b/src/gpu/GrAAConvexPathRenderer.cpp @@ -668,7 +668,7 @@ private: GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); -GrGeometryProcessor* QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* QuadEdgeEffect::TestCreate(GrProcessorTestData* d) { // Doesn't work without derivative instructions. return d->fCaps->shaderCaps()->shaderDerivativeSupport() ? QuadEdgeEffect::Create(GrRandomColor(d->fRandom), diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp index 2017173e6b..cefc93336e 100644 --- a/src/gpu/GrDefaultGeoProcFactory.cpp +++ b/src/gpu/GrDefaultGeoProcFactory.cpp @@ -251,7 +251,7 @@ private: GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); -GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { uint32_t flags = 0; if (d->fRandom->nextBool()) { flags |= kColor_GPFlag; diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index e2a4e9a21a..34d3db8924 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -203,7 +203,7 @@ private: GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleEdgeEffect); -GrGeometryProcessor* CircleEdgeEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* CircleEdgeEffect::TestCreate(GrProcessorTestData* d) { return CircleEdgeEffect::Create(GrRandomColor(d->fRandom), d->fRandom->nextBool(), GrTest::TestMatrix(d->fRandom), @@ -382,7 +382,7 @@ private: GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseEdgeEffect); -GrGeometryProcessor* EllipseEdgeEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* EllipseEdgeEffect::TestCreate(GrProcessorTestData* d) { return EllipseEdgeEffect::Create(GrRandomColor(d->fRandom), d->fRandom->nextBool(), GrTest::TestMatrix(d->fRandom), @@ -583,7 +583,7 @@ private: GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseEdgeEffect); -GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(GrProcessorTestData* d) { return DIEllipseEdgeEffect::Create(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom), (Mode)(d->fRandom->nextRangeU(0,2)), diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 7a3335c305..4f6d8788b1 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -241,10 +241,6 @@ bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con return true; } -void GrFragmentProcessor::computeInvariantOutput(GrInvariantOutput* inout) const { - this->onComputeInvariantOutput(inout); -} - /////////////////////////////////////////////////////////////////////////////////////////////////// // Initial static variable from GrXPFactory diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index ca78ff14e1..4293194de3 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -851,22 +851,13 @@ bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPa GrColor paintColor = SkColor2GrColor(skPaint.getColor()); - // Start a new block here in order to preserve our context state after calling - // asFragmentProcessor(). Since these calls get passed back to the client, we don't really - // want them messing around with the context. - { - // Allow the shader to modify paintColor and also create an effect to be installed as - // the first color effect on the GrPaint. - GrFragmentProcessor* fp = nullptr; - if (!shader->asFragmentProcessor(context, skPaint, viewM, nullptr, &paintColor, - grPaint->getProcessorDataManager(), &fp)) { - return false; - } - if (fp) { - grPaint->addColorFragmentProcessor(fp)->unref(); - constantColor = false; - } + const GrFragmentProcessor* fp = shader->asFragmentProcessor(context, viewM, NULL, + skPaint.getFilterQuality(), grPaint->getProcessorDataManager()); + if (!fp) { + return false; } + grPaint->addColorFragmentProcessor(fp)->unref(); + constantColor = false; // The grcolor is automatically set when calling asFragmentProcessor. // If the shader can be seen as an effect it returns true and adds its effect to the grpaint. diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp index 92cf9a2594..5872992aac 100644 --- a/src/gpu/effects/GrBezierEffect.cpp +++ b/src/gpu/effects/GrBezierEffect.cpp @@ -217,7 +217,7 @@ GrConicEffect::GrConicEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrConicEffect); -GrGeometryProcessor* GrConicEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrConicEffect::TestCreate(GrProcessorTestData* d) { GrGeometryProcessor* gp; do { GrPrimitiveEdgeType edgeType = @@ -425,7 +425,7 @@ GrQuadEffect::GrQuadEffect(GrColor color, const SkMatrix& viewMatrix, uint8_t co GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrQuadEffect); -GrGeometryProcessor* GrQuadEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrQuadEffect::TestCreate(GrProcessorTestData* d) { GrGeometryProcessor* gp; do { GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( @@ -645,7 +645,7 @@ GrCubicEffect::GrCubicEffect(GrColor color, const SkMatrix& viewMatrix, GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrCubicEffect); -GrGeometryProcessor* GrCubicEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrCubicEffect::TestCreate(GrProcessorTestData* d) { GrGeometryProcessor* gp; do { GrPrimitiveEdgeType edgeType = diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp index ad9be6bdc7..d8a9726030 100644 --- a/src/gpu/effects/GrBicubicEffect.cpp +++ b/src/gpu/effects/GrBicubicEffect.cpp @@ -175,7 +175,7 @@ void GrBicubicEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrBicubicEffect); -GrFragmentProcessor* GrBicubicEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrBicubicEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; SkScalar coefficients[16]; diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index 85d08629ac..69c2029edb 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -159,7 +159,7 @@ GrBitmapTextGeoProc::createGLInstance(const GrBatchTracker& bt, GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrBitmapTextGeoProc); -GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrBitmapTextGeoProc::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; static const SkShader::TileMode kTileModes[] = { diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp index 838dc1ccea..3f68268b20 100644 --- a/src/gpu/effects/GrConfigConversionEffect.cpp +++ b/src/gpu/effects/GrConfigConversionEffect.cpp @@ -128,7 +128,7 @@ void GrConfigConversionEffect::onComputeInvariantOutput(GrInvariantOutput* inout GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); -GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrConfigConversionEffect::TestCreate(GrProcessorTestData* d) { PMConversion pmConv = static_cast<PMConversion>(d->fRandom->nextULessThan(kPMConversionCnt)); bool swapRB; if (kNone_PMConversion == pmConv) { diff --git a/src/gpu/effects/GrConstColorProcessor.cpp b/src/gpu/effects/GrConstColorProcessor.cpp index 131d91c874..95a4081d4f 100644 --- a/src/gpu/effects/GrConstColorProcessor.cpp +++ b/src/gpu/effects/GrConstColorProcessor.cpp @@ -103,7 +103,7 @@ bool GrConstColorProcessor::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConstColorProcessor); -GrFragmentProcessor* GrConstColorProcessor::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrConstColorProcessor::TestCreate(GrProcessorTestData* d) { GrColor color; int colorPicker = d->fRandom->nextULessThan(3); switch (colorPicker) { diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp index 2504fd4ccc..d1495a3276 100644 --- a/src/gpu/effects/GrConvexPolyEffect.cpp +++ b/src/gpu/effects/GrConvexPolyEffect.cpp @@ -60,7 +60,7 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AARectEffect); -GrFragmentProcessor* AARectEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* AARectEffect::TestCreate(GrProcessorTestData* d) { SkRect rect = SkRect::MakeLTRB(d->fRandom->nextSScalar1(), d->fRandom->nextSScalar1(), d->fRandom->nextSScalar1(), @@ -339,7 +339,7 @@ bool GrConvexPolyEffect::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvexPolyEffect); -GrFragmentProcessor* GrConvexPolyEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrConvexPolyEffect::TestCreate(GrProcessorTestData* d) { int count = d->fRandom->nextULessThan(kMaxEdges) + 1; SkScalar edges[kMaxEdges * 3]; for (int i = 0; i < 3 * count; ++i) { diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index f70b664505..5fd62b8cdf 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -217,7 +217,7 @@ bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConvolutionEffect); -GrFragmentProcessor* GrConvolutionEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrConvolutionEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; Direction dir = d->fRandom->nextBool() ? kX_Direction : kY_Direction; diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp index 8c45d22727..89d7565894 100644 --- a/src/gpu/effects/GrCoverageSetOpXP.cpp +++ b/src/gpu/effects/GrCoverageSetOpXP.cpp @@ -245,7 +245,7 @@ void GrCoverageSetOpXPFactory::getInvariantBlendedColor(const GrProcOptInfo& col GR_DEFINE_XP_FACTORY_TEST(GrCoverageSetOpXPFactory); -GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) { +const GrXPFactory* GrCoverageSetOpXPFactory::TestCreate(GrProcessorTestData* d) { SkRegion::Op regionOp = SkRegion::Op(d->fRandom->nextULessThan(SkRegion::kLastOp + 1)); bool invertCoverage = d->fRandom->nextBool(); return GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage); diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index 58591e5810..f626e7a211 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -506,7 +506,7 @@ void GrCustomXferFP::onComputeInvariantOutput(GrInvariantOutput* inout) const { } GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCustomXferFP); -GrFragmentProcessor* GrCustomXferFP::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrCustomXferFP::TestCreate(GrProcessorTestData* d) { int mode = d->fRandom->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLastSeparableMode); return new GrCustomXferFP(d->fProcDataManager, static_cast<SkXfermode::Mode>(mode), @@ -805,7 +805,7 @@ void GrCustomXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, } GR_DEFINE_XP_FACTORY_TEST(GrCustomXPFactory); -GrXPFactory* GrCustomXPFactory::TestCreate(GrProcessorTestData* d) { +const GrXPFactory* GrCustomXPFactory::TestCreate(GrProcessorTestData* d) { int mode = d->fRandom->nextRangeU(SkXfermode::kLastCoeffMode + 1, SkXfermode::kLastSeparableMode); diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index ed6473796d..5420dbd167 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -960,7 +960,7 @@ DashingCircleEffect::DashingCircleEffect(GrColor color, GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); -GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* DashingCircleEffect::TestCreate(GrProcessorTestData* d) { DashAAMode aaMode = static_cast<DashAAMode>(d->fRandom->nextULessThan(kDashAAModeCount)); return DashingCircleEffect::Create(GrRandomColor(d->fRandom), aaMode, GrTest::TestMatrix(d->fRandom), @@ -1195,7 +1195,7 @@ DashingLineEffect::DashingLineEffect(GrColor color, GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); -GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* DashingLineEffect::TestCreate(GrProcessorTestData* d) { DashAAMode aaMode = static_cast<DashAAMode>(d->fRandom->nextULessThan(kDashAAModeCount)); return DashingLineEffect::Create(GrRandomColor(d->fRandom), aaMode, GrTest::TestMatrix(d->fRandom), diff --git a/src/gpu/effects/GrDisableColorXP.cpp b/src/gpu/effects/GrDisableColorXP.cpp index caccf10e77..3e1024b162 100644 --- a/src/gpu/effects/GrDisableColorXP.cpp +++ b/src/gpu/effects/GrDisableColorXP.cpp @@ -104,7 +104,7 @@ GrDisableColorXPFactory::onCreateXferProcessor(const GrCaps& caps, GR_DEFINE_XP_FACTORY_TEST(GrDisableColorXPFactory); -GrXPFactory* GrDisableColorXPFactory::TestCreate(GrProcessorTestData*) { +const GrXPFactory* GrDisableColorXPFactory::TestCreate(GrProcessorTestData*) { return GrDisableColorXPFactory::Create(); } diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index d0c1a3fcd8..f29bab5de2 100644 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -252,7 +252,7 @@ GrDistanceFieldA8TextGeoProc::createGLInstance(const GrBatchTracker& bt, GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldA8TextGeoProc); -GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrDistanceFieldA8TextGeoProc::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; static const SkShader::TileMode kTileModes[] = { @@ -475,7 +475,7 @@ GrDistanceFieldPathGeoProc::createGLInstance(const GrBatchTracker& bt, const GrG GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc); -GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrDistanceFieldPathGeoProc::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; static const SkShader::TileMode kTileModes[] = { @@ -748,7 +748,7 @@ GrDistanceFieldLCDTextGeoProc::createGLInstance(const GrBatchTracker& bt, GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc); -GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessorTestData* d) { +const GrGeometryProcessor* GrDistanceFieldLCDTextGeoProc::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; static const SkShader::TileMode kTileModes[] = { diff --git a/src/gpu/effects/GrDitherEffect.cpp b/src/gpu/effects/GrDitherEffect.cpp index 19b2994b5e..3cff899ac5 100644 --- a/src/gpu/effects/GrDitherEffect.cpp +++ b/src/gpu/effects/GrDitherEffect.cpp @@ -53,7 +53,7 @@ void DitherEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(DitherEffect); -GrFragmentProcessor* DitherEffect::TestCreate(GrProcessorTestData*) { +const GrFragmentProcessor* DitherEffect::TestCreate(GrProcessorTestData*) { return DitherEffect::Create(); } diff --git a/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp b/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp new file mode 100644 index 0000000000..3414df2b13 --- /dev/null +++ b/src/gpu/effects/GrExtractAlphaFragmentProcessor.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "effects/GrExtractAlphaFragmentProcessor.h" +#include "gl/GrGLFragmentProcessor.h" +#include "gl/builders/GrGLProgramBuilder.h" + +class GLExtractAlphaFragmentProcessor : public GrGLFragmentProcessor { +public: + GLExtractAlphaFragmentProcessor() {} + + void emitCode(EmitArgs& args) override { + GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); + fsBuilder->codeAppendf("vec4 alpha4 = %s.aaaa;", args.fInputColor); + SkString output; + this->emitChild(0, "alpha4", &output, args); + fsBuilder->codeAppendf("%s = %s;", args.fOutputColor, output.c_str()); + } + +private: + typedef GrGLFragmentProcessor INHERITED; +}; + +GrGLFragmentProcessor* GrExtractAlphaFragmentProcessor::onCreateGLInstance() const { + return SkNEW(GLExtractAlphaFragmentProcessor); +} + +void GrExtractAlphaFragmentProcessor::onGetGLProcessorKey(const GrGLSLCaps&, + GrProcessorKeyBuilder*) const { +} + +bool GrExtractAlphaFragmentProcessor::onIsEqual(const GrFragmentProcessor&) const { return true; } + +void GrExtractAlphaFragmentProcessor::onComputeInvariantOutput(GrInvariantOutput* inout) const { + if (inout->validFlags() & kA_GrColorComponentFlag) { + GrColor color = GrColorPackA4(GrColorUnpackA(inout->color())); + inout->setToOther(kRGBA_GrColorComponentFlags, color, + GrInvariantOutput::kWill_ReadInput); + } else { + inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); + } + this->childProcessor(0).computeInvariantOutput(inout); +} diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp index c5a7fb7836..76fa6420ab 100644 --- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp +++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp @@ -222,7 +222,7 @@ GrMatrixConvolutionEffect::CreateGaussian(GrProcessorDataManager* procDataManage GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMatrixConvolutionEffect); -GrFragmentProcessor* GrMatrixConvolutionEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrMatrixConvolutionEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; int width = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE); diff --git a/src/gpu/effects/GrOvalEffect.cpp b/src/gpu/effects/GrOvalEffect.cpp index 0f3df7d66c..42b71ade9e 100644 --- a/src/gpu/effects/GrOvalEffect.cpp +++ b/src/gpu/effects/GrOvalEffect.cpp @@ -75,7 +75,7 @@ bool CircleEffect::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircleEffect); -GrFragmentProcessor* CircleEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* CircleEffect::TestCreate(GrProcessorTestData* d) { SkPoint center; center.fX = d->fRandom->nextRangeScalar(0.f, 1000.f); center.fY = d->fRandom->nextRangeScalar(0.f, 1000.f); @@ -245,7 +245,7 @@ bool EllipseEffect::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(EllipseEffect); -GrFragmentProcessor* EllipseEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* EllipseEffect::TestCreate(GrProcessorTestData* d) { SkPoint center; center.fX = d->fRandom->nextRangeScalar(0.f, 1000.f); center.fY = d->fRandom->nextRangeScalar(0.f, 1000.f); diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index 4c9af42cde..5f34f75854 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -755,7 +755,7 @@ bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps, GR_DEFINE_XP_FACTORY_TEST(GrPorterDuffXPFactory); -GrXPFactory* GrPorterDuffXPFactory::TestCreate(GrProcessorTestData* d) { +const GrXPFactory* GrPorterDuffXPFactory::TestCreate(GrProcessorTestData* d) { SkXfermode::Mode mode = SkXfermode::Mode(d->fRandom->nextULessThan(SkXfermode::kLastCoeffMode)); return GrPorterDuffXPFactory::Create(mode); } diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp index af0f1fc8fd..b5b95679f5 100644 --- a/src/gpu/effects/GrRRectEffect.cpp +++ b/src/gpu/effects/GrRRectEffect.cpp @@ -107,7 +107,7 @@ bool CircularRRectEffect::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(CircularRRectEffect); -GrFragmentProcessor* CircularRRectEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* CircularRRectEffect::TestCreate(GrProcessorTestData* d) { SkScalar w = d->fRandom->nextRangeScalar(20.f, 1000.f); SkScalar h = d->fRandom->nextRangeScalar(20.f, 1000.f); SkScalar r = d->fRandom->nextRangeF(kRadiusMin, 9.f); @@ -432,7 +432,7 @@ bool EllipticalRRectEffect::onIsEqual(const GrFragmentProcessor& other) const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(EllipticalRRectEffect); -GrFragmentProcessor* EllipticalRRectEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* EllipticalRRectEffect::TestCreate(GrProcessorTestData* d) { SkScalar w = d->fRandom->nextRangeScalar(20.f, 1000.f); SkScalar h = d->fRandom->nextRangeScalar(20.f, 1000.f); SkVector r[4]; diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp index fb7c3a7b23..68e501c5aa 100644 --- a/src/gpu/effects/GrSimpleTextureEffect.cpp +++ b/src/gpu/effects/GrSimpleTextureEffect.cpp @@ -50,7 +50,7 @@ GrGLFragmentProcessor* GrSimpleTextureEffect::onCreateGLInstance() const { GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect); -GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrSimpleTextureEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; static const SkShader::TileMode kTileModes[] = { diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index c1f9ef03a9..93a548a047 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -280,7 +280,7 @@ void GrTextureDomainEffect::onComputeInvariantOutput(GrInvariantOutput* inout) c GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrTextureDomainEffect); -GrFragmentProcessor* GrTextureDomainEffect::TestCreate(GrProcessorTestData* d) { +const GrFragmentProcessor* GrTextureDomainEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; SkRect domain; diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index ffddd1fe6f..cd5bb9fc7c 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -90,7 +90,7 @@ private: GR_DEFINE_FRAGMENT_PROCESSOR_TEST(BigKeyProcessor); -GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { +const GrFragmentProcessor* BigKeyProcessor::TestCreate(GrProcessorTestData*) { return BigKeyProcessor::Create(); } |