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