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

Unified Diff: src/gpu/GrBatch.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/GrBatch.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBatch.cpp
diff --git a/src/gpu/GrBatch.cpp b/src/gpu/GrBatch.cpp
index ce30499ff8d4b4202c92170f6b5844158591355a..38ab1429a2f87766c3afe192946f7620c6a5128b 100644
--- a/src/gpu/GrBatch.cpp
+++ b/src/gpu/GrBatch.cpp
@@ -6,6 +6,8 @@
*/
#include "GrBatch.h"
+#include "GrBatchTarget.h"
+#include "GrResourceProvider.h"
#include "GrMemoryPool.h"
#include "SkSpinlock.h"
@@ -43,3 +45,44 @@ void* GrBatch::operator new(size_t size) {
void GrBatch::operator delete(void* target) {
return MemoryPoolAccessor().pool()->release(target);
}
+
+void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType primType,
+ size_t vertexStride, const GrIndexBuffer* indexBuffer,
+ int verticesPerInstance, int indicesPerInstance,
+ int instancesToDraw) {
+ SkASSERT(!fInstancesRemaining);
+ SkASSERT(batchTarget);
+ if (!indexBuffer) {
+ return NULL;
+ }
+ const GrVertexBuffer* vertexBuffer;
+ int firstVertex;
+ int vertexCount = verticesPerInstance * instancesToDraw;
+ void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, vertexCount, &vertexBuffer,
+ &firstVertex);
+ if (!vertices) {
+ SkDebugf("Vertices could not be allocated for instanced rendering.");
+ return NULL;
+ }
+ SkASSERT(vertexBuffer);
+ fInstancesRemaining = instancesToDraw;
+ size_t ibSize = indexBuffer->gpuMemorySize();
+ fMaxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
+
+ fDrawInfo.initInstanced(primType, vertexBuffer, indexBuffer,
+ firstVertex, verticesPerInstance, indicesPerInstance, &fInstancesRemaining,
+ fMaxInstancesPerDraw);
+ SkASSERT(fMaxInstancesPerDraw > 0);
+ return vertices;
+}
+
+void* GrBatch::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);
+}
« no previous file with comments | « src/gpu/GrBatch.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698