Split GrConstColorProcessor into three separate .fp effects.
ConstColorProcessor contained three separate InputModes with their own unique behaviors, but every (non-test) call site simply hardcoded one of the InputModes. This change also allows the actual const-color processor to remove the inputFP entirely; it is never sampled. The GM slide has been split into three separate slides as well. Change-Id: I2b77f4eab4d655f06e3704fb6fde8d4f8c70a075 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301987 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
d9800f8fda
commit
7c1967700b
@ -37,6 +37,8 @@
|
||||
#include "src/gpu/GrRenderTargetContextPriv.h"
|
||||
#include "src/gpu/SkGr.h"
|
||||
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
|
||||
#include "src/gpu/effects/generated/GrModulateAlphaEffect.h"
|
||||
#include "src/gpu/effects/generated/GrModulateRGBAEffect.h"
|
||||
#include "src/gpu/ops/GrDrawOp.h"
|
||||
#include "src/gpu/ops/GrFillRectOp.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
@ -46,17 +48,28 @@
|
||||
|
||||
namespace skiagm {
|
||||
/**
|
||||
* This GM directly exercises GrConstColorProcessor.
|
||||
* This GM directly exercises GrConstColorProcessor, GrModulateRGBAEffect and GrModulateAlphaEffect.
|
||||
*/
|
||||
class ConstColorProcessor : public GpuGM {
|
||||
class ColorProcessor : public GpuGM {
|
||||
public:
|
||||
ConstColorProcessor() {
|
||||
enum class TestMode {
|
||||
kConstColor,
|
||||
kModulateRGBA,
|
||||
kModulateAlpha
|
||||
};
|
||||
|
||||
ColorProcessor(TestMode mode) : fMode(mode) {
|
||||
this->setBGColor(0xFFDDDDDD);
|
||||
}
|
||||
|
||||
protected:
|
||||
SkString onShortName() override {
|
||||
return SkString("const_color_processor");
|
||||
switch (fMode) {
|
||||
case TestMode::kConstColor: return SkString("const_color_processor");
|
||||
case TestMode::kModulateRGBA: return SkString("modulate_rgba");
|
||||
case TestMode::kModulateAlpha: return SkString("modulate_alpha");
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
}
|
||||
|
||||
SkISize onISize() override {
|
||||
@ -86,106 +99,110 @@ protected:
|
||||
0x00000000,
|
||||
};
|
||||
|
||||
const char* kModeStrs[] {
|
||||
"kIgnore",
|
||||
"kModulateRGBA",
|
||||
"kModulateA",
|
||||
};
|
||||
static_assert(SK_ARRAY_COUNT(kModeStrs) == GrConstColorProcessor::kInputModeCnt);
|
||||
|
||||
SkScalar y = kPad;
|
||||
SkScalar x = kPad;
|
||||
SkScalar maxW = 0;
|
||||
for (size_t paintType = 0; paintType < SK_ARRAY_COUNT(kPaintColors) + 1; ++paintType) {
|
||||
for (size_t procColor = 0; procColor < SK_ARRAY_COUNT(kColors); ++procColor) {
|
||||
for (int m = 0; m < GrConstColorProcessor::kInputModeCnt; ++m) {
|
||||
// translate by x,y for the canvas draws and the test target draws.
|
||||
canvas->save();
|
||||
canvas->translate(x, y);
|
||||
// translate by x,y for the canvas draws and the test target draws.
|
||||
canvas->save();
|
||||
canvas->translate(x, y);
|
||||
|
||||
// rect to draw
|
||||
SkRect renderRect = SkRect::MakeXYWH(0, 0, kRectSize, kRectSize);
|
||||
// rect to draw
|
||||
SkRect renderRect = SkRect::MakeXYWH(0, 0, kRectSize, kRectSize);
|
||||
|
||||
// Create a base-layer FP for the const color processor to draw on top of.
|
||||
std::unique_ptr<GrFragmentProcessor> baseFP;
|
||||
if (paintType >= SK_ARRAY_COUNT(kPaintColors)) {
|
||||
GrColorInfo colorInfo;
|
||||
GrFPArgs args(context, SkSimpleMatrixProvider(SkMatrix::I()),
|
||||
kHigh_SkFilterQuality, &colorInfo);
|
||||
baseFP = as_SB(fShader)->asFragmentProcessor(args);
|
||||
} else {
|
||||
baseFP = GrConstColorProcessor::Make(
|
||||
/*inputFP=*/nullptr,
|
||||
SkPMColor4f::FromBytes_RGBA(kPaintColors[paintType]),
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
}
|
||||
// Create a base-layer FP for the const color processor to draw on top of.
|
||||
std::unique_ptr<GrFragmentProcessor> baseFP;
|
||||
if (paintType >= SK_ARRAY_COUNT(kPaintColors)) {
|
||||
GrColorInfo colorInfo;
|
||||
GrFPArgs args(context, SkSimpleMatrixProvider(SkMatrix::I()),
|
||||
kHigh_SkFilterQuality, &colorInfo);
|
||||
baseFP = as_SB(fShader)->asFragmentProcessor(args);
|
||||
} else {
|
||||
baseFP = GrConstColorProcessor::Make(
|
||||
SkPMColor4f::FromBytes_RGBA(kPaintColors[paintType]));
|
||||
}
|
||||
|
||||
// Layer a const-color FP on top of the base layer, using various modes/colors.
|
||||
auto constColorFP = GrConstColorProcessor::Make(
|
||||
std::move(baseFP), SkPMColor4f::FromBytes_RGBA(kColors[procColor]),
|
||||
GrConstColorProcessor::InputMode(m));
|
||||
// Layer a color/modulation FP on top of the base layer, using various colors.
|
||||
std::unique_ptr<GrFragmentProcessor> colorFP;
|
||||
switch (fMode) {
|
||||
case TestMode::kConstColor:
|
||||
colorFP = GrConstColorProcessor::Make(
|
||||
SkPMColor4f::FromBytes_RGBA(kColors[procColor]));
|
||||
break;
|
||||
|
||||
// Render the FP tree.
|
||||
if (auto op = sk_gpu_test::test_ops::MakeRect(context,
|
||||
std::move(constColorFP),
|
||||
renderRect.makeOffset(x, y),
|
||||
renderRect,
|
||||
SkMatrix::I())) {
|
||||
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
||||
}
|
||||
case TestMode::kModulateRGBA:
|
||||
colorFP = GrModulateRGBAEffect::Make(
|
||||
std::move(baseFP),
|
||||
SkPMColor4f::FromBytes_RGBA(kColors[procColor]));
|
||||
break;
|
||||
|
||||
// Draw labels for the input to the processor and the processor to the right of
|
||||
// the test rect. The input label appears above the processor label.
|
||||
SkFont labelFont;
|
||||
labelFont.setTypeface(ToolUtils::create_portable_typeface());
|
||||
labelFont.setEdging(SkFont::Edging::kAntiAlias);
|
||||
labelFont.setSize(10.f);
|
||||
SkPaint labelPaint;
|
||||
labelPaint.setAntiAlias(true);
|
||||
SkString inputLabel;
|
||||
inputLabel.set("Input: ");
|
||||
if (paintType >= SK_ARRAY_COUNT(kPaintColors)) {
|
||||
inputLabel.append("gradient");
|
||||
} else {
|
||||
inputLabel.appendf("0x%08x", kPaintColors[paintType]);
|
||||
}
|
||||
SkString procLabel;
|
||||
procLabel.printf("Proc: [0x%08x, %s]", kColors[procColor], kModeStrs[m]);
|
||||
case TestMode::kModulateAlpha:
|
||||
colorFP = GrModulateAlphaEffect::Make(
|
||||
std::move(baseFP),
|
||||
SkPMColor4f::FromBytes_RGBA(kColors[procColor]));
|
||||
break;
|
||||
}
|
||||
|
||||
SkRect inputLabelBounds;
|
||||
// get the bounds of the text in order to position it
|
||||
labelFont.measureText(inputLabel.c_str(), inputLabel.size(),
|
||||
SkTextEncoding::kUTF8, &inputLabelBounds);
|
||||
canvas->drawString(inputLabel, renderRect.fRight + kPad, -inputLabelBounds.fTop,
|
||||
labelFont, labelPaint);
|
||||
// update the bounds to reflect the offset we used to draw it.
|
||||
inputLabelBounds.offset(renderRect.fRight + kPad, -inputLabelBounds.fTop);
|
||||
// Render the FP tree.
|
||||
if (auto op = sk_gpu_test::test_ops::MakeRect(context,
|
||||
std::move(colorFP),
|
||||
renderRect.makeOffset(x, y),
|
||||
renderRect,
|
||||
SkMatrix::I())) {
|
||||
renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
|
||||
}
|
||||
|
||||
SkRect procLabelBounds;
|
||||
labelFont.measureText(procLabel.c_str(), procLabel.size(),
|
||||
SkTextEncoding::kUTF8, &procLabelBounds);
|
||||
canvas->drawString(procLabel, renderRect.fRight + kPad,
|
||||
inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop,
|
||||
labelFont, labelPaint);
|
||||
procLabelBounds.offset(renderRect.fRight + kPad,
|
||||
inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop);
|
||||
// Draw labels for the input to the processor and the processor to the right of
|
||||
// the test rect. The input label appears above the processor label.
|
||||
SkFont labelFont;
|
||||
labelFont.setTypeface(ToolUtils::create_portable_typeface());
|
||||
labelFont.setEdging(SkFont::Edging::kAntiAlias);
|
||||
labelFont.setSize(10.f);
|
||||
SkPaint labelPaint;
|
||||
labelPaint.setAntiAlias(true);
|
||||
SkString inputLabel("Input: ");
|
||||
if (paintType >= SK_ARRAY_COUNT(kPaintColors)) {
|
||||
inputLabel.append("gradient");
|
||||
} else {
|
||||
inputLabel.appendf("0x%08x", kPaintColors[paintType]);
|
||||
}
|
||||
SkString procLabel;
|
||||
procLabel.printf("Proc: [0x%08x]", kColors[procColor]);
|
||||
|
||||
labelPaint.setStrokeWidth(0);
|
||||
labelPaint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawRect(renderRect, labelPaint);
|
||||
SkRect inputLabelBounds;
|
||||
// get the bounds of the text in order to position it
|
||||
labelFont.measureText(inputLabel.c_str(), inputLabel.size(),
|
||||
SkTextEncoding::kUTF8, &inputLabelBounds);
|
||||
canvas->drawString(inputLabel, renderRect.fRight + kPad, -inputLabelBounds.fTop,
|
||||
labelFont, labelPaint);
|
||||
// update the bounds to reflect the offset we used to draw it.
|
||||
inputLabelBounds.offset(renderRect.fRight + kPad, -inputLabelBounds.fTop);
|
||||
|
||||
canvas->restore();
|
||||
SkRect procLabelBounds;
|
||||
labelFont.measureText(procLabel.c_str(), procLabel.size(),
|
||||
SkTextEncoding::kUTF8, &procLabelBounds);
|
||||
canvas->drawString(procLabel, renderRect.fRight + kPad,
|
||||
inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop,
|
||||
labelFont, labelPaint);
|
||||
procLabelBounds.offset(renderRect.fRight + kPad,
|
||||
inputLabelBounds.fBottom + 2.f - procLabelBounds.fTop);
|
||||
|
||||
// update x and y for the next test case.
|
||||
SkScalar height = renderRect.height();
|
||||
SkScalar width = std::max(inputLabelBounds.fRight, procLabelBounds.fRight);
|
||||
maxW = std::max(maxW, width);
|
||||
y += height + kPad;
|
||||
if (y + height > kHeight) {
|
||||
y = kPad;
|
||||
x += maxW + kPad;
|
||||
maxW = 0;
|
||||
}
|
||||
labelPaint.setStrokeWidth(0);
|
||||
labelPaint.setStyle(SkPaint::kStroke_Style);
|
||||
canvas->drawRect(renderRect, labelPaint);
|
||||
|
||||
canvas->restore();
|
||||
|
||||
// update x and y for the next test case.
|
||||
SkScalar height = renderRect.height();
|
||||
SkScalar width = std::max(inputLabelBounds.fRight, procLabelBounds.fRight);
|
||||
maxW = std::max(maxW, width);
|
||||
y += height + kPad;
|
||||
if (y + height > kHeight) {
|
||||
y = kPad;
|
||||
x += maxW + kPad;
|
||||
maxW = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,6 +211,7 @@ protected:
|
||||
private:
|
||||
// Use this as a way of generating an input FP
|
||||
sk_sp<SkShader> fShader;
|
||||
TestMode fMode;
|
||||
|
||||
static constexpr SkScalar kPad = 10.f;
|
||||
static constexpr SkScalar kRectSize = 20.f;
|
||||
@ -203,5 +221,8 @@ private:
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
DEF_GM(return new ConstColorProcessor;)
|
||||
DEF_GM(return new ColorProcessor{ColorProcessor::TestMode::kConstColor};)
|
||||
DEF_GM(return new ColorProcessor{ColorProcessor::TestMode::kModulateRGBA};)
|
||||
DEF_GM(return new ColorProcessor{ColorProcessor::TestMode::kModulateAlpha};)
|
||||
|
||||
}
|
||||
|
@ -344,6 +344,10 @@ skia_gpu_sources = [
|
||||
"$_src/gpu/effects/generated/GrMagnifierEffect.h",
|
||||
"$_src/gpu/effects/generated/GrMixerEffect.cpp",
|
||||
"$_src/gpu/effects/generated/GrMixerEffect.h",
|
||||
"$_src/gpu/effects/generated/GrModulateAlphaEffect.cpp",
|
||||
"$_src/gpu/effects/generated/GrModulateAlphaEffect.h",
|
||||
"$_src/gpu/effects/generated/GrModulateRGBAEffect.cpp",
|
||||
"$_src/gpu/effects/generated/GrModulateRGBAEffect.h",
|
||||
"$_src/gpu/effects/generated/GrOverrideInputFragmentProcessor.cpp",
|
||||
"$_src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h",
|
||||
"$_src/gpu/effects/generated/GrRGBToHSLFilterEffect.cpp",
|
||||
|
@ -96,6 +96,8 @@ skia_gpu_processor_sources = [
|
||||
"$_src/gpu/effects/GrLumaColorFilterEffect.fp",
|
||||
"$_src/gpu/effects/GrMagnifierEffect.fp",
|
||||
"$_src/gpu/effects/GrMixerEffect.fp",
|
||||
"$_src/gpu/effects/GrModulateAlphaEffect.fp",
|
||||
"$_src/gpu/effects/GrModulateRGBAEffect.fp",
|
||||
"$_src/gpu/effects/GrOverrideInputFragmentProcessor.fp",
|
||||
"$_src/gpu/effects/GrRGBToHSLFilterEffect.fp",
|
||||
"$_src/gpu/effects/GrRRectBlurEffect.fp",
|
||||
|
@ -99,9 +99,7 @@ GrFPResult SkModeColorFilter::asFragmentProcessor(std::unique_ptr<GrFragmentProc
|
||||
|
||||
SkDEBUGCODE(const bool fpHasConstIO = !inputFP || inputFP->hasConstantOutputForConstantInput();)
|
||||
|
||||
auto colorFP = GrConstColorProcessor::Make(
|
||||
/*inputFP=*/nullptr, SkColorToPMColor4f(fColor, dstColorInfo),
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
auto colorFP = GrConstColorProcessor::Make(SkColorToPMColor4f(fColor, dstColorInfo));
|
||||
auto xferFP = GrXfermodeFragmentProcessor::Make(
|
||||
std::move(colorFP), std::move(inputFP), fMode,
|
||||
GrXfermodeFragmentProcessor::ComposeBehavior::kSkModeBehavior);
|
||||
|
@ -348,8 +348,7 @@ sk_sp<SkSpecialImage> ArithmeticImageFilterImpl::filterImageGPU(
|
||||
background->getColorSpace(), background->alphaType(),
|
||||
ctx.colorSpace(), kPremul_SkAlphaType);
|
||||
} else {
|
||||
bgFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
bgFP = GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT);
|
||||
}
|
||||
|
||||
if (foreground) {
|
||||
|
@ -268,8 +268,7 @@ sk_sp<SkSpecialImage> SkXfermodeImageFilterImpl::filterImageGPU(
|
||||
background->alphaType(), ctx.colorSpace(),
|
||||
kPremul_SkAlphaType);
|
||||
} else {
|
||||
fp = GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
fp = GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT);
|
||||
}
|
||||
|
||||
if (foregroundView.asTextureProxy()) {
|
||||
|
@ -431,8 +431,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::RunInSeries(
|
||||
SkPMColor4f knownColor;
|
||||
int leadingFPsToEliminate = info.initialProcessorsToEliminate(&knownColor);
|
||||
if (leadingFPsToEliminate) {
|
||||
std::unique_ptr<GrFragmentProcessor> colorFP = GrConstColorProcessor::Make(
|
||||
/*inputFP=*/nullptr, knownColor, GrConstColorProcessor::InputMode::kIgnore);
|
||||
std::unique_ptr<GrFragmentProcessor> colorFP = GrConstColorProcessor::Make(knownColor);
|
||||
if (leadingFPsToEliminate == cnt) {
|
||||
return colorFP;
|
||||
}
|
||||
|
@ -121,6 +121,8 @@ public:
|
||||
kGrMatrixConvolutionEffect_ClassID,
|
||||
kGrMatrixEffect_ClassID,
|
||||
kGrMeshTestProcessor_ClassID,
|
||||
kGrModulateAlphaEffect_ClassID,
|
||||
kGrModulateRGBAEffect_ClassID,
|
||||
kGrMorphologyEffect_ClassID,
|
||||
kGrMixerEffect_ClassID,
|
||||
kGrOverrideInputFragmentProcessor_ClassID,
|
||||
|
@ -81,7 +81,7 @@ SkTArray<GrXPFactoryTestFactory*, true>* GrXPFactoryTestFactory::GetFactories()
|
||||
* we verify the count is as expected. If a new factory is added, then these numbers must be
|
||||
* manually adjusted.
|
||||
*/
|
||||
static const int kFPFactoryCount = 37;
|
||||
static const int kFPFactoryCount = 39;
|
||||
static const int kGPFactoryCount = 14;
|
||||
static const int kXPFactoryCount = 4;
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include "src/gpu/effects/generated/GrClampFragmentProcessor.h"
|
||||
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
|
||||
#include "src/gpu/effects/generated/GrDitherEffect.h"
|
||||
#include "src/gpu/effects/generated/GrModulateRGBAEffect.h"
|
||||
#include "src/image/SkImage_Base.h"
|
||||
#include "src/shaders/SkShaderBase.h"
|
||||
|
||||
@ -262,9 +263,8 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
|
||||
if (1.0f != paintAlpha) {
|
||||
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
|
||||
// color channels. It's value should be treated as the same in ANY color space.
|
||||
paintFP = GrConstColorProcessor::Make(
|
||||
std::move(paintFP), { paintAlpha, paintAlpha, paintAlpha, paintAlpha },
|
||||
GrConstColorProcessor::InputMode::kModulateRGBA);
|
||||
paintFP = GrModulateRGBAEffect::Make(
|
||||
std::move(paintFP), {paintAlpha, paintAlpha, paintAlpha, paintAlpha});
|
||||
}
|
||||
} else {
|
||||
// The shader's FP sees the paint *unpremul* color
|
||||
@ -276,8 +276,7 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
|
||||
// There is a blend between the primitive color and the paint color. The blend considers
|
||||
// the opaque paint color. The paint's alpha is applied to the post-blended color.
|
||||
SkPMColor4f opaqueColor = origColor.makeOpaque().premul();
|
||||
paintFP = GrConstColorProcessor::Make(/*inputFP=*/nullptr, opaqueColor,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
paintFP = GrConstColorProcessor::Make(opaqueColor);
|
||||
paintFP = GrXfermodeFragmentProcessor::Make(std::move(paintFP), /*dst=*/nullptr,
|
||||
*primColorMode);
|
||||
grPaint->setColor4f(opaqueColor);
|
||||
@ -287,9 +286,8 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
|
||||
if (1.0f != paintAlpha) {
|
||||
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
|
||||
// color channels. It's value should be treated as the same in ANY color space.
|
||||
paintFP = GrConstColorProcessor::Make(
|
||||
std::move(paintFP), { paintAlpha, paintAlpha, paintAlpha, paintAlpha },
|
||||
GrConstColorProcessor::InputMode::kModulateRGBA);
|
||||
paintFP = GrModulateRGBAEffect::Make(
|
||||
std::move(paintFP), {paintAlpha, paintAlpha, paintAlpha, paintAlpha});
|
||||
}
|
||||
} else {
|
||||
// No shader, no primitive color.
|
||||
|
@ -5,68 +5,20 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
enum class InputMode {
|
||||
kIgnore,
|
||||
kModulateRGBA,
|
||||
kModulateA,
|
||||
|
||||
kLast = kModulateA
|
||||
};
|
||||
|
||||
in fragmentProcessor? inputFP;
|
||||
layout(ctype=SkPMColor4f, tracked) in uniform half4 color;
|
||||
layout(key) in InputMode mode;
|
||||
|
||||
@optimizationFlags {
|
||||
(inputFP ? ProcessorOptimizationFlags(inputFP.get()) : kAll_OptimizationFlags) &
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
((mode != InputMode::kIgnore) ? kCompatibleWithCoverageAsAlpha_OptimizationFlag
|
||||
: kNone_OptimizationFlags) |
|
||||
((color.isOpaque()) ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags))
|
||||
(color.isOpaque() ? kPreservesOpaqueInput_OptimizationFlag : kNone_OptimizationFlags))
|
||||
}
|
||||
|
||||
void main() {
|
||||
@switch (mode) {
|
||||
case InputMode::kIgnore: {
|
||||
sk_OutColor = color;
|
||||
break;
|
||||
}
|
||||
case InputMode::kModulateRGBA: {
|
||||
half4 inputColor = sample(inputFP, sk_InColor);
|
||||
sk_OutColor = inputColor * color;
|
||||
break;
|
||||
}
|
||||
case InputMode::kModulateA: {
|
||||
half inputAlpha = sample(inputFP, sk_InColor).a;
|
||||
sk_OutColor = inputAlpha * color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sk_OutColor = color;
|
||||
}
|
||||
|
||||
@class {
|
||||
static const int kInputModeCnt = (int) InputMode::kLast + 1;
|
||||
|
||||
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
|
||||
switch (mode) {
|
||||
case InputMode::kIgnore: {
|
||||
return color;
|
||||
}
|
||||
case InputMode::kModulateA: {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input.fA;
|
||||
}
|
||||
case InputMode::kModulateRGBA: {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input;
|
||||
}
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +42,5 @@ void main() {
|
||||
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
|
||||
break;
|
||||
}
|
||||
InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputModeCnt));
|
||||
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, color, mode);
|
||||
return GrConstColorProcessor::Make(color);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "src/core/SkPathPriv.h"
|
||||
#include "src/gpu/effects/GrConvexPolyEffect.h"
|
||||
#include "src/gpu/effects/generated/GrAARectEffect.h"
|
||||
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
|
||||
#include "src/gpu/effects/generated/GrModulateRGBAEffect.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
|
||||
@ -106,17 +106,13 @@ GrFPResult GrConvexPolyEffect::Make(std::unique_ptr<GrFragmentProcessor> inputFP
|
||||
// skip the draw or omit the clip element.
|
||||
if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) {
|
||||
if (GrProcessorEdgeTypeIsInverseFill(type)) {
|
||||
return GrFPSuccess(
|
||||
GrConstColorProcessor::Make(std::move(inputFP), SK_PMColor4fWHITE,
|
||||
GrConstColorProcessor::InputMode::kModulateRGBA));
|
||||
return GrFPSuccess(GrModulateRGBAEffect::Make(std::move(inputFP), SK_PMColor4fWHITE));
|
||||
}
|
||||
// This could use kIgnore instead of kModulateRGBA but it would trigger a debug print
|
||||
// This could use ConstColor instead of ModulateRGBA but it would trigger a debug print
|
||||
// about a coverage processor not being compatible with the alpha-as-coverage optimization.
|
||||
// We don't really care about this unlikely case so we just use kModulateRGBA to suppress
|
||||
// We don't really care about this unlikely case so we just use ModulateRGBA to suppress
|
||||
// the print.
|
||||
return GrFPSuccess(
|
||||
GrConstColorProcessor::Make(std::move(inputFP), SK_PMColor4fTRANSPARENT,
|
||||
GrConstColorProcessor::InputMode::kModulateRGBA));
|
||||
return GrFPSuccess(GrModulateRGBAEffect::Make(std::move(inputFP), SK_PMColor4fTRANSPARENT));
|
||||
}
|
||||
|
||||
SkScalar edges[3 * kMaxEdges];
|
||||
|
52
src/gpu/effects/GrModulateAlphaEffect.fp
Normal file
52
src/gpu/effects/GrModulateAlphaEffect.fp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
in fragmentProcessor? inputFP;
|
||||
layout(ctype=SkPMColor4f, tracked) in uniform half4 color;
|
||||
|
||||
@optimizationFlags {
|
||||
(inputFP ? ProcessorOptimizationFlags(inputFP.get()) : kAll_OptimizationFlags) &
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(color.isOpaque() ? kPreservesOpaqueInput_OptimizationFlag : kNone_OptimizationFlags))
|
||||
}
|
||||
|
||||
void main() {
|
||||
sk_OutColor = color * sample(inputFP, sk_InColor).a;
|
||||
}
|
||||
|
||||
@class {
|
||||
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input.fA;
|
||||
}
|
||||
}
|
||||
|
||||
@test(d) {
|
||||
SkPMColor4f color;
|
||||
int colorPicker = d->fRandom->nextULessThan(3);
|
||||
switch (colorPicker) {
|
||||
case 0: {
|
||||
uint32_t a = d->fRandom->nextULessThan(0x100);
|
||||
uint32_t r = d->fRandom->nextULessThan(a+1);
|
||||
uint32_t g = d->fRandom->nextULessThan(a+1);
|
||||
uint32_t b = d->fRandom->nextULessThan(a+1);
|
||||
color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
color = SK_PMColor4fTRANSPARENT;
|
||||
break;
|
||||
case 2:
|
||||
uint32_t c = d->fRandom->nextULessThan(0x100);
|
||||
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
|
||||
break;
|
||||
}
|
||||
return GrModulateAlphaEffect::Make(/*inputFP=*/nullptr, color);
|
||||
}
|
52
src/gpu/effects/GrModulateRGBAEffect.fp
Normal file
52
src/gpu/effects/GrModulateRGBAEffect.fp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
in fragmentProcessor? inputFP;
|
||||
layout(ctype=SkPMColor4f, tracked) in uniform half4 color;
|
||||
|
||||
@optimizationFlags {
|
||||
(inputFP ? ProcessorOptimizationFlags(inputFP.get()) : kAll_OptimizationFlags) &
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(color.isOpaque() ? kPreservesOpaqueInput_OptimizationFlag : kNone_OptimizationFlags))
|
||||
}
|
||||
|
||||
void main() {
|
||||
sk_OutColor = color * sample(inputFP, sk_InColor);
|
||||
}
|
||||
|
||||
@class {
|
||||
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input;
|
||||
}
|
||||
}
|
||||
|
||||
@test(d) {
|
||||
SkPMColor4f color;
|
||||
int colorPicker = d->fRandom->nextULessThan(3);
|
||||
switch (colorPicker) {
|
||||
case 0: {
|
||||
uint32_t a = d->fRandom->nextULessThan(0x100);
|
||||
uint32_t r = d->fRandom->nextULessThan(a+1);
|
||||
uint32_t g = d->fRandom->nextULessThan(a+1);
|
||||
uint32_t b = d->fRandom->nextULessThan(a+1);
|
||||
color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
color = SK_PMColor4fTRANSPARENT;
|
||||
break;
|
||||
case 2:
|
||||
uint32_t c = d->fRandom->nextULessThan(0x100);
|
||||
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
|
||||
break;
|
||||
}
|
||||
return GrModulateRGBAEffect::Make(/*inputFP=*/nullptr, color);
|
||||
}
|
@ -339,8 +339,7 @@ std::unique_ptr<GrFragmentProcessor> GrXfermodeFragmentProcessor::Make(
|
||||
SkBlendMode mode, ComposeBehavior behavior) {
|
||||
switch (mode) {
|
||||
case SkBlendMode::kClear:
|
||||
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT);
|
||||
case SkBlendMode::kSrc:
|
||||
return GrFragmentProcessor::OverrideInput(std::move(src), SK_PMColor4fWHITE,
|
||||
/*useUniform=*/false);
|
||||
|
@ -25,55 +25,12 @@ public:
|
||||
(void)_outer;
|
||||
auto color = _outer.color;
|
||||
(void)color;
|
||||
auto mode = _outer.mode;
|
||||
(void)mode;
|
||||
colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
|
||||
kHalf4_GrSLType, "color");
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(@switch (%d) {
|
||||
case 0:
|
||||
{
|
||||
%s = %s;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{)SkSL",
|
||||
(int)_outer.mode, args.fOutputColor,
|
||||
args.fUniformHandler->getUniformCStr(colorVar));
|
||||
SkString _input1009(args.fInputColor);
|
||||
SkString _sample1009;
|
||||
if (_outer.inputFP_index >= 0) {
|
||||
_sample1009 = this->invokeChild(_outer.inputFP_index, _input1009.c_str(), args);
|
||||
} else {
|
||||
_sample1009.swap(_input1009);
|
||||
}
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(
|
||||
half4 inputColor = %s;
|
||||
%s = inputColor * %s;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{)SkSL",
|
||||
_sample1009.c_str(), args.fOutputColor,
|
||||
args.fUniformHandler->getUniformCStr(colorVar));
|
||||
SkString _input1181(args.fInputColor);
|
||||
SkString _sample1181;
|
||||
if (_outer.inputFP_index >= 0) {
|
||||
_sample1181 = this->invokeChild(_outer.inputFP_index, _input1181.c_str(), args);
|
||||
} else {
|
||||
_sample1181.swap(_input1181);
|
||||
}
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(
|
||||
half inputAlpha = %s.w;
|
||||
%s = inputAlpha * %s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
R"SkSL(%s = %s;
|
||||
)SkSL",
|
||||
_sample1181.c_str(), args.fOutputColor,
|
||||
args.fUniformHandler->getUniformCStr(colorVar));
|
||||
args.fOutputColor, args.fUniformHandler->getUniformCStr(colorVar));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -95,24 +52,15 @@ GrGLSLFragmentProcessor* GrConstColorProcessor::onCreateGLSLInstance() const {
|
||||
return new GrGLSLConstColorProcessor();
|
||||
}
|
||||
void GrConstColorProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const {
|
||||
b->add32((int32_t)mode);
|
||||
}
|
||||
GrProcessorKeyBuilder* b) const {}
|
||||
bool GrConstColorProcessor::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrConstColorProcessor& that = other.cast<GrConstColorProcessor>();
|
||||
(void)that;
|
||||
if (color != that.color) return false;
|
||||
if (mode != that.mode) return false;
|
||||
return true;
|
||||
}
|
||||
GrConstColorProcessor::GrConstColorProcessor(const GrConstColorProcessor& src)
|
||||
: INHERITED(kGrConstColorProcessor_ClassID, src.optimizationFlags())
|
||||
, color(src.color)
|
||||
, mode(src.mode) {
|
||||
if (src.inputFP_index >= 0) {
|
||||
inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index));
|
||||
}
|
||||
}
|
||||
: INHERITED(kGrConstColorProcessor_ClassID, src.optimizationFlags()), color(src.color) {}
|
||||
std::unique_ptr<GrFragmentProcessor> GrConstColorProcessor::clone() const {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrConstColorProcessor(*this));
|
||||
}
|
||||
@ -138,7 +86,6 @@ std::unique_ptr<GrFragmentProcessor> GrConstColorProcessor::TestCreate(GrProcess
|
||||
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
|
||||
break;
|
||||
}
|
||||
InputMode mode = static_cast<InputMode>(d->fRandom->nextULessThan(kInputModeCnt));
|
||||
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, color, mode);
|
||||
return GrConstColorProcessor::Make(color);
|
||||
}
|
||||
#endif
|
||||
|
@ -18,62 +18,25 @@
|
||||
|
||||
class GrConstColorProcessor : public GrFragmentProcessor {
|
||||
public:
|
||||
enum class InputMode { kIgnore = 0, kLast = 2, kModulateA = 2, kModulateRGBA = 1 };
|
||||
|
||||
static const int kInputModeCnt = (int)InputMode::kLast + 1;
|
||||
|
||||
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
|
||||
switch (mode) {
|
||||
case InputMode::kIgnore: {
|
||||
return color;
|
||||
}
|
||||
case InputMode::kModulateA: {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(
|
||||
this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input.fA;
|
||||
}
|
||||
case InputMode::kModulateRGBA: {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(
|
||||
this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input;
|
||||
}
|
||||
}
|
||||
SkUNREACHABLE;
|
||||
return color;
|
||||
}
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
SkPMColor4f color,
|
||||
InputMode mode) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(
|
||||
new GrConstColorProcessor(std::move(inputFP), color, mode));
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(SkPMColor4f color) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrConstColorProcessor(color));
|
||||
}
|
||||
GrConstColorProcessor(const GrConstColorProcessor& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "ConstColorProcessor"; }
|
||||
int inputFP_index = -1;
|
||||
SkPMColor4f color;
|
||||
InputMode mode;
|
||||
|
||||
private:
|
||||
GrConstColorProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
SkPMColor4f color,
|
||||
InputMode mode)
|
||||
: INHERITED(kGrConstColorProcessor_ClassID,
|
||||
(OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get())
|
||||
: kAll_OptimizationFlags) &
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
((mode != InputMode::kIgnore)
|
||||
? kCompatibleWithCoverageAsAlpha_OptimizationFlag
|
||||
: kNone_OptimizationFlags) |
|
||||
((color.isOpaque()) ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)))
|
||||
, color(color)
|
||||
, mode(mode) {
|
||||
inputFP_index = this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
|
||||
}
|
||||
GrConstColorProcessor(SkPMColor4f color)
|
||||
: INHERITED(
|
||||
kGrConstColorProcessor_ClassID,
|
||||
(OptimizationFlags)(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
(color.isOpaque() ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)))
|
||||
, color(color) {}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
|
103
src/gpu/effects/generated/GrModulateAlphaEffect.cpp
Normal file
103
src/gpu/effects/generated/GrModulateAlphaEffect.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrModulateAlphaEffect.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#include "GrModulateAlphaEffect.h"
|
||||
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
||||
#include "src/sksl/SkSLCPP.h"
|
||||
#include "src/sksl/SkSLUtil.h"
|
||||
class GrGLSLModulateAlphaEffect : public GrGLSLFragmentProcessor {
|
||||
public:
|
||||
GrGLSLModulateAlphaEffect() {}
|
||||
void emitCode(EmitArgs& args) override {
|
||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||
const GrModulateAlphaEffect& _outer = args.fFp.cast<GrModulateAlphaEffect>();
|
||||
(void)_outer;
|
||||
auto color = _outer.color;
|
||||
(void)color;
|
||||
colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
|
||||
kHalf4_GrSLType, "color");
|
||||
SkString _input618(args.fInputColor);
|
||||
SkString _sample618;
|
||||
if (_outer.inputFP_index >= 0) {
|
||||
_sample618 = this->invokeChild(_outer.inputFP_index, _input618.c_str(), args);
|
||||
} else {
|
||||
_sample618.swap(_input618);
|
||||
}
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(%s = %s * %s.w;
|
||||
)SkSL",
|
||||
args.fOutputColor, args.fUniformHandler->getUniformCStr(colorVar),
|
||||
_sample618.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrModulateAlphaEffect& _outer = _proc.cast<GrModulateAlphaEffect>();
|
||||
{
|
||||
const SkPMColor4f& colorValue = _outer.color;
|
||||
if (colorPrev != colorValue) {
|
||||
colorPrev = colorValue;
|
||||
pdman.set4fv(colorVar, 1, colorValue.vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
|
||||
UniformHandle colorVar;
|
||||
};
|
||||
GrGLSLFragmentProcessor* GrModulateAlphaEffect::onCreateGLSLInstance() const {
|
||||
return new GrGLSLModulateAlphaEffect();
|
||||
}
|
||||
void GrModulateAlphaEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const {}
|
||||
bool GrModulateAlphaEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrModulateAlphaEffect& that = other.cast<GrModulateAlphaEffect>();
|
||||
(void)that;
|
||||
if (color != that.color) return false;
|
||||
return true;
|
||||
}
|
||||
GrModulateAlphaEffect::GrModulateAlphaEffect(const GrModulateAlphaEffect& src)
|
||||
: INHERITED(kGrModulateAlphaEffect_ClassID, src.optimizationFlags()), color(src.color) {
|
||||
if (src.inputFP_index >= 0) {
|
||||
inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index));
|
||||
}
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrModulateAlphaEffect::clone() const {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrModulateAlphaEffect(*this));
|
||||
}
|
||||
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrModulateAlphaEffect);
|
||||
#if GR_TEST_UTILS
|
||||
std::unique_ptr<GrFragmentProcessor> GrModulateAlphaEffect::TestCreate(GrProcessorTestData* d) {
|
||||
SkPMColor4f color;
|
||||
int colorPicker = d->fRandom->nextULessThan(3);
|
||||
switch (colorPicker) {
|
||||
case 0: {
|
||||
uint32_t a = d->fRandom->nextULessThan(0x100);
|
||||
uint32_t r = d->fRandom->nextULessThan(a + 1);
|
||||
uint32_t g = d->fRandom->nextULessThan(a + 1);
|
||||
uint32_t b = d->fRandom->nextULessThan(a + 1);
|
||||
color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
color = SK_PMColor4fTRANSPARENT;
|
||||
break;
|
||||
case 2:
|
||||
uint32_t c = d->fRandom->nextULessThan(0x100);
|
||||
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
|
||||
break;
|
||||
}
|
||||
return GrModulateAlphaEffect::Make(/*inputFP=*/nullptr, color);
|
||||
}
|
||||
#endif
|
57
src/gpu/effects/generated/GrModulateAlphaEffect.h
Normal file
57
src/gpu/effects/generated/GrModulateAlphaEffect.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrModulateAlphaEffect.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#ifndef GrModulateAlphaEffect_DEFINED
|
||||
#define GrModulateAlphaEffect_DEFINED
|
||||
|
||||
#include "include/core/SkM44.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
#include "src/gpu/GrFragmentProcessor.h"
|
||||
|
||||
class GrModulateAlphaEffect : public GrFragmentProcessor {
|
||||
public:
|
||||
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(
|
||||
this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input.fA;
|
||||
}
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
SkPMColor4f color) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(
|
||||
new GrModulateAlphaEffect(std::move(inputFP), color));
|
||||
}
|
||||
GrModulateAlphaEffect(const GrModulateAlphaEffect& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "ModulateAlphaEffect"; }
|
||||
int inputFP_index = -1;
|
||||
SkPMColor4f color;
|
||||
|
||||
private:
|
||||
GrModulateAlphaEffect(std::unique_ptr<GrFragmentProcessor> inputFP, SkPMColor4f color)
|
||||
: INHERITED(kGrModulateAlphaEffect_ClassID,
|
||||
(OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get())
|
||||
: kAll_OptimizationFlags) &
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(color.isOpaque() ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)))
|
||||
, color(color) {
|
||||
inputFP_index = this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
};
|
||||
#endif
|
103
src/gpu/effects/generated/GrModulateRGBAEffect.cpp
Normal file
103
src/gpu/effects/generated/GrModulateRGBAEffect.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrModulateRGBAEffect.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#include "GrModulateRGBAEffect.h"
|
||||
|
||||
#include "src/gpu/GrTexture.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
|
||||
#include "src/sksl/SkSLCPP.h"
|
||||
#include "src/sksl/SkSLUtil.h"
|
||||
class GrGLSLModulateRGBAEffect : public GrGLSLFragmentProcessor {
|
||||
public:
|
||||
GrGLSLModulateRGBAEffect() {}
|
||||
void emitCode(EmitArgs& args) override {
|
||||
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
|
||||
const GrModulateRGBAEffect& _outer = args.fFp.cast<GrModulateRGBAEffect>();
|
||||
(void)_outer;
|
||||
auto color = _outer.color;
|
||||
(void)color;
|
||||
colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
|
||||
kHalf4_GrSLType, "color");
|
||||
SkString _input618(args.fInputColor);
|
||||
SkString _sample618;
|
||||
if (_outer.inputFP_index >= 0) {
|
||||
_sample618 = this->invokeChild(_outer.inputFP_index, _input618.c_str(), args);
|
||||
} else {
|
||||
_sample618.swap(_input618);
|
||||
}
|
||||
fragBuilder->codeAppendf(
|
||||
R"SkSL(%s = %s * %s;
|
||||
)SkSL",
|
||||
args.fOutputColor, args.fUniformHandler->getUniformCStr(colorVar),
|
||||
_sample618.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
void onSetData(const GrGLSLProgramDataManager& pdman,
|
||||
const GrFragmentProcessor& _proc) override {
|
||||
const GrModulateRGBAEffect& _outer = _proc.cast<GrModulateRGBAEffect>();
|
||||
{
|
||||
const SkPMColor4f& colorValue = _outer.color;
|
||||
if (colorPrev != colorValue) {
|
||||
colorPrev = colorValue;
|
||||
pdman.set4fv(colorVar, 1, colorValue.vec());
|
||||
}
|
||||
}
|
||||
}
|
||||
SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN};
|
||||
UniformHandle colorVar;
|
||||
};
|
||||
GrGLSLFragmentProcessor* GrModulateRGBAEffect::onCreateGLSLInstance() const {
|
||||
return new GrGLSLModulateRGBAEffect();
|
||||
}
|
||||
void GrModulateRGBAEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
|
||||
GrProcessorKeyBuilder* b) const {}
|
||||
bool GrModulateRGBAEffect::onIsEqual(const GrFragmentProcessor& other) const {
|
||||
const GrModulateRGBAEffect& that = other.cast<GrModulateRGBAEffect>();
|
||||
(void)that;
|
||||
if (color != that.color) return false;
|
||||
return true;
|
||||
}
|
||||
GrModulateRGBAEffect::GrModulateRGBAEffect(const GrModulateRGBAEffect& src)
|
||||
: INHERITED(kGrModulateRGBAEffect_ClassID, src.optimizationFlags()), color(src.color) {
|
||||
if (src.inputFP_index >= 0) {
|
||||
inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index));
|
||||
}
|
||||
}
|
||||
std::unique_ptr<GrFragmentProcessor> GrModulateRGBAEffect::clone() const {
|
||||
return std::unique_ptr<GrFragmentProcessor>(new GrModulateRGBAEffect(*this));
|
||||
}
|
||||
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrModulateRGBAEffect);
|
||||
#if GR_TEST_UTILS
|
||||
std::unique_ptr<GrFragmentProcessor> GrModulateRGBAEffect::TestCreate(GrProcessorTestData* d) {
|
||||
SkPMColor4f color;
|
||||
int colorPicker = d->fRandom->nextULessThan(3);
|
||||
switch (colorPicker) {
|
||||
case 0: {
|
||||
uint32_t a = d->fRandom->nextULessThan(0x100);
|
||||
uint32_t r = d->fRandom->nextULessThan(a + 1);
|
||||
uint32_t g = d->fRandom->nextULessThan(a + 1);
|
||||
uint32_t b = d->fRandom->nextULessThan(a + 1);
|
||||
color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a));
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
color = SK_PMColor4fTRANSPARENT;
|
||||
break;
|
||||
case 2:
|
||||
uint32_t c = d->fRandom->nextULessThan(0x100);
|
||||
color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24));
|
||||
break;
|
||||
}
|
||||
return GrModulateRGBAEffect::Make(/*inputFP=*/nullptr, color);
|
||||
}
|
||||
#endif
|
57
src/gpu/effects/generated/GrModulateRGBAEffect.h
Normal file
57
src/gpu/effects/generated/GrModulateRGBAEffect.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
/**************************************************************************************************
|
||||
*** This file was autogenerated from GrModulateRGBAEffect.fp; do not modify.
|
||||
**************************************************************************************************/
|
||||
#ifndef GrModulateRGBAEffect_DEFINED
|
||||
#define GrModulateRGBAEffect_DEFINED
|
||||
|
||||
#include "include/core/SkM44.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
#include "src/gpu/GrFragmentProcessor.h"
|
||||
|
||||
class GrModulateRGBAEffect : public GrFragmentProcessor {
|
||||
public:
|
||||
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
|
||||
SkPMColor4f input = this->numChildProcessors()
|
||||
? ConstantOutputForConstantInput(
|
||||
this->childProcessor(inputFP_index), inColor)
|
||||
: inColor;
|
||||
return color * input;
|
||||
}
|
||||
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
|
||||
SkPMColor4f color) {
|
||||
return std::unique_ptr<GrFragmentProcessor>(
|
||||
new GrModulateRGBAEffect(std::move(inputFP), color));
|
||||
}
|
||||
GrModulateRGBAEffect(const GrModulateRGBAEffect& src);
|
||||
std::unique_ptr<GrFragmentProcessor> clone() const override;
|
||||
const char* name() const override { return "ModulateRGBAEffect"; }
|
||||
int inputFP_index = -1;
|
||||
SkPMColor4f color;
|
||||
|
||||
private:
|
||||
GrModulateRGBAEffect(std::unique_ptr<GrFragmentProcessor> inputFP, SkPMColor4f color)
|
||||
: INHERITED(kGrModulateRGBAEffect_ClassID,
|
||||
(OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get())
|
||||
: kAll_OptimizationFlags) &
|
||||
(kConstantOutputForConstantInput_OptimizationFlag |
|
||||
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
|
||||
(color.isOpaque() ? kPreservesOpaqueInput_OptimizationFlag
|
||||
: kNone_OptimizationFlags)))
|
||||
, color(color) {
|
||||
inputFP_index = this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
|
||||
}
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
bool onIsEqual(const GrFragmentProcessor&) const override;
|
||||
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
|
||||
typedef GrFragmentProcessor INHERITED;
|
||||
};
|
||||
#endif
|
@ -115,13 +115,12 @@ skvm::Color SkColor4Shader::onProgram(skvm::Builder* p,
|
||||
#include "src/gpu/GrColorInfo.h"
|
||||
#include "src/gpu/GrColorSpaceXform.h"
|
||||
#include "src/gpu/SkGr.h"
|
||||
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
|
||||
#include "src/gpu/effects/generated/GrModulateAlphaEffect.h"
|
||||
|
||||
std::unique_ptr<GrFragmentProcessor> SkColorShader::asFragmentProcessor(
|
||||
const GrFPArgs& args) const {
|
||||
SkPMColor4f color = SkColorToPMColor4f(fColor, *args.fDstColorInfo);
|
||||
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, color,
|
||||
GrConstColorProcessor::InputMode::kModulateA);
|
||||
return GrModulateAlphaEffect::Make(/*inputFP=*/nullptr, color);
|
||||
}
|
||||
|
||||
std::unique_ptr<GrFragmentProcessor> SkColor4Shader::asFragmentProcessor(
|
||||
@ -130,8 +129,7 @@ std::unique_ptr<GrFragmentProcessor> SkColor4Shader::asFragmentProcessor(
|
||||
args.fDstColorInfo->colorSpace(), kUnpremul_SkAlphaType };
|
||||
SkColor4f color = fColor;
|
||||
steps.apply(color.vec());
|
||||
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, color.premul(),
|
||||
GrConstColorProcessor::InputMode::kModulateA);
|
||||
return GrModulateAlphaEffect::Make(/*inputFP=*/nullptr, color.premul());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "src/gpu/effects/GrMatrixEffect.h"
|
||||
#include "src/gpu/effects/GrTextureEffect.h"
|
||||
#include "src/gpu/effects/generated/GrConstColorProcessor.h"
|
||||
#include "src/gpu/effects/generated/GrModulateRGBAEffect.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
|
||||
@ -1386,14 +1387,12 @@ std::unique_ptr<GrFragmentProcessor> SkPerlinNoiseShaderImpl::asFragmentProcesso
|
||||
// TODO: Either treat the output of this shader as sRGB or allow client to specify a
|
||||
// color space of the noise. Either way, this case (and the GLSL) need to convert to
|
||||
// the destination.
|
||||
auto inner = GrConstColorProcessor::Make(
|
||||
/*inputFP=*/nullptr, SkPMColor4f::FromBytes_RGBA(0x80404040),
|
||||
GrConstColorProcessor::InputMode::kModulateRGBA);
|
||||
auto inner = GrModulateRGBAEffect::Make(
|
||||
/*inputFP=*/nullptr, SkPMColor4f::FromBytes_RGBA(0x80404040));
|
||||
return GrFragmentProcessor::MulChildByInputAlpha(std::move(inner));
|
||||
}
|
||||
// Emit zero.
|
||||
return GrConstColorProcessor::Make(/*inputFP=*/nullptr, SK_PMColor4fTRANSPARENT,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
return GrConstColorProcessor::Make(SK_PMColor4fTRANSPARENT);
|
||||
}
|
||||
|
||||
// Need to assert that the textures we'll create are power of 2 so that now copy is needed. We
|
||||
|
@ -92,8 +92,7 @@ static void run_test(GrContext* ctx, skiatest::Reporter* reporter) {
|
||||
GrPaint paint;
|
||||
|
||||
const SkPMColor4f color = { 1.0f, 0.0f, 0.0f, 1.0f };
|
||||
auto fp = GrConstColorProcessor::Make(/*inputFP=*/nullptr, color,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
auto fp = GrConstColorProcessor::Make(color);
|
||||
paint.addColorFragmentProcessor(std::move(fp));
|
||||
|
||||
rtc->drawPath(nullptr, std::move(paint), GrAA::kNo,
|
||||
@ -111,8 +110,7 @@ static void run_test(GrContext* ctx, skiatest::Reporter* reporter) {
|
||||
GrPaint paint;
|
||||
|
||||
const SkPMColor4f color = { 0.0f, 1.0f, 0.0f, 1.0f };
|
||||
auto fp = GrConstColorProcessor::Make(/*inputFP=*/nullptr, color,
|
||||
GrConstColorProcessor::InputMode::kIgnore);
|
||||
auto fp = GrConstColorProcessor::Make(color);
|
||||
paint.addColorFragmentProcessor(std::move(fp));
|
||||
|
||||
rtc->drawPath(nullptr, std::move(paint), GrAA::kNo,
|
||||
|
Loading…
Reference in New Issue
Block a user