| Index: src/gpu/effects/GrConvolutionEffect.cpp
|
| diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
|
| index adb62ae8aef072a5c46e8668bd929014f5d0862c..f3bd028c2cf0b78af335893a0407521ea30f9eba 100644
|
| --- a/src/gpu/effects/GrConvolutionEffect.cpp
|
| +++ b/src/gpu/effects/GrConvolutionEffect.cpp
|
| @@ -16,8 +16,6 @@ typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
|
|
|
| class GrGLConvolutionEffect : public GrGLSLFragmentProcessor {
|
| public:
|
| - GrGLConvolutionEffect(const GrProcessor&);
|
| -
|
| void emitCode(EmitArgs&) override;
|
|
|
| static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*);
|
| @@ -26,13 +24,6 @@ protected:
|
| void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&) override;
|
|
|
| private:
|
| - int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); }
|
| - bool useBounds() const { return fUseBounds; }
|
| - Gr1DKernelEffect::Direction direction() const { return fDirection; }
|
| -
|
| - int fRadius;
|
| - bool fUseBounds;
|
| - Gr1DKernelEffect::Direction fDirection;
|
| UniformHandle fKernelUni;
|
| UniformHandle fImageIncrementUni;
|
| UniformHandle fBoundsUni;
|
| @@ -40,37 +31,34 @@ private:
|
| typedef GrGLSLFragmentProcessor INHERITED;
|
| };
|
|
|
| -GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) {
|
| - const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>();
|
| - fRadius = c.radius();
|
| - fUseBounds = c.useBounds();
|
| - fDirection = c.direction();
|
| -}
|
| -
|
| void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
|
| + const GrConvolutionEffect& ce = args.fFp.cast<GrConvolutionEffect>();
|
| +
|
| GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
|
| fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
|
| kVec2f_GrSLType, kDefault_GrSLPrecision,
|
| "ImageIncrement");
|
| - if (this->useBounds()) {
|
| + if (ce.useBounds()) {
|
| fBoundsUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
|
| kVec2f_GrSLType, kDefault_GrSLPrecision,
|
| "Bounds");
|
| }
|
| +
|
| + int width = Gr1DKernelEffect::WidthFromRadius(ce.radius());
|
| +
|
| fKernelUni = uniformHandler->addUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
|
| kFloat_GrSLType, kDefault_GrSLPrecision,
|
| - "Kernel", this->width());
|
| + "Kernel", width);
|
|
|
| GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
|
| SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
|
|
|
| - fragBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor);
|
| + fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 0);", args.fOutputColor);
|
|
|
| - int width = this->width();
|
| const GrGLSLShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUni);
|
| const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
|
|
|
| - fragBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(), fRadius, imgInc);
|
| + fragBuilder->codeAppendf("vec2 coord = %s - %d.0 * %s;", coords2D.c_str(), ce.radius(), imgInc);
|
|
|
| // Manually unroll loop because some drivers don't; yields 20-30% speedup.
|
| for (int i = 0; i < width; i++) {
|
| @@ -79,19 +67,19 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
|
| index.appendS32(i);
|
| kernel.appendArrayAccess(index.c_str(), &kernelIndex);
|
|
|
| - if (this->useBounds()) {
|
| + if (ce.useBounds()) {
|
| // We used to compute a bool indicating whether we're in bounds or not, cast it to a
|
| // float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
|
| // to have a bug that caused corruption.
|
| const char* bounds = uniformHandler->getUniformCStr(fBoundsUni);
|
| - const char* component = this->direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x";
|
| + const char* component = ce.direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x";
|
| fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
|
| component, bounds, component, bounds);
|
| }
|
| fragBuilder->codeAppendf("\t\t%s += ", args.fOutputColor);
|
| fragBuilder->appendTextureLookup(args.fSamplers[0], "coord");
|
| fragBuilder->codeAppendf(" * %s;\n", kernelIndex.c_str());
|
| - if (this->useBounds()) {
|
| + if (ce.useBounds()) {
|
| fragBuilder->codeAppend("}");
|
| }
|
| fragBuilder->codeAppendf("\t\tcoord += %s;\n", imgInc);
|
| @@ -106,8 +94,7 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
|
| const GrProcessor& processor) {
|
| const GrConvolutionEffect& conv = processor.cast<GrConvolutionEffect>();
|
| GrTexture& texture = *conv.texture(0);
|
| - // the code we generated was for a specific kernel radius
|
| - SkASSERT(conv.radius() == fRadius);
|
| +
|
| float imageIncrement[2] = { 0 };
|
| float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
|
| switch (conv.direction()) {
|
| @@ -130,7 +117,9 @@ void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
|
| pdman.set2f(fBoundsUni, bounds[0], bounds[1]);
|
| }
|
| }
|
| - pdman.set1fv(fKernelUni, this->width(), conv.kernel());
|
| + int width = Gr1DKernelEffect::WidthFromRadius(conv.radius());
|
| +
|
| + pdman.set1fv(fKernelUni, width, conv.kernel());
|
| }
|
|
|
| void GrGLConvolutionEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&,
|
| @@ -201,7 +190,7 @@ void GrConvolutionEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps,
|
| }
|
|
|
| GrGLSLFragmentProcessor* GrConvolutionEffect::onCreateGLSLInstance() const {
|
| - return new GrGLConvolutionEffect(*this);
|
| + return new GrGLConvolutionEffect;
|
| }
|
|
|
| bool GrConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
|
|
|