GrTessellator: abstract vertex allocation into caller.
This abstracts all vertex allocation out of GrTessellator via a VertexBuffer interface. This removes all GPU-related calls from GrTessellator.
It also factors vertex drawing into GrTessellatingPathRenderer::drawVertices(), and makes tessellate() (now draw() also responsible for drawing. This means the cache hit case is clearer as an early-out,
and storing into cache is done in draw() as well.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1776003002
Review URL: https://codereview.chromium.org/1776003002
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index a8fa79e..f4195df 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -7,17 +7,11 @@
#include "GrTessellator.h"
-#include "GrBatchFlushState.h"
-#include "GrBatchTest.h"
-#include "GrDefaultGeoProcFactory.h"
#include "GrPathUtils.h"
-#include "GrVertices.h"
-#include "GrResourceCache.h"
-#include "GrResourceProvider.h"
-#include "SkGeometry.h"
-#include "SkChunkAlloc.h"
-#include "batches/GrVertexBatch.h"
+#include "SkChunkAlloc.h"
+#include "SkGeometry.h"
+#include "SkPath.h"
#include <stdio.h>
@@ -1370,8 +1364,7 @@
// Stage 6: Triangulate the monotone polygons into a vertex buffer.
int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
- GrResourceProvider* resourceProvider,
- SkAutoTUnref<GrVertexBuffer>& vertexBuffer, bool canMapVB, bool* isLinear) {
+ VertexAllocator* vertexAllocator, bool* isLinear) {
int contourCnt;
int sizeEstimate;
get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstimate);
@@ -1387,21 +1380,11 @@
return 0;
}
- size_t size = count * sizeof(SkPoint);
- if (!vertexBuffer.get() || vertexBuffer->gpuMemorySize() < size) {
- vertexBuffer.reset(resourceProvider->createVertexBuffer(
- size, GrResourceProvider::kStatic_BufferUsage, 0));
- }
- if (!vertexBuffer.get()) {
+ SkPoint* verts = vertexAllocator->lock(count);
+ if (!verts) {
SkDebugf("Could not allocate vertices\n");
return 0;
}
- SkPoint* verts;
- if (canMapVB) {
- verts = static_cast<SkPoint*>(vertexBuffer->map());
- } else {
- verts = new SkPoint[count];
- }
SkPoint* end = verts;
for (Poly* poly = polys; poly; poly = poly->fNext) {
if (apply_fill_type(fillType, poly->fWinding)) {
@@ -1411,13 +1394,7 @@
int actualCount = static_cast<int>(end - verts);
LOG("actual count: %d\n", actualCount);
SkASSERT(actualCount <= count);
- if (canMapVB) {
- vertexBuffer->unmap();
- } else {
- vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint));
- delete[] verts;
- }
-
+ vertexAllocator->unlock(actualCount);
return actualCount;
}