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