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

Unified Diff: src/gpu/GrAADistanceFieldPathRenderer.cpp

Issue 1122673002: Start on simplifying generateGeometry() overrides (Closed) Base URL: https://skia.googlesource.com/skia.git@ibcache
Patch Set: whitespace, remove debug return Created 5 years, 8 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/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrAAHairLinePathRenderer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAADistanceFieldPathRenderer.cpp
diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp
index ca8c52fa348289ad62ad95f0d530c46857f55db0..312b731fd7a2b35ce130be2ddd0f01699f0812fb 100755
--- a/src/gpu/GrAADistanceFieldPathRenderer.cpp
+++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp
@@ -13,9 +13,9 @@
#include "GrBufferAllocPool.h"
#include "GrContext.h"
#include "GrPipelineBuilder.h"
+#include "GrResourceProvider.h"
#include "GrSurfacePriv.h"
#include "GrSWMaskHelper.h"
-#include "GrResourceProvider.h"
#include "GrTexturePriv.h"
#include "GrVertexBuffer.h"
#include "effects/GrDistanceFieldGeoProc.h"
@@ -169,6 +169,13 @@ public:
fBatch.fCoverageIgnored = init.fCoverageIgnored;
}
+ struct FlushInfo {
+ SkAutoTUnref<const GrVertexBuffer> fVertexBuffer;
+ SkAutoTUnref<const GrIndexBuffer> fIndexBuffer;
+ int fVertexOffset;
+ int fInstancesToFlush;
+ };
+
void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override {
int instanceCount = fGeoData.count();
@@ -195,43 +202,25 @@ public:
this->initDraw(batchTarget, dfProcessor, pipeline);
- static const int kVertsPerQuad = 4;
- static const int kIndicesPerQuad = 6;
-
- SkAutoTUnref<const GrIndexBuffer> indexBuffer(
- batchTarget->resourceProvider()->refQuadIndexBuffer());
+ FlushInfo flushInfo;
// allocate vertices
size_t vertexStride = dfProcessor->getVertexStride();
SkASSERT(vertexStride == 2 * sizeof(SkPoint));
- const GrVertexBuffer* vertexBuffer;
- int vertexCount = kVertsPerQuad * instanceCount;
- int firstVertex;
+ const GrVertexBuffer* vertexBuffer;
void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
- vertexCount,
+ kVerticesPerQuad * instanceCount,
&vertexBuffer,
- &firstVertex);
-
- if (!vertices || !indexBuffer) {
+ &flushInfo.fVertexOffset);
+ flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
+ flushInfo.fIndexBuffer.reset(batchTarget->resourceProvider()->refQuadIndexBuffer());
+ if (!vertices || !flushInfo.fIndexBuffer) {
SkDebugf("Could not allocate vertices\n");
return;
}
- // We may have to flush while uploading path data to the atlas, so we set up the draw here
- int maxInstancesPerDraw = indexBuffer->maxQuads();
-
- GrDrawTarget::DrawInfo drawInfo;
- drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType);
- drawInfo.setStartVertex(0);
- drawInfo.setStartIndex(0);
- drawInfo.setVerticesPerInstance(kVertsPerQuad);
- drawInfo.setIndicesPerInstance(kIndicesPerQuad);
- drawInfo.adjustStartVertex(firstVertex);
- drawInfo.setVertexBuffer(vertexBuffer);
- drawInfo.setIndexBuffer(indexBuffer);
-
- int instancesToFlush = 0;
+ flushInfo.fInstancesToFlush = 0;
for (int i = 0; i < instanceCount; i++) {
Geometry& args = fGeoData[i];
@@ -265,9 +254,7 @@ public:
if (!this->addPathToAtlas(batchTarget,
dfProcessor,
pipeline,
- &drawInfo,
- &instancesToFlush,
- maxInstancesPerDraw,
+ &flushInfo,
atlas,
args.fPathData,
args.fPath,
@@ -284,21 +271,21 @@ public:
// Now set vertices
intptr_t offset = reinterpret_cast<intptr_t>(vertices);
- offset += i * kVertsPerQuad * vertexStride;
+ offset += i * kVerticesPerQuad * vertexStride;
SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
- this->drawPath(batchTarget,
- atlas,
- pipeline,
- dfProcessor,
- positions,
- vertexStride,
- this->viewMatrix(),
- args.fPath,
- args.fPathData);
- instancesToFlush++;
+ this->writePathVertices(batchTarget,
+ atlas,
+ pipeline,
+ dfProcessor,
+ positions,
+ vertexStride,
+ this->viewMatrix(),
+ args.fPath,
+ args.fPathData);
+ flushInfo.fInstancesToFlush++;
}
- this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDraw);
+ this->flush(batchTarget, &flushInfo);
}
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
@@ -325,9 +312,7 @@ private:
bool addPathToAtlas(GrBatchTarget* batchTarget,
const GrGeometryProcessor* dfProcessor,
const GrPipeline* pipeline,
- GrDrawTarget::DrawInfo* drawInfo,
- int* instancesToFlush,
- int maxInstancesPerDraw,
+ FlushInfo* flushInfo,
GrBatchAtlas* atlas,
PathData* pathData,
const SkPath& path,
@@ -429,9 +414,8 @@ private:
bool success = atlas->addToAtlas(&id, batchTarget, width, height, dfStorage.get(),
&atlasLocation);
if (!success) {
- this->flush(batchTarget, drawInfo, *instancesToFlush, maxInstancesPerDraw);
+ this->flush(batchTarget, flushInfo);
this->initDraw(batchTarget, dfProcessor, pipeline);
- *instancesToFlush = 0;
SkDEBUGCODE(success =) atlas->addToAtlas(&id, batchTarget, width, height,
dfStorage.get(), &atlasLocation);
@@ -467,15 +451,15 @@ private:
return true;
}
- void drawPath(GrBatchTarget* target,
- GrBatchAtlas* atlas,
- const GrPipeline* pipeline,
- const GrGeometryProcessor* gp,
- SkPoint* positions,
- size_t vertexStride,
- const SkMatrix& viewMatrix,
- const SkPath& path,
- const PathData* pathData) {
+ void writePathVertices(GrBatchTarget* target,
+ GrBatchAtlas* atlas,
+ const GrPipeline* pipeline,
+ const GrGeometryProcessor* gp,
+ SkPoint* positions,
+ size_t vertexStride,
+ const SkMatrix& viewMatrix,
+ const SkPath& path,
+ const PathData* pathData) {
GrTexture* texture = atlas->getTexture();
SkScalar dx = pathData->fBounds.fLeft;
@@ -522,20 +506,18 @@ private:
dfProcessor->initBatchTracker(batchTarget->currentBatchTracker(), init);
}
- void flush(GrBatchTarget* batchTarget,
- GrDrawTarget::DrawInfo* drawInfo,
- int instanceCount,
- int maxInstancesPerDraw) {
- while (instanceCount) {
- drawInfo->setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw));
- drawInfo->setVertexCount(drawInfo->instanceCount() * drawInfo->verticesPerInstance());
- drawInfo->setIndexCount(drawInfo->instanceCount() * drawInfo->indicesPerInstance());
-
- batchTarget->draw(*drawInfo);
-
- drawInfo->setStartVertex(drawInfo->startVertex() + drawInfo->vertexCount());
- instanceCount -= drawInfo->instanceCount();
- }
+ void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) {
+ GrDrawTarget::DrawInfo drawInfo;
+ int instancesToFlush = flushInfo->fInstancesToFlush;
+ int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads();
+ drawInfo.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
+ flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad,
+ kIndicesPerQuad, &instancesToFlush, maxInstancesPerDraw);
+ do {
+ batchTarget->draw(drawInfo);
+ } while (drawInfo.nextInstances(&instancesToFlush, maxInstancesPerDraw));
+ flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFlush;
+ flushInfo->fInstancesToFlush = 0;
}
GrColor color() const { return fBatch.fColor; }
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrAAHairLinePathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698