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

Unified Diff: src/gpu/GrBatch.h

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/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatch.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBatch.h
diff --git a/src/gpu/GrBatch.h b/src/gpu/GrBatch.h
index 7b5c888a7058e9a6eb9132bccf8533601d6a8701..d03fa677811e4f10ecb0fa49f2d0b7767f135562 100644
--- a/src/gpu/GrBatch.h
+++ b/src/gpu/GrBatch.h
@@ -11,12 +11,12 @@
#include <new>
// TODO remove this header when we move entirely to batch
#include "GrDrawTarget.h"
+#include "GrBatchTarget.h"
#include "GrGeometryProcessor.h"
#include "SkRefCnt.h"
#include "SkThread.h"
#include "SkTypes.h"
-class GrBatchTarget;
class GrGpu;
class GrIndexBufferAllocPool;
class GrPipeline;
@@ -113,6 +113,48 @@ protected:
return fBounds.joinPossiblyEmptyRect(otherBounds);
}
+ /** 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() : fInstancesRemaining(0) {}
+ /** 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 issueDraws(GrBatchTarget* batchTarget) {
+ SkASSERT(fDrawInfo.instanceCount());
+ do {
+ batchTarget->draw(fDrawInfo);
+ } while (fDrawInfo.nextInstances(&fInstancesRemaining, fMaxInstancesPerDraw));
+ }
+ private:
+ int fInstancesRemaining;
+ int fMaxInstancesPerDraw;
+ GrDrawTarget::DrawInfo fDrawInfo;
+ };
+
+ 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::issueDraws;
+
+ private:
+ typedef InstancedHelper INHERITED;
+ };
+
SkRect fBounds;
private:
« no previous file with comments | « src/gpu/GrAtlasTextContext.cpp ('k') | src/gpu/GrBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698