OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "GrDrawTarget.h" | 8 #include "GrDrawTarget.h" |
9 | 9 |
10 #include "GrAuditTrail.h" | 10 #include "GrAuditTrail.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "SkStrokeRec.h" | 25 #include "SkStrokeRec.h" |
26 | 26 |
27 #include "batches/GrClearBatch.h" | 27 #include "batches/GrClearBatch.h" |
28 #include "batches/GrCopySurfaceBatch.h" | 28 #include "batches/GrCopySurfaceBatch.h" |
29 #include "batches/GrDiscardBatch.h" | 29 #include "batches/GrDiscardBatch.h" |
30 #include "batches/GrDrawBatch.h" | 30 #include "batches/GrDrawBatch.h" |
31 #include "batches/GrDrawPathBatch.h" | 31 #include "batches/GrDrawPathBatch.h" |
32 #include "batches/GrRectBatchFactory.h" | 32 #include "batches/GrRectBatchFactory.h" |
33 #include "batches/GrStencilPathBatch.h" | 33 #include "batches/GrStencilPathBatch.h" |
34 | 34 |
| 35 #include "instanced/InstancedRendering.h" |
| 36 |
35 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
36 | 38 |
37 // Experimentally we have found that most batching occurs within the first 10 co
mparisons. | 39 // Experimentally we have found that most batching occurs within the first 10 co
mparisons. |
38 static const int kDefaultMaxBatchLookback = 10; | 40 static const int kDefaultMaxBatchLookback = 10; |
39 static const int kDefaultMaxBatchLookahead = 10; | 41 static const int kDefaultMaxBatchLookahead = 10; |
40 | 42 |
41 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, | 43 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, |
42 GrAuditTrail* auditTrail, const Options& options) | 44 GrAuditTrail* auditTrail, const Options& options) |
43 : fGpu(SkRef(gpu)) | 45 : fGpu(SkRef(gpu)) |
44 , fResourceProvider(resourceProvider) | 46 , fResourceProvider(resourceProvider) |
45 , fAuditTrail(auditTrail) | 47 , fAuditTrail(auditTrail) |
46 , fFlags(0) | 48 , fFlags(0) |
47 , fRenderTarget(rt) { | 49 , fRenderTarget(rt) |
| 50 , fInstancedRendering(fGpu->createInstancedRenderingIfSupported()) { |
48 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 51 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
49 fContext = fGpu->getContext(); | 52 fContext = fGpu->getContext(); |
50 | 53 |
51 fClipBatchToBounds = options.fClipBatchToBounds; | 54 fClipBatchToBounds = options.fClipBatchToBounds; |
52 fDrawBatchBounds = options.fDrawBatchBounds; | 55 fDrawBatchBounds = options.fDrawBatchBounds; |
53 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba
ck : | 56 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba
ck : |
54 options.fMaxBatchLookb
ack; | 57 options.fMaxBatchLookb
ack; |
55 fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLook
ahead : | 58 fMaxBatchLookahead = (options.fMaxBatchLookahead < 0) ? kDefaultMaxBatchLook
ahead : |
56 options.fMaxBatchLook
ahead; | 59 options.fMaxBatchLook
ahead; |
57 | 60 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w | 200 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w |
198 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. | 201 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. |
199 this->makeClosed(); | 202 this->makeClosed(); |
200 | 203 |
201 // Loop over the batches that haven't yet generated their geometry | 204 // Loop over the batches that haven't yet generated their geometry |
202 for (int i = 0; i < fBatches.count(); ++i) { | 205 for (int i = 0; i < fBatches.count(); ++i) { |
203 if (fBatches[i]) { | 206 if (fBatches[i]) { |
204 fBatches[i]->prepare(flushState); | 207 fBatches[i]->prepare(flushState); |
205 } | 208 } |
206 } | 209 } |
| 210 |
| 211 if (fInstancedRendering) { |
| 212 fInstancedRendering->beginFlush(flushState->resourceProvider()); |
| 213 } |
207 } | 214 } |
208 | 215 |
209 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { | 216 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { |
210 // Draw all the generated geometry. | 217 // Draw all the generated geometry. |
211 SkRandom random; | 218 SkRandom random; |
212 for (int i = 0; i < fBatches.count(); ++i) { | 219 for (int i = 0; i < fBatches.count(); ++i) { |
213 if (!fBatches[i]) { | 220 if (!fBatches[i]) { |
214 continue; | 221 continue; |
215 } | 222 } |
216 if (fDrawBatchBounds) { | 223 if (fDrawBatchBounds) { |
217 const SkRect& bounds = fBatches[i]->bounds(); | 224 const SkRect& bounds = fBatches[i]->bounds(); |
218 SkIRect ibounds; | 225 SkIRect ibounds; |
219 bounds.roundOut(&ibounds); | 226 bounds.roundOut(&ibounds); |
220 // In multi-draw buffer all the batches use the same render target a
nd we won't need to | 227 // In multi-draw buffer all the batches use the same render target a
nd we won't need to |
221 // get the batchs bounds. | 228 // get the batchs bounds. |
222 if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { | 229 if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { |
223 fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()
); | 230 fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()
); |
224 } | 231 } |
225 } | 232 } |
226 fBatches[i]->draw(flushState); | 233 fBatches[i]->draw(flushState); |
227 } | 234 } |
228 | 235 |
229 fGpu->finishDrawTarget(); | 236 fGpu->finishDrawTarget(); |
230 } | 237 } |
231 | 238 |
232 void GrDrawTarget::reset() { | 239 void GrDrawTarget::reset() { |
233 fBatches.reset(); | 240 fBatches.reset(); |
| 241 if (fInstancedRendering) { |
| 242 fInstancedRendering->endFlush(); |
| 243 } |
234 } | 244 } |
235 | 245 |
236 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, | 246 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, |
237 GrDrawContext* drawContext, | 247 GrDrawContext* drawContext, |
238 const GrClip& clip, | 248 const GrClip& clip, |
239 GrDrawBatch* batch) { | 249 GrDrawBatch* batch) { |
240 // Setup clip | 250 // Setup clip |
241 GrAppliedClip appliedClip; | 251 GrAppliedClip appliedClip; |
242 if (!clip.apply(fContext, pipelineBuilder, drawContext, &batch->bounds(), &a
ppliedClip)) { | 252 if (!clip.apply(fContext, pipelineBuilder, drawContext, &batch->bounds(), &a
ppliedClip)) { |
243 return; | 253 return; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 } | 534 } |
525 } | 535 } |
526 | 536 |
527 /////////////////////////////////////////////////////////////////////////////// | 537 /////////////////////////////////////////////////////////////////////////////// |
528 | 538 |
529 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 539 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
530 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 540 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
531 this->recordBatch(batch); | 541 this->recordBatch(batch); |
532 batch->unref(); | 542 batch->unref(); |
533 } | 543 } |
OLD | NEW |