Cleanup patch to move all of SkImageFilterUtils into SkImageFilter.

This was a utility class that dates from before GPU code was allowed
in core. Now that it is, there's no reason not to have this
functionality in SkImageFilter.

Covered by existing tests.

R=reed@google.com

Review URL: https://codereview.chromium.org/185973003

git-svn-id: http://skia.googlecode.com/svn/trunk@13646 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
senorblanco@chromium.org 2014-03-03 22:13:56 +00:00
parent 94e43ffae1
commit 6aa6fec0e3
12 changed files with 87 additions and 130 deletions

View File

@ -100,7 +100,6 @@
'<(skia_src_path)/core/SkGraphics.cpp',
'<(skia_src_path)/core/SkInstCnt.cpp',
'<(skia_src_path)/core/SkImageFilter.cpp',
'<(skia_src_path)/core/SkImageFilterUtils.cpp',
'<(skia_src_path)/core/SkImageInfo.cpp',
'<(skia_src_path)/core/SkLineClipper.cpp',
'<(skia_src_path)/core/SkMallocPixelRef.cpp',
@ -252,7 +251,6 @@
'<(skia_include_path)/core/SkImageDecoder.h',
'<(skia_include_path)/core/SkImageEncoder.h',
'<(skia_include_path)/core/SkImageFilter.h',
'<(skia_include_path)/core/SkImageFilterUtils.h',
'<(skia_include_path)/core/SkImageInfo.h',
'<(skia_include_path)/core/SkInstCnt.h',
'<(skia_include_path)/core/SkMallocPixelRef.h',

View File

@ -247,7 +247,6 @@
'core/SkTArray.h',
'core/SkStringUtils.h',
'core/SkPreConfig.h',
'core/SkImageFilterUtils.h',
'core/SkLineClipper.h',
'core/SkPathEffect.h',
'core/SkString.h',

View File

@ -146,6 +146,20 @@ public:
// Default impl returns union of all input bounds.
virtual void computeFastBounds(const SkRect&, SkRect*) const;
#ifdef SK_SUPPORT_GPU
/**
* Wrap the given texture in a texture-backed SkBitmap.
*/
static void WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result);
/**
* Recursively evaluate this filter on the GPU. If the filter has no GPU
* implementation, it will be processed in software and uploaded to the GPU.
*/
bool getInputResultGPU(SkImageFilter::Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) const;
#endif
SK_DEFINE_FLATTENABLE_TYPE(SkImageFilter)
protected:
@ -222,6 +236,7 @@ protected:
const SkMatrix& matrix,
const SkIRect& bounds) const;
private:
typedef SkFlattenable INHERITED;
int fInputCount;

View File

@ -1,38 +0,0 @@
/*
* Copyright 2013 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkImageFilterUtils_DEFINED
#define SkImageFilterUtils_DEFINED
#if SK_SUPPORT_GPU
#include "SkImageFilter.h"
class SkBitmap;
class GrTexture;
class SkImageFilter;
class SK_API SkImageFilterUtils {
public:
/**
* Wrap the given texture in a texture-backed SkBitmap.
*/
static bool WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result);
/**
* Recursively evaluate the given filter on the GPU. If filter is NULL,
* this function returns src. If the filter has no GPU implementation, it
* will be processed in software and uploaded to the GPU.
*/
static bool GetInputResultGPU(const SkImageFilter* filter, SkImageFilter::Proxy* proxy,
const SkBitmap& src, const SkMatrix& ctm, SkBitmap* result,
SkIPoint* offset);
};
#endif
#endif

View File

