add gpu impl for shadermaskfilter
adds MulChildAlphaByInput
renames MulOutputByInputAlpha --> MulChildByInputAlpha
Bug: skia:7500
Change-Id: Ic0615d4d23a887fbee510901ed77a36f98a1b11d
Reviewed-on: https://skia-review.googlesource.com/102440
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/src/effects/SkShaderMaskFilter.cpp b/src/effects/SkShaderMaskFilter.cpp
index f2088fc..74352ac 100644
--- a/src/effects/SkShaderMaskFilter.cpp
+++ b/src/effects/SkShaderMaskFilter.cpp
@@ -9,7 +9,7 @@
#include "SkMaskFilterBase.h"
#include "SkReadBuffer.h"
#include "SkShaderMaskFilter.h"
-#include "SkShader.h"
+#include "SkShaderBase.h"
#include "SkString.h"
class SkShaderMF : public SkMaskFilterBase {
@@ -30,6 +30,12 @@
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkShaderMF)
+protected:
+#if SK_SUPPORT_GPU
+ std::unique_ptr<GrFragmentProcessor> onAsFragmentProcessor(const GrFPArgs&) const override;
+ bool onHasFragmentProcessor() const override;
+#endif
+
private:
sk_sp<SkShader> fShader;
@@ -108,6 +114,19 @@
}
///////////////////////////////////////////////////////////////////////////////////////////////////
+#if SK_SUPPORT_GPU
+#include "GrFragmentProcessor.h"
+
+std::unique_ptr<GrFragmentProcessor> SkShaderMF::onAsFragmentProcessor(const GrFPArgs& args) const {
+ return GrFragmentProcessor::MulInputByChildAlpha(as_SB(fShader)->asFragmentProcessor(args));
+}
+
+bool SkShaderMF::onHasFragmentProcessor() const {
+ return true;
+}
+
+#endif
+///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkMaskFilter> SkShaderMaskFilter::Make(sk_sp<SkShader> shader) {
return shader ? sk_sp<SkMaskFilter>(new SkShaderMF(std::move(shader))) : nullptr;
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index 0c7c06f..187a177 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -103,7 +103,7 @@
return true;
}
-std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha(
+std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulChildByInputAlpha(
std::unique_ptr<GrFragmentProcessor> fp) {
if (!fp) {
return nullptr;
@@ -111,6 +111,14 @@
return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kDstIn);
}
+std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulInputByChildAlpha(
+ std::unique_ptr<GrFragmentProcessor> fp) {
+ if (!fp) {
+ return nullptr;
+ }
+ return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kSrcIn);
+}
+
std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::PremulInput(
std::unique_ptr<GrFragmentProcessor> fp) {
if (!fp) {
diff --git a/src/gpu/GrFragmentProcessor.h b/src/gpu/GrFragmentProcessor.h
index 4ec9262..fa674d5 100644
--- a/src/gpu/GrFragmentProcessor.h
+++ b/src/gpu/GrFragmentProcessor.h
@@ -33,8 +33,17 @@
* does so by returning a parent FP that multiplies the passed in FPs output by the parent's
* input alpha. The passed in FP will not receive an input color.
*/
- static std::unique_ptr<GrFragmentProcessor> MulOutputByInputAlpha(
- std::unique_ptr<GrFragmentProcessor>);
+ static std::unique_ptr<GrFragmentProcessor> MulChildByInputAlpha(
+ std::unique_ptr<GrFragmentProcessor> child);
+
+ /**
+ * Like MulChildByInputAlpha(), but reverses the sense of src and dst. In this case, return
+ * the input modulated by the child's alpha. The passed in FP will not receive an input color.
+ *
+ * output = input * child.a
+ */
+ static std::unique_ptr<GrFragmentProcessor> MulInputByChildAlpha(
+ std::unique_ptr<GrFragmentProcessor> child);
/**
* This assumes that the input color to the returned processor will be unpremul and that the
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 080d993..73e5f11 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1094,7 +1094,7 @@
if (GrPixelConfigIsAlphaOnly(config)) {
fp = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp));
} else {
- fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
+ fp = GrFragmentProcessor::MulChildByInputAlpha(std::move(fp));
}
GrPaint grPaint;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index a702d06..af0579a 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -576,7 +576,7 @@
shaderFP = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp));
}
} else {
- shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
+ shaderFP = GrFragmentProcessor::MulChildByInputAlpha(std::move(fp));
}
return SkPaintToGrPaintReplaceShader(context, colorSpaceInfo, paint, std::move(shaderFP),
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index 4ca6cd9..4eaeae2 100644
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -234,7 +234,7 @@
if (isAlphaOnly) {
return inner;
}
- return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
+ return GrFragmentProcessor::MulChildByInputAlpha(std::move(inner));
}
#endif
diff --git a/src/shaders/SkPerlinNoiseShader.cpp b/src/shaders/SkPerlinNoiseShader.cpp
index 48c9c30..5979a9b 100644
--- a/src/shaders/SkPerlinNoiseShader.cpp
+++ b/src/shaders/SkPerlinNoiseShader.cpp
@@ -1434,7 +1434,7 @@
auto inner =
GrConstColorProcessor::Make(GrColor4f::FromGrColor(0x80404040),
GrConstColorProcessor::InputMode::kModulateRGBA);
- return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
+ return GrFragmentProcessor::MulChildByInputAlpha(std::move(inner));
}
// Emit zero.
return GrConstColorProcessor::Make(GrColor4f::TransparentBlack(),
@@ -1456,7 +1456,7 @@
std::move(permutationsProxy),
std::move(noiseProxy),
m);
- return GrFragmentProcessor::MulOutputByInputAlpha(std::move(inner));
+ return GrFragmentProcessor::MulChildByInputAlpha(std::move(inner));
}
return nullptr;
}
diff --git a/src/shaders/gradients/SkGradientShaderPriv.h b/src/shaders/gradients/SkGradientShaderPriv.h
index 53411b2..d71ba02 100644
--- a/src/shaders/gradients/SkGradientShaderPriv.h
+++ b/src/shaders/gradients/SkGradientShaderPriv.h
@@ -280,7 +280,7 @@
} else {
fp = std::move(gradientFP);
}
- return GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
+ return GrFragmentProcessor::MulChildByInputAlpha(std::move(fp));
}
#if GR_TEST_UTILS