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 14 matching lines...) Expand all Loading... |
25 #include "batches/GrDiscardBatch.h" | 25 #include "batches/GrDiscardBatch.h" |
26 #include "batches/GrDrawBatch.h" | 26 #include "batches/GrDrawBatch.h" |
27 #include "batches/GrDrawPathBatch.h" | 27 #include "batches/GrDrawPathBatch.h" |
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(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider, |
36 const Options& options) | 36 const Options& options) |
37 : fGpu(SkRef(gpu)) | 37 : fGpu(SkRef(gpu)) |
38 , fResourceProvider(resourceProvider) | 38 , fResourceProvider(resourceProvider) |
39 , fFlushState(fGpu, fResourceProvider, 0) | 39 , fFlushState(fGpu, fResourceProvider, 0) |
40 , fFlushing(false) | 40 , fFlushing(false) |
41 , fFirstUnpreparedBatch(0) | 41 , fFirstUnpreparedBatch(0) |
42 , fFlags(0) | 42 , fFlags(0) |
43 , fOptions(options) { | 43 , fOptions(options) |
| 44 , fRenderTarget(rt) { |
44 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 45 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
45 fContext = fGpu->getContext(); | 46 fContext = fGpu->getContext(); |
46 fClipMaskManager.reset(new GrClipMaskManager(this)); | 47 fClipMaskManager.reset(new GrClipMaskManager(this)); |
47 | 48 |
48 #ifdef SK_DEBUG | 49 #ifdef SK_DEBUG |
49 static int debugID = 0; | 50 static int debugID = 0; |
50 fDebugID = debugID++; | 51 fDebugID = debugID++; |
51 #endif | 52 #endif |
52 } | 53 } |
53 | 54 |
54 GrDrawTarget::~GrDrawTarget() { | 55 GrDrawTarget::~GrDrawTarget() { |
| 56 if (fRenderTarget && this == fRenderTarget->getLastDrawTarget()) { |
| 57 fRenderTarget->setLastDrawTarget(nullptr); |
| 58 } |
| 59 |
55 fGpu->unref(); | 60 fGpu->unref(); |
56 } | 61 } |
57 | 62 |
58 //////////////////////////////////////////////////////////////////////////////// | 63 //////////////////////////////////////////////////////////////////////////////// |
59 | 64 |
60 // Add a GrDrawTarget-based dependency | 65 // Add a GrDrawTarget-based dependency |
61 void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { | 66 void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { |
62 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad | 67 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad |
63 | 68 |
64 if (this->dependsOn(dependedOn)) { | 69 if (this->dependsOn(dependedOn)) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return; | 182 return; |
178 } | 183 } |
179 fFlushing = true; | 184 fFlushing = true; |
180 | 185 |
181 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh | 186 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh |
182 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed | 187 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed |
183 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w | 188 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w |
184 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. | 189 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. |
185 this->makeClosed(); | 190 this->makeClosed(); |
186 | 191 |
187 // Loop over all batches and generate geometry | 192 // Loop over the batches that haven't yet generated their geometry |
188 for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) { | 193 for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) { |
189 fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState); | 194 fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState); |
190 } | 195 } |
191 | 196 |
192 // Upload all data to the GPU | 197 // Upload all data to the GPU |
193 fFlushState.preIssueDraws(); | 198 fFlushState.preIssueDraws(); |
194 | 199 |
195 // Draw all the generated geometry. | 200 // Draw all the generated geometry. |
196 for (int i = 0; i < fBatches.count(); ++i) { | 201 for (int i = 0; i < fBatches.count(); ++i) { |
197 fBatches[i]->draw(&fFlushState); | 202 fBatches[i]->draw(&fFlushState); |
(...skipping 22 matching lines...) Expand all Loading... |
220 if (clip.clipCoverageFragmentProcessor()) { | 225 if (clip.clipCoverageFragmentProcessor()) { |
221 arfps.set(&pipelineBuilder); | 226 arfps.set(&pipelineBuilder); |
222 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; | 227 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; |
223 } | 228 } |
224 | 229 |
225 GrPipeline::CreateArgs args; | 230 GrPipeline::CreateArgs args; |
226 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState()
, batch)) { | 231 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState()
, batch)) { |
227 return; | 232 return; |
228 } | 233 } |
229 | 234 |
| 235 #ifdef ENABLE_MDB |
| 236 SkASSERT(fRenderTarget); |
| 237 batch->pipeline()->addDependenciesTo(fRenderTarget); |
| 238 #endif |
| 239 |
230 this->recordBatch(batch); | 240 this->recordBatch(batch); |
231 } | 241 } |
232 | 242 |
233 static const GrStencilSettings& winding_path_stencil_settings() { | 243 static const GrStencilSettings& winding_path_stencil_settings() { |
234 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, | 244 GR_STATIC_CONST_SAME_STENCIL_STRUCT(gSettings, |
235 kIncClamp_StencilOp, | 245 kIncClamp_StencilOp, |
236 kIncClamp_StencilOp, | 246 kIncClamp_StencilOp, |
237 kAlwaysIfInClip_StencilFunc, | 247 kAlwaysIfInClip_StencilFunc, |
238 0xFFFF, 0xFFFF, 0xFFFF); | 248 0xFFFF, 0xFFFF, 0xFFFF); |
239 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); | 249 return *GR_CONST_STENCIL_SETTINGS_PTR_FROM_STRUCT_PTR(&gSettings); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 } | 458 } |
449 | 459 |
450 //////////////////////////////////////////////////////////////////////////////// | 460 //////////////////////////////////////////////////////////////////////////////// |
451 | 461 |
452 void GrDrawTarget::copySurface(GrSurface* dst, | 462 void GrDrawTarget::copySurface(GrSurface* dst, |
453 GrSurface* src, | 463 GrSurface* src, |
454 const SkIRect& srcRect, | 464 const SkIRect& srcRect, |
455 const SkIPoint& dstPoint) { | 465 const SkIPoint& dstPoint) { |
456 GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); | 466 GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint); |
457 if (batch) { | 467 if (batch) { |
| 468 #ifdef ENABLE_MDB |
| 469 this->addDependency(src); |
| 470 #endif |
| 471 |
458 this->recordBatch(batch); | 472 this->recordBatch(batch); |
459 batch->unref(); | 473 batch->unref(); |
460 } | 474 } |
461 } | 475 } |
462 | 476 |
463 template <class Left, class Right> static bool intersect(const Left& a, const Ri
ght& b) { | 477 template <class Left, class Right> static bool intersect(const Left& a, const Ri
ght& b) { |
464 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && | 478 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
465 b.fLeft <= b.fRight && b.fTop <= b.fBottom); | 479 b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
466 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f
Top < a.fBottom; | 480 return a.fLeft < b.fRight && b.fLeft < a.fRight && a.fTop < b.fBottom && b.f
Top < a.fBottom; |
467 } | 481 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 } | 564 } |
551 | 565 |
552 return true; | 566 return true; |
553 } | 567 } |
554 | 568 |
555 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 569 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
556 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 570 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
557 this->recordBatch(batch); | 571 this->recordBatch(batch); |
558 batch->unref(); | 572 batch->unref(); |
559 } | 573 } |
OLD | NEW |