diff options
author | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-03 22:13:56 +0000 |
---|---|---|
committer | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-03-03 22:13:56 +0000 |
commit | 6aa6fec0e332c9246958245bad5fc881fefee68f (patch) | |
tree | db8597899a1452785f0a75cfb7a365eda96a452d /src/core | |
parent | 94e43ffae1877869b8ef85d429dd451020ecde89 (diff) |
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
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkImageFilter.cpp | 48 | ||||
-rw-r--r-- | src/core/SkImageFilterUtils.cpp | 55 |
2 files changed, 43 insertions, 60 deletions
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index cd7c01b4e6..4a380c52eb 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -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 diff --git a/src/core/SkImageFilterUtils.cpp b/src/core/SkImageFilterUtils.cpp deleted file mode 100644 index c6c534e71d..0000000000 --- a/src/core/SkImageFilterUtils.cpp +++ /dev/null @@ -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 |