Fix LCD coverage regression in GrPorterDuffXPFactory

Fixes GrPorterDuffXPFactory to not use the blend table when getting
info about the LCD coverage XP.

BUG=skia:

Review URL: https://codereview.chromium.org/1149883004
This commit is contained in:
cdalton 2015-05-22 14:04:37 -07:00 committed by Commit bot
parent 682c269a15
commit 3e2d59ef36
2 changed files with 70 additions and 7 deletions

View File

@ -744,11 +744,16 @@ bool GrPorterDuffXPFactory::supportsRGBCoverage(GrColor /*knownColor*/,
void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
GrXPFactory::InvariantOutput* output) const {
const BlendFormula& blendFormula = get_blend_formula(fXfermode, colorPOI, coveragePOI);
output->fWillBlendWithDst = true;
output->fBlendedColorFlags = kNone_GrColorComponentFlags;
// The LCD coverage XP doesn't use the blend table, and has no invariant output.
if (coveragePOI.isFourChannelOutput()) {
return;
}
const BlendFormula& blendFormula = get_blend_formula(fXfermode, colorPOI, coveragePOI);
if (blendFormula.usesDstColor()) {
output->fWillBlendWithDst = true;
output->fBlendedColorFlags = kNone_GrColorComponentFlags;
return;
}
@ -768,16 +773,18 @@ void GrPorterDuffXPFactory::getInvariantOutput(const GrProcOptInfo& colorPOI,
output->fBlendedColorFlags = colorPOI.validFlags();
return;
// TODO: update if we ever use const color.
default:
output->fBlendedColorFlags = kNone_GrColorComponentFlags;
return;
default: return;
}
}
bool GrPorterDuffXPFactory::willReadDstColor(const GrCaps& caps,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI) const {
// The LCD coverage XP doesn't use the blend table, and never requires a dst read.
if (coveragePOI.isFourChannelOutput()) {
return false;
}
// Some formulas use dual source blending, so we fall back if it is required but not supported.
return !caps.shaderCaps()->dualSourceBlendingSupport() &&
get_blend_formula(fXfermode, colorPOI, coveragePOI).hasSecondaryOutput();

View File

@ -10,6 +10,7 @@
#if SK_SUPPORT_GPU
#include "GrBatch.h"
#include "GrContextFactory.h"
#include "GrGpu.h"
#include "GrXferProcessor.h"
@ -23,6 +24,7 @@ static void test_alpha_opaque_with_coverage(skiatest::Reporter* reporter, const
static void test_alpha_opaque_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
static void test_color_white_with_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
static void test_color_white_no_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps);
DEF_GPUTEST(GrPorterDuff, reporter, factory) {
GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType);
@ -44,6 +46,7 @@ DEF_GPUTEST(GrPorterDuff, reporter, factory) {
test_color_white_with_coverage(reporter, caps);
test_color_white_with_coverage(reporter, caps);
test_color_white_no_coverage(reporter, caps);
test_lcd_coverage(reporter, caps);
}
////////////////////////////////////////////////////////////////////////////////
@ -100,6 +103,7 @@ static void test_alpha_unknown_with_coverage(skiatest::Reporter* reporter, const
SkASSERT(!colorPOI.isOpaque());
SkASSERT(!colorPOI.isSolidWhite());
SkASSERT(!covPOI.isSolidWhite());
SkASSERT(!covPOI.isFourChannelOutput());
for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
@ -290,6 +294,7 @@ static void test_alpha_unknown_no_coverage(skiatest::Reporter* reporter, const G
SkASSERT(!colorPOI.isOpaque());
SkASSERT(!colorPOI.isSolidWhite());
SkASSERT(covPOI.isSolidWhite());
SkASSERT(!covPOI.isFourChannelOutput());
for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
@ -491,6 +496,7 @@ static void test_alpha_opaque_with_coverage(skiatest::Reporter* reporter, const
SkASSERT(colorPOI.isOpaque());
SkASSERT(!colorPOI.isSolidWhite());
SkASSERT(!covPOI.isSolidWhite());
SkASSERT(!covPOI.isFourChannelOutput());
for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
@ -684,6 +690,7 @@ static void test_alpha_opaque_no_coverage(skiatest::Reporter* reporter, const Gr
SkASSERT(colorPOI.isOpaque());
SkASSERT(!colorPOI.isSolidWhite());
SkASSERT(covPOI.isSolidWhite());
SkASSERT(!covPOI.isFourChannelOutput());
for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
@ -890,6 +897,7 @@ static void test_color_white_with_coverage(skiatest::Reporter* reporter, const G
SkASSERT(colorPOI.isOpaque());
SkASSERT(colorPOI.isSolidWhite());
SkASSERT(!covPOI.isSolidWhite());
SkASSERT(!covPOI.isFourChannelOutput());
for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
@ -1082,6 +1090,7 @@ static void test_color_white_no_coverage(skiatest::Reporter* reporter, const GrC
SkASSERT(colorPOI.isOpaque());
SkASSERT(colorPOI.isSolidWhite());
SkASSERT(covPOI.isSolidWhite());
SkASSERT(!covPOI.isFourChannelOutput());
for (int m = 0; m <= SkXfermode::kLastCoeffMode; m++) {
SkXfermode::Mode xfermode = static_cast<SkXfermode::Mode>(m);
@ -1276,5 +1285,52 @@ static void test_color_white_no_coverage(skiatest::Reporter* reporter, const GrC
}
}
static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps) {
class : public GrBatch {
void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
out->setKnownFourComponents(GrColorPackRGBA(123, 45, 67, 221));
}
void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override {
out->setUnknownFourComponents();
out->setUsingLCDCoverage();
}
const char* name() const override { return "Test LCD Text Batch"; }
void initBatchTracker(const GrPipelineInfo&) override {}
bool onCombineIfPossible(GrBatch*) override { return false; }
void generateGeometry(GrBatchTarget*, const GrPipeline*) override {}
} testLCDCoverageBatch;
GrProcOptInfo colorPOI, covPOI;
colorPOI.calcColorWithBatch(&testLCDCoverageBatch, NULL, 0);
covPOI.calcCoverageWithBatch(&testLCDCoverageBatch, NULL, 0);
SkASSERT(kRGBA_GrColorComponentFlags == colorPOI.validFlags());
SkASSERT(covPOI.isFourChannelOutput());
SkAutoTUnref<GrXPFactory> xpf(GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode));
TEST_ASSERT(!xpf->willNeedDstCopy(caps, colorPOI, covPOI));
GrXPFactory::InvariantOutput invariantOutput;
xpf->getInvariantOutput(colorPOI, covPOI, &invariantOutput);
TEST_ASSERT(invariantOutput.fWillBlendWithDst);
TEST_ASSERT(kNone_GrColorComponentFlags == invariantOutput.fBlendedColorFlags);
SkAutoTUnref<GrXferProcessor> xp(xpf->createXferProcessor(colorPOI, covPOI, 0, caps));
if (!xp) {
ERRORF(reporter, "Failed to create an XP with LCD coverage.");
return;
}
GrColor overrideColor;
xp->getOptimizations(colorPOI, covPOI, false, &overrideColor, caps);
GrXferProcessor::BlendInfo blendInfo;
xp->getBlendInfo(&blendInfo);
TEST_ASSERT(blendInfo.fWriteColor);
}
#endif