@ -14,8 +14,8 @@
#include "SkValidationUtils.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrTexture.h"
#include "SkImageFilterUtils.h"
#include "SkGrPixelRef.h"
#include "SkGr.h"
#endif
SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
@ -146,10 +146,11 @@ bool SkImageFilter::canFilterImageGPU() const {
bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input;
SkBitmap input = src;
SkASSERT(fInputCount == 1);
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, ctm, &input, &srcOffset)) {
if (this->getInput(0) &&
!this->getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
return false;
}
GrTexture* srcTexture = input.getTexture();
@ -188,7 +189,7 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMa
context->drawRectToRect(paint, dstRect, srcRect);
SkAutoTUnref<GrTexture> resultTex(dst.detach());
SkImageFilterUtils::WrapTexture(resultTex, bounds.width(), bounds.height(), result);
WrapTexture(resultTex, bounds.width(), bounds.height(), result);
return true;
#else
return false;
@ -242,3 +243,40 @@ bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkMatrix&, cons
bool SkImageFilter::asColorFilter(SkColorFilter**) const {
return false;
}
#if SK_SUPPORT_GPU
void SkImageFilter::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
result->setConfig(info);
result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
}
bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) const {
// Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
// matrix with no clip and that the matrix, clip, and render target set before this function was
// called are restored before we return to the caller.
GrContext* context = src.getTexture()->getContext();
GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
if (this->canFilterImageGPU()) {
return this->filterImageGPU(proxy, src, ctm, result, offset);
} else {
if (this->filterImage(proxy, src, ctm, result, offset)) {
if (!result->getTexture()) {
SkImageInfo info;
if (!result->asImageInfo(&info)) {
return false;
}
GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
GrUnlockAndUnrefCachedBitmapTexture(resultTex);
}
return true;
} else {
return false;
}
}
}
#endif

View File

