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

Side by Side Diff: src/gpu/batches/GrBatch.cpp

Issue 1296483002: Split GrDrawBatch and GrVertexBatch into their own files (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add new files to git Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « src/gpu/batches/GrBatch.h ('k') | src/gpu/batches/GrDrawAtlasBatch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrBatch.h" 8 #include "GrBatch.h"
9 #include "GrBatchTarget.h"
10 #include "GrResourceProvider.h"
11 9
12 #include "GrMemoryPool.h" 10 #include "GrMemoryPool.h"
13 #include "SkSpinlock.h" 11 #include "SkSpinlock.h"
14 12
15 // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small, 13 // TODO I noticed a small benefit to using a larger exclusive pool for batches. Its very small,
16 // but seems to be mostly consistent. There is a lot in flux right now, but we should really 14 // but seems to be mostly consistent. There is a lot in flux right now, but we should really
17 // revisit this when batch is everywhere 15 // revisit this when batch is everywhere
18 16
19 17
20 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on 18 // We use a global pool protected by a mutex(spinlock). Chrome may use the same GrContext on
(...skipping 30 matching lines...) Expand all
51 GrBatch::GrBatch() 49 GrBatch::GrBatch()
52 : fClassID(kIllegalBatchID) 50 : fClassID(kIllegalBatchID)
53 #if GR_BATCH_SPEW 51 #if GR_BATCH_SPEW
54 , fUniqueID(GenID(&gCurrBatchUniqueID)) 52 , fUniqueID(GenID(&gCurrBatchUniqueID))
55 #endif 53 #endif
56 { 54 {
57 SkDEBUGCODE(fUsed = false;) 55 SkDEBUGCODE(fUsed = false;)
58 } 56 }
59 57
60 GrBatch::~GrBatch() {} 58 GrBatch::~GrBatch() {}
61
62 //////////////////////////////////////////////////////////////////////////////
63
64 GrDrawBatch::GrDrawBatch() : fPipelineInstalled(false) { }
65
66 GrDrawBatch::~GrDrawBatch() {
67 if (fPipelineInstalled) {
68 this->pipeline()->~GrPipeline();
69 }
70 }
71
72 bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) {
73 GrPipelineOptimizations opts;
74 void* location = fPipelineStorage.get();
75 if (!GrPipeline::CreateAt(location, args, &opts)) {
76 return false;
77 }
78 this->initBatchTracker(opts);
79 fPipelineInstalled = true;
80 return true;
81 }
82
83 //////////////////////////////////////////////////////////////////////////////
84
85 GrVertexBatch::GrVertexBatch() : fNumberOfDraws(0) {}
86
87 void* GrVertexBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimiti veType primType,
88 size_t vertexStride, const GrIndexBuffer* i ndexBuffer,
89 int verticesPerInstance, int indicesPerInst ance,
90 int instancesToDraw) {
91 SkASSERT(batchTarget);
92 if (!indexBuffer) {
93 return NULL;
94 }
95 const GrVertexBuffer* vertexBuffer;
96 int firstVertex;
97 int vertexCount = verticesPerInstance * instancesToDraw;
98 void* vertices = batchTarget->makeVertSpace(vertexStride, vertexCount,
99 &vertexBuffer, &firstVertex);
100 if (!vertices) {
101 SkDebugf("Vertices could not be allocated for instanced rendering.");
102 return NULL;
103 }
104 SkASSERT(vertexBuffer);
105 size_t ibSize = indexBuffer->gpuMemorySize();
106 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi cesPerInstance));
107
108 fVertices.initInstanced(primType, vertexBuffer, indexBuffer,
109 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw,
110 maxInstancesPerDraw);
111 return vertices;
112 }
113
114 void* GrVertexBatch::QuadHelper::init(GrBatchTarget* batchTarget, size_t vertexS tride,
115 int quadsToDraw) {
116 SkAutoTUnref<const GrIndexBuffer> quadIndexBuffer(
117 batchTarget->resourceProvider()->refQuadIndexBuffer());
118 if (!quadIndexBuffer) {
119 SkDebugf("Could not get quad index buffer.");
120 return NULL;
121 }
122 return this->INHERITED::init(batchTarget, kTriangles_GrPrimitiveType, vertex Stride,
123 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ uad, quadsToDraw);
124 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrBatch.h ('k') | src/gpu/batches/GrDrawAtlasBatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698