OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrDrawTarget.h" | 9 #include "GrDrawTarget.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "batches/GrRectBatchFactory.h" | 28 #include "batches/GrRectBatchFactory.h" |
29 #include "batches/GrStencilPathBatch.h" | 29 #include "batches/GrStencilPathBatch.h" |
30 | 30 |
31 #include "SkStrokeRec.h" | 31 #include "SkStrokeRec.h" |
32 | 32 |
33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
34 | 34 |
35 GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) | 35 GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) |
36 : fGpu(SkRef(gpu)) | 36 : fGpu(SkRef(gpu)) |
37 , fResourceProvider(resourceProvider) | 37 , fResourceProvider(resourceProvider) |
| 38 , fFlushState(fGpu, fResourceProvider, 0) |
38 , fFlushing(false) | 39 , fFlushing(false) |
39 , fLastFlushToken(0) { | 40 , fFirstUnpreparedBatch(0) { |
40 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 41 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
41 fContext = fGpu->getContext(); | 42 fContext = fGpu->getContext(); |
42 fClipMaskManager.reset(new GrClipMaskManager(this)); | 43 fClipMaskManager.reset(new GrClipMaskManager(this)); |
43 } | 44 } |
44 | 45 |
45 GrDrawTarget::~GrDrawTarget() { | 46 GrDrawTarget::~GrDrawTarget() { |
46 fGpu->unref(); | 47 fGpu->unref(); |
47 } | 48 } |
48 | 49 |
49 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); | 111 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
111 return true; | 112 return true; |
112 } | 113 } |
113 | 114 |
114 void GrDrawTarget::flush() { | 115 void GrDrawTarget::flush() { |
115 if (fFlushing) { | 116 if (fFlushing) { |
116 return; | 117 return; |
117 } | 118 } |
118 fFlushing = true; | 119 fFlushing = true; |
119 | 120 |
120 GrBatchFlushState flushState(fGpu, fResourceProvider, fLastFlushToken); | |
121 | |
122 // Loop over all batches and generate geometry | 121 // Loop over all batches and generate geometry |
123 for (int i = 0; i < fBatches.count(); ++i) { | 122 for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) { |
124 fBatches[i]->prepare(&flushState); | 123 fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState); |
125 } | 124 } |
126 | 125 |
127 // Upload all data to the GPU | 126 // Upload all data to the GPU |
128 flushState.preIssueDraws(); | 127 fFlushState.preIssueDraws(); |
129 | 128 |
130 // Draw all the generated geometry. | 129 // Draw all the generated geometry. |
131 for (int i = 0; i < fBatches.count(); ++i) { | 130 for (int i = 0; i < fBatches.count(); ++i) { |
132 fBatches[i]->draw(&flushState); | 131 fBatches[i]->draw(&fFlushState); |
133 } | 132 } |
134 | 133 |
135 fLastFlushToken = flushState.lastFlushedToken(); | 134 SkASSERT(fFlushState.lastFlushedToken() == fFlushState.currentToken()); |
| 135 this->reset(); |
136 | 136 |
137 fFlushing = false; | 137 fFlushing = false; |
138 this->reset(); | |
139 } | 138 } |
140 | 139 |
141 void GrDrawTarget::reset() { | 140 void GrDrawTarget::reset() { |
| 141 fFirstUnpreparedBatch = 0; |
142 fBatches.reset(); | 142 fBatches.reset(); |
| 143 fFlushState.reset(); |
143 } | 144 } |
144 | 145 |
145 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { | 146 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { |
146 // Setup clip | 147 // Setup clip |
147 GrScissorState scissorState; | 148 GrScissorState scissorState; |
148 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 149 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
149 GrPipelineBuilder::AutoRestoreStencil ars; | 150 GrPipelineBuilder::AutoRestoreStencil ars; |
150 if (!fClipMaskManager->setupClipping(pipelineBuilder, &arfps, &ars, &scissor
State, | 151 if (!fClipMaskManager->setupClipping(pipelineBuilder, &arfps, &ars, &scissor
State, |
151 &batch->bounds())) { | 152 &batch->bounds())) { |
152 return; | 153 return; |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 ++i; | 428 ++i; |
428 if (i == maxCandidates) { | 429 if (i == maxCandidates) { |
429 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr
ay %d\n", i); | 430 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr
ay %d\n", i); |
430 break; | 431 break; |
431 } | 432 } |
432 } | 433 } |
433 } else { | 434 } else { |
434 GrBATCH_INFO("\t\tFirstBatch\n"); | 435 GrBATCH_INFO("\t\tFirstBatch\n"); |
435 } | 436 } |
436 fBatches.push_back().reset(SkRef(batch)); | 437 fBatches.push_back().reset(SkRef(batch)); |
| 438 if (fBatches.count() > kMaxLookback) { |
| 439 SkASSERT(fBatches.count() - kMaxLookback - fFirstUnpreparedBatch == 1); |
| 440 fBatches[fFirstUnpreparedBatch++]->prepare(&fFlushState); |
| 441 } |
437 } | 442 } |
438 | 443 |
439 /////////////////////////////////////////////////////////////////////////////// | 444 /////////////////////////////////////////////////////////////////////////////// |
440 | 445 |
441 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, | 446 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, |
442 const GrScissorState* scissor, | 447 const GrScissorState* scissor, |
443 GrDrawBatch* batch) { | 448 GrDrawBatch* batch) { |
444 GrPipeline::CreateArgs args; | 449 GrPipeline::CreateArgs args; |
445 args.fPipelineBuilder = pipelineBuilder; | 450 args.fPipelineBuilder = pipelineBuilder; |
446 args.fCaps = this->caps(); | 451 args.fCaps = this->caps(); |
(...skipping 11 matching lines...) Expand all Loading... |
458 } | 463 } |
459 | 464 |
460 return true; | 465 return true; |
461 } | 466 } |
462 | 467 |
463 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 468 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
464 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 469 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
465 this->recordBatch(batch); | 470 this->recordBatch(batch); |
466 batch->unref(); | 471 batch->unref(); |
467 } | 472 } |
OLD | NEW |