@ -1,55 +0,0 @@
/*
* Copyright 2013 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkMatrix.h"
#if SK_SUPPORT_GPU
#include "GrTexture.h"
#include "SkImageFilterUtils.h"
#include "SkBitmap.h"
#include "SkGrPixelRef.h"
#include "SkGr.h"
bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
result->setConfig(info);
result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
return true;
}
bool SkImageFilterUtils::GetInputResultGPU(const SkImageFilter* filter, SkImageFilter::Proxy* proxy,
const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) {
// Ensure that GrContext calls under filterImage and filterImageGPU below will see an identity
// matrix with no clip and that the matrix, clip, and render target set before this function was
// called are restored before we return to the caller.
GrContext* context = src.getTexture()->getContext();
GrContext::AutoWideOpenIdentityDraw awoid(context, NULL);
if (!filter) {
offset->fX = offset->fY = 0;
*result = src;
return true;
} else if (filter->canFilterImageGPU()) {
return filter->filterImageGPU(proxy, src, ctm, result, offset);
} else {
if (filter->filterImage(proxy, src, ctm, result, offset)) {
if (!result->getTexture()) {
SkImageInfo info;
if (!result->asImageInfo(&info)) {
return false;
}
GrTexture* resultTex = GrLockAndRefCachedBitmapTexture(context, *result, NULL);
result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref();
GrUnlockAndUnrefCachedBitmapTexture(resultTex);
}
return true;
} else {
return false;
}
}
}
#endif

View File

@ -16,7 +16,6 @@
#include "GrCoordTransform.h"
#include "gl/GrGLEffect.h"
#include "GrTBackendEffectFactory.h"
#include "SkImageFilterUtils.h"
#endif
static const bool gUseUnpremul = false;

View File

@ -18,7 +18,6 @@
#include "effects/GrBicubicEffect.h"
#include "GrContext.h"
#include "GrTexture.h"
#include "SkImageFilterUtils.h"
#endif
#define DS(x) SkDoubleToScalar(x)
@ -171,8 +170,8 @@ bool SkBicubicImageFilter::onFilterImage(Proxy* proxy,
bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap srcBM;
if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &srcBM, offset)) {
SkBitmap srcBM = src;
if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &srcBM, offset)) {
return false;
}
GrTexture* srcTexture = srcBM.getTexture();
@ -198,7 +197,8 @@ bool SkBicubicImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, con
SkRect srcRect;
srcBM.getBounds(&srcRect);
context->drawRectToRect(paint, dstRect, srcRect);
return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, result);
WrapTexture(dst, desc.fWidth, desc.fHeight, result);
return true;
}
#endif

View File

@ -14,7 +14,6 @@
#include "SkBlurImage_opts.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "SkImageFilterUtils.h"
#endif
SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer)
@ -254,9 +253,9 @@ bool SkBlurImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input;
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &input, &srcOffset)) {
if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
return false;
}
GrTexture* source = input.getTexture();
@ -278,7 +277,8 @@ bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
true,
sigma.x(),
sigma.y()));
return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), result);
WrapTexture(tex, rect.width(), rect.height(), result);
return true;
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return false;

View File

@ -15,7 +15,6 @@
#include "GrCoordTransform.h"
#include "gl/GrGLEffect.h"
#include "GrTBackendEffectFactory.h"
#include "SkImageFilterUtils.h"
#endif
namespace {
@ -349,17 +348,18 @@ private:
bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM;
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getColorInput(), proxy, src, ctm, &colorBM,
&colorOffset)) {
if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctm, &colorBM,
&colorOffset)) {
return false;
}
GrTexture* color = colorBM.getTexture();
SkBitmap displacementBM;
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getDisplacementInput(), proxy, src, ctm,
&displacementBM, &displacementOffset)) {
if (getDisplacementInput() &&
!getDisplacementInput()->getInputResultGPU(proxy, src, ctm, &displacementBM,
&displacementOffset)) {
return false;
}
GrTexture* displacement = displacementBM.getTexture();
@ -415,7 +415,8 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
context->drawRect(paint, SkRect::Make(colorBounds));
offset->fX = bounds.left();
offset->fY = bounds.top();
return SkImageFilterUtils::WrapTexture(dst, bounds.width(), bounds.height(), result);
WrapTexture(dst, bounds.width(), bounds.height(), result);
return true;
}
///////////////////////////////////////////////////////////////////////////////

View File

@ -18,7 +18,6 @@
#include "GrTBackendEffectFactory.h"
#include "gl/GrGLEffect.h"
#include "effects/Gr1DKernelEffect.h"
#include "SkImageFilterUtils.h"
#endif
SkMorphologyImageFilter::SkMorphologyImageFilter(SkReadBuffer& buffer)
@ -530,7 +529,8 @@ bool apply_morphology(const SkBitmap& input,
morphType, Gr1DKernelEffect::kY_Direction);
src.reset(ast.detach());
}
return SkImageFilterUtils::WrapTexture(src, rect.width(), rect.height(), dst);
SkImageFilter::WrapTexture(src, rect.width(), rect.height(), dst);
return true;
}
};
@ -541,9 +541,9 @@ bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
const SkMatrix& ctm,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap input;
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &input, &srcOffset)) {
if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) {
return false;
}
SkIRect bounds;

View File

@ -16,7 +16,6 @@
#include "GrContext.h"
#include "effects/GrSimpleTextureEffect.h"
#include "SkGr.h"
#include "SkImageFilterUtils.h"
#endif
///////////////////////////////////////////////////////////////////////////////
@ -101,17 +100,17 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
const SkMatrix& ctm,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap background;
SkBitmap background = src;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &background,
&backgroundOffset)) {
if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &background,
&backgroundOffset)) {
return false;
}
GrTexture* backgroundTex = background.getTexture();
SkBitmap foreground;
SkBitmap foreground = src;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getInput(1), proxy, src, ctm, &foreground,
&foregroundOffset)) {
if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctm, &foreground,
&foregroundOffset)) {
return false;
}
GrTexture* foregroundTex = foreground.getTexture();
@ -160,7 +159,8 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
}
offset->fX = backgroundOffset.fX;
offset->fY = backgroundOffset.fY;
return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), result);
WrapTexture(dst, src.width(), src.height(), result);
return true;
}
#endif