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 19 matching lines...) Expand all Loading... |
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 , fFlushState(fGpu, fResourceProvider, 0) |
39 , fFlushing(false) | 39 , fFlushing(false) |
40 , fFirstUnpreparedBatch(0) { | 40 , fFirstUnpreparedBatch(0) |
| 41 , fClosed(false) { |
41 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 42 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
42 fContext = fGpu->getContext(); | 43 fContext = fGpu->getContext(); |
43 fClipMaskManager.reset(new GrClipMaskManager(this)); | 44 fClipMaskManager.reset(new GrClipMaskManager(this)); |
44 } | 45 } |
45 | 46 |
46 GrDrawTarget::~GrDrawTarget() { | 47 GrDrawTarget::~GrDrawTarget() { |
47 fGpu->unref(); | 48 fGpu->unref(); |
48 } | 49 } |
49 | 50 |
50 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); | 112 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
112 return true; | 113 return true; |
113 } | 114 } |
114 | 115 |
115 void GrDrawTarget::flush() { | 116 void GrDrawTarget::flush() { |
116 if (fFlushing) { | 117 if (fFlushing) { |
117 return; | 118 return; |
118 } | 119 } |
119 fFlushing = true; | 120 fFlushing = true; |
120 | 121 |
| 122 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh |
| 123 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed |
| 124 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w |
| 125 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. |
| 126 this->makeClosed(); |
| 127 |
121 // Loop over all batches and generate geometry | 128 // Loop over all batches and generate geometry |
122 for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) { | 129 for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) { |
123 fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState); | 130 fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState); |
124 } | 131 } |
125 | 132 |
126 // Upload all data to the GPU | 133 // Upload all data to the GPU |
127 fFlushState.preIssueDraws(); | 134 fFlushState.preIssueDraws(); |
128 | 135 |
129 // Draw all the generated geometry. | 136 // Draw all the generated geometry. |
130 for (int i = 0; i < fBatches.count(); ++i) { | 137 for (int i = 0; i < fBatches.count(); ++i) { |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 406 } |
400 } | 407 } |
401 | 408 |
402 template <class Left, class Right> static bool intersect(const Left& a, const Ri
ght& b) { | 409 template <class Left, class Right> static bool intersect(const Left& a, const Ri
ght& b) { |
403 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && | 410 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
404 b.fLeft <= b.fRight && b.fTop <= b.fBottom); | 411 b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
405 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f
Top < a.fBottom; | 412 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f
Top < a.fBottom; |
406 } | 413 } |
407 | 414 |
408 void GrDrawTarget::recordBatch(GrBatch* batch) { | 415 void GrDrawTarget::recordBatch(GrBatch* batch) { |
| 416 // A closed drawTarget should never receive new/more batches |
| 417 SkASSERT(!fClosed); |
| 418 |
409 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either | 419 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either |
410 // 1) check every draw | 420 // 1) check every draw |
411 // 2) intersect with something | 421 // 2) intersect with something |
412 // 3) find a 'blocker' | 422 // 3) find a 'blocker' |
413 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. | 423 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. |
414 static const int kMaxLookback = 10; | 424 static const int kMaxLookback = 10; |
415 | 425 |
416 GrBATCH_INFO("Re-Recording (%s, B%u)\n" | 426 GrBATCH_INFO("Re-Recording (%s, B%u)\n" |
417 "\tBounds LRTB (%f, %f, %f, %f)\n", | 427 "\tBounds LRTB (%f, %f, %f, %f)\n", |
418 batch->name(), | 428 batch->name(), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 491 } |
482 | 492 |
483 return true; | 493 return true; |
484 } | 494 } |
485 | 495 |
486 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 496 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
487 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 497 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
488 this->recordBatch(batch); | 498 this->recordBatch(batch); |
489 batch->unref(); | 499 batch->unref(); |
490 } | 500 } |
OLD | NEW |