Split GrDrawBatch and GrVertexBatch into their own files
TBR=joshualitt@google.com
Review URL: https://codereview.chromium.org/1296483002
diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp
index 1c4a0b1..e9b417f 100644
--- a/gm/convexpolyeffect.cpp
+++ b/gm/convexpolyeffect.cpp
@@ -23,6 +23,7 @@
#include "SkTLList.h"
#include "batches/GrTestBatch.h"
+#include "batches/GrVertexBatch.h"
#include "effects/GrConvexPolyEffect.h"
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index a9871c4..892b873 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -227,6 +227,8 @@
'<(skia_src_path)/gpu/batches/GrBWFillRectBatch.cpp',
'<(skia_src_path)/gpu/batches/GrBatch.cpp',
'<(skia_src_path)/gpu/batches/GrBatch.h',
+ '<(skia_src_path)/gpu/batches/GrDrawBatch.cpp',
+ '<(skia_src_path)/gpu/batches/GrDrawBatch.h',
'<(skia_src_path)/gpu/batches/GrDrawAtlasBatch.cpp',
'<(skia_src_path)/gpu/batches/GrDrawAtlasBatch.h',
'<(skia_src_path)/gpu/batches/GrDrawVerticesBatch.cpp',
@@ -235,6 +237,8 @@
'<(skia_src_path)/gpu/batches/GrRectBatchFactory.cpp',
'<(skia_src_path)/gpu/batches/GrStrokeRectBatch.cpp',
'<(skia_src_path)/gpu/batches/GrStrokeRectBatch.h',
+ '<(skia_src_path)/gpu/batches/GrVertexBatch.cpp',
+ '<(skia_src_path)/gpu/batches/GrVertexBatch.h',
'<(skia_src_path)/gpu/effects/Gr1DKernelEffect.h',
'<(skia_src_path)/gpu/effects/GrConfigConversionEffect.cpp',
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index ac142e2..3a7d4d2 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -24,7 +24,7 @@
#include "SkPathPriv.h"
#include "SkString.h"
#include "SkTraceEvent.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "gl/GrGLProcessor.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
diff --git a/src/gpu/GrAADistanceFieldPathRenderer.cpp b/src/gpu/GrAADistanceFieldPathRenderer.cpp
index c4d59dd..682ec55 100755
--- a/src/gpu/GrAADistanceFieldPathRenderer.cpp
+++ b/src/gpu/GrAADistanceFieldPathRenderer.cpp
@@ -17,7 +17,7 @@
#include "GrSWMaskHelper.h"
#include "GrTexturePriv.h"
#include "GrVertexBuffer.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "effects/GrDistanceFieldGeoProc.h"
#include "SkDistanceFieldGen.h"
diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp
index f65fb74..b1be535 100644
--- a/src/gpu/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/GrAAHairLinePathRenderer.cpp
@@ -22,7 +22,7 @@
#include "SkStroke.h"
#include "SkTemplates.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "effects/GrBezierEffect.h"
diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp
index a019ed9..d1dc00d 100644
--- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp
@@ -23,7 +23,7 @@
#include "SkString.h"
#include "SkTraceEvent.h"
#include "SkPathPriv.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "gl/GrGLProcessor.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 3ba32cf..b6e0acc 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -36,7 +36,7 @@
#include "SkTextBlob.h"
#include "SkTextMapStateProc.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "effects/GrBitmapTextGeoProc.h"
#include "effects/GrDistanceFieldGeoProc.h"
diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp
index 5353877..9ab0204 100644
--- a/src/gpu/GrDefaultPathRenderer.cpp
+++ b/src/gpu/GrDefaultPathRenderer.cpp
@@ -20,7 +20,7 @@
#include "SkTLazy.h"
#include "SkTraceEvent.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
GrDefaultPathRenderer::GrDefaultPathRenderer(bool separateStencilSupport,
bool stencilWrapOpsSupport)
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 985254e..0184890 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -20,7 +20,7 @@
#include "GrTexture.h"
#include "GrVertexBuffer.h"
-#include "batches/GrBatch.h"
+#include "batches/GrDrawBatch.h"
#include "batches/GrRectBatchFactory.h"
#include "SkStrokeRec.h"
diff --git a/src/gpu/GrImmediateDrawTarget.cpp b/src/gpu/GrImmediateDrawTarget.cpp
index 3bff379..5f8d4e6 100644
--- a/src/gpu/GrImmediateDrawTarget.cpp
+++ b/src/gpu/GrImmediateDrawTarget.cpp
@@ -13,7 +13,8 @@
#include "SkRect.h"
#include "SkTypes.h"
-#include "batches/GrBatch.h"
+#include "batches/GrDrawBatch.h"
+#include "batches/GrVertexBatch.h"
GrImmediateDrawTarget::GrImmediateDrawTarget(GrContext* context)
: INHERITED(context)
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 7b33afd..fc6ecfa 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -19,7 +19,7 @@
#include "SkRRect.h"
#include "SkStrokeRec.h"
#include "SkTLazy.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "effects/GrRRectEffect.h"
#include "gl/GrGLProcessor.h"
#include "gl/GrGLGeometryProcessor.h"
diff --git a/src/gpu/GrProcOptInfo.cpp b/src/gpu/GrProcOptInfo.cpp
index e56fb74..af6b81e 100644
--- a/src/gpu/GrProcOptInfo.cpp
+++ b/src/gpu/GrProcOptInfo.cpp
@@ -9,7 +9,7 @@
#include "GrGeometryProcessor.h"
-#include "batches/GrBatch.h"
+#include "batches/GrDrawBatch.h"
void GrProcOptInfo::calcColorWithBatch(const GrDrawBatch* batch,
const GrFragmentStage* stages,
diff --git a/src/gpu/GrTargetCommands.cpp b/src/gpu/GrTargetCommands.cpp
index 2347db8..3f9d7c8 100644
--- a/src/gpu/GrTargetCommands.cpp
+++ b/src/gpu/GrTargetCommands.cpp
@@ -9,6 +9,9 @@
#include "GrBufferedDrawTarget.h"
+#include "batches/GrDrawBatch.h"
+#include "batches/GrVertexBatch.h"
+
GrBATCH_SPEW(int32_t GrTargetCommands::Cmd::gUniqueID = 0;)
void GrTargetCommands::reset() {
diff --git a/src/gpu/GrTargetCommands.h b/src/gpu/GrTargetCommands.h
index 0240480..bf973b6 100644
--- a/src/gpu/GrTargetCommands.h
+++ b/src/gpu/GrTargetCommands.h
@@ -18,7 +18,7 @@
#include "SkRect.h"
#include "SkTypes.h"
-#include "batches/GrBatch.h"
+#include "batches/GrDrawBatch.h"
class GrBufferedDrawTarget;
diff --git a/src/gpu/GrTessellatingPathRenderer.cpp b/src/gpu/GrTessellatingPathRenderer.cpp
index 30be341..c2a9900 100644
--- a/src/gpu/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/GrTessellatingPathRenderer.cpp
@@ -17,7 +17,7 @@
#include "SkChunkAlloc.h"
#include "SkGeometry.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include <stdio.h>
diff --git a/src/gpu/batches/GrAAFillRectBatch.cpp b/src/gpu/batches/GrAAFillRectBatch.cpp
index 9b19028..e8cef78 100644
--- a/src/gpu/batches/GrAAFillRectBatch.cpp
+++ b/src/gpu/batches/GrAAFillRectBatch.cpp
@@ -7,12 +7,12 @@
#include "GrAAFillRectBatch.h"
-#include "GrBatch.h"
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrResourceKey.h"
#include "GrResourceProvider.h"
#include "GrTypes.h"
+#include "GrVertexBatch.h"
#include "SkMatrix.h"
#include "SkRect.h"
diff --git a/src/gpu/batches/GrAAStrokeRectBatch.h b/src/gpu/batches/GrAAStrokeRectBatch.h
index b6fb89f..f9c4f3e 100644
--- a/src/gpu/batches/GrAAStrokeRectBatch.h
+++ b/src/gpu/batches/GrAAStrokeRectBatch.h
@@ -8,9 +8,9 @@
#ifndef GrAAStrokeRectBatch_DEFINED
#define GrAAStrokeRectBatch_DEFINED
-#include "GrBatch.h"
#include "GrColor.h"
#include "GrTypes.h"
+#include "GrVertexBatch.h"
#include "SkMatrix.h"
#include "SkRect.h"
diff --git a/src/gpu/batches/GrBWFillRectBatch.cpp b/src/gpu/batches/GrBWFillRectBatch.cpp
index 0009789..c0c93c7 100644
--- a/src/gpu/batches/GrBWFillRectBatch.cpp
+++ b/src/gpu/batches/GrBWFillRectBatch.cpp
@@ -7,11 +7,11 @@
#include "GrBWFillRectBatch.h"
-#include "GrBatch.h"
#include "GrBatchTarget.h"
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
#include "GrPrimitiveProcessor.h"
+#include "GrVertexBatch.h"
class GrBatchTarget;
class SkMatrix;
diff --git a/src/gpu/batches/GrBatch.cpp b/src/gpu/batches/GrBatch.cpp
index b696d6b..a3a9884 100644
--- a/src/gpu/batches/GrBatch.cpp
+++ b/src/gpu/batches/GrBatch.cpp
@@ -6,8 +6,6 @@
*/
#include "GrBatch.h"
-#include "GrBatchTarget.h"
-#include "GrResourceProvider.h"
#include "GrMemoryPool.h"
#include "SkSpinlock.h"
@@ -58,67 +56,3 @@
}
GrBatch::~GrBatch() {}
-
-//////////////////////////////////////////////////////////////////////////////
-
-GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { }
-
-GrDrawBatch::~GrDrawBatch() {
- if (fPipelineInstalled) {
- this->pipeline()->~GrPipeline();
- }
-}
-
-bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) {
- GrPipelineOptimizations opts;
- void* location = fPipelineStorage.get();
- if (!GrPipeline::CreateAt(location, args, &opts)) {
- return false;
- }
- this->initBatchTracker(opts);
- fPipelineInstalled = true;
- return true;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-GrVertexBatch::GrVertexBatch() : fNumberOfDraws(0) {}
-
-void* GrVertexBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType primType,
- size_t vertexStride, const GrIndexBuffer* indexBuffer,
- int verticesPerInstance, int indicesPerInstance,
- int instancesToDraw) {
- SkASSERT(batchTarget);
- if (!indexBuffer) {
- return NULL;
- }
- const GrVertexBuffer* vertexBuffer;
- int firstVertex;
- int vertexCount = verticesPerInstance * instancesToDraw;
- void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount,
- &vertexBuffer, &firstVertex);
- if (!vertices) {
- SkDebugf("Vertices could not be allocated for instanced rendering.");
- return NULL;
- }
- SkASSERT(vertexBuffer);
- size_t ibSize = indexBuffer->gpuMemorySize();
- int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
-
- fVertices.initInstanced(primType, vertexBuffer, indexBuffer,
- firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw,
- maxInstancesPerDraw);
- return vertices;
-}
-
-void* GrVertexBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride,
- int quadsToDraw) {
- SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer(
- batchTarget->resourceProvider()->refQuadIndexBuffer());
- if (!quadIndexBuffer) {
- SkDebugf("Could not get quad index buffer.");
- return NULL;
- }
- return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertexStride,
- quadIndexBuffer, kVerticesPerQuad, kIndicesPerQuad, quadsToDraw);
-}
diff --git a/src/gpu/batches/GrBatch.h b/src/gpu/batches/GrBatch.h
index ef8f56c..7bb6af1 100644
--- a/src/gpu/batches/GrBatch.h
+++ b/src/gpu/batches/GrBatch.h
@@ -9,17 +9,11 @@
#define GrBatch_DEFINED
#include <new>
-#include "GrBatchTarget.h"
-#include "GrGeometryProcessor.h"
#include "GrNonAtomicRef.h"
-#include "GrVertices.h"
-#include "SkAtomics.h"
-#include "SkTypes.h"
-class GrGpu;
-class GrPipeline;
+#include "SkRect.h"
-struct GrInitInvariantOutput;
+class GrCaps;
/**
* GrBatch is the base class for all Ganesh deferred geometry generators. To facilitate
@@ -130,94 +124,4 @@
typedef GrNonAtomicRef INHERITED;
};
-/**
- * Base class for GrBatches that draw. These batches have a GrPipeline installed by GrDrawTarget.
- */
-class GrDrawBatch : public GrBatch {
-public:
- GrDrawBatch();
- ~GrDrawBatch() override;
-
- virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0;
- virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0;
-
- const GrPipeline* pipeline() const {
- SkASSERT(fPipelineInstalled);
- return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get());
- }
-
- bool installPipeline(const GrPipeline::CreateArgs&);
-
- // TODO no GrPrimitiveProcessors yet read fragment position
- bool willReadFragmentPosition() const { return false; }
-
-private:
- /**
- * initBatchTracker is a hook for the some additional overrides / optimization possibilities
- * from the GrXferProcessor.
- */
- virtual void initBatchTracker(const GrPipelineOptimizations&) = 0;
-
- SkAlignedSTStorage<1, GrPipeline> fPipelineStorage;
- bool fPipelineInstalled;
- typedef GrBatch INHERITED;
-};
-
-/**
- * Base class for vertex-based GrBatches.
- */
-class GrVertexBatch : public GrDrawBatch {
-public:
- GrVertexBatch();
-
- virtual void generateGeometry(GrBatchTarget*) = 0;
-
- // TODO this goes away when batches are everywhere
- void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; }
- int numberOfDraws() const { return fNumberOfDraws; }
-
-protected:
- /** Helper for rendering instances using an instanced index index buffer. This class creates the
- space for the vertices and flushes the draws to the batch target. */
- class InstancedHelper {
- public:
- InstancedHelper() {}
- /** Returns the allocated storage for the vertices. The caller should populate the before
- vertices before calling issueDraws(). */
- void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStride,
- const GrIndexBuffer*, int verticesPerInstance, int indicesPerInstance,
- int instancesToDraw);
-
- /** Call after init() to issue draws to the batch target.*/
- void issueDraw(GrBatchTarget* batchTarget) {
- SkASSERT(fVertices.instanceCount());
- batchTarget->draw(fVertices);
- }
- private:
- GrVertices fVertices;
- };
-
- static const int kVerticesPerQuad = 4;
- static const int kIndicesPerQuad = 6;
-
- /** A specialization of InstanceHelper for quad rendering. */
- class QuadHelper : private InstancedHelper {
- public:
- QuadHelper() : INHERITED() {}
- /** Finds the cached quad index buffer and reserves vertex space. Returns NULL on failure
- and on sucess a pointer to the vertex data that the caller should populate before
- calling issueDraws(). */
- void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToDraw);
-
- using InstancedHelper::issueDraw;
-
- private:
- typedef InstancedHelper INHERITED;
- };
-
-private:
- int fNumberOfDraws;
- typedef GrDrawBatch INHERITED;
-};
-
#endif
diff --git a/src/gpu/batches/GrDrawAtlasBatch.h b/src/gpu/batches/GrDrawAtlasBatch.h
index 6b46cfb..6e353ef 100644
--- a/src/gpu/batches/GrDrawAtlasBatch.h
+++ b/src/gpu/batches/GrDrawAtlasBatch.h
@@ -8,9 +8,9 @@
#ifndef GrDrawAtlasBatch_DEFINED
#define GrDrawAtlasBatch_DEFINED
-#include "GrBatch.h"
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
+#include "GrVertexBatch.h"
class GrDrawAtlasBatch : public GrVertexBatch {
public:
diff --git a/src/gpu/batches/GrDrawBatch.cpp b/src/gpu/batches/GrDrawBatch.cpp
new file mode 100644
index 0000000..5e5d412
--- /dev/null
+++ b/src/gpu/batches/GrDrawBatch.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrDrawBatch.h"
+
+GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { }
+
+GrDrawBatch::~GrDrawBatch() {
+ if (fPipelineInstalled) {
+ this->pipeline()->~GrPipeline();
+ }
+}
+
+bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) {
+ GrPipelineOptimizations opts;
+ void* location = fPipelineStorage.get();
+ if (!GrPipeline::CreateAt(location, args, &opts)) {
+ return false;
+ }
+ this->initBatchTracker(opts);
+ fPipelineInstalled = true;
+ return true;
+}
diff --git a/src/gpu/batches/GrDrawBatch.h b/src/gpu/batches/GrDrawBatch.h
new file mode 100644
index 0000000..8ac758e
--- /dev/null
+++ b/src/gpu/batches/GrDrawBatch.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrDrawBatch_DEFINED
+#define GrDrawBatch_DEFINED
+
+#include "GrBatch.h"
+#include "GrPipeline.h"
+
+struct GrInitInvariantOutput;
+
+/**
+ * Base class for GrBatches that draw. These batches have a GrPipeline installed by GrDrawTarget.
+ */
+class GrDrawBatch : public GrBatch {
+public:
+ GrDrawBatch();
+ ~GrDrawBatch() override;
+
+ virtual void getInvariantOutputColor(GrInitInvariantOutput* out) const = 0;
+ virtual void getInvariantOutputCoverage(GrInitInvariantOutput* out) const = 0;
+
+ const GrPipeline* pipeline() const {
+ SkASSERT(fPipelineInstalled);
+ return reinterpret_cast<const GrPipeline*>(fPipelineStorage.get());
+ }
+
+ bool installPipeline(const GrPipeline::CreateArgs&);
+
+ // TODO no GrPrimitiveProcessors yet read fragment position
+ bool willReadFragmentPosition() const { return false; }
+
+private:
+ /**
+ * initBatchTracker is a hook for the some additional overrides / optimization possibilities
+ * from the GrXferProcessor.
+ */
+ virtual void initBatchTracker(const GrPipelineOptimizations&) = 0;
+
+ SkAlignedSTStorage<1, GrPipeline> fPipelineStorage;
+ bool fPipelineInstalled;
+ typedef GrBatch INHERITED;
+};
+
+#endif
diff --git a/src/gpu/batches/GrDrawVerticesBatch.h b/src/gpu/batches/GrDrawVerticesBatch.h
index 11decbe..5e9628b 100644
--- a/src/gpu/batches/GrDrawVerticesBatch.h
+++ b/src/gpu/batches/GrDrawVerticesBatch.h
@@ -8,9 +8,9 @@
#ifndef GrDrawVerticesBatch_DEFINED
#define GrDrawVerticesBatch_DEFINED
-#include "GrBatch.h"
#include "GrColor.h"
#include "GrTypes.h"
+#include "GrVertexBatch.h"
#include "SkMatrix.h"
#include "SkRect.h"
#include "SkTDArray.h"
diff --git a/src/gpu/batches/GrStrokeRectBatch.h b/src/gpu/batches/GrStrokeRectBatch.h
index 2c891a4..31b11d9 100644
--- a/src/gpu/batches/GrStrokeRectBatch.h
+++ b/src/gpu/batches/GrStrokeRectBatch.h
@@ -8,9 +8,9 @@
#ifndef GrStrokeRectBatch_DEFINED
#define GrStrokeRectBatch_DEFINED
-#include "GrBatch.h"
#include "GrColor.h"
#include "GrDefaultGeoProcFactory.h"
+#include "GrVertexBatch.h"
class GrStrokeRectBatch : public GrVertexBatch {
public:
diff --git a/src/gpu/batches/GrTestBatch.h b/src/gpu/batches/GrTestBatch.h
index d8986b6..f72ea61 100644
--- a/src/gpu/batches/GrTestBatch.h
+++ b/src/gpu/batches/GrTestBatch.h
@@ -8,9 +8,11 @@
#ifndef GrTestBatch_DEFINED
#define GrTestBatch_DEFINED
+#include "GrBatchTarget.h"
+#include "GrGeometryProcessor.h"
#include "GrVertexBuffer.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
/*
* A simple batch only for testing purposes which actually doesn't batch at all, but can fit into
diff --git a/src/gpu/batches/GrVertexBatch.cpp b/src/gpu/batches/GrVertexBatch.cpp
new file mode 100644
index 0000000..e800422
--- /dev/null
+++ b/src/gpu/batches/GrVertexBatch.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrVertexBatch.h"
+#include "GrBatchTarget.h"
+#include "GrResourceProvider.h"
+
+GrVertexBatch::GrVertexBatch() : fNumberOfDraws(0) {}
+
+void* GrVertexBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType primType,
+ size_t vertexStride, const GrIndexBuffer* indexBuffer,
+ int verticesPerInstance, int indicesPerInstance,
+ int instancesToDraw) {
+ SkASSERT(batchTarget);
+ if (!indexBuffer) {
+ return NULL;
+ }
+ const GrVertexBuffer* vertexBuffer;
+ int firstVertex;
+ int vertexCount = verticesPerInstance * instancesToDraw;
+ void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount,
+ &vertexBuffer, &firstVertex);
+ if (!vertices) {
+ SkDebugf("Vertices could not be allocated for instanced rendering.");
+ return NULL;
+ }
+ SkASSERT(vertexBuffer);
+ size_t ibSize = indexBuffer->gpuMemorySize();
+ int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
+
+ fVertices.initInstanced(primType, vertexBuffer, indexBuffer,
+ firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw,
+ maxInstancesPerDraw);
+ return vertices;
+}
+
+void* GrVertexBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexStride,
+ int quadsToDraw) {
+ SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer(
+ batchTarget->resourceProvider()->refQuadIndexBuffer());
+ if (!quadIndexBuffer) {
+ SkDebugf("Could not get quad index buffer.");
+ return NULL;
+ }
+ return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertexStride,
+ quadIndexBuffer, kVerticesPerQuad, kIndicesPerQuad, quadsToDraw);
+}
diff --git a/src/gpu/batches/GrVertexBatch.h b/src/gpu/batches/GrVertexBatch.h
new file mode 100644
index 0000000..882cfa0
--- /dev/null
+++ b/src/gpu/batches/GrVertexBatch.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrVertexBatch_DEFINED
+#define GrVertexBatch_DEFINED
+
+#include "GrDrawBatch.h"
+#include "GrBatchTarget.h"
+
+/**
+ * Base class for vertex-based GrBatches.
+ */
+class GrVertexBatch : public GrDrawBatch {
+public:
+ GrVertexBatch();
+
+ virtual void generateGeometry(GrBatchTarget*) = 0;
+
+ // TODO this goes away when batches are everywhere
+ void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; }
+ int numberOfDraws() const { return fNumberOfDraws; }
+
+protected:
+ /** Helper for rendering instances using an instanced index index buffer. This class creates the
+ space for the vertices and flushes the draws to the batch target. */
+ class InstancedHelper {
+ public:
+ InstancedHelper() {}
+ /** Returns the allocated storage for the vertices. The caller should populate the before
+ vertices before calling issueDraws(). */
+ void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStride,
+ const GrIndexBuffer*, int verticesPerInstance, int indicesPerInstance,
+ int instancesToDraw);
+
+ /** Call after init() to issue draws to the batch target.*/
+ void issueDraw(GrBatchTarget* batchTarget) {
+ SkASSERT(fVertices.instanceCount());
+ batchTarget->draw(fVertices);
+ }
+ private:
+ GrVertices fVertices;
+ };
+
+ static const int kVerticesPerQuad = 4;
+ static const int kIndicesPerQuad = 6;
+
+ /** A specialization of InstanceHelper for quad rendering. */
+ class QuadHelper : private InstancedHelper {
+ public:
+ QuadHelper() : INHERITED() {}
+ /** Finds the cached quad index buffer and reserves vertex space. Returns NULL on failure
+ and on sucess a pointer to the vertex data that the caller should populate before
+ calling issueDraws(). */
+ void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToDraw);
+
+ using InstancedHelper::issueDraw;
+
+ private:
+ typedef InstancedHelper INHERITED;
+ };
+
+private:
+ int fNumberOfDraws;
+ typedef GrDrawBatch INHERITED;
+};
+
+#endif
diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp
index 92f6104..9da8c69 100644
--- a/src/gpu/effects/GrDashingEffect.cpp
+++ b/src/gpu/effects/GrDashingEffect.cpp
@@ -20,7 +20,7 @@
#include "GrStrokeInfo.h"
#include "GrVertexBuffer.h"
#include "SkGr.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/builders/GrGLProgramBuilder.h"
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 57a65a0..b6af16b 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -24,7 +24,7 @@
#include "SkRandom.h"
#include "Test.h"
-#include "batches/GrBatch.h"
+#include "batches/GrDrawBatch.h"
#include "effects/GrConfigConversionEffect.h"
#include "effects/GrPorterDuffXferProcessor.h"
diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp
index c276e59..34dd12b 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -15,7 +15,7 @@
#include "GrGpu.h"
#include "GrResourceProvider.h"
#include "GrXferProcessor.h"
-#include "batches/GrBatch.h"
+#include "batches/GrVertexBatch.h"
#include "effects/GrPorterDuffXferProcessor.h"
#include "gl/GrGLCaps.h"