Replace make_RGBW_shader shader with a gradient.
This is functionally the same, but will work in Graphite without
special bitmap handling. Also, this change exposed a bug in the
blender tests--the code was evaluating the edges between pixels,
instead of pixel centers.
Change-Id: I4c152b019812a5572dea0de5cb223bc1d0ba0ead
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/583556
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 6806beb..498348d 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -1018,6 +1018,20 @@
}
}
+DEF_SIMPLE_GM(rgbw_sweep_gradient, canvas, 100, 100) {
+ static constexpr SkScalar size = 100;
+ static constexpr SkColor colors[] = {SK_ColorWHITE, SK_ColorWHITE,
+ SK_ColorBLUE, SK_ColorBLUE,
+ SK_ColorRED, SK_ColorRED,
+ SK_ColorGREEN, SK_ColorGREEN};
+ static constexpr SkScalar pos[] = { 0, .25f, .25f, .50f, .50f, .75, .75, 1 };
+ static_assert(std::size(colors) == std::size(pos), "size mismatch");
+
+ SkPaint p;
+ p.setShader(SkGradientShader::MakeSweep(size / 2, size / 2, colors, pos, std::size(colors)));
+ canvas->drawRect(SkRect::MakeWH(size, size), p);
+}
+
// Exercises the special-case Ganesh gradient effects.
DEF_SIMPLE_GM(gradients_interesting, canvas, 640, 1300) {
static const SkColor colors2[] = { SK_ColorRED, SK_ColorBLUE };
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 999d2c4..8c9ea49 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
-#include "include/core/SkBitmap.h"
#include "include/core/SkBlender.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorFilter.h"
@@ -14,6 +13,7 @@
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkBlenders.h"
+#include "include/effects/SkGradientShader.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/gpu/GrDirectContext.h"
#include "include/sksl/SkSLDebugTrace.h"
@@ -488,18 +488,17 @@
SkTLazy<SkRuntimeBlendBuilder> fBuilder;
};
-// Produces a 2x2 bitmap shader, with opaque colors:
+// Produces a shader which will paint these opaque colors in a 2x2 rectangle:
// [ Red, Green ]
// [ Blue, White ]
static sk_sp<SkShader> make_RGBW_shader() {
- SkBitmap bmp;
- bmp.allocPixels(SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType));
- SkIRect topLeft = SkIRect::MakeWH(1, 1);
- bmp.pixmap().erase(SK_ColorRED, topLeft);
- bmp.pixmap().erase(SK_ColorGREEN, topLeft.makeOffset(1, 0));
- bmp.pixmap().erase(SK_ColorBLUE, topLeft.makeOffset(0, 1));
- bmp.pixmap().erase(SK_ColorWHITE, topLeft.makeOffset(1, 1));
- return bmp.makeShader(SkSamplingOptions());
+ static constexpr SkColor colors[] = {SK_ColorWHITE, SK_ColorWHITE,
+ SK_ColorBLUE, SK_ColorBLUE,
+ SK_ColorRED, SK_ColorRED,
+ SK_ColorGREEN, SK_ColorGREEN};
+ static constexpr SkScalar pos[] = { 0, .25f, .25f, .50f, .50f, .75, .75, 1 };
+ static_assert(std::size(colors) == std::size(pos), "size mismatch");
+ return SkGradientShader::MakeSweep(1, 1, colors, pos, std::size(colors));
}
static void test_RuntimeEffect_Shaders(skiatest::Reporter* r, GrRecordingContext* rContext) {
@@ -1008,16 +1007,16 @@
"uniform half2 pos;"
"half4 main(half4 s, half4 d) { return child.eval(pos); }");
effect.child("child") = make_RGBW_shader();
- effect.uniform("pos") = float2{0, 0};
+ effect.uniform("pos") = float2{0.5, 0.5};
effect.test(0xFF0000FF);
- effect.uniform("pos") = float2{1, 0};
+ effect.uniform("pos") = float2{1.5, 0.5};
effect.test(0xFF00FF00);
- effect.uniform("pos") = float2{0, 1};
+ effect.uniform("pos") = float2{0.5, 1.5};
effect.test(0xFFFF0000);
- effect.uniform("pos") = float2{1, 1};
+ effect.uniform("pos") = float2{1.5, 1.5};
effect.test(0xFFFFFFFF);
// Sampling a color filter