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

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: drawinfo changes 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
Index: src/gpu/GrBatch.cpp
diff --git a/src/gpu/GrBatch.cpp b/src/gpu/GrBatch.cpp
index ce30499ff8d4b4202c92170f6b5844158591355a..1ef6c9797c1f4b08e8d1b8ad945706841b2b7d00 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,43 @@ void* GrBatch::operator new(size_t size) {
void GrBatch::operator delete(void* target) {
return MemoryPoolAccessor().pool()->release(target);
}
+
+void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, 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;
+
+ fDrawInfo.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
+ firstVertex, verticesPerInstance, indicesPerInstance, &fInstancesRemaining,
+ indexBuffer->maxQuads());
+ size_t ibSize = fDrawInfo.indexBuffer()->gpuMemorySize();
+ fMaxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
+ 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, vertexStride, quadIndexBuffer, kVerticesPerQuad,
+ kIndicesPerQuad, quadsToDraw);
+}
« no previous file with comments | « src/gpu/GrBatch.h ('k') | src/gpu/GrContext.cpp » ('j') | src/gpu/GrDrawTarget.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698