Revert of Add gpu implementation of SkAvoidXfermode (patchset #10 id:170001 of https://codereview.chromium.org/1658623002/ )

Reason for revert:
shader compilation failures

error C1008: undefined variable "null"

https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Ubuntu-GCC-ShuttleA-GPU-GTX660-x86_64-Debug/builds/4064/steps/dm/logs/stdio

Original issue's description:
> Add gpu implementation of SkAvoidXfermode
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1658623002
>
> TBR=bsalomon@google.com
>
> Committed: https://skia.googlesource.com/skia/+/15691a055db9b68c9b48f589e48d8a85888cf83f

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review URL: https://codereview.chromium.org/1663093002
This commit is contained in:
mtklein 2016-02-03 06:42:16 -08:00 committed by Commit bot
parent c9715406c4
commit f16e2a2e92
6 changed files with 7 additions and 459 deletions

View File

@ -67,9 +67,9 @@ protected:
r.offsetTo(0.0f, 64);
// LL corner: replace red with transparent blue with a loose tolerance
// LL corner: replace red with blue with a loose tolerance
SkPaint p3;
p3.setColor(0x7F0000FF);
p3.setColor(SK_ColorBLUE);
p3.setXfermode(SkAvoidXfermode::Create(SK_ColorRED,
250,
SkAvoidXfermode::kTargetColor_Mode))->unref();

View File

@ -1,84 +0,0 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "gm.h"
#include "SkAvoidXfermode.h"
class AvoidXfermode2GM : public skiagm::GM {
public:
AvoidXfermode2GM() { }
protected:
SkString onShortName() override {
return SkString("avoidxfermode2");
}
SkISize onISize() override { return SkISize::Make(128, 128); }
void onDraw(SkCanvas* canvas) override {
canvas->drawARGB(255, 0, 0, 0);
SkRect r = SkRect::MakeXYWH(32, 32, 64, 64);
SkPaint p0;
p0.setColor(SK_ColorGREEN);
p0.setAntiAlias(false);
canvas->drawRect(r, p0);
r = SkRect::MakeIWH(64, 64);
// UL corner: replace the green with a tight tolerance
SkPaint p1;
p1.setColor(SK_ColorRED);
p1.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
55,
SkAvoidXfermode::kTargetColor_Mode))->unref();
canvas->drawRect(r, p1);
r.offsetTo(64, 0.0f);
// UR corner: avoid the green with a tight tolerance
SkPaint p2;
p2.setColor(SK_ColorRED);
p2.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
200,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
canvas->drawRect(r, p2);
r.offsetTo(0.0f, 64);
// LL corner: replace the green with a loose tolerance
SkPaint p3;
p3.setColor(SK_ColorRED);
p3.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
200,
SkAvoidXfermode::kTargetColor_Mode))->unref();
canvas->drawRect(r, p3);
r.offsetTo(64, 64);
// LR corner: avoid the green with a loose tolerance
SkPaint p4;
p4.setColor(SK_ColorRED);
p4.setXfermode(SkAvoidXfermode::Create(SK_ColorGREEN,
55,
SkAvoidXfermode::kAvoidColor_Mode))->unref();
canvas->drawRect(r, p4);
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new AvoidXfermode2GM;)

View File

@ -51,12 +51,6 @@ public:
void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const override;
#if SK_SUPPORT_GPU
bool asFragmentProcessor(const GrFragmentProcessor** output,
const GrFragmentProcessor* dst) const override;
bool asXPFactory(GrXPFactory** xpf) const override;
#endif
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(AvoidXfermode)

View File

