Chromium Code Reviews| 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(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 , fFlushing(false) | 38 , fFlushing(false) |
| 39 , fLastFlushToken(0) { | 39 , fLastFlushToken(0) |
| 40 , fLastFlushedBatch(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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 SkDebugf("Failed to create temporary copy of destination texture.\n"); | 105 SkDebugf("Failed to create temporary copy of destination texture.\n"); |
| 105 return false; | 106 return false; |
| 106 } | 107 } |
| 107 SkIPoint dstPoint = {0, 0}; | 108 SkIPoint dstPoint = {0, 0}; |
| 108 this->copySurface(copy, rt, copyRect, dstPoint); | 109 this->copySurface(copy, rt, copyRect, dstPoint); |
| 109 dstTexture->setTexture(copy); | 110 dstTexture->setTexture(copy); |
| 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::flushN(int N) { |
| 116 SkASSERT(fLastFlushedBatch + N <= fBatches.count()); | |
| 115 if (fFlushing) { | 117 if (fFlushing) { |
| 116 return; | 118 return; |
| 117 } | 119 } |
| 118 fFlushing = true; | 120 fFlushing = true; |
| 119 | 121 |
| 120 GrBatchFlushState flushState(fGpu, fResourceProvider, fLastFlushToken); | 122 GrBatchFlushState flushState(fGpu, fResourceProvider, fLastFlushToken); |
| 121 | 123 |
| 124 int flushTo = fLastFlushedBatch + N; | |
| 125 | |
| 122 // Loop over all batches and generate geometry | 126 // Loop over all batches and generate geometry |
| 123 for (int i = 0; i < fBatches.count(); ++i) { | 127 for (int i = fLastFlushedBatch; i < flushTo; ++i) { |
| 124 fBatches[i]->prepare(&flushState); | 128 fBatches[i]->prepare(&flushState); |
| 125 } | 129 } |
| 126 | 130 |
| 127 // Upload all data to the GPU | 131 // Upload all data to the GPU |
| 128 flushState.preIssueDraws(); | 132 flushState.preIssueDraws(); |
| 129 | 133 |
| 130 // Draw all the generated geometry. | 134 // Draw all the generated geometry. |
| 131 for (int i = 0; i < fBatches.count(); ++i) { | 135 for (int i = fLastFlushedBatch; i < flushTo; ++i) { |
| 132 fBatches[i]->draw(&flushState); | 136 fBatches[i]->draw(&flushState); |
| 133 } | 137 } |
| 134 | 138 |
| 135 fLastFlushToken = flushState.lastFlushedToken(); | 139 fLastFlushToken = flushState.lastFlushedToken(); |
| 136 | 140 |
| 137 fFlushing = false; | 141 fFlushing = false; |
| 142 } | |
| 143 | |
| 144 void GrDrawTarget::flush() { | |
| 145 this->flushN(fBatches.count() - fLastFlushedBatch); | |
| 138 this->reset(); | 146 this->reset(); |
| 139 } | 147 } |
| 140 | 148 |
| 141 void GrDrawTarget::reset() { | 149 void GrDrawTarget::reset() { |
| 150 fLastFlushedBatch = 0; | |
| 142 fBatches.reset(); | 151 fBatches.reset(); |
| 143 } | 152 } |
| 144 | 153 |
| 145 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat ch* batch) { | 154 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat ch* batch) { |
| 146 // Setup clip | 155 // Setup clip |
| 147 GrScissorState scissorState; | 156 GrScissorState scissorState; |
| 148 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 157 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 149 GrPipelineBuilder::AutoRestoreStencil ars; | 158 GrPipelineBuilder::AutoRestoreStencil ars; |
| 150 if (!fClipMaskManager->setupClipping(pipelineBuilder, &arfps, &ars, &scissor State, | 159 if (!fClipMaskManager->setupClipping(pipelineBuilder, &arfps, &ars, &scissor State, |
| 151 &batch->bounds())) { | 160 &batch->bounds())) { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 ++i; | 436 ++i; |
| 428 if (i == maxCandidates) { | 437 if (i == maxCandidates) { |
| 429 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr ay %d\n", i); | 438 GrBATCH_INFO("\t\tReached max lookback or beginning of batch arr ay %d\n", i); |
| 430 break; | 439 break; |
| 431 } | 440 } |
| 432 } | 441 } |
| 433 } else { | 442 } else { |
| 434 GrBATCH_INFO("\t\tFirstBatch\n"); | 443 GrBATCH_INFO("\t\tFirstBatch\n"); |
| 435 } | 444 } |
| 436 fBatches.push_back().reset(SkRef(batch)); | 445 fBatches.push_back().reset(SkRef(batch)); |
| 446 if (fBatches.count() > kMaxLookback) { | |
| 447 this->flushN(1); | |
|
bsalomon
2015/10/02 13:56:37
Maybe assert that we're only 1 ahead? Otherwise, l
| |
| 448 fLastFlushedBatch++; | |
| 449 } | |
| 437 } | 450 } |
| 438 | 451 |
| 439 /////////////////////////////////////////////////////////////////////////////// | 452 /////////////////////////////////////////////////////////////////////////////// |
| 440 | 453 |
| 441 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB uilder, | 454 bool GrDrawTarget::installPipelineInDrawBatch(const GrPipelineBuilder* pipelineB uilder, |
| 442 const GrScissorState* scissor, | 455 const GrScissorState* scissor, |
| 443 GrDrawBatch* batch) { | 456 GrDrawBatch* batch) { |
| 444 GrPipeline::CreateArgs args; | 457 GrPipeline::CreateArgs args; |
| 445 args.fPipelineBuilder = pipelineBuilder; | 458 args.fPipelineBuilder = pipelineBuilder; |
| 446 args.fCaps = this->caps(); | 459 args.fCaps = this->caps(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 458 } | 471 } |
| 459 | 472 |
| 460 return true; | 473 return true; |
| 461 } | 474 } |
| 462 | 475 |
| 463 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { | 476 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend erTarget* rt) { |
| 464 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 477 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
| 465 this->recordBatch(batch); | 478 this->recordBatch(batch); |
| 466 batch->unref(); | 479 batch->unref(); |
| 467 } | 480 } |
| OLD | NEW |