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

Side by Side Diff: src/gpu/batches/GrVertexBatch.h

Issue 1286043004: Make GrVertexBatch objects hold their own draws during GrDrawTarget flush (Closed) Base URL: https://skia.googlesource.com/skia.git@m
Patch Set: forward decl 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/GrTestBatch.h ('k') | src/gpu/batches/GrVertexBatch.cpp » ('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 #ifndef GrVertexBatch_DEFINED 8 #ifndef GrVertexBatch_DEFINED
9 #define GrVertexBatch_DEFINED 9 #define GrVertexBatch_DEFINED
10 10
11 #include "GrDrawBatch.h" 11 #include "GrDrawBatch.h"
12 #include "GrBatchTarget.h" 12 #include "GrPrimitiveProcessor.h"
13 #include "GrPendingProgramElement.h"
14 #include "GrVertices.h"
15
16 #include "SkTLList.h"
17
18 class GrBatchFlushState;
13 19
14 /** 20 /**
15 * Base class for vertex-based GrBatches. 21 * Base class for vertex-based GrBatches.
16 */ 22 */
17 class GrVertexBatch : public GrDrawBatch { 23 class GrVertexBatch : public GrDrawBatch {
18 public: 24 public:
25 class Target;
26
19 GrVertexBatch(); 27 GrVertexBatch();
20 28
21 virtual void generateGeometry(GrBatchTarget*) = 0; 29 void prepareDraws(GrBatchFlushState* state);
22 30 void issueDraws(GrBatchFlushState* state);
23 // TODO this goes away when batches are everywhere
24 void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; }
25 int numberOfDraws() const { return fNumberOfDraws; }
26 31
27 protected: 32 protected:
28 /** Helper for rendering instances using an instanced index index buffer. Th is class creates the 33 /** Helper for rendering instances using an instanced index index buffer. Th is class creates the
29 space for the vertices and flushes the draws to the batch target. */ 34 space for the vertices and flushes the draws to the batch target. */
30 class InstancedHelper { 35 class InstancedHelper {
31 public: 36 public:
32 InstancedHelper() {} 37 InstancedHelper() {}
33 /** Returns the allocated storage for the vertices. The caller should po pulate the before 38 /** Returns the allocated storage for the vertices. The caller should po pulate the before
34 vertices before calling issueDraws(). */ 39 vertices before calling issueDraws(). */
35 void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStr ide, 40 void* init(Target*, GrPrimitiveType, size_t vertexStride,
36 const GrIndexBuffer*, int verticesPerInstance, int indicesPer Instance, 41 const GrIndexBuffer*, int verticesPerInstance, int indicesPer Instance,
37 int instancesToDraw); 42 int instancesToDraw);
38 43
39 /** Call after init() to issue draws to the batch target.*/ 44 /** Call after init() to issue draws to the batch target.*/
40 void issueDraw(GrBatchTarget* batchTarget) { 45 void recordDraw(Target* target);
41 SkASSERT(fVertices.instanceCount());
42 batchTarget->draw(fVertices);
43 }
44 private: 46 private:
45 GrVertices fVertices; 47 GrVertices fVertices;
46 }; 48 };
47 49
48 static const int kVerticesPerQuad = 4; 50 static const int kVerticesPerQuad = 4;
49 static const int kIndicesPerQuad = 6; 51 static const int kIndicesPerQuad = 6;
50 52
51 /** A specialization of InstanceHelper for quad rendering. */ 53 /** A specialization of InstanceHelper for quad rendering. */
52 class QuadHelper : private InstancedHelper { 54 class QuadHelper : private InstancedHelper {
53 public: 55 public:
54 QuadHelper() : INHERITED() {} 56 QuadHelper() : INHERITED() {}
55 /** Finds the cached quad index buffer and reserves vertex space. Return s NULL on failure 57 /** Finds the cached quad index buffer and reserves vertex space. Return s NULL on failure
56 and on sucess a pointer to the vertex data that the caller should po pulate before 58 and on sucess a pointer to the vertex data that the caller should po pulate before
57 calling issueDraws(). */ 59 calling issueDraws(). */
58 void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToD raw); 60 void* init(Target* batchTarget, size_t vertexStride, int quadsToDraw);
59 61
60 using InstancedHelper::issueDraw; 62 using InstancedHelper::recordDraw;
61
62 private: 63 private:
63 typedef InstancedHelper INHERITED; 64 typedef InstancedHelper INHERITED;
64 }; 65 };
65 66
66 private: 67 private:
67 int fNumberOfDraws; 68 virtual void onPrepareDraws(Target*) = 0;
69
70 // A set of contiguous draws with no inline uploads between them that all us e the same
71 // primitive processor. All the draws in a DrawArray share a primitive proce ssor and use the
72 // the batch's GrPipeline.
73 struct DrawArray {
74 SkSTArray<1, GrVertices, true> fDraws;
75 GrPendingProgramElement<const GrPrimitiveProcessor> fPrimitiveProcessor;
76 };
77
78 // Array of DrawArray. There may be inline uploads between each DrawArray an d each DrawArray
79 // may use a different primitive processor.
80 SkTLList<DrawArray> fDrawArrays;
81
82 // What is this?
83 GrBatchTracker fBatchTracker;
84
68 typedef GrDrawBatch INHERITED; 85 typedef GrDrawBatch INHERITED;
69 }; 86 };
70 87
71 #endif 88 #endif
OLDNEW
« no previous file with comments | « src/gpu/batches/GrTestBatch.h ('k') | src/gpu/batches/GrVertexBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698