Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Unified Diff: src/gpu/GrOvalRenderer.cpp

Issue 1139723004: Preliminary attempt to remove batch tracker (Closed) Base URL: https://skia.googlesource.com/skia.git@cleanup5
Patch Set: tweaks Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrGeometryProcessor.h ('k') | src/gpu/GrPathProcessor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrOvalRenderer.cpp
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 0a7b3f89fce1f8c8976bbe1bb31bb32db1141ae2..69baebb22821155b1b311c5388102532112e2036 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -71,14 +71,17 @@ inline bool circle_stays_circle(const SkMatrix& m) {
class CircleEdgeEffect : public GrGeometryProcessor {
public:
- static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatrix& localMatrix) {
- return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix));
+ static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatrix& localMatrix,
+ bool usesLocalCoords) {
+ return SkNEW_ARGS(CircleEdgeEffect, (color, stroke, localMatrix, usesLocalCoords));
}
const Attribute* inPosition() const { return fInPosition; }
const Attribute* inCircleEdge() const { return fInCircleEdge; }
GrColor color() const { return fColor; }
+ bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
const SkMatrix& localMatrix() const { return fLocalMatrix; }
+ bool usesLocalCoords() const { return fUsesLocalCoords; }
virtual ~CircleEdgeEffect() {}
const char* name() const override { return "CircleEdge"; }
@@ -94,7 +97,6 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
- const BatchTracker& local = args.fBT.cast<BatchTracker>();
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
@@ -104,9 +106,10 @@ public:
args.fPB->addVarying("CircleEdge", &v);
vsBuilder->codeAppendf("%s = %s;", v.vsOut(), ce.inCircleEdge()->fName);
- // Setup pass through color
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
- &fColorUniform);
+ // setup pass through color
+ if (!ce.colorIgnored()) {
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform);
+ }
// Setup position
this->setupPosition(pb, gpArgs, ce.inPosition()->fName);
@@ -131,22 +134,22 @@ public:
const GrBatchTracker& bt,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
- const BatchTracker& local = bt.cast<BatchTracker>();
const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>();
uint16_t key = ce.isStroked() ? 0x1 : 0x0;
- key |= local.fUsesLocalCoords && ce.localMatrix().hasPerspective() ? 0x2 : 0x0;
- b->add32(key << 16 | local.fInputColorType);
+ key |= ce.usesLocalCoords() && ce.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= ce.colorIgnored() ? 0x4 : 0x0;
+ b->add32(key);
}
virtual void setData(const GrGLProgramDataManager& pdman,
const GrPrimitiveProcessor& gp,
const GrBatchTracker& bt) override {
- const BatchTracker& local = bt.cast<BatchTracker>();
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) {
+ const CircleEdgeEffect& ce = gp.cast<CircleEdgeEffect>();
+ if (ce.color() != fColor) {
GrGLfloat c[4];
- GrColorToRGBAFloat(local.fColor, c);
+ GrColorToRGBAFloat(ce.color(), c);
pdman.set4fv(fColorUniform, 1, c);
- fColor = local.fColor;
+ fColor = ce.color();
}
}
@@ -174,16 +177,11 @@ public:
return SkNEW_ARGS(GLProcessor, (*this, bt));
}
- void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override {
- BatchTracker* local = bt->cast<BatchTracker>();
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false);
- local->fUsesLocalCoords = init.fUsesLocalCoords;
- }
-
private:
- CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix)
+ CircleEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix, bool usesLocalCoords)
: fColor(color)
- , fLocalMatrix(localMatrix) {
+ , fLocalMatrix(localMatrix)
+ , fUsesLocalCoords(usesLocalCoords) {
this->initClassID<CircleEdgeEffect>();
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType));
fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge",
@@ -191,17 +189,12 @@ private:
fStroke = stroke;
}
- struct BatchTracker {
- GrGPInput fInputColorType;
- GrColor fColor;
- bool fUsesLocalCoords;
- };
-
GrColor fColor;
SkMatrix fLocalMatrix;
const Attribute* fInPosition;
const Attribute* fInCircleEdge;
bool fStroke;
+ bool fUsesLocalCoords;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
@@ -216,7 +209,8 @@ GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random,
GrTexture* textures[]) {
return CircleEdgeEffect::Create(GrRandomColor(random),
random->nextBool(),
- GrTest::TestMatrix(random));
+ GrTest::TestMatrix(random),
+ random->nextBool());
}
///////////////////////////////////////////////////////////////////////////////
@@ -231,8 +225,9 @@ GrGeometryProcessor* CircleEdgeEffect::TestCreate(SkRandom* random,
class EllipseEdgeEffect : public GrGeometryProcessor {
public:
- static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatrix& localMatrix) {
- return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix));
+ static GrGeometryProcessor* Create(GrColor color, bool stroke, const SkMatrix& localMatrix,
+ bool usesLocalCoords) {
+ return SkNEW_ARGS(EllipseEdgeEffect, (color, stroke, localMatrix, usesLocalCoords));
}
virtual ~EllipseEdgeEffect() {}
@@ -243,7 +238,9 @@ public:
const Attribute* inEllipseOffset() const { return fInEllipseOffset; }
const Attribute* inEllipseRadii() const { return fInEllipseRadii; }
GrColor color() const { return fColor; }
+ bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
const SkMatrix& localMatrix() const { return fLocalMatrix; }
+ bool usesLocalCoords() const { return fUsesLocalCoords; }
inline bool isStroked() const { return fStroke; }
@@ -256,7 +253,6 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
- const BatchTracker& local = args.fBT.cast<BatchTracker>();
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
@@ -272,9 +268,10 @@ public:
vsBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(),
ee.inEllipseRadii()->fName);
- // Setup pass through color
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
- &fColorUniform);
+ // setup pass through color
+ if (!ee.colorIgnored()) {
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform);
+ }
// Setup position
this->setupPosition(pb, gpArgs, ee.inPosition()->fName);
@@ -314,23 +311,22 @@ public:
const GrBatchTracker& bt,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
- const BatchTracker& local = bt.cast<BatchTracker>();
const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>();
uint16_t key = ee.isStroked() ? 0x1 : 0x0;
- key |= local.fUsesLocalCoords && ee.localMatrix().hasPerspective() ? 0x2 : 0x0;
- b->add32(key << 16 | local.fInputColorType);
+ key |= ee.usesLocalCoords() && ee.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= ee.colorIgnored() ? 0x4 : 0x0;
+ b->add32(key);
}
virtual void setData(const GrGLProgramDataManager& pdman,
const GrPrimitiveProcessor& gp,
const GrBatchTracker& bt) override {
-
- const BatchTracker& local = bt.cast<BatchTracker>();
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) {
+ const EllipseEdgeEffect& ee = gp.cast<EllipseEdgeEffect>();
+ if (ee.color() != fColor) {
GrGLfloat c[4];
- GrColorToRGBAFloat(local.fColor, c);
+ GrColorToRGBAFloat(ee.color(), c);
pdman.set4fv(fColorUniform, 1, c);
- fColor = local.fColor;
+ fColor = ee.color();
}
}
@@ -359,16 +355,12 @@ public:
return SkNEW_ARGS(GLProcessor, (*this, bt));
}
- void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override {
- BatchTracker* local = bt->cast<BatchTracker>();
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false);
- local->fUsesLocalCoords = init.fUsesLocalCoords;
- }
-
private:
- EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix)
+ EllipseEdgeEffect(GrColor color, bool stroke, const SkMatrix& localMatrix,
+ bool usesLocalCoords)
: fColor(color)
- , fLocalMatrix(localMatrix) {
+ , fLocalMatrix(localMatrix)
+ , fUsesLocalCoords(usesLocalCoords) {
this->initClassID<EllipseEdgeEffect>();
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType));
fInEllipseOffset = &this->addVertexAttrib(Attribute("inEllipseOffset",
@@ -378,18 +370,13 @@ private:
fStroke = stroke;
}
- struct BatchTracker {
- GrGPInput fInputColorType;
- GrColor fColor;
- bool fUsesLocalCoords;
- };
-
const Attribute* fInPosition;
const Attribute* fInEllipseOffset;
const Attribute* fInEllipseRadii;
GrColor fColor;
SkMatrix fLocalMatrix;
bool fStroke;
+ bool fUsesLocalCoords;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
@@ -404,7 +391,8 @@ GrGeometryProcessor* EllipseEdgeEffect::TestCreate(SkRandom* random,
GrTexture* textures[]) {
return EllipseEdgeEffect::Create(GrRandomColor(random),
random->nextBool(),
- GrTest::TestMatrix(random));
+ GrTest::TestMatrix(random),
+ random->nextBool());
}
///////////////////////////////////////////////////////////////////////////////
@@ -422,8 +410,9 @@ class DIEllipseEdgeEffect : public GrGeometryProcessor {
public:
enum Mode { kStroke = 0, kHairline, kFill };
- static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, Mode mode) {
- return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode));
+ static GrGeometryProcessor* Create(GrColor color, const SkMatrix& viewMatrix, Mode mode,
+ bool usesLocalCoords) {
+ return SkNEW_ARGS(DIEllipseEdgeEffect, (color, viewMatrix, mode, usesLocalCoords));
}
virtual ~DIEllipseEdgeEffect() {}
@@ -434,7 +423,9 @@ public:
const Attribute* inEllipseOffsets0() const { return fInEllipseOffsets0; }
const Attribute* inEllipseOffsets1() const { return fInEllipseOffsets1; }
GrColor color() const { return fColor; }
+ bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
+ bool usesLocalCoords() const { return fUsesLocalCoords; }
inline Mode getMode() const { return fMode; }
@@ -447,7 +438,6 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
- const BatchTracker& local = args.fBT.cast<BatchTracker>();
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
@@ -463,9 +453,10 @@ public:
vsBuilder->codeAppendf("%s = %s;", offsets1.vsOut(),
ee.inEllipseOffsets1()->fName);
- // Setup pass through color
- this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, NULL,
- &fColorUniform);
+ // setup pass through color
+ if (!ee.colorIgnored()) {
+ this->setupUniformColor(pb, args.fOutputColor, &fColorUniform);
+ }
// Setup position
this->setupPosition(pb, gpArgs, ee.inPosition()->fName, ee.viewMatrix());
@@ -519,11 +510,11 @@ public:
const GrBatchTracker& bt,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
- const BatchTracker& local = bt.cast<BatchTracker>();
const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffect>();
uint16_t key = ellipseEffect.getMode();
- key |= ComputePosKey(ellipseEffect.viewMatrix()) << 9;
- b->add32(key << 16 | local.fInputColorType);
+ key |= ellipseEffect.colorIgnored() << 9;
+ key |= ComputePosKey(ellipseEffect.viewMatrix()) << 10;
+ b->add32(key);
}
virtual void setData(const GrGLProgramDataManager& pdman,
@@ -532,12 +523,11 @@ public:
const DIEllipseEdgeEffect& dee = gp.cast<DIEllipseEdgeEffect>();
this->setUniformViewMatrix(pdman, dee.viewMatrix());
- const BatchTracker& local = bt.cast<BatchTracker>();
- if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) {
+ if (dee.color() != fColor) {
GrGLfloat c[4];
- GrColorToRGBAFloat(local.fColor, c);
+ GrColorToRGBAFloat(dee.color(), c);
pdman.set4fv(fColorUniform, 1, c);
- fColor = local.fColor;
+ fColor = dee.color();
}
}
@@ -559,37 +549,28 @@ public:
return SkNEW_ARGS(GLProcessor, (*this, bt));
}
- void initBatchTracker(GrBatchTracker* bt, const GrPipelineInfo& init) const override {
- BatchTracker* local = bt->cast<BatchTracker>();
- local->fInputColorType = GetColorInputType(&local->fColor, this->color(), init, false);
- local->fUsesLocalCoords = init.fUsesLocalCoords;
- }
-
private:
- DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode)
+ DIEllipseEdgeEffect(GrColor color, const SkMatrix& viewMatrix, Mode mode,
+ bool usesLocalCoords)
: fColor(color)
- , fViewMatrix(viewMatrix) {
+ , fViewMatrix(viewMatrix)
+ , fUsesLocalCoords(usesLocalCoords) {
this->initClassID<DIEllipseEdgeEffect>();
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType));
fInEllipseOffsets0 = &this->addVertexAttrib(Attribute("inEllipseOffsets0",
- kVec2f_GrVertexAttribType));
+ kVec2f_GrVertexAttribType));
fInEllipseOffsets1 = &this->addVertexAttrib(Attribute("inEllipseOffsets1",
- kVec2f_GrVertexAttribType));
+ kVec2f_GrVertexAttribType));
fMode = mode;
}
- struct BatchTracker {
- GrGPInput fInputColorType;
- GrColor fColor;
- bool fUsesLocalCoords;
- };
-
const Attribute* fInPosition;
const Attribute* fInEllipseOffsets0;
const Attribute* fInEllipseOffsets1;
GrColor fColor;
SkMatrix fViewMatrix;
Mode fMode;
+ bool fUsesLocalCoords;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST;
@@ -604,7 +585,8 @@ GrGeometryProcessor* DIEllipseEdgeEffect::TestCreate(SkRandom* random,
GrTexture* textures[]) {
return DIEllipseEdgeEffect::Create(GrRandomColor(random),
GrTest::TestMatrix(random),
- (Mode)(random->nextRangeU(0,2)));
+ (Mode)(random->nextRangeU(0,2)),
+ random->nextBool());
}
///////////////////////////////////////////////////////////////////////////////
@@ -692,20 +674,11 @@ public:
// Setup geometry processor
SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->color(),
this->stroke(),
- invert));
+ invert,
+ this->usesLocalCoords()));
batchTarget->initDraw(gp, pipeline);
- // TODO this is hacky, but the only way we have to initialize the GP is to use the
- // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
- // everywhere we can remove this nastiness
- GrPipelineInfo init;
- init.fColorIgnored = fBatch.fColorIgnored;
- init.fOverrideColor = GrColor_ILLEGAL;
- init.fCoverageIgnored = fBatch.fCoverageIgnored;
- init.fUsesLocalCoords = this->usesLocalCoords();
- gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
-
int instanceCount = fGeoData.count();
size_t vertexStride = gp->getVertexStride();
SkASSERT(vertexStride == sizeof(CircleVertex));
@@ -916,20 +889,11 @@ public:
// Setup geometry processor
SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->color(),
this->stroke(),
- invert));
+ invert,
+ this->usesLocalCoords()));
batchTarget->initDraw(gp, pipeline);
- // TODO this is hacky, but the only way we have to initialize the GP is to use the
- // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
- // everywhere we can remove this nastiness
- GrPipelineInfo init;
- init.fColorIgnored = fBatch.fColorIgnored;
- init.fOverrideColor = GrColor_ILLEGAL;
- init.fCoverageIgnored = fBatch.fCoverageIgnored;
- init.fUsesLocalCoords = this->usesLocalCoords();
- gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
-
int instanceCount = fGeoData.count();
QuadHelper helper;
size_t vertexStride = gp->getVertexStride();
@@ -1184,20 +1148,11 @@ public:
// Setup geometry processor
SkAutoTUnref<GrGeometryProcessor> gp(DIEllipseEdgeEffect::Create(this->color(),
this->viewMatrix(),
- this->mode()));
+ this->mode(),
+ this->usesLocalCoords()));
batchTarget->initDraw(gp, pipeline);
- // TODO this is hacky, but the only way we have to initialize the GP is to use the
- // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
- // everywhere we can remove this nastiness
- GrPipelineInfo init;
- init.fColorIgnored = fBatch.fColorIgnored;
- init.fOverrideColor = GrColor_ILLEGAL;
- init.fCoverageIgnored = fBatch.fCoverageIgnored;
- init.fUsesLocalCoords = this->usesLocalCoords();
- gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
-
int instanceCount = fGeoData.count();
size_t vertexStride = gp->getVertexStride();
SkASSERT(vertexStride == sizeof(DIEllipseVertex));
@@ -1549,20 +1504,11 @@ public:
// Setup geometry processor
SkAutoTUnref<GrGeometryProcessor> gp(CircleEdgeEffect::Create(this->color(),
this->stroke(),
- invert));
+ invert,
+ this->usesLocalCoords()));
batchTarget->initDraw(gp, pipeline);
- // TODO this is hacky, but the only way we have to initialize the GP is to use the
- // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
- // everywhere we can remove this nastiness
- GrPipelineInfo init;
- init.fColorIgnored = fBatch.fColorIgnored;
- init.fOverrideColor = GrColor_ILLEGAL;
- init.fCoverageIgnored = fBatch.fCoverageIgnored;
- init.fUsesLocalCoords = this->usesLocalCoords();
- gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
-
int instanceCount = fGeoData.count();
size_t vertexStride = gp->getVertexStride();
SkASSERT(vertexStride == sizeof(CircleVertex));
@@ -1731,20 +1677,11 @@ public:
// Setup geometry processor
SkAutoTUnref<GrGeometryProcessor> gp(EllipseEdgeEffect::Create(this->color(),
this->stroke(),
- invert));
+ invert,
+ this->usesLocalCoords()));
batchTarget->initDraw(gp, pipeline);
- // TODO this is hacky, but the only way we have to initialize the GP is to use the
- // GrPipelineInfo struct so we can generate the correct shader. Once we have GrBatch
- // everywhere we can remove this nastiness
- GrPipelineInfo init;
- init.fColorIgnored = fBatch.fColorIgnored;
- init.fOverrideColor = GrColor_ILLEGAL;
- init.fCoverageIgnored = fBatch.fCoverageIgnored;
- init.fUsesLocalCoords = this->usesLocalCoords();
- gp->initBatchTracker(batchTarget->currentBatchTracker(), init);
-
int instanceCount = fGeoData.count();
size_t vertexStride = gp->getVertexStride();
SkASSERT(vertexStride == sizeof(EllipseVertex));
« no previous file with comments | « src/gpu/GrGeometryProcessor.h ('k') | src/gpu/GrPathProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698