OLD | NEW |
---|---|
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 GrBatch_DEFINED | 8 #ifndef GrBatch_DEFINED |
9 #define GrBatch_DEFINED | 9 #define GrBatch_DEFINED |
10 | 10 |
11 #include "../private/SkAtomics.h" | 11 #include "../private/SkAtomics.h" |
12 #include "GrNonAtomicRef.h" | 12 #include "GrNonAtomicRef.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 | 15 |
16 #include <new> | 16 #include <new> |
17 | 17 |
18 class GrCaps; | 18 class GrCaps; |
19 class GrGpuCommandBuffer; | |
19 class GrBatchFlushState; | 20 class GrBatchFlushState; |
20 class GrRenderTarget; | 21 class GrRenderTarget; |
21 | 22 |
22 /** | 23 /** |
23 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate | 24 * GrBatch is the base class for all Ganesh deferred geometry generators. To fa cilitate |
24 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it | 25 * reorderable batching, Ganesh does not generate geometry inline with draw call s. Instead, it |
25 * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch | 26 * captures the arguments to the draw and then generates the geometry on demand. This gives GrBatch |
26 * subclasses complete freedom to decide how / what they can batch. | 27 * subclasses complete freedom to decide how / what they can batch. |
27 * | 28 * |
28 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be | 29 * Batches are created when GrContext processes a draw call. Batches of the same subclass may be |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 } | 104 } |
104 return fUniqueID; | 105 return fUniqueID; |
105 } | 106 } |
106 SkDEBUGCODE(bool isUsed() const { return fUsed; }) | 107 SkDEBUGCODE(bool isUsed() const { return fUsed; }) |
107 | 108 |
108 /** Called prior to drawing. The batch should perform any resource creation necessary to | 109 /** Called prior to drawing. The batch should perform any resource creation necessary to |
109 to quickly issue its draw when draw is called. */ | 110 to quickly issue its draw when draw is called. */ |
110 void prepare(GrBatchFlushState* state) { this->onPrepare(state); } | 111 void prepare(GrBatchFlushState* state) { this->onPrepare(state); } |
111 | 112 |
112 /** Issues the batches commands to GrGpu. */ | 113 /** Issues the batches commands to GrGpu. */ |
113 void draw(GrBatchFlushState* state) { this->onDraw(state); } | 114 void draw(GrBatchFlushState* state, GrGpuCommandBuffer* buffer) { this->onDr aw(state, buffer); } |
bsalomon
2016/06/20 16:51:14
Could buffer be on the state?
egdaniel
2016/06/22 15:26:57
Done.
| |
114 | 115 |
115 /** Used to block batching across render target changes. Remove this once we store | 116 /** Used to block batching across render target changes. Remove this once we store |
116 GrBatches for different RTs in different targets. */ | 117 GrBatches for different RTs in different targets. */ |
117 virtual uint32_t renderTargetUniqueID() const = 0; | 118 virtual uint32_t renderTargetUniqueID() const = 0; |
118 | 119 |
119 /** Used for spewing information about batches when debugging. */ | 120 /** Used for spewing information about batches when debugging. */ |
120 virtual SkString dumpInfo() const = 0; | 121 virtual SkString dumpInfo() const = 0; |
121 | 122 |
122 /** Can remove this when multi-draw-buffer lands */ | 123 /** Can remove this when multi-draw-buffer lands */ |
123 virtual GrRenderTarget* renderTarget() const = 0; | 124 virtual GrRenderTarget* renderTarget() const = 0; |
124 | 125 |
125 protected: | 126 protected: |
126 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds | 127 // NOTE, compute some bounds, even if extremely conservative. Do *NOT* setL argest on the bounds |
127 // rect because we outset it for dst copy textures | 128 // rect because we outset it for dst copy textures |
128 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } | 129 void setBounds(const SkRect& newBounds) { fBounds = newBounds; } |
129 | 130 |
130 void joinBounds(const SkRect& otherBounds) { | 131 void joinBounds(const SkRect& otherBounds) { |
131 return fBounds.joinPossiblyEmptyRect(otherBounds); | 132 return fBounds.joinPossiblyEmptyRect(otherBounds); |
132 } | 133 } |
133 | 134 |
134 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } | 135 static uint32_t GenBatchClassID() { return GenID(&gCurrBatchClassID); } |
135 | 136 |
136 SkRect fBounds; | 137 SkRect fBounds; |
137 | 138 |
138 private: | 139 private: |
139 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; | 140 virtual bool onCombineIfPossible(GrBatch*, const GrCaps& caps) = 0; |
140 | 141 |
141 virtual void onPrepare(GrBatchFlushState*) = 0; | 142 virtual void onPrepare(GrBatchFlushState*) = 0; |
142 virtual void onDraw(GrBatchFlushState*) = 0; | 143 virtual void onDraw(GrBatchFlushState*, GrGpuCommandBuffer*) = 0; |
143 | 144 |
144 static uint32_t GenID(int32_t* idCounter) { | 145 static uint32_t GenID(int32_t* idCounter) { |
145 // The atomic inc returns the old value not the incremented value. So we add | 146 // The atomic inc returns the old value not the incremented value. So we add |
146 // 1 to the returned value. | 147 // 1 to the returned value. |
147 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; | 148 uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1; |
148 if (!id) { | 149 if (!id) { |
149 SkFAIL("This should never wrap as it should only be called once for each GrBatch " | 150 SkFAIL("This should never wrap as it should only be called once for each GrBatch " |
150 "subclass."); | 151 "subclass."); |
151 } | 152 } |
152 return id; | 153 return id; |
153 } | 154 } |
154 | 155 |
155 enum { | 156 enum { |
156 kIllegalBatchID = 0, | 157 kIllegalBatchID = 0, |
157 }; | 158 }; |
158 | 159 |
159 SkDEBUGCODE(bool fUsed;) | 160 SkDEBUGCODE(bool fUsed;) |
160 const uint32_t fClassID; | 161 const uint32_t fClassID; |
161 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } | 162 static uint32_t GenBatchID() { return GenID(&gCurrBatchUniqueID); } |
162 mutable uint32_t fUniqueID; | 163 mutable uint32_t fUniqueID; |
163 static int32_t gCurrBatchUniqueID; | 164 static int32_t gCurrBatchUniqueID; |
164 static int32_t gCurrBatchClassID; | 165 static int32_t gCurrBatchClassID; |
165 }; | 166 }; |
166 | 167 |
167 #endif | 168 #endif |
OLD | NEW |