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 20 matching lines...) Expand all Loading... |
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 , fFlags(0) { |
42 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 42 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
43 fContext = fGpu->getContext(); | 43 fContext = fGpu->getContext(); |
44 fClipMaskManager.reset(new GrClipMaskManager(this)); | 44 fClipMaskManager.reset(new GrClipMaskManager(this)); |
45 } | 45 } |
46 | 46 |
47 GrDrawTarget::~GrDrawTarget() { | 47 GrDrawTarget::~GrDrawTarget() { |
48 fGpu->unref(); | 48 fGpu->unref(); |
49 } | 49 } |
50 | 50 |
51 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
52 | 52 |
| 53 // Add a GrDrawTarget-based dependency |
| 54 void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { |
| 55 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad |
| 56 |
| 57 if (this->dependsOn(dependedOn)) { |
| 58 return; // don't add duplicate dependencies |
| 59 } |
| 60 |
| 61 *fDependencies.push() = dependedOn; |
| 62 } |
| 63 |
| 64 // Convert from a GrSurface-based dependency to a GrDrawTarget one |
| 65 void GrDrawTarget::addDependency(GrSurface* dependedOn) { |
| 66 if (dependedOn->asRenderTarget() && dependedOn->asRenderTarget()->getLastDra
wTarget()) { |
| 67 // If it is still receiving dependencies, this DT shouldn't be closed |
| 68 SkASSERT(!this->isClosed()); |
| 69 |
| 70 GrDrawTarget* dt = dependedOn->asRenderTarget()->getLastDrawTarget(); |
| 71 if (dt == this) { |
| 72 // self-read - presumably for dst reads |
| 73 } else { |
| 74 this->addDependency(dt); |
| 75 |
| 76 // Can't make it closed in the self-read case |
| 77 dt->makeClosed(); |
| 78 } |
| 79 } |
| 80 } |
| 81 |
53 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
der, | 82 bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
der, |
54 const GrProcOptInfo& colorPOI, | 83 const GrProcOptInfo& colorPOI, |
55 const GrProcOptInfo& coveragePOI, | 84 const GrProcOptInfo& coveragePOI, |
56 GrXferProcessor::DstTexture* dstTextu
re, | 85 GrXferProcessor::DstTexture* dstTextu
re, |
57 const SkRect& batchBounds) { | 86 const SkRect& batchBounds) { |
58 SkRect bounds = batchBounds; | 87 SkRect bounds = batchBounds; |
59 bounds.outset(0.5f, 0.5f); | 88 bounds.outset(0.5f, 0.5f); |
60 | 89 |
61 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), colorPOI, coverageP
OI)) { | 90 if (!pipelineBuilder.willXPNeedDstTexture(*this->caps(), colorPOI, coverageP
OI)) { |
62 return true; | 91 return true; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 436 } |
408 | 437 |
409 template <class Left, class Right> static bool intersect(const Left& a, const Ri
ght& b) { | 438 template <class Left, class Right> static bool intersect(const Left& a, const Ri
ght& b) { |
410 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && | 439 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
411 b.fLeft <= b.fRight && b.fTop <= b.fBottom); | 440 b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
412 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f
Top < a.fBottom; | 441 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f
Top < a.fBottom; |
413 } | 442 } |
414 | 443 |
415 void GrDrawTarget::recordBatch(GrBatch* batch) { | 444 void GrDrawTarget::recordBatch(GrBatch* batch) { |
416 // A closed drawTarget should never receive new/more batches | 445 // A closed drawTarget should never receive new/more batches |
417 SkASSERT(!fClosed); | 446 SkASSERT(!this->isClosed()); |
418 | 447 |
419 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either | 448 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either |
420 // 1) check every draw | 449 // 1) check every draw |
421 // 2) intersect with something | 450 // 2) intersect with something |
422 // 3) find a 'blocker' | 451 // 3) find a 'blocker' |
423 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. | 452 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. |
424 static const int kMaxLookback = 10; | 453 static const int kMaxLookback = 10; |
425 | 454 |
426 GrBATCH_INFO("Re-Recording (%s, B%u)\n" | 455 GrBATCH_INFO("Re-Recording (%s, B%u)\n" |
427 "\tBounds LRTB (%f, %f, %f, %f)\n", | 456 "\tBounds LRTB (%f, %f, %f, %f)\n", |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 520 } |
492 | 521 |
493 return true; | 522 return true; |
494 } | 523 } |
495 | 524 |
496 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 525 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
497 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 526 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
498 this->recordBatch(batch); | 527 this->recordBatch(batch); |
499 batch->unref(); | 528 batch->unref(); |
500 } | 529 } |
OLD | NEW |