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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
34 | 34 |
35 // Experimentally we have found that most batching occurs within the first 10 co
mparisons. | 35 // Experimentally we have found that most batching occurs within the first 10 co
mparisons. |
36 static const int kDefaultMaxBatchLookback = 10; | 36 static const int kDefaultMaxBatchLookback = 10; |
37 | 37 |
38 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, | 38 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, |
39 const Options& options) | 39 const Options& options) |
40 : fGpu(SkRef(gpu)) | 40 : fGpu(SkRef(gpu)) |
41 , fResourceProvider(resourceProvider) | 41 , fResourceProvider(resourceProvider) |
42 , fFlushing(false) | |
43 , fFlags(0) | 42 , fFlags(0) |
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, options.fClipBatchToBound
s)); | 46 fClipMaskManager.reset(new GrClipMaskManager(this, options.fClipBatchToBound
s)); |
48 | 47 |
49 fDrawBatchBounds = options.fDrawBatchBounds; | 48 fDrawBatchBounds = options.fDrawBatchBounds; |
50 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba
ck : | 49 fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookba
ck : |
51 options.fMaxBatchLookb
ack; | 50 options.fMaxBatchLookb
ack; |
52 | 51 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return false; | 175 return false; |
177 } | 176 } |
178 SkIPoint dstPoint = {0, 0}; | 177 SkIPoint dstPoint = {0, 0}; |
179 this->copySurface(copy, rt, copyRect, dstPoint); | 178 this->copySurface(copy, rt, copyRect, dstPoint); |
180 dstTexture->setTexture(copy); | 179 dstTexture->setTexture(copy); |
181 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); | 180 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
182 return true; | 181 return true; |
183 } | 182 } |
184 | 183 |
185 void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) { | 184 void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) { |
186 if (fFlushing) { | |
187 return; | |
188 } | |
189 fFlushing = true; | |
190 | |
191 // 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 |
192 // 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 |
193 // 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 |
194 // 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. |
195 this->makeClosed(); | 189 this->makeClosed(); |
196 | 190 |
197 // Loop over the batches that haven't yet generated their geometry | 191 // Loop over the batches that haven't yet generated their geometry |
198 for (int i = 0; i < fBatches.count(); ++i) { | 192 for (int i = 0; i < fBatches.count(); ++i) { |
199 fBatches[i]->prepare(flushState); | 193 fBatches[i]->prepare(flushState); |
200 } | 194 } |
201 } | 195 } |
202 | 196 |
203 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { | 197 void GrDrawTarget::drawBatches(GrBatchFlushState* flushState) { |
204 // Draw all the generated geometry. | 198 // Draw all the generated geometry. |
205 SkRandom random; | 199 SkRandom random; |
206 for (int i = 0; i < fBatches.count(); ++i) { | 200 for (int i = 0; i < fBatches.count(); ++i) { |
207 if (fDrawBatchBounds) { | 201 if (fDrawBatchBounds) { |
208 const SkRect& bounds = fBatches[i]->bounds(); | 202 const SkRect& bounds = fBatches[i]->bounds(); |
209 SkIRect ibounds; | 203 SkIRect ibounds; |
210 bounds.roundOut(&ibounds); | 204 bounds.roundOut(&ibounds); |
211 // In multi-draw buffer all the batches use the same render target a
nd we won't need to | 205 // In multi-draw buffer all the batches use the same render target a
nd we won't need to |
212 // get the batchs bounds. | 206 // get the batchs bounds. |
213 if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { | 207 if (GrRenderTarget* rt = fBatches[i]->renderTarget()) { |
214 fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()
); | 208 fGpu->drawDebugWireRect(rt, ibounds, 0xFF000000 | random.nextU()
); |
215 } | 209 } |
216 } | 210 } |
217 fBatches[i]->draw(flushState); | 211 fBatches[i]->draw(flushState); |
218 } | 212 } |
219 | |
220 fFlushing = false; | |
221 } | 213 } |
222 | 214 |
223 void GrDrawTarget::reset() { | 215 void GrDrawTarget::reset() { |
224 fBatches.reset(); | 216 fBatches.reset(); |
225 } | 217 } |
226 | 218 |
227 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { | 219 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { |
228 // Setup clip | 220 // Setup clip |
229 GrPipelineBuilder::AutoRestoreStencil ars; | 221 GrPipelineBuilder::AutoRestoreStencil ars; |
230 GrAppliedClip clip; | 222 GrAppliedClip clip; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 536 } |
545 | 537 |
546 return true; | 538 return true; |
547 } | 539 } |
548 | 540 |
549 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 541 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
550 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 542 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
551 this->recordBatch(batch); | 543 this->recordBatch(batch); |
552 batch->unref(); | 544 batch->unref(); |
553 } | 545 } |
OLD | NEW |