Image filters: refactor input GPU processing into filterInputGPU().
(analog of CPU version here: https://codereview.chromium.org/1404743005/)
No change in behaviour; this is a straight refactoring.
BUG=skia:3194
Review URL: https://codereview.chromium.org/1393283008
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index de35718..64e1581 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -248,12 +248,14 @@
*/
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 Context&,
- SkBitmap* result, SkIPoint* offset) const;
+ // Helper function which invokes GPU filter processing on the
+ // input at the specified "index". If the input is null, it leaves
+ // "result" and "offset" untouched, and returns true. If the input
+ // has a GPU implementation, it will be invoked directly.
+ // Otherwise, the filter will be processed in software and
+ // uploaded to the GPU.
+ bool filterInputGPU(int index, SkImageFilter::Proxy* proxy, const SkBitmap& src, const Context&,
+ SkBitmap* result, SkIPoint* offset) const;
#endif
SK_TO_STRING_PUREVIRT()
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 9cadc3f..d7af4e6 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -329,8 +329,7 @@
SkBitmap input = src;
SkASSERT(fInputCount == 1);
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
+ if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
GrTexture* srcTexture = input.getTexture();
@@ -466,18 +465,22 @@
result->setPixelRef(new SkGrPixelRef(info, texture))->unref();
}
-bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy,
- const SkBitmap& src, const Context& ctx,
- SkBitmap* result, SkIPoint* offset) const {
+bool SkImageFilter::filterInputGPU(int index, SkImageFilter::Proxy* proxy,
+ const SkBitmap& src, const Context& ctx,
+ SkBitmap* result, SkIPoint* offset) const {
+ SkImageFilter* input = this->getInput(index);
+ if (!input) {
+ return true;
+ }
// 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();
- if (this->canFilterImageGPU()) {
- return this->filterImageGPU(proxy, src, ctx, result, offset);
+ if (input->canFilterImageGPU()) {
+ return input->filterImageGPU(proxy, src, ctx, result, offset);
} else {
- if (this->filterImage(proxy, src, ctx, result, offset)) {
+ if (input->filterImage(proxy, src, ctx, result, offset)) {
if (!result->getTexture()) {
const SkImageInfo info = result->info();
if (kUnknown_SkColorType == info.colorType()) {
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index ddc034d..2097696 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -194,8 +194,7 @@
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
+ if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect rect;
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 5de945f..4be8d77 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -384,15 +384,12 @@
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
- if (this->getColorInput() &&
- !this->getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM, &colorOffset)) {
+ if (!this->filterInputGPU(1, proxy, src, ctx, &colorBM, &colorOffset)) {
return false;
}
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
- if (this->getDisplacementInput() &&
- !this->getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
- &displacementOffset)) {
+ if (!this->filterInputGPU(0, proxy, src, ctx, &displacementBM, &displacementOffset)) {
return false;
}
SkIRect bounds;
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 270c10f..199bb4d 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -361,8 +361,7 @@
SkIPoint* offset) const {
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
+ if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect bounds;
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index f3ae6ac..6f6a1e1 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -612,8 +612,7 @@
SkIPoint* offset) const {
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
- if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
+ if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect bounds;
diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp
index 9692a2d..6cedf84 100644
--- a/src/effects/SkXfermodeImageFilter.cpp
+++ b/src/effects/SkXfermodeImageFilter.cpp
@@ -130,8 +130,7 @@
SkIPoint* offset) const {
SkBitmap background = src;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
- if (this->getInput(0) &&
- !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &background, &backgroundOffset)) {
+ if (!this->filterInputGPU(0, proxy, src, ctx, &background, &backgroundOffset)) {
return false;
}
@@ -143,8 +142,7 @@
SkBitmap foreground = src;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
- if (this->getInput(1) &&
- !this->getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground, &foregroundOffset)) {
+ if (!this->filterInputGPU(1, proxy, src, ctx, &foreground, &foregroundOffset)) {
return false;
}
GrTexture* foregroundTex = foreground.getTexture();