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