Start adding unit tests of SkRuntimeEffect
- Change SkRuntimeEffect::Make so *it* can fail, and returns
[Effect, ErrorText].
- Initial tests just test for expected failure conditions.
Next steps are to add tests for effects that should work,
and to validate results on CPU and GPU.
Change-Id: Ibac8c3046104577434034263e9e4a4b177e89129
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/261095
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 86f811a..5a69649 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -469,8 +469,8 @@
grPaint->numColorFragmentProcessors() > 0) {
int32_t ditherRange = dither_range_type_for_config(ct);
if (ditherRange >= 0) {
- static auto ditherEffect = SkRuntimeEffect::Make(SkString(SKSL_DITHER_SRC));
- auto ditherFP = GrSkSLFP::Make(context, ditherEffect, "Dither",
+ static auto effect = std::get<0>(SkRuntimeEffect::Make(SkString(SKSL_DITHER_SRC)));
+ auto ditherFP = GrSkSLFP::Make(context, effect, "Dither",
&ditherRange, sizeof(ditherRange));
if (ditherFP) {
grPaint->addColorFragmentProcessor(std::move(ditherFP));
diff --git a/src/gpu/effects/GrSkSLFP.cpp b/src/gpu/effects/GrSkSLFP.cpp
index 708a5c1..e269fc7 100644
--- a/src/gpu/effects/GrSkSLFP.cpp
+++ b/src/gpu/effects/GrSkSLFP.cpp
@@ -284,21 +284,21 @@
int type = d->fRandom->nextULessThan(3);
switch (type) {
case 0: {
- static auto ditherEffect = SkRuntimeEffect::Make(SkString(SKSL_DITHER_SRC));
+ static auto effect = std::get<0>(SkRuntimeEffect::Make(SkString(SKSL_DITHER_SRC)));
int rangeType = d->fRandom->nextULessThan(3);
- auto result = GrSkSLFP::Make(d->context(), ditherEffect, "Dither",
+ auto result = GrSkSLFP::Make(d->context(), effect, "Dither",
&rangeType, sizeof(rangeType));
return std::unique_ptr<GrFragmentProcessor>(result.release());
}
case 1: {
- static auto arithmeticEffect = SkRuntimeEffect::Make(SkString(SKSL_ARITHMETIC_SRC));
+ static auto effect = std::get<0>(SkRuntimeEffect::Make(SkString(SKSL_ARITHMETIC_SRC)));
ArithmeticFPInputs inputs;
inputs.k[0] = d->fRandom->nextF();
inputs.k[1] = d->fRandom->nextF();
inputs.k[2] = d->fRandom->nextF();
inputs.k[3] = d->fRandom->nextF();
inputs.enforcePMColor = d->fRandom->nextBool();
- auto result = GrSkSLFP::Make(d->context(), arithmeticEffect, "Arithmetic",
+ auto result = GrSkSLFP::Make(d->context(), effect, "Arithmetic",
&inputs, sizeof(inputs));
result->addChild(GrConstColorProcessor::Make(
SK_PMColor4fWHITE,
@@ -306,12 +306,12 @@
return std::unique_ptr<GrFragmentProcessor>(result.release());
}
case 2: {
- static auto overdrawEffect = SkRuntimeEffect::Make(SkString(SKSL_OVERDRAW_SRC));
+ static auto effect = std::get<0>(SkRuntimeEffect::Make(SkString(SKSL_OVERDRAW_SRC)));
SkColor4f inputs[6];
for (int i = 0; i < 6; ++i) {
inputs[i] = SkColor4f::FromBytes_RGBA(d->fRandom->nextU());
}
- auto result = GrSkSLFP::Make(d->context(), overdrawEffect, "Overdraw",
+ auto result = GrSkSLFP::Make(d->context(), effect, "Overdraw",
&inputs, sizeof(inputs));
return std::unique_ptr<GrFragmentProcessor>(result.release());
}