@ -164,373 +164,11 @@ void SkAvoidXfermode::xferA8(SkAlpha dst[], const SkPMColor src[], int count,
const SkAlpha aa[]) const {
}
#if SK_SUPPORT_GPU
#include "GrFragmentProcessor.h"
#include "GrInvariantOutput.h"
#include "GrXferProcessor.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLXferProcessor.h"
///////////////////////////////////////////////////////////////////////////////
// Fragment Processor
///////////////////////////////////////////////////////////////////////////////
class GLAvoidFP;
class AvoidFP : public GrFragmentProcessor {
public:
static const GrFragmentProcessor* Create(SkColor opColor, uint8_t tolerance,
SkAvoidXfermode::Mode mode,
const GrFragmentProcessor* dst) {
return new AvoidFP(opColor, tolerance, mode, dst);
}
~AvoidFP() override { }
const char* name() const override { return "Avoid"; }
SkString dumpInfo() const override {
SkString str;
str.appendf("Color: 0x%08x Tol: %d Mode: %s",
fOpColor, fTolerance,
fMode == SkAvoidXfermode::kAvoidColor_Mode ? "Avoid" : "Target");
return str;
}
SkColor opColor() const { return fOpColor; }
uint8_t tol() const { return fTolerance; }
SkAvoidXfermode::Mode mode() const { return fMode; }
private:
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
void onGetGLSLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor& fpBase) const override {
const AvoidFP& fp = fpBase.cast<AvoidFP>();
return fOpColor == fp.fOpColor &&
fTolerance == fp.fTolerance &&
fMode == fp.fMode;
}
void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
inout->setToUnknown(GrInvariantOutput::kWill_ReadInput);
}
AvoidFP(SkColor opColor, uint8_t tolerance,
SkAvoidXfermode::Mode mode, const GrFragmentProcessor* dst)
: fOpColor(opColor), fTolerance(tolerance), fMode(mode) {
this->initClassID<AvoidFP>();
SkASSERT(dst);
SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst);
SkASSERT(0 == dstIndex);
}
SkColor fOpColor;
uint8_t fTolerance;
SkAvoidXfermode::Mode fMode;
GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
typedef GrFragmentProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
// Add common code for calculating avoid's distance value
static void add_avoid_code(GrGLSLFragmentBuilder* fragBuilder,
const char* dstColor,
const char* kColorAndTolUni,
const char* kDist,
SkAvoidXfermode::Mode mode) {
fragBuilder->codeAppendf("vec3 temp = %s.rgb - %s.rgb;", dstColor, kColorAndTolUni);
fragBuilder->codeAppendf("float %s = max(max(abs(temp.r), abs(temp.g)), abs(temp.b));", kDist);
if (SkAvoidXfermode::kTargetColor_Mode == mode) {
fragBuilder->codeAppendf("%s = 1.0 - %s;", kDist, kDist);
}
// the 'a' portion of the uniform is the scaled and inverted tolerance
fragBuilder->codeAppendf("%s = %s * %s.a - (%s.a - 1.0);", kDist, kDist,
kColorAndTolUni, kColorAndTolUni);
}
class GLAvoidFP : public GrGLSLFragmentProcessor {
public:
void emitCode(EmitArgs& args) override {
const AvoidFP& avoid = args.fFp.cast<AvoidFP>();
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString dstColor("dstColor");
this->emitChild(0, nullptr, &dstColor, args);
fColorAndTolUni = args.fUniformHandler->addUniform(
GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"colorAndTol");
const char* kColorAndTolUni = args.fUniformHandler->getUniformCStr(fColorAndTolUni);
// add_avoid_code emits the code needed to compute the distance and put it in this variable
const char* kDistanceVar = "dist";
add_avoid_code(fragBuilder, dstColor.c_str(), kColorAndTolUni, kDistanceVar, avoid.mode());
fragBuilder->codeAppendf("vec4 newCoverage = vec4(%s);", kDistanceVar);
fragBuilder->codeAppendf("%s = newCoverage * %s + (vec4(1.0)-newCoverage) * %s;",
args.fOutputColor, args.fInputColor, dstColor.c_str());
}
static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
const AvoidFP& avoid = proc.cast<AvoidFP>();
uint32_t key = avoid.mode() == SkAvoidXfermode::kTargetColor_Mode ? 1 : 0;
b->add32(key);
}
protected:
void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override {
const AvoidFP& avoid = proc.cast<AvoidFP>();
pdman.set4f(fColorAndTolUni,
SkColorGetR(avoid.opColor())/255.0f,
SkColorGetG(avoid.opColor())/255.0f,
SkColorGetB(avoid.opColor())/255.0f,
256.0f/(avoid.tol()+1.0f));
}
private:
GrGLSLProgramDataManager::UniformHandle fColorAndTolUni;
typedef GrGLSLFragmentProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
GrGLSLFragmentProcessor* AvoidFP::onCreateGLSLInstance() const {
return new GLAvoidFP;
}
void AvoidFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
GLAvoidFP::GenKey(*this, caps, b);
}
const GrFragmentProcessor* AvoidFP::TestCreate(GrProcessorTestData* d) {
SkColor opColor = d->fRandom->nextU();
uint8_t tolerance = d->fRandom->nextBits(8);
SkAvoidXfermode::Mode mode = d->fRandom->nextBool() ? SkAvoidXfermode::kAvoidColor_Mode
: SkAvoidXfermode::kTargetColor_Mode;
SkAutoTUnref<const GrFragmentProcessor> dst(GrProcessorUnitTest::CreateChildFP(d));
return new AvoidFP(opColor, tolerance, mode, dst);
}
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(AvoidFP);
///////////////////////////////////////////////////////////////////////////////
// Xfer Processor
///////////////////////////////////////////////////////////////////////////////
class AvoidXP : public GrXferProcessor {
public:
AvoidXP(const DstTexture* dstTexture, bool hasMixedSamples,
SkColor opColor, uint8_t tolerance, SkAvoidXfermode::Mode mode)
: INHERITED(dstTexture, true, hasMixedSamples)
, fOpColor(opColor)
, fTolerance(tolerance)
, fMode(mode) {
this->initClassID<AvoidXP>();
}
const char* name() const override { return "Avoid"; }
GrGLSLXferProcessor* createGLSLInstance() const override;
SkColor opColor() const { return fOpColor; }
uint8_t tol() const { return fTolerance; }
SkAvoidXfermode::Mode mode() const { return fMode; }
private:
GrXferProcessor::OptFlags onGetOptimizations(const GrPipelineOptimizations& optimizations,
bool doesStencilWrite,
GrColor* overrideColor,
const GrCaps& caps) const override {
return GrXferProcessor::kNone_OptFlags;
}
void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
bool onIsEqual(const GrXferProcessor& xpBase) const override {
const AvoidXP& xp = xpBase.cast<AvoidXP>();
return fOpColor == xp.fOpColor &&
fTolerance == xp.fTolerance &&
fMode == xp.fMode;
}
SkColor fOpColor;
uint8_t fTolerance;
SkAvoidXfermode::Mode fMode;
typedef GrXferProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
class GLAvoidXP : public GrGLSLXferProcessor {
public:
static void GenKey(const GrProcessor& processor, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
const AvoidXP& avoid = processor.cast<AvoidXP>();
uint32_t key = SkAvoidXfermode::kTargetColor_Mode == avoid.mode() ? 1 : 0;
b->add32(key);
}
private:
void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder* fragBuilder,
GrGLSLUniformHandler* uniformHandler,
const char* srcColor,
const char* srcCoverage,
const char* dstColor,
const char* outColor,
const char* outColorSecondary,
const GrXferProcessor& proc) override {
const AvoidXP& avoid = proc.cast<AvoidXP>();
fColorAndTolUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"colorAndTol");
const char* kColorandTolUni = uniformHandler->getUniformCStr(fColorAndTolUni);
// add_avoid_code emits the code needed to compute the distance and put it in this variable
const char* kDistanceVar = "dist";
add_avoid_code(fragBuilder, dstColor, kColorandTolUni, kDistanceVar, avoid.mode());
fragBuilder->codeAppendf("vec4 newCoverage = vec4(%s);", kDistanceVar);
if (srcCoverage) {
fragBuilder->codeAppendf("newCoverage *= %s;", srcCoverage);
}
// The raster implementation's quantization and behavior yield a very noticeable
// result near zero (0.0039 = 1/256).
fragBuilder->codeAppendf("if (%s < 0.0039) { %s = %s; } else {",
kDistanceVar, outColor, dstColor);
fragBuilder->codeAppendf("%s = %s;", outColor, srcColor);
INHERITED::DefaultCoverageModulation(fragBuilder, "newCoverage", dstColor, outColor,
outColorSecondary, proc);
fragBuilder->codeAppend("}");
}
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrXferProcessor& processor) override {
const AvoidXP& avoid = processor.cast<AvoidXP>();
pdman.set4f(fColorAndTolUni,
SkColorGetR(avoid.opColor())/255.0f,
SkColorGetG(avoid.opColor())/255.0f,
SkColorGetB(avoid.opColor())/255.0f,
256.0f/(avoid.tol()+1.0f));
};
GrGLSLProgramDataManager::UniformHandle fColorAndTolUni;
typedef GrGLSLXferProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
void AvoidXP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const {
GLAvoidXP::GenKey(*this, caps, b);
}
GrGLSLXferProcessor* AvoidXP::createGLSLInstance() const { return new GLAvoidXP; }
///////////////////////////////////////////////////////////////////////////////
class GrAvoidXPFactory : public GrXPFactory {
public:
static GrXPFactory* Create(SkColor opColor, uint8_t tolerance,
SkAvoidXfermode::Mode mode) {
return new GrAvoidXPFactory(opColor, tolerance, mode);
}
void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
GrXPFactory::InvariantBlendedColor* blendedColor) const override {
blendedColor->fWillBlendWithDst = true;
blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags;
}
private:
GrAvoidXPFactory(SkColor opColor, uint8_t tolerance, SkAvoidXfermode::Mode mode)
: fOpColor(opColor)
, fTolerance(tolerance)
, fMode(mode) {
this->initClassID<GrAvoidXPFactory>();
}
GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
const GrPipelineOptimizations& optimizations,
bool hasMixedSamples,
const DstTexture* dstTexture) const override {
return new AvoidXP(dstTexture, hasMixedSamples, fOpColor, fTolerance, fMode);
}
bool onWillReadDstColor(const GrCaps& caps,
const GrPipelineOptimizations& optimizations,
bool hasMixedSamples) const override {
return true;
}
bool onIsEqual(const GrXPFactory& xpfBase) const override {
const GrAvoidXPFactory& xpf = xpfBase.cast<GrAvoidXPFactory>();
return fOpColor == xpf.fOpColor &&
fTolerance == xpf.fTolerance &&
fMode == xpf.fMode;
}
GR_DECLARE_XP_FACTORY_TEST;
SkColor fOpColor;
uint8_t fTolerance;
SkAvoidXfermode::Mode fMode;
typedef GrXPFactory INHERITED;
};
GR_DEFINE_XP_FACTORY_TEST(GrAvoidXPFactory);
const GrXPFactory* GrAvoidXPFactory::TestCreate(GrProcessorTestData* d) {
SkColor opColor = d->fRandom->nextU();
uint8_t tolerance = d->fRandom->nextBits(8);
SkAvoidXfermode::Mode mode = d->fRandom->nextBool() ? SkAvoidXfermode::kAvoidColor_Mode
: SkAvoidXfermode::kTargetColor_Mode;
return GrAvoidXPFactory::Create(opColor, tolerance, mode);
}
///////////////////////////////////////////////////////////////////////////////
bool SkAvoidXfermode::asFragmentProcessor(const GrFragmentProcessor** output,
const GrFragmentProcessor* dst) const {
if (output) {
*output = AvoidFP::Create(fOpColor, fTolerance, fMode, dst);
}
return true;
}
bool SkAvoidXfermode::asXPFactory(GrXPFactory** xpf) const {
if (xpf) {
*xpf = GrAvoidXPFactory::Create(fOpColor, fTolerance, fMode);
}
return true;
}
#endif
#ifndef SK_IGNORE_TO_STRING
void SkAvoidXfermode::toString(SkString* str) const {
str->append("AvoidXfermode: opColor: ");
str->appendHex(fOpColor);
str->appendf("tolerance: %d ", fTolerance);
str->appendf("distMul: %d ", fDistMul);
static const char* gModeStrings[] = { "Avoid", "Target" };

View File

@ -345,8 +345,8 @@ private:
}
bool onWillReadDstColor(const GrCaps& caps,
const GrPipelineOptimizations& optimizations,
bool hasMixedSamples) const override {
const GrPipelineOptimizations& optimizations,
bool hasMixedSamples) const override {
return true;
}

View File

@ -48,9 +48,9 @@ GrProcessorTestFactory<GrGeometryProcessor>::GetFactories() {
* we verify the count is as expected. If a new factory is added, then these numbers must be
* manually adjusted.
*/
static const int kFPFactoryCount = 41;
static const int kFPFactoryCount = 40;
static const int kGPFactoryCount = 14;
static const int kXPFactoryCount = 8;
static const int kXPFactoryCount = 7;
template<>
void GrProcessorTestFactory<GrFragmentProcessor>::VerifyFactoryCount() {