Reland "Add SkRuntimeBlender class."
This is a reland of 6034941cc28a28a7c9fc79d6cb815fed188cdfb6
Original change's description:
> Add SkRuntimeBlender class.
>
> This class is returned by SkRuntimeEffect::makeBlender when a runtime
> blend is returned. SkRuntimeBlendBuilder is also added as a convenience
> class to simplify creation and uniform setup.
>
> Our ability to add tests is limited in this CL because the SkPaint does
> not contain an SkBlender yet. We do have one test which builds an
> SkBlender, but there's not much we can do with it. Testing will be
> bulked up in the next CL.
>
> Change-Id: Ib2d7d04186690ec0d2238fc990a19d9e6b786ce3
> Bug: skia:12080
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/417006
> Commit-Queue: John Stiles <johnstiles@google.com>
> Auto-Submit: John Stiles <johnstiles@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
Bug: skia:12080
Change-Id: Ie41be141ba3787452f9d5c72946ebc748a5d6176
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419160
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index c2e24ff..69d4579 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -6,6 +6,7 @@
*/
#include "include/core/SkBitmap.h"
+#include "include/core/SkBlender.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkData.h"
@@ -329,7 +330,7 @@
void test(GrColor TL, GrColor TR, GrColor BL, GrColor BR,
PreTestFn preTestCallback = nullptr) {
- auto shader = fBuilder->makeShader(nullptr, false);
+ auto shader = fBuilder->makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/false);
if (!shader) {
REPORT_FAILURE(fReporter, "shader", SkString("Effect didn't produce a shader"));
return;
@@ -499,10 +500,27 @@
// Test passes if this sequence doesn't assert. skbug.com/10667
SkRuntimeShaderBuilder b(std::move(effect));
b.uniform("x") = 0.0f;
- auto shader_0 = b.makeShader(nullptr, false);
+ auto shader_0 = b.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/false);
b.uniform("x") = 1.0f;
- auto shader_1 = b.makeShader(nullptr, true);
+ auto shader_1 = b.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/true);
+}
+
+DEF_TEST(SkRuntimeBlendBuilderReuse, r) {
+ const char* kSource = R"(
+ uniform half x;
+ half4 main(half4 s, half4 d) { return half4(x); }
+ )";
+
+ sk_sp<SkRuntimeEffect> effect = SkRuntimeEffect::MakeForBlender(SkString(kSource)).effect;
+ REPORTER_ASSERT(r, effect);
+
+ // We should be able to construct multiple SkBlenders in a row without asserting.
+ SkRuntimeBlendBuilder b(std::move(effect));
+ for (float x = 0.0f; x <= 2.0f; x += 2.0f) {
+ b.uniform("x") = x;
+ sk_sp<SkBlender> blender = b.makeBlender();
+ }
}
DEF_TEST(SkRuntimeShaderBuilderSetUniforms, r) {
@@ -530,8 +548,7 @@
REPORTER_ASSERT(r, !b.uniform("offset").set<float>(origin, 3));
#endif
-
- auto shader = b.makeShader(nullptr, false);
+ auto shader = b.makeShader(/*localMatrix=*/nullptr, /*isOpaque=*/false);
}
DEF_TEST(SkRuntimeEffectThreaded, r) {