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

Unified Diff: src/gpu/batches/GrAAFillRectBatch.cpp

Issue 2115673002: Remove unneeded helpers in AA and non-AA rect GrBatch subclasses (Closed) Base URL: https://chromium.googlesource.com/skia.git@rectgeoms2
Patch Set: Add back \n to debug print Created 4 years, 6 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 | « no previous file | src/gpu/batches/GrNonAAFillRectBatch.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/batches/GrAAFillRectBatch.cpp
diff --git a/src/gpu/batches/GrAAFillRectBatch.cpp b/src/gpu/batches/GrAAFillRectBatch.cpp
index cba91c67e64891ef2f97793277e4a4e041054786..f8d4f8d03994d2b463cc0f5a99dbae1940a97eaf 100644
--- a/src/gpu/batches/GrAAFillRectBatch.cpp
+++ b/src/gpu/batches/GrAAFillRectBatch.cpp
@@ -200,13 +200,16 @@ public:
static AAFillRectNoLocalMatrixBatch* Create() { return new AAFillRectNoLocalMatrixBatch; }
- const char* name() const override { return Name(); }
+ const char* name() const override { return "AAFillRectBatchNoLocalMatrix"; }
SkString dumpInfo() const override {
SkString str;
str.appendf("# batched: %d\n", fGeoData.count());
for (int i = 0; i < fGeoData.count(); ++i) {
- str.append(DumpInfo(fGeoData[i], i));
+ const Geometry& geo = fGeoData[i];
+ str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
+ i, geo.fColor,
+ geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect.fBottom);
}
str.append(INHERITED::dumpInfo());
return str;
@@ -217,7 +220,7 @@ public:
GrBatchToXPOverrides* overrides) const override {
// When this is called on a batch, there is only one geometry bundle
color->setKnownFourComponents(fGeoData[0].fColor);
- InitInvariantOutputCoverage(coverage);
+ coverage->setUnknownSingleComponent();
}
void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
@@ -228,92 +231,32 @@ public:
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
// After seeding, the client should call init() so the Batch can initialize itself
- void init() {
- const Geometry& geo = fGeoData[0];
- SetBounds(geo, &fBounds);
- }
-
- void updateBoundsAfterAppend() {
- const Geometry& geo = fGeoData.back();
- UpdateBoundsAfterAppend(geo, &fBounds);
- }
+ void init() { fBounds = fGeoData[0].fDevRect; }
private:
- static const int kVertsPerInstance = kVertsPerAAFillRect;
- static const int kIndicesPerInstance = kIndicesPerAAFillRect;
-
- static void InitInvariantOutputCoverage(GrInitInvariantOutput* out) {
- out->setUnknownSingleComponent();
- }
-
- static const GrBuffer* GetIndexBuffer(GrResourceProvider* rp) {
- return get_index_buffer(rp);
- }
-
- static void SetBounds(const Geometry& geo, SkRect* outBounds) {
- *outBounds = geo.fDevRect;
- }
-
- static void UpdateBoundsAfterAppend(const Geometry& geo, SkRect* outBounds) {
- outBounds->join(geo.fDevRect);
- }
-
- static const char* Name() { return "AAFillRectBatchNoLocalMatrix"; }
-
- static SkString DumpInfo(const Geometry& geo, int index) {
- SkString str;
- str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
- index,
- geo.fColor,
- geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect.fBottom);
- return str;
- }
-
- static bool CanCombine(const Geometry& mine, const Geometry& theirs,
- const GrXPOverridesForBatch& overrides) {
- // We apply the viewmatrix to the rect points on the cpu. However, if the pipeline uses
- // local coords then we won't be able to batch. We could actually upload the viewmatrix
- // using vertex attributes in these cases, but haven't investigated that
- return !overrides.readsLocalCoords() || mine.fViewMatrix.cheapEqualTo(theirs.fViewMatrix);
- }
-
- static sk_sp<GrGeometryProcessor> MakeGP(const Geometry& geo,
- const GrXPOverridesForBatch& overrides) {
- sk_sp<GrGeometryProcessor> gp =
- create_fill_rect_gp(geo.fViewMatrix, overrides,
- GrDefaultGeoProcFactory::LocalCoords::kUsePosition_Type);
-
- SkASSERT(overrides.canTweakAlphaForCoverage() ?
- gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
- gp->getVertexStride() ==
- sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
- return gp;
- }
-
- static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo,
- const GrXPOverridesForBatch& overrides) {
- generate_aa_fill_rect_geometry(vertices, vertexStride,
- geo.fColor, geo.fViewMatrix, geo.fRect, geo.fDevRect,
- overrides, nullptr);
- }
-
AAFillRectNoLocalMatrixBatch() : INHERITED(ClassID()) {}
void onPrepareDraws(Target* target) const override {
- sk_sp<GrGeometryProcessor> gp(MakeGP(this->seedGeometry(), fOverrides));
+ sk_sp<GrGeometryProcessor> gp =
+ create_fill_rect_gp(fGeoData[0].fViewMatrix, fOverrides,
+ GrDefaultGeoProcFactory::LocalCoords::kUsePosition_Type);
if (!gp) {
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
+ SkASSERT(fOverrides.canTweakAlphaForCoverage() ?
+ gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) :
+ gp->getVertexStride() ==
+ sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr));
size_t vertexStride = gp->getVertexStride();
int instanceCount = fGeoData.count();
- SkAutoTUnref<const GrBuffer> indexBuffer(GetIndexBuffer(target->resourceProvider()));
+ SkAutoTUnref<const GrBuffer> indexBuffer(get_index_buffer(target->resourceProvider()));
InstancedHelper helper;
void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride,
- indexBuffer, kVertsPerInstance,
- kIndicesPerInstance, instanceCount);
+ indexBuffer, kVertsPerAAFillRect,
+ kIndicesPerAAFillRect, instanceCount);
if (!vertices || !indexBuffer) {
SkDebugf("Could not allocate vertices\n");
return;
@@ -321,14 +264,15 @@ private:
for (int i = 0; i < instanceCount; i++) {
intptr_t verts = reinterpret_cast<intptr_t>(vertices) +
- i * kVertsPerInstance * vertexStride;
- Tesselate(verts, vertexStride, fGeoData[i], fOverrides);
+ i * kVertsPerAAFillRect * vertexStride;
+ generate_aa_fill_rect_geometry(verts, vertexStride,
+ fGeoData[i].fColor, fGeoData[i].fViewMatrix,
+ fGeoData[i].fRect, fGeoData[i].fDevRect, fOverrides,
+ nullptr);
}
helper.recordDraw(target, gp.get());
}
- const Geometry& seedGeometry() const { return fGeoData[0]; }
-
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
AAFillRectNoLocalMatrixBatch* that = t->cast<AAFillRectNoLocalMatrixBatch>();
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
@@ -336,7 +280,11 @@ private:
return false;
}
- if (!CanCombine(this->seedGeometry(), that->seedGeometry(), fOverrides)) {
+ // We apply the viewmatrix to the rect points on the cpu. However, if the pipeline uses
+ // local coords then we won't be able to batch. We could actually upload the viewmatrix
+ // using vertex attributes in these cases, but haven't investigated that
+ if (fOverrides.readsLocalCoords() &&
+ !fGeoData[0].fViewMatrix.cheapEqualTo(that->fGeoData[0].fViewMatrix)) {
return false;
}
@@ -371,13 +319,16 @@ public:
static AAFillRectLocalMatrixBatch* Create() { return new AAFillRectLocalMatrixBatch; }
- const char* name() const override { return Name(); }
+ const char* name() const override { return "AAFillRectBatchLocalMatrix"; }
SkString dumpInfo() const override {
SkString str;
str.appendf("# batched: %d\n", fGeoData.count());
for (int i = 0; i < fGeoData.count(); ++i) {
- str.append(DumpInfo(fGeoData[i], i));
+ const Geometry& geo = fGeoData[i];
+ str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
+ i, geo.fColor,
+ geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect.fBottom);
}
str.append(INHERITED::dumpInfo());
return str;
@@ -388,7 +339,7 @@ public:
GrBatchToXPOverrides* overrides) const override {
// When this is called on a batch, there is only one geometry bundle
color->setKnownFourComponents(fGeoData[0].fColor);
- InitInvariantOutputCoverage(coverage);
+ coverage->setUnknownSingleComponent();
}
void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
@@ -399,90 +350,33 @@ public:
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
// After seeding, the client should call init() so the Batch can initialize itself
- void init() {
- const Geometry& geo = fGeoData[0];
- SetBounds(geo, &fBounds);
- }
-
- void updateBoundsAfterAppend() {
- const Geometry& geo = fGeoData.back();
- UpdateBoundsAfterAppend(geo, &fBounds);
- }
+ void init() { fBounds = fGeoData[0].fDevRect; }
private:
- static const int kVertsPerInstance = kVertsPerAAFillRect;
- static const int kIndicesPerInstance = kIndicesPerAAFillRect;
-
- static void InitInvariantOutputCoverage(GrInitInvariantOutput* out) {
- out->setUnknownSingleComponent();
- }
-
- static const GrBuffer* GetIndexBuffer(GrResourceProvider* rp) {
- return get_index_buffer(rp);
- }
-
- static void SetBounds(const Geometry& geo, SkRect* outBounds) {
- *outBounds = geo.fDevRect;
- }
-
- static void UpdateBoundsAfterAppend(const Geometry& geo, SkRect* outBounds) {
- outBounds->join(geo.fDevRect);
- }
-
- static const char* Name() { return "AAFillRectBatchLocalMatrix"; }
-
- static SkString DumpInfo(const Geometry& geo, int index) {
- SkString str;
- str.appendf("%d: Color: 0x%08x, Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n",
- index,
- geo.fColor,
- geo.fRect.fLeft, geo.fRect.fTop, geo.fRect.fRight, geo.fRect.fBottom);
- return str;
- }
-
- static bool CanCombine(const Geometry& mine, const Geometry& theirs,
- const GrXPOverridesForBatch& overrides) {
- return true;
- }
-
- static sk_sp<GrGeometryProcessor> MakeGP(const Geometry& geo,
- const GrXPOverridesForBatch& overrides) {
- sk_sp<GrGeometryProcessor> gp =
- create_fill_rect_gp(geo.fViewMatrix, overrides,
- GrDefaultGeoProcFactory::LocalCoords::kHasExplicit_Type);
-
- SkASSERT(overrides.canTweakAlphaForCoverage() ?
- gp->getVertexStride() ==
- sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr) :
- gp->getVertexStride() ==
- sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordCoverage));
- return gp;
- }
-
- static void Tesselate(intptr_t vertices, size_t vertexStride, const Geometry& geo,
- const GrXPOverridesForBatch& overrides) {
- generate_aa_fill_rect_geometry(vertices, vertexStride,
- geo.fColor, geo.fViewMatrix, geo.fRect, geo.fDevRect,
- overrides, &geo.fLocalMatrix);
- }
-
AAFillRectLocalMatrixBatch() : INHERITED(ClassID()) {}
void onPrepareDraws(Target* target) const override {
- sk_sp<GrGeometryProcessor> gp(MakeGP(this->seedGeometry(), fOverrides));
+ sk_sp<GrGeometryProcessor> gp =
+ create_fill_rect_gp(fGeoData[0].fViewMatrix, fOverrides,
+ GrDefaultGeoProcFactory::LocalCoords::kHasExplicit_Type);
if (!gp) {
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
+ SkASSERT(fOverrides.canTweakAlphaForCoverage() ?
+ gp->getVertexStride() ==
+ sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr) :
+ gp->getVertexStride() ==
+ sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordCoverage));
size_t vertexStride = gp->getVertexStride();
int instanceCount = fGeoData.count();
- SkAutoTUnref<const GrBuffer> indexBuffer(GetIndexBuffer(target->resourceProvider()));
+ SkAutoTUnref<const GrBuffer> indexBuffer(get_index_buffer(target->resourceProvider()));
InstancedHelper helper;
void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride,
- indexBuffer, kVertsPerInstance,
- kIndicesPerInstance, instanceCount);
+ indexBuffer, kVertsPerAAFillRect,
+ kIndicesPerAAFillRect, instanceCount);
if (!vertices || !indexBuffer) {
SkDebugf("Could not allocate vertices\n");
return;
@@ -490,14 +384,15 @@ private:
for (int i = 0; i < instanceCount; i++) {
intptr_t verts = reinterpret_cast<intptr_t>(vertices) +
- i * kVertsPerInstance * vertexStride;
- Tesselate(verts, vertexStride, fGeoData[i], fOverrides);
+ i * kVertsPerAAFillRect * vertexStride;
+ generate_aa_fill_rect_geometry(verts, vertexStride, fGeoData[i].fColor,
+ fGeoData[i].fViewMatrix, fGeoData[i].fRect,
+ fGeoData[i].fDevRect, fOverrides,
+ &fGeoData[i].fLocalMatrix);
}
helper.recordDraw(target, gp.get());
}
- const Geometry& seedGeometry() const { return fGeoData[0]; }
-
bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
AAFillRectLocalMatrixBatch* that = t->cast<AAFillRectLocalMatrixBatch>();
if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(),
@@ -505,10 +400,6 @@ private:
return false;
}
- if (!CanCombine(this->seedGeometry(), that->seedGeometry(), fOverrides)) {
- return false;
- }
-
// In the event of two batches, one who can tweak, one who cannot, we just fall back to
// not tweaking
if (fOverrides.canTweakAlphaForCoverage() && !that->fOverrides.canTweakAlphaForCoverage()) {
« no previous file with comments | « no previous file | src/gpu/batches/GrNonAAFillRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698