Initialize test textures for ProcessorOptimizationValidationTest.
Ensure the data in the RGBA texture is premul.
Reenable the "modulation" optimization flag on GrAlphaThresholdFragmentProcessor.
Change-Id: I49ef215cee83ea74526c589bcee4bc215bc28ba4
Reviewed-on: https://skia-review.googlesource.com/8323
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index 49938c6..678fbaa 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -271,21 +271,41 @@
desc.fHeight = 256;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = kRGBA_8888_GrPixelConfig;
- sk_sp<GrTexture> tex0(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+
+ // Put premul data into the RGBA texture that the test FPs can optionally use.
+ std::unique_ptr<GrColor[]> rgbaData(new GrColor[256 * 256]);
+ for (int y = 0; y < 256; ++y) {
+ for (int x = 0; x < 256; ++x) {
+ rgbaData.get()[256 * y + x] =
+ texel_color(random.nextULessThan(256), random.nextULessThan(256));
+ }
+ }
+ sk_sp<GrTexture> tex0(context->textureProvider()->createTexture(
+ desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
+
+ // Put random values into the alpha texture that the test FPs can optionally use.
desc.fConfig = kAlpha_8_GrPixelConfig;
- sk_sp<GrTexture> tex1(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+ std::unique_ptr<uint8_t[]> alphaData(new uint8_t[256 * 256]);
+ for (int y = 0; y < 256; ++y) {
+ for (int x = 0; x < 256; ++x) {
+ alphaData.get()[256 * y + x] = random.nextULessThan(256);
+ }
+ }
+ sk_sp<GrTexture> tex1(context->textureProvider()->createTexture(desc, SkBudgeted::kYes,
+ alphaData.get(), 256));
GrTexture* textures[] = {tex0.get(), tex1.get()};
GrProcessorTestData testData(&random, context, rtc.get(), textures);
- std::unique_ptr<GrColor[]> data(new GrColor[256 * 256]);
+ // Use a different array of premul colors for the output of the fragment processor that preceeds
+ // the fragment processor under test.
for (int y = 0; y < 256; ++y) {
for (int x = 0; x < 256; ++x) {
- data.get()[256 * y + x] = texel_color(x, y);
+ rgbaData.get()[256 * y + x] = texel_color(x, y);
}
}
desc.fConfig = kRGBA_8888_GrPixelConfig;
sk_sp<GrTexture> dataTexture(context->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, data.get(), 256 * sizeof(GrColor)));
+ desc, SkBudgeted::kYes, rgbaData.get(), 256 * sizeof(GrColor)));
// Because processors factories configure themselves in random ways, this is not exhaustive.
for (int i = 0; i < FPFactory::Count(); ++i) {
@@ -305,10 +325,10 @@
continue;
}
test_draw_op(rtc.get(), fp, dataTexture.get());
- memset(data.get(), 0x0, sizeof(GrColor) * 256 * 256);
+ memset(rgbaData.get(), 0x0, sizeof(GrColor) * 256 * 256);
rtc->readPixels(
SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
- data.get(), 0, 0, 0);
+ rgbaData.get(), 0, 0, 0);
bool passing = true;
if (0) { // Useful to see what FPs are being tested.
SkString children;
@@ -324,7 +344,7 @@
for (int y = 0; y < 256 && passing; ++y) {
for (int x = 0; x < 256 && passing; ++x) {
GrColor input = texel_color(x, y);
- GrColor output = data.get()[y * 256 + x];
+ GrColor output = rgbaData.get()[y * 256 + x];
if (fp->modulatesInput()) {
// A modulating processor is allowed to modulate either the input color or
// just the input alpha.