Migrate color filter flag into SkRuntimeEffect.
The alpha-unchanged flag previously lived in SkFilterColorProgram,
but in SkRP we won't use SkFilterColorProgram. There wasn't any
benefit to keeping the flag in the helper class, so it's now a flag
in SkRuntimeEffect proper.
Change-Id: I84b2ba6dd9ab896ccdcd737d236f7159c98dbb47
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/670343
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/include/effects/SkRuntimeEffect.h b/include/effects/SkRuntimeEffect.h
index ef4fa11..4d3450e 100644
--- a/include/effects/SkRuntimeEffect.h
+++ b/include/effects/SkRuntimeEffect.h
@@ -283,6 +283,7 @@
kSamplesOutsideMain_Flag = 0x10,
kUsesColorTransform_Flag = 0x20,
kAlwaysOpaque_Flag = 0x40,
+ kAlphaUnchanged_Flag = 0x80,
};
SkRuntimeEffect(std::unique_ptr<SkSL::Program> baseProgram,
@@ -308,6 +309,7 @@
bool samplesOutsideMain() const { return (fFlags & kSamplesOutsideMain_Flag); }
bool usesColorTransform() const { return (fFlags & kUsesColorTransform_Flag); }
bool alwaysOpaque() const { return (fFlags & kAlwaysOpaque_Flag); }
+ bool isAlphaUnchanged() const { return (fFlags & kAlphaUnchanged_Flag); }
const SkFilterColorProgram* getFilterColorProgram() const;
const SkSL::RP::Program* getRPProgram(SkSL::DebugTracePriv* debugTrace) const;
diff --git a/src/core/SkRuntimeEffect.cpp b/src/core/SkRuntimeEffect.cpp
index eca0f07..829c3d3 100644
--- a/src/core/SkRuntimeEffect.cpp
+++ b/src/core/SkRuntimeEffect.cpp
@@ -549,6 +549,15 @@
flags |= kSamplesOutsideMain_Flag;
}
+ // Look for color filters that preserve the input alpha. This analysis is very conservative, and
+ // only returns true when the input alpha is returned as-is from main() with no intervening
+ // copies or arithmetic.
+ if (flags & kAllowColorFilter_Flag) {
+ if (SkSL::Analysis::ReturnsInputAlpha(*main->definition(), *program->usage())) {
+ flags |= kAlphaUnchanged_Flag;
+ }
+ }
+
// Determine if this effect uses of the color transform intrinsics. Effects need to know this
// so they can allocate color transform objects, etc.
if (SkSL::Analysis::CallsColorTransformIntrinsics(*program)) {
@@ -978,24 +987,16 @@
return nullptr;
}
- // This is very conservative, and only returns true when the input alpha is returned as-is
- // from main() with no intervening copies or arithmetic.
- bool alphaUnchanged = SkSL::Analysis::ReturnsInputAlpha(effect->fMain,
- *effect->fBaseProgram->usage());
-
// We'll use this program to filter one color at a time, don't bother with jit
return std::unique_ptr<SkFilterColorProgram>(
new SkFilterColorProgram(p.done(/*debug_name=*/nullptr, /*allow_jit=*/false),
- std::move(sampleCalls),
- alphaUnchanged));
+ std::move(sampleCalls)));
}
SkFilterColorProgram::SkFilterColorProgram(skvm::Program program,
- std::vector<SampleCall> sampleCalls,
- bool alphaUnchanged)
+ std::vector<SampleCall> sampleCalls)
: fProgram(std::move(program))
- , fSampleCalls(std::move(sampleCalls))
- , fAlphaUnchanged(alphaUnchanged) {}
+ , fSampleCalls(std::move(sampleCalls)) {}
SkPMColor4f SkFilterColorProgram::eval(
const SkPMColor4f& inColor,
@@ -1347,7 +1348,7 @@
bool onIsAlphaUnchanged() const override {
return fEffect->getFilterColorProgram() &&
- fEffect->getFilterColorProgram()->isAlphaUnchanged();
+ fEffect->isAlphaUnchanged();
}
void flatten(SkWriteBuffer& buffer) const override {
diff --git a/src/core/SkRuntimeEffectPriv.h b/src/core/SkRuntimeEffectPriv.h
index 46264ad..557c526 100644
--- a/src/core/SkRuntimeEffectPriv.h
+++ b/src/core/SkRuntimeEffectPriv.h
@@ -142,8 +142,6 @@
const void* uniformData,
std::function<SkPMColor4f(int, SkPMColor4f)> evalChild) const;
- bool isAlphaUnchanged() const { return fAlphaUnchanged; }
-
private:
struct SampleCall {
enum class Kind {
@@ -162,13 +160,10 @@
};
};
- SkFilterColorProgram(skvm::Program program,
- std::vector<SampleCall> sampleCalls,
- bool alphaUnchanged);
+ SkFilterColorProgram(skvm::Program program, std::vector<SampleCall> sampleCalls);
skvm::Program fProgram;
std::vector<SampleCall> fSampleCalls;
- bool fAlphaUnchanged;
};
#endif // SK_ENABLE_SKSL