diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-24 13:18:06 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-07-24 13:18:06 +0000 |
commit | 58c856a54a75e703aa3c82a0cd4e1affd9bd8ffc (patch) | |
tree | 4cfc8e41169906cdda2422b5701e59bab83aae6c /src | |
parent | 7f1af501f206da48a7ff791af53432c9c1c89d08 (diff) |
Reverting r10251 (Implement crop rect for SkImageFilter) due to Chromium-side unit test failures
git-svn-id: http://skia.googlecode.com/svn/trunk@10304 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapProcState.cpp | 8 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 23 | ||||
-rw-r--r-- | src/effects/SkBlurImageFilter.cpp | 69 | ||||
-rwxr-xr-x | src/effects/SkColorFilterImageFilter.cpp | 27 | ||||
-rw-r--r-- | src/effects/SkGpuBlurUtils.cpp | 47 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 14 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.cpp | 35 | ||||
-rw-r--r-- | src/gpu/effects/GrConvolutionEffect.h | 23 |
8 files changed, 68 insertions, 178 deletions
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index ab3babaad7..37c5026797 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -94,13 +94,13 @@ static bool valid_for_filtering(unsigned dimension) { static bool effective_matrix_scale_sqrd(const SkMatrix& mat) { SkPoint v1, v2; - + v1.fX = mat.getScaleX(); v1.fY = mat.getSkewY(); - + v2.fX = mat.getSkewX(); v2.fY = mat.getScaleY(); - + return SkMaxScalar(v1.lengthSqd(), v2.lengthSqd()); } @@ -216,7 +216,7 @@ void SkBitmapProcState::possiblyScaleImage() { // want to reqeust mipmaps fFilterLevel = SkPaint::kMedium_FilterLevel; } - + SkASSERT(SkPaint::kMedium_FilterLevel == fFilterLevel); /** diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index ff060a1a52..ddd6449490 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -18,27 +18,22 @@ SK_DEFINE_INST_COUNT(SkImageFilter) -SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const SkIRect* cropRect) - : fInputCount(inputCount), - fInputs(new SkImageFilter*[inputCount]), - fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { +SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs) + : fInputCount(inputCount), fInputs(new SkImageFilter*[inputCount]) { for (int i = 0; i < inputCount; ++i) { fInputs[i] = inputs[i]; SkSafeRef(fInputs[i]); } } -SkImageFilter::SkImageFilter(SkImageFilter* input, const SkIRect* cropRect) - : fInputCount(1), - fInputs(new SkImageFilter*[1]), - fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { +SkImageFilter::SkImageFilter(SkImageFilter* input) + : fInputCount(1), fInputs(new SkImageFilter*[1]) { fInputs[0] = input; SkSafeRef(fInputs[0]); } -SkImageFilter::SkImageFilter(SkImageFilter* input1, SkImageFilter* input2, const SkIRect* cropRect) - : fInputCount(2), fInputs(new SkImageFilter*[2]), - fCropRect(cropRect ? *cropRect : SkIRect::MakeLargest()) { +SkImageFilter::SkImageFilter(SkImageFilter* input1, SkImageFilter* input2) + : fInputCount(2), fInputs(new SkImageFilter*[2]) { fInputs[0] = input1; fInputs[1] = input2; SkSafeRef(fInputs[0]); @@ -61,7 +56,6 @@ SkImageFilter::SkImageFilter(SkFlattenableReadBuffer& buffer) fInputs[i] = NULL; } } - buffer.readIRect(&fCropRect); } void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { @@ -73,7 +67,6 @@ void SkImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { buffer.writeFlattenable(input); } } - buffer.writeIRect(fCropRect); } bool SkImageFilter::filterImage(Proxy* proxy, const SkBitmap& src, @@ -144,10 +137,6 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* #endif } -bool SkImageFilter::applyCropRect(SkIRect* rect) const { - return rect->intersect(fCropRect); -} - bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) { *dst = src; diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp index f75d0c16d5..157a0c3335 100644 --- a/src/effects/SkBlurImageFilter.cpp +++ b/src/effects/SkBlurImageFilter.cpp @@ -21,11 +21,8 @@ SkBlurImageFilter::SkBlurImageFilter(SkFlattenableReadBuffer& buffer) fSigma.fHeight = buffer.readScalar(); } -SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, - SkScalar sigmaY, - SkImageFilter* input, - const SkIRect* cropRect) - : INHERITED(input, cropRect), fSigma(SkSize::Make(sigmaX, sigmaY)) { +SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, SkScalar sigmaY, SkImageFilter* input) + : INHERITED(input), fSigma(SkSize::Make(sigmaX, sigmaY)) { SkASSERT(sigmaX >= 0 && sigmaY >= 0); } @@ -36,13 +33,13 @@ void SkBlurImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { } static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize, - int leftOffset, int rightOffset, const SkIRect& bounds) + int leftOffset, int rightOffset) { - int width = bounds.width(), height = bounds.height(); + int width = src.width(), height = src.height(); int rightBorder = SkMin32(rightOffset + 1, width); for (int y = 0; y < height; ++y) { int sumA = 0, sumR = 0, sumG = 0, sumB = 0; - SkPMColor* p = src.getAddr32(bounds.fLeft, y + bounds.fTop); + SkPMColor* p = src.getAddr32(0, y); for (int i = 0; i < rightBorder; ++i) { sumA += SkGetPackedA32(*p); sumR += SkGetPackedR32(*p); @@ -51,7 +48,7 @@ static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize, p++; } - const SkColor* sptr = src.getAddr32(bounds.fLeft, bounds.fTop + y); + const SkColor* sptr = src.getAddr32(0, y); SkColor* dptr = dst->getAddr32(0, y); for (int x = 0; x < width; ++x) { *dptr = SkPackARGB32(sumA / kernelSize, @@ -79,15 +76,15 @@ static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize, } static void boxBlurY(const SkBitmap& src, SkBitmap* dst, int kernelSize, - int topOffset, int bottomOffset, const SkIRect& bounds) + int topOffset, int bottomOffset) { - int width = bounds.width(), height = bounds.height(); + int width = src.width(), height = src.height(); int bottomBorder = SkMin32(bottomOffset + 1, height); int srcStride = src.rowBytesAsPixels(); int dstStride = dst->rowBytesAsPixels(); for (int x = 0; x < width; ++x) { int sumA = 0, sumR = 0, sumG = 0, sumB = 0; - SkColor* p = src.getAddr32(bounds.fLeft + x, bounds.fTop); + SkColor* p = src.getAddr32(x, 0); for (int i = 0; i < bottomBorder; ++i) { sumA += SkGetPackedA32(*p); sumR += SkGetPackedR32(*p); @@ -96,7 +93,7 @@ static void boxBlurY(const SkBitmap& src, SkBitmap* dst, int kernelSize, p += srcStride; } - const SkColor* sptr = src.getAddr32(bounds.fLeft + x, bounds.fTop); + const SkColor* sptr = src.getAddr32(x, 0); SkColor* dptr = dst->getAddr32(x, 0); for (int y = 0; y < height; ++y) { *dptr = SkPackARGB32(sumA / kernelSize, @@ -156,14 +153,7 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy, return false; } - SkIRect srcBounds, dstBounds; - src.getBounds(&srcBounds); - if (!this->applyCropRect(&srcBounds)) { - return false; - } - - dst->setConfig(src.config(), srcBounds.width(), srcBounds.height()); - dst->getBounds(&dstBounds); + dst->setConfig(src.config(), src.width(), src.height()); dst->allocPixels(); int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; @@ -186,23 +176,21 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy, } if (kernelSizeX > 0 && kernelSizeY > 0) { - boxBlurX(src, &temp, kernelSizeX, lowOffsetX, highOffsetX, srcBounds); - boxBlurY(temp, dst, kernelSizeY, lowOffsetY, highOffsetY, dstBounds); - boxBlurX(*dst, &temp, kernelSizeX, highOffsetX, lowOffsetX, dstBounds); - boxBlurY(temp, dst, kernelSizeY, highOffsetY, lowOffsetY, dstBounds); - boxBlurX(*dst, &temp, kernelSizeX3, highOffsetX, highOffsetX, dstBounds); - boxBlurY(temp, dst, kernelSizeY3, highOffsetY, highOffsetY, dstBounds); + boxBlurX(src, &temp, kernelSizeX, lowOffsetX, highOffsetX); + boxBlurY(temp, dst, kernelSizeY, lowOffsetY, highOffsetY); + boxBlurX(*dst, &temp, kernelSizeX, highOffsetX, lowOffsetX); + boxBlurY(temp, dst, kernelSizeY, highOffsetY, lowOffsetY); + boxBlurX(*dst, &temp, kernelSizeX3, highOffsetX, highOffsetX); + boxBlurY(temp, dst, kernelSizeY3, highOffsetY, highOffsetY); } else if (kernelSizeX > 0) { - boxBlurX(src, dst, kernelSizeX, lowOffsetX, highOffsetX, srcBounds); - boxBlurX(*dst, &temp, kernelSizeX, highOffsetX, lowOffsetX, dstBounds); - boxBlurX(temp, dst, kernelSizeX3, highOffsetX, highOffsetX, dstBounds); + boxBlurX(src, dst, kernelSizeX, lowOffsetX, highOffsetX); + boxBlurX(*dst, &temp, kernelSizeX, highOffsetX, lowOffsetX); + boxBlurX(temp, dst, kernelSizeX3, highOffsetX, highOffsetX); } else if (kernelSizeY > 0) { - boxBlurY(src, dst, kernelSizeY, lowOffsetY, highOffsetY, srcBounds); - boxBlurY(*dst, &temp, kernelSizeY, highOffsetY, lowOffsetY, dstBounds); - boxBlurY(temp, dst, kernelSizeY3, highOffsetY, highOffsetY, dstBounds); + boxBlurY(src, dst, kernelSizeY, lowOffsetY, highOffsetY); + boxBlurY(*dst, &temp, kernelSizeY, highOffsetY, lowOffsetY); + boxBlurY(temp, dst, kernelSizeY3, highOffsetY, highOffsetY); } - offset->fX += srcBounds.fLeft; - offset->fY += srcBounds.fTop; return true; } @@ -214,17 +202,12 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitm return false; } GrTexture* source = input.getTexture(); - SkIRect rect; + SkRect rect; src.getBounds(&rect); - if (!this->applyCropRect(&rect)) { - return false; - } SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(), - source, false, SkRect::Make(rect), + source, false, rect, fSigma.width(), fSigma.height())); - offset->fX += rect.fLeft; - offset->fY += rect.fTop; - return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), result); + return SkImageFilterUtils::WrapTexture(tex, src.width(), src.height(), result); #else SkDEBUGFAIL("Should not call in GPU-less build"); return false; diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index a24934e0e2..1d3cfee1c3 100755 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -57,7 +57,7 @@ bool matrix_needs_clamping(SkScalar matrix[20]) { }; SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, - SkImageFilter* input, const SkIRect* cropRect) { + SkImageFilter* input) { SkASSERT(cf); SkScalar colorMatrix[20], inputMatrix[20]; SkColorFilter* inputColorFilter; @@ -69,15 +69,13 @@ SkColorFilterImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkScalar combinedMatrix[20]; mult_color_matrix(inputMatrix, colorMatrix, combinedMatrix); SkAutoTUnref<SkColorFilter> newCF(SkNEW_ARGS(SkColorMatrixFilter, (combinedMatrix))); - return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(0), cropRect)); + return SkNEW_ARGS(SkColorFilterImageFilter, (newCF, input->getInput(0))); } } - return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input, cropRect)); + return SkNEW_ARGS(SkColorFilterImageFilter, (cf, input)); } -SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, - SkImageFilter* input, const SkIRect* cropRect) - : INHERITED(input, cropRect), fColorFilter(cf) { +SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf, SkImageFilter* input) : INHERITED(input), fColorFilter(cf) { SkASSERT(cf); SkSafeRef(cf); } @@ -105,31 +103,22 @@ bool SkColorFilterImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& sourc return false; } - SkIRect bounds; - src.getBounds(&bounds); - if (!this->applyCropRect(&bounds)) { - return false; - } - - SkAutoTUnref<SkDevice> device(proxy->createDevice(bounds.width(), bounds.height())); + SkAutoTUnref<SkDevice> device(proxy->createDevice(src.width(), src.height())); SkCanvas canvas(device.get()); SkPaint paint; paint.setXfermodeMode(SkXfermode::kSrc_Mode); paint.setColorFilter(fColorFilter); - canvas.drawSprite(src, -bounds.fLeft, -bounds.fTop, &paint); + canvas.drawSprite(src, 0, 0, &paint); *result = device.get()->accessBitmap(false); - loc->fX += bounds.fLeft; - loc->fY += bounds.fTop; return true; } bool SkColorFilterImageFilter::asColorFilter(SkColorFilter** filter) const { - if (filter && cropRect().isLargest()) { + if (filter) { *filter = fColorFilter; fColorFilter->ref(); - return true; } - return false; + return true; } diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp index 5b52ad3cea..479648850c 100644 --- a/src/effects/SkGpuBlurUtils.cpp +++ b/src/effects/SkGpuBlurUtils.cpp @@ -11,7 +11,6 @@ #if SK_SUPPORT_GPU #include "effects/GrConvolutionEffect.h" -#include "effects/GrTextureDomainEffect.h" #include "GrContext.h" #endif @@ -41,29 +40,18 @@ static float adjust_sigma(float sigma, int *scaleFactor, int *radius) { static void convolve_gaussian(GrContext* context, GrTexture* texture, - const SkRect& srcRect, - const SkRect& dstRect, + const SkRect& rect, float sigma, int radius, Gr1DKernelEffect::Direction direction) { GrPaint paint; - paint.reset(); - float cropRect[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; - if (direction == Gr1DKernelEffect::kX_Direction) { - cropRect[0] = SkScalarToFloat(srcRect.left()) / texture->width(); - cropRect[1] = SkScalarToFloat(srcRect.right()) / texture->width(); - } else { - cropRect[2] = SkScalarToFloat(srcRect.top()) / texture->height(); - cropRect[3] = SkScalarToFloat(srcRect.bottom()) / texture->height(); - } SkAutoTUnref<GrEffectRef> conv(GrConvolutionEffect::CreateGaussian(texture, direction, radius, - sigma, - cropRect)); + sigma)); paint.addColorEffect(conv); - context->drawRectToRect(paint, dstRect, srcRect); + context->drawRect(paint, rect); } GrTexture* GaussianBlur(GrContext* context, @@ -91,7 +79,7 @@ GrTexture* GaussianBlur(GrContext* context, scale_rect(&srcRect, static_cast<float>(scaleFactorX), static_cast<float>(scaleFactorY)); - GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.height())); + GrContext::AutoClip acs(context, srcRect); GrAssert(kBGRA_8888_GrPixelConfig == srcTexture->config() || kRGBA_8888_GrPixelConfig == srcTexture->config() || @@ -116,25 +104,10 @@ GrTexture* GaussianBlur(GrContext* context, matrix.setIDiv(srcTexture->width(), srcTexture->height()); context->setRenderTarget(dstTexture->asRenderTarget()); SkRect dstRect(srcRect); - if (i == 1) { - dstRect.offset(-dstRect.fLeft, -dstRect.fTop); - SkRect domain; - matrix.mapRect(&domain, rect); - domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width() : 0.0f, - i < scaleFactorY ? SK_ScalarHalf / srcTexture->height() : 0.0f); - SkAutoTUnref<GrEffectRef> effect(GrTextureDomainEffect::Create( - srcTexture, - matrix, - domain, - GrTextureDomainEffect::kDecal_WrapMode, - true)); - paint.addColorEffect(effect); - } else { - GrTextureParams params(SkShader::kClamp_TileMode, true); - paint.addColorTextureEffect(srcTexture, matrix, params); - } scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, i < scaleFactorY ? 0.5f : 1.0f); + GrTextureParams params(SkShader::kClamp_TileMode, true); + paint.addColorTextureEffect(srcTexture, matrix, params); context->drawRectToRect(paint, dstRect, srcRect); srcRect = dstRect; srcTexture = dstTexture; @@ -153,11 +126,9 @@ GrTexture* GaussianBlur(GrContext* context, context->clear(&clearRect, 0x0); } context->setRenderTarget(dstTexture->asRenderTarget()); - SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); - convolve_gaussian(context, srcTexture, srcRect, dstRect, sigmaX, radiusX, + convolve_gaussian(context, srcTexture, srcRect, sigmaX, radiusX, Gr1DKernelEffect::kX_Direction); srcTexture = dstTexture; - srcRect = dstRect; SkTSwap(dstTexture, tempTexture); } @@ -171,11 +142,9 @@ GrTexture* GaussianBlur(GrContext* context, } context->setRenderTarget(dstTexture->asRenderTarget()); - SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); - convolve_gaussian(context, srcTexture, srcRect, dstRect, sigmaY, radiusY, + convolve_gaussian(context, srcTexture, srcRect, sigmaY, radiusY, Gr1DKernelEffect::kY_Direction); srcTexture = dstTexture; - srcRect = dstRect; SkTSwap(dstTexture, tempTexture); } diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 4456f513c4..eaac5ab12c 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -1387,7 +1387,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, SkAutoCachedTexture act(this, bitmap, NULL, &texture); SkImageFilter* filter = paint.getImageFilter(); - SkIPoint offset = SkIPoint::Make(left, top); + SkIPoint offset = SkIPoint::Make(0, 0); // This bitmap will own the filtered result as a texture. SkBitmap filteredBitmap; @@ -1396,8 +1396,6 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, texture = (GrTexture*) filteredBitmap.getTexture(); w = filteredBitmap.width(); h = filteredBitmap.height(); - } else { - return; } } @@ -1409,12 +1407,12 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, } fContext->drawRectToRect(grPaint, - SkRect::MakeXYWH(SkIntToScalar(offset.fX), - SkIntToScalar(offset.fY), + SkRect::MakeXYWH(SkIntToScalar(left), + SkIntToScalar(top), SkIntToScalar(w), SkIntToScalar(h)), - SkRect::MakeXYWH(0, - 0, + SkRect::MakeXYWH(SkIntToScalar(offset.fX), + SkIntToScalar(offset.fY), SK_Scalar1 * w / texture->width(), SK_Scalar1 * h / texture->height())); } @@ -1483,8 +1481,6 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device, h = filteredBitmap.height(); x += offset.fX; y += offset.fY; - } else { - return; } } diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index 5682b9c65c..380581fae3 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -37,7 +37,6 @@ private: int fRadius; UniformHandle fKernelUni; UniformHandle fImageIncrementUni; - UniformHandle fCropRectUni; GrGLEffectMatrix fEffectMatrix; typedef GrGLEffect INHERITED; @@ -48,7 +47,6 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& facto : INHERITED(factory) , fKernelUni(kInvalidUniformHandle) , fImageIncrementUni(kInvalidUniformHandle) - , fCropRectUni(kInvalidUniformHandle) , fEffectMatrix(drawEffect.castEffect<GrConvolutionEffect>().coordsType()) { const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>(); fRadius = c.radius(); @@ -64,8 +62,6 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec2f_GrSLType, "ImageIncrement"); - fCropRectUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, - kVec4f_GrSLType, "CropRect"); fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLType, "Kernel", this->width()); @@ -74,7 +70,6 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, int width = this ->width(); const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); const char* imgInc = builder->getUniformCStr(fImageIncrementUni); - const char* cropRect = builder->getUniformCStr(fCropRectUni); builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords, fRadius, imgInc); @@ -86,11 +81,9 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder, kernel.appendArrayAccess(index.c_str(), &kernelIndex); builder->fsCodeAppendf("\t\t%s += ", outputColor); builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, samplers[0], "coord"); - builder->fsCodeAppendf(" * float(coord.x >= %s.x && coord.x <= %s.y && coord.y >= %s.z && coord.y <= %s.w) * %s;\n", - cropRect, cropRect, cropRect, cropRect, kernelIndex.c_str()); + builder->fsCodeAppendf(" * %s;\n", kernelIndex.c_str()); builder->fsCodeAppendf("\t\tcoord += %s;\n", imgInc); } - SkString modulate; GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); builder->fsCodeAppend(modulate.c_str()); @@ -103,26 +96,17 @@ void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, // the code we generated was for a specific kernel radius GrAssert(conv.radius() == fRadius); float imageIncrement[2] = { 0 }; - float ySign = texture.origin() != kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; switch (conv.direction()) { case Gr1DKernelEffect::kX_Direction: imageIncrement[0] = 1.0f / texture.width(); break; case Gr1DKernelEffect::kY_Direction: - imageIncrement[1] = ySign / texture.height(); + imageIncrement[1] = 1.0f / texture.height(); break; default: GrCrash("Unknown filter direction."); } uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement); - float c[4]; - memcpy(c, conv.cropRect(), sizeof(c)); - if (texture.origin() != kTopLeft_GrSurfaceOrigin) { - float tmp = 1.0f - c[2]; - c[2] = 1.0f - c[3]; - c[3] = tmp; - } - uman.set4fv(fCropRectUni, 0, 1, c); uman.set1fv(fKernelUni, 0, this->width(), conv.kernel()); fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0)); } @@ -144,8 +128,7 @@ GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffe GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, Direction direction, int radius, - const float* kernel, - float cropRect[4]) + const float* kernel) : Gr1DKernelEffect(texture, direction, radius) { GrAssert(radius <= kMaxKernelRadius); GrAssert(NULL != kernel); @@ -153,14 +136,12 @@ GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, for (int i = 0; i < width; i++) { fKernel[i] = kernel[i]; } - memcpy(fCropRect, cropRect, sizeof(fCropRect)); } GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, Direction direction, int radius, - float gaussianSigma, - float cropRect[4]) + float gaussianSigma) : Gr1DKernelEffect(texture, direction, radius) { GrAssert(radius <= kMaxKernelRadius); int width = this->width(); @@ -179,7 +160,6 @@ GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, for (int i = 0; i < width; ++i) { fKernel[i] *= scale; } - memcpy(fCropRect, cropRect, sizeof(fCropRect)); } GrConvolutionEffect::~GrConvolutionEffect() { @@ -194,7 +174,6 @@ bool GrConvolutionEffect::onIsEqual(const GrEffect& sBase) const { return (this->texture(0) == s.texture(0) && this->radius() == s.radius() && this->direction() == s.direction() && - 0 == memcmp(fCropRect, s.fCropRect, sizeof(fCropRect)) && 0 == memcmp(fKernel, s.fKernel, this->width() * sizeof(float))); } @@ -211,13 +190,9 @@ GrEffectRef* GrConvolutionEffect::TestCreate(SkMWCRandom* random, Direction dir = random->nextBool() ? kX_Direction : kY_Direction; int radius = random->nextRangeU(1, kMaxKernelRadius); float kernel[kMaxKernelRadius]; - float cropRect[4]; for (int i = 0; i < kMaxKernelRadius; ++i) { kernel[i] = random->nextSScalar1(); } - for (int i = 0; i < 4; ++i) { - cropRect[i] = random->nextF(); - } - return GrConvolutionEffect::Create(textures[texIdx], dir, radius, kernel, cropRect); + return GrConvolutionEffect::Create(textures[texIdx], dir, radius,kernel); } diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h index f75cfe9155..e4faa945b8 100644 --- a/src/gpu/effects/GrConvolutionEffect.h +++ b/src/gpu/effects/GrConvolutionEffect.h @@ -22,16 +22,11 @@ class GrConvolutionEffect : public Gr1DKernelEffect { public: /// Convolve with an arbitrary user-specified kernel - static GrEffectRef* Create(GrTexture* tex, - Direction dir, - int halfWidth, - const float* kernel, - float cropRect[4]) { + static GrEffectRef* Create(GrTexture* tex, Direction dir, int halfWidth, const float* kernel) { AutoEffectUnref effect(SkNEW_ARGS(GrConvolutionEffect, (tex, dir, halfWidth, - kernel, - cropRect))); + kernel))); return CreateEffectRef(effect); } @@ -39,13 +34,11 @@ public: static GrEffectRef* CreateGaussian(GrTexture* tex, Direction dir, int halfWidth, - float gaussianSigma, - float cropRect[4]) { + float gaussianSigma) { AutoEffectUnref effect(SkNEW_ARGS(GrConvolutionEffect, (tex, dir, halfWidth, - gaussianSigma, - cropRect))); + gaussianSigma))); return CreateEffectRef(effect); } @@ -53,8 +46,6 @@ public: const float* kernel() const { return fKernel; } - const float* cropRect() const { return fCropRect; } - static const char* Name() { return "Convolution"; } typedef GrGLConvolutionEffect GLEffect; @@ -81,17 +72,15 @@ public: protected: float fKernel[kMaxKernelWidth]; - float fCropRect[4]; private: GrConvolutionEffect(GrTexture*, Direction, - int halfWidth, const float* kernel, float cropRect[4]); + int halfWidth, const float* kernel); /// Convolve with a Gaussian kernel GrConvolutionEffect(GrTexture*, Direction, int halfWidth, - float gaussianSigma, - float cropRect[4]); + float gaussianSigma); virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |