diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-10 10:51:58 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-10 10:51:58 +0000 |
commit | cac5fd597f6e2495f50aaa6bcbe3dadc56f0b977 (patch) | |
tree | aeeee764feb84da585a469d005bfaf0e4a69bc13 /src/effects | |
parent | b471a32460a44043e1f00d28cbefc87579dc30c5 (diff) |
Factory methods for heap-allocated SkImageFilter objects.
This is part of an effort to ensure that all SkPaint effects can only be
allocated on the heap.
This patch makes the constructors of SkImageFilter and its subclasses non-public
and instead provides factory methods for creating these objects on the heap. We
temporarily keep constructor of publicly visible classes public behind a flag.
BUG=skia:2187
R=scroggo@google.com, mtklein@chromium.org, reed@google.com, senorblanco@google.com, senorblanco@chromium.org, bsalomon@google.com, sugoi@chromium.org, zork@chromium.org
Author: dominikg@chromium.org
Review URL: https://codereview.chromium.org/182983003
git-svn-id: http://skia.googlecode.com/svn/trunk@13718 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r-- | src/effects/SkDisplacementMapEffect.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkDropShadowImageFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkMagnifierImageFilter.cpp | 2 | ||||
-rw-r--r-- | src/effects/SkMatrixConvolutionImageFilter.cpp | 56 | ||||
-rw-r--r-- | src/effects/SkPictureImageFilter.cpp | 14 |
5 files changed, 40 insertions, 38 deletions
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index 62fba1ac48..15e93c11cd 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -19,6 +19,8 @@ namespace { +#define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at most + template<SkDisplacementMapEffect::ChannelSelectorType type> uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { SkDEBUGFAIL("Unknown channel selector"); @@ -602,7 +604,7 @@ GrGLEffect::EffectKey GrGLDisplacementMapEffect::GenKey(const GrDrawEffect& draw drawEffect.castEffect<GrDisplacementMapEffect>(); EffectKey xKey = displacementMap.xChannelSelector(); - EffectKey yKey = displacementMap.yChannelSelector() << SkDisplacementMapEffect::kKeyBits; + EffectKey yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBits; return xKey | yKey; } diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp index 6d68a24d43..7c9631c393 100644 --- a/src/effects/SkDropShadowImageFilter.cpp +++ b/src/effects/SkDropShadowImageFilter.cpp @@ -82,7 +82,7 @@ bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source matrix.mapVectors(&sigma, &localSigma, 1); sigma.fX = SkMaxScalar(0, sigma.fX); sigma.fY = SkMaxScalar(0, sigma.fY); - SkAutoTUnref<SkImageFilter> blurFilter(new SkBlurImageFilter(sigma.fX, sigma.fY)); + SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY)); SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); SkPaint paint; paint.setImageFilter(blurFilter.get()); diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 4ab3fa1749..931ed7ec6b 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -247,7 +247,7 @@ SkMagnifierImageFilter::SkMagnifierImageFilter(SkReadBuffer& buffer) } // FIXME: implement single-input semantics -SkMagnifierImageFilter::SkMagnifierImageFilter(SkRect srcRect, SkScalar inset) +SkMagnifierImageFilter::SkMagnifierImageFilter(const SkRect& srcRect, SkScalar inset) : INHERITED(0), fSrcRect(srcRect), fInset(inset) { SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); } diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp index 79b8e2781b..9e4ad63e08 100644 --- a/src/effects/SkMatrixConvolutionImageFilter.cpp +++ b/src/effects/SkMatrixConvolutionImageFilter.cpp @@ -38,7 +38,7 @@ SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter( const SkScalar* kernel, SkScalar gain, SkScalar bias, - const SkIPoint& target, + const SkIPoint& kernelOffset, TileMode tileMode, bool convolveAlpha, SkImageFilter* input, @@ -47,15 +47,15 @@ SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter( fKernelSize(kernelSize), fGain(gain), fBias(bias), - fTarget(target), + fKernelOffset(kernelOffset), fTileMode(tileMode), fConvolveAlpha(convolveAlpha) { uint32_t size = fKernelSize.fWidth * fKernelSize.fHeight; fKernel = SkNEW_ARRAY(SkScalar, size); memcpy(fKernel, kernel, size * sizeof(SkScalar)); SkASSERT(kernelSize.fWidth >= 1 && kernelSize.fHeight >= 1); - SkASSERT(target.fX >= 0 && target.fX < kernelSize.fWidth); - SkASSERT(target.fY >= 0 && target.fY < kernelSize.fHeight); + SkASSERT(kernelOffset.fX >= 0 && kernelOffset.fX < kernelSize.fWidth); + SkASSERT(kernelOffset.fY >= 0 && kernelOffset.fY < kernelSize.fHeight); } SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkReadBuffer& buffer) @@ -79,8 +79,8 @@ SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkReadBuffer& buf } fGain = buffer.readScalar(); fBias = buffer.readScalar(); - fTarget.fX = buffer.readInt(); - fTarget.fY = buffer.readInt(); + fKernelOffset.fX = buffer.readInt(); + fKernelOffset.fY = buffer.readInt(); fTileMode = (TileMode) buffer.readInt(); fConvolveAlpha = buffer.readBool(); buffer.validate((fKernel != 0) && @@ -96,8 +96,8 @@ void SkMatrixConvolutionImageFilter::flatten(SkWriteBuffer& buffer) const { buffer.writeScalarArray(fKernel, fKernelSize.fWidth * fKernelSize.fHeight); buffer.writeScalar(fGain); buffer.writeScalar(fBias); - buffer.writeInt(fTarget.fX); - buffer.writeInt(fTarget.fY); + buffer.writeInt(fKernelOffset.fX); + buffer.writeInt(fKernelOffset.fY); buffer.writeInt((int) fTileMode); buffer.writeBool(fConvolveAlpha); } @@ -160,8 +160,8 @@ void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src, for (int cy = 0; cy < fKernelSize.fHeight; cy++) { for (int cx = 0; cx < fKernelSize.fWidth; cx++) { SkPMColor s = PixelFetcher::fetch(src, - x + cx - fTarget.fX, - y + cy - fTarget.fY, + x + cx - fKernelOffset.fX, + y + cy - fKernelOffset.fY, bounds); SkScalar k = fKernel[cy * fKernelSize.fWidth + cx]; if (convolveAlpha) { @@ -289,8 +289,8 @@ bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy, offset->fX = bounds.fLeft; offset->fY = bounds.fTop; bounds.offset(-srcOffset); - SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fTarget.fX, - bounds.top() + fTarget.fY, + SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fKernelOffset.fX, + bounds.top() + fKernelOffset.fY, bounds.width() - fKernelSize.fWidth + 1, bounds.height() - fKernelSize.fHeight + 1); SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(), interior.top()); @@ -323,7 +323,7 @@ public: const SkScalar* kernel, SkScalar gain, SkScalar bias, - const SkIPoint& target, + const SkIPoint& kernelOffset, TileMode tileMode, bool convolveAlpha) { AutoEffectUnref effect(SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, @@ -332,7 +332,7 @@ public: kernel, gain, bias, - target, + kernelOffset, tileMode, convolveAlpha))); return CreateEffectRef(effect); @@ -348,7 +348,7 @@ public: static const char* Name() { return "MatrixConvolution"; } const SkIRect& bounds() const { return fBounds; } const SkISize& kernelSize() const { return fKernelSize; } - const float* target() const { return fTarget; } + const float* kernelOffset() const { return fKernelOffset; } const float* kernel() const { return fKernel; } float gain() const { return fGain; } float bias() const { return fBias; } @@ -366,7 +366,7 @@ private: const SkScalar* kernel, SkScalar gain, SkScalar bias, - const SkIPoint& target, + const SkIPoint& kernelOffset, TileMode tileMode, bool convolveAlpha); @@ -377,7 +377,7 @@ private: float *fKernel; float fGain; float fBias; - float fTarget[2]; + float fKernelOffset[2]; TileMode fTileMode; bool fConvolveAlpha; @@ -475,7 +475,7 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder, kFloat_GrSLType, "Bias"); const char* bounds = builder->getUniformCStr(fBoundsUni); - const char* target = builder->getUniformCStr(fTargetUni); + const char* kernelOffset = builder->getUniformCStr(fTargetUni); const char* imgInc = builder->getUniformCStr(fImageIncrementUni); const char* kernel = builder->getUniformCStr(fKernelUni); const char* gain = builder->getUniformCStr(fGainUni); @@ -484,7 +484,7 @@ void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder, int kHeight = fKernelSize.height(); builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n"); - builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords2D.c_str(), target, imgInc); + builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords2D.c_str(), kernelOffset, imgInc); builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight); builder->fsCodeAppendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth); builder->fsCodeAppendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth); @@ -545,7 +545,7 @@ void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman, imageIncrement[0] = 1.0f / texture.width(); imageIncrement[1] = ySign / texture.height(); uman.set2fv(fImageIncrementUni, 1, imageIncrement); - uman.set2fv(fTargetUni, 1, conv.target()); + uman.set2fv(fTargetUni, 1, conv.kernelOffset()); uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.kernel()); uman.set1f(fGainUni, conv.gain()); uman.set1f(fBiasUni, conv.bias()); @@ -567,7 +567,7 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, const SkScalar* kernel, SkScalar gain, SkScalar bias, - const SkIPoint& target, + const SkIPoint& kernelOffset, TileMode tileMode, bool convolveAlpha) : INHERITED(texture, MakeDivByTextureWHMatrix(texture)), @@ -581,8 +581,8 @@ GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture, for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) { fKernel[i] = SkScalarToFloat(kernel[i]); } - fTarget[0] = static_cast<float>(target.x()); - fTarget[1] = static_cast<float>(target.y()); + fKernelOffset[0] = static_cast<float>(kernelOffset.x()); + fKernelOffset[1] = static_cast<float>(kernelOffset.y()); this->setWillNotUseInputColor(); } @@ -602,7 +602,7 @@ bool GrMatrixConvolutionEffect::onIsEqual(const GrEffect& sBase) const { fKernelSize.width() * fKernelSize.height() * sizeof(float)) && fGain == s.gain() && fBias == s.bias() && - fTarget == s.target() && + fKernelOffset == s.kernelOffset() && fTileMode == s.tileMode() && fConvolveAlpha == s.convolveAlpha(); } @@ -628,8 +628,8 @@ GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkRandom* random, } SkScalar gain = random->nextSScalar1(); SkScalar bias = random->nextSScalar1(); - SkIPoint target = SkIPoint::Make(random->nextRangeU(0, kernelSize.width()), - random->nextRangeU(0, kernelSize.height())); + SkIPoint kernelOffset = SkIPoint::Make(random->nextRangeU(0, kernelSize.width()), + random->nextRangeU(0, kernelSize.height())); SkIRect bounds = SkIRect::MakeXYWH(random->nextRangeU(0, textures[texIdx]->width()), random->nextRangeU(0, textures[texIdx]->height()), random->nextRangeU(0, textures[texIdx]->width()), @@ -642,7 +642,7 @@ GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkRandom* random, kernel.get(), gain, bias, - target, + kernelOffset, tileMode, convolveAlpha); } @@ -662,7 +662,7 @@ bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect, fKernel, fGain, fBias, - fTarget, + fKernelOffset, fTileMode, fConvolveAlpha); return true; diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp index 6e76231867..8db9914930 100644 --- a/src/effects/SkPictureImageFilter.cpp +++ b/src/effects/SkPictureImageFilter.cpp @@ -15,15 +15,15 @@ SkPictureImageFilter::SkPictureImageFilter(SkPicture* picture) : INHERITED(0, 0), fPicture(picture), - fRect(SkRect::MakeWH(picture ? SkIntToScalar(picture->width()) : 0, - picture ? SkIntToScalar(picture->height()) : 0)) { + fCropRect(SkRect::MakeWH(picture ? SkIntToScalar(picture->width()) : 0, + picture ? SkIntToScalar(picture->height()) : 0)) { SkSafeRef(fPicture); } -SkPictureImageFilter::SkPictureImageFilter(SkPicture* picture, const SkRect& rect) +SkPictureImageFilter::SkPictureImageFilter(SkPicture* picture, const SkRect& cropRect) : INHERITED(0, 0), fPicture(picture), - fRect(rect) { + fCropRect(cropRect) { SkSafeRef(fPicture); } @@ -41,7 +41,7 @@ SkPictureImageFilter::SkPictureImageFilter(SkReadBuffer& buffer) #else buffer.readBool(); #endif - buffer.readRect(&fRect); + buffer.readRect(&fCropRect); } void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { @@ -55,7 +55,7 @@ void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { #else buffer.writeBool(false); #endif - buffer.writeRect(fRect); + buffer.writeRect(fCropRect); } bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const SkMatrix& matrix, @@ -67,7 +67,7 @@ bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Sk SkRect floatBounds; SkIRect bounds; - matrix.mapRect(&floatBounds, fRect); + matrix.mapRect(&floatBounds, fCropRect); floatBounds.roundOut(&bounds); if (bounds.isEmpty()) { |