| 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 18 matching lines...) Expand all Loading... |
| 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(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, | 35 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, |
| 36 const Options& options) | 36 const Options& options) |
| 37 : fGpu(SkRef(gpu)) | 37 : fGpu(SkRef(gpu)) |
| 38 , fResourceProvider(resourceProvider) | 38 , fResourceProvider(resourceProvider) |
| 39 , fFlushState(fGpu, fResourceProvider, 0) | 39 , fFlushState(fGpu, fResourceProvider) |
| 40 , fFlushing(false) | 40 , fFlushing(false) |
| 41 , fFirstUnpreparedBatch(0) | |
| 42 , fFlags(0) | 41 , fFlags(0) |
| 43 , fOptions(options) | 42 , fOptions(options) |
| 44 , fRenderTarget(rt) { | 43 , fRenderTarget(rt) { |
| 45 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 44 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
| 46 fContext = fGpu->getContext(); | 45 fContext = fGpu->getContext(); |
| 47 fClipMaskManager.reset(new GrClipMaskManager(this)); | 46 fClipMaskManager.reset(new GrClipMaskManager(this)); |
| 48 | 47 |
| 49 #ifdef SK_DEBUG | 48 #ifdef SK_DEBUG |
| 50 static int debugID = 0; | 49 static int debugID = 0; |
| 51 fDebugID = debugID++; | 50 fDebugID = debugID++; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 182 } |
| 184 fFlushing = true; | 183 fFlushing = true; |
| 185 | 184 |
| 186 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh | 185 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh |
| 187 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed | 186 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed |
| 188 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w | 187 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w |
| 189 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. | 188 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. |
| 190 this->makeClosed(); | 189 this->makeClosed(); |
| 191 | 190 |
| 192 // Loop over the batches that haven't yet generated their geometry | 191 // Loop over the batches that haven't yet generated their geometry |
| 193 for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) { | 192 for (int i = 0; i < fBatches.count(); ++i) { |
| 194 fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState); | 193 fBatches[i]->prepare(&fFlushState); |
| 195 } | 194 } |
| 196 | 195 |
| 197 // Upload all data to the GPU | 196 // Upload all data to the GPU |
| 198 fFlushState.preIssueDraws(); | 197 fFlushState.preIssueDraws(); |
| 199 | 198 |
| 200 // Draw all the generated geometry. | 199 // Draw all the generated geometry. |
| 201 for (int i = 0; i < fBatches.count(); ++i) { | 200 for (int i = 0; i < fBatches.count(); ++i) { |
| 202 fBatches[i]->draw(&fFlushState); | 201 fBatches[i]->draw(&fFlushState); |
| 203 } | 202 } |
| 204 | 203 |
| 205 SkASSERT(fFlushState.lastFlushedToken() == fFlushState.currentToken()); | 204 SkASSERT(fFlushState.lastFlushedToken() == fFlushState.currentToken()); |
| 206 this->reset(); | 205 this->reset(); |
| 207 | 206 |
| 208 fFlushing = false; | 207 fFlushing = false; |
| 209 } | 208 } |
| 210 | 209 |
| 211 void GrDrawTarget::reset() { | 210 void GrDrawTarget::reset() { |
| 212 fFirstUnpreparedBatch = 0; | |
| 213 fBatches.reset(); | 211 fBatches.reset(); |
| 214 fFlushState.reset(); | 212 fFlushState.reset(); |
| 215 } | 213 } |
| 216 | 214 |
| 217 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { | 215 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { |
| 218 // Setup clip | 216 // Setup clip |
| 219 GrPipelineBuilder::AutoRestoreStencil ars; | 217 GrPipelineBuilder::AutoRestoreStencil ars; |
| 220 GrAppliedClip clip; | 218 GrAppliedClip clip; |
| 221 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds()
, &clip)) { | 219 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds()
, &clip)) { |
| 222 return; | 220 return; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 ++i; | 513 ++i; |
| 516 if (i == maxCandidates) { | 514 if (i == maxCandidates) { |
| 517 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr
ay %d\n", i); | 515 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr
ay %d\n", i); |
| 518 break; | 516 break; |
| 519 } | 517 } |
| 520 } | 518 } |
| 521 } else { | 519 } else { |
| 522 GrBATCH_INFO("\t\tFirstBatch\n"); | 520 GrBATCH_INFO("\t\tFirstBatch\n"); |
| 523 } | 521 } |
| 524 fBatches.push_back().reset(SkRef(batch)); | 522 fBatches.push_back().reset(SkRef(batch)); |
| 525 if (fBatches.count() > kMaxLookback) { | |
| 526 SkASSERT(fBatches.count() - kMaxLookback - fFirstUnpreparedBatch == 1); | |
| 527 fBatches[fFirstUnpreparedBatch++]->prepare(&fFlushState); | |
| 528 } | |
| 529 if (fOptions.fImmediateMode) { | 523 if (fOptions.fImmediateMode) { |
| 530 this->flush(); | 524 this->flush(); |
| 531 } | 525 } |
| 532 } | 526 } |
| 533 | 527 |
| 534 /////////////////////////////////////////////////////////////////////////////// | 528 /////////////////////////////////////////////////////////////////////////////// |
| 535 | 529 |
| 536 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, | 530 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB
uilder, |
| 537 const GrAppliedClip* clip, GrDrawB
atch* batch) { | 531 const GrAppliedClip* clip, GrDrawB
atch* batch) { |
| 538 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 532 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 558 } | 552 } |
| 559 | 553 |
| 560 return true; | 554 return true; |
| 561 } | 555 } |
| 562 | 556 |
| 563 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 557 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
| 564 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 558 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
| 565 this->recordBatch(batch); | 559 this->recordBatch(batch); |
| 566 batch->unref(); | 560 batch->unref(); |
| 567 } | 561 } |
| OLD | NEW |