Add a hardwired-blend-mode version of GrBlendFragmentProcessor::Make.

When `Make<BlendOp>(src, dst)` is used, the blend mode will always be
hard-coded into the shader, instead of using a uniform to apply a
generic Porter-Duff blend.

Change-Id: I59a05eea3417b1880cef63738c0116d19f01ee3e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/525641
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
John Stiles 2022-03-29 19:15:01 -04:00 committed by SkCQ
parent 33782728ee
commit 4cd5e50c5d
8 changed files with 27 additions and 20 deletions

View File

@ -297,15 +297,13 @@ static GM::DrawResult run(GrRecordingContext* rContext, SkCanvas* canvas, SkStr
sampler,
caps);
// Compose against white (default paint color)
fp = GrBlendFragmentProcessor::Make(std::move(fp),
/*dst=*/nullptr,
SkBlendMode::kSrcOver);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kSrcOver>(std::move(fp),
/*dst=*/nullptr);
GrPaint paint;
// Compose against white (default paint color) and then replace the dst
// (SkBlendMode::kSrc).
fp = GrBlendFragmentProcessor::Make(std::move(fp),
/*dst=*/nullptr,
SkBlendMode::kSrcOver);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kSrcOver>(std::move(fp),
/*dst=*/nullptr);
paint.setColorFragmentProcessor(std::move(fp));
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
sdc->fillRectToRect(nullptr,
@ -415,9 +413,8 @@ static DrawResult do_very_large_blur_gm(GrRecordingContext* rContext,
if (result) {
std::unique_ptr<GrFragmentProcessor> fp =
GrTextureEffect::Make(std::move(result), kPremul_SkAlphaType);
fp = GrBlendFragmentProcessor::Make(std::move(fp),
/*dst=*/nullptr,
SkBlendMode::kSrcOver);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kSrcOver>(std::move(fp),
/*dst=*/nullptr);
sdc->fillRectToRectWithFP(SkIRect::MakeSize(dstB.size()),
dstRect,
std::move(fp));

View File

@ -206,7 +206,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulInputByChildAlpha(
if (!fp) {
return nullptr;
}
return GrBlendFragmentProcessor::Make(/*src=*/nullptr, std::move(fp), SkBlendMode::kSrcIn);
return GrBlendFragmentProcessor::Make<SkBlendMode::kSrcIn>(/*src=*/nullptr, std::move(fp));
}
std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::ApplyPaintAlpha(
@ -227,9 +227,8 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::ApplyPaintAlpha(
std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::ModulateRGBA(
std::unique_ptr<GrFragmentProcessor> inputFP, const SkPMColor4f& color) {
auto colorFP = MakeColor(color);
return GrBlendFragmentProcessor::Make(std::move(colorFP),
std::move(inputFP),
SkBlendMode::kModulate);
return GrBlendFragmentProcessor::Make<SkBlendMode::kModulate>(std::move(colorFP),
std::move(inputFP));
}
std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::ClampOutput(

View File

@ -17,12 +17,23 @@ namespace GrBlendFragmentProcessor {
/**
* Blends src and dst inputs according to the blend mode. If either input is null, fInputColor is
* used instead.
* used instead. TODO(johnstiles): Uses a uniform to specify the blend mode, reducing shader count.
*/
std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> src,
std::unique_ptr<GrFragmentProcessor> dst,
SkBlendMode mode);
/**
* Blends src and dst inputs according to the blend mode. If either input is null, fInputColor is
* used instead. Bakes the blend function directly into the code.
*/
template <SkBlendMode mode>
std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> src,
std::unique_ptr<GrFragmentProcessor> dst) {
return Make(std::move(src), std::move(dst), mode);
}
} // namespace GrBlendFragmentProcessor
#endif

View File

@ -1181,7 +1181,7 @@ GrOp::Owner TextureOp::Make(GrRecordingContext* context,
caps);
}
fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(textureXform));
fp = GrBlendFragmentProcessor::Make(std::move(fp), nullptr, SkBlendMode::kModulate);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kModulate>(std::move(fp), nullptr);
if (saturate == Saturate::kYes) {
fp = GrFragmentProcessor::ClampOutput(std::move(fp));
}

View File

@ -1646,7 +1646,7 @@ GrFPResult ClipStack::GetSWMaskFP(GrRecordingContext* context, Mask::Stack* mask
fp = GrFragmentProcessor::DeviceSpace(std::move(fp));
// Must combine the coverage sampled from the texture effect with the previous coverage
fp = GrBlendFragmentProcessor::Make(std::move(fp), std::move(clipFP), SkBlendMode::kDstIn);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kDstIn>(std::move(fp), std::move(clipFP));
return GrFPSuccess(std::move(fp));
}

View File

@ -521,8 +521,8 @@ void draw_image(GrRecordingContext* rContext,
if (!shaderFP) {
return;
}
fp = GrBlendFragmentProcessor::Make(
std::move(fp), std::move(shaderFP), SkBlendMode::kDstIn);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kDstIn>(std::move(fp),
std::move(shaderFP));
} else {
// Multiply the input (paint) color by the texture (alpha)
fp = GrFragmentProcessor::MulInputByChildAlpha(std::move(fp));

View File

@ -626,7 +626,7 @@ void SurfaceDrawContext::drawTexture(const GrClip* clip,
if (colorSpaceXform) {
fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform));
}
fp = GrBlendFragmentProcessor::Make(std::move(fp), nullptr, SkBlendMode::kModulate);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kModulate>(std::move(fp), nullptr);
paint.setColorFragmentProcessor(std::move(fp));
if (blendMode != SkBlendMode::kSrcOver) {
paint.setXPFactory(SkBlendMode_AsXPFactory(blendMode));

View File

@ -366,7 +366,7 @@ std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
kPremul_SkAlphaType);
if (fImage->isAlphaOnly()) {
fp = GrBlendFragmentProcessor::Make(std::move(fp), nullptr, SkBlendMode::kDstIn);
fp = GrBlendFragmentProcessor::Make<SkBlendMode::kDstIn>(std::move(fp), nullptr);
}
}