| 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 12 matching lines...) Expand all Loading... |
| 23 #include "batches/GrClearBatch.h" | 23 #include "batches/GrClearBatch.h" |
| 24 #include "batches/GrCopySurfaceBatch.h" | 24 #include "batches/GrCopySurfaceBatch.h" |
| 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 GrDrawTarget* getLastDT6(GrGpuResource* res) { |
| 34 GrRenderTarget* rt = res->arrgh(); |
| 35 if (rt) { |
| 36 return rt->getLastDrawTarget(); |
| 37 } else { |
| 38 return nullptr; |
| 39 } |
| 40 } |
| 41 |
| 42 void addRequiredDep(GrDrawTarget* dst, GrDrawTarget* src) { |
| 43 dst->addRequiredDep(src); |
| 44 } |
| 45 |
| 33 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 34 | 47 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider) |
| 35 GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r
esourceProvider) | |
| 36 : fGpu(SkRef(gpu)) | 48 : fGpu(SkRef(gpu)) |
| 37 , fResourceProvider(resourceProvider) | 49 , fResourceProvider(resourceProvider) |
| 38 , fFlushing(false) | 50 , fFlushing(false) |
| 39 , fFlags(0) | 51 , fFlags(0) |
| 40 , fRenderTarget(rt) { | 52 , fRenderTarget(rt) { |
| 41 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) | 53 // TODO: Stop extracting the context (currently needed by GrClipMaskManager) |
| 42 fContext = fGpu->getContext(); | 54 fContext = fGpu->getContext(); |
| 43 fClipMaskManager.reset(new GrClipMaskManager(this)); | 55 fClipMaskManager.reset(new GrClipMaskManager(this)); |
| 44 | 56 |
| 45 #ifdef SK_DEBUG | 57 #ifdef SK_DEBUG |
| 46 static int debugID = 0; | 58 static int debugID = 0; |
| 47 fDebugID = debugID++; | 59 fDebugID = debugID++; |
| 48 #endif | 60 #endif |
| 49 } | 61 } |
| 50 | 62 |
| 63 void GrDrawTarget::checkUses() const { |
| 64 for (int i = 0; i < fRequired.count(); ++i) { |
| 65 SkASSERT(fDependencies.find(fRequired[i]) >= 0); |
| 66 } |
| 67 for (int i = 0; i < fDependencies.count(); ++i) { |
| 68 SkASSERT(fRequired.find(fDependencies[i]) >= 0); |
| 69 } |
| 70 } |
| 71 |
| 72 |
| 51 GrDrawTarget::~GrDrawTarget() { | 73 GrDrawTarget::~GrDrawTarget() { |
| 74 // TODO: this seems like a reasonable assert |
| 75 //SkASSERT(fClosed); |
| 76 |
| 52 if (fRenderTarget && this == fRenderTarget->getLastDrawTarget()) { | 77 if (fRenderTarget && this == fRenderTarget->getLastDrawTarget()) { |
| 53 fRenderTarget->setLastDrawTarget(nullptr); | 78 fRenderTarget->setLastDrawTarget(nullptr); |
| 54 } | 79 } |
| 55 | 80 |
| 81 this->checkUses(); |
| 82 |
| 56 fGpu->unref(); | 83 fGpu->unref(); |
| 57 } | 84 } |
| 58 | 85 |
| 59 //////////////////////////////////////////////////////////////////////////////// | 86 //////////////////////////////////////////////////////////////////////////////// |
| 60 | 87 |
| 61 // Add a GrDrawTarget-based dependency | 88 // Add a GrDrawTarget-based dependency |
| 62 void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { | 89 void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) { |
| 63 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad | 90 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad |
| 64 | 91 |
| 65 if (this->dependsOn(dependedOn)) { | 92 if (this->dependsOn(dependedOn)) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 this->copySurface(copy, rt, copyRect, dstPoint); | 197 this->copySurface(copy, rt, copyRect, dstPoint); |
| 171 dstTexture->setTexture(copy); | 198 dstTexture->setTexture(copy); |
| 172 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); | 199 dstTexture->setOffset(copyRect.fLeft, copyRect.fTop); |
| 173 return true; | 200 return true; |
| 174 } | 201 } |
| 175 | 202 |
| 176 void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) { | 203 void GrDrawTarget::prepareBatches(GrBatchFlushState* flushState) { |
| 177 if (fFlushing) { | 204 if (fFlushing) { |
| 178 return; | 205 return; |
| 179 } | 206 } |
| 207 |
| 208 this->checkUses(); |
| 209 |
| 180 fFlushing = true; | 210 fFlushing = true; |
| 181 | 211 |
| 182 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh | 212 // Semi-usually the drawTargets are already closed at this point, but someti
mes Ganesh |
| 183 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed | 213 // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won'
t be closed |
| 184 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w | 214 // but need to be flushed anyway. Closing such drawTargets here will mean ne
w |
| 185 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. | 215 // drawTargets will be created to replace them if the SkGpuDevice(s) write t
o them again. |
| 186 this->makeClosed(); | 216 this->makeClosed(); |
| 187 | 217 |
| 188 // Loop over the batches that haven't yet generated their geometry | 218 // Loop over the batches that haven't yet generated their geometry |
| 189 for (int i = 0; i < fBatches.count(); ++i) { | 219 for (int i = 0; i < fBatches.count(); ++i) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 201 } | 231 } |
| 202 | 232 |
| 203 void GrDrawTarget::reset() { | 233 void GrDrawTarget::reset() { |
| 204 fBatches.reset(); | 234 fBatches.reset(); |
| 205 } | 235 } |
| 206 | 236 |
| 207 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { | 237 void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
ch* batch) { |
| 208 // Setup clip | 238 // Setup clip |
| 209 GrPipelineBuilder::AutoRestoreStencil ars; | 239 GrPipelineBuilder::AutoRestoreStencil ars; |
| 210 GrAppliedClip clip; | 240 GrAppliedClip clip; |
| 211 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds()
, &clip)) { | 241 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds()
, &clip, fRenderTarget)) { |
| 212 return; | 242 return; |
| 213 } | 243 } |
| 214 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 244 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 215 if (clip.clipCoverageFragmentProcessor()) { | 245 if (clip.clipCoverageFragmentProcessor()) { |
| 216 arfps.set(&pipelineBuilder); | 246 arfps.set(&pipelineBuilder); |
| 217 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; | 247 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; |
| 218 } | 248 } |
| 219 | 249 |
| 220 GrPipeline::CreateArgs args; | 250 GrPipeline::CreateArgs args; |
| 221 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState()
, batch)) { | 251 if (!this->installPipelineInDrawBatch(&pipelineBuilder, &clip.scissorState()
, batch)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 const SkMatrix& viewMatrix, | 299 const SkMatrix& viewMatrix, |
| 270 const GrPath* path, | 300 const GrPath* path, |
| 271 GrPathRendering::FillType fill) { | 301 GrPathRendering::FillType fill) { |
| 272 // TODO: extract portions of checkDraw that are relevant to path stenciling. | 302 // TODO: extract portions of checkDraw that are relevant to path stenciling. |
| 273 SkASSERT(path); | 303 SkASSERT(path); |
| 274 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); | 304 SkASSERT(this->caps()->shaderCaps()->pathRenderingSupport()); |
| 275 | 305 |
| 276 // Setup clip | 306 // Setup clip |
| 277 GrPipelineBuilder::AutoRestoreStencil ars; | 307 GrPipelineBuilder::AutoRestoreStencil ars; |
| 278 GrAppliedClip clip; | 308 GrAppliedClip clip; |
| 279 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, nullptr, &clip))
{ | 309 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, nullptr, &clip,
fRenderTarget)) { |
| 280 return; | 310 return; |
| 281 } | 311 } |
| 282 | 312 |
| 283 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 313 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 284 if (clip.clipCoverageFragmentProcessor()) { | 314 if (clip.clipCoverageFragmentProcessor()) { |
| 285 arfps.set(&pipelineBuilder); | 315 arfps.set(&pipelineBuilder); |
| 286 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; | 316 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; |
| 287 } | 317 } |
| 288 | 318 |
| 289 // set stencil settings for path | 319 // set stencil settings for path |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder, | 360 void GrDrawTarget::drawPathBatch(const GrPipelineBuilder& pipelineBuilder, |
| 331 GrDrawPathBatchBase* batch, | 361 GrDrawPathBatchBase* batch, |
| 332 GrPathRendering::FillType fill) { | 362 GrPathRendering::FillType fill) { |
| 333 // This looks like drawBatch() but there is an added wrinkle that stencil se
ttings get inserted | 363 // This looks like drawBatch() but there is an added wrinkle that stencil se
ttings get inserted |
| 334 // after setting up clipping but before onDrawBatch(). TODO: Figure out a be
tter model for | 364 // after setting up clipping but before onDrawBatch(). TODO: Figure out a be
tter model for |
| 335 // handling stencil settings WRT interactions between pipeline(builder), cli
pmaskmanager, and | 365 // handling stencil settings WRT interactions between pipeline(builder), cli
pmaskmanager, and |
| 336 // batches. | 366 // batches. |
| 337 | 367 |
| 338 GrPipelineBuilder::AutoRestoreStencil ars; | 368 GrPipelineBuilder::AutoRestoreStencil ars; |
| 339 GrAppliedClip clip; | 369 GrAppliedClip clip; |
| 340 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds()
, &clip)) { | 370 if (!fClipMaskManager->setupClipping(pipelineBuilder, &ars, &batch->bounds()
, &clip, fRenderTarget)) { |
| 341 return; | 371 return; |
| 342 } | 372 } |
| 343 | 373 |
| 344 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; | 374 GrPipelineBuilder::AutoRestoreFragmentProcessorState arfps; |
| 345 if (clip.clipCoverageFragmentProcessor()) { | 375 if (clip.clipCoverageFragmentProcessor()) { |
| 346 arfps.set(&pipelineBuilder); | 376 arfps.set(&pipelineBuilder); |
| 347 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; | 377 arfps.addCoverageFragmentProcessor(clip.clipCoverageFragmentProcessor())
; |
| 348 } | 378 } |
| 349 | 379 |
| 350 // Ensure the render target has a stencil buffer and get the stencil setting
s. | 380 // Ensure the render target has a stencil buffer and get the stencil setting
s. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 } | 575 } |
| 546 | 576 |
| 547 return true; | 577 return true; |
| 548 } | 578 } |
| 549 | 579 |
| 550 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { | 580 void GrDrawTarget::clearStencilClip(const SkIRect& rect, bool insideClip, GrRend
erTarget* rt) { |
| 551 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); | 581 GrBatch* batch = new GrClearStencilClipBatch(rect, insideClip, rt); |
| 552 this->recordBatch(batch); | 582 this->recordBatch(batch); |
| 553 batch->unref(); | 583 batch->unref(); |
| 554 } | 584 } |
| OLD | NEW |