From 6599efffeef3168dfc68dca99c30454c5c23b859 Mon Sep 17 00:00:00 2001 From: senorblanco Date: Thu, 10 Mar 2016 08:38:45 -0800 Subject: 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 --- src/gpu/GrTessellator.cpp | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) (limited to 'src/gpu/GrTessellator.cpp') diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp index a8fa79e560..f4195dfb03 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 @@ -1370,8 +1364,7 @@ namespace GrTessellator { // Stage 6: Triangulate the monotone polygons into a vertex buffer. int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, - GrResourceProvider* resourceProvider, - SkAutoTUnref& 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 @@ int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBo 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(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 PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBo int actualCount = static_cast(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; } -- cgit v1.2.3