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>
This commit is contained in:
parent
f687709011
commit
d1a8bdfbb9
@ -33,11 +33,10 @@ sk_sp<GrFragmentProcessor> GrAlphaThresholdFragmentProcessor::Make(
|
||||
}
|
||||
|
||||
inline GrFragmentProcessor::OptimizationFlags GrAlphaThresholdFragmentProcessor::OptFlags(float outerThreshold) {
|
||||
// TODO: Advertise that this processor modulates.
|
||||
if (outerThreshold >= 1.f) {
|
||||
return kPreservesOpaqueInput_OptimizationFlag;
|
||||
return kPreservesOpaqueInput_OptimizationFlag | kModulatesInput_OptimizationFlag;
|
||||
} else {
|
||||
return kNone_OptimizationFlags;
|
||||
return kModulatesInput_OptimizationFlag;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,21 +271,41 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
|
||||
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 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
|
||||
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 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user